Code: Select all
[BITS 32]
[GLOBAL start]
[EXTERN _osmain]
;we are currently @ 1MB physical
start:
lgdt [gdtr] ;load new GDT (after bootsector did its thing)
lidt [idtr] ;load IDT
%macro DEFINT 2
push ax
mov ax, _int32
and ax, 0xFFFF
mov [idt + (32 * 8)],ax
mov ax, _int32
shr ax, 16
mov [idt + (32 * 8) + 6], ax
pop ax
%endmacro
DEFINT 32, _int32
call _osmain ;hop into C
hlt ;if C ever returns to this...halt the CPU, something's fucked
[EXTERN _testint]
[GLOBAL _int32]
_int32:
pusha
push ds
push es
push fs
push gs
mov eax,0x10 ; Data segment
mov ds,eax
mov es,eax
cld
call _testint
pop gs
pop fs
pop es
pop ds
popa
iret
gdt:
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
dd 0 ;this is the same as above, still just 8 bytes of blanks
dd 0
DATASEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
CODESEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 9Ah ; present,ring 0,code,non-conforming,readable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
gdtend:
gdtr:
dw gdtend - gdt - 1
dd gdt
idt:
%rep 256
dw 0 ;0
dw DATASEL ;2
dw 0x8E00 ;4
dw 0 ;6
%endrep
endidt:
idtr:
dw endidt - idt - 1
dd idt