Page 1 of 1

Bochs - different behavior on a start versus restart

Posted: Tue Jan 27, 2009 6:10 pm
by justin
I didn't believe it at first, but I've tested my code numerous times now and I am getting different results when I run it the first time versus when I press the restart button in bochs. I thought that it should behave the same since it is starting fresh from a CPU reset in both circumstances. Consistently, though, it produces one result on a start and a second different result on a restart.

Is there something that I am missing here?

Re: Bochs - different behavior on a start versus restart

Posted: Tue Jan 27, 2009 6:13 pm
by Combuster
If you press restart, it will do that: reset the computer. That also means that parts of the state are left unchanged like in a real machine.

Re: Bochs - different behavior on a start versus restart

Posted: Tue Jan 27, 2009 6:23 pm
by gzaloprgm
Memory may be conserved after a reset. My old kernel crashed after you reseted (only happened in bochs afaik, in qemu worked ok)

Just remember to initialize your variables: Dont asumme int n; n may or may not be 0 (caused by some default memset done by bochs)

If you're using your own bootloader and your kernel is in a plain binary format remember to include the .bss (zero initialized data) into the file (may add some size to your .bin) or memset from the start to the end of bss section.

Cheers,
Gonzalo

Re: Bochs - different behavior on a start versus restart

Posted: Tue Jan 27, 2009 11:02 pm
by Love4Boobies
As far as I can see it (correct me if I'm wrong), the reset button actually sends a NMI to the CPU and this will load its initial state. In doing so, it will also restart the BIOS intialization code (because of CS:EIP and such). So it's really up to the BIOS mainly - it's not the memory controller itself that automatically that clears up the memory on reset, it's how the BIOS decides to use that controller.

You can probably still count on a few things like the PIT being set to fire up 18.2 times every second, the IVT being back where it's supposed to (in case it was trashed), the MBR being reloaded at 0000:7C00H, MP systems behaving like there was only one CPU, etc.

Re: Bochs - different behavior on a start versus restart

Posted: Wed Jan 28, 2009 2:35 am
by Combuster
NMI is an interrupt - The OS can handle that whatever way they want. Therefore it can't be used for the reset switch. Instead, the reset signal is asserted, which makes the processor restart. But not all the other parts.

Re: Bochs - different behavior on a start versus restart

Posted: Wed Jan 28, 2009 2:55 am
by Love4Boobies
Sorry about that, then. Anyway, that's what I mean about restarting the CPU only. But the way the environment is set up is mainly up to the PC BIOS.