segmentation.S 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "common.h"
  2. BEGIN
  3. CLEAR
  4. STAGE2
  5. PROTECTED_MODE
  6. /* Sanity check 1: just print the output. */
  7. VGA_PRINT_STRING $output
  8. /* Sanity check 2: make a mov without any segment manipulation. */
  9. mov message, %cl
  10. mov %cl, output
  11. VGA_PRINT_STRING $output
  12. /* Now for the real action. */
  13. mov $gdt_data, %edx
  14. /* We are touching the 7th byte of the data entry. */
  15. add $3, %edx
  16. mov (%edx), %al
  17. /* Cache it for later. */
  18. mov %al, %bl
  19. /* Set the first bit of the descriptor memory. */
  20. xor $1, %al
  21. mov %al, (%edx)
  22. /* We must re-set ds because the segment descriptor is cached
  23. * and this updates it:
  24. * http://wiki.osdev.org/Descriptor_Cache
  25. */
  26. mov $DATA_SEG, %ax
  27. mov %ax, %ds
  28. /* This is the only memory access we will make with
  29. * the modified segment, to minimize the effect on our IO.
  30. */
  31. mov message, %cl
  32. /* Restore the old segment. */
  33. /* TODO is this needed to take into account the new segmentation? */
  34. dec %edx
  35. mov %bl, (%edx)
  36. mov %ax, %ds
  37. /* TODO this sanity check is not printing "ab".
  38. * It fails, so we're not restoring the old state properly.
  39. * Maybe blows up because video memory going wrong?
  40. */
  41. VGA_PRINT_STRING $message
  42. mov %cl, output
  43. VGA_PRINT_STRING $output
  44. hlt
  45. message:
  46. .asciz "ab"
  47. output:
  48. .asciz "x"