User:Pinged/TR18037: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
m Bot: Replace deprecated source tag with syntaxhighlight |
||
(One intermediate revision by one other user not shown) | |||
Line 10: | Line 10: | ||
==iohw.h== |
==iohw.h== |
||
This header defines standard functions and types for port-io, these include: |
This header defines standard functions and types for port-io, these include: |
||
< |
<syntaxhighlight lang="c"> |
||
typedef /* ioindex type */ ioindex_t; |
typedef /* ioindex type */ ioindex_t; |
||
typedef /* ioreg type */ ioreg; |
typedef /* ioreg type */ ioreg; |
||
Line 59: | Line 59: | ||
/* Map group a to group b */ |
/* Map group a to group b */ |
||
void iogroup_map (/* iogroup specifier */ a, /* iogroup specifier */ b); |
void iogroup_map (/* iogroup specifier */ a, /* iogroup specifier */ b); |
||
</syntaxhighlight> |
|||
</source> |
|||
===iord, iordbuf, iordl, iordbufl=== |
|||
These functions, are usually equivalent to the in''x'' functions found in most operating systems, a simple implementation for iord would be: |
|||
<syntaxhighlight lang="c"> |
|||
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; |
|||
} |
|||
</syntaxhighlight> |
|||
My implementation system adds another two functions iordw, iordbufw for reading 2 bytes from a port. |
|||
<syntaxhighlight lang="c"> |
|||
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; |
|||
} |
|||
</syntaxhighlight> |
|||
==stdfix.h== |
==stdfix.h== |
||
Line 71: | Line 95: | ||
==Named register storage class== |
==Named register storage class== |
||
This feature allows you to select the register a <span style="font-family:monospace">register</span> variable is placed in, GCC supports this feature albeit with a slightly different syntax. |
|||
''TODO'' |
|||
<syntaxhighlight lang="c"> |
|||
/* TR18037 specified syntax: */ |
|||
register /* register specifier */ unsigned val; |
|||
/* GCC extension syntax: */ |
|||
register unsigned val asm ("register name here"); |
|||
</syntaxhighlight> |
|||
[[Category:In Progress]] |
[[Category:In Progress]] |
Latest revision as of 06:50, 9 June 2024
This page is a work in progress.
This page 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");