Subversion Repositories HelenOS-historic

Rev

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