Page 1 of 1
Invalid opcode(again)
Posted: Thu Jul 12, 2007 12:13 am
by Pyrofan1
right, i figured out that this code is causing the exception
Code: Select all
void outportb(unsigned short port,unsigned char val)
{
asm("outb %0,%1"::"a"(val),"Nd"(port));
}
but i can't figure out what's wrong with this code.
Posted: Thu Jul 12, 2007 1:03 am
by os64dev
use asm volatile anyway and there is nothing wrong with the code. however at what ring is it executed? If it's executed on ring 0 i don't understand the problem on any other ring you should have enable the access to io via the io_bitmap of the tss or via the flags. If you didn't do that it would generate an exception. Its all in the manuals
Posted: Thu Jul 12, 2007 1:17 am
by Pyrofan1
i tried asm volatile and that didn't work and this code is in ring 0.
Posted: Thu Jul 12, 2007 1:27 am
by JamesM
Have you checked the value of EIP when the program crashes and cross-referenced that with an objdump of your kernel? It may for some reason not be calling on an instruction boundary (some kind of stack craziness maybe).
Posted: Thu Jul 12, 2007 1:38 am
by Pyrofan1
how exactly would i do that?
Posted: Thu Jul 12, 2007 2:17 am
by JamesM
Are you running it in bochs? If so check bochsout.txt, it should dump the register state when it encounters an illegal instruction.
I can't actually remember whether illegal instruction triggers an exception or an immediate restart. If it triggers an exception you can inspect the EIP field the processor pushes to the stack. (I don't think it does cause an exception though... at work atm so can't check)
Posted: Thu Jul 12, 2007 2:43 am
by Pyrofan1
Are you running it in bochs?
i'm not
I can't actually remember whether illegal instruction triggers an exception
it does that's what the Invalid opcode exception is for
Posted: Thu Jul 12, 2007 4:32 am
by os64dev
the code is ok as it i the same as mine. so it is something else. I strongly suggest that you learn to use bochs because the internal debugger is very handy as in situation like this.
PS. Regarding your signature, I am not over-educated. Funny though