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
@
6
@    This file is part of emBIOS.
7
@
8
@    emBIOS is free software: you can redistribute it and/or
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
@
13
@    emBIOS is distributed in the hope that it will be useful,
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
19
@    along with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
@
21
@
22
 
23
 
24
.section .icode.contextswitch, "ax", %progbits
25
.align 2
26
.global context_switch
27
.type context_switch, %function
28
context_switch:
15 theseven 29
	mrs	r1, cpsr
43 theseven 30
	msr	cpsr_c, #0xdf
14 theseven 31
	ldr	r0, =current_thread
32
	ldr	r0, [r0]
33
	stmia	r0!, {r0-r14}
34
	str	lr, [r0], #4
35
	str	r1, [r0]
15 theseven 36
	msr	cpsr_c, #0xd2
14 theseven 37
	adr	lr, resume_thread
15 theseven 38
	mov	r0, #-1
14 theseven 39
	b	scheduler_switch
40
.size context_switch, .-context_switch
41
 
43 theseven 42
.global syscall_handler
43
.type syscall_handler, %function
44
syscall_handler:
45
	ldr	sp, [lr,#-4]
46
	bics	sp, sp, #0xff000000
47
	beq	syscall_breakpoint
48
	mov	r12, lr
49
	mrs	sp, spsr
50
	msr	cpsr_c, sp
51
	mov	lr, r12
52
	ldr	r12, [lr,#-4]
53
	bic	r12, r12, #0xff000000
54
	cmp	r12, #(swilist_end-swilist_start)/4+1
55
	movcs	r0, #0
56
	addcc	pc, pc, r12,lsl#2
57
	adr	r1, unknown_swi_string
58
	mov	r2, r12
59
swilist_start:
60
	b	panicf
61
	b	get_syscall_table
147 theseven 62
	b	__clzsi2
63
	b	__aeabi_uidivmod
64
	b	__aeabi_idivmod
43 theseven 65
swilist_end:
66
 
67
syscall_breakpoint:
68
	msr	cpsr_c, #0xd3
69
	ldr	sp, =current_thread
70
	ldr	sp, [sp]
71
	stmia	sp!, {r0-r12}
72
	mov	r2, lr
73
	mrs	r3, spsr
74
	mov	r4, #1
75
	mov	r5, sp
76
	msr	cpsr_c, #0xdf
77
	mov	r0, sp
78
	mov	r1, lr
79
	msr	cpsr_c, #0xd2
80
	stmia	r5, {r0-r4}
389 theseven 81
	bl	scheduler_pause_accounting
43 theseven 82
	adr	lr, resume_thread
83
	mov	r0, #-1
84
	b	scheduler_switch
85
.size syscall_handler, .-syscall_handler
86
 
14 theseven 87
.global irq_handler
88
.type irq_handler, %function
43 theseven 89
was_in_svc_mode:
90
	msr	cpsr_c, #0xd3
91
	sub	r3, lr, #4
92
	mrs	r4, spsr
93
	msr	cpsr_c, r5
94
	b enter_irqhandler
95
 
14 theseven 96
irq_handler:
97
	str	r12, [sp,#-4]
98
	ldr	r12, =current_thread
99
	ldr	r12, [r12]
100
	stmia	r12!, {r0-r11}
101
	ldr	r0, [sp,#-4]
102
	mrs	r5, cpsr
103
	mrs	r4, spsr
43 theseven 104
	msr	cpsr_c, #0xdf
14 theseven 105
	mov	r1, sp
106
	mov	r2, lr
43 theseven 107
	and	r3, r4, #0x1f
108
	cmp	r3, #0x13
109
	beq	was_in_svc_mode
14 theseven 110
	msr	cpsr_c, r5
111
	sub	r3, lr, #4
43 theseven 112
enter_irqhandler:
14 theseven 113
	stmia	r12, {r0-r4}
389 theseven 114
	bl	scheduler_pause_accounting
14 theseven 115
	bl	irqhandler
116
@ fallthrough
117
 
118
.global resume_thread
119
.type resume_thread, %function
120
resume_thread:
389 theseven 121
	bl	scheduler_resume_accounting
15 theseven 122
	ldr	lr, =current_thread
123
	ldr	lr, [lr]
124
	mov	r0, lr
125
	ldr	r1, [lr,#0x40]
126
	ldr	lr, [lr,#0x3c]
127
	msr	spsr_all, r1
43 theseven 128
	msr	cpsr_c, 0xdf
15 theseven 129
	ldmia	r0, {r0-r14}
14 theseven 130
	msr	cpsr_c, #0xd2
131
	movs	pc, lr
132
.size irq_handler, .-irq_handler
133
.size resume_thread, .-resume_thread
134
 
135
.global enter_critical_section
136
.type enter_critical_section, %function
137
enter_critical_section:
138
	mrs	r0, cpsr
15 theseven 139
	orr	r1, r0, #0xc0
140
	msr	cpsr_c, r1
14 theseven 141
	mov	pc, lr
142
.size enter_critical_section, .-enter_critical_section
143
 
144
.global leave_critical_section
145
.type leave_critical_section, %function
146
leave_critical_section:
147
	msr	cpsr_c, r0
148
	mov	pc, lr
149
.size leave_critical_section, .-leave_critical_section
43 theseven 150
 
127 theseven 151
.global execfirmware
152
.type execfirmware, %function
153
execfirmware:
140 theseven 154
	str	r0, [sp,#-4]!
219 theseven 155
	bl	interrupt_shutdown
140 theseven 156
	bl	clean_dcache
157
	ldr	r1, [sp], #4
127 theseven 158
	msr	cpsr_c, #0xd3
140 theseven 159
	mrc	p15, 0, r0,c1,c0
312 theseven 160
	bic	r0, r0, #5
140 theseven 161
	mcr	p15, 0, r0,c1,c0
312 theseven 162
	mov	r0, #0
140 theseven 163
	mcr	p15, 0, r0,c7,c5
164
	bx	r1
127 theseven 165
.size execfirmware, .-execfirmware
166
 
43 theseven 167
unknown_swi_string:
99 theseven 168
	.ascii "Unhandled SWI %06X\0"