1
Lowlevel-Coding / Re: GDT über Inline-Assembler
« am: 07. November 2008, 11:23 »
Für alle Pascal-Interessierten hier jetzt mal der funktionierende Code meiner Unit:
Code: [Auswählen]
unit moloGDT;
interface
type
gdt_entry = packed record
limit_low : Word;
base_low : Word;
base_middle : Byte;
access : Byte;
granularity : Byte;
base_high : Byte;
end;
gdt_ptr = packed record
limit : Word;
base : LongWord;
end;
var gdt : array[0..2] of gdt_entry;
gp : gdt_ptr;
procedure gdt_set_gate(num:LongInt; base,limit:LongWord; access,gran:Byte);
procedure gdt_install;
implementation
procedure gdt_flush; Assembler; nostackframe;
label
flush;
asm
lgdt [gp]
mov ax,$10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
jmp $08,flush // don't know the correct syntax in FPC inline assembler, but it works!
flush:
end;
procedure gdt_set_gate(num:LongInt; base,limit:LongWord; access,gran:Byte);
begin
gdt[num].base_low := (base AND $FFFF);
gdt[num].base_middle := (base SHR 16) AND $FF;
gdt[num].base_high := (base SHR 24) AND $FF;
gdt[num].limit_low := (limit AND $FFFF);
gdt[num].granularity := (limit SHR 16) AND $0F;
gdt[num].granularity := gdt[num].granularity OR (gran AND $F0);
gdt[num].access := access;
end;
procedure gdt_install;[public , alias: 'gdt_install'];
begin
gdt_set_gate(0,0,0,0,0);
gdt_set_gate(1,0,$FFFFFFFF,$9A,$CF);
gdt_set_gate(2,0,$FFFFFFFF,$92,$CF);
gp.limit := (sizeOf(gdt))-1;
gp.base := LongWord(@gdt);
gdt_flush;
end;
end.