summaryrefslogtreecommitdiff
path: root/include/asm
AgeCommit message (Collapse)Author
2019-09-02Updated MakefileJake Mannens
2018-08-20Defined macros cli() and sti() in asm/interrupt.h to disable and enableJake Mannens
interrupts respectively. Added the scheduling primatives sleep_on() and interruptible_sleep_on() to sched.c. sleep_on() adds the current task to the specified wait queue then puts it into an uninterruptible sleep. Wait queues are formed by having each waiting task holding a pointer to the waiting task that preceeded it, then placing a pointer to it's own task struct into the queue's head pointer. When the first task in the queue is awoken, it wakes the preceeding task prior to returning from sleep_on(). The function interruptible_sleep_on() works in a similar manner, however when a task is awoken from interruptible_sleep_on(), it wakes up the first task in it's wait queue, then puts itself back to sleep. The purpose of this, is to automatically dissolve and reform the wait queue. As each task in the queue is a awakened, tasks that need to handle signals will do so whilst tasks that have no pending signals and are still waiting will place themselves back into the wait queue by calling interruptible_sleep_on() again. Whilst this method isn't the most effiecient due to waking every task in a wait queue because one received a signal, it does avoid the mess and complications involved in maintaining the queue as an array or linked list. Added prototypes for the scheduling primatives wake_up(), sleep_on() and interruptible_sleep_on() to kernel/sched.h so that these functions may be used throughout the kernel. Added code to temporaily re-enable interrupts in reschedule() so that the idle loop may continue to function even if interrupts were disabled prior to calling the function.
2018-08-06Defined ssize_t in unistd.h.Jake Mannens
Added the _syscall2 macro to unistd.h to facilitate system calls that require two arguments to be passed. Modified the ATA driver to simply abort initialisation if a drive is not found, or cannot be configured. This will allow the kernel to function on a diskless system without invoking panic() unnecessarily. Added the functions irq_enable() and irq_disable() to asm/interrupt.h to make it easier for C code to mask and unmask IRQ's on each PIC. Moved the declaration for rsputs() from kernel/con.h to the new kernel/serial.h file since this is a function provided by the serial driver. Implemented a basic I/O input framework. This involves the new system call sys_read, which takes an I/O read request and directs it to the appropriate kernel handler function depending on the calling process' ctty value. This mechanism is identical to the sys_puts system call. Added the rsread() function to service sys_read calls from processes whose ctty value is equal to 1. This function will continually copy data from the serial buffer to the location specified. If there is not a sufficient amount of new data in the buffer to satisfy the request, the process is put into the TSTATE_UNINTERRUPTIBLE state and the scheduler is called to switch tasks. Prior to calling the scheduler, the function will set the waiting_task pointer to the calling process. This pointer will later be used by the interrupt handler to wake the process when new data arrives. Added an interrupt handler to service the IRQ4 (UART) interrupt. This subroutine is a stub which will save the machine's state then transfer control to rs_handler() in serial.c which will read bytes from the serial port and place them in a buffer. Before returning, rs_handler() checks the waiting_task pointer to see if a task is waiting for the newly received data and if so, it sets the task's state to TSTATE_RUNNING before resetting the pointer to NULL and returning. Ideally, the scheduler should be invoked at this point to select another task but since our basic round-robin scheduler currently has no concept of task priorities (and for the sake of simplicity), we will avoid invoking the scheduler in response to interrupts for now.
2018-07-30Added a new subroutine invlpg() to asm.s which simply checks the currentJake Mannens
CPU is not an i386 before executing the invlpg instruction with the provided address. This will once again make the kernel compatible with the i386 processor as executing the invlpg instruction without these checks would have resulted in an invalid opcode exception.
2018-07-28Added new function register_trap() which creates trap gate entries inJake Mannens
the IDT. This function takes the same parameters as register_isr() which creates interrupt gate entries in the IDT. The register_isr() function now sets the gate type to 0x0E regardless of what was already in the descriptor. This is to break reliance on the IDT already being initialized to a known state as well as avoiding conflicts with the new register_trap() function. Added declaration for the 'ticks' variable in kernel/sched.h so that it's value may be used throughout the kernel. Changed the system call gate to a trap gate. This means that interrupts will not be disabled prior to entry into the system call handler. This will allow hardware functions such as the timer to operate continuously even if the user makes a system call. Added checks to the timer interrupt handler. These checks prevent the scheduler from being called if the interrupt occurred during kernel mode execution. The idea here, is that the timer interrupt handler only services the hardware (increments the tick count and sends an EOI to the PIC's) if a system call was already running in the kernel. The system call handler has also been expanded to check if the timer fired prior to returning to userspace. If the timer did fire, the syscall handler will invoke the scheduler (as the timer handler would have), so that it can decide if it's time to switch tasks.
2018-07-14con_init() is now called during the kernel's boot sequence in kboot()Jake Mannens
rather than in kmain() as some subsystems may now require early console I/O. Added 16-bit read/write I/O functions to asm/io.h. These functions are inw() and outw() respectively. Added the file kernel/fs.h which will contain definitions relating to filesystem functions. Defined the type off_t as a signed 32-bit value in sys/types.h. This type will be required for filesystem functionality. Added the directory 'kernel/fs' to the project's source tree. The kernel's makefile has been updated accordingly. This directory will contain any source files relating to filesystem functionality (both assembly and C files). Added the file 'fs/hd.c' to the kernel's source tree. This file currently contains three main functions (which are defined in kernel/hd.h). These functions are as follows; hd_init() to enumerate and initialize the hard disks, hd_read() to read sectors from the disk and hd_write() to write sectors to the disk. Currently, all transfers are done in ATA PIO mode using polling, however this will change in future. The function hd_init() is called during the kernel's boot sequence in kboot(). Added the file hd.img to the project's root directory. This is a 20MB raw image file that will be used by Qemu as a 20MB hard disk. The main makefile has been updated to tell Qemu to use this file on launch.
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-07Added '-g' flag for GCC to all makefiles to ensure debugging informationJake Mannens
is produced. This may change later. Added the new directory 'lib' to the source tree which build lib.a, an archive containing common library routines for both the kernel and userspace code to use. Added the file string.c to the lib directory (as well as the appropriate headers in /include) which provides some basic functions from the standard C string library. Added a physical memory manager which is now located in memory.c. This memory manager tracks free pages from 1MB-8MB with a simple table and allocates memory in blocks of 4KB pages. Multiple pages can be allocated in which they are returned as a linked list. Added a 'page window' in memory.c which allows the temporary mapping of a single page at a time into the current address space. Moved all paging routines that were previously located in page.s over to memory.c where they have been re-implemented as a mixture of C and inline assembly. Moved the primative userspace routines from usrspace.s over to the new sched.c. The only remaining routine, usrcall is now located in asm.s as 'switch_to' which takes two arguments, pointers to the task structure and task state structure of the new task which is being switched to. Pages for userspace are now allocated dynamically. The user binary is loaded in at 1GB upwards. The user stack is located at the end of the 4GB address space with the lower 1GB being reserved for the kernel. Updated the link.ld file for the userspace binary to include the new starting address 0x40000000 (1GB). Renamed the symbols for the user binary blob to make them shorter.
2018-06-25Added the header asm/interrupt.h which includes a prototype for theJake Mannens
assembly function register_isr making it usable within the C portions of the source. Added a new file panic.s with the function panic that will print a panic message, disable interrupts and halt the system. Created the skeleton framework for paging in the new file page.s. The new function paging_init (called in kboot) will setup a simple page directory with two tables covering all addresses 0-8MB. It will also mark pages from 0-1MB as 'supervisor-only' to protect the kernel. NOTE: The function paging_init must be called before initialising the IDT as it does not disable interrupts! Modified the page fault handler to print the offending linear address along with the supplied error code. Following that, the handler will initiate a kernel panic. This function (along with panic) assumes console I/O to be operational. Modified the userspace test code to deliberately intiate a page fault by accessing an unmapped page.
2018-06-16Initial commitJake Mannens