main.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "../lib/kernel/print.h"
  2. #include "debug.h"
  3. #include "init.h"
  4. #include "memory.h"
  5. #include "../thread/thread.h"
  6. #include "interrupt.h"
  7. #include "../device/console.h"
  8. #include "../device/ioqueue.h"
  9. #include "../device/keyboard.h"
  10. #include "../userprog/process.h"
  11. void kernel_thread_a_func(void *);
  12. void kernel_thread_b_func(void *);
  13. void user_prog_a(void *);
  14. void user_prog_b(void *);
  15. int test_var_a = 0, test_var_b = 0;
  16. int main(void)
  17. {
  18. put_str("I am kernel\n");
  19. init_all();
  20. // asm volatile("sti"); // 使能中断
  21. // ASSERT(1 == 2);
  22. // void *addr = get_kernel_pages(4);
  23. // put_str("\n get_kernel_page start vaddr is ");
  24. // put_int((uintptr_t)addr);
  25. // put_str("\n");
  26. thread_start("kernel_thread_a_func", 31, kernel_thread_a_func, "argA ");
  27. thread_start("kernel_thread_a_func", 31, kernel_thread_b_func, "argB ");
  28. process_execute(user_prog_a, "user_prog_a");
  29. // process_execute(user_prog_b, "user_prog_b");
  30. intr_enable(); // 打开中断,使中断起作用
  31. // 主线程会一直执行, 直到被中断或被其他线程强制结束
  32. while (1)
  33. ;
  34. return 0;
  35. }
  36. /*在线程中运行的函数*/
  37. void kernel_thread_a_func(void *UNUSED(arg))
  38. {
  39. // 用 void 来表示通用类型,这样就可以传递任意类型的参数
  40. while (1)
  41. {
  42. console_put_str("v_a:0x");
  43. console_put_int(test_var_a);
  44. }
  45. }
  46. void kernel_thread_b_func(void *UNUSED(arg))
  47. {
  48. while (1)
  49. {
  50. console_put_str(" v_b:0x");
  51. console_put_int(test_var_b);
  52. }
  53. }
  54. /*测试用户进程*/
  55. void user_prog_a(void *UNUSED(arg))
  56. {
  57. while (1)
  58. {
  59. test_var_a++;
  60. }
  61. }
  62. void user_prog_b(void *UNUSED(arg))
  63. {
  64. while (1)
  65. {
  66. test_var_b++;
  67. }
  68. }