aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--apps/Makefile2
-rw-r--r--apps/init.c3
-rw-r--r--apps/link.ld29
-rw-r--r--boot/load.c2
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/drivers/fb.c12
-rw-r--r--kernel/features/load.c5
-rw-r--r--kernel/features/mm.c26
-rw-r--r--kernel/features/syscall.c10
-rw-r--r--kernel/inc/fb.h2
-rw-r--r--kernel/inc/mm.h9
-rw-r--r--kernel/link.ld2
-rw-r--r--kernel/main.c2
14 files changed, 48 insertions, 62 deletions
diff --git a/Makefile b/Makefile
index f08c26b..e086c05 100644
--- a/Makefile
+++ b/Makefile
@@ -7,8 +7,8 @@ CFLAGS_DEFAULT = $(CFLAGS_WARNINGS) $(CFLAGS_OPTIMIZATION) -std=c99 -m32 -nostdl
all: compile
# TODO: Fix stack protector in userspace
-# TODO: Fix ubsan in userspace (probably due to kernel size)
-debug: CFLAGS_DEFAULT += -Wno-error -ggdb3 -s #-fsanitize=undefined #-fstack-protector-all
+# TODO: Fix ubsan in userspace - Os should be a temporary fix
+debug: CFLAGS_DEFAULT += -Wno-error -ggdb3 -s -Os -fsanitize=undefined -fstack-protector-all
debug: compile
export
diff --git a/apps/Makefile b/apps/Makefile
index 66f8e42..d43104a 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -13,7 +13,7 @@ all: $(COBJS)
%.o: %.c
@mkdir -p ../build/apps/
@$(CC) -c $(CFLAGS) $< -o $@
- @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ -static $@ -lgui -ltxt -lc
+ @$(LD) -o $(@:.o=.elf) --section-start=.text=0x42000000 -L../build/ -static $@ -lgui -ltxt -lc
@cp $(@:.o=.elf) ../build/apps/$(@:.o=)
#@$(ST) --strip-all ../build/apps/$(@:.o=)
diff --git a/apps/init.c b/apps/init.c
index 221708e..35d296b 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -8,9 +8,8 @@ int main(int argc, char **argv)
{
UNUSED(argc);
UNUSED(argv);
- log("Arrived!\n");
- /* assert(exec("/bin/wm", "wm", NULL) == 0); */
+ assert(exec("/bin/wm", "wm", NULL) == 0);
/* assert(exec("/bin/window", "test", NULL) == 0); */
return 0;
diff --git a/apps/link.ld b/apps/link.ld
deleted file mode 100644
index e28bb34..0000000
--- a/apps/link.ld
+++ /dev/null
@@ -1,29 +0,0 @@
-OUTPUT_FORMAT("elf32-i386")
-OUTPUT_ARCH(i386)
-ENTRY(_start)
-
-SECTIONS
-{
- . = 0x40000000;
-
- .text : {
- code = .;
- *(.text)
- *(.rodata)
- . = ALIGN(4096);
- }
-
- .data : {
- data = .;
- *(.data)
- . = ALIGN(4096);
- }
-
- .bss : {
- bss = .;
- *(.bss)
- . = ALIGN(4096);
- }
-
- . = ALIGN(4096);
-}
diff --git a/boot/load.c b/boot/load.c
index 34c6af8..4a6f3db 100644
--- a/boot/load.c
+++ b/boot/load.c
@@ -336,7 +336,7 @@ void *read_inode(struct inode *in)
if (!num_blocks)
return 0;
- void *buf = (void *)0x50000;
+ void *buf = (void *)0x9000;
//assert(buf != 0);
int indirect;
diff --git a/kernel/Makefile b/kernel/Makefile
index 1d9e87a..64035e5 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -36,5 +36,5 @@ all: compile
compile: $(COBJS)
@mkdir -p ../build/
- @$(LD) -N -z undefs -ekernel_main -Ttext 0x00050000 -o ../build/kernel.elf -L../build/ $+ -lk
+ @$(LD) -N -z undefs -ekernel_main -Ttext 0x00009000 -o ../build/kernel.elf -L../build/ $+ -lk
@$(LD) -N -z max-page-size=0x1000 -Tlink.ld -o ../build/kernel.bin -L../build/ $+ -lk
diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c
index af8a830..2db05f2 100644
--- a/kernel/drivers/fb.c
+++ b/kernel/drivers/fb.c
@@ -33,11 +33,8 @@ static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct devi
case IO_FB_GET: {
if (!info)
return -1;
- struct vbe_basic *vbe = (struct vbe_basic *)info->vbe;
memcpy(arg1, info->vbe, sizeof(struct vbe_basic));
- u32 size = vbe->height * vbe->pitch;
- memory_map_identity(proc_current()->page_dir,
- memory_range_around((u32)vbe->fb, size), MEMORY_USER);
+ fb_map_buffer(proc_current()->page_dir, info);
return 0;
}
default:
@@ -50,6 +47,13 @@ static s32 fb_ready(void)
return 1;
}
+void fb_map_buffer(struct page_dir *dir, struct vid_info *boot)
+{
+ struct vbe_basic *vbe = (struct vbe_basic *)boot->vbe;
+ u32 size = vbe->height * vbe->pitch;
+ memory_map_identity(dir, memory_range_around((u32)vbe->fb, size), MEMORY_USER);
+}
+
void fb_install(struct vid_info *boot)
{
info = boot;
diff --git a/kernel/features/load.c b/kernel/features/load.c
index d3f3495..3430a75 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -104,9 +104,8 @@ s32 elf_load(const char *path, struct proc *proc)
struct memory_range prange = physical_alloc(vrange.size);
virtual_map(proc->page_dir, prange, vrange.base, MEMORY_CLEAR | MEMORY_USER);
- if ((u32)vfs_read(path, (void *)program.vaddr, program.offset, program.filesz) !=
- program.filesz) {
- print("OH NOSE!\n");
+ if ((u32)vfs_read(proc->name, (void *)program.vaddr, program.offset,
+ program.filesz) != program.filesz) {
memory_switch_dir(prev);
return -ENOEXEC;
}
diff --git a/kernel/features/mm.c b/kernel/features/mm.c
index b06657f..b804076 100644
--- a/kernel/features/mm.c
+++ b/kernel/features/mm.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include <cpu.h>
#include <def.h>
+#include <fb.h>
#include <mem.h>
#include <mm.h>
#include <print.h>
@@ -15,23 +16,23 @@ static struct page_table kernel_tables[PAGE_KERNEL_COUNT] ALIGNED(PAGE_SIZE) = {
* Lowlevel paging
*/
-/*static void paging_disable(void)
+static void paging_switch_dir(u32 dir)
+{
+ cr3_set(dir);
+}
+
+extern void paging_invalidate_tlb(void);
+
+/*void paging_disable(void)
{
cr0_set(cr0_get() | 0x7fffffff);
}*/
-static void paging_enable(void)
+void paging_enable(void)
{
cr0_set(cr0_get() | 0x80000000);
}
-static void paging_switch_dir(u32 dir)
-{
- cr3_set(dir);
-}
-
-extern void paging_invalidate_tlb(void);
-
void page_fault_handler(struct regs *r)
{
print("--- PAGE FAULT! ---\n");
@@ -415,12 +416,12 @@ void memory_backup_dir(struct page_dir **backup)
static u8 memory_bypass_validity = 0;
void memory_bypass_enable(void)
{
- memory_bypass_validity = 1;
+ /* memory_bypass_validity = 1; */
}
void memory_bypass_disable(void)
{
- memory_bypass_validity = 0;
+ /* memory_bypass_validity = 0; */
}
// TODO: Limit by proc stack and data range
@@ -506,9 +507,10 @@ void memory_install(struct mem_info *mem_info, struct vid_info *vid_info)
memory_map_identity(&kernel_dir, memory_range_around(STACK_START - STACK_SIZE, STACK_SIZE),
MEMORY_NONE);
- // Map VBE data
+ // Map framebuffer
memory_map_identity(&kernel_dir, memory_range_around((u32)vid_info->vbe, 0x1000),
MEMORY_NONE);
+ fb_map_buffer(virtual_kernel_dir(), vid_info);
// Unmap NULL byte/page
struct memory_range zero = memory_range(0, PAGE_SIZE);
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 2334947..7d68d93 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -73,11 +73,13 @@ static void syscall_handler(struct regs *r)
char *path = (char *)r->ebx;
struct proc *proc = proc_make(PROC_PRIV_NONE);
r->eax = (u32)elf_load(path, proc);
- if (r->eax != 0)
+ if (r->eax != 0) {
proc_exit(proc, -r->eax);
- // TODO: Reimplement argc,argv
- proc_stack_push(proc, 0);
- proc_yield(r);
+ } else {
+ // TODO: Reimplement argc,argv
+ proc_stack_push(proc, 0);
+ proc_yield(r);
+ }
break;
}
case SYS_EXIT: {
diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h
index 212230b..3b545fd 100644
--- a/kernel/inc/fb.h
+++ b/kernel/inc/fb.h
@@ -4,7 +4,9 @@
#define FB_H
#include <boot.h>
+#include <mm.h>
+void fb_map_buffer(struct page_dir *dir, struct vid_info *boot);
void fb_install(struct vid_info *boot);
#endif
diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h
index 98dcf46..5a307b2 100644
--- a/kernel/inc/mm.h
+++ b/kernel/inc/mm.h
@@ -13,6 +13,13 @@ struct memory_range {
};
/**
+ * Lowlevel paging
+ */
+
+void paging_enable(void);
+void page_fault_handler(struct regs *r);
+
+/**
* Physical
*/
@@ -109,6 +116,4 @@ u8 memory_valid(const void *addr);
void memory_install(struct mem_info *mem_info, struct vid_info *vid_info);
-void page_fault_handler(struct regs *r);
-
#endif
diff --git a/kernel/link.ld b/kernel/link.ld
index 5a63e33..fbe8a8c 100644
--- a/kernel/link.ld
+++ b/kernel/link.ld
@@ -1,7 +1,7 @@
OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386)
ENTRY(kernel_main)
-phys = 0x00050000;
+phys = 0x00009000;
SECTIONS
{
diff --git a/kernel/main.c b/kernel/main.c
index 5c5299e..3ff0463 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -27,6 +27,8 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info)
serial_print("Serial connected.\n");
memory_install(mem_info, vid_info);
+ memory_switch_dir(virtual_kernel_dir());
+ paging_enable();
cpu_enable_features();
cpu_print();