wakeup_32.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. .section .text.page_aligned
  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. #define BEEP \
  15. inb $97, %al; \
  16. outb %al, $0x80; \
  17. movb $3, %al; \
  18. outb %al, $97; \
  19. outb %al, $0x80; \
  20. movb $-74, %al; \
  21. outb %al, $67; \
  22. outb %al, $0x80; \
  23. movb $-119, %al; \
  24. outb %al, $66; \
  25. outb %al, $0x80; \
  26. movb $15, %al; \
  27. outb %al, $66;
  28. ALIGN
  29. .align 4096
  30. ENTRY(wakeup_start)
  31. wakeup_code:
  32. wakeup_code_start = .
  33. .code16
  34. cli
  35. cld
  36. # setup data segment
  37. movw %cs, %ax
  38. movw %ax, %ds # Make ds:0 point to wakeup_start
  39. movw %ax, %ss
  40. testl $4, realmode_flags - wakeup_code
  41. jz 1f
  42. BEEP
  43. 1:
  44. mov $(wakeup_stack - wakeup_code), %sp # Private stack is needed for ASUS board
  45. pushl $0 # Kill any dangerous flags
  46. popfl
  47. movl real_magic - wakeup_code, %eax
  48. cmpl $0x12345678, %eax
  49. jne bogus_real_magic
  50. testl $1, realmode_flags - wakeup_code
  51. jz 1f
  52. lcall $0xc000,$3
  53. movw %cs, %ax
  54. movw %ax, %ds # Bios might have played with that
  55. movw %ax, %ss
  56. 1:
  57. testl $2, realmode_flags - wakeup_code
  58. jz 1f
  59. mov video_mode - wakeup_code, %ax
  60. call mode_set
  61. 1:
  62. # set up page table
  63. movl $swsusp_pg_dir-__PAGE_OFFSET, %eax
  64. movl %eax, %cr3
  65. testl $1, real_efer_save_restore - wakeup_code
  66. jz 4f
  67. # restore efer setting
  68. movl real_save_efer_edx - wakeup_code, %edx
  69. movl real_save_efer_eax - wakeup_code, %eax
  70. mov $0xc0000080, %ecx
  71. wrmsr
  72. 4:
  73. # make sure %cr4 is set correctly (features, etc)
  74. movl real_save_cr4 - wakeup_code, %eax
  75. movl %eax, %cr4
  76. # need a gdt -- use lgdtl to force 32-bit operands, in case
  77. # the GDT is located past 16 megabytes.
  78. lgdtl real_save_gdt - wakeup_code
  79. movl real_save_cr0 - wakeup_code, %eax
  80. movl %eax, %cr0
  81. jmp 1f
  82. 1:
  83. movl real_magic - wakeup_code, %eax
  84. cmpl $0x12345678, %eax
  85. jne bogus_real_magic
  86. testl $8, realmode_flags - wakeup_code
  87. jz 1f
  88. BEEP
  89. 1:
  90. ljmpl $__KERNEL_CS, $wakeup_pmode_return
  91. real_save_gdt: .word 0
  92. .long 0
  93. real_save_cr0: .long 0
  94. real_save_cr3: .long 0
  95. real_save_cr4: .long 0
  96. real_magic: .long 0
  97. video_mode: .long 0
  98. realmode_flags: .long 0
  99. real_efer_save_restore: .long 0
  100. real_save_efer_edx: .long 0
  101. real_save_efer_eax: .long 0
  102. bogus_real_magic:
  103. jmp bogus_real_magic
  104. /* This code uses an extended set of video mode numbers. These include:
  105. * Aliases for standard modes
  106. * NORMAL_VGA (-1)
  107. * EXTENDED_VGA (-2)
  108. * ASK_VGA (-3)
  109. * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
  110. * of compatibility when extending the table. These are between 0x00 and 0xff.
  111. */
  112. #define VIDEO_FIRST_MENU 0x0000
  113. /* Standard BIOS video modes (BIOS number + 0x0100) */
  114. #define VIDEO_FIRST_BIOS 0x0100
  115. /* VESA BIOS video modes (VESA number + 0x0200) */
  116. #define VIDEO_FIRST_VESA 0x0200
  117. /* Video7 special modes (BIOS number + 0x0900) */
  118. #define VIDEO_FIRST_V7 0x0900
  119. # Setting of user mode (AX=mode ID) => CF=success
  120. # For now, we only handle VESA modes (0x0200..0x03ff). To handle other
  121. # modes, we should probably compile in the video code from the boot
  122. # directory.
  123. mode_set:
  124. movw %ax, %bx
  125. subb $VIDEO_FIRST_VESA>>8, %bh
  126. cmpb $2, %bh
  127. jb check_vesa
  128. setbad:
  129. clc
  130. ret
  131. check_vesa:
  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. .code32
  140. ALIGN
  141. .org 0x800
  142. wakeup_stack_begin: # Stack grows down
  143. .org 0xff0 # Just below end of page
  144. wakeup_stack:
  145. ENTRY(wakeup_end)
  146. .org 0x1000
  147. wakeup_pmode_return:
  148. movw $__KERNEL_DS, %ax
  149. movw %ax, %ss
  150. movw %ax, %ds
  151. movw %ax, %es
  152. movw %ax, %fs
  153. movw %ax, %gs
  154. # reload the gdt, as we need the full 32 bit address
  155. lgdt saved_gdt
  156. lidt saved_idt
  157. lldt saved_ldt
  158. ljmp $(__KERNEL_CS),$1f
  159. 1:
  160. movl %cr3, %eax
  161. movl %eax, %cr3
  162. wbinvd
  163. # and restore the stack ... but you need gdt for this to work
  164. movl saved_context_esp, %esp
  165. movl %cs:saved_magic, %eax
  166. cmpl $0x12345678, %eax
  167. jne bogus_magic
  168. # jump to place where we left off
  169. movl saved_eip,%eax
  170. jmp *%eax
  171. bogus_magic:
  172. jmp bogus_magic
  173. ##
  174. # acpi_copy_wakeup_routine
  175. #
  176. # Copy the above routine to low memory.
  177. #
  178. # Parameters:
  179. # %eax: place to copy wakeup routine to
  180. #
  181. # Returned address is location of code in low memory (past data and stack)
  182. #
  183. ENTRY(acpi_copy_wakeup_routine)
  184. pushl %ebx
  185. sgdt saved_gdt
  186. sidt saved_idt
  187. sldt saved_ldt
  188. str saved_tss
  189. movl nx_enabled, %edx
  190. movl %edx, real_efer_save_restore - wakeup_start (%eax)
  191. testl $1, real_efer_save_restore - wakeup_start (%eax)
  192. jz 2f
  193. # save efer setting
  194. pushl %eax
  195. movl %eax, %ebx
  196. mov $0xc0000080, %ecx
  197. rdmsr
  198. movl %edx, real_save_efer_edx - wakeup_start (%ebx)
  199. movl %eax, real_save_efer_eax - wakeup_start (%ebx)
  200. popl %eax
  201. 2:
  202. movl %cr3, %edx
  203. movl %edx, real_save_cr3 - wakeup_start (%eax)
  204. movl %cr4, %edx
  205. movl %edx, real_save_cr4 - wakeup_start (%eax)
  206. movl %cr0, %edx
  207. movl %edx, real_save_cr0 - wakeup_start (%eax)
  208. sgdt real_save_gdt - wakeup_start (%eax)
  209. movl saved_videomode, %edx
  210. movl %edx, video_mode - wakeup_start (%eax)
  211. movl acpi_realmode_flags, %edx
  212. movl %edx, realmode_flags - wakeup_start (%eax)
  213. movl $0x12345678, real_magic - wakeup_start (%eax)
  214. movl $0x12345678, saved_magic
  215. popl %ebx
  216. ret
  217. save_registers:
  218. leal 4(%esp), %eax
  219. movl %eax, saved_context_esp
  220. movl %ebx, saved_context_ebx
  221. movl %ebp, saved_context_ebp
  222. movl %esi, saved_context_esi
  223. movl %edi, saved_context_edi
  224. pushfl ; popl saved_context_eflags
  225. movl $ret_point, saved_eip
  226. ret
  227. restore_registers:
  228. movl saved_context_ebp, %ebp
  229. movl saved_context_ebx, %ebx
  230. movl saved_context_esi, %esi
  231. movl saved_context_edi, %edi
  232. pushl saved_context_eflags ; popfl
  233. ret
  234. ENTRY(do_suspend_lowlevel)
  235. call save_processor_state
  236. call save_registers
  237. pushl $3
  238. call acpi_enter_sleep_state
  239. addl $4, %esp
  240. # In case of S3 failure, we'll emerge here. Jump
  241. # to ret_point to recover
  242. jmp ret_point
  243. .p2align 4,,7
  244. ret_point:
  245. call restore_registers
  246. call restore_processor_state
  247. ret
  248. .data
  249. ALIGN
  250. ENTRY(saved_magic) .long 0
  251. ENTRY(saved_eip) .long 0
  252. # saved registers
  253. saved_gdt: .long 0,0
  254. saved_idt: .long 0,0
  255. saved_ldt: .long 0
  256. saved_tss: .long 0