wakeup_32.S 6.6 KB

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