kernel.c 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #include "../drivers/ports.h"
  2. void main() {
  3. /* Screen cursor position: ask VGA control register (0x3d4) for bytes
  4. * 14 = high byte of cursor and 15 = low byte of cursor. */
  5. port_byte_out(0x3d4, 14); /* Requesting byte 14: high byte of cursor pos */
  6. /* Data is returned in VGA data register (0x3d5) */
  7. int position = port_byte_in(0x3d5);
  8. position = position << 8; /* high byte */
  9. port_byte_out(0x3d4, 15); /* requesting low byte */
  10. position += port_byte_in(0x3d5);
  11. /* VGA 'cells' consist of the character and its control data
  12. * e.g. 'white on black background', 'red text on white bg', etc */
  13. int offset_from_vga = position * 2;
  14. /* Now you can examine both variables using gdb, since we still
  15. * don't know how to print strings on screen. Run 'make debug' and
  16. * on the gdb console:
  17. * breakpoint kernel.c:21
  18. * continue
  19. * print position
  20. * print offset_from_vga
  21. */
  22. /* Let's write on the current cursor position, we already know how
  23. * to do that */
  24. char *vga = 0xb8000;
  25. vga[offset_from_vga] = 'X';
  26. vga[offset_from_vga+1] = 0x0f; /* White text on black background */
  27. }