aboutsummaryrefslogtreecommitdiffstats
path: root/com32/include/sys
diff options
context:
space:
mode:
Diffstat (limited to 'com32/include/sys')
-rw-r--r--com32/include/sys/cpu.h78
-rw-r--r--com32/include/sys/io.h42
-rw-r--r--com32/include/sys/pci.h23
-rw-r--r--com32/include/sys/types.h16
4 files changed, 159 insertions, 0 deletions
diff --git a/com32/include/sys/cpu.h b/com32/include/sys/cpu.h
new file mode 100644
index 00000000..1af2db71
--- /dev/null
+++ b/com32/include/sys/cpu.h
@@ -0,0 +1,78 @@
+#ifndef _CPU_H
+#define _CPU_H
+
+#include <inttypes.h>
+
+static inline uint64_t rdtsc(void)
+{
+ uint64_t v;
+ asm volatile("rdtsc" : "=A" (v));
+ return v;
+}
+
+static inline uint32_t rdtscl(void)
+{
+ uint32_t v;
+ asm volatile("rdtsc" : "=a" (v) : : "edx");
+ return v;
+}
+
+static inline uint32_t cpuid_eax(uint32_t level)
+{
+ uint32_t v;
+
+ asm("cpuid" : "=a" (v) : "a" (level) : "ebx", "ecx", "edx");
+ return v;
+}
+static inline uint32_t cpuid_ebx(uint32_t level)
+{
+ uint32_t v;
+
+ asm("cpuid" : "=b" (v), "+a" (level) : : "ecx", "edx");
+ return v;
+}
+static inline uint32_t cpuid_ecx(uint32_t level)
+{
+ uint32_t v;
+
+ asm("cpuid" : "=c" (v), "+a" (level) : : "ebx", "edx");
+ return v;
+}
+static inline uint32_t cpuid_edx(uint32_t level)
+{
+ uint32_t v;
+
+ asm("cpuid" : "=d" (v), "+a" (level) : : "ebx", "ecx");
+ return v;
+}
+
+static inline uint64_t rdmsr(uint32_t msr)
+{
+ uint64_t v;
+
+ asm volatile("rdmsr" : "=A" (v) : "c" (msr));
+ return v;
+}
+static inline void wrmsr(uint64_t v, uint32_t msr)
+{
+ asm volatile("wrmsr" : : "A" (v), "c" (msr));
+}
+
+static inline void cpu_relax(void)
+{
+ asm volatile("rep ; nop");
+}
+
+/* These are local cli/sti; not SMP-safe!!! */
+
+static inline void cli(void)
+{
+ asm volatile("cli");
+}
+
+static inline void sti(void)
+{
+ asm volatile("sti");
+}
+
+#endif
diff --git a/com32/include/sys/io.h b/com32/include/sys/io.h
new file mode 100644
index 00000000..460f2309
--- /dev/null
+++ b/com32/include/sys/io.h
@@ -0,0 +1,42 @@
+#ifndef _SYS_IO_H
+#define _SYS_IO_H
+
+#include <inttypes.h>
+
+static inline uint8_t inb(uint16_t p)
+{
+ uint8_t v;
+ asm volatile("inb %1,%0" : "=a" (v) : "Nd" (p));
+ return v;
+}
+
+static inline uint16_t inw(uint16_t p)
+{
+ uint16_t v;
+ asm volatile("inw %1,%0" : "=a" (v) : "Nd" (p));
+ return v;
+}
+
+static inline uint32_t inl(uint16_t p)
+{
+ uint32_t v;
+ asm volatile("inl %1,%0" : "=a" (v) : "Nd" (p));
+ return v;
+}
+
+static inline void outb(uint8_t v, uint16_t p)
+{
+ asm volatile("outb %0,%1" : : "a" (v), "Nd" (p));
+}
+
+static inline void outw(uint16_t v, uint16_t p)
+{
+ asm volatile("outw %0,%1" : : "a" (v), "Nd" (p));
+}
+
+static inline void outl(uint32_t v, uint16_t p)
+{
+ asm volatile("outl %0,%1" : : "a" (v), "Nd" (p));
+}
+
+#endif /* _SYS_IO_H */
diff --git a/com32/include/sys/pci.h b/com32/include/sys/pci.h
new file mode 100644
index 00000000..9a01cc47
--- /dev/null
+++ b/com32/include/sys/pci.h
@@ -0,0 +1,23 @@
+#ifndef _SYS_PCI_H
+#define _SYS_PCI_H
+
+#include <inttypes.h>
+#include <sys/io.h>
+
+typedef uint32_t pciaddr_t;
+
+static inline pciaddr_t pci_mkaddr(uint32_t bus, uint32_t dev,
+ uint32_t func, uint32_t reg)
+{
+ return 0x80000000 | ((bus & 0xff) << 16) | ((dev & 0x1f) << 11) |
+ ((func & 0x07) << 8) | (reg & 0xff);
+}
+
+uint8_t pci_read8(pciaddr_t a);
+uint16_t pci_read16(pciaddr_t a);
+uint32_t pci_read32(pciaddr_t a);
+void pci_write8(uint8_t v, pciaddr_t a);
+void pci_write16(uint16_t v, pciaddr_t a);
+void pci_write32(uint32_t v, pciaddr_t a);
+
+#endif /* _SYS_PCI_H */
diff --git a/com32/include/sys/types.h b/com32/include/sys/types.h
new file mode 100644
index 00000000..d7e9cba3
--- /dev/null
+++ b/com32/include/sys/types.h
@@ -0,0 +1,16 @@
+/*
+ * sys/types.h
+ */
+
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+#include <klibc/compiler.h>
+#include <stddef.h>
+#include <stdint.h>
+
+typedef ptrdiff_t ssize_t;
+typedef int mode_t;
+typedef int64_t off_t;
+
+#endif