3

How can I perform restricted instructions such as IN and OUT from protected mode?

I've found out that It would require privilege level (CPL) high enough to perform the IO instruction. How can I run in kernel mode, have IO permission or anything other that may help me? - I would like to have direct access to hardware, without anything blocking me.

Thanks.

durron597
  • 31,968
  • 17
  • 99
  • 158
Barak
  • 133
  • 1
  • 6
  • Assuming you're running under a third-party operating system, you'll need to write a kernel-mode driver. How you do this is highly dependent on exactly what OS you have. Also, it might help to know exactly what you're trying to do with this. Do you want to program some kind of unusual hardware, or do you have another goal in mind? – bcat Aug 09 '10 at 22:58
  • 1
    Actually I am trying to access simple hardware such as the keyboard. You can take a look at this question: http://stackoverflow.com/questions/219120? that's basically what I'm trying to do - access IO devices using the IN and OUT, just as the first answer on the link given suggests. – Barak Aug 09 '10 at 23:23
  • 3
    I might add that I'm making a 16bit assembly application, which would probably be emulated using DOS-Box – Barak Aug 09 '10 at 23:25
  • Oh, OK. That's a rather different situation. Under DOS, your code runs in real mode, where hardware protection is basically irrelevant. You should be able to executes `IN` and `OUT` instructions from here without any trouble. If you do have a problem with code that you know should work, it might be caused by inaccurate emulation on the part of DOSBox. I would think that basic keyboard IO would work, though. – bcat Aug 10 '10 at 02:36
  • someone tried the code using dosemu running on the console and he said that it worked fine. However, when I try my code using DOS-Box, it doesn't work. Do you have any suggestions? – Barak Aug 10 '10 at 12:25
  • Anyway, I would like to know how to perform the IN/OUT instructions under protected mode (gaining IO Privileges or whatever), and even how to leave protected mode. – Barak Aug 10 '10 at 12:27

1 Answers1

1

DOS is not a protected mode OS. In the olden days there were PM frameworks called DOS extenders. They have an API for things like this. Creating your own PM environment consists of much more than just switching the CPU to Protected Mode.

You should also use a debugger program to check what exactly is wrong under DosBox.

vbence
  • 20,084
  • 9
  • 69
  • 118