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
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
util;
|
util,
|
||||||
|
types;
|
||||||
|
|
||||||
type
|
procedure create(base : dword; limit : dword; flags : byte);
|
||||||
TSegementDescriptor = bitpacked record
|
procedure init();
|
||||||
|
|
||||||
|
type
|
||||||
|
TSegmentDescriptor = bitpacked record
|
||||||
limit_low : WORD;
|
limit_low : WORD;
|
||||||
base_low : WORD;
|
base_low : WORD;
|
||||||
access : Byte;
|
access : Byte;
|
||||||
@ -15,55 +19,35 @@ 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
|
GDTarr : array [0..5] of TSegmentDescriptor;
|
||||||
data_addr : dword;
|
GDTptr : PSegmentDescriptor;
|
||||||
begin
|
GDT_length : integer = 0;
|
||||||
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;
|
|
||||||
|
|
||||||
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
|
||||||
if limit <= 65536 then begin
|
descriptor_ptr:= @descriptor[0];
|
||||||
descriptor[6] := $40
|
s_descriptor_ptr:= @s_descriptor;
|
||||||
end else begin
|
if limit <= 65536 then begin
|
||||||
if (limit and $FFF) <> $FFF then begin
|
descriptor[6] := $40
|
||||||
limit := (limit SHR 12) -1
|
end else begin
|
||||||
end else begin
|
if (limit and $FFF) <> $FFF then begin
|
||||||
limit := limit SHR 12;
|
limit := (limit SHR 12) -1
|
||||||
end;
|
end else begin
|
||||||
|
limit := limit SHR 12;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
descriptor[6] := $C0;
|
descriptor[6] := $C0;
|
||||||
|
|
||||||
descriptor[0] := limit and $FF;
|
descriptor[0] := limit and $FF;
|
||||||
descriptor[1] := (limit shr 8) and $FF;
|
descriptor[1] := (limit shr 8) and $FF;
|
||||||
@ -77,22 +61,41 @@ begin
|
|||||||
descriptor[5] := flags;
|
descriptor[5] := flags;
|
||||||
|
|
||||||
asm
|
asm
|
||||||
MOV EAX, descriptor_ptr
|
MOV EAX, descriptor_ptr
|
||||||
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.
|
||||||
|
@ -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
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);
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user