git-svn-id: https://spexeah.com:8443/svn/Asuro@654 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c

This commit is contained in:
kieron
2018-05-03 23:16:37 +00:00
parent a5bae52f09
commit 6ae51ac70d
67 changed files with 341 additions and 17 deletions

257
src/cpu.pas Normal file
View File

@ -0,0 +1,257 @@
unit cpu;
interface
uses
console, util, RTC, terminal;
type
PCapabilities_Old = ^TCapabilities_Old;
TCapabilities_Old = bitpacked record
FPU : Boolean;
VME : Boolean;
DE : Boolean;
PSE : Boolean;
TSC : Boolean;
MSR : Boolean;
PAE : Boolean;
MCE : Boolean;
CX8 : Boolean;
APIC : Boolean;
RESV0 : Boolean;
SEP : Boolean;
MTRR : Boolean;
PGE : Boolean;
MCA : Boolean;
CMOV : Boolean;
PAT : Boolean;
PSE36 : Boolean;
PSN : Boolean;
CLF : Boolean;
RESV1 : Boolean;
DTES : Boolean;
ACPI : Boolean;
MMX : Boolean;
FXSR : Boolean;
SSE : Boolean;
SSE2 : Boolean;
SS : Boolean;
HTT : Boolean;
TM1 : Boolean;
IA64 : Boolean;
PBE : Boolean;
end;
PCapabilities_New = ^TCapabilities_New;
TCapabilities_New = bitpacked record
SSE3 : Boolean;
PCLMUL : Boolean;
DTES64 : Boolean;
MONITOR : Boolean;
DS_CPL : Boolean;
VMX : Boolean;
SMX : Boolean;
EST : Boolean;
TM2 : Boolean;
SSSE3 : Boolean;
CID : Boolean;
RESV0 : Boolean;
FMA : Boolean;
CX16 : Boolean;
ETPRD : Boolean;
PDCM : Boolean;
RESV1 : Boolean;
PCIDE : Boolean;
DCA : Boolean;
SSE4_1 : Boolean;
SSE4_2 : Boolean;
x2APIC : Boolean;
MOVBE : Boolean;
POPCNT : Boolean;
RESV2 : Boolean;
AES : Boolean;
XSAVE : Boolean;
OSXSAVE : Boolean;
AVX : Boolean;
RESV3 : Boolean;
RESV4 : Boolean;
RESV5 : Boolean;
end;
TClockSpeed = record
Hz : uint32;
MHz : uint32;
GHz : uint32;
end;
TCPUID = record
ClockSpeed : TClockSpeed;
Identifier : Array[0..12] of Char;
Capabilities0 : PCapabilities_Old;
Capabilities1 : PCapabilities_New;
end;
var
CPUID : TCPUID;
CAP_OLD, CAP_NEW : uint32;
procedure init();
implementation
procedure getCPUIdentifier;
var
id0, id1, id2 : uint32;
id : pchar;
i : uint32;
begin
asm
PUSH EAX
PUSH EBX
PUSH ECX
PUSH EDX
MOV EAX, 0
CPUID
MOV id0, EBX
MOV id1, EDX
MOV id2, ECX
POP EDX
POP ECX
POP EBX
POP EAX
end;
CPUID.Identifier[12]:= char(0);
id:= pchar(@id0);
for i:=0 to 3 do begin
CPUID.Identifier[0+i]:= id[i];
end;
id:= pchar(@id1);
for i:=0 to 3 do begin
CPUID.Identifier[4+i]:= id[i];
end;
id:= pchar(@id2);
for i:=0 to 3 do begin
CPUID.Identifier[8+i]:= id[i];
end;
end;
procedure getCPUCapabilities;
begin
asm
PUSH EAX
PUSH EBX
PUSH ECX
PUSH EDX
MOV EAX, 1
CPUID
MOV CAP_OLD, EDX
MOV CAP_NEW, ECX
POP EDX
POP ECX
POP EBX
POP EAX
end;
end;
procedure getCPUClockSpeed;
var
t1, t2 : TDateTime;
c : uint32;
begin
c:= 0;
t1:= getDateTime;
t2:= getDateTime;
while (t1.Seconds = t2.Seconds) do begin
inc(c);
t2:= getDateTime;
end;
CPUID.ClockSpeed.Hz:= c;
CPUID.ClockSpeed.MHz:= CPUID.ClockSpeed.Hz div 1000;
CPUID.ClockSpeed.GHz:= CPUID.ClockSpeed.MHz div 1000;
end;
procedure printCapabilities(WND : HWND);
begin
{ Old Capabilities }
if CPUID.Capabilities0^.FPU then writestringWND('FPU', WND);
if CPUID.Capabilities0^.VME then writestringWND(', VME', WND);
if CPUID.Capabilities0^.DE then writestringWND(', DE', WND);
if CPUID.Capabilities0^.PSE then writestringWND(', PSE', WND);
if CPUID.Capabilities0^.TSC then writestringWND(', TSC', WND);
if CPUID.Capabilities0^.MSR then writestringWND(', MSR', WND);
if CPUID.Capabilities0^.PAE then writestringWND(', PAE', WND);
if CPUID.Capabilities0^.MCE then writestringWND(', MCE', WND);
if CPUID.Capabilities0^.CX8 then writestringWND(', CX8', WND);
if CPUID.Capabilities0^.APIC then writestringWND(', APIC', WND);
if CPUID.Capabilities0^.SEP then writestringWND(', SEP', WND);
if CPUID.Capabilities0^.MTRR then writestringWND(', MTRR', WND);
if CPUID.Capabilities0^.PGE then writestringWND(', PGE', WND);
if CPUID.Capabilities0^.MCA then writestringWND(', MCA', WND);
if CPUID.Capabilities0^.CMOV then writestringWND(', CMOV', WND);
if CPUID.Capabilities0^.PAT then writestringWND(', PAT', WND);
if CPUID.Capabilities0^.PSE36 then writestringWND(', PSE36', WND);
if CPUID.Capabilities0^.PSN then writestringWND(', PSN', WND);
if CPUID.Capabilities0^.CLF then writestringWND(', CLF', WND);
if CPUID.Capabilities0^.DTES then writestringWND(', DTES', WND);
if CPUID.Capabilities0^.ACPI then writestringWND(', ACPI', WND);
if CPUID.Capabilities0^.MMX then writestringWND(', MMX', WND);
if CPUID.Capabilities0^.FXSR then writestringWND(', FXSR', WND);
if CPUID.Capabilities0^.SSE then writestringWND(', SSE', WND);
if CPUID.Capabilities0^.SSE2 then writestringWND(', SSE2', WND);
if CPUID.Capabilities0^.SS then writestringWND(', SS', WND);
if CPUID.Capabilities0^.HTT then writestringWND(', HTT', WND);
if CPUID.Capabilities0^.TM1 then writestringWND(', TM1', WND);
if CPUID.Capabilities0^.IA64 then writestringWND(', IA64', WND);
if CPUID.Capabilities0^.PBE then writestringWND(', PBE', WND);
{ Newer Capabilities }
if CPUID.Capabilities1^.SSE3 then writestringWND(', SSE3', WND);
if CPUID.Capabilities1^.PCLMUL then writestringWND(', PCLMUL', WND);
if CPUID.Capabilities1^.DTES64 then writestringWND(', DTES64', WND);
if CPUID.Capabilities1^.MONITOR then writestringWND(', MONITOR', WND);
if CPUID.Capabilities1^.DS_CPL then writestringWND(', DS_CPL', WND);
if CPUID.Capabilities1^.VMX then writestringWND(', VMX', WND);
if CPUID.Capabilities1^.SMX then writestringWND(', SMX', WND);
if CPUID.Capabilities1^.EST then writestringWND(', EST', WND);
if CPUID.Capabilities1^.TM2 then writestringWND(', TM2', WND);
if CPUID.Capabilities1^.SSSE3 then writestringWND(', SSSE3', WND);
if CPUID.Capabilities1^.CID then writestringWND(', CID', WND);
if CPUID.Capabilities1^.FMA then writestringWND(', FMA', WND);
if CPUID.Capabilities1^.CX16 then writestringWND(', CX16', WND);
if CPUID.Capabilities1^.ETPRD then writestringWND(', ETPRD', WND);
if CPUID.Capabilities1^.PDCM then writestringWND(', PDCM', WND);
if CPUID.Capabilities1^.PCIDE then writestringWND(', PCIDE', WND);
if CPUID.Capabilities1^.DCA then writestringWND(', DCA', WND);
if CPUID.Capabilities1^.SSE4_1 then writestringWND(', SSE4_1', WND);
if CPUID.Capabilities1^.SSE4_2 then writestringWND(', SSE4_2', WND);
if CPUID.Capabilities1^.x2APIC then writestringWND(', x2APIC', WND);
if CPUID.Capabilities1^.MOVBE then writestringWND(', MOVBE', WND);
if CPUID.Capabilities1^.POPCNT then writestringWND(', POPCNT', WND);
if CPUID.Capabilities1^.AES then writestringWND(', AES', WND);
if CPUID.Capabilities1^.XSAVE then writestringWND(', XSAVE', WND);
if CPUID.Capabilities1^.OSXSAVE then writestringWND(', OSXSAVE', WND);
if CPUID.Capabilities1^.AVX then writestringWND(', AVX', WND);
writestringlnWND(' ', WND);
end;
procedure Terminal_Command_CPU(Params : PParamList);
begin
writeStringWND('Vendor: ', getTerminalHWND);
writeStringLnWND(@CPUID.Identifier[0], getTerminalHWND);
writeStringWND('CPU Clock: ', getTerminalHWND);
writeIntWND(CPUID.ClockSpeed.MHz, getTerminalHWND);
writeStringlnWND('MHz', getTerminalHWND);
writeStringWND('CPU Capabilities: ', getTerminalHWND);
printCapabilities(getTerminalHWND);
end;
procedure init();
begin
terminal.registerCommand('CPU', @Terminal_Command_CPU, 'CPU Info.');
CPUID.Capabilities0:= PCapabilities_Old(@CAP_OLD);
CPUID.Capabilities1:= PCapabilities_New(@CAP_NEW);
getCPUIdentifier;
getCPUCapabilities;
getCPUClockSpeed;
end;
end.

