Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
35 jermar 1
#
2071 jermar 2
# Copyright (c) 2005 Jakub Jermar
35 jermar 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
 
473 jermar 29
#include <arch/register.h>
869 vana 30
#include <arch/mm/page.h>
31
#include <arch/mm/asid.h>
32
#include <mm/asid.h>
473 jermar 33
 
869 vana 34
#define RR_MASK (0xFFFFFFFF00000002)
3766 jermar 35
#define RID_SHIFT	8
36
#define PS_SHIFT	2
869 vana 37
 
3766 jermar 38
#define KERNEL_TRANSLATION_I	0x0010000000000661
39
#define KERNEL_TRANSLATION_D	0x0010000000000661
40
#define KERNEL_TRANSLATION_VIO	0x0010000000000671
41
#define KERNEL_TRANSLATION_IO	0x00100FFFFC000671 
42
#define KERNEL_TRANSLATION_FW	0x00100000F0000671 
869 vana 43
 
923 vana 44
.section K_TEXT_START, "ax"
60 jermar 45
 
35 jermar 46
.global kernel_image_start
47
 
37 jermar 48
stack0:
35 jermar 49
kernel_image_start:
81 jermar 50
	.auto
412 jermar 51
 
3766 jermar 52
	# Identify self(CPU) in OS structures by ID / EID
3578 vana 53
 
3766 jermar 54
	mov r9 = cr64
55
	mov r10 = 1
56
	movl r12 = 0xffffffff
57
	movl r8 = cpu_by_id_eid_list
58
	and r8 = r8, r12
59
	shr r9 = r9, 16
60
	add r8 = r8, r9
61
	st1 [r8] = r10
3578 vana 62
 
2726 vana 63
	mov psr.l = r0
64
	srlz.i
65
	srlz.d
66
 
893 jermar 67
	# Fill TR.i and TR.d using Region Register #VRN_KERNEL
869 vana 68
 
2110 jermar 69
	movl r8 = (VRN_KERNEL << VRN_SHIFT)
70
	mov r9 = rr[r8]
2726 vana 71
 
2110 jermar 72
	movl r10 = (RR_MASK)
73
	and r9 = r10, r9
74
	movl r10 = ((RID_KERNEL << RID_SHIFT) | (KERNEL_PAGE_WIDTH << PS_SHIFT))
75
	or  r9 = r10, r9
2726 vana 76
 
2110 jermar 77
	mov rr[r8] = r9
869 vana 78
 
2110 jermar 79
	movl r8 = (VRN_KERNEL << VRN_SHIFT)
80
	mov cr.ifa = r8
2726 vana 81
 
82
	mov r11 = cr.itir ;;
83
	movl r10 = (KERNEL_PAGE_WIDTH << PS_SHIFT);;
3766 jermar 84
	or r10 = r10, r11 ;;
2726 vana 85
	mov cr.itir = r10;;
86
 
2110 jermar 87
	movl r10 = (KERNEL_TRANSLATION_I)
88
	itr.i itr[r0] = r10
89
	movl r10 = (KERNEL_TRANSLATION_D)
90
	itr.d dtr[r0] = r10
869 vana 91
 
2726 vana 92
	movl r7 = 1
93
	movl r8 = (VRN_KERNEL << VRN_SHIFT) | VIO_OFFSET
94
	mov cr.ifa = r8
95
	movl r10 = (KERNEL_TRANSLATION_VIO)
96
	itr.d dtr[r7] = r10
97
 
98
	mov r11 = cr.itir ;;
99
	movl r10 = ~0xfc;;
3766 jermar 100
	and r10 = r10, r11 ;;
2726 vana 101
	movl r11 = (IO_PAGE_WIDTH << PS_SHIFT);;
3766 jermar 102
	or r10 = r10, r11 ;;
2726 vana 103
	mov cr.itir = r10;;
104
 
105
	movl r7 = 2
106
	movl r8 = (VRN_KERNEL << VRN_SHIFT) | IO_OFFSET
107
	mov cr.ifa = r8
108
	movl r10 = (KERNEL_TRANSLATION_IO)
109
	itr.d dtr[r7] = r10
110
 
3766 jermar 111
	# Setup mapping for fimware arrea (also SAPIC)
2726 vana 112
 
3578 vana 113
	mov r11 = cr.itir ;;
114
	movl r10 = ~0xfc;;
3766 jermar 115
	and r10 = r10, r11 ;;
3578 vana 116
	movl r11 = (FW_PAGE_WIDTH << PS_SHIFT);;
3766 jermar 117
	or r10 = r10, r11 ;;
3578 vana 118
	mov cr.itir = r10;;
2726 vana 119
 
3578 vana 120
	movl r7 = 3
121
	movl r8 = (VRN_KERNEL << VRN_SHIFT) | FW_OFFSET
122
	mov cr.ifa = r8
123
	movl r10 = (KERNEL_TRANSLATION_FW)
124
	itr.d dtr[r7] = r10
125
 
3766 jermar 126
	# Initialize PSR
3578 vana 127
 
2110 jermar 128
	movl r10 = (PSR_DT_MASK | PSR_RT_MASK | PSR_IT_MASK | PSR_IC_MASK)  /* Enable paging */
129
	mov r9 = psr
