Fixed GDT Code up - not tested properly yet, but it compiles.
git-svn-id: https://spexeah.com:8443/svn/Asuro@19 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
eebe77ad9b
commit
da08dfd941
99
src/gdt.pas
99
src/gdt.pas
@ -3,10 +3,14 @@ unit gdt;
|
||||
interface
|
||||
|
||||
uses
|
||||
util;
|
||||
util,
|
||||
types;
|
||||
|
||||
type
|
||||
TSegementDescriptor = bitpacked record
|
||||
procedure create(base : dword; limit : dword; flags : byte);
|
||||
procedure init();
|
||||
|
||||
type
|
||||
TSegmentDescriptor = bitpacked record
|
||||
limit_low : WORD;
|
||||
base_low : WORD;
|
||||
access : Byte;
|
||||
@ -15,55 +19,35 @@ type
|
||||
end;
|
||||
PSegmentDescriptor = ^TSegmentDescriptor;
|
||||
|
||||
var
|
||||
GDTarr : array of TSegementDescriptor;
|
||||
GDTptr : PSegmentDescriptor;
|
||||
GDT_length : integer = 0;
|
||||
|
||||
procedure init();
|
||||
procedure create(base : dword; limit : dword; flags : byte);
|
||||
|
||||
implementation
|
||||
|
||||
procedure init();
|
||||
var
|
||||
data_addr : dword;
|
||||
begin
|
||||
GDTptr := @GDTarr[0];
|
||||
data_addr := (@GDTarr[2] - @GDTarr[0]) shr 16;
|
||||
create($0000, $0000, $00); //null segment / GDT pointer
|
||||
create($0000, $FFFF, $9A); //code descriptor
|
||||
create($0000, $FFFF, $92); //data descriptor
|
||||
asm
|
||||
LGDT GDTptr
|
||||
MOV AX, data_addr
|
||||
MOV DS, AX
|
||||
MOV SS, AX
|
||||
MOV ES, AX
|
||||
MOV FS, AX
|
||||
MOV GS, AX
|
||||
end;
|
||||
end;
|
||||
var
|
||||
GDTarr : array [0..5] of TSegmentDescriptor;
|
||||
GDTptr : PSegmentDescriptor;
|
||||
GDT_length : integer = 0;
|
||||
|
||||
procedure create(base : dword; limit : dword; flags : byte);
|
||||
var
|
||||
descriptor : array[0..8] of Byte;
|
||||
descriptor_ptr : ^Byte = @descriptor[0];
|
||||
s_descriptor : TSegementDescriptor;
|
||||
s_descriptor_ptr : ^TSegementDescriptor = @s_descriptor;
|
||||
descriptor_ptr : PByte;
|
||||
|
||||
s_descriptor : TSegmentDescriptor;
|
||||
s_descriptor_ptr : PSegmentDescriptor;
|
||||
|
||||
begin
|
||||
if limit <= 65536 then begin
|
||||
descriptor[6] := $40
|
||||
end else begin
|
||||
if (limit and $FFF) <> $FFF then begin
|
||||
limit := (limit SHR 12) -1
|
||||
end else begin
|
||||
limit := limit SHR 12;
|
||||
end;
|
||||
descriptor_ptr:= @descriptor[0];
|
||||
s_descriptor_ptr:= @s_descriptor;
|
||||
if limit <= 65536 then begin
|
||||
descriptor[6] := $40
|
||||
end else begin
|
||||
if (limit and $FFF) <> $FFF then begin
|
||||
limit := (limit SHR 12) -1
|
||||
end else begin
|
||||
limit := limit SHR 12;
|
||||
end;
|
||||
end;
|
||||
|
||||
descriptor[6] := $C0;
|
||||
descriptor[6] := $C0;
|
||||
|
||||
descriptor[0] := limit and $FF;
|
||||
descriptor[1] := (limit shr 8) and $FF;
|
||||
@ -77,22 +61,41 @@ begin
|
||||
descriptor[5] := flags;
|
||||
|
||||
asm
|
||||
MOV EAX, descriptor_ptr
|
||||
MOV s_descriptor_ptr, EAX
|
||||
end;
|
||||
MOV EAX, descriptor_ptr
|
||||
MOV s_descriptor_ptr, EAX
|
||||
end;
|
||||
|
||||
descriptor_ptr = @descriptor[4];
|
||||
descriptor_ptr:= @descriptor[4];
|
||||
|
||||
asm
|
||||
MOV EAX, descriptor_ptr
|
||||
MOV EBX, s_descriptor_ptr
|
||||
ADD EBX, 1
|
||||
MOV (EBX), EAX
|
||||
MOV [EBX], EAX
|
||||
end;
|
||||
|
||||
GDTarr[GDT_length] := s_descriptor;
|
||||
GDT_length := GDT_length + 1;
|
||||
end;
|
||||
|
||||
|
||||
procedure init();
|
||||
var
|
||||
data_addr : dword;
|
||||
begin
|
||||
GDTptr := @GDTarr[0];
|
||||
data_addr := (@GDTarr[2] - @GDTarr[0]) shr 16;
|
||||
create($0000, $0000, $00); //null segment / GDT pointer
|
||||
create($0000, $FFFF, $9A); //code descriptor
|
||||
create($0000, $FFFF, $92); //data descriptor
|
||||
asm
|
||||
LGDT GDTptr
|
||||
MOV EAX, data_addr
|
||||
MOV DS, AX
|
||||
MOV SS, AX
|
||||
MOV ES, AX
|
||||
MOV FS, AX
|
||||
MOV GS, AX
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -5,6 +5,7 @@ interface
|
||||
uses
|
||||
multiboot,
|
||||
util,
|
||||
gdt,
|
||||
console,
|
||||
bios_data_area,
|
||||
keyboard;
|
||||
@ -18,6 +19,7 @@ var
|
||||
c : byte;
|
||||
|
||||
begin
|
||||
gdt.init();
|
||||
console.init();
|
||||
console.writestringln('Booting Asuro...');
|
||||
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin
|
||||
|
25
src/types.pas
Normal file
25
src/types.pas
Normal file
@ -0,0 +1,25 @@
|
||||
unit types;
|
||||
|
||||
interface
|
||||
|
||||
type
|
||||
//Standard Types
|
||||
Int8 = BYTE;
|
||||
Int16 = WORD;
|
||||
Int32 = DWORD;
|
||||
Int64 = QWORD;
|
||||
|
||||
//Pointer Types
|
||||
PByte = ^Byte;
|
||||
PInt8 = PByte;
|
||||
PInt16 = ^Int16;
|
||||
PInt32 = ^Int32;
|
||||
PInt64 = ^Int64;
|
||||
|
||||
Void = ^Int32;
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
14
src/util.pas
14
src/util.pas
@ -32,7 +32,7 @@ begin
|
||||
switchendian:= (lo(b) SHL 4) OR hi(b);
|
||||
end;
|
||||
|
||||
procedure outl(port : word; val : longword); [public, alias: 'outl'];
|
||||
procedure outl(port : word; val : longword); [public, alias: 'util_outl'];
|
||||
begin
|
||||
asm
|
||||
PUSH EAX
|
||||
@ -45,7 +45,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure outw(port : word; val : word); [public, alias: 'outw'];
|
||||
procedure outw(port : word; val : word); [public, alias: 'util_outw'];
|
||||
begin
|
||||
asm
|
||||
PUSH EAX
|
||||
@ -58,7 +58,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure outb(port : word; val : byte); [public, alias: 'outb'];
|
||||
procedure outb(port : word; val : byte); [public, alias: 'util_outb'];
|
||||
begin
|
||||
asm
|
||||
PUSH EAX
|
||||
@ -71,7 +71,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure halt_and_catch_fire(); [public, alias: 'halt_and_catch_fire'];
|
||||
procedure halt_and_catch_fire(); [public, alias: 'util_halt_and_catch_fire'];
|
||||
begin
|
||||
asm
|
||||
cli
|
||||
@ -79,7 +79,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function inl(port : word) : dword; [public, alias: 'inl'];
|
||||
function inl(port : word) : dword; [public, alias: 'util_inl'];
|
||||
begin
|
||||
asm
|
||||
PUSH EAX
|
||||
@ -92,7 +92,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function inw(port : word) : word; [public, alias: 'inw'];
|
||||
function inw(port : word) : word; [public, alias: 'util_inw'];
|
||||
begin
|
||||
asm
|
||||
PUSH EAX
|
||||
@ -105,7 +105,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function inb(port : word) : byte; [public, alias: 'inb'];
|
||||
function inb(port : word) : byte; [public, alias: 'util_inb'];
|
||||
begin
|
||||
asm
|
||||
PUSH EAX
|
||||
|
Loading…
x
Reference in New Issue
Block a user