#include "../lib/kernel/print.h" #include "debug.h" #include "init.h" #include "memory.h" #include "../thread/thread.h" #include "interrupt.h" #include "../device/console.h" #include "../device/ioqueue.h" #include "../device/keyboard.h" #include "../userprog/process.h" void kernel_thread_a_func(void *); void kernel_thread_b_func(void *); void user_prog_a(void *); void user_prog_b(void *); int test_var_a = 0, test_var_b = 0; int main(void) { put_str("I am kernel\n"); init_all(); // asm volatile("sti"); // 使能中断 // ASSERT(1 == 2); // void *addr = get_kernel_pages(4); // put_str("\n get_kernel_page start vaddr is "); // put_int((uintptr_t)addr); // put_str("\n"); thread_start("kernel_thread_a_func", 31, kernel_thread_a_func, "argA "); thread_start("kernel_thread_a_func", 31, kernel_thread_b_func, "argB "); process_execute(user_prog_a, "user_prog_a"); // process_execute(user_prog_b, "user_prog_b"); intr_enable(); // 打开中断,使中断起作用 // 主线程会一直执行, 直到被中断或被其他线程强制结束 while (1) ; return 0; } /*在线程中运行的函数*/ void kernel_thread_a_func(void *UNUSED(arg)) { // 用 void 来表示通用类型,这样就可以传递任意类型的参数 while (1) { console_put_str("v_a:0x"); console_put_int(test_var_a); } } void kernel_thread_b_func(void *UNUSED(arg)) { while (1) { console_put_str(" v_b:0x"); console_put_int(test_var_b); } } /*测试用户进程*/ void user_prog_a(void *UNUSED(arg)) { while (1) { test_var_a++; } } void user_prog_b(void *UNUSED(arg)) { while (1) { test_var_b++; } }