summaryrefslogtreecommitdiff
path: root/arch/x86/platform/olpc/xo1-wakeup.S
blob: 948deb289753f8a26c1cbf3e47d96898e97fe983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
.text
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/page.h>
#include <asm/pgtable_32.h>

	.macro writepost,value
		movb $0x34, %al
		outb %al, $0x70
		movb $\value, %al
		outb %al, $0x71
	.endm

wakeup_start:
	# OFW lands us here, running in protected mode, with a
	# kernel-compatible GDT already setup.

	# Clear any dangerous flags
	pushl $0
	popfl

	writepost 0x31

	# Set up %cr3
	movl $initial_page_table - __PAGE_OFFSET, %eax
	movl %eax, %cr3

	movl saved_cr4, %eax
	movl %eax, %cr4

	movl saved_cr0, %eax
	movl %eax, %cr0

	# Control registers were modified, pipeline resync is needed
	jmp 1f
1:

	movw    $__KERNEL_DS, %ax
	movw    %ax, %ss
	movw    %ax, %ds
	movw    %ax, %es
	movw    %ax, %fs
	movw    %ax, %gs

	lgdt    saved_gdt
	lidt    saved_idt
	lldt    saved_ldt
	ljmp    $(__KERNEL_CS),$1f
1:
	movl    %cr3, %eax
	movl    %eax, %cr3
	wbinvd

	# Go back to the return point
	jmp ret_point

save_registers:
	sgdt  saved_gdt
	sidt  saved_idt
	sldt  saved_ldt

	pushl %edx
	movl %cr4, %edx
	movl %edx, saved_cr4

	movl %cr0, %edx
	movl %edx, saved_cr0

	popl %edx

	movl %ebx, saved_context_ebx
	movl %ebp, saved_context_ebp
	movl %esi, saved_context_esi
	movl %edi, saved_context_edi

	pushfl
	popl saved_context_eflags

	ret

restore_registers:
	movl saved_context_ebp, %ebp
	movl saved_context_ebx, %ebx
	movl saved_context_esi, %esi
	movl saved_context_edi, %edi

	pushl saved_context_eflags
	popfl

	ret

ENTRY(do_olpc_suspend_lowlevel)
	call	save_processor_state
	call	save_registers

	# This is the stack context we want to remember
	movl %esp, saved_context_esp

	pushl	$3
	call	xo1_do_sleep

	jmp	wakeup_start
	.p2align 4,,7
ret_point:
	movl    saved_context_esp, %esp

	writepost 0x32

	call	restore_registers
	call	restore_processor_state
	ret

.data
saved_gdt:             .long   0,0
saved_idt:             .long   0,0
saved_ldt:             .long   0
saved_cr4:             .long   0
saved_cr0:             .long   0
saved_context_esp:     .long   0
saved_context_edi:     .long   0
saved_context_esi:     .long   0
saved_context_ebx:     .long   0
saved_context_ebp:     .long   0
saved_context_eflags:  .long   0