1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/mos_global.h>
6#include <mos/types.h>
7
8typedef u16 x86_port_t;
9
10should_inline u8 port_inb(u16 port)
11{
12 u8 value;
13 __asm__ volatile("inb %1, %0" : "=a"(value) : "dN"(port));
14 return value;
15}
16
17should_inline u16 port_inw(x86_port_t port)
18{
19 u16 value;
20 __asm__ volatile("inw %1, %0" : "=a"(value) : "dN"(port));
21 return value;
22}
23
24should_inline u32 port_inl(x86_port_t port)
25{
26 u32 value;
27 __asm__ volatile("inl %1, %0" : "=a"(value) : "dN"(port));
28 return value;
29}
30
31should_inline void port_outb(u16 port, u8 value)
32{
33 __asm__ volatile("outb %1, %0" : : "dN"(port), "a"(value));
34}
35
36should_inline void port_outw(x86_port_t port, u16 value)
37{
38 __asm__ volatile("outw %1, %0" : : "dN"(port), "a"(value));
39}
40
41should_inline void port_outl(x86_port_t port, u32 value)
42{
43 __asm__ volatile("outl %1, %0" : : "dN"(port), "a"(value));
44}
45