Hey! I'm a long time stalker here, working on my own OS.
Anyway, I have an consistent issue that happens on all our pc's in my house (6 pc's), on every after bootloader jumps to my kernel, i get an Invalid Opcode Exception. However my kernel works just fine in VMWare Player, Bochs, VirtualPC.
I've read several topics here by searching that this might be caused by me having Optimization set to /Ox in visual studio. (Kernel is in VC++).
Now here is my question, if this might be the case, how important is it to actually have the max optimization included? I'm thinking about turning it completely off to avoid any surprises. But i would also be willingly to debug out which instruction it is that causes this if it is smart to enable max Optimization level.
Thanks, Philip.
Invalid Opcode
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Invalid Opcode
Did you figure out which instruction is causing the invalid opcode exception? Which CPUs do you use for testing?
I don't know much about VC++, so I cannot say much about its optimization. I use GCC with optimization level -O2, and there is a compiler switch which allows choosing a specific target CPU. For example, -march=pentium will generate only instructions that a Pentium CPU knows about. I don't know whether VC++ has a similar option, but this is what I would try to figure out.
I don't know much about VC++, so I cannot say much about its optimization. I use GCC with optimization level -O2, and there is a compiler switch which allows choosing a specific target CPU. For example, -march=pentium will generate only instructions that a Pentium CPU knows about. I don't know whether VC++ has a similar option, but this is what I would try to figure out.
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Invalid Opcode
Since it is failing on real hardware but not emulators, it's more likely that the problem is being caused by improperly initialized memory. Emulators tend to zero out all of their memory, which means that uninitialized memory is set to zero and may behave properly when you really should get undefined behavior; on real hardware, the contents of memory at boot are pretty much random, so uninitialized memory will likely cause problems.
Also, if your code is failing due to optimizations, you should always try to fix it. Optimizations never create bugs, they only reveal existing ones.
Also, if your code is failing due to optimizations, you should always try to fix it. Optimizations never create bugs, they only reveal existing ones.
Re: Invalid Opcode
Thanks for the suggestions so far guys.
@XenOS
I won't be able to do more debugging till i get home in some hours, but it obviously happens after setting up exceptions
And I actually know Visual Studio has an option for target cpu. All the CPU's I've tested on are Intel.
@NickJohnson
You may be correct here, it could be memory initialization that is incorrect. I'll have to look into that once i get home.
And that answer was in the alley I were looking for (about optimizations). I assume then it's smarter to have optimizations enabled than disabling them and just working around it.
I'll still appreciate more comments to this!
Thanks, Philip.
@XenOS
I won't be able to do more debugging till i get home in some hours, but it obviously happens after setting up exceptions
And I actually know Visual Studio has an option for target cpu. All the CPU's I've tested on are Intel.
@NickJohnson
You may be correct here, it could be memory initialization that is incorrect. I'll have to look into that once i get home.
And that answer was in the alley I were looking for (about optimizations). I assume then it's smarter to have optimizations enabled than disabling them and just working around it.
I'll still appreciate more comments to this!
Thanks, Philip.
Re: Invalid Opcode
Haha so found out what the problem was. Really stupid mistake.
Was using a signed int when looping through available pages instead of an unsigned int.
I have no idea how the emulators allowed that =/
Thanks for suggestions again!
Was using a signed int when looping through available pages instead of an unsigned int.
I have no idea how the emulators allowed that =/
Thanks for suggestions again!