better print and mem

This commit is contained in:
Freya Murphy 2024-02-02 10:31:51 -05:00
parent 179ddf64c1
commit 95f52a55ad
Signed by: freya
GPG key ID: 744AB800E383AE52
6 changed files with 33 additions and 11 deletions

View file

@ -8,7 +8,6 @@
struct memory_segment { struct memory_segment {
uint64_t addr; uint64_t addr;
uint64_t len; uint64_t len;
uint32_t type;
}; };
struct memory_map { struct memory_map {

View file

@ -300,7 +300,7 @@ static int debugger_prompt(struct isr_regs *state) {
case 's': // step (n) case 's': // step (n)
rflags->tf = 1; rflags->tf = 1;
dbg_steps = atol(buf + 1) - 1; dbg_steps = atol(buf + 1) - 1;
if (dbg_steps < 0) dbg_steps = 0; //if (dbg_steps < 0) dbg_steps = 0;
return 0; return 0;
case 'b': // breakpoints case 'b': // breakpoints
{ {

View file

@ -133,19 +133,43 @@ static void read_cmdline(
shim_info->cmdline[size] = '\0'; shim_info->cmdline[size] = '\0';
} }
static const char *segment_type[] = {
"Reserved",
"Free",
"Reserved",
"ACPI Reserved",
"Hibernation",
"Defective",
"Unknown"
};
static void read_memory_map( static void read_memory_map(
struct boot_info *shim_info, struct boot_info *shim_info,
struct mboot_tag_mmap *map struct mboot_tag_mmap *map
) { ) {
int idx = 0; int idx = 0;
uintptr_t i = (uintptr_t)map->entries; uintptr_t i = (uintptr_t)map->entries;
kprintf("MEMORY MAP\n");
char buf[20];
for ( ; for ( ;
i < (uintptr_t)map->entries + map->size; i < (uintptr_t)map->entries + map->size;
i += map->entry_size, idx++ i += map->entry_size, idx++
) { ) {
struct mboot_mmap_entry *seg = (struct mboot_mmap_entry *) i; 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].addr = seg->addr;
shim_info->map.entries[idx].type = seg->type;
shim_info->map.entries[idx].len = seg->len; shim_info->map.entries[idx].len = seg->len;
} }
shim_info->map.entry_count = idx; shim_info->map.entry_count = idx;

View file

@ -109,7 +109,6 @@ void free_phys_pages(void *ptr, int pages) {
} }
static bool segment_invalid(const struct memory_segment *segment) { 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 < kaddr(kernel_start)) return true;
if (segment->addr + segment->len < memory_start) return true; if (segment->addr + segment->len < memory_start) return true;
if (segment->addr + segment->len < kaddr(kernel_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; struct memory_area *area = page_start;
kprintf("MEMORY MAP\n");
for (uint32_t i = 0; i < map->entry_count; i++) { for (uint32_t i = 0; i < map->entry_count; i++) {
struct memory_segment *segment = &map->entries[i]; struct memory_segment *segment = &map->entries[i];
if (segment_invalid(segment)) if (segment_invalid(segment))
continue; continue;
kprintf("addr: 0x%16p\tlen: %ld\n", (void *)segment->addr, segment->len);
struct memory_area temp = segment_to_area(segment); struct memory_area temp = segment_to_area(segment);
*area = temp; *area = temp;

View file

@ -129,13 +129,9 @@ static void merge_back(struct addr_node *node) {
} }
static void merge_forward(struct addr_node *node) { static void merge_forward(struct addr_node *node) {
<<<<<<< HEAD
while (node->next && !node->is_alloc) {
=======
while(node->next) { while(node->next) {
if (node->is_alloc != node->next->is_alloc) if (node->is_alloc != node->next->is_alloc)
break; break;
>>>>>>> ea2de5a (looping kalloc can allocate all of memory (sometimes) :3)
struct addr_node *temp = node->next; struct addr_node *temp = node->next;
node->end = temp->end; node->end = temp->end;
node->next = temp->next; node->next = temp->next;

View file

@ -344,7 +344,7 @@ static void print_unum(
bool space_pre = (flag & FLG_LEFT_ALIGN) || !(flag & FLG_ZERO); 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'); char x = base + ('x' - 'a');
serial_out('0'); serial_out('0');
serial_out(x); serial_out(x);
@ -372,6 +372,12 @@ static void print_unum(
zero_padded = true; zero_padded = true;
} }
if (space_pre && radix == 16 && flag & FLG_ALTERNATE) {
char x = base + ('x' - 'a');
serial_out('0');
serial_out(x);
}
kputs(str); kputs(str);
if (!zero_padded && (flag & FLG_ALTERNATE) && radix == 8) if (!zero_padded && (flag & FLG_ALTERNATE) && radix == 8)