diff options
| author | EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> | 2025-01-20 13:22:39 -0500 |
|---|---|---|
| committer | EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> | 2025-01-20 13:22:39 -0500 |
| commit | 0f78d65d57c7049032278398890941413d2a8e33 (patch) | |
| tree | a80d22c2fa69a2dd07fc2527437913371792c27e /kernel/include/arch/x86_64/io.h | |
| parent | 8eda325ede02d3fc606a34f7fa3c4922b05a84e4 (diff) | |
i have no idea i thought this was already in there
Diffstat (limited to 'kernel/include/arch/x86_64/io.h')
| -rw-r--r-- | kernel/include/arch/x86_64/io.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/kernel/include/arch/x86_64/io.h b/kernel/include/arch/x86_64/io.h new file mode 100644 index 0000000..b99f0ef --- /dev/null +++ b/kernel/include/arch/x86_64/io.h @@ -0,0 +1,32 @@ +#ifndef HW_IO_H
+#define HW_IO_H
+
+#include <stdint.h>
+
+// Used for io access
+
+static inline void outb(uint16_t port, uint8_t val)
+{
+ asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) :"memory");
+ /* 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 */
+}
+
+static inline uint8_t inb(uint16_t port)
+{
+ uint8_t ret;
+ asm volatile ( "inb %1, %0"
+ : "=a"(ret)
+ : "Nd"(port)
+ : "memory");
+ return ret;
+}
+
+static inline void io_wait(void)
+{
+ outb(0x80, 0);
+}
+
+#endif
\ No newline at end of file |
