summaryrefslogtreecommitdiff
path: root/kernel/traps.s
diff options
context:
space:
mode:
authorJake Mannens <jake72360@gmail.com>2018-07-08 01:44:13 +1000
committerJake Mannens <jake72360@gmail.com>2018-07-08 01:44:13 +1000
commit70b141b3af85771f36119165e072c1c45d64de84 (patch)
tree8c67026fc02c86ffc7328e13354adede5f0ea9ed /kernel/traps.s
parentec4f58e8e362e371718f656923c2d234f8ac215c (diff)
Added a printf() function to the library under stdio.c which uses the
vsprintf() function to render formatted strings and then the puts system call to output them. Moved the vsprintf() function from the kernel to the library. Furthermore, the prototype for the function has been moved from the kernel's headers, to the new header file stdio.h. Renamed the kernel's internal printf() function to printk() in order to avoid confusion with the library provided function. Renamed the sys_print system call to the more appropriate name, sys_puts. Added a new system call sys_time, which returns the system's uptime in seconds. This is mainly for testing the userspace binary and will not be permanent. Added the file time.c to the library which contains the caller for sys_time and a helper routine sleep() which delays execution for the specified number of seconds. The new header file time.h contains prototypes for both these functions as well as the definition for the type time_t. Fixed a bug in which the value of EAX was not properly passed to the system call handler, resulting in the wrong system call being executed. This was caused by the code in the SAVE macro not properly preserving the value. Fixed a bug in which the value of EAX was not preserved during a return from system call, but rather restored with the original EAX value prior to the call. As a result, system call return codes were not properly passed. This has been corrected by introducing a new macro RESTORE_SYS which carries out the same restore operations, but maintains EAX prior to the return.
Diffstat (limited to 'kernel/traps.s')
-rw-r--r--kernel/traps.s17
1 files changed, 15 insertions, 2 deletions
diff --git a/kernel/traps.s b/kernel/traps.s
index 0381ee8..15e2640 100644
--- a/kernel/traps.s
+++ b/kernel/traps.s
@@ -23,7 +23,7 @@ extern register_isr
mov fs, ax
mov gs, ax
; restore EAX (needed for syscalls)
- mov eax, [esp+44]
+ mov eax, [esp+30]
%endmacro
%macro SAVE_ERR 0
@@ -64,6 +64,19 @@ extern register_isr
iret
%endmacro
+%macro RESTORE_SYS 0
+ ; preserve our modified EAX (return value for syscalls)
+ mov [esp+30], eax
+ ; restore the data segment selectors
+ pop ax
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ popa
+ iret
+%endmacro
+
traps:
dd exc_div
dd exc_debug
@@ -230,7 +243,7 @@ syscall_handler:
call [eax]
add esp, 12
- RESTORE
+ RESTORE_SYS
syscall_init: