IBMPC::IO Class Reference

#include <ibmpc.h>

List of all members.


Detailed Description

Handles accesses to I/O ports.

Also provides simple per-port protection mechanism.

Implementation
Maintains set of port descriptors where each registered port is attached to it's virtual Device which is called to perform an action when port is read or written to (usually by the CPU).
Protection
Protection is implemented by storing 32-bit "flags" field in each port descriptor which includes bits such as PERM_READABLE and PERM_WRITEABLE. These flags are checked before each port access.
In case of protection fault special "state" bitmask will be updated to indicate error. This bitmask can then be retrieved using get_state() call.
Note:
The state bitmask is reset each port read/write operation, so it should be checked immediately after performing the operation.

In case of error operation will NOT be performed (driver handler methods such as port_read8() will *not* be called).

READ operations will return 0 in case of error.

Definition at line 273 of file ibmpc.h.

Public Types

 PERM_READABLE = 0x0001
 This port is readable.
 PERM_WRITEABLE = 0x0002
 This port is writeable.
 STATE_FAULT = 0x0001
 0:last operation succeeded; 1:failed
 STATE_DIR = 0x0002
 0:last operation was READ, 1:WRITE
enum  perm_t { PERM_READABLE = 0x0001, PERM_WRITEABLE = 0x0002 }
 I/O port permissions bitmask. More...
enum  state_t { STATE_FAULT = 0x0001, STATE_DIR = 0x0002 }
 I/O bus state bitmask (used to check for error in last operation). More...

Public Member Functions

 IO ()
 Construct instance of I/O ports manager.
 ~IO ()
 Destruct instance of I/O ports manager.
void port_set_perm (unsigned int port, uint32 perm)
 Set permissions for port (also see enum perm_t).
uint32 port_get_perm (unsigned int port)
 Retrieve permissions of given port.
bool port_attach (unsigned int port_index, Device *device)
 Attach device driver to handle accesses to this port.
bool port_free (unsigned int port_index)
 Detach port from Device driver.
uint8 port_read8 (unsigned int port_index)
 Read 8 bits from port at given address.
void port_write8 (unsigned int port_index, uint8 data)
 Write 8 bits to port at given address.
uint32 get_state ()
 Query last I/O access status.


Member Enumeration Documentation

enum IBMPC::IO::perm_t

I/O port permissions bitmask.

Enumerator:
PERM_READABLE  This port is readable.
PERM_WRITEABLE  This port is writeable.

Definition at line 278 of file ibmpc.h.

enum IBMPC::IO::state_t

I/O bus state bitmask (used to check for error in last operation).

Enumerator:
STATE_FAULT  0:last operation succeeded; 1:failed
STATE_DIR  0:last operation was READ, 1:WRITE

Definition at line 285 of file ibmpc.h.


Constructor & Destructor Documentation

IBMPC::IO::IO (  ) 

Construct instance of I/O ports manager.

Definition at line 167 of file ibmpc.cpp.

IBMPC::IO::~IO (  ) 

Destruct instance of I/O ports manager.

Definition at line 172 of file ibmpc.cpp.


Member Function Documentation

void IBMPC::IO::port_set_perm ( unsigned int  port,
uint32  perm 
)

Set permissions for port (also see enum perm_t).

Note:
If port number is out of bounds or port is not attached to any Device driver the function will OE_ASSERT() in DEBUG build, and do nothing in RELEASE build.

Definition at line 176 of file ibmpc.cpp.

uint32 IBMPC::IO::port_get_perm ( unsigned int  port  ) 

Retrieve permissions of given port.

Returns:
bitmask with set of bits defined in enum perm_t describing access permissions of this port.
Note:
If port number is out of bounds or port is not attached to any Device driver the function will return 0.

Definition at line 184 of file ibmpc.cpp.

bool IBMPC::IO::port_attach ( unsigned int  port_index,
Device device 
)

Attach device driver to handle accesses to this port.

Returns:
true if succeeded, false if port is already attached to another driver, or parameter "device" is NULL.
Attention:
Initially, after attachment, the port will have FULL permissions (READ/WRITE). Call port_set_perm() to change these initial permissions if you need.
Failure case
In case of failure the ports set will not be affected in any way.
Reattachment (special cases)
If port was already attached to ANOTHER driver - the function will fail (return false), and port will not change its owner. If port was already attached to THIS driver - the function will succeed (return true).

Definition at line 194 of file ibmpc.cpp.

Referenced by IBMPC::VDD_Video_CGA_6845::init(), IBMPC::VDD_SYS_PPI_8255A::init(), and IBMPC::VDD_Floppy::init().

bool IBMPC::IO::port_free ( unsigned int  port_index  ) 

Detach port from Device driver.

Returns:
true if succeeded, false if port is already detached from drivers.
Note:
The port_get_perm() on the freed ports will always return 0.

Definition at line 210 of file ibmpc.cpp.

Referenced by IBMPC::VDD_Video_CGA_6845::done(), IBMPC::VDD_SYS_PPI_8255A::done(), and IBMPC::VDD_Floppy::done().

uint8 IBMPC::IO::port_read8 ( unsigned int  port_index  ) 

Read 8 bits from port at given address.

Returns:
Value returned by driver associated with the port (see port_attach(), or 0 if access failed. If permissions allow, the associated driver's port_read8() method will be invoked. (see class Driver).
Note:
In case port is not attached to any driver, or port permissions are violated, value of 0 will be returned, and state flags (state_t) set to indicate fault. It is caller's responsibility to check for faults using call to get_state() immediately after performing the access.

Definition at line 222 of file ibmpc.cpp.

void IBMPC::IO::port_write8 ( unsigned int  port_index,
uint8  data 
)

Write 8 bits to port at given address.

If permissions allow, the associated driver's port_write8() method will be invoked. (see class Driver).

Note:
In case addr is out of bounds or port permissions are violated, state flags (state_t) will be set to indicate fault. It is caller's responsibility to check for faults using call to get_state() immediately after performing the access.

Definition at line 236 of file ibmpc.cpp.

uint32 IBMPC::IO::get_state (  ) 

Query last I/O access status.

Returns:
bitmask defined by enum state_t. The value is reset each time port_read8() or port_write8() operation is performed.
Users who want to check for errors and violations during access to ports will need to call get_state() after each call to port accessing functions port_read8() or port_write8().
Note:
This will mostly be called from inside CPU emulators.


The documentation for this class was generated from the following files:
Generated on Sat Sep 9 03:50:54 2006 for Openem APIs by  doxygen 1.4.7