blob: cf69081073b5414700b926761180b68df5cfd6a4 [file] [log] [blame]
Thomas Gleixner767a67b2019-06-01 10:08:44 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Jan Beulichec7fd342013-03-11 10:06:12 +00002 .text
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/linkage.h>
4#include <asm/segment.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -08005#include <asm/page_types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Thomas Gleixner767a67b2019-06-01 10:08:44 +02007# Copyright 2003, 2008 Pavel Machek <pavel@suse.cz
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 .code32
10 ALIGN
11
Jiri Slaby78762b02019-10-11 13:51:05 +020012SYM_CODE_START(wakeup_pmode_return)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 movw $__KERNEL_DS, %ax
14 movw %ax, %ss
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 movw %ax, %fs
16 movw %ax, %gs
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Ingo Molnarffa64ef2015-06-22 14:40:03 +020018 movw $__USER_DS, %ax
19 movw %ax, %ds
20 movw %ax, %es
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 # reload the gdt, as we need the full 32 bit address
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 lidt saved_idt
24 lldt saved_ldt
Pavel Macheke44b7b72008-04-10 23:28:10 +020025 ljmp $(__KERNEL_CS), $1f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261:
27 movl %cr3, %eax
28 movl %eax, %cr3
29 wbinvd
30
31 # and restore the stack ... but you need gdt for this to work
32 movl saved_context_esp, %esp
33
34 movl %cs:saved_magic, %eax
35 cmpl $0x12345678, %eax
36 jne bogus_magic
37
38 # jump to place where we left off
Pavel Macheke44b7b72008-04-10 23:28:10 +020039 movl saved_eip, %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 jmp *%eax
Jiri Slaby78762b02019-10-11 13:51:05 +020041SYM_CODE_END(wakeup_pmode_return)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43bogus_magic:
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 jmp bogus_magic
45
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Pavel Macheke44b7b72008-04-10 23:28:10 +020048save_registers:
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 sidt saved_idt
50 sldt saved_ldt
51 str saved_tss
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 leal 4(%esp), %eax
54 movl %eax, saved_context_esp
Pavel Macheke44b7b72008-04-10 23:28:10 +020055 movl %ebx, saved_context_ebx
56 movl %ebp, saved_context_ebp
57 movl %esi, saved_context_esi
58 movl %edi, saved_context_edi
59 pushfl
60 popl saved_context_eflags
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Pavel Macheke44b7b72008-04-10 23:28:10 +020062 movl $ret_point, saved_eip
Peter Zijlstraf94909c2021-12-04 14:43:40 +010063 RET
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65
66restore_registers:
Pavel Macheke44b7b72008-04-10 23:28:10 +020067 movl saved_context_ebp, %ebp
68 movl saved_context_ebx, %ebx
69 movl saved_context_esi, %esi
70 movl saved_context_edi, %edi
71 pushl saved_context_eflags
72 popfl
Peter Zijlstraf94909c2021-12-04 14:43:40 +010073 RET
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Jiri Slaby78762b02019-10-11 13:51:05 +020075SYM_CODE_START(do_suspend_lowlevel)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 call save_processor_state
77 call save_registers
Len Brown3b6961b2012-07-26 19:40:08 -040078 pushl $3
Lv Zheng40bce102013-10-31 09:31:18 +080079 call x86_acpi_enter_sleep_state
Len Brown3b6961b2012-07-26 19:40:08 -040080 addl $4, %esp
William Morrrow4e6e6502006-08-14 22:37:31 -070081
82# In case of S3 failure, we'll emerge here. Jump
83# to ret_point to recover
84 jmp ret_point
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 .p2align 4,,7
86ret_point:
87 call restore_registers
88 call restore_processor_state
Peter Zijlstraf94909c2021-12-04 14:43:40 +010089 RET
Jiri Slaby78762b02019-10-11 13:51:05 +020090SYM_CODE_END(do_suspend_lowlevel)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Shaohua Lidaacf8b2006-06-23 02:04:50 -070092.data
Linus Torvalds1da177e2005-04-16 15:20:36 -070093ALIGN
Jiri Slaby37503f732019-10-11 13:50:42 +020094SYM_DATA(saved_magic, .long 0)
Jiri Slaby5a064d32019-01-30 13:46:45 +010095saved_eip: .long 0
Shaohua Lidaacf8b2006-06-23 02:04:50 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097# saved registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070098saved_idt: .long 0,0
99saved_ldt: .long 0
100saved_tss: .long 0
101