summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grapes/link.ld26
-rw-r--r--src/grapes/test/Makefile30
-rw-r--r--src/grapes/test/main.c8
-rw-r--r--src/stem/Makefile1
-rw-r--r--src/stem/core/kmain.c49
-rw-r--r--src/stem/linker/elf.c13
-rw-r--r--src/stem/mem/mem.c1
-rw-r--r--src/stem/mem/paging.c4
-rw-r--r--src/stem/stem.map340
-rw-r--r--src/stem/task/task.c6
-rw-r--r--src/stem/task/task.h2
11 files changed, 116 insertions, 364 deletions
diff --git a/src/grapes/link.ld b/src/grapes/link.ld
new file mode 100644
index 0000000..7527b80
--- /dev/null
+++ b/src/grapes/link.ld
@@ -0,0 +1,26 @@
+ENTRY (start)
+
+SECTIONS{
+ . = 0x10000000;
+
+ .text : {
+ *(.text)
+ }
+
+ .rodata ALIGN (0x1000) :{
+ *(.rodata)
+ }
+
+ .data ALIGN (0x1000) : {
+ *(.data)
+ }
+
+ .bss : {
+ sbss = .;
+ *(COMMON)
+ *(.bss)
+ ebss = .;
+ }
+
+ end = .; _end = .; __end = .;
+}
diff --git a/src/grapes/test/Makefile b/src/grapes/test/Makefile
new file mode 100644
index 0000000..ddcc36f
--- /dev/null
+++ b/src/grapes/test/Makefile
@@ -0,0 +1,30 @@
+.PHONY: clean, mrproper
+
+CC = gcc
+CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra
+
+LD = ld
+LDFLAGS = -T ../link.ld
+
+Objects = main.o
+Outfile = test
+
+all: $(Outfile)
+ echo "* Done with $(Outfile)"
+
+rebuild: mrproper all
+
+$(Outfile): $(Objects)
+ echo "* Linking $@..."
+ $(LD) $(LDFLAGS) -o $@ $^
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
+clean:
+ echo "* Removing objects..."
+ rm $(Objects)
+
+mrproper: clean
+ rm $(Outfile)
+
diff --git a/src/grapes/test/main.c b/src/grapes/test/main.c
new file mode 100644
index 0000000..d10ad35
--- /dev/null
+++ b/src/grapes/test/main.c
@@ -0,0 +1,8 @@
+void printk(char *s) {
+ asm volatile("int $64" : : "a"(4), "b"(s));
+}
+
+void start() {
+ printk("Hi world !");
+ asm volatile("int $64" : : "a"(0));
+}
diff --git a/src/stem/Makefile b/src/stem/Makefile
index 41b5368..fe42ea3 100644
--- a/src/stem/Makefile
+++ b/src/stem/Makefile
@@ -1,3 +1,4 @@
+.PHONY: clean, mrproper
CC = gcc
CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra -I . -I ./lib
diff --git a/src/stem/core/kmain.c b/src/stem/core/kmain.c
index 28c2df7..5b6c06e 100644
--- a/src/stem/core/kmain.c
+++ b/src/stem/core/kmain.c
@@ -8,29 +8,22 @@
#include <mem/gdt.h>
#include <mem/paging.h>
#include <mem/mem.h>
-
-void kmain_othertask(void *data) {
- uint32_t i;
- for(i = 0; i < 100; i++) {
- monitor_write("2task ");
- thread_sleep(0);
- }
- process_exit(0);
-}
-
-void kmain_stage2(void *data) {
- sti();
- thread_new(current_thread->process, kmain_othertask, 0);
- while (1) {
- monitor_write("TASK1 ");
- thread_sleep(0);
- }
-}
+#include <linker/elf.h>
void kmain(struct multiboot_info_t* mbd, int32_t magic) {
size_t totalRam = 0;
+ uint32_t i;
mem_placementAddr = (size_t)&end;
+ mbd->cmdline += 0xE0000000; mbd->mods_addr += 0xE0000000;
+ struct module_t *mods = (struct module_t*)mbd->mods_addr;
+ for (i = 0; i < mbd->mods_count; i++) {
+ mods[i].mod_start += 0xE0000000;
+ mods[i].mod_end += 0xE0000000;
+ mods[i].string += 0xE0000000;
+ if (mods[i].mod_end > mem_placementAddr)
+ mem_placementAddr = (mods[i].mod_end & 0xFFFFF000) + 0x1000;
+ }
monitor_clear();
@@ -48,5 +41,23 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) {
paging_cleanup();
kheap_init();
timer_init(20);
- tasking_init(kmain_stage2, 0);
+ tasking_init();
+
+ monitor_write("Loading modules...\n");
+ for (i = 0; i < mbd->mods_count; i++) {
+ monitor_write((char*)mods[i].string);
+ if (elf_check((uint8_t*)mods[i].mod_start)) {
+ monitor_write(" : Invalid ELF file\n");
+ } else {
+ if (elf_exec((uint8_t*)mods[i].mod_start) == 0) {
+ monitor_write(" : Error loading\n");
+ } else {
+ monitor_write(" : OK\n");
+ }
+ }
+ }
+
+ monitor_write("Passing conroll to loaded modules...\n");
+ sti();
+ tasking_switch();
}
diff --git a/src/stem/linker/elf.c b/src/stem/linker/elf.c
index 62030ee..dc7481b 100644
--- a/src/stem/linker/elf.c
+++ b/src/stem/linker/elf.c
@@ -2,6 +2,7 @@
#include <mem/paging.h>
#include <mem/seg.h>
#include <stdlib.h>
+#include <core/sys.h>
int elf_check(uint8_t *data) {
struct elf_ehdr *h = (struct elf_ehdr*)data;
@@ -29,3 +30,15 @@ thread_entry elf_load(uint8_t *data, struct process* process) {
}
return (thread_entry)ehdr->e_entry;
}
+
+struct process* elf_exec(uint8_t *data) {
+ if (elf_check(data)) return 0;
+
+ struct process* p = process_new(0, 0, PL_DRIVER);
+
+ thread_entry e = elf_load(data, p);
+
+ thread_new(p, e, 0);
+
+ return p;
+}
diff --git a/src/stem/mem/mem.c b/src/stem/mem/mem.c
index 02b3ac5..c96a29d 100644
--- a/src/stem/mem/mem.c
+++ b/src/stem/mem/mem.c
@@ -35,6 +35,7 @@ static void get_free_pages() {
freepages[freepagecount].virt = i;
freepages[freepagecount].phys = frame_alloc() * 0x1000;
page_map(pagedir_getPage(kernel_pagedir, i, 0), i, 0, 0);
+ freepagecount++;
} else {
if (mem_placementAddr & 0xFFFFF000) {
mem_placementAddr &= 0xFFFFF000;
diff --git a/src/stem/mem/paging.c b/src/stem/mem/paging.c
index 4d98e75..9b9c989 100644
--- a/src/stem/mem/paging.c
+++ b/src/stem/mem/paging.c
@@ -76,6 +76,10 @@ struct page_directory *pagedir_new() {
pd->tablesPhysical = kmalloc_page(&pd->physicalAddr);
pd->mappedSegs = 0;
+ for (i = 0; i < 1024; i++) {
+ pd->tables[i] = 0; pd->tablesPhysical[i] = 0;
+ }
+
for (i = 768; i < 1024; i++) {
pd->tables[i] = kernel_pagedir->tables[i];
pd->tablesPhysical[i] = kernel_pagedir->tablesPhysical[i];
diff --git a/src/stem/stem.map b/src/stem/stem.map
deleted file mode 100644
index a919c01..0000000
--- a/src/stem/stem.map
+++ /dev/null
@@ -1,340 +0,0 @@
-
-Allocating common symbols
-Common symbol size file
-
-idt_ptr 0x6 task/idt.o
-mem_placementAddr 0x4 mem/mem.o
-tasking_tmpStack 0x10000 task/task.o
-idt_entries 0x800 task/idt.o
-kernel_process 0x4 task/task.o
-idle_thread 0x4 task/task.o
-current_pagedir 0x4 mem/paging.o
-kernel_pagedir 0x4 mem/paging.o
-
-Memory Configuration
-
-Name Origin Length Attributes
-*default* 0x00000000 0xffffffff
-
-Linker script and memory map
-
- 0x00100000 . = 0x100000
-
-.setup 0x00100000 0x3a
- *(.setup)
- .setup 0x00100000 0x3a core/loader_.o
- 0x00100000 loader
- 0xe010003a . = (. + 0xe0000000)
-
-.text 0xe0100040 0x355a load address 0x00100040
- *(.text)
- .text 0xe0100040 0x25 core/loader_.o
- *fill* 0xe0100065 0x3 00
- .text 0xe0100068 0x126 core/kmain.o
- 0xe0100068 kmain_othertask
- 0xe01000a7 kmain_stage2
- 0xe01000eb kmain
- *fill* 0xe010018e 0x2 00
- .text 0xe0100190 0xf6 core/sys.o
- 0xe0100190 outb
- 0xe01001ae outw
- 0xe01001ce inb
- 0xe01001eb inw
- 0xe010020a panic
- 0xe010024e cli
- 0xe0100261 sti
- *fill* 0xe0100286 0x2 00
- .text 0xe0100288 0x310 core/monitor.o
- 0xe0100399 monitor_put
- 0xe01004a5 monitor_clear
- 0xe0100502 monitor_write
- 0xe010052b monitor_writeHex
- .text 0xe0100598 0x104 task/timer.o
- 0xe0100598 timer_callback
- 0xe01005d0 timer_uptime
- 0xe01005da timer_time
- 0xe0100611 timer_init
- .text 0xe010069c 0xa26 task/idt.o
- 0xe010069c idt_isrHandler
- 0xe0100734 idt_irqHandler
- 0xe01007d5 idt_syscallHandler
- 0xe0100882 idt_init
- 0xe01010b0 idt_handleIrq
- *fill* 0xe01010c2 0xe 00
- .text 0xe01010d0 0x293 task/idt_.o
- 0xe01010d0 gdt_flush
- 0xe01010ed idt_flush
- 0xe0101185 isr0
- 0xe010118f isr1
- 0xe0101199 isr2
- 0xe01011a3 isr3
- 0xe01011ad isr4
- 0xe01011b7 isr5
- 0xe01011c1 isr6
- 0xe01011cb isr7
- 0xe01011d5 isr8
- 0xe01011dd isr9
- 0xe01011e7 isr10
- 0xe01011ef isr11
- 0xe01011f7 isr12
- 0xe01011ff isr13
- 0xe0101207 isr14
- 0xe010120f isr15
- 0xe0101219 isr16
- 0xe0101223 isr17
- 0xe010122d isr18
- 0xe0101237 isr19
- 0xe0101241 isr20
- 0xe010124b isr21
- 0xe0101255 isr22
- 0xe010125f isr23
- 0xe0101269 isr24
- 0xe0101273 isr25
- 0xe010127d isr26
- 0xe0101287 isr27
- 0xe0101291 isr28
- 0xe010129b isr29
- 0xe01012a5 isr30
- 0xe01012af isr31
- 0xe01012b9 irq0
- 0xe01012c3 irq1
- 0xe01012cd irq2
- 0xe01012d7 irq3
- 0xe01012e1 irq4
- 0xe01012eb irq5
- 0xe01012f5 irq6
- 0xe01012ff irq7
- 0xe0101309 irq8
- 0xe0101313 irq9
- 0xe010131d irq10
- 0xe0101327 irq11
- 0xe0101331 irq12
- 0xe010133b irq13
- 0xe0101345 irq14
- 0xe010134f irq15
- 0xe0101359 syscall64
- *fill* 0xe0101363 0x1 00
- .text 0xe0101364 0x6f6 task/task.o
- 0xe0101364 tasking_init
- 0xe01014af tasking_switch
- 0xe0101556 tasking_updateKernelPagetable
- 0xe01015a0 tasking_handleException
- 0xe0101611 thread_sleep
- 0xe01016f5 thread_exit
- 0xe0101709 process_exit
- 0xe01017a5 thread_new
- 0xe010189a process_new
- *fill* 0xe0101a5a 0x6 00
- .text 0xe0101a60 0xa task/task_.o
- 0xe0101a60 read_eip
- 0xe0101a63 task_idle
- *fill* 0xe0101a6a 0x2 00
- .text 0xe0101a6c 0x66 task/syscall.o
- *fill* 0xe0101ad2 0x2 00
- .text 0xe0101ad4 0x13a lib/stdlib.o
- 0xe0101ad4 memcpy
- 0xe0101b7e memset
- 0xe0101bb0 memsetw
- 0xe0101be6 strlen
- *fill* 0xe0101c0e 0x2 00
- .text 0xe0101c10 0x173 lib/bitset.o
- 0xe0101c10 bitset_set
- 0xe0101c64 bitset_clear
- 0xe0101cba bitset_test
- 0xe0101cfc bitset_firstFree
- *fill* 0xe0101d83 0x1 00
- .text 0xe0101d84 0x29f mem/mem.o
- 0xe0101eea kmalloc_page
- 0xe0101f31 kfree_page
- 0xe0101f6c kheap_init
- 0xe0101fc1 kmalloc
- 0xe0101fff kfree
- *fill* 0xe0102023 0x1 00
- .text 0xe0102024 0x6cc mem/paging.o
- 0xe0102024 frame_alloc
- 0xe0102051 frame_free
- 0xe010206c paging_init
- 0xe0102213 paging_cleanup
- 0xe010226e pagedir_switch
- 0xe010229d pagedir_new
- 0xe0102332 pagedir_delete
- 0xe010239d paging_fault
- 0xe01024ea pagedir_getPage
- 0xe0102601 page_map
- 0xe0102689 page_unmap
- 0xe01026ac page_unmapFree
- .text 0xe01026f0 0x19f mem/gdt.o
- 0xe010277f gdt_init
- *fill* 0xe010288f 0x1 00
- .text 0xe0102890 0x858 mem/heap.o
- 0xe0102a20 heap_create
- 0xe0102df3 heap_alloc
- 0xe0102f54 heap_free
- .text 0xe01030e8 0x2ed mem/seg.o
- 0xe01030e8 seg_map
- 0xe0103156 seg_unmap
- 0xe0103235 simpleseg_make
- 0xe01032b2 simpleseg_map
- 0xe01032e8 simpleseg_unmap
- 0xe010333b simpleseg_handleFault
- 0xe01033d0 simpleseg_delete
- *fill* 0xe01033d5 0x3 00
- .text 0xe01033d8 0x1c2 linker/elf.o
- 0xe01033d8 elf_check
- 0xe010341d elf_load
-
-.iplt 0xe010359c 0x0 load address 0x0010359a
- .iplt 0x00000000 0x0 core/loader_.o
-
-.rodata 0xe0104000 0x395 load address 0x00104000
- *(.rodata)
- .rodata 0xe0104000 0x52 core/kmain.o
- .rodata 0xe0104052 0x2c core/sys.o
- .rodata 0xe010407e 0xf task/timer.o
- *fill* 0xe010408d 0x3 00
- .rodata 0xe0104090 0x8a task/idt.o
- *fill* 0xe010411a 0x6 00
- .rodata 0xe0104120 0x1ec task/task.o
- .rodata 0xe010430c 0x10 mem/mem.o
- .rodata 0xe010431c 0x71 mem/paging.o
- .rodata 0xe010438d 0x8 mem/gdt.o
-
-.rel.dyn 0xe0104398 0x0 load address 0x00104395
- .rel.iplt 0x00000000 0x0 core/loader_.o
- .rel.text 0x00000000 0x0 core/loader_.o
-
-.data 0xe0105000 0x24 load address 0x00105000
- *(.data)
- .data 0xe0105000 0x0 core/kmain.o
- .data 0xe0105000 0x4 core/sys.o
- .data 0xe0105004 0x4 core/monitor.o
- .data 0xe0105008 0x0 task/timer.o
- .data 0xe0105008 0x0 task/idt.o
- .data 0xe0105008 0x4 task/task.o
- .data 0xe010500c 0x18 task/syscall.o
- 0xe010500c syscalls
- .data 0xe0105024 0x0 lib/stdlib.o
- .data 0xe0105024 0x0 lib/bitset.o
- .data 0xe0105024 0x0 mem/mem.o
- .data 0xe0105024 0x0 mem/paging.o
- .data 0xe0105024 0x0 mem/gdt.o
- .data 0xe0105024 0x0 mem/heap.o
- .data 0xe0105024 0x0 mem/seg.o
- .data 0xe0105024 0x0 linker/elf.o
-
-.igot.plt 0xe0105024 0x0 load address 0x00105024
- .igot.plt 0x00000000 0x0 core/loader_.o
-
-.bss 0xe0105040 0x10970 load address 0x00105040
- 0xe0105040 sbss = .
- *(COMMON)
- COMMON 0xe0105040 0x820 task/idt.o
- 0xe0105040 idt_ptr
- 0xe0105060 idt_entries
- COMMON 0xe0105860 0x10008 task/task.o
- 0xe0105860 tasking_tmpStack
- 0xe0115860 kernel_process
- 0xe0115864 idle_thread
- COMMON 0xe0115868 0x4 mem/mem.o
- 0xe0115868 mem_placementAddr
- COMMON 0xe011586c 0x8 mem/paging.o
- 0xe011586c current_pagedir
- 0xe0115870 kernel_pagedir
- *(.bss)
- .bss 0xe0115874 0x0 core/kmain.o
- .bss 0xe0115874 0x0 core/sys.o
- .bss 0xe0115874 0x8 core/monitor.o
- .bss 0xe011587c 0xc task/timer.o
- *fill* 0xe0115888 0x18 00
- .bss 0xe01158a0 0x40 task/idt.o
- .bss 0xe01158e0 0xc task/task.o
- 0xe01158e0 processes
- 0xe01158e4 threads
- 0xe01158e8 current_thread
- .bss 0xe01158ec 0x0 task/syscall.o
- .bss 0xe01158ec 0x0 lib/stdlib.o
- .bss 0xe01158ec 0x0 lib/bitset.o
- *fill* 0xe01158ec 0x14 00
- .bss 0xe0115900 0x60 mem/mem.o
- 0xe0115900 freepagecount
- .bss 0xe0115960 0x8 mem/paging.o
- *fill* 0xe0115968 0x18 00
- .bss 0xe0115980 0x2e mem/gdt.o
- *fill* 0xe01159ae 0x2 00
- .bss 0xe01159b0 0x0 mem/heap.o
- .bss 0xe01159b0 0x0 mem/seg.o
- .bss 0xe01159b0 0x0 linker/elf.o
- 0xe01159b0 ebss = .
- 0xe01159b0 end = .
- 0xe01159b0 _end = .
- 0xe01159b0 __end = .
-LOAD core/loader_.o
-LOAD core/kmain.o
-LOAD core/sys.o
-LOAD core/monitor.o
-LOAD task/timer.o
-LOAD task/idt.o
-LOAD task/idt_.o
-LOAD task/task.o
-LOAD task/task_.o
-LOAD task/syscall.o
-LOAD lib/stdlib.o
-LOAD lib/bitset.o
-LOAD mem/mem.o
-LOAD mem/paging.o
-LOAD mem/gdt.o
-LOAD mem/heap.o
-LOAD mem/seg.o
-LOAD linker/elf.o
-OUTPUT(stem.elf elf32-i386)
-
-.comment 0x00000000 0x11
- .comment 0x00000000 0x11 core/kmain.o
- 0x12 (size before relaxing)
- .comment 0x00000000 0x12 core/sys.o
- .comment 0x00000000 0x12 core/monitor.o
- .comment 0x00000000 0x12 task/timer.o
- .comment 0x00000000 0x12 task/idt.o
- .comment 0x00000000 0x12 task/task.o
- .comment 0x00000000 0x12 task/syscall.o
- .comment 0x00000000 0x12 lib/stdlib.o
- .comment 0x00000000 0x12 lib/bitset.o
- .comment 0x00000000 0x12 mem/mem.o
- .comment 0x00000000 0x12 mem/paging.o
- .comment 0x00000000 0x12 mem/gdt.o
- .comment 0x00000000 0x12 mem/heap.o
- .comment 0x00000000 0x12 mem/seg.o
- .comment 0x00000000 0x12 linker/elf.o
-
-.note.GNU-stack
- 0x00000000 0x0
- .note.GNU-stack
- 0x00000000 0x0 core/kmain.o
- .note.GNU-stack
- 0x00000000 0x0 core/sys.o
- .note.GNU-stack
- 0x00000000 0x0 core/monitor.o
- .note.GNU-stack
- 0x00000000 0x0 task/timer.o
- .note.GNU-stack
- 0x00000000 0x0 task/idt.o
- .note.GNU-stack
- 0x00000000 0x0 task/task.o
- .note.GNU-stack
- 0x00000000 0x0 task/syscall.o
- .note.GNU-stack
- 0x00000000 0x0 lib/stdlib.o
- .note.GNU-stack
- 0x00000000 0x0 lib/bitset.o
- .note.GNU-stack
- 0x00000000 0x0 mem/mem.o
- .note.GNU-stack
- 0x00000000 0x0 mem/paging.o
- .note.GNU-stack
- 0x00000000 0x0 mem/gdt.o
- .note.GNU-stack
- 0x00000000 0x0 mem/heap.o
- .note.GNU-stack
- 0x00000000 0x0 mem/seg.o
- .note.GNU-stack
- 0x00000000 0x0 linker/elf.o
diff --git a/src/stem/task/task.c b/src/stem/task/task.c
index 5ab001c..0352308 100644
--- a/src/stem/task/task.c
+++ b/src/stem/task/task.c
@@ -25,7 +25,7 @@ struct thread *threads = 0, *current_thread = 0, *idle_thread;
uint32_t tasking_tmpStack[0x4000];
-void tasking_init(thread_entry whereToGo, void *data) {
+void tasking_init() {
cli();
kernel_process = kmalloc(sizeof(struct process)); //This process must be hidden to users
kernel_process->pid = kernel_process->uid = kernel_process->threads = 0;
@@ -36,10 +36,8 @@ void tasking_init(thread_entry whereToGo, void *data) {
current_thread = 0;
idle_thread = thread_new(kernel_process, task_idle, 0);
threads = 0; //Do not include idle thread in threads
- thread_new(kernel_process, whereToGo, data);
sti();
- monitor_write("Tasking starting\n");
- tasking_switch();
+ monitor_write("Tasking set up\n");
}
static struct thread *thread_next() {
diff --git a/src/stem/task/task.h b/src/stem/task/task.h
index 1d1d121..c9f1794 100644
--- a/src/stem/task/task.h
+++ b/src/stem/task/task.h
@@ -41,7 +41,7 @@ struct thread {
extern struct thread *current_thread;
-void tasking_init(thread_entry whereToGo, void *data);
+void tasking_init();
void tasking_switch();
void tasking_updateKernelPagetable(uint32_t idx, struct page_table *table, uint32_t tablePhysical);
uint32_t tasking_handleException(struct registers *regs);