1 |
786 |
skrzyp |
##=============================================================================
|
2 |
|
|
##
|
3 |
|
|
## platform.S
|
4 |
|
|
##
|
5 |
|
|
## MIPS VRC4372 platform code
|
6 |
|
|
##
|
7 |
|
|
##=============================================================================
|
8 |
|
|
## ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
## -------------------------------------------
|
10 |
|
|
## This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
##
|
13 |
|
|
## eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
## the terms of the GNU General Public License as published by the Free
|
15 |
|
|
## Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
## version.
|
17 |
|
|
##
|
18 |
|
|
## eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
## for more details.
|
22 |
|
|
##
|
23 |
|
|
## You should have received a copy of the GNU General Public License
|
24 |
|
|
## along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
##
|
27 |
|
|
## As a special exception, if other files instantiate templates or use
|
28 |
|
|
## macros or inline functions from this file, or you compile this file
|
29 |
|
|
## and link it with other works to produce a work based on this file,
|
30 |
|
|
## this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
## the GNU General Public License. However the source code for this file
|
32 |
|
|
## must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
## General Public License v2.
|
34 |
|
|
##
|
35 |
|
|
## This exception does not invalidate any other reasons why a work based
|
36 |
|
|
## on this file might be covered by the GNU General Public License.
|
37 |
|
|
## -------------------------------------------
|
38 |
|
|
## ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
##=============================================================================
|
40 |
|
|
#######DESCRIPTIONBEGIN####
|
41 |
|
|
##
|
42 |
|
|
## Author(s): nickg
|
43 |
|
|
## Contributors: nickg
|
44 |
|
|
## Date: 1999-04-20
|
45 |
|
|
## Purpose: MIPS vrc4372 platform code
|
46 |
|
|
## Description: Platform specific code for VRC4372 board.
|
47 |
|
|
##
|
48 |
|
|
##
|
49 |
|
|
##
|
50 |
|
|
##
|
51 |
|
|
######DESCRIPTIONEND####
|
52 |
|
|
##
|
53 |
|
|
##=============================================================================
|
54 |
|
|
|
55 |
|
|
#include
|
56 |
|
|
#include
|
57 |
|
|
|
58 |
|
|
#ifdef CYGPKG_KERNEL
|
59 |
|
|
# include
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
#include
|
63 |
|
|
|
64 |
|
|
##-----------------------------------------------------------------------------
|
65 |
|
|
## ISR springboard.
|
66 |
|
|
## This routine decodes the interrupt from the VRC4372 interrupt controller
|
67 |
|
|
## and vectors to it.
|
68 |
|
|
|
69 |
|
|
# On entry:
|
70 |
|
|
# a0 = MIPS status register interrupt number (1,2 or 3)
|
71 |
|
|
# a1 = ISR data value (= interrupt status reg address)
|
72 |
|
|
# a2 = saved reg dump ptr
|
73 |
|
|
# s0 = saved reg dump ptr
|
74 |
|
|
# s1 = vector table offset
|
75 |
|
|
# s2 = interrupt number
|
76 |
|
|
# a3,v0,v1 etc available for use
|
77 |
|
|
|
78 |
|
|
.text
|
79 |
|
|
|
80 |
|
|
hal_isr_springboard:
|
81 |
|
|
|
82 |
|
|
lw v0,0(a1) # v0 = stat reg value
|
83 |
|
|
|
84 |
|
|
# The following code implements an ls bit index algorithm similar
|
85 |
|
|
# to that in hal_lsbit_index() in hal_misc.c.
|
86 |
|
|
negu v1,v0 # v1 = -v0
|
87 |
|
|
and v1,v1,v0 # v1 &= v0 [isolate ls bit]
|
88 |
|
|
sll v0,v1,16 # v0 = v1<<16
|
89 |
|
|
subu v1,v0,v1 # v1 = v0 - v1
|
90 |
|
|
sll a0,v1,6 # a0 = v1<<6
|
91 |
|
|
addu v1,v1,a0 # v1 += a0
|
92 |
|
|
sll a1,v1,4 # a1 = v1<<4
|
93 |
|
|
addu v1,v1,a1 # v1 += a1
|
94 |
|
|
la v0,hal_isr_springboard_table # v0 = table address
|
95 |
|
|
srl v1,v1,26 # v1 = v1>>26
|
96 |
|
|
addu v1,v1,v0 # v1 = table entry address
|
97 |
|
|
lb a0,0(v1) # a0 = intc isr number
|
98 |
|
|
|
99 |
|
|
addi s2,a0,6 # s2 = eCos isr number
|
100 |
|
|
sll s1,s2,2 # s1 = isr table index
|
101 |
|
|
|
102 |
|
|
la v1,hal_interrupt_handlers
|
103 |
|
|
addu v1,v1,s1 # v1 = isr handler address
|
104 |
|
|
lw v1,0(v1) # v1 = isr handler
|
105 |
|
|
|
106 |
|
|
la a1,hal_interrupt_data
|
107 |
|
|
addu a1,a1,s1 # a1 = address of data ptr
|
108 |
|
|
lw a1,0(a1) # a1 = data pointer
|
109 |
|
|
|
110 |
|
|
move a0,s2 # pass interrupt number
|
111 |
|
|
|
112 |
|
|
jr v1 # jump to handler, return is to
|
113 |
|
|
# default vsr already in ra
|
114 |
|
|
nop
|
115 |
|
|
|
116 |
|
|
hal_isr_springboard_table:
|
117 |
|
|
.byte -1, 0, 1, 12, 2, 6, 0, 13
|
118 |
|
|
.byte 3, 0, 7, 0, 0, 0, 0, 14
|
119 |
|
|
.byte 10, 4, 0, 0, 8, 0, 0, 25
|
120 |
|
|
.byte 0, 0, 0, 0, 0, 21, 27, 15
|
121 |
|
|
.byte 31, 11, 5, 0, 0, 0, 0, 0
|
122 |
|
|
.byte 9, 0, 0, 24, 0, 0, 20, 26
|
123 |
|
|
.byte 30, 0, 0, 0, 0, 23, 0, 19
|
124 |
|
|
.byte 29, 0, 22, 18, 28, 17, 16, 0
|
125 |
|
|
|
126 |
|
|
##-----------------------------------------------------------------------------
|
127 |
|
|
## Data Load/Store Bus error VSR
|
128 |
|
|
##
|
129 |
|
|
## If the VRC4373 tries to access a PCI config space register that does
|
130 |
|
|
## not have a real device behind it, it provokes a bus error.
|
131 |
|
|
## This is a special bus error VSR that detects when we get a bus error
|
132 |
|
|
## from a PCI configuration space access and fixes it up to allow the
|
133 |
|
|
## program to continue.
|
134 |
|
|
## This VSR works in conjunction with hal_pci_config_read().
|
135 |
|
|
## Essentially, if we get a bus error it checks the EPC value and if it
|
136 |
|
|
## is at the instruction that accesses the PCI bus, in hal_pci_config_read(),
|
137 |
|
|
## it skips it and fixes the registers to allow the program to continue.
|
138 |
|
|
## None of this would be necessary if the VRC4373 behaved sensibly and
|
139 |
|
|
## returned 0xFFFFFFFF for reads from empty device slots like it should.
|
140 |
|
|
|
141 |
|
|
.text
|
142 |
|
|
|
143 |
|
|
.globl hal_bus_error_vsr
|
144 |
|
|
hal_bus_error_vsr:
|
145 |
|
|
# We come here with everything still in registers and:
|
146 |
|
|
# K0 = vector number (==7*4)
|
147 |
|
|
# K1 = address of this routine
|
148 |
|
|
|
149 |
|
|
# Check for special address
|
150 |
|
|
|
151 |
|
|
la k1,hal_pci_config_read_load
|
152 |
|
|
mvafc0 k0,epc
|
153 |
|
|
bne k0,k1,1f
|
154 |
|
|
nop
|
155 |
|
|
|
156 |
|
|
# We have a match, skip the offending instruction
|
157 |
|
|
# and put 0xFFFFFFFF into V0.
|
158 |
|
|
# First we must clear the EXL bit so that we can
|
159 |
|
|
# write to EPC.
|
160 |
|
|
mfc0 k1,status # Get status reg
|
161 |
|
|
la v0,0xFFFFFFFD # mask for EXL
|
162 |
|
|
and k1,v0,k1 # clear EXL
|
163 |
|
|
mtc0 k1,status # return to CP0
|
164 |
|
|
nop # let it work
|
165 |
|
|
nop
|
166 |
|
|
nop
|
167 |
|
|
addi k0,k0,4 # skip offending instruction
|
168 |
|
|
mvatc0 k0,epc # return to EPC
|
169 |
|
|
nop # let it work
|
170 |
|
|
nop
|
171 |
|
|
nop
|
172 |
|
|
la v0,0xFFFFFFFF # Put 0xFFFFFFFF into v0
|
173 |
|
|
sync # let everything settle
|
174 |
|
|
eret # and return
|
175 |
|
|
nop
|
176 |
|
|
|
177 |
|
|
# If this is not the special location, we need to continue
|
178 |
|
|
# with the usual bus error handling. Since we no longer have
|
179 |
|
|
# the original VSR table entry, we use the one just before it
|
180 |
|
|
# (for instruction fetch bus error). At present this points
|
181 |
|
|
# to the same error handler.
|
182 |
|
|
1:
|
183 |
|
|
la k1,hal_vsr_table # Get VSR table
|
184 |
|
|
lw k1,24(k1) # Pick another vector to follow
|
185 |
|
|
la k0,28 # but pretend we are still Bus Error
|
186 |
|
|
jr k1 # go there
|
187 |
|
|
nop
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
##-----------------------------------------------------------------------------
|
191 |
|
|
## PCI config space access function
|
192 |
|
|
##
|
193 |
|
|
## This is the only function that should be used to read data from the PCI
|
194 |
|
|
## configuration space data register. It works with the bus error VSR
|
195 |
|
|
## above to work around any bus errors provoked by the VRC4373.
|
196 |
|
|
|
197 |
|
|
FUNC_START(hal_pci_config_read)
|
198 |
|
|
|
199 |
|
|
hal_pci_config_read_load:
|
200 |
|
|
.set noreorder
|
201 |
|
|
lw v0,0(a0) # Read the value. If this bus-errors the
|
202 |
|
|
# handler will skip this instruction and
|
203 |
|
|
# put 0xFFFFFFFF into v0.
|
204 |
|
|
jr ra # And return
|
205 |
|
|
nop
|
206 |
|
|
|
207 |
|
|
FUNC_END(hal_pci_config_read)
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
##-----------------------------------------------------------------------------
|
211 |
|
|
## Breakpoint springboard
|
212 |
|
|
|
213 |
|
|
## The following value has been determined by looking at the code that
|
214 |
|
|
## PMON puts in the interrupt vector. Clearly it will be different for
|
215 |
|
|
## different versions of PMON. A better approach might be to copy the original
|
216 |
|
|
## code out and execute that here. However, there is no guarantee that it is
|
217 |
|
|
## position independent.
|
218 |
|
|
|
219 |
|
|
#define CYGHWR_MIPS_PMON_EXEPTION_ENTRY 0xa0000dd4
|
220 |
|
|
|
221 |
|
|
.text
|
222 |
|
|
|
223 |
|
|
.globl hal_breakpoint_springboard
|
224 |
|
|
hal_breakpoint_springboard:
|
225 |
|
|
|
226 |
|
|
# We enter here with all of the CPU state still
|
227 |
|
|
# in its registers except:
|
228 |
|
|
# K0 = vector index
|
229 |
|
|
# K1 = address of this function
|
230 |
|
|
|
231 |
|
|
la k0,CYGHWR_MIPS_PMON_EXEPTION_ENTRY
|
232 |
|
|
jr k0
|
233 |
|
|
nop
|
234 |
|
|
|
235 |
|
|
##-----------------------------------------------------------------------------
|
236 |
|
|
## ISR tables.
|
237 |
|
|
|
238 |
|
|
.extern hal_default_isr
|
239 |
|
|
|
240 |
|
|
.data
|
241 |
|
|
|
242 |
|
|
.globl hal_interrupt_handlers
|
243 |
|
|
hal_interrupt_handlers:
|
244 |
|
|
.long hal_default_isr
|
245 |
|
|
.long hal_isr_springboard
|
246 |
|
|
.long hal_isr_springboard
|
247 |
|
|
.long hal_isr_springboard
|
248 |
|
|
.long hal_default_isr
|
249 |
|
|
.long hal_default_isr
|
250 |
|
|
|
251 |
|
|
.rept 32
|
252 |
|
|
.long hal_default_isr
|
253 |
|
|
.endr
|
254 |
|
|
|
255 |
|
|
.globl hal_interrupt_data
|
256 |
|
|
hal_interrupt_data:
|
257 |
|
|
|
258 |
|
|
.long 0
|
259 |
|
|
.long CYGHWR_HAL_MIPS_VRC4373_INTC_STAT0
|
260 |
|
|
.long CYGHWR_HAL_MIPS_VRC4373_INTC_STAT1
|
261 |
|
|
.long CYGHWR_HAL_MIPS_VRC4373_INTC_STAT2
|
262 |
|
|
.long 0
|
263 |
|
|
.long 0
|
264 |
|
|
|
265 |
|
|
.rept 32
|
266 |
|
|
.long 0
|
267 |
|
|
.endr
|
268 |
|
|
|
269 |
|
|
.globl hal_interrupt_objects
|
270 |
|
|
hal_interrupt_objects:
|
271 |
|
|
.rept 38
|
272 |
|
|
.long 0
|
273 |
|
|
.endr
|
274 |
|
|
|
275 |
|
|
.globl cyg_hal_interrupt_level
|
276 |
|
|
cyg_hal_interrupt_level:
|
277 |
|
|
.rept 38
|
278 |
|
|
.byte 0
|
279 |
|
|
.endr
|
280 |
|
|
|
281 |
|
|
##-----------------------------------------------------------------------------
|
282 |
|
|
## MMU setup.
|
283 |
|
|
## Much of this code is taken from the PMON sources, hence it does not fully
|
284 |
|
|
## conform to our normal coding conventions.
|
285 |
|
|
|
286 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
|
287 |
|
|
|
288 |
|
|
## DEFINITIONS FOR THE TLB SUPPORT
|
289 |
|
|
|
290 |
|
|
#define IO_PHYSICAL_BASE 0x80000000
|
291 |
|
|
#define IO_VIRTUAL_BASE 0xc0000000
|
292 |
|
|
#define NTLBENTRIES 32
|
293 |
|
|
#define K0BASE 0x80000000
|
294 |
|
|
#define TLBLO_G 0x00000001
|
295 |
|
|
#define TLBLO_V 0x00000002
|
296 |
|
|
#define TLBLO_D 0x00000004
|
297 |
|
|
#define TLBPGMASK_MASK 0x01ffe000
|
298 |
|
|
#define TLBINX_INXMASK 0x0000003f
|
299 |
|
|
#define CFG_C_UNCACHED 2
|
300 |
|
|
#define TLBLO_CSHIFT 3
|
301 |
|
|
#define TLBLO_PFNSHIFT 6
|
302 |
|
|
#define TLBLO_PFNMASK 0x3fffffc0
|
303 |
|
|
#define TLBHI_VPN2MASK 0xffffe000
|
304 |
|
|
#define TLBHI_VPN2SHIFT 13
|
305 |
|
|
#define TLBHI_VPNMASK 0xfffff000
|
306 |
|
|
#define TLBHI_VPNSHIFT 12
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
#define TLBLO_UNCACHED (CFG_C_UNCACHED<
|
310 |
|
|
#define PAGE_SIZE 0x01000000
|
311 |
|
|
#define PADDR_INC 0x02000000
|
312 |
|
|
#define NUMB_PG 8
|
313 |
|
|
|
314 |
|
|
.text
|
315 |
|
|
|
316 |
|
|
.set noreorder
|
317 |
|
|
|
318 |
|
|
.extern hal_mmu_setup_return
|
319 |
|
|
|
320 |
|
|
FUNC_START(hal_mmu_setup)
|
321 |
|
|
|
322 |
|
|
mtc0 zero,tlbhi
|
323 |
|
|
nop
|
324 |
|
|
li a0,0
|
325 |
|
|
2:
|
326 |
|
|
bal resettlb
|
327 |
|
|
nop
|
328 |
|
|
addiu a0,a0,1
|
329 |
|
|
bne a0,NTLBENTRIES,2b
|
330 |
|
|
nop
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
#define tlblo_even s0
|
334 |
|
|
#define tlblo_odd s1
|
335 |
|
|
#define vaddr s2
|
336 |
|
|
#define paddr0 s3
|
337 |
|
|
#define paddr1 s4
|
338 |
|
|
#define pmask s5
|
339 |
|
|
#define tmp s6
|
340 |
|
|
#define ix k1
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
li ix,0
|
344 |
|
|
li vaddr,IO_VIRTUAL_BASE
|
345 |
|
|
li paddr0,IO_PHYSICAL_BASE
|
346 |
|
|
loop:
|
347 |
|
|
|
348 |
|
|
li a0,((PAGE_SIZE - 1) << 1)
|
349 |
|
|
li a1,TLBPGMASK_MASK
|
350 |
|
|
and pmask, a0,a1
|
351 |
|
|
|
352 |
|
|
li tlblo_even, TLBLO_V | TLBLO_D | TLBLO_G
|
353 |
|
|
li tlblo_odd, TLBLO_V | TLBLO_D | TLBLO_G
|
354 |
|
|
|
355 |
|
|
li tmp,PAGE_SIZE
|
356 |
|
|
addu paddr1,paddr0,tmp
|
357 |
|
|
li tmp,TLBHI_VPN2MASK
|
358 |
|
|
and a1,vaddr,tmp
|
359 |
|
|
|
360 |
|
|
li tmp,TLBLO_PFNSHIFT
|
361 |
|
|
srl a2,paddr0,tmp
|
362 |
|
|
li tmp,TLBLO_PFNMASK
|
363 |
|
|
and a2,a2,tmp
|
364 |
|
|
or a2,a2,TLBLO_UNCACHED
|
365 |
|
|
or a2,a2,tlblo_even
|
366 |
|
|
|
367 |
|
|
li tmp,TLBLO_PFNSHIFT
|
368 |
|
|
srl a3,paddr1,tmp
|
369 |
|
|
li tmp,TLBLO_PFNMASK
|
370 |
|
|
and a3,a3,tmp
|
371 |
|
|
or a3,a3,TLBLO_UNCACHED
|
372 |
|
|
or a3,a3,tlblo_odd
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
move a0,pmask
|
376 |
|
|
or a0,a0,ix
|
377 |
|
|
|
378 |
|
|
bal map_tlb4000
|
379 |
|
|
nop
|
380 |
|
|
|
381 |
|
|
addi ix,ix,1
|
382 |
|
|
|
383 |
|
|
li tmp,PADDR_INC
|
384 |
|
|
addu vaddr,vaddr,tmp
|
385 |
|
|
addu paddr0,paddr0,tmp
|
386 |
|
|
|
387 |
|
|
li tmp,NUMB_PG
|
388 |
|
|
bne ix,tmp,loop
|
389 |
|
|
nop
|
390 |
|
|
|
391 |
|
|
# Go back via a jump, not a return
|
392 |
|
|
lar k0,hal_mmu_setup_return
|
393 |
|
|
jr k0
|
394 |
|
|
nop
|
395 |
|
|
|
396 |
|
|
FUNC_END(hal_mmu_setup)
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
## Invalidate the TLB entry specified by index
|
400 |
|
|
##
|
401 |
|
|
## resettlb(index)
|
402 |
|
|
## a0 = index
|
403 |
|
|
##
|
404 |
|
|
## Uses : t0, t2, v0, a0
|
405 |
|
|
|
406 |
|
|
FUNC_START(resettlb)
|
407 |
|
|
|
408 |
|
|
li t2,K0BASE & TLBHI_VPN2MASK
|
409 |
|
|
mfc0 t0,tlbhi # save current TLBHI
|
410 |
|
|
mfc0 v0,status # save SR and disable interrupts
|
411 |
|
|
mtc0 zero,status # clear interrupts
|
412 |
|
|
mtc0 t2,tlbhi # invalidate entry
|
413 |
|
|
mtc0 zero,tlblo0
|
414 |
|
|
mtc0 zero,tlblo1
|
415 |
|
|
mtc0 a0,index
|
416 |
|
|
nop; nop; nop; nop; nop; nop; nop; nop
|
417 |
|
|
tlbwi
|
418 |
|
|
nop; nop; nop; nop; nop; nop; nop; nop
|
419 |
|
|
mtc0 t0,tlbhi
|
420 |
|
|
mtc0 v0,status
|
421 |
|
|
j ra
|
422 |
|
|
nop
|
423 |
|
|
|
424 |
|
|
FUNC_END(resettlb)
|
425 |
|
|
|
426 |
|
|
## Setup R4000 TLB entry
|
427 |
|
|
##
|
428 |
|
|
## map_tlb4000(mask_index, tlbhi, pte_even, pte_odd)
|
429 |
|
|
## a0 = TLB entry index and page mask
|
430 |
|
|
## a1 = virtual page number and PID
|
431 |
|
|
## a2 = pte -- contents of even pte
|
432 |
|
|
## a3 = pte -- contents of odd pte
|
433 |
|
|
##
|
434 |
|
|
##
|
435 |
|
|
##
|
436 |
|
|
## Uses : t0, t1, t2, v0, a0, a1, a2, a3
|
437 |
|
|
|
438 |
|
|
FUNC_START(map_tlb4000)
|
439 |
|
|
and t2,a0,TLBPGMASK_MASK
|
440 |
|
|
and a0,TLBINX_INXMASK
|
441 |
|
|
mfc0 t1,tlbhi # save current TLBPID
|
442 |
|
|
mfc0 v0,status # save SR and disable interrupts
|
443 |
|
|
mtc0 zero,status # clear interrupts
|
444 |
|
|
mtc0 t2,pagemask # set
|
445 |
|
|
mtc0 a1,tlbhi # set VPN and TLBPID
|
446 |
|
|
mtc0 a2,tlblo0 # set PPN and access bits
|
447 |
|
|
mtc0 a3,tlblo1 # set PPN and access bits
|
448 |
|
|
mtc0 a0,index # set INDEX to wired entry
|
449 |
|
|
nop; nop; nop; nop; nop; nop; nop; nop
|
450 |
|
|
tlbwi # drop it in
|
451 |
|
|
nop; nop; nop; nop; nop; nop; nop; nop
|
452 |
|
|
mtc0 t1,tlbhi # restore TLBPID
|
453 |
|
|
mtc0 v0,status # restore SR
|
454 |
|
|
j ra
|
455 |
|
|
nop
|
456 |
|
|
FUNC_END(map_tlb4000)
|
457 |
|
|
|
458 |
|
|
#endif
|
459 |
|
|
|
460 |
|
|
##-----------------------------------------------------------------------------
|
461 |
|
|
## MEMC initialization.
|
462 |
|
|
## This also initializes the PCI bus and ISA bus bridge, so at the end of this
|
463 |
|
|
## we should have full access to all the memory and devices we need.
|
464 |
|
|
## This code is table driven, which is somewhat more compact that coding it all.
|
465 |
|
|
## Table entries consist of an address and a value to store in that address.
|
466 |
|
|
## A zero address terminates the table. Two special address values modify the
|
467 |
|
|
## behaviour:
|
468 |
|
|
## DELAY_LOOP loops for the number of iterations in the value field.
|
469 |
|
|
## WRITE16 treats the next 2 words as an address and value to be written
|
470 |
|
|
## with a 16 bit write cycle.
|
471 |
|
|
|
472 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
|
473 |
|
|
|
474 |
|
|
#define DELAY_LOOP 1
|
475 |
|
|
#define WRITE16 2
|
476 |
|
|
#define WRITEREAD32 3
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
FUNC_START(hal_memc_setup)
|
480 |
|
|
|
481 |
|
|
lar t0,hal_memc_setup_table
|
482 |
|
|
la t1,0xbfc00000
|
483 |
|
|
la t2,DELAY_LOOP
|
484 |
|
|
la t3,WRITE16
|
485 |
|
|
la t4,WRITEREAD32
|
486 |
|
|
1:
|
487 |
|
|
lw a0,0(t0) # next table entry
|
488 |
|
|
lw a1,4(t0) # value to write
|
489 |
|
|
addiu t0,8 # go to next entry
|
490 |
|
|
beq a0,t2,2f # Check for delay
|
491 |
|
|
nop
|
492 |
|
|
beq a0,t3,3f # Check for 16 bit write
|
493 |
|
|
nop
|
494 |
|
|
beq a0,t4,4f # Check for 32 bit write/read
|
495 |
|
|
nop
|
496 |
|
|
beqz a0,9f # zero terminates loop
|
497 |
|
|
nop
|
498 |
|
|
lw zero,0(t1) # uncached read to flush write buffer
|
499 |
|
|
sw a1,0(a0) # write it
|
500 |
|
|
lw zero,0(t1) # uncached read to flush write buffer
|
501 |
|
|
b 1b
|
502 |
|
|
nop
|
503 |
|
|
4:
|
504 |
|
|
lw a3,0(t0) # get next word
|
505 |
|
|
addiu t0,4 # skip it
|
506 |
|
|
lw zero,0(t1) # uncached read to flush write buffer
|
507 |
|
|
sw a3,0(a1) # write it
|
508 |
|
|
lw a3,0(a1) # and read it back
|
509 |
|
|
lw zero,0(t1) # uncached read to flush write buffer
|
510 |
|
|
b 1b
|
511 |
|
|
nop
|
512 |
|
|
2:
|
513 |
|
|
lw zero,0(t1) # uncached read to flush write buffer
|
514 |
|
|
bnez a1,2b # count down by value in a1
|
515 |
|
|
addiu a1,-1 # decrement in delay slot
|
516 |
|
|
b 1b # go back to loop
|
517 |
|
|
nop
|
518 |
|
|
3:
|
519 |
|
|
lw a3,0(t0) # get next word
|
520 |
|
|
addiu t0,4 # skip it
|
521 |
|
|
sh a3,0(a1) # store halfword
|
522 |
|
|
lw zero,0(t1) # uncached read to flush write buffer
|
523 |
|
|
b 1b
|
524 |
|
|
nop
|
525 |
|
|
9:
|
526 |
|
|
jr ra
|
527 |
|
|
nop
|
528 |
|
|
|
529 |
|
|
FUNC_END(hal_memc_setup)
|
530 |
|
|
|
531 |
|
|
##-----------------------------------------------------------------------------
|
532 |
|
|
## Definitions for the VRC4373, also known as the Nile I,
|
533 |
|
|
## and maybe the Nile III as well.
|
534 |
|
|
|
535 |
|
|
#define N1_BASE 0xAF000000
|
536 |
|
|
#define N2_BASE 0xBC000000
|
537 |
|
|
|
538 |
|
|
#define BMCTRL (N1_BASE + 0x00)
|
539 |
|
|
#define S1CTRL (N1_BASE + 0x04)
|
540 |
|
|
#define S2CTRL (N1_BASE + 0x08)
|
541 |
|
|
#define S3CTRL (N1_BASE + 0x0C)
|
542 |
|
|
#define S4CTRL (N1_BASE + 0x10)
|
543 |
|
|
#define PCIMSTRADDR1 (N1_BASE + 0x14)
|
544 |
|
|
#define PCIMSTRADDR2 (N1_BASE + 0x18)
|
545 |
|
|
#define PCISLAVADDR1 (N1_BASE + 0x1C)
|
546 |
|
|
#define PCISLAVADDR2 (N1_BASE + 0x20)
|
547 |
|
|
#define PCIMSTRIO (N1_BASE + 0x24)
|
548 |
|
|
#define PCICNFGDATA (N1_BASE + 0x28)
|
549 |
|
|
#define PCICNFGADDR (N1_BASE + 0x2C)
|
550 |
|
|
#define PCIMBOX1 (N1_BASE + 0x30)
|
551 |
|
|
#define PCIMBOX2 (N1_BASE + 0x34)
|
552 |
|
|
#define DMACTRL1 (N1_BASE + 0x38)
|
553 |
|
|
#define DMALCLADDR1 (N1_BASE + 0x3C)
|
554 |
|
|
#define DMAPCIADDR1 (N1_BASE + 0x40)
|
555 |
|
|
#define DMACTRL2 (N1_BASE + 0x44)
|
556 |
|
|
#define DMALCLADDR2 (N1_BASE + 0x48)
|
557 |
|
|
#define DMAPCIADDR2 (N1_BASE + 0x4C)
|
558 |
|
|
#define BUSERRSTAT (N1_BASE + 0x50)
|
559 |
|
|
#define INTCNTRL (N1_BASE + 0x54)
|
560 |
|
|
#define REFRESHRATE (N1_BASE + 0x58)
|
561 |
|
|
#define BOOTROMWPRTCT (N1_BASE + 0x5C)
|
562 |
|
|
#define PCI_EXCL_ACC (N1_BASE + 0x60)
|
563 |
|
|
#define PCI_ENABLE_REG (N1_BASE + 0x74)
|
564 |
|
|
#define N3_POM_INIT (N1_BASE + 0x78)
|
565 |
|
|
/*
|
566 |
|
|
#define N1RESERVED1 (N1_BASE + 0x60)
|
567 |
|
|
*/
|
568 |
|
|
|
569 |
|
|
#if defined(CYGPKG_HAL_MIPS_VR4300_VRC4375)
|
570 |
|
|
#define N3_EM (N1_BASE + 0x7C)
|
571 |
|
|
#define N3_ARB (N1_BASE + 0x80)
|
572 |
|
|
#define UARTRBR (N1_BASE + 0x84)
|
573 |
|
|
#define UARTTHR (N1_BASE + 0x84)
|
574 |
|
|
#define UARTIER (N1_BASE + 0x88)
|
575 |
|
|
#define UARTDLL (N1_BASE + 0x84)
|
576 |
|
|
#define UARTDLM (N1_BASE + 0x88)
|
577 |
|
|
#define UARTIIR (N1_BASE + 0x8C)
|
578 |
|
|
#define UARTFCR (N1_BASE + 0x8C)
|
579 |
|
|
#define UARTLCR (N1_BASE + 0x90)
|
580 |
|
|
#define UARTMCR (N1_BASE + 0x94)
|
581 |
|
|
#define UARTLSR (N1_BASE + 0x98)
|
582 |
|
|
#define UARTMSR (N1_BASE + 0x9C)
|
583 |
|
|
#define UARTSCR (N1_BASE + 0xA0)
|
584 |
|
|
#endif
|
585 |
|
|
|
586 |
|
|
#define N1PCIHEADER (N1_BASE + 0x100)
|
587 |
|
|
#define N1PCICMD (N1PCIHEADER + 0x04)
|
588 |
|
|
#define MBOXPCIADDR (N1PCIHEADER + 0x10)
|
589 |
|
|
|
590 |
|
|
#define N1CLSIZE (N1PCIHEADER + 0x0c) /* Cache Line Size */
|
591 |
|
|
#define N1MLTIM (N1PCIHEADER + 0x0d)
|
592 |
|
|
#define N1MBADD (N1PCIHEADER + 0x10)
|
593 |
|
|
#define N1RSVD2 (N1PCIHEADER + 0x40) /* Word boundary */
|
594 |
|
|
#define N1RTYTIM (N1PCIHEADER + 0x41)
|
595 |
|
|
|
596 |
|
|
##-----------------------------------------------------------------------------
|
597 |
|
|
## Definitions for the VRC4372, also known as the Nile II.
|
598 |
|
|
|
599 |
|
|
#if defined(CYGPKG_HAL_MIPS_VR4300_VRC4373)
|
600 |
|
|
#define PCI_N2_DEV 0x00010000 /* PCI Device # - Nile 2 */
|
601 |
|
|
#elif defined(CYGPKG_HAL_MIPS_VR4300_VRC4375)
|
602 |
|
|
#define PCI_N2_DEV 0x00080000 /* PCI Device # - Nile 2 */
|
603 |
|
|
#endif
|
604 |
|
|
|
605 |
|
|
#define N2CLSIZE ( 0x0c) /* Cache Line Size */
|
606 |
|
|
#define N2IOADD ( 0x14)
|
607 |
|
|
#define N2DSCTIM ( 0x40)
|
608 |
|
|
|
609 |
|
|
#define IOCON (N2_BASE + 0x0000)
|
610 |
|
|
|
611 |
|
|
/* GPIO Bus Controller Registers */
|
612 |
|
|
#define GPDIR (IOCON + 0x0100)
|
613 |
|
|
#define GPOUT (IOCON + 0x0104)
|
614 |
|
|
#define GPIN (IOCON + 0x0108)
|
615 |
|
|
|
616 |
|
|
/* Interrupt Controller Registers */
|
617 |
|
|
#define INTPOL (IOCON + 0x200)
|
618 |
|
|
#define INTTRIG (IOCON + 0x204)
|
619 |
|
|
#define INTPINS (IOCON + 0x208)
|
620 |
|
|
#define INTMASK0 (IOCON + 0x20C)
|
621 |
|
|
#define INTSTAT0 (IOCON + 0x210)
|
622 |
|
|
#define INTMASK1 (IOCON + 0x214)
|
623 |
|
|
#define INTSTAT1 (IOCON + 0x218)
|
624 |
|
|
#define INTMASK2 (IOCON + 0x21C)
|
625 |
|
|
#define INTSTAT2 (IOCON + 0x220)
|
626 |
|
|
|
627 |
|
|
/* IO Bus Controller Registers */
|
628 |
|
|
#if defined(CYGPKG_HAL_MIPS_MSBFIRST)
|
629 |
|
|
// The 16 bit registers are swapped pairwise in each word.
|
630 |
|
|
#define IOPROF_00 (IOCON + 0x0402)
|
631 |
|
|
#define IOPROF_01 (IOCON + 0x0400)
|
632 |
|
|
#define IOPROF_02 (IOCON + 0x0406)
|
633 |
|
|
#define IOPROF_03 (IOCON + 0x0404)
|
634 |
|
|
#define IOPROF_04 (IOCON + 0x040A)
|
635 |
|
|
#define IOPROF_05 (IOCON + 0x0408)
|
636 |
|
|
#define IOPROF_06 (IOCON + 0x040E)
|
637 |
|
|
#define IOPROF_07 (IOCON + 0x040C)
|
638 |
|
|
#define IOPROF_08 (IOCON + 0x0412)
|
639 |
|
|
#define IOPROF_09 (IOCON + 0x0410)
|
640 |
|
|
#define IOPROF_0A (IOCON + 0x0416)
|
641 |
|
|
#define IOPROF_0B (IOCON + 0x0414)
|
642 |
|
|
#define IOPROF_0C (IOCON + 0x041a)
|
643 |
|
|
#define IOPROF_10 (IOCON + 0x0422)
|
644 |
|
|
#define IOPROF_11 (IOCON + 0x0420)
|
645 |
|
|
#define IOPROF_12 (IOCON + 0x0426)
|
646 |
|
|
#define IOPROF_13 (IOCON + 0x0424)
|
647 |
|
|
#elif defined(CYGPKG_HAL_MIPS_LSBFIRST)
|
648 |
|
|
#define IOPROF_00 (IOCON + 0x0400)
|
649 |
|
|
#define IOPROF_01 (IOCON + 0x0402)
|
650 |
|
|
#define IOPROF_02 (IOCON + 0x0404)
|
651 |
|
|
#define IOPROF_03 (IOCON + 0x0406)
|
652 |
|
|
#define IOPROF_04 (IOCON + 0x0408)
|
653 |
|
|
#define IOPROF_05 (IOCON + 0x040A)
|
654 |
|
|
#define IOPROF_06 (IOCON + 0x040C)
|
655 |
|
|
#define IOPROF_07 (IOCON + 0x040E)
|
656 |
|
|
#define IOPROF_08 (IOCON + 0x0410)
|
657 |
|
|
#define IOPROF_09 (IOCON + 0x0412)
|
658 |
|
|
#define IOPROF_0A (IOCON + 0x0414)
|
659 |
|
|
#define IOPROF_0B (IOCON + 0x0416)
|
660 |
|
|
#define IOPROF_0C (IOCON + 0x0418)
|
661 |
|
|
#define IOPROF_10 (IOCON + 0x0420)
|
662 |
|
|
#define IOPROF_11 (IOCON + 0x0422)
|
663 |
|
|
#define IOPROF_12 (IOCON + 0x0424)
|
664 |
|
|
#define IOPROF_13 (IOCON + 0x0426)
|
665 |
|
|
#else
|
666 |
|
|
#error MIPS endianness not define by configuration
|
667 |
|
|
#endif
|
668 |
|
|
#define IOTOUT (IOCON + 0x0430)
|
669 |
|
|
#define IOPOL (IOCON + 0x0434)
|
670 |
|
|
|
671 |
|
|
##-----------------------------------------------------------------------------
|
672 |
|
|
## PCI definitions
|
673 |
|
|
|
674 |
|
|
#define PCI_IOSPACE_BASE 0x0c /* PCI I/O Space Adr */
|
675 |
|
|
|
676 |
|
|
#define PCIADR_REGNO 0x000000fc /* Register # mask */
|
677 |
|
|
|
678 |
|
|
#define PCI_CONFIG( dev, func, reg ) ( dev | ( reg & PCIADR_REGNO) )
|
679 |
|
|
|
680 |
|
|
#define PCI_COMMAND_STATUS_REG 0x04
|
681 |
|
|
#define PCI_MAP_REG_START 0x10
|
682 |
|
|
#define PCI_INTERRUPT_REG 0x3c
|
683 |
|
|
|
684 |
|
|
##-----------------------------------------------------------------------------
|
685 |
|
|
## The initialization table
|
686 |
|
|
|
687 |
|
|
hal_memc_setup_table:
|
688 |
|
|
|
689 |
|
|
.long DELAY_LOOP, 0x00010000 # Wait for HW to settle
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
# Set up SDRAM and SIMM1
|
693 |
|
|
|
694 |
|
|
#if defined(CYGPKG_HAL_MIPS_VR4300_VRC4373)
|
695 |
|
|
|
696 |
|
|
.long BMCTRL, 0x0000803b # Base memory setup
|
697 |
|
|
.long S1CTRL, 0x0402013f # SIMM1
|
698 |
|
|
|
699 |
|
|
#elif defined(CYGPKG_HAL_MIPS_VR4300_VRC4375)
|
700 |
|
|
|
701 |
|
|
.long N3_EM, 0x00000000
|
702 |
|
|
.long N3_ARB, 0x00000000
|
703 |
|
|
|
704 |
|
|
.long BMCTRL, 0x0000100b # Base memory setup
|
705 |
|
|
|
706 |
|
|
# Dont set up SIMMs on VR4375 at present.
|
707 |
|
|
|
708 |
|
|
#else
|
709 |
|
|
#error Unsupported board
|
710 |
|
|
#endif
|
711 |
|
|
|
712 |
|
|
# Set up power-on memory state
|
713 |
|
|
.long N3_POM_INIT, 0x00000002 # Power-on memory init
|
714 |
|
|
.long DELAY_LOOP, 0x00000100 # wait a bit
|
715 |
|
|
.long WRITEREAD32, N3_POM_INIT, 0x00000004 # Power-on memory init
|
716 |
|
|
.long DELAY_LOOP, 0x00000100 # wait a bit
|
717 |
|
|
.long WRITEREAD32, N3_POM_INIT, 0x00000001 # Power-on memory init
|
718 |
|
|
.long DELAY_LOOP, 0x00000100 # wait a bit
|
719 |
|
|
.long REFRESHRATE, 0x00000fff # DRAM refresh rate
|
720 |
|
|
|
721 |
|
|
#if defined(CYGPKG_HAL_MIPS_VR4300_VRC4375)
|
722 |
|
|
.long N3_ARB, 0x00000005
|
723 |
|
|
#endif
|
724 |
|
|
|
725 |
|
|
.long BOOTROMWPRTCT, 0xffffff3e # Write protect boot ROM
|
726 |
|
|
|
727 |
|
|
# Set up PCI master address window
|
728 |
|
|
.long PCIMSTRADDR1, 0x1c0fd01c
|
729 |
|
|
.long PCIMSTRADDR2, 0x80081080
|
730 |
|
|
|
731 |
|
|
# Set up PCI slave address window
|
732 |
|
|
.long PCISLAVADDR1, 0x00081000
|
733 |
|
|
.long PCISLAVADDR2, 0x10081080
|
734 |
|
|
|
735 |
|
|
# Map PCI IO space Phys == Local
|
736 |
|
|
.long PCIMSTRIO, 0x0c0fd00c
|
737 |
|
|
|
738 |
|
|
# VRC437X Bridge config space
|
739 |
|
|
|
740 |
|
|
.long N1PCICMD, 0x00000006 # Memory space enable, bus master
|
741 |
|
|
.long N1CLSIZE, 0x00003000 # Master latency time
|
742 |
|
|
.long N1MBADD, 0x20000000 # Mailbox base address
|
743 |
|
|
.long N1RSVD2, 0x0000f000 # Retry value
|
744 |
|
|
|
745 |
|
|
.long PCI_EXCL_ACC, 0x00000020 # PCI exclusive access register
|
746 |
|
|
.long PCI_ENABLE_REG, 0x00000005 # PCI config done, enable arbitration
|
747 |
|
|
|
748 |
|
|
# Set up 4372. This is configured entirely through its PCI
|
749 |
|
|
# configuration space. Hence the following all consist of
|
750 |
|
|
# writing an address to the PCICNFGADDR register followed
|
751 |
|
|
# by a write of the data to the PCICNFGDATA register.
|
752 |
|
|
|
753 |
|
|
.long PCICNFGADDR, PCI_CONFIG( PCI_N2_DEV, 0, PCI_COMMAND_STATUS_REG)
|
754 |
|
|
.long PCICNFGDATA, 0x00000146
|
755 |
|
|
|
756 |
|
|
.long PCICNFGADDR, PCI_CONFIG( PCI_N2_DEV, 0, N2CLSIZE)
|
757 |
|
|
.long PCICNFGDATA, 0x00003000
|
758 |
|
|
|
759 |
|
|
.long PCICNFGADDR, PCI_CONFIG( PCI_N2_DEV, 0, PCI_MAP_REG_START)
|
760 |
|
|
.long PCICNFGDATA, 0x1c000000
|
761 |
|
|
|
762 |
|
|
.long PCICNFGADDR, PCI_CONFIG( PCI_N2_DEV, 0, N2IOADD)
|
763 |
|
|
.long PCICNFGDATA, 0x80000000
|
764 |
|
|
|
765 |
|
|
.long PCICNFGADDR, PCI_CONFIG( PCI_N2_DEV, 0, PCI_INTERRUPT_REG)
|
766 |
|
|
.long PCICNFGDATA, 0x00000000
|
767 |
|
|
|
768 |
|
|
.long PCICNFGADDR, PCI_CONFIG( PCI_N2_DEV, 0, N2DSCTIM)
|
769 |
|
|
.long PCICNFGDATA, 0x0070f000
|
770 |
|
|
|
771 |
|
|
# Set up IO bus controller chip select profile registers to
|
772 |
|
|
# allow access to the devices.
|
773 |
|
|
|
774 |
|
|
.long WRITE16, IOPROF_00, 0x04d1 # RTC - DS1386
|
775 |
|
|
.long WRITE16, IOPROF_01, 0x007f # DUART - Z8530
|
776 |
|
|
.long WRITE16, IOPROF_02, 0x007f # Timer - Z8536
|
777 |
|
|
.long WRITE16, IOPROF_03, 0x00d9 # Parallel = 8255
|
778 |
|
|
.long WRITE16, IOPROF_06, 0x007f # 7 segment display
|
779 |
|
|
.long WRITE16, IOPROF_07, 0x007f # 7 segment display
|
780 |
|
|
|
781 |
|
|
# Configure the rest of the 4372
|
782 |
|
|
|
783 |
|
|
.long IOTOUT, 0x200003c0 # IO timout control
|
784 |
|
|
.long IOPOL, 0x00000000 # IO bus pin polarity
|
785 |
|
|
.long GPDIR, 0x000007c0 # GPIO pins 6-10 output
|
786 |
|
|
.long INTPOL, 0x00003fff # Interrupt polarity
|
787 |
|
|
.long INTTRIG, 0x00003fff # Interrupt trigger
|
788 |
|
|
.long INTMASK0, 0x00000000
|
789 |
|
|
.long INTMASK1, 0x00000000
|
790 |
|
|
.long INTMASK2, 0x00000000
|
791 |
|
|
.long INTSTAT0, 0x00000000 # Zero all int status regs
|
792 |
|
|
.long INTSTAT1, 0x00000000
|
793 |
|
|
.long INTSTAT2, 0x00000000
|
794 |
|
|
|
795 |
|
|
.long DELAY_LOOP, 0x00010000 # Wait for HW to settle
|
796 |
|
|
|
797 |
|
|
.long 0, 0
|
798 |
|
|
|
799 |
|
|
#endif
|
800 |
|
|
|
801 |
|
|
##-----------------------------------------------------------------------------
|
802 |
|
|
## end of platform.S
|
803 |
|
|
|