Subversion Repositories HelenOS-historic

Rev

Rev 1131 | Rev 1157 | 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"
31
 
914 decky 32
.data
33
 
34
flush_buffer:
933 decky 35
	.space (L1_CACHE_LINES * L1_CACHE_BYTES)
914 decky 36
 
913 decky 37
.text
38
 
1058 decky 39
.global halt
1075 decky 40
.global memcpy
913 decky 41
.global jump_to_kernel
42
 
1058 decky 43
halt:
44
	b halt
913 decky 45
 
1075 decky 46
memcpy:
47
	srwi. r7, r5, 3
48
	addi r6, r3, -4
49
	addi r4, r4, -4
50
	beq	2f
51
 
52
	andi. r0, r6, 3
53
	mtctr r7
54
	bne 5f
55
 
56
	1:
57
 
58
	lwz r7, 4(r4)
59
	lwzu r8, 8(r4)
60
	stw r7, 4(r6)
61
	stwu r8, 8(r6)
62
	bdnz 1b
63
 
64
	andi. r5, r5, 7
65
 
66
	2:
67
 
68
	cmplwi 0, r5, 4
69
	blt 3f
70
 
71
	lwzu r0, 4(r4)
72
	addi r5, r5, -4
73
	stwu r0, 4(r6)
74
 
75
	3:
76
 
77
	cmpwi 0, r5, 0
78
	beqlr
79
	mtctr r5
80
	addi r4, r4, 3
81
	addi r6, r6, 3
82
 
83
	4:
84
 
85
	lbzu r0, 1(r4)
86
	stbu r0, 1(r6)
87
	bdnz 4b
88
	blr
89
 
90
	5:
91
 
92
	subfic r0, r0, 4
93
	mtctr r0
94
 
95
	6:
96
 
97
	lbz r7, 4(r4)
98
	addi r4, r4, 1
99
	stb r7, 4(r6)
100
	addi r6, r6, 1
101
	bdnz 6b
102
	subf r5, r0, r5
103
	rlwinm. r7, r5, 32-3, 3, 31
104
	beq 2b
105
	mtctr r7
106
	b 1b
107
 
108
 
913 decky 109
jump_to_kernel:
1022 decky 110
 
1131 decky 111
	# r3 = bootinfo (pa)
112
	# r4 = bootinfo_size
113
	# r5 = trans (pa)
114
	# r6 = kernel size
1146 decky 115
	# r7 = framebuffer (pa)
116
	# r8 = real_mode (pa)
1022 decky 117
 
1146 decky 118
	mtspr srr0, r8
1022 decky 119
 
120
	# jumps to real_mode
121
 
1058 decky 122
	mfmsr r31
123
	lis r30, ~0@h
124
	ori r30, r30, ~(msr_ir | msr_dr)@l
125
	and r31, r31, r30
126
	mtspr srr1, r31
1022 decky 127
	rfi
128
 
129
.section REALMODE
1058 decky 130
.align PAGE_WIDTH
1022 decky 131
.global real_mode
132
 
133
real_mode:
1058 decky 134
 
135
	# copy kernel to proper location
136
	#
1131 decky 137
	# r5 = trans (pa)
138
	# r6 = kernel size
1146 decky 139
	# r7 = framebuffer (pa)
1058 decky 140
 
1068 decky 141
	li r31, PAGE_SIZE >> 2
1058 decky 142
	li r30, 0
143
 
144
	page_copy:
145
 
1131 decky 146
		cmpwi r6, 0
1058 decky 147
		beq copy_end
148
 
1068 decky 149
		# copy page
1058 decky 150
 
151
		mtctr r31
1131 decky 152
		lwz r29, 0(r5)
1058 decky 153
 
154
		copy_loop:
155
 
156
			lwz r28, 0(r29)
157
			stw r28, 0(r30)
158
 
159
			addi r29, r29, 4
160
			addi r30, r30, 4
1131 decky 161
			subi r6, r6, 4
1058 decky 162
 
1131 decky 163
			cmpwi r6, 0
1068 decky 164
			beq copy_end
165
 
1058 decky 166
			bdnz copy_loop
167
 
1131 decky 168
		addi r5, r5, 4
1058 decky 169
		b page_copy
170
 
171
	copy_end:
1068 decky 172
 
173
	# invalidate segment registers
1022 decky 174
 
1071 decky 175
	li r31, 16
176
	mtctr r31
177
	li r31, 0
178
	li r30, 0
179
 
1022 decky 180
	seg_fill:
181
 
1071 decky 182
		mtsrin r30, r31
183
		addis r31, r31, 0x1000    # move to next SR
184
 
185
		bdnz seg_fill
1022 decky 186
 
1068 decky 187
	# invalidate block address translation registers
188
 
189
	mtspr ibat0u, r30
190
	mtspr ibat0l, r30
191
 
192
	mtspr ibat1u, r30
193
	mtspr ibat1l, r30
194
 
195
	mtspr ibat2u, r30
196
	mtspr ibat2l, r30
197
 
198
	mtspr ibat3u, r30
199
	mtspr ibat3l, r30
200
 
201
	mtspr dbat0u, r30
202
	mtspr dbat0l, r30
203
 
204
	mtspr dbat1u, r30
205
	mtspr dbat1l, r30
206
 
207
	mtspr dbat2u, r30
208
	mtspr dbat2l, r30
209
 
210
	mtspr dbat3u, r30
211
	mtspr dbat3l, r30
212
 
1058 decky 213
	# create identity mapping
214
 
1068 decky 215
	# FIXME: map exactly the size of RAM
216
 
217
	lis r31, 0x8000
218
	ori r31, r31, 0x0ffe
219
 
220
	lis r30, 0x0000
221
	ori r30, r30, 0x0002
222
 
223
	mtspr ibat0u, r31
224
	mtspr ibat0l, r30
225
 
226
	mtspr dbat0u, r31
227
	mtspr dbat0l, r30
228
 
229
	# FIXME: temporal framebuffer mapping
230
 
231
	lis r31, 0xf000
232
	ori r31, r31, 0x0ffe
233
 
1146 decky 234
	mr r30, r7
1068 decky 235
	ori r30, r30, 0x0002
236
 
237
	mtspr dbat1u, r31
238
	mtspr dbat1l, r30
239
 
1058 decky 240
	tlbia
241
 
242
	# start the kernel
1022 decky 243
	#
1131 decky 244
	# r3 = bootinfo (pa)
1022 decky 245
 
1058 decky 246
	lis r31, KERNEL_START_ADDR@ha
247
	addi r31, r31, KERNEL_START_ADDR@l
1022 decky 248
 
1058 decky 249
	mtspr srr0, r31
1022 decky 250
 
1058 decky 251
	mfmsr r31
252
	ori r31, r31, (msr_ir | msr_dr)@l
253
	mtspr srr1, r31
254
 
1146 decky 255
	sync
256
	isync
1022 decky 257
	rfi
1058 decky 258
 
259
.align PAGE_WIDTH
260
.global trans
261
trans:
262
	.space (TRANS_SIZE * TRANS_ITEM_SIZE)