aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-08-15 14:21:52 +0200
committerMarvin Borner2020-08-15 14:21:52 +0200
commit32b8722128dfb4ca9e814940a23c2b22a283bb12 (patch)
tree80c881a7717dc129fd11baaf98cd8b226fd30c67
parent162c84cfe6b4652bae213776944b910390553d41 (diff)
Added some syscall wrappers
-rw-r--r--apps/a.c6
-rw-r--r--apps/b.c4
-rw-r--r--apps/init.c12
-rw-r--r--kernel/drivers/interrupts.c2
-rw-r--r--kernel/drivers/timer.c2
-rw-r--r--kernel/features/load.c6
-rw-r--r--kernel/features/proc.c5
-rw-r--r--kernel/features/syscall.c7
-rw-r--r--kernel/inc/load.h2
-rw-r--r--kernel/inc/proc.h1
-rw-r--r--lib/inc/mem.h1
-rw-r--r--lib/inc/sys.h13
12 files changed, 38 insertions, 23 deletions
diff --git a/apps/a.c b/apps/a.c
index 448bedd..b49e7f9 100644
--- a/apps/a.c
+++ b/apps/a.c
@@ -2,13 +2,11 @@
#include <def.h>
#include <print.h>
-#include <sys.h>
void main()
{
- print("\nA loaded!\n");
- sys0(SYS_LOOP);
+ print("\nA loaded.\n");
while (1) {
- print("a");
+ print("A");
}
}
diff --git a/apps/b.c b/apps/b.c
index 1ed9249..504a5fd 100644
--- a/apps/b.c
+++ b/apps/b.c
@@ -5,8 +5,8 @@
void main()
{
- print("\nB loaded\n");
+ print("\nB loaded.\n");
while (1) {
- print("b");
+ print("B");
}
}
diff --git a/apps/init.c b/apps/init.c
index 5879c1e..5e88eff 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -10,13 +10,7 @@ void main()
{
print("Init loaded.\n");
- char *buf = malloc(10);
- conv_base(42, buf, 8, 0);
- printf("\n----\nTEST: %s\n----\n", buf);
- /* printf("%x %d %b\n ABC %s", 42, 42, 42, "BAUM"); */
- sys0(SYS_LOOP);
- /* sys1(SYS_EXEC, (int)"/a"); */
- while (1) {
- print("b");
- };
+ exec("/a");
+ exec("/b");
+ exit();
}
diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c
index 0b94208..9088915 100644
--- a/kernel/drivers/interrupts.c
+++ b/kernel/drivers/interrupts.c
@@ -34,7 +34,7 @@ void idt_install()
// Clear IDT by setting memory cells to 0
memset(&idt, 0, sizeof(struct idt_entry) * 256);
- __asm__("lidt %0" : : "m"(idt_ptr));
+ __asm__ volatile("lidt %0" : : "m"(idt_ptr));
}
/**
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
index a3b4137..0207cc0 100644
--- a/kernel/drivers/timer.c
+++ b/kernel/drivers/timer.c
@@ -27,7 +27,7 @@ void timer_wait(u32 ticks)
eticks = timer_ticks + ticks;
while (timer_ticks < eticks) {
- __asm__("sti//hlt//cli");
+ __asm__ volatile("sti//hlt//cli");
}
}
diff --git a/kernel/features/load.c b/kernel/features/load.c
index 5ef7def..2f3f65f 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -9,9 +9,12 @@
#include <proc.h>
#include <str.h>
-void bin_load(char *path, struct proc *proc)
+int bin_load(char *path, struct proc *proc)
{
char *data = read_file(path);
+ if (!data)
+ return 0;
+
u32 stack = (u32)malloc(0x1000) + 0x1000;
proc->regs.ebp = (u32)stack;
@@ -19,6 +22,7 @@ void bin_load(char *path, struct proc *proc)
proc->regs.useresp = (u32)stack;
proc->regs.eip = (u32)data;
strcpy(proc->name, path + 1);
+ return 1;
}
int elf_verify(struct elf_header *h)
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index 64a4ac1..40a52f8 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -72,6 +72,11 @@ void proc_attach(struct proc *proc)
}
}
+void proc_exit()
+{
+ current->state = PROC_ASLEEP;
+}
+
struct proc *proc_make()
{
struct proc *proc = malloc(sizeof(*proc));
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 519532c..fd57f3b 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -30,8 +30,11 @@ void syscall_handler(struct regs *r)
case SYS_EXEC: {
char *path = (char *)r->ebx;
struct proc *proc = proc_make();
- bin_load(path, proc);
- proc_print();
+ r->eax = bin_load(path, proc);
+ break;
+ }
+ case SYS_EXIT: {
+ proc_exit();
break;
}
default: {
diff --git a/kernel/inc/load.h b/kernel/inc/load.h
index 863f04f..43c941c 100644
--- a/kernel/inc/load.h
+++ b/kernel/inc/load.h
@@ -58,7 +58,7 @@ struct elf_program_header {
u32 align;
};
-void bin_load(char *path, struct proc *proc);
+int bin_load(char *path, struct proc *proc);
void elf_load(char *path, struct proc *proc);
#endif
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 39ba704..9f3816d 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -25,6 +25,7 @@ struct proc {
void proc_init();
void proc_print();
+void proc_exit();
struct proc *proc_make();
#endif
diff --git a/lib/inc/mem.h b/lib/inc/mem.h
index 9399b54..0030b3d 100644
--- a/lib/inc/mem.h
+++ b/lib/inc/mem.h
@@ -17,7 +17,6 @@
#error "No lib target specified. Please use -Dkernel or -Duserspace"
#endif
-// TODO: Use malloc as syscall
u32 HEAP;
u32 HEAP_START;
diff --git a/lib/inc/sys.h b/lib/inc/sys.h
index aefaead..16d3c4f 100644
--- a/lib/inc/sys.h
+++ b/lib/inc/sys.h
@@ -4,7 +4,7 @@
#ifndef SYS_H
#define SYS_H
-enum sys { SYS_LOOP, SYS_MALLOC, SYS_FREE, SYS_EXEC };
+enum sys { SYS_LOOP, SYS_MALLOC, SYS_FREE, SYS_EXEC, SYS_EXIT };
int sys0(enum sys num);
int sys1(enum sys num, int d1);
@@ -13,4 +13,15 @@ int sys3(enum sys num, int d1, int d2, int d3);
int sys4(enum sys num, int d1, int d2, int d3, int d4);
int sys5(enum sys num, int d1, int d2, int d3, int d4, int d5);
+/**
+ * Wrappers
+ */
+
+#define loop() sys0(SYS_LOOP)
+#define exec(path) sys1(SYS_EXEC, (int)path)
+#define exit() \
+ sys0(SYS_EXIT); \
+ while (1) { \
+ }
+
#endif