xref: /linux/arch/x86/platform/olpc/xo1-wakeup.S (revision 0d456bad36d42d16022be045c8a53ddbb59ee478)
1.text
2#include <linux/linkage.h>
3#include <asm/segment.h>
4#include <asm/page.h>
5#include <asm/pgtable_32.h>
6
7	.macro writepost,value
8		movb $0x34, %al
9		outb %al, $0x70
10		movb $\value, %al
11		outb %al, $0x71
12	.endm
13
14wakeup_start:
15	# OFW lands us here, running in protected mode, with a
16	# kernel-compatible GDT already setup.
17
18	# Clear any dangerous flags
19	pushl $0
20	popfl
21
22	writepost 0x31
23
24	# Set up %cr3
25	movl $initial_page_table - __PAGE_OFFSET, %eax
26	movl %eax, %cr3
27
28	movl saved_cr4, %eax
29	movl %eax, %cr4
30
31	movl saved_cr0, %eax
32	movl %eax, %cr0
33
34	# Control registers were modified, pipeline resync is needed
35	jmp 1f
361:
37
38	movw    $__KERNEL_DS, %ax
39	movw    %ax, %ss
40	movw    %ax, %ds
41	movw    %ax, %es
42	movw    %ax, %fs
43	movw    %ax, %gs
44
45	lgdt    saved_gdt
46	lidt    saved_idt
47	lldt    saved_ldt
48	ljmp    $(__KERNEL_CS),$1f
491:
50	movl    %cr3, %eax
51	movl    %eax, %cr3
52	wbinvd
53
54	# Go back to the return point
55	jmp ret_point
56
57save_registers:
58	sgdt  saved_gdt
59	sidt  saved_idt
60	sldt  saved_ldt
61
62	pushl %edx
63	movl %cr4, %edx
64	movl %edx, saved_cr4
65
66	movl %cr0, %edx
67	movl %edx, saved_cr0
68
69	popl %edx
70
71	movl %ebx, saved_context_ebx
72	movl %ebp, saved_context_ebp
73	movl %esi, saved_context_esi
74	movl %edi, saved_context_edi
75
76	pushfl
77	popl saved_context_eflags
78
79	ret
80
81restore_registers:
82	movl saved_context_ebp, %ebp
83	movl saved_context_ebx, %ebx
84	movl saved_context_esi, %esi
85	movl saved_context_edi, %edi
86
87	pushl saved_context_eflags
88	popfl
89
90	ret
91
92ENTRY(do_olpc_suspend_lowlevel)
93	call	save_processor_state
94	call	save_registers
95
96	# This is the stack context we want to remember
97	movl %esp, saved_context_esp
98
99	pushl	$3
100	call	xo1_do_sleep
101
102	jmp	wakeup_start
103	.p2align 4,,7
104ret_point:
105	movl    saved_context_esp, %esp
106
107	writepost 0x32
108
109	call	restore_registers
110	call	restore_processor_state
111	ret
112
113.data
114saved_gdt:             .long   0,0
115saved_idt:             .long   0,0
116saved_ldt:             .long   0
117saved_cr4:             .long   0
118saved_cr0:             .long   0
119saved_context_esp:     .long   0
120saved_context_edi:     .long   0
121saved_context_esi:     .long   0
122saved_context_ebx:     .long   0
123saved_context_ebp:     .long   0
124saved_context_eflags:  .long   0
125