summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init/linker.ld24
-rw-r--r--src/init/main.c10
-rw-r--r--src/kernel/main.c9
-rw-r--r--src/kernel/util.c8
-rw-r--r--src/kernel/util.h1
-rw-r--r--src/test_module1
6 files changed, 50 insertions, 3 deletions
diff --git a/src/init/linker.ld b/src/init/linker.ld
new file mode 100644
index 0000000..9f3f4b5
--- /dev/null
+++ b/src/init/linker.ld
@@ -0,0 +1,24 @@
+ENTRY(main)
+OUTPUT_FORMAT("binary")
+
+SECTIONS
+{
+ . = 2M;
+ .text BLOCK(4K) : ALIGN(4K)
+ {
+ *(.text)
+ }
+ .rodata BLOCK(4K) : ALIGN(4K)
+ {
+ *(.rodata)
+ }
+ .data BLOCK(4K) : ALIGN(4K)
+ {
+ *(.data)
+ }
+ .bss BLOCK(4K) : ALIGN(4K)
+ {
+ *(COMMON)
+ *(.bss)
+ }
+}
diff --git a/src/init/main.c b/src/init/main.c
new file mode 100644
index 0000000..e6188ac
--- /dev/null
+++ b/src/init/main.c
@@ -0,0 +1,10 @@
+#include <stdint.h>
+
+int main() {
+ // change the colors of VGA text
+ // doesn't require a lot of code, but still shows that it's working
+ uint8_t *vga = (void*) 0xB8000;
+ for (int i = 0; i < 80 * 25; i++)
+ vga[(i << 1) + 1] = 0x4e;
+ for (;;);
+}
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 677faaf..7f49fed 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -3,16 +3,21 @@
#include <kernel/mem.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
+#include <kernel/util.h>
+#include <stdint.h>
void r3_test();
void kmain(struct kmain_info info) {
- log_write(info.init.at, info.init.size);
log_const("mem...");
mem_init(&info);
log_const("creating process...");
- struct process *proc = process_new(r3_test);
+
+ void *init_addr = (void*)0x200000;
+ memcpy(init_addr, info.init.at, info.init.size);
+
+ struct process *proc = process_new(init_addr);
log_const("switching...");
process_switch(proc);
}
diff --git a/src/kernel/util.c b/src/kernel/util.c
index da3ac9d..f4dc5e1 100644
--- a/src/kernel/util.c
+++ b/src/kernel/util.c
@@ -1,6 +1,14 @@
#include <kernel/util.h>
#include <stdint.h>
+void *memcpy(void *dest, const void *src, size_t n) {
+ char *d = dest;
+ const char *s = src;
+ for (size_t i = 0; i < n; i++)
+ d[i] = s[i];
+ return dest;
+}
+
void *memset(void *s, int c, size_t n) {
uint8_t *s2 = s;
for (size_t i = 0; i < n; n++)
diff --git a/src/kernel/util.h b/src/kernel/util.h
index 688ac63..4bd7c31 100644
--- a/src/kernel/util.h
+++ b/src/kernel/util.h
@@ -1,4 +1,5 @@
#pragma once
#include <stddef.h>
+void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
diff --git a/src/test_module b/src/test_module
deleted file mode 100644
index 4e809fd..0000000
--- a/src/test_module
+++ /dev/null
@@ -1 +0,0 @@
-[init binary goes here]