2 #include <linux/linkage.h>
3 #include <asm/segment.h>
4 #include <asm/pgtable.h>
8 # Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
10 # wakeup_code runs in real mode, and at unknown address (determined at run-time).
11 # Therefore it must only use relative jumps/calls.
13 # Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled
15 # If physical address of wakeup_code is 0x12345, BIOS should call us with
16 # cs = 0x1234, eip = 0x05
42 # Running in *copy* of this code, somewhere in low 1MB.
44 movb $0xa1, %al ; outb %al, $0x80
49 movw %ax, %ds # Make ds:0 point to wakeup_start
52 # Data segment must be set up before we can see whether to beep.
53 testl $1, beep_flags - wakeup_code
58 # Private stack is needed for ASUS board
59 mov $(wakeup_stack - wakeup_code), %sp
61 pushl $0 # Kill any dangerous flags
64 movl real_magic - wakeup_code, %eax
65 cmpl $0x12345678, %eax
68 call verify_cpu # Verify the cpu supports long
73 testl $1, video_flags - wakeup_code
77 movw %ax, %ds # Bios might have played with that
81 testl $2, video_flags - wakeup_code
83 mov video_mode - wakeup_code, %ax
89 movw $0x0e00 + 'L', %fs:(0x10)
91 movb $0xa2, %al ; outb %al, $0x80
93 mov %ds, %ax # Find 32bit wakeup_code addr
94 movzx %ax, %esi # (Convert %ds:gdt to a liner ptr)
97 addl %esi, wakeup_32_vector - wakeup_code
98 addl %esi, wakeup_long64_vector - wakeup_code
99 addl %esi, gdt_48a + 2 - wakeup_code # Fixup the gdt pointer
101 lidtl %ds:idt_48a - wakeup_code
102 lgdtl %ds:gdt_48a - wakeup_code # load gdt with whatever is
105 movl $1, %eax # protected mode (PE) bit
106 lmsw %ax # This is it!
110 ljmpl *(wakeup_32_vector - wakeup_code)
114 .long wakeup_32 - wakeup_code
115 .word __KERNEL32_CS, 0
119 # Running in this code, but at low address; paging is not yet turned on.
120 movb $0xa5, %al ; outb %al, $0x80
122 movl $__KERNEL_DS, %eax
125 movw $0x0e00 + 'i', %ds:(0xb8012)
126 movb $0xa8, %al ; outb %al, $0x80;
129 * Prepare for entering 64bits mode
137 /* Setup early boot stage 4 level pagetables */
138 leal (wakeup_level4_pgt - wakeup_code)(%esi), %eax
141 /* Check if nx is implemented */
142 movl $0x80000001, %eax
146 /* Enable Long Mode */
148 btsl $_EFER_LME, %eax
150 /* No Execute supported? */
155 /* Make changes effective */
156 1: movl $MSR_EFER, %ecx
161 btsl $31, %eax /* Enable paging and in turn activate Long Mode */
162 btsl $0, %eax /* Enable protected mode */
164 /* Make changes effective */
170 CR3 must point to PML4
171 Next instruction must be a branch
172 This must be on identity-mapped page
175 * At this point we're in long mode but in 32bit compatibility mode
176 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
177 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we load
178 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
181 /* Finally jump in 64bit mode */
182 ljmp *(wakeup_long64_vector - wakeup_code)(%esi)
185 wakeup_long64_vector:
186 .long wakeup_long64 - wakeup_code
191 /* Hooray, we are in Long 64-bit mode (but still running in
196 * We must switch to a new descriptor in kernel space for the GDT
197 * because soon the kernel won't have access anymore to the userspace
198 * addresses where we're currently running on. We have to do that here
199 * because in 32bit we couldn't load a 64bit linear address.
203 movw $0x0e00 + 'n', %ds:(0xb8014)
204 movb $0xa9, %al ; outb %al, $0x80
206 movq saved_magic, %rax
207 movq $0x123456789abcdef0, %rdx
211 movw $0x0e00 + 'u', %ds:(0xb8016)
215 movw $__KERNEL_DS, %ax
223 movw $0x0e00 + 'x', %ds:(0xb8018)
229 movw $0x0e00 + '!', %ds:(0xb801a)
237 /* Its good to keep gdt in sync with one in trampoline.S */
238 .word 0, 0, 0, 0 # dummy
239 /* ??? Why I need the accessed bit set in order for this to work? */
240 .quad 0x00cf9b000000ffff # __KERNEL32_CS
241 .quad 0x00af9b000000ffff # __KERNEL_CS
242 .quad 0x00cf93000000ffff # __KERNEL_DS
245 .word 0 # idt limit = 0
246 .word 0, 0 # idt base = 0L
249 .word 0x800 # gdt limit=2048,
251 .long gdta - wakeup_code # gdt base (relocated in later)
260 movb $0xba,%al ; outb %al,$0x80
265 movb $0xb3,%al ; outb %al,$0x80
270 movb $0xbc,%al ; outb %al,$0x80
273 #include "../verify_cpu.S"
275 /* This code uses an extended set of video mode numbers. These include:
276 * Aliases for standard modes
280 * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
281 * of compatibility when extending the table. These are between 0x00 and 0xff.
283 #define VIDEO_FIRST_MENU 0x0000
285 /* Standard BIOS video modes (BIOS number + 0x0100) */
286 #define VIDEO_FIRST_BIOS 0x0100
288 /* VESA BIOS video modes (VESA number + 0x0200) */
289 #define VIDEO_FIRST_VESA 0x0200
291 /* Video7 special modes (BIOS number + 0x0900) */
292 #define VIDEO_FIRST_V7 0x0900
294 # Setting of user mode (AX=mode ID) => CF=success
302 testb $VIDEO_RECALC>>8, %ah
305 cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah
308 cmpb $VIDEO_FIRST_SPECIAL>>8, %ah
311 cmpb $VIDEO_FIRST_V7>>8, %ah
315 cmpb $VIDEO_FIRST_VESA>>8, %ah
323 # jz setbios Add bios modes later
329 subb $VIDEO_FIRST_VESA>>8, %bh
330 orw $0x4000, %bx # Use linear frame buffer
331 movw $0x4f02, %ax # VESA BIOS mode set call
333 cmpw $0x004f, %ax # AL=4f if implemented
334 jnz _setbada # AH=0 if OK
339 _setbada: jmp setbada
341 wakeup_stack_begin: # Stack grows down
344 wakeup_stack: # Just below end of page
347 ENTRY(wakeup_level4_pgt)
348 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
350 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
351 .quad level3_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
356 # acpi_copy_wakeup_routine
358 # Copy the above routine to low memory.
361 # %rdi: place to copy wakeup routine to
363 # Returned address is location of code in low memory (past data and stack)
366 ENTRY(acpi_copy_wakeup_routine)
370 movl s2ram_beep, %edx
371 movl %edx, beep_flags - wakeup_start (,%rdi)
372 movl saved_video_mode, %edx
373 movl %edx, video_mode - wakeup_start (,%rdi)
374 movl acpi_video_flags, %edx
375 movl %edx, video_flags - wakeup_start (,%rdi)
376 movq $0x12345678, real_magic - wakeup_start (,%rdi)
377 movq $0x123456789abcdef0, %rdx
378 movq %rdx, saved_magic
380 movq saved_magic, %rax
381 movq $0x123456789abcdef0, %rdx
385 # restore the regs we used
388 ENTRY(do_suspend_lowlevel_s4bios)
393 .globl do_suspend_lowlevel
394 .type do_suspend_lowlevel,@function
399 call save_processor_state
401 movq %rsp, saved_context_esp(%rip)
402 movq %rax, saved_context_eax(%rip)
403 movq %rbx, saved_context_ebx(%rip)
404 movq %rcx, saved_context_ecx(%rip)
405 movq %rdx, saved_context_edx(%rip)
406 movq %rbp, saved_context_ebp(%rip)
407 movq %rsi, saved_context_esi(%rip)
408 movq %rdi, saved_context_edi(%rip)
409 movq %r8, saved_context_r08(%rip)
410 movq %r9, saved_context_r09(%rip)
411 movq %r10, saved_context_r10(%rip)
412 movq %r11, saved_context_r11(%rip)
413 movq %r12, saved_context_r12(%rip)
414 movq %r13, saved_context_r13(%rip)
415 movq %r14, saved_context_r14(%rip)
416 movq %r15, saved_context_r15(%rip)
417 pushfq ; popq saved_context_eflags(%rip)
419 movq $.L97, saved_rip(%rip)
430 jmp acpi_enter_sleep_state
437 movq saved_context+58(%rip), %rax
439 movq saved_context+50(%rip), %rax
441 movq saved_context+42(%rip), %rax
443 movq saved_context+34(%rip), %rax
445 pushq saved_context_eflags(%rip) ; popfq
446 movq saved_context_esp(%rip), %rsp
447 movq saved_context_ebp(%rip), %rbp
448 movq saved_context_eax(%rip), %rax
449 movq saved_context_ebx(%rip), %rbx
450 movq saved_context_ecx(%rip), %rcx
451 movq saved_context_edx(%rip), %rdx
452 movq saved_context_esi(%rip), %rsi
453 movq saved_context_edi(%rip), %rdi
454 movq saved_context_r08(%rip), %r8
455 movq saved_context_r09(%rip), %r9
456 movq saved_context_r10(%rip), %r10
457 movq saved_context_r11(%rip), %r11
458 movq saved_context_r12(%rip), %r12
459 movq saved_context_r13(%rip), %r13
460 movq saved_context_r14(%rip), %r14
461 movq saved_context_r15(%rip), %r15
465 jmp restore_processor_state
468 .size do_suspend_lowlevel,.Lfe5-do_suspend_lowlevel
472 ENTRY(saved_rbp) .quad 0
473 ENTRY(saved_rsi) .quad 0
474 ENTRY(saved_rdi) .quad 0
475 ENTRY(saved_rbx) .quad 0
477 ENTRY(saved_rip) .quad 0
478 ENTRY(saved_rsp) .quad 0
480 ENTRY(saved_magic) .quad 0