2018-07-20 15:41:58 +02:00
|
|
|
#pragma once
|
2024-01-29 23:27:10 +01:00
|
|
|
#include "stdint.h"
|
2018-07-20 15:41:58 +02:00
|
|
|
|
|
|
|
// NIH http://wiki.osdev.org/Inline_Assembly/Examples#I.2FO_access
|
|
|
|
static inline void outb(uint16_t port, uint8_t val)
|
|
|
|
{
|
2020-04-27 00:14:37 +02:00
|
|
|
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
|
|
|
|
/* There's an outb %al, $imm8 encoding, for compile-time constant port numbers that fit in
|
|
|
|
* 8b. (N constraint). Wider immediate constants would be truncated at assemble-time (e.g.
|
|
|
|
* "i" constraint). The outb %al, %dx encoding is the only option for all other cases.
|
|
|
|
* %1 expands to %dx because port is a uint16_t. %w1 could be used if we had the port
|
|
|
|
* number a wider C type */
|
2018-07-20 15:41:58 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 23:55:15 +02:00
|
|
|
static inline void outw(uint16_t port, int16_t val)
|
|
|
|
{
|
|
|
|
asm volatile("outw %w0, %w1" :: "a"(val), "Nd"(port));
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:41:58 +02:00
|
|
|
static inline uint8_t inb(uint16_t port)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
2020-04-27 00:14:37 +02:00
|
|
|
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
|
2018-07-20 15:41:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2021-10-05 21:59:36 +02:00
|
|
|
|
|
|
|
static inline uint16_t inw(uint16_t port)
|
|
|
|
{
|
|
|
|
uint16_t ret;
|
|
|
|
asm volatile("inw %w1, %0" : "=a"(ret) : "Nd"(port));
|
|
|
|
return ret;
|
|
|
|
}
|