View File

@ -21,6 +21,9 @@ type
TKeyInfo = packed record
key_code : byte;
is_down_code : boolean; //true when pressing down, false when releasing
SHIFT_DOWN : boolean;
CTRL_DOWN : boolean;
ALT_DOWN : boolean;
end;
PKeyInfo = ^TKeyInfo;
@ -31,7 +34,9 @@ var
key_matrix : array [1..256] of TKeyInfo;
key_matrix_shift : array [1..256] of TKeyInfo;
captin_hook : pp_hook_method = nil;
is_shift : boolean = false;
is_shift : boolean = false;
is_ctrl : boolean = false;
is_alt : boolean = false;
procedure init(keyboard_layout : array of TKeyInfo);
procedure hook(proc : pp_hook_method);
@ -43,20 +48,36 @@ uses
drivermanagement;
procedure callback(scan_code : void);
var
info : TKeyInfo;
begin
//console.writehex(uint8(scan_code));
//console.writestring('[Keyboard] Scancode: ');
//console.writeintln(uint32(scan_code));
info.SHIFT_DOWN:= is_shift;
info.CTRL_DOWN:= is_ctrl;
info.ALT_DOWN:= is_alt;
if is_shift then begin
if key_matrix_shift[uint8(scan_code)].key_code <> 0 then begin
if captin_hook <> nil then captin_hook(key_matrix_shift[uint8(scan_code)]);
if captin_hook <> nil then begin
info.key_code:= key_matrix_shift[uint8(scan_code)].key_code;
captin_hook(info);
end;
end;
end else begin
if key_matrix[uint8(scan_code)].key_code <> 0 then begin
if captin_hook <> nil then captin_hook(key_matrix[uint8(scan_code)]);
if captin_hook <> nil then begin
info.key_code:= key_matrix[uint8(scan_code)].key_code;
captin_hook(info);
end;
end;
end;
if uint8(scan_code) = 42 then is_shift := true;
if uint8(scan_code) = 170 then is_shift := false;
if uint8(scan_code) = 29 then is_ctrl := true;
if uint8(scan_code) = 157 then is_ctrl := false;
if uint8(scan_code) = 56 then is_alt := true;
if uint8(scan_code) = 184 then is_alt := false;
end;
function load(ptr : void) : boolean;

