User:Pinged/TR18037
Jump to navigation
Jump to search
This page or section is a work in progress and may thus be incomplete. Its content may be changed in the near future. |
What is TR18037?
TR18037 is a set of extensions to the C standard library to make low level programming, including OSDev, easier. The features it adds include:
- iohw.h - standard functions for port-io
- stdfix.h - builtin fixed point types
- Named address spaces
- Named register storage classes
iohw.h
This header defines standard functions and types for port-io, these include:
typedef /* ioindex type */ ioindex_t;
typedef /* ioreg type */ ioreg;
/* Read from a port */
unsigned iord (ioreg port);
unsigned long iordl (ioreg port);
unsigned iordbuf (ioreg port, ioindex_t idx);
unsigned long iordbufl (ioreg port, ioindex_t idx);
/* Write to a port */
void iowr (ioreg port, unsigned val);
void iowrl (ioreg port, unsigned long val);
void iowrbuf (ioreg port, ioindex_t idx, unsigned val);
void iowrbufl (ioreg dev, ioindex_t idx, unsigned long val);
/* These functions are pretty much useless to x86 programmers, but those for ARM
and other architectures might find them useful.
*/
/* Do a bitwise and on a port */
void ioand (ioreg port, unsigned val);
void ioandl (ioreg port, unsigned long val);
void ioandbuf (ioreg port, ioindex_t idx, unsigned val);
void ioandbufl (ioreg port, ioindex_t idx, unsigned long val);
/* Do a bitwise or on a port */
void ioor (ioreg port, unsigned val);
void ioorl (ioreg port, unsigned long val);
void ioorbuf (ioreg port, ioindex_t idx, unsigned val);
void ioorbufl (ioreg port, ioindex_t idx, unsigned long val);
/* Do a bitwise xor on a port */
void ioxor (ioreg port, unsigned val);
void ioxorl (ioreg port, unsigned long val);
void ioxorbuf (ioreg port, ioindex_t idx, unsigned val);
void ioxorbufl (ioreg port, ioindex_t idx, unsigned long val);
/* These functions are kind of useless to anyone in kernel space (ring 0) but could
be useful for anybody writing a user mode hardware driver in a microkernel.
*/
/* Allow access to a group of IO ports */
void iogroup_acquire (/* iogroup specifier */ group);
/* Disable access to a group of IO ports */
void iogroup_release (/* iogroup specifier */ group);
/* Map group a to group b */
void iogroup_map (/* iogroup specifier */ a, /* iogroup specifier */ b);
iord, iordbuf, iordl, iordbufl
These functions, are usually equivalent to the inx functions found in most operating systems, a simple implementation for iord would be:
inline unsigned iord (ioreg port)
{
uint8_t val = 0; /* Read 1 byte from the port */
asm volatile ("inb %1, %0" : "=a" (val) : "dN" (port));
return val;
}
My implementation system adds another two functions iordw, iordbufw for reading 2 bytes from a port.
inline uint16_t iordw (ioreg port)
{
uint16_t val = 0; /* Read 2 bytes from a port */
asm volatile ("inw %1, %0" : "=a" (val) : "dN" (port));
return val;
}
stdfix.h
TODO
Named address spaces
TODO
Named register storage class
This feature allows you to select the register a register variable is placed in, GCC supports this feature albeit with a slightly different syntax.
/* TR18037 specified syntax: */
register /* register specifier */ unsigned val;
/* GCC extension syntax: */
register unsigned val asm ("register name here");