kernel.c 837 B

1234567891011121314151617181920212223242526
  1. /* Kernel: entered from bootloader in 32-bit protected mode at 0x7E00.
  2. * Must be linked so this function is at 0x7E00 (see kernel.ld). */
  3. #define VGA_BASE ((volatile unsigned short *)0xB8000)
  4. #define VGA_ATTR 0x0A /* green on black */
  5. /* String in .text so it loads with the kernel */
  6. static const char msg[] __attribute__((section(".text"))) = "Hello from C (protected mode)";
  7. /* Entry point: must be first in .text so bootloader jump to 0x7E00 hits it */
  8. void kernel_main(void) __attribute__((section(".text.entry")));
  9. void kernel_main(void)
  10. {
  11. unsigned i;
  12. /* Clear screen */
  13. for (i = 0; i < 80 * 25; i++)
  14. VGA_BASE[i] = (unsigned short)(VGA_ATTR << 8);
  15. /* Print message */
  16. for (i = 0; msg[i] != '\0'; i++)
  17. VGA_BASE[i] = (unsigned short)((VGA_ATTR << 8) | (unsigned char)msg[i]);
  18. for (;;)
  19. __asm__ volatile ("hlt");
  20. }