| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #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"
- #include "../userprog/syscall-init.h"
- #include "../lib/user/syscall.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 prog_a_pid = 0, prog_b_pid = 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");
- process_execute(user_prog_a, "user_prog_a");
- // process_execute(user_prog_b, "user_prog_b");
- intr_enable(); // 打开中断,使中断起作用
- console_put_str(" main_pid:0x");
- console_put_int(sys_getpid());
- console_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 ");
- // 主线程会一直执行, 直到被中断或被其他线程强制结束
- while (1)
- ;
- return 0;
- }
- /*在线程中运行的函数*/
- void kernel_thread_a_func(void *arg)
- {
- // 用 void 来表示通用类型,这样就可以传递任意类型的参数
- char *para = arg;
- console_put_str(" thread_a_pid:0x");
- console_put_int(sys_getpid());
- console_put_char('\n');
- console_put_str(" prog_a_pid:0x");
- console_put_int(prog_a_pid);
- console_put_char('\n');
- }
- void kernel_thread_b_func(void *arg)
- {
- char *para = arg;
- console_put_str(" thread_b_pid:0x");
- console_put_int(sys_getpid());
- console_put_char('\n');
- console_put_str(" prog_b_pid:0x");
- console_put_int(prog_b_pid);
- console_put_char('\n');
- }
- /*测试用户进程*/
- void user_prog_a(void *UNUSED(arg))
- {
- prog_a_pid = getpid();
- while (1)
- ;
- }
- void user_prog_b(void *UNUSED(arg))
- {
- prog_b_pid = getpid();
- while (1)
- ;
- }
|