diff options
author | Marvin Borner | 2020-04-18 19:27:00 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-18 19:27:00 +0200 |
commit | dce9106bcb47ef37a4cf5a221340f4eb438aedfe (patch) | |
tree | 2b1ec8efdba9b31510ad6f49a9610df701aab025 | |
parent | f943fad362a0e17f6e294341b32e49b9afd6e9d7 (diff) |
Added fadt flags and ACPI reboot
-rw-r--r-- | src/kernel/acpi/acpi.c | 49 | ||||
-rw-r--r-- | src/kernel/acpi/acpi.h | 32 | ||||
-rw-r--r-- | src/kernel/cmos/rtc.c | 2 | ||||
-rw-r--r-- | src/kernel/kernel.c | 2 | ||||
-rw-r--r-- | src/kernel/lib/memory.c | 8 | ||||
-rw-r--r-- | src/kernel/multiboot.c | 32 |
6 files changed, 72 insertions, 53 deletions
diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c index f826e19..5485042 100644 --- a/src/kernel/acpi/acpi.c +++ b/src/kernel/acpi/acpi.c @@ -37,6 +37,7 @@ void acpi_init(struct rsdp *rsdp) if (strncmp(rsdp->signature, "RSD PTR ", 8) == 0) { memcpy(rsdt, rsdp->rsdt_address, sizeof(struct rsdt) + 32); + debug("Found RSDT"); if (!check_sum((struct sdt_header *)rsdt)) { warn("Corrupted RSDT!"); } else { @@ -48,17 +49,17 @@ void acpi_init(struct rsdp *rsdp) memcpy(header, (void *)address, sizeof(struct sdt_header)); if (strncmp(header->signature, "FACP", 4) == 0) { - info("Found FADT"); + debug("Found FADT"); memcpy(fadt, (void *)address, sizeof(struct fadt)); if (!check_sum((struct sdt_header *)fadt)) warn("Corrupted FADT!"); } else if (strncmp(header->signature, "HPET", 4) == 0) { - info("Found HPET"); + debug("Found HPET"); memcpy(hpet, (void *)address, sizeof(struct hpet)); if (!check_sum((struct sdt_header *)hpet)) warn("Corrupted HPET!"); } else if (strncmp(header->signature, "APIC", 4) == 0) { - info("Found MADT"); + debug("Found MADT"); memcpy(madt, (void *)address, sizeof(struct madt)); if (!check_sum((struct sdt_header *)madt)) warn("Corrupted MADT!"); @@ -83,36 +84,26 @@ void acpi_new_init(struct multiboot_tag_new_acpi *tag) void acpi_poweroff() { + // TODO: Add APCI poweroff support cli(); - /* - if (SCI_EN == 0) { - warn("ACPI shutdown is not supported"); - return; - } - - // Send shutdown command - outw((uint16_t)(unsigned int)PM1a_CNT, (uint16_t)(SLP_TYPa | SLP_EN)); - if (PM1b_CNT != 0) - outw((uint16_t)(unsigned int)PM1b_CNT, (uint16_t)(SLP_TYPb | SLP_EN)); - else { - outw(0xB004, 0x2000); // Bochs - outw(0x604, 0x2000); // QEMU - outw(0x4004, 0x3400); // VirtualBox - } - */ + outw(0x604, 0x2000); // QEMU + outw(0xB004, 0x2000); // Bochs + outw(0x4004, 0x3400); // VirtualBox + halt_loop(); } void reboot() { cli(); - outb(fadt->reset_reg.address, fadt->reset_value); - halt_loop(); - - /* else? - uint8_t good = 0x02; - while (good & 0x02) - good = inb(0x64); - outb(0x64, 0xFE); - halt_loop(); - */ + if (fadt->header.revision >= 2 && fadt->flags.reset_support) { + debug("Reset support!"); + outb(fadt->reset_reg.address, fadt->reset_value); + halt_loop(); + } else { + uint8_t good = 0x02; + while (good & 0x02) + good = inb(0x64); + outb(0x64, 0xFE); + halt_loop(); + } } diff --git a/src/kernel/acpi/acpi.h b/src/kernel/acpi/acpi.h index c9df040..055af2c 100644 --- a/src/kernel/acpi/acpi.h +++ b/src/kernel/acpi/acpi.h @@ -28,6 +28,33 @@ struct address_structure { uint64_t address; }; +// p. 138 +struct fadt_flags { + uint8_t WBINVD : 1; + uint8_t WBINVD_flush : 1; + uint8_t C1_support : 1; + uint8_t C2_mp_support : 1; + uint8_t power_button : 1; // 1 if not present + uint8_t sleep_button : 1; // 1 if not present + uint8_t rtc_fix_reg : 1; + uint8_t rtc_wakes_S4 : 1; + uint8_t timer_32 : 1; + uint8_t dock_support : 1; + uint8_t reset_support : 1; + uint8_t sealed_case : 1; + uint8_t headless : 1; + uint8_t slp_instruction : 1; + uint8_t pci_wake_support : 1; + uint8_t use_platform_clock : 1; + uint8_t rtc_valid_S4 : 1; + uint8_t remote_on_support : 1; + uint8_t force_apic_cluster : 1; + uint8_t force_apic_physical : 1; + uint8_t hw_reduced_acpi : 1; + uint8_t low_power_S0_support : 1; + uint16_t reserved : 10; +}; + struct rsdp { char signature[8]; char checksum; @@ -50,11 +77,12 @@ struct sdt_header { struct rsdt { struct sdt_header header; + uint32_t sdt_pointer[]; }; struct xsdt { struct sdt_header header; - uint32_t *sdt_pointer; + uint32_t sdt_pointer[]; }; struct fadt { @@ -96,7 +124,7 @@ struct fadt { uint8_t century; uint16_t boot_architecture_flags; // Reserved in 1.0 uint8_t reserved2; - uint32_t flags; + struct fadt_flags flags; struct address_structure reset_reg; uint8_t reset_value; uint8_t reserved3[3]; diff --git a/src/kernel/cmos/rtc.c b/src/kernel/cmos/rtc.c index 734c18a..a10f484 100644 --- a/src/kernel/cmos/rtc.c +++ b/src/kernel/cmos/rtc.c @@ -24,7 +24,7 @@ uint8_t get_rtc_register(int reg) void read_rtc() { - unsigned int century = 20; // ... + uint32_t century = 20; uint8_t last_second; uint8_t last_minute; uint8_t last_hour; diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index d3806fa..a0a1fb2 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -40,8 +40,8 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address) idt_install(); isrs_install(); irq_install(); - paging_install(multiboot_address); + multiboot_parse(multiboot_address); // Install drivers diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index 3901c39..6238535 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -80,17 +80,17 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag) mmap = (multiboot_memory_map_t *)((uint32_t)mmap + ((struct multiboot_tag_mmap *)tag)->entry_size)) { if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { - log("Found free memory"); + debug("Found free memory"); paging_set_present(mmap->addr, mmap->len >> 12); sum += mmap->len; } else if (mmap->type == MULTIBOOT_MEMORY_RESERVED) { - log("Found reserved memory"); + debug("Found reserved memory"); paging_set_present(mmap->addr, mmap->len >> 12); paging_set_used(mmap->addr, mmap->len >> 12); } else if (mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE) { - log("Found ACPI reclaimable memory"); + debug("Found ACPI reclaimable memory"); } else if (mmap->type == MULTIBOOT_MEMORY_NVS) { - log("Found NVS memory"); + debug("Found NVS memory"); } else if (mmap->type == MULTIBOOT_MEMORY_BADRAM) { warn("Found bad memory!"); } diff --git a/src/kernel/multiboot.c b/src/kernel/multiboot.c index 8f20662..fb96e10 100644 --- a/src/kernel/multiboot.c +++ b/src/kernel/multiboot.c @@ -15,57 +15,57 @@ void multiboot_parse(uint32_t multiboot_address) tag = (struct multiboot_tag *)((multiboot_uint8_t *)tag + ((tag->size + 7) & ~7))) { switch (tag->type) { case MULTIBOOT_TAG_TYPE_CMDLINE: - info("Got cmdline"); + debug("Got cmdline"); break; case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: - info("Got bootloader name: %s", + debug("Got bootloader name: %s", ((struct multiboot_tag_string *)tag)->string); break; case MULTIBOOT_TAG_TYPE_MODULE: - info("Got modules"); + debug("Got modules"); break; case MULTIBOOT_TAG_TYPE_BOOTDEV: - info("Got boot device"); + debug("Got boot device"); break; case MULTIBOOT_TAG_TYPE_VBE: - info("Got VBE info"); + debug("Got VBE debug"); break; case MULTIBOOT_TAG_TYPE_FRAMEBUFFER: - info("Got framebuffer info"); + debug("Got framebuffer debug"); break; case MULTIBOOT_TAG_TYPE_APM: - info("Got APM table"); + debug("Got APM table"); break; case MULTIBOOT_TAG_TYPE_EFI32: - info("Got EFI32"); + debug("Got EFI32"); break; case MULTIBOOT_TAG_TYPE_SMBIOS: // GRUB doesn't detect SMBIOS on QEMU! - info("Got SMBIOS table"); + debug("Got SMBIOS table"); smbios_init((struct multiboot_tag_smbios *)tag); break; case MULTIBOOT_TAG_TYPE_ACPI_OLD: - info("Got ACPI 1.0 table"); + debug("Got ACPI 1.0 table"); acpi_old_init((struct multiboot_tag_old_acpi *)tag); break; case MULTIBOOT_TAG_TYPE_ACPI_NEW: - info("Got ACPI 2.0 table"); + debug("Got ACPI 2.0 table"); acpi_new_init((struct multiboot_tag_new_acpi *)tag); break; case MULTIBOOT_TAG_TYPE_NETWORK: - info("Got network info"); + debug("Got network debug"); break; case MULTIBOOT_TAG_TYPE_EFI_MMAP: - info("Got EFI memory map"); + debug("Got EFI memory map"); break; case MULTIBOOT_TAG_TYPE_EFI_BS: - info("Got EFI boot services"); + debug("Got EFI boot services"); break; case MULTIBOOT_TAG_TYPE_EFI32_IH: - info("Got EFI image handler pointer"); + debug("Got EFI image handler pointer"); break; case MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR: - info("Got image load base address"); + debug("Got image load base address"); break; } } |