3766 jermar 130
 
2110 jermar 131
	or r10 = r10, r9
132
	mov cr.ipsr = r10
133
	mov cr.ifs = r0
134
	movl r8 = paging_start
135
	mov cr.iip = r8
473 jermar 136
	srlz.d
869 vana 137
	srlz.i
879 vana 138
 
893 jermar 139
	.explicit
3766 jermar 140
 
893 jermar 141
	/*
142
	 * Return From Interupt is the only the way to fill upper half word of PSR.
143
	 */
144
	rfi;;
879 vana 145
 
3766 jermar 146
 
879 vana 147
.global paging_start
148
paging_start:
893 jermar 149
 
150
	/*
151
	 * Now we are paging.
152
	 */
153
 
3766 jermar 154
	# Switch to register bank 1
473 jermar 155
	bsw.1
3578 vana 156
 
3766 jermar 157
	# Am I BSP or AP?
158
	movl r20 = bsp_started;;
159
	ld8 r20 = [r20];;
160
	cmp.eq p3, p2 = r20, r0;;
473 jermar 161
 
3766 jermar 162
	# Initialize register stack
81 jermar 163
	mov ar.rsc = r0
2110 jermar 164
	movl r8 = (VRN_KERNEL << VRN_SHIFT) ;;
869 vana 165
	mov ar.bspstore = r8
81 jermar 166
	loadrs
36 jermar 167
 
3766 jermar 168
	# Initialize memory stack to some sane value
2110 jermar 169
	movl r12 = stack0 ;;
170
	add r12 = -16, r12	/* allocate a scratch area on the stack */
60 jermar 171
 
3766 jermar 172
	# Initialize gp (Global Pointer) register
2519 vana 173
	movl r20 = (VRN_KERNEL << VRN_SHIFT);;
174
	or r20 = r20,r1;;
919 jermar 175
	movl r1 = _hardcoded_load_address
2519 vana 176
 
893 jermar 177
	/*
3578 vana 178
	 * Initialize hardcoded_* variables. Do only BSP
893 jermar 179
	 */
3578 vana 180
(p3)	movl r14 = _hardcoded_ktext_size
181
(p3)	movl r15 = _hardcoded_kdata_size
182
(p3)	movl r16 = _hardcoded_load_address ;;
183
(p3)	addl r17 = @gprel(hardcoded_ktext_size), gp
184
(p3)	addl r18 = @gprel(hardcoded_kdata_size), gp
185
(p3)	addl r19 = @gprel(hardcoded_load_address), gp
186
(p3)	addl r21 = @gprel(bootinfo), gp
106 jermar 187
	;;
3578 vana 188
(p3)	st8 [r17] = r14
189
(p3)	st8 [r18] = r15
190
(p3)	st8 [r19] = r16
191
(p3)	st8 [r21] = r20
869 vana 192
 
2110 jermar 193
	ssm (1 << 19) ;; /* Disable f32 - f127 */
194
	srlz.i
195
	srlz.d ;;
1053 vana 196
 
3578 vana 197
(p2)	movl r18 = main_ap ;;
198
(p2)   	mov b1 = r18 ;;
199
(p2)	br.call.sptk.many b0 = b1
200
 
3766 jermar 201
	# Mark that BSP is on
3578 vana 202
	mov r20=1;;
203
	movl r21=bsp_started;;
204
	st8 [r21]=r20;;
205
 
1223 jermar 206
	br.call.sptk.many b0 = arch_pre_main
1053 vana 207
 
2110 jermar 208
	movl r18 = main_bsp ;;
209
	mov b1 = r18 ;;
210
	br.call.sptk.many b0 = b1
51 jermar 211
 
36 jermar 212
0:
39 jermar 213
	br 0b
3578 vana 214
.align 4096
215
 
216
kernel_image_ap_start:
217
	.auto
3766 jermar 218
 
219
	# Identify self(CPU) in OS structures by ID / EID
220
 
221
	mov r9 = cr64
222
	mov r10 = 1
223
	movl r12 = 0xffffffff
224
	movl r8 = cpu_by_id_eid_list
225
	and r8 = r8, r12
226
	shr r9 = r9, 16
227
	add r8 = r8, r9
228
	st1 [r8] = r10
3578 vana 229
 
3766 jermar 230
	# Wait for wakeup synchro signal (#3 in cpu_by_id_eid_list)
3578 vana 231
kernel_image_ap_start_loop:
3766 jermar 232
	movl r11 = kernel_image_ap_start_loop
233
	and r11 = r11, r12
3578 vana 234
   	mov b1 = r11 
235
 
3766 jermar 236
	ld1 r20 = [r8];;
237
	movl r21 = 3;;
238
	cmp.eq p2, p3 = r20, r21;;
239
(p3)	br.call.sptk.many b0 = b1
3578 vana 240
 
3766 jermar 241
	movl r11 = kernel_image_start
242
	and r11 = r11, r12
243
	mov b1 = r11 
3578 vana 244
	br.call.sptk.many b0 = b1
245
 
246
 
247
.align 16
248
.global bsp_started
249
bsp_started:
250
.space 8
251
 
252
.align 4096
253
.global cpu_by_id_eid_list
254
cpu_by_id_eid_list:
255
.space 65536
256