feat(boot+shell): add bootable disk image, unified scheduler and interactive user-space shell
- Implement Limine v8 boot protocol requests in dedicated PT_LOAD RW segment - Configure IOPL=3 and SSE in arch setup for Ring 3 drivers and libc - Unify scheduler context switching via switch_to and preempt_tick - Support dual-source keyboard/serial input in sys_key_read - Add automated 'make image' and 'make run' targets for instant QEMU launch - Complete interactive UNIX-like shell (osh) with built-in commands & ramdisk
This commit is contained in:
+51
-8
@@ -1,14 +1,15 @@
|
||||
/* opencoreC - Thread Context Switch */
|
||||
/* opencoreC - Thread Context Switch & Entry Trampoline */
|
||||
.global switch_to
|
||||
.global thread_entry_trampoline
|
||||
|
||||
.section .text
|
||||
/*
|
||||
* void switch_to(uint64_t **prev_rsp_ptr, uint64_t *next_rsp);
|
||||
* RDI = pointer to current thread's stored RSP
|
||||
* RSI = target thread's RSP
|
||||
* switch_to(uint64_t *prev_rsp_ptr, uint64_t next_rsp)
|
||||
* RDI = ¤t_thread.context.rsp (save current RSP here)
|
||||
* RSI = next thread's saved RSP
|
||||
*/
|
||||
switch_to:
|
||||
/* Push callee-saved registers of outgoing thread */
|
||||
/* Save callee-saved registers of outgoing thread */
|
||||
push rbp
|
||||
push rbx
|
||||
push r12
|
||||
@@ -16,13 +17,13 @@ switch_to:
|
||||
push r14
|
||||
push r15
|
||||
|
||||
/* Save current stack pointer */
|
||||
/* Save RSP of outgoing thread */
|
||||
mov [rdi], rsp
|
||||
|
||||
/* Load target stack pointer */
|
||||
/* Load RSP of incoming thread */
|
||||
mov rsp, rsi
|
||||
|
||||
/* Pop callee-saved registers of incoming thread */
|
||||
/* Restore callee-saved registers of incoming thread */
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
@@ -31,3 +32,45 @@ switch_to:
|
||||
pop rbp
|
||||
|
||||
ret
|
||||
|
||||
/*
|
||||
* thread_entry_trampoline:
|
||||
* Jumped to via 'ret' in switch_to when a newly created thread runs for the first time.
|
||||
* When create_user_thread created the stack:
|
||||
* R12 was populated with user_rsp
|
||||
* R13 was populated with entry_rip
|
||||
*/
|
||||
thread_entry_trampoline:
|
||||
/* Set user data segments (0x18 | 3 = 0x1B) */
|
||||
mov ax, 0x1B
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
/* Build hardware IRETQ frame on kernel stack */
|
||||
push 0x1B /* User SS */
|
||||
push r12 /* User RSP */
|
||||
push 0x3202 /* RFLAGS (IF=1, IOPL=3 for hardware drivers) */
|
||||
push 0x23 /* User CS (0x20 | 3 = 0x23) */
|
||||
push r13 /* User RIP */
|
||||
|
||||
/* Clear all general-purpose registers */
|
||||
xor rax, rax
|
||||
xor rbx, rbx
|
||||
xor rcx, rcx
|
||||
xor rdx, rdx
|
||||
xor rsi, rsi
|
||||
xor rdi, rdi
|
||||
xor rbp, rbp
|
||||
xor r8, r8
|
||||
xor r9, r9
|
||||
xor r10, r10
|
||||
xor r11, r11
|
||||
xor r12, r12
|
||||
xor r13, r13
|
||||
xor r14, r14
|
||||
xor r15, r15
|
||||
|
||||
/* Transition to Ring 3 */
|
||||
iretq
|
||||
|
||||
Reference in New Issue
Block a user