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

@ -190,6 +190,70 @@ irq 0x0D
irq 0x0E
irq 0x0F
.global gate_syscall
gate_syscall:
cli
/* push scratch registers */
pushq %rax
pushq %rcx
pushq %rdx
pushq %rsi
pushq %rdi
pushq %r8
pushq %r9
pushq %r10
pushq %r11
/* get current task registers */
call proc_current_regs
/* save current task registers */
popq %rdi
movq %rdi, 80(%rax) /* r11 */
popq %rdi
movq %rdi, 72(%rax) /* r10 */
popq %rdi
movq %rdi, 64(%rax) /* r9 */
popq %rdi
movq %rdi, 56(%rax) /* r8 */
popq %rdi
movq %rdi, 40(%rax) /* rdi */
popq %rdi
movq %rdi, 32(%rax) /* rsi */
popq %rdi
movq %rdi, 24(%rax) /* rdx */
popq %rdi
movq %rdi, 16(%rax) /* rcx */
popq %rdi
movq %rdi, 0(%rax) /* rax */
/* save remaining registers */
movq %rbx, 8(%rax)
movq %rbp, 48(%rax)
movq %r12, 88(%rax)
movq %r13, 96(%rax)
movq %r14, 104(%rax)
movq %r15, 112(%rax)
/* save IRETQ frame */
popq %rdi
movq %rdi, 120(%rax)
popq %rdi
movq %rdi, 128(%rax)
popq %rdi
movq %rdi, 136(%rax)
popq %rdi
movq %rdi, 144(%rax)
popq %rdi
movq %rdi, 152(%rax)
movq 0(%rax), %rdi /* syscall number */
movq 40(%rax), %rsi /* arguments */
call syscall
call schedule
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */
.global _return_to_user
_return_to_user:
@ -224,3 +288,7 @@ _return_to_user:
iretq
.global yield
yield:
hlt
jmp yield