Page 1 of 1

how to operate io function in user mode?

Posted: Fri Apr 05, 2013 1:16 am
by funggong
hi,every body .
i confused that how an user mode driver using io ports in a microkernel env.
for example, a keyboard driver read a scancode using "in al,dx" instruction,but in ring 3 is not allow,i know tss io bitmap can do this,without change tss,is there another method can implement it. sorry for my english grammer and expression

Re: how to operate io function in user mode?

Posted: Fri Apr 05, 2013 1:25 am
by bluemoon
I'm not doing microkernel but I can think of some possibilities:

1. kernel API - the kernel expose a hardware interface to driver, the actual IO is performed by kernel in ring 0.
2. TSS.io bitmap prevent direct IO, the kernel catch the #GP and emulate the io instruction
3. Driver request to grant access right and modify io bitmap.

I think 3 is more of the standard way, and there are nice tricks like mapping the bitmap via paging to avoid "modifying" TSS on every task switch.

Re: how to operate io function in user mode?

Posted: Fri Apr 05, 2013 1:44 am
by funggong
bluemoon wrote:I'm not doing microkernel but I can think of some possibilities:

1. kernel API - the kernel expose a hardware interface to driver, the actual IO is performed by kernel in ring 0.
2. TSS.io bitmap prevent direct IO, the kernel catch the #GP and emulate the io instruction
3. Driver request to grant access right and modify io bitmap.

I think 3 is more of the standard way, and there are nice tricks like mapping the bitmap via paging to avoid "modifying" TSS on every task switch.
thinks your reply.
but 3 will change tss every time scheduling thread which cost resource.

Re: how to operate io function in user mode?

Posted: Fri Apr 05, 2013 2:05 am
by funggong
you gave me a great help,i will try it later

Re: how to operate io function in user mode?

Posted: Fri Apr 05, 2013 2:59 am
by Combuster
funggong wrote:but 3 will change tss every time scheduling thread which cost resource.

Code: Select all

  TSS (cpu1)
    IOPB ----------------+
  TSS (cpu2)             |
    IOPB ----------------+
  (...)                  |
-- page boundary --      |
  IO bitmap   <----------+

That way you can just reserve your zero-filled page for the IO bitmap space by default, and then replace the pages with actual content only for those drivers that need I/O ports. Changing address spaces will now give you a free IO bitmap update :wink:

Re: how to operate io function in user mode?

Posted: Fri Apr 05, 2013 3:22 am
by bluemoon
funggong wrote:but 3 will change tss every time scheduling thread which cost resource.
No, as I said there are tricks like page mapping, read Combuster's response for the concept.

Re: how to operate io function in user mode?

Posted: Fri Apr 05, 2013 11:09 pm
by funggong
understand now,that is said allocating a page for io bitmap which needed