Page 1 of 1

Mtdbg and in out instructions.

Posted: Mon Feb 17, 2014 8:02 pm
by Mohsen47
If my program contains in out instructions and I want debug it using kolibri debugger Mtdbg, I get ??? at memory locations where I have thses instructions and when exection reaches these instructions I get this message Debugged Program Caused an exception 0D.Suspended.
Why is this heppening?
Could any body help?

Re: Mtdbg and in out instructions.

Posted: Mon Feb 17, 2014 10:04 pm
by Mario_r4
If you watch the source code debugger, a message is issued in the following cases:

Code: Select all

    ; int3 command generates exception 0D, #GP
or

Code: Select all

    ; check for 0xCC byte at eip

Re: Mtdbg and in out instructions.

Posted: Mon Feb 17, 2014 10:35 pm
by CleverMouse
in and out instructions are privileged. User-mode code is not allowed to use them, they are intended for the kernel and drivers.

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 9:23 am
by Mohsen47
This means I cannot debug my code if it contains these instructions?There is no way to do that?

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 10:03 am
by art_zh
Mohsen47
Your application can request port i/o permissions with fn 46.
Alternatively, you can easily modify your Kernel to enable any in/out command in the userspace.

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 11:38 am
by Mohsen47
art_zh
Thanks for the tip it worked well, but there is a little problem I tried to reserve the io port range for pci from 0xcf8 to 0xcfc and I was able to write a double word to pci config register but when I try to read a double word from pci data register I get the same exception, I am only able to read a word from data register, why is this?

Posted: Tue Feb 18, 2014 1:16 pm
by yogev_ezra
If you attach your full source code, it would be much easier to help you.

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 2:57 pm
by art_zh
Mohsen47
PCI ports are restricted system resources.
Use fn 62 to access PCI configspace
(in Kolibri-A you will also enjoy MMIO access to the Extended PCIe configspace, but it only runs on AMD Fusion).

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 5:22 pm
by Mohsen47
Thanks for your interest guys.
This is my simple code:

Code: Select all

mov eax,46
mov ebx,0
mov ecx,0xcf8
mov edx,0xcfd
int 0x40
cmp eax,1
je exit
mov eax,0x80001800 ;get the vendor and device id for device number 3 in pci bus number 0 which is my network interface.
mov dx,0xcf8
out dx,eax
mov dx,0xcfc
in dx,eax
exit:
This code doesn't work and gives me the same exception at

Code: Select all

 in dx,eax 
instruction but if I replace it with

Code: Select all

 in ax,dx 
it works and allows me to read the vendor id only in the lower two bytes of eax but I cannot get the device id.

I don't want to use fn 62 to access PCI configspace because I want to move this code to my OS so I want to accomplish this only using assembly instruction that are provided in every assembler, I am using kolbri because it is simple and allows me to debug the assembly code very easily.

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 5:31 pm
by Mario_r4
Mohsen47 wrote:I don't want to use fn 62 to access PCI configspace because I want to move this code to my OS so I want to accomplish this only using assembly instruction that are provided in every assembler, I am using kolbri because it is simple and allows me to debug the assembly code very easily.
Probably it will help to you:
core/taskman.inc

Code: Select all

mov     [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF
Change EFL_IOPL1 to EFL_IOPL3 and compile the kernel.

Re: Mtdbg and in out instructions.

Posted: Tue Feb 18, 2014 7:32 pm
by Mohsen47
Thanks Mario_r4.
Actually I don't have all the source code on my computer but when I have it I will try what you said, really thanks a lot.