From c4749319beb6227164d1d070aadef550ec51e4ac Mon Sep 17 00:00:00 2001 From: Greg Bowne Date: Wed, 19 Jul 2023 23:31:54 -0700 Subject: [PATCH] working on types and eisa bus driver --- src/drivers/bus/eisa.c | 31 ++++++++++++++++++++++++++++- src/drivers/tty/tty.c | 7 +++---- src/kernel/arch/x86/include/types.c | 18 +++++++++++++++++ src/kernel/arch/x86/include/types.h | 12 +++++------ src/kernel/arch/x86/isr.h | 2 +- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 src/kernel/arch/x86/include/types.c diff --git a/src/drivers/bus/eisa.c b/src/drivers/bus/eisa.c index a870e63..1baed6b 100644 --- a/src/drivers/bus/eisa.c +++ b/src/drivers/bus/eisa.c @@ -22,7 +22,36 @@ void eisa_init() // Detect and configure EISA devices void eisa_detect_devices() { - // Add any necessary device detection and configuration code here + uint32_t bus, slot, func; + uint16_t vendor_id, device_id, class_code; + + for (bus = 0; bus < 256; bus++) + { + for (slot = 0; slot < 32; slot++) + { + for (func = 0; func < 8; func++) + { + uint32_t address = (bus << 16) | (slot << 11) | (func << 8); + uint32_t id = eisa_read_config_dword(address, 0); + vendor_id = id & 0xFFFF; + device_id = (id >> 16) & 0xFFFF; + class_code = eisa_read_config_word(address, 10); + if (vendor_id != 0xFFFF) + { + // Device detected, do something with it + if (vendor_id == MY_DEVICE_VENDOR_ID && + device_id == MY_DEVICE_DEVICE_ID && + class_code == MY_DEVICE_CLASS_CODE) + { + // This is my device, configure it + uint32_t config1 = eisa_read_config_dword(address, 4); + uint32_t config2 = eisa_read_config_dword(address, 8); + // Do something with the configuration data + } + } + } + } + } } // Read from an EISA device diff --git a/src/drivers/tty/tty.c b/src/drivers/tty/tty.c index f1012fd..a82948a 100644 --- a/src/drivers/tty/tty.c +++ b/src/drivers/tty/tty.c @@ -4,12 +4,11 @@ #include #include -#include "../display.h" -#include "../interrupts.h" +#include "../display/display.h" #include "../io/io.h" -#include "../keyboard.h" +#include "../keyboard/keyboard.h" +#include "../screen/screen.h" #include "../string.h" -#include "./screen/screen.h" #include "./tty.h" diff --git a/src/kernel/arch/x86/include/types.c b/src/kernel/arch/x86/include/types.c new file mode 100644 index 0000000..56fa289 --- /dev/null +++ b/src/kernel/arch/x86/include/types.c @@ -0,0 +1,18 @@ +#include "./types.h" + +void gdt_set_entry(gdt_entry_t *entry, uint32_t base, uint32_t limit, + uint16_t flags) +{ + entry->base = base; + entry->limit = limit; + entry->flags = flags; +} + +void idt_set_entry(idt_entry_t *entry, uint32_t base, uint16_t selector, + uint16_t flags) +{ + entry->base_low = base & 0xFFFF; + entry->base_high = (base >> 16) & 0xFFFF; + entry->selector = selector; + entry->flags = flags; +} \ No newline at end of file diff --git a/src/kernel/arch/x86/include/types.h b/src/kernel/arch/x86/include/types.h index 44207c2..26280d0 100644 --- a/src/kernel/arch/x86/include/types.h +++ b/src/kernel/arch/x86/include/types.h @@ -14,11 +14,11 @@ typedef struct typedef struct { - uint16_t base_lo; // Lower 16 bits of handler function address - uint16_t selector; // Kernel segment selector - uint8_t always0; // Always 0 - uint8_t flags; // Flags - uint16_t base_hi; // Upper 16 bits of handler function address -} idt_entry_t; + uint16_t base_low; + uint16_t selector; + uint8_t zero; + uint8_t flags; + uint16_t base_high; +} __attribute__((packed)) idt_entry_t; #endif /* TYPES_H */ \ No newline at end of file diff --git a/src/kernel/arch/x86/isr.h b/src/kernel/arch/x86/isr.h index a7f8852..e733a0d 100644 --- a/src/kernel/arch/x86/isr.h +++ b/src/kernel/arch/x86/isr.h @@ -16,7 +16,7 @@ struct isr_regs }; // Register an ISR -void isr_register(uint8_t num, void (*handler)(void)); +void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)); // ISR handler void isr_handler(struct isr_regs *regs);