summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-02 10:31:51 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-02 10:31:51 -0500
commit95f52a55ad556d956c483abfc28a11603b75f4a8 (patch)
tree210868e9cc62b47c0941cddc836c1f2212d8ff6f
parentmerge virtnodes on alloc (diff)
downloadcorn-95f52a55ad556d956c483abfc28a11603b75f4a8.tar.gz
corn-95f52a55ad556d956c483abfc28a11603b75f4a8.tar.bz2
corn-95f52a55ad556d956c483abfc28a11603b75f4a8.zip
better print and mem
-rw-r--r--include/shim.h1
-rw-r--r--src/arch/amd64/debugger.c2
-rw-r--r--src/arch/amd64/mboot.c26
-rw-r--r--src/memory/physalloc.c3
-rw-r--r--src/memory/virtalloc.c4
-rw-r--r--src/print.c8
6 files changed, 33 insertions, 11 deletions
diff --git a/include/shim.h b/include/shim.h
index 7178a0f..2bf9726 100644
--- a/include/shim.h
+++ b/include/shim.h
@@ -8,7 +8,6 @@
struct memory_segment {
uint64_t addr;
uint64_t len;
- uint32_t type;
};
struct memory_map {
diff --git a/src/arch/amd64/debugger.c b/src/arch/amd64/debugger.c
index 4df59f7..2356e4a 100644
--- a/src/arch/amd64/debugger.c
+++ b/src/arch/amd64/debugger.c
@@ -300,7 +300,7 @@ static int debugger_prompt(struct isr_regs *state) {
case 's': // step (n)
rflags->tf = 1;
dbg_steps = atol(buf + 1) - 1;
- if (dbg_steps < 0) dbg_steps = 0;
+ //if (dbg_steps < 0) dbg_steps = 0;
return 0;
case 'b': // breakpoints
{
diff --git a/src/arch/amd64/mboot.c b/src/arch/amd64/mboot.c
index f39dd79..315747e 100644
--- a/src/arch/amd64/mboot.c
+++ b/src/arch/amd64/mboot.c
@@ -133,19 +133,43 @@ static void read_cmdline(
shim_info->cmdline[size] = '\0';
}
+static const char *segment_type[] = {
+ "Reserved",
+ "Free",
+ "Reserved",
+ "ACPI Reserved",
+ "Hibernation",
+ "Defective",
+ "Unknown"
+};
+
static void read_memory_map(
struct boot_info *shim_info,
struct mboot_tag_mmap *map
) {
int idx = 0;
uintptr_t i = (uintptr_t)map->entries;
+ kprintf("MEMORY MAP\n");
+ char buf[20];
for ( ;
i < (uintptr_t)map->entries + map->size;
i += map->entry_size, idx++
) {
struct mboot_mmap_entry *seg = (struct mboot_mmap_entry *) i;
+ const char *type = NULL;
+ if (seg->type > 4)
+ type = segment_type[6];
+ else
+ type = segment_type[seg->type];
+ kprintf("ADDR: 0x%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;
shim_info->map.entries[idx].addr = seg->addr;
- shim_info->map.entries[idx].type = seg->type;
shim_info->map.entries[idx].len = seg->len;
}
shim_info->map.entry_count = idx;
diff --git a/src/memory/physalloc.c b/src/memory/physalloc.c
index b0dbdcd..3115e35 100644
--- a/src/memory/physalloc.c
+++ b/src/memory/physalloc.c
@@ -109,7 +109,6 @@ void free_phys_pages(void *ptr, int pages) {
}
static bool segment_invalid(const struct memory_segment *segment) {
- if (segment->type != 1) return true;
if (segment->addr < kaddr(kernel_start)) return true;
if (segment->addr + segment->len < memory_start) return true;
if (segment->addr + segment->len < kaddr(kernel_start)) return true;
@@ -188,14 +187,12 @@ void memory_init(struct memory_map *map) {
struct memory_area *area = page_start;
- kprintf("MEMORY MAP\n");
for (uint32_t i = 0; i < map->entry_count; i++) {
struct memory_segment *segment = &map->entries[i];
if (segment_invalid(segment))
continue;
- kprintf("addr: 0x%16p\tlen: %ld\n", (void *)segment->addr, segment->len);
struct memory_area temp = segment_to_area(segment);
*area = temp;
diff --git a/src/memory/virtalloc.c b/src/memory/virtalloc.c
index f59e8e3..a1d7294 100644
--- a/src/memory/virtalloc.c
+++ b/src/memory/virtalloc.c
@@ -129,13 +129,9 @@ static void merge_back(struct addr_node *node) {
}
static void merge_forward(struct addr_node *node) {
-<<<<<<< HEAD
- while (node->next && !node->is_alloc) {
-=======
while(node->next) {
if (node->is_alloc != node->next->is_alloc)
break;
->>>>>>> ea2de5a (looping kalloc can allocate all of memory (sometimes) :3)
struct addr_node *temp = node->next;
node->end = temp->end;
node->next = temp->next;
diff --git a/src/print.c b/src/print.c
index f158985..712df30 100644
--- a/src/print.c
+++ b/src/print.c
@@ -344,7 +344,7 @@ static void print_unum(
bool space_pre = (flag & FLG_LEFT_ALIGN) || !(flag & FLG_ZERO);
- if (space_pre && radix == 16 && flag & FLG_ALTERNATE) {
+ if (!space_pre && radix == 16 && flag & FLG_ALTERNATE) {
char x = base + ('x' - 'a');
serial_out('0');
serial_out(x);
@@ -372,6 +372,12 @@ static void print_unum(
zero_padded = true;
}
+ if (space_pre && radix == 16 && flag & FLG_ALTERNATE) {
+ char x = base + ('x' - 'a');
+ serial_out('0');
+ serial_out(x);
+ }
+
kputs(str);
if (!zero_padded && (flag & FLG_ALTERNATE) && radix == 8)