after setting up IDT and GDT tables STI still crashes my VM!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
R2_
Member
Member
Posts: 50
Joined: Sat Dec 02, 2006 3:27 pm

after setting up IDT and GDT tables STI still crashes my VM!

Post by R2_ »

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
I've setup IDT and GDT tables and it still doesn't work.. when I call STI it crashes the VM. Is there anything im missing in my above code ? the VM works well with other OSs such as linux and unix
TheQuux
Member
Member
Posts: 73
Joined: Sun Oct 22, 2006 6:49 pm

Post by TheQuux »

1) sorry if I'm missing something, but where do you set SS? after the GDT, you still need to set ES, SS, DS, and CS.

Code: Select all

mov ax, [i]DSS[/i]
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp [i]CSS[/i]:.next
.next: mov esp, [i]top of stack[/i]
before any pushes or pops, but after the GDT is setup.

Note that DSS, CSS, and "top of stack" should be replaced by the appropriate values.

2) You need to have something in the GDT, otherwise you can't set the segment registers. Further, you need the segment registers to access the stack. This is where you get the CSS and DSS from.

3) an interrupt is (i believe) a far call, so it adjusts CS. This means that CS has to be in the GDT...[/code]
My project: Xenon
Post Reply