kernel.c 1003 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "../cpu/isr.h"
  2. #include "../drivers/screen.h"
  3. #include "kernel.h"
  4. #include "../libc/string.h"
  5. #include "../libc/mem.h"
  6. void main() {
  7. isr_install();
  8. irq_install();
  9. kprint("Type something, it will go through the kernel\n"
  10. "Type END to halt the CPU or PAGE to request a kmalloc()\n> ");
  11. }
  12. void user_input(char *input) {
  13. if (strcmp(input, "END") == 0) {
  14. kprint("Stopping the CPU. Bye!\n");
  15. asm volatile("hlt");
  16. } else if (strcmp(input, "PAGE") == 0) {
  17. /* Lesson 22: Code to test kmalloc, the rest is unchanged */
  18. u32 phys_addr;
  19. u32 page = kmalloc(1000, 1, &phys_addr);
  20. char page_str[16] = "";
  21. hex_to_ascii(page, page_str);
  22. char phys_str[16] = "";
  23. hex_to_ascii(phys_addr, phys_str);
  24. kprint("Page: ");
  25. kprint(page_str);
  26. kprint(", physical address: ");
  27. kprint(phys_str);
  28. kprint("\n");
  29. }
  30. kprint("You said: ");
  31. kprint(input);
  32. kprint("\n> ");
  33. }