Machine resets itself after loading new GDT
Posted: Thu Sep 15, 2011 1:07 pm
I'm trying a few things with multiboot and I have built a small example that as far as I understand should work. Once the code is called at the start label I set the stack and then load a new GDT. After the GDT is loaded I do a far jump and update the rest of the segment registers. However, at the point of the far jump the virtual machine (qemu 0.14.1) resets and I can't figure out why. Does anyone have an idea on why this happens?
Code: Select all
.global start
.set ALIGN, 1 << 0
.set MEM_INFO, 1 << 1
.set KLUDGE, 1 << 16
.set MAGIC, 0x1BADB002
.set FLAGS, ALIGN | MEM_INFO | KLUDGE
.set CHECKSUM, -(MAGIC + FLAGS)
.section .text
.code32
.align 0x4
multiboot_header:
.long MAGIC
.long FLAGS
.long CHECKSUM
.long multiboot_header
.long text
.long data_end
.long kernel_end
.long start
.set STACKSIZE, 0x4000
.comm stack, STACKSIZE, 32
start:
mov $(stack + STACKSIZE), %esp
lgdt (gdtr)
ljmp $0x8, $1f
1:
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
hang: hlt
jmp hang
.align 0x10
gdt:
.quad 0x0
.quad 0x0000ffff00cf9a00
.quad 0x0000ffff00cf9200
gdtr:
.word .-gdt-1
.quad gdt