This topic is 4726 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]

• 22
• 10
• 19
• 15
• 14
• ### Similar Content

• I've got a bug with my brick breaker style game. The bricks move down one line at a time ever 1.5 seconds. What appears to be happening is occasionally the ball will be just about to hit the brick when the brick moves down a line, and now the ball is behind it. I'm not sure how to fix this. I have two ideas but I'm not sure of implementation. 1 solution would be to check where they were and where they are going to be before rendering the frame. Then if they crossed paths, then register the brick as hit. Solution 2 would be change how the bricks move. I could maybe slide them down line by line, instead of a jump down. I'm not sure of this will fix the issue or not. Any ideas?
• By Pixeye
I wrote an extension for unity inspector that allows to group/fold variables.
Available on github  , cheers!

• I'M interested in programming tools (For animation, UI, etc). Can anyone suggest me the resources where I can start learning or which technologies I need achive it.

Thanks,
Rakshit
• By Paszq
Group photo of some of the characters and creatures currently living in Arpago
• By Paszq
A bunch of chests full of sweet loot :)