You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
%macro HALT 0 |
|
%%h: |
|
cli |
|
hlt |
|
jmp %%h |
|
%endmacro |
|
|
|
%macro CRLF 0 |
|
push ax |
|
mov ax, 0xe00|13 |
|
int 0x10 |
|
mov al, 10 |
|
int 0x10 |
|
pop ax |
|
%endmacro |
|
|
|
|
|
; GDT Stuff |
|
%define Data 0000b |
|
%define DataMutable 0010b |
|
%define DataShrink 0100b |
|
%define DataShrinkMutable 0110b |
|
%define Code 1000b |
|
%define CodeRead 1010b |
|
%define CodeOnlyOwnPriv 1100b |
|
%define CodeOnlyOwnPrivRead 1110b |
|
|
|
%macro GDT_NULL_ENTRY 1 ; address |
|
%assign address %1 |
|
lea di, [address] |
|
xor ax, ax |
|
mov cx, 4 |
|
rep stosw |
|
%endmacro |
|
|
|
%macro GDT_ENTRY 6 ; address base limit type privilege bits32 |
|
%assign address %1 |
|
|
|
%assign base %2 |
|
%assign limit %3 |
|
|
|
%assign type (%4 & 0xf) |
|
%assign reserved (1<<4) |
|
%assign privilege ((%5 & 0x3) << 5) |
|
%assign present (1<<7) |
|
%assign access (present | privilege | reserved | type) |
|
|
|
%assign bits32 ((%6 & 1) << 2) |
|
%assign granularity (1<<3) |
|
%assign flags (granularity | bits32) |
|
|
|
%assign limit_0_15 (limit & 0xffff) |
|
%assign limit_16_19 ((limit >> 16) & 0xf) |
|
%assign base_0_15 (base & 0xffff) |
|
%assign base_16_23 ((base >> 16) & 0xff) |
|
%assign base_24_31 ((base >> 24) & 0xff) |
|
|
|
mov WORD [address + 0], limit_0_15 |
|
mov WORD [address + 2], base_0_15 |
|
mov WORD [address + 4], base_16_23 | (access << 8) |
|
mov WORD [address + 6], limit_16_19 | (flags << 4) | (base_24_31 << 8) |
|
%endmacro |
|
|
|
%define GDT_Selector(DescriptorIndex, TableIndicator, RequestorPrivLevel) ((DescriptorIndex << 3) | ((TableIndicator & 1) << 2) | (RequestorPrivLevel & 0x3)) |