wakeup.S 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 -- use lgdtl to force 32-bit operands, in case
  66. # the GDT is located past 16 megabytes.
  67. lgdtl real_save_gdt - wakeup_code
  68. movl real_save_cr0 - wakeup_code, %eax
  69. movl %eax, %cr0
  70. jmp 1f
  71. 1:
  72. movw $0x0e00 + 'n', %fs:(0x14)
  73. movl real_magic - wakeup_code, %eax
  74. cmpl $0x12345678, %eax
  75. jne bogus_real_magic
  76. ljmpl $__KERNEL_CS,$wakeup_pmode_return
  77. real_save_gdt: .word 0
  78. .long 0
  79. real_save_cr0: .long 0
  80. real_save_cr3: .long 0
  81. real_save_cr4: .long 0
  82. real_magic: .long 0
  83. video_mode: .long 0
  84. video_flags: .long 0
  85. real_efer_save_restore: .long 0
  86. real_save_efer_edx: .long 0
  87. real_save_efer_eax: .long 0
  88. bogus_real_magic:
  89. movw $0x0e00 + 'B', %fs:(0x12)
  90. jmp bogus_real_magic
  91. /* This code uses an extended set of video mode numbers. These include:
  92. * Aliases for standard modes
  93. * NORMAL_VGA (-1)
  94. * EXTENDED_VGA (-2)
  95. * ASK_VGA (-3)
  96. * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
  97. * of compatibility when extending the table. These are between 0x00 and 0xff.
  98. */
  99. #define VIDEO_FIRST_MENU 0x0000
  100. /* Standard BIOS video modes (BIOS number + 0x0100) */
  101. #define VIDEO_FIRST_BIOS 0x0100
  102. /* VESA BIOS video modes (VESA number + 0x0200) */
  103. #define VIDEO_FIRST_VESA 0x0200
  104. /* Video7 special modes (BIOS number + 0x0900) */
  105. #define VIDEO_FIRST_V7 0x0900
  106. # Setting of user mode (AX=mode ID) => CF=success
  107. mode_set:
  108. movw %ax, %bx
  109. #if 0
  110. cmpb $0xff, %ah
  111. jz setalias
  112. testb $VIDEO_RECALC>>8, %ah
  113. jnz _setrec
  114. cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah
  115. jnc setres
  116. cmpb $VIDEO_FIRST_SPECIAL>>8, %ah
  117. jz setspc
  118. cmpb $VIDEO_FIRST_V7>>8, %ah
  119. jz setv7
  120. #endif
  121. cmpb $VIDEO_FIRST_VESA>>8, %ah
  122. jnc check_vesa
  123. #if 0
  124. orb %ah, %ah
  125. jz setmenu
  126. #endif
  127. decb %ah
  128. # jz setbios Add bios modes later
  129. setbad: clc
  130. ret
  131. check_vesa:
  132. subb $VIDEO_FIRST_VESA>>8, %bh
  133. orw $0x4000, %bx # Use linear frame buffer
  134. movw $0x4f02, %ax # VESA BIOS mode set call
  135. int $0x10
  136. cmpw $0x004f, %ax # AL=4f if implemented
  137. jnz _setbad # AH=0 if OK
  138. stc
  139. ret
  140. _setbad: jmp setbad
  141. .code32
  142. ALIGN
  143. .org 0x800
  144. wakeup_stack_begin: # Stack grows down
  145. .org 0xff0 # Just below end of page
  146. wakeup_stack:
  147. ENTRY(wakeup_end)
  148. .org 0x1000
  149. wakeup_pmode_return:
  150. movw $__KERNEL_DS, %ax
  151. movw %ax, %ss
  152. movw %ax, %ds
  153. movw %ax, %es
  154. movw %ax, %fs
  155. movw %ax, %gs
  156. movw $0x0e00 + 'u', 0xb8016
  157. # reload the gdt, as we need the full 32 bit address
  158. lgdt saved_gdt
  159. lidt saved_idt
  160. lldt saved_ldt
  161. ljmp $(__KERNEL_CS),$1f
  162. 1:
  163. movl %cr3, %eax
  164. movl %eax, %cr3
  165. wbinvd
  166. # and restore the stack ... but you need gdt for this to work
  167. movl saved_context_esp, %esp
  168. movl %cs:saved_magic, %eax
  169. cmpl $0x12345678, %eax
  170. jne bogus_magic
  171. # jump to place where we left off
  172. movl saved_eip,%eax
  173. jmp *%eax
  174. bogus_magic:
  175. movw $0x0e00 + 'B', 0xb8018
  176. jmp bogus_magic
  177. ##
  178. # acpi_copy_wakeup_routine
  179. #
  180. # Copy the above routine to low memory.
  181. #
  182. # Parameters:
  183. # %eax: place to copy wakeup routine to
  184. #
  185. # Returned address is location of code in low memory (past data and stack)
  186. #
  187. ENTRY(acpi_copy_wakeup_routine)
  188. sgdt saved_gdt
  189. sidt saved_idt
  190. sldt saved_ldt
  191. str saved_tss
  192. movl nx_enabled, %edx
  193. movl %edx, real_efer_save_restore - wakeup_start (%eax)
  194. testl $1, real_efer_save_restore - wakeup_start (%eax)
  195. jz 2f
  196. # save efer setting
  197. pushl %eax
  198. movl %eax, %ebx
  199. mov $0xc0000080, %ecx
  200. rdmsr
  201. movl %edx, real_save_efer_edx - wakeup_start (%ebx)
  202. movl %eax, real_save_efer_eax - wakeup_start (%ebx)
  203. popl %eax
  204. 2:
  205. movl %cr3, %edx
  206. movl %edx, real_save_cr3 - wakeup_start (%eax)
  207. movl %cr4, %edx
  208. movl %edx, real_save_cr4 - wakeup_start (%eax)
  209. movl %cr0, %edx
  210. movl %edx, real_save_cr0 - wakeup_start (%eax)
  211. sgdt real_save_gdt - wakeup_start (%eax)
  212. movl saved_videomode, %edx
  213. movl %edx, video_mode - wakeup_start (%eax)
  214. movl acpi_video_flags, %edx
  215. movl %edx, video_flags - wakeup_start (%eax)
  216. movl $0x12345678, real_magic - wakeup_start (%eax)
  217. movl $0x12345678, saved_magic
  218. ret
  219. .data
  220. ALIGN
  221. ENTRY(saved_magic) .long 0
  222. ENTRY(saved_eip) .long 0
  223. save_registers:
  224. leal 4(%esp), %eax
  225. movl %eax, saved_context_esp
  226. movl %ebx, saved_context_ebx
  227. movl %ebp, saved_context_ebp
  228. movl %esi, saved_context_esi
  229. movl %edi, saved_context_edi
  230. pushfl ; popl saved_context_eflags
  231. movl $ret_point, saved_eip
  232. ret
  233. restore_registers:
  234. movl saved_context_ebp, %ebp
  235. movl saved_context_ebx, %ebx
  236. movl saved_context_esi, %esi
  237. movl saved_context_edi, %edi
  238. pushl saved_context_eflags ; popfl
  239. ret
  240. ENTRY(do_suspend_lowlevel)
  241. call save_processor_state
  242. call save_registers
  243. pushl $3
  244. call acpi_enter_sleep_state
  245. addl $4, %esp
  246. ret
  247. .p2align 4,,7
  248. ret_point:
  249. call restore_registers
  250. call restore_processor_state
  251. ret
  252. ENTRY(do_suspend_lowlevel_s4bios)
  253. call save_processor_state
  254. call save_registers
  255. call acpi_enter_sleep_state_s4bios
  256. ret
  257. ALIGN
  258. # saved registers
  259. saved_gdt: .long 0,0
  260. saved_idt: .long 0,0
  261. saved_ldt: .long 0
  262. saved_tss: .long 0