View File

@ -3,11 +3,11 @@ unit asuro;
interface
const
VERSION = '1.0.0-651a';
VERSION = '1.0.0-653a';
VERSION_MAJOR = '1';
VERSION_MINOR = '0';
VERSION_SUB = '0';
REVISION = '651';
REVISION = '653';
RELEASE = 'a';
implementation

View File

@ -49,9 +49,18 @@ type
end;
PMCFG = ^TMCFG;
TCounters = record
c16 : uint16;
c32 : uint32;
c64 : uint64;
end;
const
BDA : PBDA = PBDA($C0000400);
var
Counters : TCounters;
procedure tick_update(data : void);
implementation
@ -61,7 +70,11 @@ uses
procedure tick_update(data : void);
begin
BDA^.Ticks:= BDA^.Ticks + 1;
//BDA^.Ticks:= BDA^.Ticks + 1;
inc(BDA^.Ticks);
inc(Counters.c16);
inc(Counters.c32);
inc(Counters.c64);
end;
end.

View File

@ -46,6 +46,10 @@ procedure BSOD(fault : pchar; info : pchar);
procedure psleep(t : uint16);
procedure sleep(seconds : uint32);
function get16bitcounter : uint16;
function get32bitcounter : uint32;
function get64bitcounter : uint64;
function BCDToUint8(bcd : uint8) : uint8;
procedure resetSystem();
@ -339,6 +343,21 @@ begin
halt_and_catch_fire;
end;
function get16bitcounter : uint16;
begin
get16bitcounter:= bios_data_area.Counters.c16;
end;
function get32bitcounter : uint32;
begin
get32bitcounter:= bios_data_area.Counters.c32;
end;
function get64bitcounter : uint64;
begin
get64bitcounter:= bios_data_area.Counters.c64;
end;
procedure BSOD(fault : pchar; info : pchar);
var
trace : pchar;

