usr: implement user process switching

This is a rather large commit, so the gist of it is this:

User context switching is now functional, after a change to the TSS, and
a few minor details in the scheduler and loader.

ELF parsing is rather primitive, but basically functional, as long as it
only loads code.

The interrupt 0x80 is for syscalls, and will switch from user mode to
kernel mode. It is currently the only interrupt that can be called from
user mode

This adds the syscall functionality, which currently uses a red-black
tree to store the function pointers, although when the table is more
flushed out, it will probably be replaced with an array

The pager now correctly marks the parent nodes with attributes as it
allocates them. Without doing this, the page table entries will never be
reached in lower privilege modes, causing page faults

Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
Michael Shaw 2023-11-20 21:59:12 -05:00
commit 37518aea81
19 changed files with 262 additions and 69 deletions

View file

@ -10,12 +10,12 @@ CC := x86_64-elf-gcc
LD := x86_64-elf-ld
OUT := test1.elf
CSRC := test.c
CSRC :=
SSRC := start.S
OBJ := $(CSRC:.c=.o) $(SSRC:.S=.o)
DEP := $(OBJ:.o=.d)
CFLAGS := -Wall -ffreestanding -mno-mmx -mno-sse2 -mno-sse -m64 -MMD
CFLAGS := -Wall -ffreestanding -mno-mmx -mno-sse2 -mno-sse -m64 -MMD -g
LDFLAGS := -nostdlib -static -m elf_x86_64
CURDIR := $(shell pwd | awk -F '/' '{print $$(NF-1),"/",$$NF}' | sed 's/ //g')

View file

@ -5,11 +5,13 @@
* Test the basic functionality of the kernel loader
*/
sys_exit = 60
sys_exit = 60
.global _start
_start:
call main
movq %rax, %rdi
movq sys_exit, %rax
movq $0x123456, %rdi
movq $sys_exit, %rax
int $0x80
_no_exit:
movq $0, %rbx
jmp _no_exit

View file

@ -1,5 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
int main()
{
return 0x123456;
}