1
0

kernel.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include <stdint.h>
  7. void kernel_main() {
  8. isr_install();
  9. irq_install();
  10. kprint("Type something, it will go through the kernel\n"
  11. "Type END to halt the CPU or PAGE to request a kmalloc()\n> ");
  12. }
  13. void user_input(char *input) {
  14. if (strcmp(input, "END") == 0) {
  15. kprint("Stopping the CPU. Bye!\n");
  16. asm volatile("hlt");
  17. } else if (strcmp(input, "PAGE") == 0) {
  18. /* Lesson 22: Code to test kmalloc, the rest is unchanged */
  19. uint32_t phys_addr;
  20. uint32_t page = kmalloc(1000, 1, &phys_addr);
  21. char page_str[16] = "";
  22. hex_to_ascii(page, page_str);
  23. char phys_str[16] = "";
  24. hex_to_ascii(phys_addr, phys_str);
  25. kprint("Page: ");
  26. kprint(page_str);
  27. kprint(", physical address: ");
  28. kprint(phys_str);
  29. kprint("\n");
  30. }
  31. kprint("You said: ");
  32. kprint(input);
  33. kprint("\n> ");
  34. }