rebootcode.s 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "mem.h"
  2. /*
  3. * Turn off MMU, then memmory the new kernel to its correct location
  4. * in physical memory. Then jumps the to start of the kernel.
  5. */
  6. TEXT main(SB),$0
  7. MOVL p1+0(FP), DI /* destination */
  8. MOVL DI, AX /* entry point */
  9. MOVL p2+4(FP), SI /* source */
  10. MOVL n+8(FP), CX /* byte count */
  11. /*
  12. * disable paging
  13. */
  14. MOVL CR0, DX
  15. ANDL $~0x80000000, DX /* ~(PG) */
  16. MOVL DX, CR0
  17. MOVL $0, DX
  18. MOVL DX, CR3
  19. /*
  20. * the source and destination may overlap.
  21. * determine whether to copy forward or backwards
  22. */
  23. CMPL SI, DI
  24. JGT _forward
  25. MOVL SI, DX
  26. ADDL CX, DX
  27. CMPL DX, DI
  28. JGT _back
  29. _forward:
  30. CLD
  31. REP; MOVSB
  32. JMP _startkernel
  33. _back:
  34. ADDL CX, DI
  35. ADDL CX, SI
  36. SUBL $1, DI
  37. SUBL $1, SI
  38. STD
  39. REP; MOVSB
  40. JMP _startkernel
  41. /*
  42. * JMP to kernel entry point. Note the true kernel entry point is
  43. * the virtual address KZERO|AX, but this must wait until
  44. * the MMU is enabled by the kernel in l.s
  45. */
  46. _startkernel:
  47. ORL AX, AX /* NOP: avoid link bug */
  48. JMP* AX