wakeup.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. .text
  2. #include <linux/linkage.h>
  3. #include <asm/segment.h>
  4. #include <asm/page.h>
  5. #
  6. # wakeup_code runs in real mode, and at unknown address (determined at run-time).
  7. # Therefore it must only use relative jumps/calls.
  8. #
  9. # Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled
  10. #
  11. # If physical address of wakeup_code is 0x12345, BIOS should call us with
  12. # cs = 0x1234, eip = 0x05
  13. #
  14. ALIGN
  15. .align 4096
  16. ENTRY(wakeup_start)
  17. wakeup_code:
  18. wakeup_code_start = .
  19. .code16
  20. movw $0xb800, %ax
  21. movw %ax,%fs
  22. movw $0x0e00 + 'L', %fs:(0x10)
  23. cli
  24. cld
  25. # setup data segment
  26. movw %cs, %ax
  27. movw %ax, %ds # Make ds:0 point to wakeup_start
  28. movw %ax, %ss
  29. mov $(wakeup_stack - wakeup_code), %sp # Private stack is needed for ASUS board
  30. movw $0x0e00 + 'S', %fs:(0x12)
  31. pushl $0 # Kill any dangerous flags
  32. popfl
  33. movl real_magic - wakeup_code, %eax
  34. cmpl $0x12345678, %eax
  35. jne bogus_real_magic
  36. testl $1, video_flags - wakeup_code
  37. jz 1f
  38. lcall $0xc000,$3
  39. movw %cs, %ax
  40. movw %ax, %ds # Bios might have played with that
  41. movw %ax, %ss
  42. 1:
  43. testl $2, video_flags - wakeup_code
  44. jz 1f
  45. mov video_mode - wakeup_code, %ax
  46. call mode_set
  47. 1:
  48. # set up page table
  49. movl $swapper_pg_dir-__PAGE_OFFSET, %eax
  50. movl %eax, %cr3
  51. testl $1, real_efer_save_restore - wakeup_code
  52. jz 4f
  53. # restore efer setting
  54. movl real_save_efer_edx - wakeup_code, %edx
  55. movl real_save_efer_eax - wakeup_code, %eax
  56. mov $0xc0000080, %ecx
  57. wrmsr
  58. 4:
  59. # make sure %cr4 is set correctly (features, etc)
  60. movl real_save_cr4 - wakeup_code, %eax
  61. movl %eax, %cr4
  62. movw $0xb800, %ax
  63. movw %ax,%fs
  64. movw $0x0e00 + 'i', %fs:(0x12)
  65. # need a gdt
  66. lgdt real_save_gdt - wakeup_code
  67. movl real_save_cr0 - wakeup_code, %eax
  68. movl %eax, %cr0
  69. jmp 1f
  70. 1:
  71. movw $0x0e00 + 'n', %fs:(0x14)
  72. movl real_magic - wakeup_code, %eax
  73. cmpl $0x12345678, %eax
  74. jne bogus_real_magic
  75. ljmpl $__KERNEL_CS,$wakeup_pmode_return
  76. real_save_gdt: .word 0
  77. .long 0
  78. real_save_cr0: .long 0
  79. real_save_cr3: .long 0
  80. real_save_cr4: .long 0
  81. real_magic: .long 0
  82. video_mode: .long 0
  83. video_flags: .long 0
  84. real_efer_save_restore: .long 0
  85. real_save_efer_edx: .long 0
  86. real_save_efer_eax: .long 0
  87. bogus_real_magic:
  88. movw $0x0e00 + 'B', %fs:(0x12)
  89. jmp bogus_real_magic
  90. /* This code uses an extended set of video mode numbers. These include:
  91. * Aliases for standard modes
  92. * NORMAL_VGA (-1)
  93. * EXTENDED_VGA (-2)
  94. * ASK_VGA (-3)
  95. * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
  96. * of compatibility when extending the table. These are between 0x00 and 0xff.
  97. */
  98. #define VIDEO_FIRST_MENU 0x0000
  99. /* Standard BIOS video modes (BIOS number + 0x0100) */
  100. #define VIDEO_FIRST_BIOS 0x0100
  101. /* VESA BIOS video modes (VESA number + 0x0200) */
  102. #define VIDEO_FIRST_VESA 0x0200
  103. /* Video7 special modes (BIOS number + 0x0900) */
  104. #define VIDEO_FIRST_V7 0x0900
  105. # Setting of user mode (AX=mode ID) => CF=success
  106. mode_set:
  107. movw %ax, %bx
  108. #if 0
  109. cmpb $0xff, %ah
  110. jz setalias
  111. testb $VIDEO_RECALC>>8, %ah
  112. jnz _setrec
  113. cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah
  114. jnc setres
  115. cmpb $VIDEO_FIRST_SPECIAL>>8, %ah
  116. jz setspc
  117. cmpb $VIDEO_FIRST_V7>>8, %ah
  118. jz setv7
  119. #endif
  120. cmpb $VIDEO_FIRST_VESA>>8, %ah
  121. jnc check_vesa
  122. #if 0
  123. orb %ah, %ah
  124. jz setmenu
  125. #endif
  126. decb %ah
  127. # jz setbios Add bios modes later
  128. setbad: clc
  129. ret
  130. check_vesa:
  131. subb $VIDEO_FIRST_VESA>>8, %bh
  132. orw $0x4000, %bx # Use linear frame buffer
  133. movw $0x4f02, %ax # VESA BIOS mode set call
  134. int $0x10
  135. cmpw $0x004f, %ax # AL=4f if implemented
  136. jnz _setbad # AH=0 if OK
  137. stc
  138. ret
  139. _setbad: jmp setbad
  140. .code32
  141. ALIGN
  142. .org 0x800
  143. wakeup_stack_begin: # Stack grows down
  144. .org 0xff0 # Just below end of page
  145. wakeup_stack:
  146. ENTRY(wakeup_end)
  147. .org 0x1000
  148. wakeup_pmode_return:
  149. movw $__KERNEL_DS, %ax
  150. movw %ax, %ss
  151. movw %ax, %ds
  152. movw %ax, %es
  153. movw %ax, %fs
  154. movw %ax, %gs
  155. movw $0x0e00 + 'u', 0xb8016
  156. # reload the gdt, as we need the full 32 bit address
  157. lgdt saved_gdt
  158. lidt saved_idt
  159. lldt saved_ldt
  160. ljmp $(__KERNEL_CS),$1f
  161. 1:
  162. movl %cr3, %eax
  163. movl %eax, %cr3
  164. wbinvd
  165. # and restore the stack ... but you need gdt for this to work
  166. movl saved_context_esp, %esp
  167. movl %cs:saved_magic, %eax
  168. cmpl $0x12345678, %eax
  169. jne bogus_magic
  170. # jump to place where we left off
  171. movl saved_eip,%eax
  172. jmp *%eax
  173. bogus_magic:
  174. movw $0x0e00 + 'B', 0xb8018
  175. jmp bogus_magic
  176. ##
  177. # acpi_copy_wakeup_routine
  178. #
  179. # Copy the above routine to low memory.
  180. #
  181. # Parameters:
  182. # %eax: place to copy wakeup routine to
  183. #
  184. # Returned address is location of code in low memory (past data and stack)
  185. #
  186. ENTRY(acpi_copy_wakeup_routine)
  187. sgdt saved_gdt
  188. sidt saved_idt
  189. sldt saved_ldt
  190. str saved_tss
  191. movl nx_enabled, %edx
  192. movl %edx, real_efer_save_restore - wakeup_start (%eax)
  193. testl $1, real_efer_save_restore - wakeup_start (%eax)
  194. jz 2f
  195. # save efer setting
  196. pushl %eax
  197. movl %eax, %ebx
  198. mov $0xc0000080, %ecx
  199. rdmsr
  200. movl %edx, real_save_efer_edx - wakeup_start (%ebx)
  201. movl %eax, real_save_efer_eax - wakeup_start (%ebx)
  202. popl %eax
  203. 2:
  204. movl %cr3, %edx
  205. movl %edx, real_save_cr3 - wakeup_start (%eax)
  206. movl %cr4, %edx
  207. movl %edx, real_save_cr4 - wakeup_start (%eax)
  208. movl %cr0, %edx
  209. movl %edx, real_save_cr0 - wakeup_start (%eax)
  210. sgdt real_save_gdt - wakeup_start (%eax)
  211. movl saved_videomode, %edx
  212. movl %edx, video_mode - wakeup_start (%eax)
  213. movl acpi_video_flags, %edx
  214. movl %edx, video_flags - wakeup_start (%eax)
  215. movl $0x12345678, real_magic - wakeup_start (%eax)
  216. movl $0x12345678, saved_magic
  217. ret
  218. .data
  219. ALIGN
  220. ENTRY(saved_magic) .long 0
  221. ENTRY(saved_eip) .long 0
  222. save_registers:
  223. leal 4(%esp), %eax
  224. movl %eax, saved_context_esp
  225. movl %ebx, saved_context_ebx
  226. movl %ebp, saved_context_ebp
  227. movl %esi, saved_context_esi
  228. movl %edi, saved_context_edi
  229. pushfl ; popl saved_context_eflags
  230. movl $ret_point, saved_eip
  231. ret
  232. restore_registers:
  233. movl saved_context_ebp, %ebp
  234. movl saved_context_ebx, %ebx
  235. movl saved_context_esi, %esi
  236. movl saved_context_edi, %edi
  237. pushl saved_context_eflags ; popfl
  238. ret
  239. ENTRY(do_suspend_lowlevel)
  240. call save_processor_state
  241. call save_registers
  242. pushl $3
  243. call acpi_enter_sleep_state
  244. addl $4, %esp
  245. ret
  246. .p2align 4,,7
  247. ret_point:
  248. call restore_registers
  249. call restore_processor_state
  250. ret
  251. ENTRY(do_suspend_lowlevel_s4bios)
  252. call save_processor_state
  253. call save_registers
  254. call acpi_enter_sleep_state_s4bios
  255. ret
  256. ALIGN
  257. # saved registers
  258. saved_gdt: .long 0,0
  259. saved_idt: .long 0,0
  260. saved_ldt: .long 0
  261. saved_tss: .long 0