Bochs - different behavior on a start versus restart

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

Bochs - different behavior on a start versus restart

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bochs - different behavior on a start versus restart

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Re: Bochs - different behavior on a start versus restart

Post 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
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Bochs - different behavior on a start versus restart

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bochs - different behavior on a start versus restart

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Bochs - different behavior on a start versus restart

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply