how to operate io function in user mode?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
funggong
Posts: 4
Joined: Fri Apr 05, 2013 1:03 am

how to operate io function in user mode?

Post 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
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: how to operate io function in user mode?

Post 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.
funggong
Posts: 4
Joined: Fri Apr 05, 2013 1:03 am

Re: how to operate io function in user mode?

Post 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.
funggong
Posts: 4
Joined: Fri Apr 05, 2013 1:03 am

Re: how to operate io function in user mode?

Post by funggong »

you gave me a great help,i will try it later
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: how to operate io function in user mode?

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: how to operate io function in user mode?

Post 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.
funggong
Posts: 4
Joined: Fri Apr 05, 2013 1:03 am

Re: how to operate io function in user mode?

Post by funggong »

understand now,that is said allocating a page for io bitmap which needed
Post Reply