diff options
author | the lemons <citrons@mondecitronne.com> | 2021-04-04 02:53:05 -0500 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2021-04-04 02:53:05 -0500 |
commit | 88b524543119a18297240a563cb8c08ff440dd53 (patch) | |
tree | 14fb52ad6374faafc0361c224fe5ca713caa8a8b | |
parent | ec5845bed56c0eb2350070f6d152f9c1070c06bc (diff) |
memory bookkeeping
-rwxr-xr-x | kernel.bin | bin | 87888 -> 89720 bytes | |||
-rw-r--r-- | os.iso | bin | 19890176 -> 19892224 bytes | |||
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/memory.c | 42 | ||||
-rw-r--r-- | src/memory.h | 35 | ||||
-rw-r--r-- | src/redacted.h | 11 |
6 files changed, 92 insertions, 3 deletions
Binary files differBinary files differ @@ -3,8 +3,8 @@ #include "vga.h" #include "interrupt.h" -#include "string.h" #include "multiboot.h" +#include "memory.h" #include "printf.h" extern void *gdt; @@ -29,11 +29,12 @@ const char *pope = "by means of its diplomatic relations and political accords with many \n" "independent states.\n"; -void kernel_main(multiboot_info_t *mbd) { +void kernel_main(multiboot_info_t *mb) { vsetcolor(vga_color(vga_black, vga_white)); vclear(); interrupt_init(); start_interrupts(); + init_memory(mb); vprint(" _ _ \n"); vprint(" ___(_) |_ _ __ ___ _ __ ___ ___ ___ \n"); @@ -43,5 +44,5 @@ void kernel_main(multiboot_info_t *mbd) { vprint(pope); - while (1) asm("hlt"); + while (1) asm volatile("hlt"); } diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000..970ba29 --- /dev/null +++ b/src/memory.c @@ -0,0 +1,42 @@ + +#include <stdint.h> +#include <limits.h> +#include <stddef.h> +#include "memory.h" +#include "multiboot.h" + +struct memory_area { + uint32_t len; + struct memory_area *next; +}; + +struct memory_area *first = NULL; + +void init_memory(multiboot_info_t *mb) { + struct memory_area *prev = NULL; + for ( + multiboot_memory_map_t *e = (multiboot_memory_map_t *) mb->mmap_addr; + (unsigned int) e < mb->mmap_addr + mb->mmap_length; + e += 1 + ) { + if (e->type != MULTIBOOT_MEMORY_AVAILABLE) continue; + // memory below 1MB is not safe to use. + if (e->addr < 1000000) continue; + // memory above UINT_MAX is unusable. + if (e->addr > UINT_MAX) continue; + + uint32_t length; + // if the memory reaches outside of UINT_MAX, truncate length value + if (e->addr + e->len > UINT_MAX) + length = UINT_MAX - e->addr; + else length = e->len; + + struct memory_area *cur = (struct memory_area *) e->addr; + cur->len = length; + + if (prev != NULL) + prev->next = (struct memory_area *) e->addr; + + prev = cur; + } +} diff --git a/src/memory.h b/src/memory.h new file mode 100644 index 0000000..3c38af7 --- /dev/null +++ b/src/memory.h @@ -0,0 +1,35 @@ +#ifndef __MEMORY_H +#define __MEMORY_H + +#include <stdint.h> +#include "redacted.h" +#include "multiboot.h" + +enum cell_type { + FREE_CELL, + CONS_CELL, + INT_CELL, + CHAR_CELL, + FLOAT_CELL, + ARRAY_CELL, + ARRAY_MEMBER, + APIOFORM +}; + +struct cell { + uint8_t type; + union car { + struct cell *free; + struct cell *cons; + struct {int type : 8; int size : 24;} ARRAY_CELL; + uint32_t int_; + uint32_t char_; + float float_; + REDACTED_t apioform; + }; + struct cell *cdr; +}; + +void init_memory(multiboot_info_t *mb); + +#endif diff --git a/src/redacted.h b/src/redacted.h new file mode 100644 index 0000000..5b5a667 --- /dev/null +++ b/src/redacted.h @@ -0,0 +1,11 @@ +#ifndef __REDACTED_H +#define __REDACTED_H + +typedef struct { + unsigned int type : 8; + unsigned int apiocity : 4; + int communism_value : 4; + int rotational_velocity : 16; +} REDACTED_t; + +#endif |