2 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
4 * From coreboot src/arch/x86/wakeup.S
6 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/acpi_s3.h>
10 #include <asm/processor.h>
11 #include <asm/processor-flags.h>
13 #define RELOCATED(x) ((x) - __wakeup + WAKEUP_BASE)
15 #define CODE_SEG (X86_GDT_ENTRY_16BIT_CS * X86_GDT_ENTRY_SIZE)
16 #define DATA_SEG (X86_GDT_ENTRY_16BIT_DS * X86_GDT_ENTRY_SIZE)
21 /* First prepare the jmp to the resume vector */
22 mov 0x4(%esp), %eax /* vector */
23 /* last 4 bits of linear addr are taken as offset */
25 movw %ax, (__wakeup_offset)
27 /* the rest is taken as segment */
29 movw %ax, (__wakeup_segment)
31 /* Activate the right segment descriptor real mode */
32 ljmp $CODE_SEG, $RELOCATED(1f)
34 /* 16 bit code from here on... */
38 * Load the segment registers w/ properly configured segment
39 * descriptors. They will retain these configurations (limits,
40 * writability, etc.) once protected mode is turned off.
49 /* Turn off protection */
51 andl $~X86_CR0_PE, %eax
54 /* Now really going into real mode */
55 ljmp $0, $RELOCATED(1f)
65 * This is a FAR JMP to the OS waking vector.
66 * The C code changes the address to be correct.
70 __wakeup_offset = RELOCATED(.)
73 __wakeup_segment = RELOCATED(.)