Xyris  0.5
ports.cpp
Go to the documentation of this file.
1 /**
2  * @file ports.cpp
3  * @author Keeton Feavel ([email protected])
4  * @brief CPU port access functions
5  * @version 0.3
6  * @date 2020-06-30
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2020
9  *
10  */
11 #include <Arch/i686/ports.hpp>
12 
13 uint8_t readByte(uint16_t port) {
14  uint8_t result;
15  asm volatile("inb %1, %0" : "=a" (result) : "Nd" (port));
16  return result;
17 }
18 
19 void writeByte(uint16_t port, uint8_t data) {
20  asm volatile("outb %0, %1" : : "a" (data), "Nd" (port));
21 }
22 
23 void writeByteSlow(uint16_t port, uint8_t data) {
24  asm volatile("outb %0, %1\njmp 1f\n1: jmp 1f\n1:" : : "a" (data), "Nd" (port));
25 }
26 
27 uint16_t readWord(uint16_t port) {
28  uint16_t result;
29  asm volatile("inw %1, %0" : "=a" (result) : "Nd" (port));
30  return result;
31 }
32 
33 void writeWord(uint16_t port, uint16_t data) {
34  asm volatile("outw %0, %1" : : "a" (data), "Nd" (port));
35 }
36 
37 uint32_t readLong(uint16_t port) {
38  uint32_t result;
39  asm volatile("inl %1, %0" : "=a" (result) : "Nd" (port));
40  return result;
41 }
42 
43 void writeLong(uint16_t port, uint32_t data) {
44  asm volatile("outl %0, %1" : : "a"(data), "Nd" (port));
45 }
ports.hpp
Ports header file. Provides inline functions for getting and setting values at different ports....
readLong
uint32_t readLong(uint16_t port)
Reads a long (32 bits) off the CPU bus at a given port address.
Definition: ports.cpp:37
readWord
uint16_t readWord(uint16_t port)
Reads a word (16 bits) off the CPU bus at a given port address.
Definition: ports.cpp:27
writeWord
void writeWord(uint16_t port, uint16_t data)
Writes a word (16 bits) to the CPU bus at a given port address.
Definition: ports.cpp:33
writeByteSlow
void writeByteSlow(uint16_t port, uint8_t data)
Writes a byte (8 bits) slowly to the CPU bus at a given port address.
Definition: ports.cpp:23
writeByte
void writeByte(uint16_t port, uint8_t data)
Writes a byte (8 bits) to the CPU bus at a given port address.
Definition: ports.cpp:19
readByte
uint8_t readByte(uint16_t port)
Reads a byte (8 bits) off the CPU bus at a given port address.
Definition: ports.cpp:13
writeLong
void writeLong(uint16_t port, uint32_t data)
Writes a long (32 bits) to the CPU bus at a given port address.
Definition: ports.cpp:43