summaryrefslogtreecommitdiff
path: root/kernel/sys.c
AgeCommit message (Collapse)Author
2018-07-11Implemented a basic scheduler using an array of task structures in whichJake Mannens
each structure has a TSS inside, as well as several descriptor entries in the GDT pointing to each task's TSS. Task switching is performed in hardware by means of far jumping to the new task's TSS descriptor in the GDT. Task states are saved manually by copying the saved state from the interrupt handler's stack, back into the task's TSS. Added the function save_state() to sched.c which can be called from assembly to copy the state information of the suspended task from the current stack, to it's respective task structure. NOTE: this assumes that the pointer cstate has been set ahead of time to point to the state information on the stack, and that the pointer ctask has not yet been modified. Added the function reschedule() which is currently called from the timer's tick handler. Currently, this function merely alternates between the two tasks created in sched_init(), but in future, will be expanded to decided independently which task will run next. The function userspace_init() was renamed to the more appropriate sched_init(). Moved most of the code from the original userspace_init() to the new function create_proc() which sets up a virtual address space and state information, copies the specified binary into the new address space, then returns a pointer to the newly created tasks entry in the task table. Defined the type pid_t in unistd.h as a 16-bit unsigned integer. Added two new debugging system calls for checking which task is currently active. The getpid() system calls returns the caller's PID whilst the getpdir() call returns the physical location of the caller's page directory (the value of CR3). The getpdir() call can be used as a fallback to determine which task is *actually* running if the information in ctask or the getpid() call is faulty. Added two new subroutines; set_tss() and clear_tss() (whose prototypes are defined in asm/system.h) for managing the task-state descriptor entries in the GDT. set_tss() initializes a TSS descriptor and sets it's base pointer to the supplied TSS pointer whilst clear_tss() simply marks a TSS descriptor as 'not present' without clearing it.
2018-07-08Added a printf() function to the library under stdio.c which uses theJake Mannens
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.
2018-06-24Modified makefiles to use the more appropriate variable $(MAKE) whenJake Mannens
invoking the tool recursively. Disabled GCC's position-independent-code generation in makefiles. Modified makefile for kernel/usrbin so that it now compiles and links C code into the userspace test. Created errno.h and populated it with standard error definitions. Replaced the va_list based system call handlers with a system call table defined in the header kernel/sys.h. NOTE: This header is included in kmain.c and should ONLY be included there! Do NOT include this header in sys.c. Rather than fetching the user's stack pointer and using it to initialize a va_list, parameters are now passed to the call handlers via the general purpose registers EAX, EBX, ECX and EDX where EAX contains the requested call number and conveys the return value. Setup macros in unistd.h to aid to making system calls from userspace. Implemented two basic system calls; sys_print and sys_dummy. The former takes a single char* argument and displays it on screen whilst the latter is used to populate otherwise empty entries of the system call table. sys_dummy returns the error ENOSYS whenever it is called.