head.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * linux/boot/head.S
  3. *
  4. * Copyright (C) 1991, 1992, 1993 Linus Torvalds
  5. *
  6. * $Id: head.S,v 1.3 2001/04/20 00:59:28 ak Exp $
  7. */
  8. /*
  9. * head.S contains the 32-bit startup code.
  10. *
  11. * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
  12. * the page directory will exist. The startup code will be overwritten by
  13. * the page directory. [According to comments etc elsewhere on a compressed
  14. * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
  15. *
  16. * Page 0 is deliberately kept safe, since System Management Mode code in
  17. * laptops may need to access the BIOS data stored there. This is also
  18. * useful for future device drivers that either access the BIOS via VM86
  19. * mode.
  20. */
  21. /*
  22. * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  23. */
  24. .code32
  25. .text
  26. #include <linux/linkage.h>
  27. #include <asm/segment.h>
  28. #include <asm/page.h>
  29. .code32
  30. .globl startup_32
  31. startup_32:
  32. cld
  33. cli
  34. movl $(__KERNEL_DS),%eax
  35. movl %eax,%ds
  36. movl %eax,%es
  37. movl %eax,%fs
  38. movl %eax,%gs
  39. lss stack_start,%esp
  40. xorl %eax,%eax
  41. 1: incl %eax # check that A20 really IS enabled
  42. movl %eax,0x000000 # loop forever if it isn't
  43. cmpl %eax,0x100000
  44. je 1b
  45. /*
  46. * Initialize eflags. Some BIOS's leave bits like NT set. This would
  47. * confuse the debugger if this code is traced.
  48. * XXX - best to initialize before switching to protected mode.
  49. */
  50. pushl $0
  51. popfl
  52. /*
  53. * Clear BSS
  54. */
  55. xorl %eax,%eax
  56. movl $_edata,%edi
  57. movl $_end,%ecx
  58. subl %edi,%ecx
  59. cld
  60. rep
  61. stosb
  62. /*
  63. * Do the decompression, and jump to the new kernel..
  64. */
  65. subl $16,%esp # place for structure on the stack
  66. movl %esp,%eax
  67. pushl %esi # real mode pointer as second arg
  68. pushl %eax # address of structure as first arg
  69. call decompress_kernel
  70. orl %eax,%eax
  71. jnz 3f
  72. addl $8,%esp
  73. xorl %ebx,%ebx
  74. ljmp $(__KERNEL_CS), $__PHYSICAL_START
  75. /*
  76. * We come here, if we were loaded high.
  77. * We need to move the move-in-place routine down to 0x1000
  78. * and then start it with the buffer addresses in registers,
  79. * which we got from the stack.
  80. */
  81. 3:
  82. movl %esi,%ebx
  83. movl $move_routine_start,%esi
  84. movl $0x1000,%edi
  85. movl $move_routine_end,%ecx
  86. subl %esi,%ecx
  87. addl $3,%ecx
  88. shrl $2,%ecx
  89. cld
  90. rep
  91. movsl
  92. popl %esi # discard the address
  93. addl $4,%esp # real mode pointer
  94. popl %esi # low_buffer_start
  95. popl %ecx # lcount
  96. popl %edx # high_buffer_start
  97. popl %eax # hcount
  98. movl $__PHYSICAL_START,%edi
  99. cli # make sure we don't get interrupted
  100. ljmp $(__KERNEL_CS), $0x1000 # and jump to the move routine
  101. /*
  102. * Routine (template) for moving the decompressed kernel in place,
  103. * if we were high loaded. This _must_ PIC-code !
  104. */
  105. move_routine_start:
  106. movl %ecx,%ebp
  107. shrl $2,%ecx
  108. rep
  109. movsl
  110. movl %ebp,%ecx
  111. andl $3,%ecx
  112. rep
  113. movsb
  114. movl %edx,%esi
  115. movl %eax,%ecx # NOTE: rep movsb won't move if %ecx == 0
  116. addl $3,%ecx
  117. shrl $2,%ecx
  118. rep
  119. movsl
  120. movl %ebx,%esi # Restore setup pointer
  121. xorl %ebx,%ebx
  122. ljmp $(__KERNEL_CS), $__PHYSICAL_START
  123. move_routine_end:
  124. /* Stack for uncompression */
  125. .align 32
  126. user_stack:
  127. .fill 4096,4,0
  128. stack_start:
  129. .long user_stack+4096
  130. .word __KERNEL_DS