summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-16 16:48:56 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-16 16:48:56 -0400
commit730aafc1758e4096853c2491345901a296b4cc3e (patch)
tree45f8ffde614a9d30f0c93e1155fc6d799d10e94f /kernel
parentadd binary radix (%b) to printf (diff)
downloadcomus-730aafc1758e4096853c2491345901a296b4cc3e.tar.gz
comus-730aafc1758e4096853c2491345901a296b4cc3e.tar.bz2
comus-730aafc1758e4096853c2491345901a296b4cc3e.zip
remove all printing to report functions
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/acpi.c37
-rw-r--r--kernel/drivers/pci.c4
-rw-r--r--kernel/include/comus/drivers/acpi.h5
-rw-r--r--kernel/include/comus/drivers/pci.h5
-rw-r--r--kernel/include/comus/memory.h6
-rw-r--r--kernel/main.c14
-rw-r--r--kernel/mboot/mmap.c15
-rw-r--r--kernel/memory/physalloc.c43
8 files changed, 105 insertions, 24 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c
index bd9fe54..41f7ba1 100644
--- a/kernel/drivers/acpi.c
+++ b/kernel/drivers/acpi.c
@@ -1,7 +1,9 @@
+#include "lib/kio.h"
#include <lib.h>
#include <comus/drivers/acpi.h>
#include <comus/asm.h>
#include <comus/memory.h>
+#include <stdint.h>
struct acpi_header {
uint32_t signature;
@@ -295,7 +297,6 @@ static void acpi_load_table(uint64_t addr)
kunmapaddr(mapped);
return;
}
- kprintf("%.*s: %#016lx\n", 4, (char *)&mapped->signature, (size_t)temp);
acpi_handle_table(mapped);
}
@@ -311,20 +312,48 @@ void acpi_init(void *rootsdp)
}
if (rsdp->revision == 0) {
state.version = 0;
- kprintf("ACPI 1.0\n");
acpi_load_table(rsdp->rsdt_addr);
} else if (rsdp->revision == 2) {
state.version = 2;
struct xsdp *xsdp = (struct xsdp *)rsdp;
- kprintf("ACPI 2.0\n");
acpi_load_table(xsdp->xsdt_addr);
} else {
panic("invalid acpi rev: %d\n", rsdp->revision);
}
- kprintf("\n");
outb(state.fadt->smi_command_port, state.fadt->acpi_enable);
}
+void acpi_report(void)
+{
+ if (state.version == 0) {
+ kprintf("ACPI 1.0\n");
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.sdt.rsdt->h.signature,
+ (uintptr_t) state.sdt.rsdt);
+ } else {
+ kprintf("ACPI 2.0\n");
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.sdt.xsdt->h.signature,
+ (uintptr_t) state.sdt.xsdt);
+ }
+
+ if (state.fadt)
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.fadt->h.signature,
+ (uintptr_t) state.fadt);
+ if (state.dsdt)
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.dsdt->h.signature,
+ (uintptr_t) state.dsdt);
+ if (state.apic)
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.apic->h.signature,
+ (uintptr_t) state.apic);
+ if (state.hept)
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.hept->h.signature,
+ (uintptr_t) state.hept);
+ if (state.waet)
+ kprintf("%.*s: %#016lx\n", 4, (char *) &state.waet->h.signature,
+ (uintptr_t) state.waet);
+
+ kprintf("\n");
+}
+
void acpi_shutdown(void)
{
outw((unsigned int)state.fadt->pm1_a_control_block,
diff --git a/kernel/drivers/pci.c b/kernel/drivers/pci.c
index e84ca11..ce2583f 100644
--- a/kernel/drivers/pci.c
+++ b/kernel/drivers/pci.c
@@ -134,6 +134,10 @@ void pci_init(void)
}
}
}
+}
+
+void pci_report(void)
+{
kprintf("PCI DEVICES\n");
for (size_t i = 0; i < pci_table_next; i++) {
print_device(&pci_table[i]);
diff --git a/kernel/include/comus/drivers/acpi.h b/kernel/include/comus/drivers/acpi.h
index bb11860..f4948f7 100644
--- a/kernel/include/comus/drivers/acpi.h
+++ b/kernel/include/comus/drivers/acpi.h
@@ -15,6 +15,11 @@
void acpi_init(void *rsdp);
/**
+ * Report ACPI tables
+ */
+void acpi_report(void);
+
+/**
* Shutdowns down the system
*/
__attribute__((noreturn)) void acpi_shutdown(void);
diff --git a/kernel/include/comus/drivers/pci.h b/kernel/include/comus/drivers/pci.h
index 34bcdda..b06aca9 100644
--- a/kernel/include/comus/drivers/pci.h
+++ b/kernel/include/comus/drivers/pci.h
@@ -56,6 +56,11 @@ struct pci_device {
*/
void pci_init(void);
+/**
+ * Report all PCI devices
+ */
+void pci_report(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,
diff --git a/kernel/include/comus/memory.h b/kernel/include/comus/memory.h
index dec872d..ceca4aa 100644
--- a/kernel/include/comus/memory.h
+++ b/kernel/include/comus/memory.h
@@ -29,6 +29,7 @@
struct memory_segment {
uint64_t addr;
uint64_t len;
+ uint32_t type;
};
struct memory_map {
@@ -60,6 +61,11 @@ uint64_t memory_free(void);
uint64_t memory_used(void);
/**
+ * Reports system memory usage and map
+ */
+void memory_report(void);
+
+/**
* Allocate a new memory context
*
* @returns pointer context or NULL on failure
diff --git a/kernel/main.c b/kernel/main.c
index 4f91d95..f600320 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -1,10 +1,21 @@
+#include "lib/kio.h"
#include <comus/cpu.h>
#include <comus/memory.h>
#include <comus/mboot.h>
#include <comus/drivers.h>
+#include <comus/drivers/acpi.h>
+#include <comus/drivers/pci.h>
#include <comus/fs.h>
#include <lib.h>
+void kreport(void)
+{
+ cpu_report();
+ memory_report();
+ acpi_report();
+ pci_report();
+}
+
void main(long magic, volatile void *mboot)
{
// initalize idt and pic
@@ -22,6 +33,9 @@ void main(long magic, volatile void *mboot)
// load file systems
fs_init();
+ // report system state
+ kreport();
+
// halt
kprintf("halting...\n");
}
diff --git a/kernel/mboot/mmap.c b/kernel/mboot/mmap.c
index e93421d..8959c49 100644
--- a/kernel/mboot/mmap.c
+++ b/kernel/mboot/mmap.c
@@ -20,11 +20,6 @@ struct multiboot_tag_mmap {
struct multiboot_mmap_entry entries[];
};
-static const char *segment_type[] = { "Reserved", "Free",
- "Reserved", "ACPI Reserved",
- "Hibernation", "Defective",
- "Unknown" };
-
int mboot_get_mmap(struct memory_map *res)
{
void *tag = locate_mboot_table(MULTIBOOT_TAG_TYPE_MMAP);
@@ -35,22 +30,14 @@ int mboot_get_mmap(struct memory_map *res)
int idx = 0;
uintptr_t i = (uintptr_t)mmap->entries;
- kprintf("MEMORY MAP\n");
char buf[20];
for (; i < (uintptr_t)mmap->entries + mmap->size;
i += mmap->entry_size, idx++) {
struct multiboot_mmap_entry *seg = (struct multiboot_mmap_entry *)i;
const char *type = NULL;
- if (seg->type > 6)
- type = segment_type[6];
- else
- type = segment_type[seg->type];
- kprintf("ADDR: %16p LEN: %4s TYPE: %s (%d)\n", (void *)seg->addr,
- btoa(seg->len, buf), type, seg->type);
- if (seg->type != 1 || seg->len < 1)
- continue;
res->entries[idx].addr = seg->addr;
res->entries[idx].len = seg->len;
+ res->entries[idx].type = seg->type;
}
res->entry_count = idx;
diff --git a/kernel/memory/physalloc.c b/kernel/memory/physalloc.c
index 7083c21..328502f 100644
--- a/kernel/memory/physalloc.c
+++ b/kernel/memory/physalloc.c
@@ -1,3 +1,4 @@
+#include "lib/kio.h"
#include <lib.h>
#include <comus/memory.h>
#include <comus/asm.h>
@@ -16,8 +17,14 @@ static uint64_t total_memory;
static uint64_t free_memory;
static uint64_t page_count;
static uint64_t segment_count;
+struct memory_map phys_mmap;
struct memory_segment *page_start;
+static const char *segment_type_str[] = { "Reserved", "Free",
+ "Reserved", "ACPI Reserved",
+ "Hibernation", "Defective",
+ "Unknown" };
+
static int n_pages(const struct memory_segment *m)
{
return m->len / PAGE_SIZE;
@@ -115,6 +122,10 @@ void free_phys_pages(void *ptr, int pages)
static bool segment_invalid(const struct memory_segment *segment)
{
+ if (segment->len < 1)
+ return true;
+ if (segment->type != 1)
+ return true;
if (segment->addr < kaddr(kernel_start))
return true;
if (segment->addr + segment->len < memory_start)
@@ -161,6 +172,7 @@ void physalloc_init(struct memory_map *map)
free_memory = 0;
page_count = 0;
page_start = NULL;
+ phys_mmap = *map;
segment_count = 0;
@@ -209,12 +221,6 @@ void physalloc_init(struct memory_map *map)
total_memory = page_count * PAGE_SIZE;
page_count -= bitmap_pages;
free_memory = page_count * PAGE_SIZE;
-
- char buf[20];
- kprintf("\nMEMORY USAGE\n");
- kprintf("mem total: %s\n", btoa(memory_total(), buf));
- kprintf("mem free: %s\n", btoa(memory_free(), buf));
- kprintf("mem used: %s\n\n", btoa(memory_used(), buf));
}
uint64_t memory_total(void)
@@ -231,3 +237,28 @@ uint64_t memory_used(void)
{
return total_memory - free_memory;
}
+
+void memory_report(void)
+{
+ char buf[20];
+
+ kprintf("MEMORY MAP\n");
+ for (uint32_t i = 0; i < phys_mmap.entry_count; i++) {
+ struct memory_segment *seg;
+ const char *type_str;
+
+ seg = &phys_mmap.entries[i];
+ if (seg->type > 6)
+ type_str = segment_type_str[6];
+ else
+ type_str = segment_type_str[seg->type];
+
+ kprintf("ADDR: %16p LEN: %4s TYPE: %s (%d)\n", (void *)seg->addr,
+ btoa(seg->len, buf), type_str, seg->type);
+ }
+
+ kprintf("\nMEMORY USAGE\n");
+ kprintf("mem total: %s\n", btoa(memory_total(), buf));
+ kprintf("mem free: %s\n", btoa(memory_free(), buf));
+ kprintf("mem used: %s\n\n", btoa(memory_used(), buf));
+}