kernel.c 1.1 KB

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