Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 theseven 1
@
2
@
3
@    Copyright 2010 TheSeven
4
@
5
@
427 farthen 6
@    This file is part of emCORE.
14 theseven 7
@
427 farthen 8
@    emCORE is free software: you can redistribute it and/or
14 theseven 9
@    modify it under the terms of the GNU General Public License as
10
@    published by the Free Software Foundation, either version 2 of the
11
@    License, or (at your option) any later version.
12
@
427 farthen 13
@    emCORE is distributed in the hope that it will be useful,
14 theseven 14
@    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
@    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
@    See the GNU General Public License for more details.
17
@
18
@    You should have received a copy of the GNU General Public License
427 farthen 19
@    along with emCORE.  If not, see <http://www.gnu.org/licenses/>.
14 theseven 20
@
21
@
22
 
563 theseven 23
#define ASM_FILE
24
#include "global.h"
14 theseven 25
 
702 theseven 26
.section .icode.contextswitch, "ax", %progbits
14 theseven 27
.align 2
702 theseven 28
.global panic_recover
29
.type panic_recover, %function
30
panic_recover:
31
	mrs	r0, cpsr
32
	and	r0, r0, #0x1f
33
	cmp	r0, #0x17
34
	cmpne	r0, #0x1b
35
	bne	yield
36
	ldr	sp, =_abortstackend - 0x44
37
	ldr	r9, =current_thread
38
	ldr	lr, [r9]
39
	ldmia	sp!, {r0-r7}
40
	stmia	lr!, {r0-r7}
41
	ldmia	sp!, {r0-r8}
42
	stmia	lr!, {r0-r8}
43
	msr	cpsr_c, #0xd2
44
	bl	scheduler_pause_accounting
45
	adr	lr, resume_thread
46
	mov	r0, #0
47
	mov	r1, r9
48
	b	scheduler_switch
49
.size panic_recover, .-panic_recover
50
 
593 theseven 51
.global yield
52
.type yield, %function
53
yield:
15 theseven 54
	mrs	r1, cpsr
43 theseven 55
	msr	cpsr_c, #0xdf
14 theseven 56
	ldr	r0, =current_thread
57
	ldr	r0, [r0]
595 theseven 58
	stmia	r0, {r0-r14}
59
	str	lr, [r0,#0x3c]
60
	str	r1, [r0,#0x40]
15 theseven 61
	msr	cpsr_c, #0xd2
595 theseven 62
	mov	r4, r0
594 theseven 63
	bl	scheduler_pause_accounting
14 theseven 64
	adr	lr, resume_thread
595 theseven 65
	mov	r0, #0
66
	mov	r1, r4
14 theseven 67
	b	scheduler_switch
593 theseven 68
.size yield, .-yield
14 theseven 69
 
43 theseven 70
.global syscall_handler
71
.type syscall_handler, %function
72
syscall_handler:
73
	ldr	sp, [lr,#-4]
74
	bics	sp, sp, #0xff000000
75
	beq	syscall_breakpoint
76
	mov	r12, lr
77
	mrs	sp, spsr
78
	msr	cpsr_c, sp
79
	mov	lr, r12
80
	ldr	r12, [lr,#-4]
81
	bic	r12, r12, #0xff000000
82
	cmp	r12, #(swilist_end-swilist_start)/4+1
83
	movcs	r0, #0
84
	addcc	pc, pc, r12,lsl#2
85
	adr	r1, unknown_swi_string
86
	mov	r2, r12
87
swilist_start:
88
	b	panicf
89
	b	get_syscall_table
90
swilist_end:
91
 
92
syscall_breakpoint:
93
	msr	cpsr_c, #0xd3
94
	ldr	sp, =current_thread
95
	ldr	sp, [sp]
96
	stmia	sp!, {r0-r12}
97
	mov	r2, lr
98
	mrs	r3, spsr
99
	mov	r4, #1
100
	mov	r5, sp
101
	msr	cpsr_c, #0xdf
102
	mov	r0, sp
103
	mov	r1, lr
104
	msr	cpsr_c, #0xd2
105
	stmia	r5, {r0-r4}
389 theseven 106
	bl	scheduler_pause_accounting
43 theseven 107
	adr	lr, resume_thread
595 theseven 108
	mov	r0, #0
109
	mov	r1, #0
43 theseven 110
	b	scheduler_switch
111
.size syscall_handler, .-syscall_handler
112
 
14 theseven 113
.global irq_handler
114
.type irq_handler, %function
43 theseven 115
was_in_svc_mode:
116
	msr	cpsr_c, #0xd3
117
	sub	r3, lr, #4
118
	mrs	r4, spsr
119
	msr	cpsr_c, r5
120
	b enter_irqhandler
121
 
14 theseven 122
irq_handler:
123
	str	r12, [sp,#-4]
124
	ldr	r12, =current_thread
125
	ldr	r12, [r12]
126
	stmia	r12!, {r0-r11}
127
	ldr	r0, [sp,#-4]
128
	mrs	r5, cpsr
129
	mrs	r4, spsr
43 theseven 130
	msr	cpsr_c, #0xdf
14 theseven 131
	mov	r1, sp
132
	mov	r2, lr
43 theseven 133
	and	r3, r4, #0x1f
134
	cmp	r3, #0x13
135
	beq	was_in_svc_mode
14 theseven 136
	msr	cpsr_c, r5
137
	sub	r3, lr, #4
43 theseven 138
enter_irqhandler:
14 theseven 139
	stmia	r12, {r0-r4}
389 theseven 140
	bl	scheduler_pause_accounting
14 theseven 141
	bl	irqhandler
142
@ fallthrough
143
 
144
.global resume_thread
145
.type resume_thread, %function
146
resume_thread:
389 theseven 147
	bl	scheduler_resume_accounting
15 theseven 148
	ldr	lr, =current_thread
149
	ldr	lr, [lr]
150
	mov	r0, lr
151
	ldr	r1, [lr,#0x40]
152
	ldr	lr, [lr,#0x3c]
153
	msr	spsr_all, r1
43 theseven 154
	msr	cpsr_c, 0xdf
15 theseven 155
	ldmia	r0, {r0-r14}
14 theseven 156
	msr	cpsr_c, #0xd2
157
	movs	pc, lr
158
.size irq_handler, .-irq_handler
159
.size resume_thread, .-resume_thread
160
 
161
.global enter_critical_section
162
.type enter_critical_section, %function
163
enter_critical_section:
164
	mrs	r0, cpsr
15 theseven 165
	orr	r1, r0, #0xc0
166
	msr	cpsr_c, r1
14 theseven 167
	mov	pc, lr
168
.size enter_critical_section, .-enter_critical_section
169
 
170
.global leave_critical_section
171
.type leave_critical_section, %function
172
leave_critical_section:
173
	msr	cpsr_c, r0
174
	mov	pc, lr
175
.size leave_critical_section, .-leave_critical_section
43 theseven 176
 
127 theseven 177
.global execfirmware
178
.type execfirmware, %function
179
execfirmware:
519 theseven 180
	ldr	sp, =_abortstackend
438 theseven 181
	stmfd	sp!, {r0-r2}
219 theseven 182
	bl	interrupt_shutdown
443 theseven 183
	mov	r0, sp
438 theseven 184
	msr	cpsr_c, #0xd3
443 theseven 185
	mov	sp, r0
438 theseven 186
	ldmfd	sp, {r0-r2}
187
	bl	memmove
140 theseven 188
	bl	clean_dcache
563 theseven 189
#ifdef HAVE_TARGETINIT_EXECFIRMWARE
190
	bl	targetinit_execfirmware
191
#endif
438 theseven 192
	ldr	r1, [sp]
140 theseven 193
	mrc	p15, 0, r0,c1,c0
312 theseven 194
	bic	r0, r0, #5
140 theseven 195
	mcr	p15, 0, r0,c1,c0
312 theseven 196
	mov	r0, #0
140 theseven 197
	mcr	p15, 0, r0,c7,c5
198
	bx	r1
127 theseven 199
.size execfirmware, .-execfirmware
200
 
43 theseven 201
unknown_swi_string:
99 theseven 202
	.ascii "Unhandled SWI %06X\0"