diff options
| author | Tianhao Wang <shrik3@mailbox.org> | 2024-06-10 20:47:54 +0200 |
|---|---|---|
| committer | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:17:14 +0200 |
| commit | 13e3eca8ac3f6bd8c7a8fddde8b1937757e358ee (patch) | |
| tree | eb2d4992d5692287c232ac729ad18f9690eaa153 /src/lib.rs | |
| parent | 8aaad696463004a9e51d35e4c466c131b3402822 (diff) | |
proc: basic task/stack creation
Now we can do a simple context swap (without scheduler though)
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -21,6 +21,7 @@ use machine::cgascr::CGAScreen; use machine::key::Modifiers; use machine::multiboot; use machine::serial::Serial; +use proc::task::Task; #[panic_handler] fn panic(info: &PanicInfo) -> ! { @@ -58,6 +59,7 @@ pub extern "C" fn _entry() -> ! { let mut test_vec = Vec::<&str>::new(); test_vec.push("hello "); test_vec.push("world"); + _test_proc_switch_to(); for s in test_vec.iter() { println!("{s}"); } @@ -78,3 +80,25 @@ pub unsafe fn _test_pf() { let name_buf = slice::from_raw_parts_mut(0xffffffffffff0000 as *mut u64, 10); asm!("mov [rdi], rax", in("rdi") name_buf.as_mut_ptr()); } + +pub fn _test_proc_switch_to() { + use crate::arch::x86_64::arch_regs::Context64; + use crate::mm::KSTACK_ALLOCATOR; + use crate::proc::task::*; + let sp = unsafe { KSTACK_ALLOCATOR.lock().allocate() }; + println!("new task on {:#X}", sp); + let new_task = unsafe { + Task::settle_on_stack( + sp, + Task { + magic: Mem::KERNEL_STACK_TASK_MAGIC, + task_id: 42, + kernel_stack: sp, + state: TaskState::Meow, + context: Context64::default(), + }, + ) + }; + new_task.prepare_context(_task_entry as u64); + unsafe { context_swap_to(&(new_task.context) as *const _ as u64) } +} |
