Subversion Repositories HelenOS-historic

Rev

Rev 1003 | Rev 1058 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
913 decky 1
#
2
# Copyright (C) 2006 Martin Decky
3
# All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
#
9
# - Redistributions of source code must retain the above copyright
10
#   notice, this list of conditions and the following disclaimer.
11
# - Redistributions in binary form must reproduce the above copyright
12
#   notice, this list of conditions and the following disclaimer in the
13
#   documentation and/or other materials provided with the distribution.
14
# - The name of the author may not be used to endorse or promote products
15
#   derived from this software without specific prior written permission.
16
#
17
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#
28
 
29
#include "regname.h"
30
 
914 decky 31
.data
32
 
33
flush_buffer:
933 decky 34
	.space (L1_CACHE_LINES * L1_CACHE_BYTES)
914 decky 35
 
913 decky 36
.text
37
 
38
.global memsetb
39
.global memcpy
956 decky 40
.global flush_instruction_cache
913 decky 41
.global jump_to_kernel
42
 
43
memsetb:
44
	rlwimi r5, r5, 8, 16, 23
45
	rlwimi r5, r5, 16, 0, 15
46
 
47
	addi r14, r3, -4
48
 
49
	cmplwi 0, r4, 4
50
	blt 7f
51
 
52
	stwu r5, 4(r14)
53
	beqlr
54
 
55
	andi. r15, r14, 3
56
	add r4, r15, r4
57
	subf r14, r15, r14
58
	srwi r15, r4, 2
59
	mtctr r15
60
 
61
	bdz 6f
62
 
63
	1:
64
		stwu r5, 4(r14)
65
		bdnz 1b
66
 
67
	6:
68
 
69
	andi. r4, r4, 3
70
 
71
	7:
72
 
73
	cmpwi 0, r4, 0
74
	beqlr
75
 
76
	mtctr r4
77
	addi r6, r6, 3
78
 
79
	8:
80
 
81
	stbu r5, 1(r14)
82
	bdnz 8b
83
 
84
	blr
85
 
86
memcpy:
87
	srwi. r7, r5, 3
88
	addi r6, r3, -4
89
	addi r4, r4, -4
90
	beq	2f
91
 
92
	andi. r0, r6, 3
93
	mtctr r7
94
	bne 5f
95
 
96
	1:
97
 
98
	lwz r7, 4(r4)
99
	lwzu r8, 8(r4)
100
	stw r7, 4(r6)
101
	stwu r8, 8(r6)
102
	bdnz 1b
103
 
104
	andi. r5, r5, 7
105
 
106
	2:
107
 
108
	cmplwi 0, r5, 4
109
	blt 3f
110
 
111
	lwzu r0, 4(r4)
112
	addi r5, r5, -4
113
	stwu r0, 4(r6)
114
 
115
	3:
116
 
117
	cmpwi 0, r5, 0
118
	beqlr
119
	mtctr r5
120
	addi r4, r4, 3
121
	addi r6, r6, 3
122
 
123
	4:
124
 
125
	lbzu r0, 1(r4)
126
	stbu r0, 1(r6)
127
	bdnz 4b
128
	blr
129
 
130
	5:
131
 
132
	subfic r0, r0, 4
133
	mtctr r0
134
 
135
	6:
136
 
137
	lbz r7, 4(r4)
138
	addi r4, r4, 1
139
	stb r7, 4(r6)
140
	addi r6, r6, 1
141
	bdnz 6b
142
	subf r5, r0, r5
143
	rlwinm. r7, r5, 32-3, 3, 31
144
	beq 2b
145
	mtctr r7
146
	b 1b
147
 
914 decky 148
flush_instruction_cache:
149
 
150
	# Flush data cache
151
 
152
	lis r3, flush_buffer@h
153
	ori r3, r3, flush_buffer@l
154
	li r4, L1_CACHE_LINES
155
	mtctr r4
156
 
157
	0:
158
 
159
	lwz r4, 0(r3)
160
	addi r3, r3, L1_CACHE_BYTES
161
	bdnz 0b
162
 
163
	# Invalidate instruction cache
164
 
165
	li r3, 0
1003 decky 166
	ori	r3, r3, (hid0_ice | hid0_dce | hid0_icfi | hid0_dci)
167
	mfspr r4, hid0
914 decky 168
	or r5, r4, r3
169
	isync
1003 decky 170
	mtspr hid0, r5
914 decky 171
	sync
172
	isync
173
 
174
	# Enable instruction cache
175
 
1003 decky 176
	ori	r5, r4, hid0_ice
177
	mtspr hid0, r5
914 decky 178
	sync
179
	isync
180
	blr
181
 
913 decky 182
jump_to_kernel:
1022 decky 183
 
184
	# r3 = kernel_start (va)
185
	# r4 = memmap (pa)
186
	# r5 = real_mode (pa)
187
 
188
	mtspr srr0, r5
189
 
190
	# jumps to real_mode
191
 
192
	mfmsr r5
193
	lis r6, ~0@h
194
	ori r6, r6, ~(msr_ir | msr_dr)@l
195
	and r5, r5, r6
196
	mtspr srr1, r5
197
	rfi
198
 
199
.section REALMODE
200
.align 12
201
.global real_mode
202
 
203
real_mode:
204
 
205
	# fill segment registers
206
 
207
	li r5, 16
208
	mtctr r5
209
	li r5, 0
210
	li r6, 0
211
 
212
	seg_fill:
213
 
214
		mtsrin r6, r5
215
		addis r5, r5, 0x1000    # move to next SR
216
		addis r6, r6, 0x10      # add 256 MB, move to next SR
217
 
218
		bdnz seg_fill
219
 
220
	# bootstrap kernel
221
	#
222
	# r3 = kernel_start (va)
223
	# r4 = memmap (pa)       -> r10
224
 
225
	mtspr srr0, r3
226
 
227
	mfmsr r5
228
	ori r5, r5, (msr_ir | msr_dr)@l
229
	mtspr srr1, r5
230
 
964 decky 231
	mr r10, r4
1022 decky 232
	rfi