bios_initial_state.S 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "common.h"
  2. .macro INITIAL_STORE x
  3. mov %\()\x, \x
  4. .endm
  5. .macro INITIAL_DATA x
  6. \x: .skip 2
  7. \x\()s: .ascii "\x = \0"
  8. .endm
  9. .macro INITIAL_PRINT x
  10. PRINT_STRING $\x\()s
  11. PRINT_BYTES $\x, $2
  12. PRINT_NEWLINE
  13. .endm
  14. /*
  15. Indispensable initialization.
  16. This initialization is a bit redundant with BEGIN,
  17. and does dirty some registers, but I haven't found a better option.
  18. */
  19. .code16
  20. cli
  21. xor %ax, %ax
  22. mov %ax, %ds
  23. /*
  24. We want our data do be before STAGE2,
  25. or it will get overwritten during the load.
  26. */
  27. jmp after_data
  28. .irp reg, ax, bx, cx, dx, cs, ds, es, fs, gs, ss
  29. INITIAL_DATA \reg
  30. .endr
  31. cr0: .long 0
  32. cr0s: .ascii "cr0 = \0"
  33. after_data:
  34. .irp reg, ax, bx, cx, dx, cs, ds, es, fs, gs, ss
  35. INITIAL_STORE \reg
  36. .endr
  37. /* Does not have a 16-bit mov version. */
  38. mov %cr0, %eax
  39. mov %eax, cr0
  40. /*
  41. We delay a full BEGIN as late as possible
  42. to mess with less initial state.
  43. */
  44. BEGIN
  45. STAGE2
  46. .irp reg, ax, bx, cx, dx, cs, ds, es, fs, gs, ss
  47. INITIAL_PRINT \reg
  48. .endr
  49. PRINT_STRING $cr0s
  50. PRINT_BYTES cr0, $4
  51. PRINT_NEWLINE
  52. hlt