Failing at loading the GDT
Posted: Mon Jun 13, 2005 6:42 pm
Hi, nice to meet all you guys
I'm working with Bran's Kernel Development Tutorial from osdever.net, and I've run into a fairly major snag. I've followed everything there, up til loading the gdt, and haven't gone any further, because loading the gdt just won't work.
I'm using linux - fedora core 3, gcc, nasm, ld, syslinux as the bootloader, and I'm using a floppy image file with bochs.
Here's the gdt loading part of the assembly file for those of you who don't know the tutorial:
Here is all my files, in case you wanted a look. http://www.geocities.com/naim_kingston/os.zip (run 'make', then 'make createimage', then 'make kernelimage' to compile, create a floppy image, copy the files to the floppy image)
In my main() function, I init_video() for writing text to the screen, then I call gdt_install(), and then I print out a message from the main, "Hello World".
The fairly confusing part is that whenever I run it, it continually resets. I understand that this probably means I'm not giving the gdt proper values. So, I'll start up bochs and run it, and I'll see the basic system info come up on the screen and then I'll get the 3 debug messages from the gdt_install() function and I'll also see the "Hello World" from main() pop up with the debug messages, and then it will reset and I'll see all of that again.
The very confusing part is that in the portion of the start.asm file I gave, there is a commented out infinite looop, and if I uncomment that, it will pause and not go any futher. So, I'll see the 3 debug messages and no resetting. But, if I move the loop to the line under "lgdt [gp]", it will start resetting again, but, this time, without the "Hello World" message from main().
So, I pretty much have no idea what's going on.
I'm working with Bran's Kernel Development Tutorial from osdever.net, and I've run into a fairly major snag. I've followed everything there, up til loading the gdt, and haven't gone any further, because loading the gdt just won't work.
I'm using linux - fedora core 3, gcc, nasm, ld, syslinux as the bootloader, and I'm using a floppy image file with bochs.
Here's the gdt loading part of the assembly file for those of you who don't know the tutorial:
Code: Select all
; gdt loading part of start.asm
global gdt_flush ; Allows the C code to link to this
extern gp ; Says that '_gp' is in another file
gdt_flush:
;looop:
; jmp looop
lgdt [gp] ; Load the GDT with our '_gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
In my main() function, I init_video() for writing text to the screen, then I call gdt_install(), and then I print out a message from the main, "Hello World".
The fairly confusing part is that whenever I run it, it continually resets. I understand that this probably means I'm not giving the gdt proper values. So, I'll start up bochs and run it, and I'll see the basic system info come up on the screen and then I'll get the 3 debug messages from the gdt_install() function and I'll also see the "Hello World" from main() pop up with the debug messages, and then it will reset and I'll see all of that again.
The very confusing part is that in the portion of the start.asm file I gave, there is a commented out infinite looop, and if I uncomment that, it will pause and not go any futher. So, I'll see the 3 debug messages and no resetting. But, if I move the loop to the line under "lgdt [gp]", it will start resetting again, but, this time, without the "Hello World" message from main().
So, I pretty much have no idea what's going on.