www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/12/15:57:02

Message-Id: <199701122021.VAA05611@math.amu.edu.pl>
Comments: Authenticated sender is <grendel AT ananke DOT amu DOT edu DOT pl>
From: "Mark Habersack" <grendel AT ananke DOT amu DOT edu DOT pl>
Organization: What? (Poznan, Poland)
To: Matthew Mastracci <mmastrac AT acs DOT ucalgary DOT ca>
Date: Sun, 12 Jan 1997 21:26:05 +0100
MIME-Version: 1.0
Subject: Re: Low-level access
Reply-to: grendel AT ananke DOT amu DOT edu DOT pl
CC: djgpp AT delorie DOT com

Once upon a time (on 12 Jan 97 at 0:57) Matthew Mastracci said:

>      I'd like to create a hardware-interaction-intensive program,
>      but I'm
> afraid of all the overhead involved with port I/O.  From my
> understanding, any program not running at ring-0 invokes an
> exception error with port I/O?  I believe I know the fastest way to
No. It is not a rule. It depends on the server's (in general sense, 
not only DPMI) implementation. The primary mechanism of I/O ports 
access protection is the IOPL (I/O Privilege Level) in the eflags 
register. If the currently executing task has it's privilege level 
lower or equal to the IOPL value, the it can access directly ALL I/O 
address space. Direct access means that no software intercepts and 
emulates the I/O CPU instructions: IN, OUT, INS, OUTS. Under CWSDPMI 
IOPL == 3, so you have access to all registers.
Beginning from i386 there's, however, an additional and better 
mechanism of I/O protection. TSS (Task State Segment) in 
i386 stores a bitmapped table of I/O access permissions. The table is 
(or isn't) stored at the end of TSS. Now, if I/O permission bitmap is *not* present 
then the client (or process if we're talking about PM OS) has no 
direct access to any of the ports present (bitmap is assumed to 
contain all 1s) - OS/server emulates the instructions mentioned above. 
If the OS or server wants to allow direct access to some addresses in 
I/O address space, the it has to put 0s in the bits corresponding to 
the ports in question.
Having explained that, we can draw our conclusions. If you're working 
under plain DOS and CWSDPMI (probably under other DOS DPMI servers 
also) you have a direct access to ports and your program's speed will 
not be injured. However uder the *real* PM OSes like, Windows NT, 
Linux, FreeBSD, and under a *semi-real* PM oses like Win95 ;-)), you 
can be sure that at least part of the I/O address space will be 
protected. It usually concerns the areas that are vital for the 
operating system in question. I suspect that all of the above systems 
will protect the DMA, RTC, main-board, FPU, HDD and FDC registers, 
and those which work in gfx mode will also protect the gfx adapter 
ones.
I hope that helps.

_http://ananke.amu.edu.pl/~grendel_________________________
We buy fresh bagels from the corner store where swastikas
are spat from areosols. I sit in the bar sipping iced white
russians, trying to score but nobody's pushing. And everyone
looks at everyone's faces, searching for signs and praying
for traces of a conscience in residence, are we sitting on
a barbed wire fence chasing the clouds home?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019