Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
913 decky 1
#
2071 jermar 2
# Copyright (c) 2006 Martin Decky
913 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
 
1058 decky 29
#include "asm.h"
913 decky 30
#include "regname.h"
31
 
32
.text
33
 
1058 decky 34
.global halt
1075 decky 35
.global memcpy
913 decky 36
.global jump_to_kernel
37
 
1058 decky 38
halt:
39
	b halt
913 decky 40
 
1075 decky 41
memcpy:
42
	srwi. r7, r5, 3
43
	addi r6, r3, -4
44
	addi r4, r4, -4
45
	beq	2f
46
 
47
	andi. r0, r6, 3
48
	mtctr r7
49
	bne 5f
50
 
51
	1:
52
 
53
	lwz r7, 4(r4)
54
	lwzu r8, 8(r4)
55
	stw r7, 4(r6)
56
	stwu r8, 8(r6)
57
	bdnz 1b
58
 
59
	andi. r5, r5, 7
60
 
61
	2:
62
 
63
	cmplwi 0, r5, 4
64
	blt 3f
65
 
66
	lwzu r0, 4(r4)
67
	addi r5, r5, -4
68
	stwu r0, 4(r6)
69
 
70
	3:
71
 
72
	cmpwi 0, r5, 0
73
	beqlr
74
	mtctr r5
75
	addi r4, r4, 3
76
	addi r6, r6, 3
77
 
78
	4:
79
 
80
	lbzu r0, 1(r4)
81
	stbu r0, 1(r6)
82
	bdnz 4b
83
	blr
84
 
85
	5:
86
 
87
	subfic r0, r0, 4
88
	mtctr r0
89
 
90
	6:
91
 
92
	lbz r7, 4(r4)
93
	addi r4, r4, 1
94
	stb r7, 4(r6)
95
	addi r6, r6, 1
96
	bdnz 6b
97
	subf r5, r0, r5
98
	rlwinm. r7, r5, 32-3, 3, 31
99
	beq 2b
100
	mtctr r7
101
	b 1b
102
 
103
 
913 decky 104
jump_to_kernel:
1022 decky 105
 
1131 decky 106
	# r3 = bootinfo (pa)
107
	# r4 = bootinfo_size
108
	# r5 = trans (pa)
1372 decky 109
	# r6 = bytes to copy
110
	# r7 = real_mode (pa)
1478 decky 111
	# r8 = framebuffer (pa)
112
	# r9 = scanline
1022 decky 113
 
1216 decky 114
	# disable interrupts
115
 
116
	mfmsr r31
117
	rlwinm r31, r31, 0, 17, 15
118
	mtmsr r31
119
 
120
	# set real_mode meeting point address
121
 
1372 decky 122
	mtspr srr0, r7
1022 decky 123
 
124
	# jumps to real_mode
125
 
1058 decky 126
	mfmsr r31
127
	lis r30, ~0@h
1478 decky 128
	ori r30, r30, ~(msr_ir | msr_dr | msr_ee)@l
1058 decky 129
	and r31, r31, r30
130
	mtspr srr1, r31
1157 decky 131
 
132
	sync
133
	isync
1022 decky 134
	rfi
135
 
1214 decky 136
.section REALMODE, "ax"
1058 decky 137
.align PAGE_WIDTH
1022 decky 138
.global real_mode
139
 
140
real_mode:
1479 decky 141
 
1058 decky 142
	# copy kernel to proper location
143
	#
1131 decky 144
	# r5 = trans (pa)
1372 decky 145
	# r6 = bytes to copy
1478 decky 146
	# r8 = framebuffer (pa)
147
	# r9 = scanline
1058 decky 148
 
1068 decky 149
	li r31, PAGE_SIZE >> 2
1058 decky 150
	li r30, 0
151
 
152
	page_copy:
153
 
1131 decky 154
		cmpwi r6, 0
1058 decky 155
		beq copy_end
156
 
1068 decky 157
		# copy page
1058 decky 158
 
159
		mtctr r31
1131 decky 160
		lwz r29, 0(r5)
1058 decky 161
 
162
		copy_loop:
163
 
164
			lwz r28, 0(r29)
165
			stw r28, 0(r30)
166
 
167
			addi r29, r29, 4
168
			addi r30, r30, 4
1131 decky 169
			subi r6, r6, 4
1058 decky 170
 
1131 decky 171
			cmpwi r6, 0
1068 decky 172
			beq copy_end
173
 
1058 decky 174
			bdnz copy_loop
1479 decky 175
 
1131 decky 176
		addi r5, r5, 4
1058 decky 177
		b page_copy
178
 
179
	copy_end:
1068 decky 180
 
1214 decky 181
	# initially fill segment registers
1728 decky 182
 
1071 decky 183
	li r31, 0
1728 decky 184
 
185
	li r29, 8
186
	mtctr r29
1737 decky 187
	li r30, 0                     # ASID 0 (VSIDs 0 .. 7)
1071 decky 188
 
1728 decky 189
	seg_fill_uspace:
1022 decky 190
 
1071 decky 191
		mtsrin r30, r31
1728 decky 192
		addi r30, r30, 1
1071 decky 193
		addis r31, r31, 0x1000    # move to next SR
194
 
1728 decky 195
		bdnz seg_fill_uspace
1022 decky 196
 
1728 decky 197
	li r29, 8
198
	mtctr r29
