aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/Makefile2
-rw-r--r--apps/init.c13
-rw-r--r--apps/link.ld6
-rw-r--r--apps/wm.c13
-rw-r--r--kernel/Makefile4
-rw-r--r--kernel/features/event.c4
-rw-r--r--kernel/features/proc.c14
-rw-r--r--kernel/features/syscall.c25
-rw-r--r--kernel/inc/proc.h2
-rw-r--r--libc/Makefile14
-rw-r--r--libc/cpu.c2
-rw-r--r--libc/crt/crt0.asm15
-rw-r--r--libc/crt/crti.asm13
-rw-r--r--libc/crt/crtn.asm9
-rw-r--r--libc/inc/sys.h4
-rw-r--r--libgui/Makefile6
16 files changed, 105 insertions, 41 deletions
diff --git a/apps/Makefile b/apps/Makefile
index e36ec35..17af36a 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -9,7 +9,7 @@ OC = ../cross/opt/bin/i686-elf-objcopy
# TODO: Fix optimization flags (relocation of functions)
CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -O0
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-emain -I../libc/inc/ -I../libgui/inc/ -fPIE -Duserspace
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -I../libc/inc/ -I../libgui/inc/ -fPIE -Duserspace
all: $(COBJS)
diff --git a/apps/init.c b/apps/init.c
index de87798..64fbde3 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -8,11 +8,14 @@
#include <sys.h>
#include <vesa.h>
-void main(struct vbe *vbe)
+int main(int argc, char **argv)
{
- print("Init loaded.\n");
- int a = exec("/wm", vbe);
+ (void)argc;
- if (a)
- exit();
+ printf("ARGC: %d\n", argc);
+ printf("ARGV: %x\n", argv);
+ printf("%s loaded.\n", argv[0]);
+
+ exec("/wm", "wm", argv[1], NULL);
+ return 0;
}
diff --git a/apps/link.ld b/apps/link.ld
index 84b2e2f..2b9599a 100644
--- a/apps/link.ld
+++ b/apps/link.ld
@@ -1,14 +1,14 @@
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)
-ENTRY(main)
+STARTUP(libc.a) /* HUH */
+ENTRY(_start)
SECTIONS
{
. = 0x00000000;
.text : {
- *(.text.main)
- *(.text*)
+ *(.text)
}
.rodata : {
diff --git a/apps/wm.c b/apps/wm.c
index 5f9503e..c5347e4 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -16,11 +16,12 @@ void onkey(u32 scancode)
}
}
-void main(char **argv)
+int main(int argc, char **argv)
{
- struct vbe *vbe = (struct vbe *)argv[0];
+ struct vbe *vbe = (struct vbe *)argv[1];
- print("WM loaded.\n");
+ printf("%x\n", argc);
+ printf("%s loaded.\n", argv[0]);
printf("VBE: %dx%d\n", vbe->width, vbe->height);
const u32 color[3] = { 0, 0, 0 };
@@ -29,10 +30,10 @@ void main(char **argv)
gui_init("/font/spleen-16x32.psfu");
gui_write(vbe, 50, 50, text, "hallo");
- printf("onkey: %x\n", onkey);
- map(EVENT_KEYBOARD, onkey);
+ /* printf("onkey: %x\n", onkey); */
+ /* map(EVENT_KEYBOARD, onkey); */
while (1) {
};
- exit();
+ return 0;
}
diff --git a/kernel/Makefile b/kernel/Makefile
index e781141..e119933 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -20,9 +20,9 @@ AS = nasm
# Flags to make the binary smaller TODO: Remove after indirect pointer support!
CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -I../libc/inc/ -Iinc/ -Dkernel
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mno-red-zone -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -I../libc/inc/ -Iinc/ -Dkernel
-ASFLAGS = -f elf32 -O3
+ASFLAGS = -f elf32
all: compile bootloader
diff --git a/kernel/features/event.c b/kernel/features/event.c
index 02f5f1d..8fafb05 100644
--- a/kernel/features/event.c
+++ b/kernel/features/event.c
@@ -52,7 +52,7 @@ u32 event_trigger(enum event id, u32 *data)
struct node *iterator = ((struct list *)event_table[id])->head;
- if (!iterator->data) {
+ if (memcmp(event_table[id], 0, sizeof(struct list)) == 0) {
printf("Event %d not mapped!\n", id);
return 1;
}
@@ -65,7 +65,5 @@ u32 event_trigger(enum event id, u32 *data)
break;
}
- // TODO: Execute event function in ring3 with process stack, ...
- /* location(data); */
return 0;
}
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index b43b800..7eb6832 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -42,7 +42,7 @@ void scheduler(struct regs *regs)
if (current->event) {
// TODO: Modify and backup EIP
- printf("Event %d for %d\n", current->event, current->pid);
+ printf("Event %d for pid %d\n", current->event, current->pid);
// TODO: Clear bit after resolve
current->event = 0;
}
@@ -89,8 +89,9 @@ void proc_attach(struct proc *proc)
}
}
-void proc_exit()
+void proc_exit(int status)
{
+ printf("Process %d exited with status %d\n", current->pid, status);
current->state = PROC_ASLEEP;
}
@@ -121,7 +122,14 @@ void proc_init()
_eip = root->regs.eip;
_esp = root->regs.esp;
- ((u32 *)_esp)[1] = (u32)boot_passed->vbe; // First argument
+
+ char *args[] = { "init", (char *)boot_passed->vbe, NULL };
+
+ ((u32 *)_esp)[0] = 2; // First argument (argc)
+ ((u32 *)_esp)[1] = (u32)args; // Second argument (argv)
proc_jump_userspace();
+ printf("Returned!\n");
+ while (1) {
+ };
}
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 9d5ac82..02b17e5 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -15,53 +15,64 @@ void syscall_handler(struct regs *r)
{
enum sys num = r->eax;
r->eax = 0;
- printf("[SYSCALL] %d\n", num);
+ printf("[SYSCALL] %d: ", num);
switch (num) {
case SYS_LOOP: {
+ printf("loop\n");
loop();
break;
}
case SYS_MALLOC: {
+ printf("malloc\n");
r->eax = (u32)malloc(r->eax);
break;
}
case SYS_FREE: {
+ printf("free\n");
free(r->eax);
break;
}
case SYS_READ: {
+ printf("read\n");
r->eax = (u32)read_file((char *)r->ebx);
break;
}
case SYS_WRITE: {
+ printf("write\n");
// TODO: Write ext2 support
break;
}
case SYS_EXEC: {
+ printf("exec\n");
char *path = (char *)r->ebx;
struct proc *proc = proc_make();
- ((u32 *)proc->regs.esp)[0] = r->ecx;
- ((u32 *)proc->regs.esp)[1] = r->edx;
- ((u32 *)proc->regs.esp)[2] = r->esi;
- ((u32 *)proc->regs.esp)[3] = r->edi;
+
r->eax = bin_load(path, proc);
+ ((u32 *)proc->regs.useresp)[0] = 42;
+ ((char *)proc->regs.useresp)[1] = r->ecx;
+ ((char *)proc->regs.useresp)[2] = r->edx;
+ ((char *)proc->regs.useresp)[3] = r->esi;
+ ((char *)proc->regs.useresp)[4] = r->edi;
break;
}
case SYS_EXIT: {
- proc_exit();
+ printf("exit\n");
+ proc_exit(r->ebx);
break;
}
case SYS_MAP: {
+ printf("map\n");
event_map(r->ebx, (u32 *)r->ecx);
break;
}
case SYS_UNMAP: {
+ printf("unmap\n");
event_unmap(r->ebx, (u32 *)r->ecx);
break;
}
default: {
- printf("Unknown syscall!\n");
+ printf("unknown\n");
loop();
break;
}
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 1ed5df2..4c6ffaf 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -26,7 +26,7 @@ struct proc {
void proc_init();
void proc_print();
struct proc *proc_current();
-void proc_exit();
+void proc_exit(int status);
struct proc *proc_make();
#endif
diff --git a/libc/Makefile b/libc/Makefile
index f4286ae..d57b9c4 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -12,25 +12,29 @@ COBJS = str.o \
list.o
CC = ../cross/opt/bin/i686-elf-gcc
LD = ../cross/opt/bin/i686-elf-ld
-OC = ../cross/opt/bin/i686-elf-ar
+AR = ../cross/opt/bin/i686-elf-ar
+AS = nasm
# Flags to make the binary smaller TODO: Remove after indirect pointer support!
CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -fno-builtin -mno-red-zone -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/
+
+ASFLAGS = -f elf32
%.o: %.c
@$(CC) -c $(CFLAGS) $< -o $@
libc: CFLAGS += -Duserspace -fPIE
libc: $(COBJS)
+ @$(AS) $(ASFLAGS) crt/crt0.asm -o crt0.o
@mkdir -p ../build/
- @$(AR) qc ../build/libc.a $+
+ @$(AR) rcs ../build/libc.a crt0.o $+
-libk: CFLAGS += -Dkernel
+libk: CFLAGS += -Dkernel -ffreestanding
libk: $(COBJS)
@mkdir -p ../build/
- @$(AR) qc ../build/libk.a $+
+ @$(AR) rcs ../build/libk.a $+
clean:
@find . -name "*.o" -type f -delete
diff --git a/libc/cpu.c b/libc/cpu.c
index 5ed9de9..0425dc8 100644
--- a/libc/cpu.c
+++ b/libc/cpu.c
@@ -47,6 +47,7 @@ void outl(u16 port, u32 data)
__asm__ volatile("outl %0, %1" ::"a"(data), "Nd"(port));
}
+#ifdef kernel
void cli()
{
__asm__ volatile("cli");
@@ -73,3 +74,4 @@ void loop()
cli();
idle();
}
+#endif
diff --git a/libc/crt/crt0.asm b/libc/crt/crt0.asm
new file mode 100644
index 0000000..4d473ec
--- /dev/null
+++ b/libc/crt/crt0.asm
@@ -0,0 +1,15 @@
+; MIT License, Copyright (c) 2020 Marvin Borner
+
+section .text
+
+extern main
+extern sys1
+
+global _start
+_start:
+ call main
+
+ push edi
+ push 6
+ call sys1
+ jmp $
diff --git a/libc/crt/crti.asm b/libc/crt/crti.asm
new file mode 100644
index 0000000..394aaea
--- /dev/null
+++ b/libc/crt/crti.asm
@@ -0,0 +1,13 @@
+; MIT License, Copyright (c) 2020 Marvin Borner
+
+section .init
+global _init
+_init:
+ push ebp
+ mov ebp, esp
+
+section .fini
+global _fini
+fini:
+ push ebp
+ mov ebp, esp
diff --git a/libc/crt/crtn.asm b/libc/crt/crtn.asm
new file mode 100644
index 0000000..f20ec6a
--- /dev/null
+++ b/libc/crt/crtn.asm
@@ -0,0 +1,9 @@
+; MIT License, Copyright (c) 2020 Marvin Borner
+
+section .init
+ pop ebp
+ ret
+
+section .fini
+ pop ebp
+ ret
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index 88d83df..e776f44 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -35,9 +35,9 @@ int sysv(enum sys num, ...);
#define read(path) (void *)sys1(SYS_READ, (int)path)
#define write(path, buf) sys2(SYS_WRITE, (int)path, buf)
#define exec(path, ...) sysv(SYS_EXEC, (int)path, ##__VA_ARGS__)
-#define exit() \
+#define exit(status) \
{ \
- sys0(SYS_EXIT); \
+ sys1(SYS_EXIT, (int)status); \
while (1) { \
} \
}
diff --git a/libgui/Makefile b/libgui/Makefile
index 59254d4..bcd2016 100644
--- a/libgui/Makefile
+++ b/libgui/Makefile
@@ -5,12 +5,12 @@ COBJS = vesa.o \
gui.o
CC = ../cross/opt/bin/i686-elf-gcc
LD = ../cross/opt/bin/i686-elf-ld
-OC = ../cross/opt/bin/i686-elf-ar
+AR = ../cross/opt/bin/i686-elf-ar
# Flags to make the binary smaller TODO: Remove after indirect pointer support!
CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ -I../libc/inc/ -Duserspace -fPIE
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ -I../libc/inc/ -Duserspace -fPIE
all: libgui clean
@@ -19,7 +19,7 @@ all: libgui clean
libgui: $(COBJS)
@mkdir -p ../build/
- @$(AR) qc ../build/libgui.a $+
+ @$(AR) rcs ../build/libgui.a $+
clean:
@find . -name "*.o" -type f -delete