WKern
Loading...
Searching...
No Matches
asm.c
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#include <io/kio.h>
20#include <types/nums.h>
21
22#ifndef __clang__ // We do this to maKe ClangD shutup
23
30inline void Outb(u16 port, u8 val) {
31 __asm__ volatile("outb %0, %1" : : "a"(val), "Nd"(port));
32}
33
40inline u8 Inb(u16 port) {
41 u8 ret;
42 __asm__ volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
43 return ret;
44}
45
52inline void Outw(u16 port, u16 val) {
53 __asm__ volatile("outw %0, %1" : : "a"(val), "Nd"(port));
54}
55
62inline u16 Inw(u16 port) {
63 u16 ret;
64 __asm__ volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
65 return ret;
66}
67
74inline void Outl(u16 port, u32 val) {
75 __asm__ volatile("outl %0, %1" : : "a"(val), "Nd"(port));
76}
77
84inline u32 Inl(u16 port) {
85 u32 ret;
86 __asm__ volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
87 return ret;
88}
89
96inline void Cli() { __asm__ volatile("cli"); }
97
104inline void Sti() { __asm__ volatile("sti; nop; nop; nop"); }
105
106#endif
void Outb(u16 port, u8 val)
Write a byte to the specified I/O port.
Definition asm.c:30
void Outw(u16 port, u16 val)
Write a 16-bit word to the specified I/O port.
Definition asm.c:52
u32 Inl(u16 port)
Read a 32-bit value from the specified I/O port.
Definition asm.c:84
u8 Inb(u16 port)
Read a byte from the specified I/O port.
Definition asm.c:40
u16 Inw(u16 port)
Read a 16-bit word from the specified I/O port.
Definition asm.c:62
void Sti()
Enable CPU interrupts (set interrupt flag).
Definition asm.c:104
void Outl(u16 port, u32 val)
Write a 32-bit value to the specified I/O port.
Definition asm.c:74
void Cli()
Disable CPU interrupts (clear interrupt flag).
Definition asm.c:96
unsigned int u32
32-Bit Unsigned Int
Definition nums.h:30
unsigned short u16
16-Bit Unsigned Int
Definition nums.h:36
unsigned char u8
8-Bit Unsigned Int
Definition nums.h:32