Code: Select all
%include "grub.inc" ; needed for the multiboot header
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file
gdtr dw 0 ; for limit storage
dd 0 ; for base storage
setGdt:
mov eax,[esp+4]
mov [gdtr+2],eax
mov ax,[esp+8]
mov [gdtr],ax
lgdt [gdtr]
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the IDT with it's descriptors
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start_of_idt:
;interrupt 0
dw 0x0000
dw 0x10
dw 0x8E00
dw 0x20
;interrupt 1
dw 0x0000
dw 0x10
dw 0x8E00
dw 0x20
;interrupt 2, intel reserved, we set the 'present' bit to 0 on this one
dw 0x0000
dw 0x10
dw 0xE00
dw 0x20
;interrupts 3-14 now, since we are making the descriptors
;identical, we are going to loop to get them all(12 total)
%rep 0xC
dw 0x0000
dw 0x10
dw 0x8E00
dw 0x20
%endrep
;interrupt 15, intel reserved, we set the 'present' bit to 0 on this one
dw 0x0000
dw 0x10
dw 0xE00
dw 0x20
;interrupt 16
dw 0x0000
dw 0x10
dw 0x8E00
dw 0x20
end_of_idt:
idt_pointer:
dw end_of_idt - start_of_idt - 1
dd start_of_idt
start:
; stop using bootloader GDT, and load new GDT
lgdt [gdtr]
lidt [idt_pointer]
push es
pop ds
push ds
STI
xor eax,eax
in al,0x60
call _k_main
jmp $ ; crash
hlt ; halt the CPU
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Multiboot header for GRUB bootloader. This must be in the first 8K
; of the kernel file. We use the aout kludge so it works with ELF,
; DJGPP COFF, Win32 PE, or other formats.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; these are in the linker script file
EXTERN code, bss, end
ALIGN 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
; aout kludge. These must be PHYSICAL addresses
dd mboot
dd code
dd bss
dd end
dd start