Wed, 01 Mar 2023 21:41:45 +0100
8 files changed,
54 insertions(+),
28 deletions(-)
M
src/apps/assembly.h
→
src/apps/assembly.h
@@ -1,19 +1,19 @@
#ifndef ASSEMBLY_H #define ASSEMBLY_H -/*! - * Performs a syscall. - */ -__attribute__((always_inline)) inline int syscall(int eax, int ebx, int ecx, int edx) { - int res; - __asm__ volatile ( "mov %1, %%eax;" - "mov %2, %%ebx;" - "mov %3, %%ecx;" - "mov %4, %%edx;" - "int $0x30;" - "mov %%eax, %0;" : "=m" (res) : "" (eax), "" (ebx), "" (ecx), "" (edx) : "eax", "ebx", "ecx", "edx"); - return res; -} + +#define interrupt(num, res, arg1, arg2, arg3, arg4) \ + __asm__ volatile ( \ + "mov %1, %%eax;" \ + "mov %2, %%ebx;" \ + "mov %3, %%ecx;" \ + "mov %4, %%edx;" \ + "int $" #num ";" \ + "mov %%eax, %0;" \ + : "=m" (res) \ + : "" (arg1), "" (arg2), "" (arg3), "" (arg4) \ + : "eax", "ebx", "ecx", "edx" \ + ) /*! * Waits for the next interrupt.
A
src/apps/cedos.c
@@ -0,0 +1,20 @@
+#include "cedos.h" +#include "assembly.h" + +int sysprint(const char *fmt, int arg1, int arg2) { + int res = 0; + interrupt(0x30, res, 4, fmt, arg1, arg2); + return res; +} + +int yield() { + int res = 0; + interrupt(0x20, res, 0, 0, 0, 0); + return res; +} + +int get_pid() { + int res = 0; + interrupt(0x30, res, 3, 0, 0, 0); + return res; +}
A
src/apps/cedos.h
@@ -0,0 +1,10 @@
+#ifndef CEDOS_H +#define CEDOS_H + +#include "assembly.h" + +int sysprint(const char *fmt, int arg1, int arg2); +int yield(); +int get_pid(); + +#endif
M
src/apps/fibonacci.c
→
src/apps/fibonacci.c
@@ -1,14 +1,15 @@
-#include "assembly.h" +#include "cedos.h" #include <stdint.h> void fib(void) { - uint32_t a = 0, b = 1; + uint32_t a = 0, b = 1, i = 0; while (1) { uint32_t tmp = a + b; a = b; b = tmp; - syscall(0, a, 0, 0); - hlt(); + sysprint("fib (%i) = %i\n", i, a); + i++; + hlt();//yield(); } }
M
src/apps/start.c
→
src/apps/start.c
@@ -8,8 +8,6 @@ int start(void) {
uint32_t eip, esp, ebp; __asm__ volatile ("call jump; jump: pop %0; mov %%esp, %1; mov %%ebp, %2" : "=m" (eip), "=m" (esp), "=m" (ebp)); - syscall(0, eip, esp, ebp); - fib(); while(1);
M
src/kernel/syscall.c
→
src/kernel/syscall.c
@@ -6,11 +6,16 @@ void test(uint32_t ebx, uint32_t ecx, uint32_t edx) {
printk("SYSCALL 0x01: EBX=%i ECX=%X EDX=%X\n", ebx, ecx, edx); } +int __sysprint(const char *fmt, int arg1, int arg2) { + printk(fmt, arg1, arg2); +} + void* SYSCALL_TABLE[] = { test, hard_reset, sched_yield, - get_current_process + get_current_process, + __sysprint }; extern void syscall_interrupt(void);