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