diff options
author | Marvin Borner | 2020-09-08 15:29:38 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-08 15:29:38 +0200 |
commit | 36d7c86a1e9e72d689d672a0e8576adbc740d541 (patch) | |
tree | b4556b37b0f82d8e41b0ff43ec444c71fca0ccbd /kernel | |
parent | 9c2f40441e0cc909ebefe432ddc10e2de29b82ac (diff) |
Some work on CPU stuff (soon: SMP)
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/drivers/acpi.c | 49 | ||||
-rw-r--r-- | kernel/inc/acpi.h | 79 | ||||
-rw-r--r-- | kernel/main.c | 3 |
3 files changed, 125 insertions, 6 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c index 4c7a1a8..e853a6f 100644 --- a/kernel/drivers/acpi.c +++ b/kernel/drivers/acpi.c @@ -36,9 +36,10 @@ struct rsdp *find_rsdp() } // Or first KB of EBDA? - for (int i = 0x100000; i < 0x101000; i++) { - if (memcmp((u32 *)i, RSDP_MAGIC, 8) == 0) - return (struct rsdp *)i; + u8 *ebda = (void *)(*((u16 *)0x40E) << 4); + for (int i = 0; i < 1024; i += 16) { + if (memcmp(ebda + i, RSDP_MAGIC, 8) == 0) + return (struct rsdp *)(ebda + i); } return NULL; @@ -72,6 +73,8 @@ void acpi_install() madt = find_sdt(rsdt, MADT_MAGIC); fadt = find_sdt(rsdt, FADT_MAGIC); hpet = find_sdt(rsdt, HPET_MAGIC); + + madt_install(); } void hpet_install(int period) @@ -91,3 +94,43 @@ void hpet_install(int period) hpet = NULL; } } + +void madt_install() +{ + if (!madt) + return; + + struct madt_entry_header *entry = &madt->entry; + while (entry && entry->length) { + switch (entry->type) { + case MADT_LOCAL_APIC_ENTRY: { + struct madt_local_apic_entry *table = (struct madt_local_apic_entry *)entry; + printf("CPU %b\n", table->flags); + break; + } + case MADT_IO_APIC_ENTRY: { + /* struct madt_io_apic_entry *table = (struct madt_io_apic_entry *)entry; */ + break; + } + case MADT_INT_SRC_OVERRIDE_ENTRY: { + /* struct madt_int_src_override_entry *table = */ + /* (struct madt_int_src_override_entry *)entry; */ + break; + } + case MADT_NON_MASKABLE_INT_ENTRY: { + /* struct madt_non_maskable_int_entry *table = */ + /* (struct madt_non_maskable_int_entry *)entry; */ + break; + } + case MADT_LOCAL_APIC_OVERRIDE_ENTRY: { + /* struct madt_local_apic_override_entry *table = */ + /* (struct madt_local_apic_override_entry *)entry; */ + break; + } + default: { + break; + } + } + entry = (struct madt_entry_header *)((u32)entry + entry->length); + } +} diff --git a/kernel/inc/acpi.h b/kernel/inc/acpi.h index 6cebf9b..4e04037 100644 --- a/kernel/inc/acpi.h +++ b/kernel/inc/acpi.h @@ -21,6 +21,10 @@ struct address_structure { u32 phys; // Actually u64 }; +/** + * General headers + */ + struct sdt_header { char signature[4]; u32 length; @@ -40,21 +44,85 @@ struct sdp_header { u8 revision; }; +/** + * RSDT + */ + struct rsdt { struct sdt_header header; u32 sdt_pointer[]; }; +/** + * MADT + */ + +struct madt_entry_header { + u8 type; + u8 length; +}; + struct madt { struct sdt_header header; u32 local_address; u32 flags; -}; + struct madt_entry_header entry; +} __attribute__((packed)); + +#define MADT_LOCAL_APIC_ENTRY 0 +#define MADT_IO_APIC_ENTRY 1 +#define MADT_INT_SRC_OVERRIDE_ENTRY 2 +#define MADT_NON_MASKABLE_INT_ENTRY 4 // Where's 3? +#define MADT_LOCAL_APIC_OVERRIDE_ENTRY 5 + +struct madt_local_apic_entry { + struct madt_entry_header header; + u8 processor_id; + u8 id; + u32 flags; +} __attribute__((packed)); + +struct madt_io_apic_entry { + struct madt_entry_header header; + u8 id; + u8 reserved; + u32 address; + u32 global_system_interrupt_base; +} __attribute__((packed)); + +struct madt_int_src_override_entry { + struct madt_entry_header header; + u8 bus_source; + u8 irq_source; + u32 global_system_interrupt; + u16 flags; +} __attribute__((packed)); + +struct madt_non_maskable_int_entry { + struct madt_entry_header header; + u8 processor_id; + u16 flags; + u8 lint_number; +} __attribute__((packed)); + +struct madt_local_apic_override_entry { + struct madt_entry_header header; + u16 reserved; + u64 address; +} __attribute__((packed)); + +/** + * FADT + */ struct fadt { struct sdt_header header; // TODO: FADT table (big!) -}; +} __attribute__((packed)); + +/** + * HPET + */ struct hpet { struct sdt_header header; @@ -68,7 +136,7 @@ struct hpet { u8 hpet_number; u16 minimum_tick; u8 page_protection; -}; +} __attribute__((packed)); enum hpet_features { hpet_counter_size = 1 << 3, hpet_legacy_replacement_support = 1 << 5 }; enum hpet_config { hpet_enable = 1 << 0, hpet_legacy_replacement = 1 << 1 }; @@ -102,6 +170,10 @@ struct hpet_registers { u64 timer_comparator0; // In femtoseconds } __attribute__((packed)); +/** + * RSDP + */ + struct rsdp { struct sdp_header header; struct rsdt *rsdt; @@ -113,5 +185,6 @@ struct hpet *hpet; void acpi_install(); void hpet_install(int frequency); +void madt_install(); #endif diff --git a/kernel/main.c b/kernel/main.c index 34332e2..880c66c 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -9,6 +9,7 @@ #include <load.h> #include <mem.h> #include <mouse.h> +#include <print.h> #include <serial.h> #include <syscall.h> #include <timer.h> @@ -23,6 +24,8 @@ void kernel_main(struct vid_info *vid_info) serial_install(); serial_print("\nConnected.\n"); + cpu_print(); + // Install drivers acpi_install(); interrupts_install(); |