2 #include <linux/linkage.h>
3 #include <asm/segment.h>
7 # Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
9 # wakeup_code runs in real mode, and at unknown address (determined at run-time).
10 # Therefore it must only use relative jumps/calls.
12 # Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled
14 # If physical address of wakeup_code is 0x12345, BIOS should call us with
15 # cs = 0x1234, eip = 0x05
26 # Running in *copy* of this code, somewhere in low 1MB.
28 movb $0xa1, %al ; outb %al, $0x80
33 movw %ax, %ds # Make ds:0 point to wakeup_start
35 # Private stack is needed for ASUS board
36 mov $(wakeup_stack - wakeup_code), %sp
38 pushl $0 # Kill any dangerous flags
41 movl real_magic - wakeup_code, %eax
42 cmpl $0x12345678, %eax
45 testl $1, video_flags - wakeup_code
49 movw %ax, %ds # Bios might have played with that
53 testl $2, video_flags - wakeup_code
55 mov video_mode - wakeup_code, %ax
61 movw $0x0e00 + 'L', %fs:(0x10)
63 movb $0xa2, %al ; outb %al, $0x80
65 lidt %ds:idt_48a - wakeup_code
67 movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
69 addl $(gdta - wakeup_code), %eax
70 movl %eax, gdt_48a +2 - wakeup_code
71 lgdtl %ds:gdt_48a - wakeup_code # load gdt with whatever is
74 movl $1, %eax # protected mode (PE) bit
75 lmsw %ax # This is it!
79 ljmpl *(wakeup_32_vector - wakeup_code)
83 .long wakeup_32 - __START_KERNEL_map
84 .word __KERNEL32_CS, 0
88 # Running in this code, but at low address; paging is not yet turned on.
89 movb $0xa5, %al ; outb %al, $0x80
91 /* Check if extended functions are implemented */
92 movl $0x80000000, %eax
94 cmpl $0x80000000, %eax
103 movl $__KERNEL_DS, %eax
106 movl saved_magic - __START_KERNEL_map, %eax
107 cmpl $0x9abcdef0, %eax
110 movw $0x0e00 + 'i', %ds:(0xb8012)
111 movb $0xa8, %al ; outb %al, $0x80;
114 * Prepare for entering 64bits mode
122 /* Setup early boot stage 4 level pagetables */
123 movl $(wakeup_level4_pgt - __START_KERNEL_map), %eax
126 /* Enable Long Mode */
128 btsl $_EFER_LME, %eax
130 /* No Execute supported? */
135 /* Make changes effective */
136 1: movl $MSR_EFER, %ecx
141 btsl $31, %eax /* Enable paging and in turn activate Long Mode */
142 btsl $0, %eax /* Enable protected mode */
144 /* Make changes effective */
150 CR3 must point to PML4
151 Next instruction must be a branch
152 This must be on identity-mapped page
155 * At this point we're in long mode but in 32bit compatibility mode
156 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
157 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we load
158 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
161 /* Finally jump in 64bit mode */
162 ljmp *(wakeup_long64_vector - __START_KERNEL_map)
165 wakeup_long64_vector:
166 .long wakeup_long64 - __START_KERNEL_map
171 /* Hooray, we are in Long 64-bit mode (but still running in
176 * We must switch to a new descriptor in kernel space for the GDT
177 * because soon the kernel won't have access anymore to the userspace
178 * addresses where we're currently running on. We have to do that here
179 * because in 32bit we couldn't load a 64bit linear address.
181 lgdt cpu_gdt_descr - __START_KERNEL_map
183 movw $0x0e00 + 'n', %ds:(0xb8014)
184 movb $0xa9, %al ; outb %al, $0x80
186 movw $0x0e00 + 'u', %ds:(0xb8016)
190 movw $__KERNEL_DS, %ax
198 movw $0x0e00 + 'x', %ds:(0xb8018)
204 movw $0x0e00 + '!', %ds:(0xb801a)
212 /* Its good to keep gdt in sync with one in trampoline.S */
213 .word 0, 0, 0, 0 # dummy
214 /* ??? Why I need the accessed bit set in order for this to work? */
215 .quad 0x00cf9b000000ffff # __KERNEL32_CS
216 .quad 0x00af9b000000ffff # __KERNEL_CS
217 .quad 0x00cf93000000ffff # __KERNEL_DS
220 .word 0 # idt limit = 0
221 .word 0, 0 # idt base = 0L
224 .word 0x800 # gdt limit=2048,
226 .word 0, 0 # gdt base (filled in later)
234 movb $0xba,%al ; outb %al,$0x80
238 movb $0xb3,%al ; outb %al,$0x80
242 movb $0xbc,%al ; outb %al,$0x80
246 /* This code uses an extended set of video mode numbers. These include:
247 * Aliases for standard modes
251 * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
252 * of compatibility when extending the table. These are between 0x00 and 0xff.
254 #define VIDEO_FIRST_MENU 0x0000
256 /* Standard BIOS video modes (BIOS number + 0x0100) */
257 #define VIDEO_FIRST_BIOS 0x0100
259 /* VESA BIOS video modes (VESA number + 0x0200) */
260 #define VIDEO_FIRST_VESA 0x0200
262 /* Video7 special modes (BIOS number + 0x0900) */
263 #define VIDEO_FIRST_V7 0x0900
265 # Setting of user mode (AX=mode ID) => CF=success
272 testb $VIDEO_RECALC>>8, %ah
275 cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah
278 cmpb $VIDEO_FIRST_SPECIAL>>8, %ah
281 cmpb $VIDEO_FIRST_V7>>8, %ah
285 cmpb $VIDEO_FIRST_VESA>>8, %ah
293 # jz setbios Add bios modes later
299 subb $VIDEO_FIRST_VESA>>8, %bh
300 orw $0x4000, %bx # Use linear frame buffer
301 movw $0x4f02, %ax # VESA BIOS mode set call
303 cmpw $0x004f, %ax # AL=4f if implemented
304 jnz _setbada # AH=0 if OK
309 _setbada: jmp setbada
311 wakeup_stack_begin: # Stack grows down
314 wakeup_stack: # Just below end of page
319 # acpi_copy_wakeup_routine
321 # Copy the above routine to low memory.
324 # %rdi: place to copy wakeup routine to
326 # Returned address is location of code in low memory (past data and stack)
329 ENTRY(acpi_copy_wakeup_routine)
333 movl saved_video_mode, %edx
334 movl %edx, video_mode - wakeup_start (,%rdi)
335 movl acpi_video_flags, %edx
336 movl %edx, video_flags - wakeup_start (,%rdi)
337 movq $0x12345678, real_magic - wakeup_start (,%rdi)
338 movq $0x123456789abcdef0, %rdx
339 movq %rdx, saved_magic
341 movl saved_magic - __START_KERNEL_map, %eax
342 cmpl $0x9abcdef0, %eax
345 # restore the regs we used
348 ENTRY(do_suspend_lowlevel_s4bios)
353 .globl do_suspend_lowlevel
354 .type do_suspend_lowlevel,@function
359 call save_processor_state
361 movq %rsp, saved_context_esp(%rip)
362 movq %rax, saved_context_eax(%rip)
363 movq %rbx, saved_context_ebx(%rip)
364 movq %rcx, saved_context_ecx(%rip)
365 movq %rdx, saved_context_edx(%rip)
366 movq %rbp, saved_context_ebp(%rip)
367 movq %rsi, saved_context_esi(%rip)
368 movq %rdi, saved_context_edi(%rip)
369 movq %r8, saved_context_r08(%rip)
370 movq %r9, saved_context_r09(%rip)
371 movq %r10, saved_context_r10(%rip)
372 movq %r11, saved_context_r11(%rip)
373 movq %r12, saved_context_r12(%rip)
374 movq %r13, saved_context_r13(%rip)
375 movq %r14, saved_context_r14(%rip)
376 movq %r15, saved_context_r15(%rip)
377 pushfq ; popq saved_context_eflags(%rip)
379 movq $.L97, saved_rip(%rip)
390 jmp acpi_enter_sleep_state
397 movq saved_context+58(%rip), %rax
399 movq saved_context+50(%rip), %rax
401 movq saved_context+42(%rip), %rax
403 movq saved_context+34(%rip), %rax
405 pushq saved_context_eflags(%rip) ; popfq
406 movq saved_context_esp(%rip), %rsp
407 movq saved_context_ebp(%rip), %rbp
408 movq saved_context_eax(%rip), %rax
409 movq saved_context_ebx(%rip), %rbx
410 movq saved_context_ecx(%rip), %rcx
411 movq saved_context_edx(%rip), %rdx
412 movq saved_context_esi(%rip), %rsi
413 movq saved_context_edi(%rip), %rdi
414 movq saved_context_r08(%rip), %r8
415 movq saved_context_r09(%rip), %r9
416 movq saved_context_r10(%rip), %r10
417 movq saved_context_r11(%rip), %r11
418 movq saved_context_r12(%rip), %r12
419 movq saved_context_r13(%rip), %r13
420 movq saved_context_r14(%rip), %r14
421 movq saved_context_r15(%rip), %r15
425 jmp restore_processor_state
428 .size do_suspend_lowlevel,.Lfe5-do_suspend_lowlevel
432 ENTRY(saved_rbp) .quad 0
433 ENTRY(saved_rsi) .quad 0
434 ENTRY(saved_rdi) .quad 0
435 ENTRY(saved_rbx) .quad 0
437 ENTRY(saved_rip) .quad 0
438 ENTRY(saved_rsp) .quad 0
440 ENTRY(saved_magic) .quad 0