summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/panic.h10
-rw-r--r--include/pci.h55
-rw-r--r--include/shim.h8
3 files changed, 69 insertions, 4 deletions
diff --git a/include/panic.h b/include/panic.h
index dc96da1..d7f612c 100644
--- a/include/panic.h
+++ b/include/panic.h
@@ -3,9 +3,11 @@
#define _PANIC_STR(x) _PANIC_STR2(x)
#define _PANIC_STR2(x) #x
-#define panic(msg) _panic_impl(_PANIC_STR(__LINE__), __FILE__, msg)
-#define kassert(val, msg) do { if (!(val)) { panic(msg); } } while(0)
+#define panic(msg, ...) _panic_impl(_PANIC_STR(__LINE__), __FILE__, msg, ## __VA_ARGS__)
+#define kassert(val, msg, ...) do { if (!(val)) { panic(msg, ## __VA_ARGS__); } } while(0)
-_Noreturn void _panic_impl(char *line, char *file, char *msg);
+__attribute__((noreturn,format(printf, 3, 4)))
+void _panic_impl(char *line, char *file, char *msg, ...);
-_Noreturn void panic_interrupt(void *ip, void *bp, char *msg);
+__attribute__((noreturn,format(printf, 3, 4)))
+void _panic_interrupt(void *ip, void *bp, char *msg, ...);
diff --git a/include/pci.h b/include/pci.h
new file mode 100644
index 0000000..b35abf8
--- /dev/null
+++ b/include/pci.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+// common
+#define PCI_VENDOR_W 0x00
+#define PCI_DEVICE_W 0x02
+#define PCI_COMMAND_W 0x04
+#define PCI_STATUS_W 0x06
+#define PCI_REVISION_B 0x08
+#define PCI_PROG_IF_B 0x09
+#define PCI_SUBCLASS_B 0x0A
+#define PCI_CLASS_B 0x0B
+#define PCI_CACHE_SIZE_B 0x0C
+#define PCI_LATENCY_TIMER_B 0x0D
+#define PCI_HEADER_TYPE_B 0x0E
+#define PCI_BIST_B 0x0F
+
+// header type 0
+#define PCI_BAR0_D 0x10
+#define PCI_BAR1_D 0x14
+#define PCI_BAR2_D 0x18
+#define PCI_BAR3_D 0x1C
+#define PCI_BAR4_D 0x20
+#define PCI_BAR5_D 0x24
+#define PCI_CARDBUS_CIS_D 0x28
+#define PCI_SUBSYSTEM_VENDOR_W 0x2C
+#define PCI_SUBSYSTEM_W 0x2E
+#define PCI_EXPANSION_ROM_D 0x30
+#define PCI_CAP_PTR_B 0x34
+#define PCI_INT_LINE_B 0x3C
+#define PCI_INT_PIN_B 0x3D
+#define PCI_MIN_GRANT_B 0x3E
+#define PCI_MAX_LATENCY_B 0x3F
+
+struct pci_device {
+ uint8_t bus: 8;
+ uint8_t device: 5;
+ uint8_t function: 3;
+};
+
+void pci_init(void);
+
+bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass, size_t *offset);
+bool pci_findby_id(struct pci_device *dest, uint16_t device, uint16_t vendor, size_t *offset);
+
+uint32_t pci_rcfg_d(struct pci_device dev, uint8_t offset);
+uint16_t pci_rcfg_w(struct pci_device dev, uint8_t offset);
+uint8_t pci_rcfg_b(struct pci_device dev, uint8_t offset);
+
+void pci_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword);
+void pci_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word);
+void pci_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte);
diff --git a/include/shim.h b/include/shim.h
index 2bf9726..498de92 100644
--- a/include/shim.h
+++ b/include/shim.h
@@ -15,6 +15,14 @@ struct memory_map {
struct memory_segment entries[MMAP_MAX_ENTRY];
};
+//struct framebuffer {
+// uint64_t addr;
+// uint32_t pitch;
+// uint32_t width;
+// uint32_t height;
+// uint8_t bit_depth;
+//};
+
struct boot_info {
struct memory_map map;
void *symbol_table;