FUUUUUUUUUUUUUUUUUUUUUUU

git-svn-id: https://spexeah.com:8443/svn/Asuro@176 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
kieron 2017-05-22 00:49:38 +00:00
parent f1dc0516df
commit 5a2004b486
15 changed files with 104 additions and 20 deletions

BIN
Asuro.iso

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -15,7 +15,7 @@ uses
console;
type
TGDT_Entry = bitpacked record
TGDT_Entry = packed record
limit_low : uint16;
base_low : uint16;
base_middle : uint8;
@ -25,17 +25,19 @@ type
end;
PGDT_Entry = ^TGDT_Entry;
TGDT_Pointer = bitpacked record
TGDT_Pointer = packed record
limit : uint16;
base : uint32;
end;
var
gdt_entries : array[0..4] of TGDT_Entry;
gdt_entries : array[0..6] of TGDT_Entry;
gdt_pointer : TGDT_Pointer;
procedure init();
procedure set_gate(Gate_Number : uint32; Base : uint32; Limit : uint32; Access : uint8; Granularity : uint8);
procedure flush;
procedure reload;
implementation
@ -54,8 +56,35 @@ asm
@@flush: // It's just data, honest gov'.
end;
procedure set_gate(Gate_Number : uint32; Base : uint32; Limit : uint32; Access : uint8; Granularity : uint8);
procedure flush;
begin
console.writestringln('GDT: FLUSH.');
flush_gdt(uint32(@gdt_pointer));
end;
procedure reload_gdt(gdt_ptr : uint32); assembler;
asm
MOV EAX, gdt_ptr
LGDT [EAX]
end;
procedure reload;
begin
reload_gdt(uint32(@gdt_pointer));
end;
procedure set_gate(Gate_Number : uint32; Base : uint32; Limit : uint32; Access : uint8; Granularity : uint8);
var
lLimit : uint32;
begin
lLimit:= (Gate_Number + 1) * 8;
lLimit:= lLimit - 1;
writestring('lLimit: ');
writewordln(lLimit);
if lLimit > gdt_pointer.limit then begin
gdt_pointer.limit:= lLimit;
end;
gdt_entries[Gate_Number].base_low := (Base AND $FFFF);
gdt_entries[Gate_Number].base_middle := (Base SHR 16) AND $FF;
gdt_entries[Gate_Number].base_high := (Base SHR 24) AND $FF;
@ -70,15 +99,14 @@ end;
procedure init();
begin
console.writestringln('GDT: INIT START.');
gdt_pointer.limit := (sizeof(TGDT_Entry) * 5) - 1;
gdt_pointer.limit:= 0;
gdt_pointer.base := uint32(@gdt_entries);
set_gate($00, $00, $00, $00, $00); //OFFSET: 0
set_gate($01, $00, $FFFFFFFF, $9A, $CF); //OFFSET: 8
set_gate($02, $00, $FFFFFFFF, $92, $CF); //OFFSET: 16
set_gate($03, $00, $FFFFFFFF, $FA, $CF); //OFFSET: 24
set_gate($04, $00, $FFFFFFFF, $F2, $CF); //OFFSET: 32
console.writestringln('GDT: FLUSH.');
flush_gdt(uint32(@gdt_pointer));
flush;
console.writestringln('GDT: INIT END.');
end;

View File

@ -29,13 +29,20 @@ var
procedure Main(); interrupt;
var
i : integer;
ec : uint32;
begin
asm
MOV EAX, [ESP-4]
MOV ec, EAX
end;
CLI;
for i:=0 to MAX_HOOKS-1 do begin
if uint32(Hooks[i]) <> 0 then Hooks[i](void(13));
end;
console.writestringln('General Protection Fault.');
console.writestring('General Protection Fault. [');
console.writehex(ec);
console.writestringln(']');
util.halt_and_catch_fire;
end;

View File

@ -42,6 +42,7 @@ var
pint2 : puint32;
keyboard_layout : array [0..1] of TKeyInfo;
i : uint32;
cEIP : uint32;
begin
multibootinfo:= mbinfo;
@ -51,6 +52,10 @@ begin
console.writestringln('Booting Asuro...');
for i:=0 to 100000000 do begin
end;
if (multibootmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin
console.setdefaultattribute(console.combinecolors(Red, Black));
console.writestringln('Multiboot Compliant Boot-Loader Needed!');
@ -62,12 +67,13 @@ begin
idt.init();
isr.init();
irq.init();
tss.init();
pmemorymanager.init();
vmemorymanager.init();
lmemorymanager.init();
tss.init();
scheduler.init();
while true do begin end;
STI;

View File

@ -17,9 +17,9 @@ uses
console;
type
{
{TTaskStateSegment = packed record
Res1 : uint16;
IOPBOffset : uint16;
IOMap : uint16;
LDTR : uint16;
Res2 : uint16;
GS : uint16;
@ -54,7 +54,8 @@ type
ESP0 : uint32;
LINK : uint16;
Res12 : uint16;
}
end;
PTaskStateSegment = ^TTaskStateSegment;}
{
Res12 : uint16;
@ -143,6 +144,36 @@ type
end;
PTaskStateSegment = ^TTaskStateSegment;
{TTaskStateSegment = packed record
link : uint32;
esp0 : uint32;
ss0 : uint32;
esp1 : uint32;
ss1 : uint32;
esp2 : uint32;
ss2 : uint32;
cr3 : uint32;
eip : uint32;
eflags : uint32;
eax : uint32;
ecx : uint32;
edx : uint32;
ebx : uint32;
esp : uint32;
ebp : uint32;
esi : uint32;
edi : uint32;
es : uint32;
cs : uint32;
ss : uint32;
ds : uint32;
fs : uint32;
gs : uint32;
ldt : uint32;
iomap : uint32;
end;
PTaskStateSegment = ^TTaskStateSegment;}
var
TaskStateSegment : TTaskStateSegment;
ptrTaskStateSegment : PTaskStateSegment = @TaskStateSegment;
@ -154,15 +185,27 @@ implementation
procedure init;
var
cESP : uint32;
cCR3 : uint32;
begin
ptrTaskStateSegment^.ss0:= $10;
ptrTaskStateSegment^.iomap:= sizeof(TTaskStateSegment);
gdt.set_gate($05, uint32(ptrTaskStateSegment) - KERNEL_VIRTUAL_BASE, sizeof(TTaskStateSegment), $89, $40); //OFFSET: 40
console.writehexln(uint32(ptrTaskStateSegment));
ptrTaskStateSegment^.ss0:= $08;
ptrTaskStateSegment^.iomap:= sizeof(TTaskStateSegment)-1;
asm
MOV cESP, ESP
MOV EAX, CR3
MOV cCR3, EAX
end;
console.writewordln(sizeof(TTaskStateSegment));
ptrTaskStateSegment^.esp0:= cESP;
//ptrTaskStateSegment^.CR3:= cCR3;
console.writestring('OLD LIMIT: ');
console.writewordln(gdt.gdt_pointer.limit);
//gdt.set_gate($05, uint32(ptrTaskStateSegment)-KERNEL_VIRTUAL_BASE, sizeof(TTaskStateSegment)-1, $89, $40); //OFFSET: 40
console.writestring('NEW LIMIT: ');
console.writewordln(gdt.gdt_pointer.limit);
gdt.reload;
while true do begin end;
console.writestringln('A');
asm
mov AX, 40