wakeup_32.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. #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. movw $0xb800, %ax
  35. movw %ax,%fs
  36. movw $0x0e00 + 'L', %fs:(0x10)
  37. cli
  38. cld
  39. # setup data segment
  40. movw %cs, %ax
  41. movw %ax, %ds # Make ds:0 point to wakeup_start
  42. movw %ax, %ss
  43. testl $4, realmode_flags - wakeup_code
  44. jz 1f
  45. BEEP
  46. 1:
  47. mov $(wakeup_stack - wakeup_code), %sp # Private stack is needed for ASUS board
  48. pushl $0 # Kill any dangerous flags
  49. popfl
  50. movl real_magic - wakeup_code, %eax
  51. cmpl $0x12345678, %eax
  52. jne bogus_real_magic
  53. testl $1, realmode_flags - wakeup_code
  54. jz 1f
  55. lcall $0xc000,$3
  56. movw %cs, %ax
  57. movw %ax, %ds # Bios might have played with that
  58. movw %ax, %ss
  59. 1:
  60. testl $2, realmode_flags - wakeup_code
  61. jz 1f
  62. mov video_mode - wakeup_code, %ax
  63. call mode_set
  64. 1:
  65. # set up page table
  66. movl $swsusp_pg_dir-__PAGE_OFFSET, %eax
  67. movl %eax, %cr3
  68. testl $1, real_efer_save_restore - wakeup_code
  69. jz 4f
  70. # restore efer setting
  71. movl real_save_efer_edx - wakeup_code, %edx
  72. movl real_save_efer_eax - wakeup_code, %eax
  73. mov $0xc0000080, %ecx
  74. wrmsr
  75. 4:
  76. # make sure %cr4 is set correctly (features, etc)
  77. movl real_save_cr4 - wakeup_code, %eax
  78. movl %eax, %cr4
  79. # need a gdt -- use lgdtl to force 32-bit operands, in case
  80. # the GDT is located past 16 megabytes.
  81. lgdtl real_save_gdt - wakeup_code
  82. movl real_save_cr0 - wakeup_code, %eax
  83. movl %eax, %cr0
  84. jmp 1f
  85. 1:
  86. movl real_magic - wakeup_code, %eax
  87. cmpl $0x12345678, %eax
  88. jne bogus_real_magic
  89. testl $8, realmode_flags - wakeup_code
  90. jz 1f
  91. BEEP
  92. 1:
  93. ljmpl $__KERNEL_CS, $wakeup_pmode_return
  94. real_save_gdt: .word 0
  95. .long 0
  96. real_save_cr0: .long 0
  97. real_save_cr3: .long 0
  98. real_save_cr4: .long 0
  99. real_magic: .long 0
  100. video_mode: .long 0
  101. realmode_flags: .long 0
  102. real_efer_save_restore: .long 0
  103. real_save_efer_edx: .long 0
  104. real_save_efer_eax: .long 0
  105. bogus_real_magic:
  106. jmp bogus_real_magic
  107. /* This code uses an extended set of video mode numbers. These include:
  108. * Aliases for standard modes
  109. * NORMAL_VGA (-1)
  110. * EXTENDED_VGA (-2)
  111. * ASK_VGA (-3)
  112. * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
  113. * of compatibility when extending the table. These are between 0x00 and 0xff.
  114. */
  115. #define VIDEO_FIRST_MENU 0x0000
  116. /* Standard BIOS video modes (BIOS number + 0x0100) */
  117. #define VIDEO_FIRST_BIOS 0x0100
  118. /* VESA BIOS video modes (VESA number + 0x0200) */
  119. #define VIDEO_FIRST_VESA 0x0200
  120. /* Video7 special modes (BIOS number + 0x0900) */
  121. #define VIDEO_FIRST_V7 0x0900
  122. # Setting of user mode (AX=mode ID) => CF=success
  123. # For now, we only handle VESA modes (0x0200..0x03ff). To handle other
  124. # modes, we should probably compile in the video code from the boot
  125. # directory.
  126. mode_set:
  127. movw %ax, %bx
  128. subb $VIDEO_FIRST_VESA>>8, %bh
  129. cmpb $2, %bh
  130. jb check_vesa
  131. setbad:
  132. clc
  133. ret
  134. check_vesa:
  135. orw $0x4000, %bx # Use linear frame buffer
  136. movw $0x4f02, %ax # VESA BIOS mode set call
  137. int $0x10
  138. cmpw $0x004f, %ax # AL=4f if implemented
  139. jnz setbad # AH=0 if OK
  140. stc
  141. ret
  142. .code32
  143. ALIGN
  144. .org 0x800
  145. wakeup_stack_begin: # Stack grows down
  146. .org 0xff0 # Just below end of page
  147. wakeup_stack:
  148. ENTRY(wakeup_end)
  149. .org 0x1000
  150. wakeup_pmode_return:
  151. movw $__KERNEL_DS, %ax
  152. movw %ax, %ss
  153. movw %ax, %ds
  154. movw %ax, %es
  155. movw %ax, %fs
  156. movw %ax, %gs
  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. 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. pushl %ebx
  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_realmode_flags, %edx
  215. movl %edx, realmode_flags - wakeup_start (%eax)
  216. movl $0x12345678, real_magic - wakeup_start (%eax)
  217. movl $0x12345678, saved_magic
  218. popl %ebx
  219. ret
  220. save_registers:
  221. leal 4(%esp), %eax
  222. movl %eax, saved_context_esp
  223. movl %ebx, saved_context_ebx
  224. movl %ebp, saved_context_ebp
  225. movl %esi, saved_context_esi
  226. movl %edi, saved_context_edi
  227. pushfl ; popl saved_context_eflags
  228. movl $ret_point, saved_eip
  229. ret
  230. restore_registers:
  231. movl saved_context_ebp, %ebp
  232. movl saved_context_ebx, %ebx
  233. movl saved_context_esi, %esi
  234. movl saved_context_edi, %edi
  235. pushl saved_context_eflags ; popfl
  236. ret
  237. ENTRY(do_suspend_lowlevel)
  238. call save_processor_state
  239. call save_registers
  240. pushl $3
  241. call acpi_enter_sleep_state
  242. addl $4, %esp
  243. # In case of S3 failure, we'll emerge here. Jump
  244. # to ret_point to recover
  245. jmp ret_point
  246. .p2align 4,,7
  247. ret_point:
  248. call restore_registers
  249. call restore_processor_state
  250. ret
  251. .data
  252. ALIGN
  253. ENTRY(saved_magic) .long 0
  254. ENTRY(saved_eip) .long 0
  255. # saved registers
  256. saved_gdt: .long 0,0
  257. saved_idt: .long 0,0
  258. saved_ldt: .long 0
  259. saved_tss: .long 0