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:
kieron 2017-05-16 11:53:51 +00:00
parent eebe77ad9b
commit da08dfd941
4 changed files with 85 additions and 55 deletions

View File

@ -3,10 +3,14 @@ unit gdt;
interface interface
uses uses
util; util,
types;
procedure create(base : dword; limit : dword; flags : byte);
procedure init();
type type
TSegementDescriptor = bitpacked record TSegmentDescriptor = bitpacked record
limit_low : WORD; limit_low : WORD;
base_low : WORD; base_low : WORD;
access : Byte; access : Byte;
@ -15,44 +19,24 @@ type
end; end;
PSegmentDescriptor = ^TSegmentDescriptor; PSegmentDescriptor = ^TSegmentDescriptor;
var
GDTarr : array of TSegementDescriptor;
GDTptr : PSegmentDescriptor;
GDT_length : integer = 0;
procedure init();
procedure create(base : dword; limit : dword; flags : byte);
implementation implementation
procedure init();
var var
data_addr : dword; GDTarr : array [0..5] of TSegmentDescriptor;
begin GDTptr : PSegmentDescriptor;
GDTptr := @GDTarr[0]; GDT_length : integer = 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;
procedure create(base : dword; limit : dword; flags : byte); procedure create(base : dword; limit : dword; flags : byte);
var var
descriptor : array[0..8] of Byte; descriptor : array[0..8] of Byte;
descriptor_ptr : ^Byte = @descriptor[0]; descriptor_ptr : PByte;
s_descriptor : TSegementDescriptor;
s_descriptor_ptr : ^TSegementDescriptor = @s_descriptor; s_descriptor : TSegmentDescriptor;
s_descriptor_ptr : PSegmentDescriptor;
begin begin
descriptor_ptr:= @descriptor[0];
s_descriptor_ptr:= @s_descriptor;
if limit <= 65536 then begin if limit <= 65536 then begin
descriptor[6] := $40 descriptor[6] := $40
end else begin end else begin
@ -81,18 +65,37 @@ begin
MOV s_descriptor_ptr, EAX MOV s_descriptor_ptr, EAX
end; end;
descriptor_ptr = @descriptor[4]; descriptor_ptr:= @descriptor[4];
asm asm
MOV EAX, descriptor_ptr MOV EAX, descriptor_ptr
MOV EBX, s_descriptor_ptr MOV EBX, s_descriptor_ptr
ADD EBX, 1 ADD EBX, 1
MOV (EBX), EAX MOV [EBX], EAX
end; end;
GDTarr[GDT_length] := s_descriptor; GDTarr[GDT_length] := s_descriptor;
GDT_length := GDT_length + 1; GDT_length := GDT_length + 1;
end; 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. end.

View File

@ -5,6 +5,7 @@ interface
uses uses
multiboot, multiboot,
util, util,
gdt,
console, console,
bios_data_area, bios_data_area,
keyboard; keyboard;
@ -18,6 +19,7 @@ var
c : byte; c : byte;
begin begin
gdt.init();
console.init(); console.init();
console.writestringln('Booting Asuro...'); console.writestringln('Booting Asuro...');
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin

25
src/types.pas Normal file
View 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.

View File

@ -32,7 +32,7 @@ begin
switchendian:= (lo(b) SHL 4) OR hi(b); switchendian:= (lo(b) SHL 4) OR hi(b);
end; end;
procedure outl(port : word; val : longword); [public, alias: 'outl']; procedure outl(port : word; val : longword); [public, alias: 'util_outl'];
begin begin
asm asm
PUSH EAX PUSH EAX
@ -45,7 +45,7 @@ begin
end; end;
end; end;
procedure outw(port : word; val : word); [public, alias: 'outw']; procedure outw(port : word; val : word); [public, alias: 'util_outw'];
begin begin
asm asm
PUSH EAX PUSH EAX
@ -58,7 +58,7 @@ begin
end; end;
end; end;
procedure outb(port : word; val : byte); [public, alias: 'outb']; procedure outb(port : word; val : byte); [public, alias: 'util_outb'];
begin begin
asm asm
PUSH EAX PUSH EAX
@ -71,7 +71,7 @@ begin
end; end;
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 begin
asm asm
cli cli
@ -79,7 +79,7 @@ begin
end; end;
end; end;
function inl(port : word) : dword; [public, alias: 'inl']; function inl(port : word) : dword; [public, alias: 'util_inl'];
begin begin
asm asm
PUSH EAX PUSH EAX
@ -92,7 +92,7 @@ begin
end; end;
end; end;
function inw(port : word) : word; [public, alias: 'inw']; function inw(port : word) : word; [public, alias: 'util_inw'];
begin begin
asm asm
PUSH EAX PUSH EAX
@ -105,7 +105,7 @@ begin
end; end;
end; end;
function inb(port : word) : byte; [public, alias: 'inb']; function inb(port : word) : byte; [public, alias: 'util_inb'];
begin begin
asm asm
PUSH EAX PUSH EAX