TSS i/o bitmap

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
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

TSS i/o bitmap

Post by FlashBurn »

I´m about to start coding for the TSS i/o bitmap and got a few questions.

So the x86 architecture has at max 64k ports (0-0xFFFF) and the bitmap is at max 8kb. I wanted to use 3 pages for that:

Code: Select all

0 - 0xF97 cpu specific data
0xF98 - 0xFFF TSS
0x1000 - 0x2FFF i/o-bitmap
The 1st problem I have is that behind the table should be a byte with "0xFF", but as I planed to use 2 4kb pages (so that I need only to change the pages if needed for every process) and there I can´t guarantee that the byte behind the table exists. I could now put the TSS at 0xF94 and save the dword of the 1st 32 ports in my process structure. My question would be if the 1st 32 ports are used? If they aren´t used I needn´t to save the dword in my process structure.

Do you think this is a good idea? How are you solving the problem to give a process (which only can be a driver and no normal user process) i/o access only to the ports it is allowed to access?

And how is it with performance with this method? Are there any faster methods to check permission for i/o ports?
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: TSS i/o bitmap

Post by Combuster »

The I/O bitmap is, for userland drivers, the fastest safe method to allow port I/O.

I don't know about the erratum that says to add extra bytes, but the only reason it would be needed was to fix port i/o that wraps around the 16 bits - which is a software error. If you need to lose the byte on the processor in question, remove the last byte (i.e. make the TSS size 12k - 1 byte) - from what I've seen there's nothing mapped to ports FFFC-FFFF. You better not drop the first 32 as the DMA controller starts from port 0000 and you can't do "proper" (no Dex, don't) floppy and soundblaster drivers without that range.

The fully correct solution is to have a page of ones, or no page, directly after the TSS. This also has the advantage that you can just reuse your "white page" for all TSSes until the process in question actually uses ports, in which case you can allocate the needed page on demand and save space. If you care about the bits you can also just use three pages.

Note that you might want to take care of the fact that directly under the IO bitmap is the interrupt redirection bitmap - in case you ever want to do Virtual 8086 mode. (so you'd lose the top 256+8 ports with only 2 pages, which again never was a problem here)

I won't bother with my TSS implementation - it uses some really nasty hacks to save spacetime on SMP systems. There's a link in my signature for the daring ones :)
"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 ]
Post Reply