View File

@ -40,7 +40,8 @@ uses
serial,
shell,
memview,
splash;
splash,
cpu;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@ -144,6 +145,9 @@ begin
{ Console Init }
console.init();
{ CPUID }
cpu.init();
{ Serial Init }
serial.init();

View File

@ -117,19 +117,29 @@ begin
tmHex:printmemoryashex(MEM_LOC, 176, 16, ' ', true);
tmChar:printmemoryaschar(MEM_LOC, 176, 16, ' ', true);
end;
end;
end;
procedure OnKeyPressed(info : TKeyInfo);
begin
if info.key_code = 16 then begin
dec(MEM_LOC, 16);
NEW_LOC:= true;
end;
if info.key_code = 18 then begin
inc(MEM_LOC, 16);
NEW_LOC:= true;
if info.CTRL_DOWN then begin
if info.key_code = 16 then begin
dec(MEM_LOC, 176);
NEW_LOC:= true;
end;
if info.key_code = 18 then begin
inc(MEM_LOC, 176);
NEW_LOC:= true;
end;
end else begin
if info.key_code = 16 then begin
dec(MEM_LOC, 16);
NEW_LOC:= true;
end;
if info.key_code = 18 then begin
inc(MEM_LOC, 16);
NEW_LOC:= true;
end;
end;
if info.key_code = uint8('c') then begin
Mode:= tmChar;