1737 decky 199
	lis r30, 0x4000               # priviledged access only
200
	ori r30, r30, 8               # ASID 0 (VSIDs 8 .. 15)
1728 decky 201
 
202
	seg_fill_kernel:
203
 
204
		mtsrin r30, r31
205
		addi r30, r30, 1
206
		addis r31, r31, 0x1000    # move to next SR
207
 
208
		bdnz seg_fill_kernel
209
 
1068 decky 210
	# invalidate block address translation registers
211
 
1373 decky 212
	li r30, 0
213
 
1068 decky 214
	mtspr ibat0u, r30
215
	mtspr ibat0l, r30
216
 
217
	mtspr ibat1u, r30
218
	mtspr ibat1l, r30
219
 
220
	mtspr ibat2u, r30
221
	mtspr ibat2l, r30
222
 
223
	mtspr ibat3u, r30
224
	mtspr ibat3l, r30
225
 
226
	mtspr dbat0u, r30
227
	mtspr dbat0l, r30
228
 
229
	mtspr dbat1u, r30
230
	mtspr dbat1l, r30
231
 
232
	mtspr dbat2u, r30
233
	mtspr dbat2l, r30
234
 
235
	mtspr dbat3u, r30
236
	mtspr dbat3l, r30
237
 
1738 decky 238
	# create empty Page Hash Table
239
	# on top of memory, size 64 KB
1725 decky 240
 
1738 decky 241
	lwz r31, 0(r3)                # r31 = memory size
1725 decky 242
 
1738 decky 243
	lis r30, 65536@h
244
	ori r30, r30, 65536@l         # r30 = 65536
245
 
246
	subi r29, r30, 1              # r29 = 65535
247
 
248
	sub r31, r31, r30
249
	andc r31, r31, r29            # pht = ALIGN_DOWN(memory_size - 65536, 65536)
250
 
251
	mtsdr1 r31
252
 
253
	li r29, 2
254
	srw r30, r30, r29             # r30 = 16384
1728 decky 255
	li r29, 0
256
 
257
	pht_clear:
258
 
1737 decky 259
		# write zeroes
260
 
1728 decky 261
		stw r29, 0(r31)
262
 
263
		addi r31, r31, 4
264
		subi r30, r30, 4
265
 
266
		cmpwi r30, 0
267
		beq clear_end
268
 
269
		bdnz pht_clear
270
 
271
	clear_end:
272
 
273
#ifdef CONFIG_BAT
274
 
1737 decky 275
	# create BAT identity mapping
276
 
1738 decky 277
	lwz r31, 0(r3)                # r31 = memory size
1068 decky 278
 
1737 decky 279
	lis r29, 0x0002
280
	cmpw r31, r29
281
	blt no_bat                    # less than 128 KB -> no BAT
1068 decky 282
 
1737 decky 283
	li r29, 18
284
	srw r31, r31, r29             # r31 = total >> 18
285
 
286
	# create Block Length mask by replicating
287
	# the leading logical one 14 times
288
 
289
	li r29, 14
290
	mtctr r31
291
	li r29, 1
292
 
293
	bat_mask:
294
		srw r30, r31, r29         # r30 = mask >> 1
295
		or r31, r31, r30          # mask = mask | r30
296
 
297
		bdnz bat_mask
298
 
299
	andi. r31, r31, 0x07ff        # mask = mask & 0x07ff (BAT can map up to 256 MB)
300
 
301
	li r29, 2
302
	slw r31, r31, r29             # mask = mask << 2
303
	ori r31, r31, 0x0002          # mask = mask | 0x0002 (priviledged access only)
304
 
305
	lis r29, 0x8000
306
	or r29, r29, r31
307
 
1068 decky 308
	lis r30, 0x0000
309
	ori r30, r30, 0x0002
310
 
1737 decky 311
	mtspr ibat0u, r29
1068 decky 312
	mtspr ibat0l, r30
313
 
1737 decky 314
	mtspr dbat0u, r29
1068 decky 315
	mtspr dbat0l, r30
1737 decky 316
 
317
	no_bat:
3824 decky 318
 
1728 decky 319
#endif
1068 decky 320
 
1381 decky 321
	tlbsync
1058 decky 322
 
323
	# start the kernel
1022 decky 324
	#
1728 decky 325
	# pc = KERNEL_START_ADDR
1131 decky 326
	# r3 = bootinfo (pa)
1728 decky 327
	# sprg0 = KA2PA(KERNEL_START_ADDR)
328
	# sprg3 = physical memory size
329
	# sp = 0 (pa)
1022 decky 330
 
1058 decky 331
	lis r31, KERNEL_START_ADDR@ha
332
	addi r31, r31, KERNEL_START_ADDR@l
1022 decky 333
 
1058 decky 334
	mtspr srr0, r31
1022 decky 335
 
1728 decky 336
	subis r31, r31, 0x8000
337
	mtsprg0 r31
338
 
339
	lwz r31, 0(r3)
340
	mtsprg3 r31
341
 
342
	li sp, 0
343
 
1058 decky 344
	mfmsr r31
345
	ori r31, r31, (msr_ir | msr_dr)@l
346
	mtspr srr1, r31
347
 
1146 decky 348
	sync
349
	isync
1022 decky 350
	rfi
1058 decky 351
 
352
.align PAGE_WIDTH
353
.global trans
354
trans:
355
	.space (TRANS_SIZE * TRANS_ITEM_SIZE)