This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Share on other sites
Have you tried using the halt instruction for debugging purposes? Just put a hlt somewhere in the code and move it down until the OS crashes. Now you know which line the crashes are occuring.

When I tried writing my own OS I also had major troubles getting the GDT and the code around it right. It's easy to forget about something.

[Edited by - doho on June 12, 2005 11:09:09 PM]

Share on other sites
What if the 'hlt' instruction isn't working?

I've tried putting the halt instruction at every single line inside the gdt_flush function (the one in the start.asm assembly file), and I got nothing. I assume that the instruction is just supposed to stop everthing, right? I is it supposed to reset the system as well? Because if it's not, then it didn't work.

Share on other sites
Yea it's supposed to stop/halt the system. If a hlt in the beginning of gdt_flush doesn't halt the system it just means that the crash occurs before the gdt_flush. If this is the case, put it in the beginning of the startup code and move it down until it doesn't halt anymore.

Share on other sites
But, here's the strange thing. It looks like the crash happens after the gdt_flush function has been exited.

void main(){        init_video();   // init screen for output        gdt_install();  // init the gdt for memory bounds        //idt_install();        // install the interrupt descriptor table        puts("Hello World!\n");        //i = 10 / 0;        //putch(i);        for (;;);}

I've put init_video() before the gdt_install(), so I can output some error messages.

void gdt_install(){        // setup the GDT pointer and limit        gp.limit = (sizeof(struct gdt_entry) * 3) - 1;        gp.base = (unsigned int)&gdt;        // our NULL descriptor        gdt_set_gate(0,0,0,0,0);        puts("Set NULL gate");        /* The second entry is our code segment. The base address         * is 0, the limit is 4Gbytes, it uses 4Kbyte ganularity,         * uses 32-bit opcodes, and is a Code Segment descriptor.         * Please check the table above in the tutorial in order         * to see exactly what each value means.         */        gdt_set_gate(1, 0, 0xffffffff, 0x9a, 0xcf);        puts("Set gate 1");        /* The third entry is our Data Segment. It's EXACTLY the         * same as our code segment, but the descriptor type in         * this entry's access byte says its a Data Segment         */        gdt_set_gate(2, 0, 0xffffffff, 0x92, 0xcf);        puts("Set gate 2");        // flush out the old GDT and install the new changes         gdt_flush();}

All the debug messages show up, and so does the "Hello World" from the main function, which happens after the gdt_install() function is returned from.

Share on other sites
Well it sounds like you have a wierd problem then. The for(;;) loop should not reset the computer.

Just use hlt as I said to find out which line is causing the crash and then try to think of a possible reason why the crash is occuring.

Share on other sites
The hlt instruction is resetting the os!!

void main(){        init_video();   // init screen for output        gdt_install();  // init the gdt for memory bounds        //idt_install();        // install the interrupt descriptor table        //__asm__ ("hlt");        puts("Hello World!\n");        for (;;);}

As is, when it is run, everything shows up: the three debug messages in the gdt_install() function and the "Hello World". But, if I uncomment the assembly line in the main function above, only the gdt_install() messages show up.

It looks like the hlt command is resetting the os.

Anyone know why?

Share on other sites
Is it beeing reseted or halted? There is huge difference.

Share on other sites
All I know is that when the os hits the 'hlt' line, the whole os is booted up again.

Here's what happens:

1. I compile, link, and copy the kernel to the floppy image.
2. I run bochs and run the simulation.
3. The os goes through all the general start up system info.
4. It prints out the 3 debug messages from the gdt_install() function.
5. It prints out the "Hello World" message from the main() function.
6. The screen goes blank.
7. Goes back to 3.

And all of this happens fairly fast.

Share on other sites
Try setting a for(;;); in the beginning of the main and then move it down. Then you know if the setup_gdt is making the machine restart when more instructions are beeing executed after its execution. Maybe some interrupt is occuring while your GDT isn't correctly initialized and that this is causing a crash as soon as you return from setup_gdt or maybe it crashed inside setup_gdt. Have you tried putting hlt inside setup_gdt too? if you have weird problems with halt you could just do for(;;); as you are doing now in your main.

[Edited by - doho on June 13, 2005 6:52:21 AM]

1. 1
2. 2
frob
14
3. 3
4. 4
5. 5
Rutin
12

• 12
• 12
• 57
• 14
• 15
• Forum Statistics

• Total Topics
632115
• Total Posts
3004189

×