Invalid opcode(again)

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
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Invalid opcode(again)

Post 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.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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
Author of COBOS
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

i tried asm volatile and that didn't work and this code is in ring 0.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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).
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

how exactly would i do that?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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)
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post 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
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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
Author of COBOS
Post Reply