summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2021-04-04 02:53:05 -0500
committerthe lemons <citrons@mondecitronne.com>2021-04-04 02:53:05 -0500
commit88b524543119a18297240a563cb8c08ff440dd53 (patch)
tree14fb52ad6374faafc0361c224fe5ca713caa8a8b
parentec5845bed56c0eb2350070f6d152f9c1070c06bc (diff)
memory bookkeeping
-rwxr-xr-xkernel.binbin87888 -> 89720 bytes
-rw-r--r--os.isobin19890176 -> 19892224 bytes
-rw-r--r--src/main.c7
-rw-r--r--src/memory.c42
-rw-r--r--src/memory.h35
-rw-r--r--src/redacted.h11
6 files changed, 92 insertions, 3 deletions
diff --git a/kernel.bin b/kernel.bin
index a3d698f..1043589 100755
--- a/kernel.bin
+++ b/kernel.bin
Binary files differ
diff --git a/os.iso b/os.iso
index 9c9759f..a095b2f 100644
--- a/os.iso
+++ b/os.iso
Binary files differ
diff --git a/src/main.c b/src/main.c
index 0022a4c..a17db9a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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