git repos for lemote 502 board
[pmon-gdium.git] / Targets / Bonito2emcpu / Bonito / start.S.bakgodson1
blob2794cde1b58722ae30de3bd76d64c79db7c1c288
1 /*      $Id: start.S,v 1.3 2004/05/17 10:39:22 wlin Exp $ */
3 /*
4  * Copyright (c) 2001 Opsycon AB  (www.opsycon.se)
5  * 
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. 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  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Opsycon AB, Sweden.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  */
34 #ifndef _KERNEL
35 #define _KERNEL
36 #endif
38 #include <asm.h>
39 #include <regnum.h>
40 #include <cpu.h>
41 #include <pte.h>
44 #include "pmon/dev/ns16550.h"
45 #include "target/i82371eb.h"
46 #include "target/prid.h"
47 #include "target/sbd.h"
48 #include "target/bonito.h"
49 #include "target/i8254.h"
50 #include "target/pc97307.h"
51 #include "target/isapnpreg.h"
52 #define DEBUG_LOCORE
53 #undef  DEBUG_DIMM_SPD
54 #ifdef DEBUG_LOCORE
55 #define TTYDBG(x) \
56         .rdata;98: .asciz x; .text; la a0, 98b; bal stringserial; nop
57 #else
58 #define TTYDBG(x)
59 #endif
60 #define PRINTSTR(x) \
61         .rdata;98: .asciz x; .text; la a0, 98b; bal stringserial; nop
64 #define tmpsize         s1
65 #define msize           s2
66 #define sdShape         s3
67 #define bonito          s4
68 #define dbg             s5
69 #define sdCfg           s6
71 #define CFG_IB 0x00000020
72 #define CFG_DB 0x00000010
73 #define CFG_C_WBACK 3
74 #define CFG_BE 0x00008000
75 #define CFG_EPMASK 0x0f000000
76 #define CFG_EPD 0x00000000
77 #define CFG_EM_R4K 0x00000000
78 #define CFG_EMMASK 0x00c00000
79 #define CFG_AD 0x00800000
82  *   Register usage:
83  *
84  *      s0      link versus load offset, used to relocate absolute adresses.
85  *      s1      free
86  *      s2      memory size.
87  *      s3      sdShape.
88  *      s4      Bonito base address.
89  *      s5      dbg.
90  *      s6      sdCfg.
91  *      s7      rasave.
92  *      s8      L3 Cache size.
93  */
96         .set    noreorder
97         .globl  _start
98         .globl  start
99         .globl  __main
100 _start:
101 start:
102         .globl  stack
103 stack = start - 0x4000          /* Place PMON stack below PMON start in RAM */
105 /* NOTE!! Not more that 16 instructions here!!! Right now it's FULL! */
106         mtc0    zero, COP_0_STATUS_REG
107         mtc0    zero, COP_0_CAUSE_REG
108         li      t0, SR_BOOT_EXC_VEC     /* Exception to Boostrap Location */
109         mtc0    t0, COP_0_STATUS_REG
110         la      sp, stack
111         la      gp, _gp
113         bal     uncached                /* Switch to uncached address space */
114         nop
116         bal     locate                  /* Get current execute address */
117         nop
119 uncached:
120         or      ra, UNCACHED_MEMORY_ADDR
121         j       ra
122         nop
125  *  Reboot vector usable from outside pmon.
126  */
127         .align  8
128 ext_map_and_reboot:
129         bal     CPU_TLBClear
130         nop
132         li      a0, 0xc0000000
133         li      a1, 0x40000000
134         bal     CPU_TLBInit
135         nop
136         la      v0, tgt_reboot
137         la      v1, start
138         subu    v0, v1
139         lui     v1, 0xffc0
140         addu    v0, v1
141         jr      v0
142         nop
145  *  Exception vectors here for rom, before we are up and running. Catch
146  *  whatever comes up before we have a fully fledged exception handler.
147  */
148         .align  9                       /* bfc00200 */
149         la      a0, v200_msg
150         bal     stringserial
151         nop
152         b       exc_common
154         .align  7                       /* bfc00280 */
155         la      a0, v280_msg
156         bal     stringserial
157         nop
158         b       exc_common
160 /* Cache error */
161         .align  8                       /* bfc00300 */
162         PRINTSTR("\r\nPANIC! Unexpected Cache Error exception! ")
163         mfc0    a0, COP_0_CACHE_ERR
164         bal     hexserial
165         nop
166         b       exc_common
168 /* General exception */
169         .align  7                       /* bfc00380 */
170         la      a0, v380_msg
171         bal     stringserial
172         nop
173         b       exc_common
174         
175         .align  8                       /* bfc00400 */
176         la      a0, v400_msg
177         bal     stringserial
178         nop
181         
182 exc_common:
183         PRINTSTR("\r\nERRORPC=")
184         mfc0    a0, COP_0_ERROR_PC
185         bal     hexserial
186         nop
187         PRINTSTR("\r\nEPC=")
188         mfc0    a0, COP_0_EXC_PC
189         bal     hexserial
190         nop
191         PRINTSTR("\r\nDERR0=")
192         cfc0    a0, COP_0_DERR_0
193         bal     hexserial
194         nop
195         PRINTSTR("\r\nDERR1=")
196         cfc0    a0, COP_0_DERR_1
197         bal     hexserial
198         nop
199 //      b       ext_map_and_reboot
200         nop
202         .align 8
203                 nop
204         .align 8
205         .word read
206         .word write
207         .word open
208         .word close
209         .word nullfunction
210         .word printf
211         .word vsprintf
212         .word nullfunction
213         .word nullfunction
214         .word getenv
215         .word nullfunction
216         .word nullfunction
217         .word nullfunction
218         .word nullfunction
222  *  We get here from executing a bal to get the PC value of the current execute
223  *  location into ra. Check to see if we run from ROM or if this is ramloaded.
224  */
225 locate:
226         la      s0,start
227         subu    s0,ra,s0
228         and     s0,0xffff0000
230         li      t0,SR_BOOT_EXC_VEC
231         mtc0    t0,COP_0_STATUS_REG
232         mtc0    zero,COP_0_CAUSE_REG
233         .set noreorder
235         li      bonito,PHYS_TO_UNCACHED(BONITO_REG_BASE)
236 #if 0
237 locate:
238         la      s0, start               /* RA set from BAL above! */
239         subu    s0, ra, s0              /* s0 is now load vs. link offset */
240         and     s0, 0xffff0000          /* Mask off lower bits */
241         mfc0    t0,COP_0_PRID
242         mfc0    v0,COP_0_STATUS_REG
243         mtc0    zero,COP_0_WATCH_LO
244         mtc0    zero,COP_0_WATCH_HI
245         and     v0,SR_SOFT_RESET                # preserve Soft Reset
246         or      v0,SR_BOOT_EXC_VEC               # set Boot Exceptions
247         beq     t0,0x0a11,1f            # R4200 rev 1.1: disable cache errors
248         nop
249         beq     t0,0x5413,1f            # R5432 rev 1.3: disable cache errors
250         nop
251         b       2f
252         nop
253 1:      or      v0,SR_DIAG_DE
257  *  Clean out and initialize the TLB
258  */
260         bal     CPU_TLBClear
261         nop
263         li      a0, 0xc0000000
264         li      a1, 0x40000000
265         bal     CPU_TLBInit
266         nop
268  *  Turn off all high decoders to avoid address conflicts.
269  */
270         mtc0    v0,COP_0_STATUS_REG
271         mtc0    zero,COP_0_CAUSE_REG
272         mfc0    t1,COP_0_CONFIG
273         mfc0    t2,COP_0_PRID              # get PrID
274         mtc0    zero,$18                # C0_IWATCH/C0_WATCHLO
275         mtc0    zero,$19                # C0_DWATCH/C0_WATCHHI
276                                                                                 
277         li      bonito,PHYS_TO_UNCACHED(BONITO_REG_BASE)
278         
279         srl     t2,8
280         and     t2,0xff
281         
282         bne     t2,PRID_R4650,2f
283         nop                                                                        
284         mtc0    zero,$0                 # C0_IBASE
285         mtc0    zero,$1                 # C0_IBOUND
286         mtc0    zero,$2                 # C0_DBASE
287         mtc0    zero,$3                 # C0_DBOUND
288         b       3f
289         nop
290                                                                                 
291 2:     
292         and     t1,~0x3f                # set bits 5..0 only
293         or      t1,CFG_IB | CFG_DB | CFG_C_WBACK
295         and     t1,~CFG_EPMASK
296         or      t1,CFG_EPD
297         bne     t2,PRID_R5400,1f
298         nop
299         and     t1,~CFG_EMMASK
300         or      t1,CFG_EM_R4K
301         b       2f
302         nop
303 1:      and     t1,~CFG_AD
304 2:      mtc0    t1,COP_0_CONFIG
305 3:      mfc0    t1,COP_0_STATUS_REG            # get Status
306         mtc0    zero,COP_0_CAUSE_REG
307         and     t1,SR_SOFT_RESET                # leave the SoftReset bit
308         or      t1,SR_BOOT_EXC_VEC               # force Boot Exception Vec
309         mtc0    t1,COP_0_STATUS_REG
310 #endif
312 #define MOD_MASK        0x00000003
313 #define MOD_B           0x00000000 /* byte "modifier" */
314 #define MOD_H           0x00000001 /* halfword "modifier" */
315 #define MOD_W           0x00000002 /* word "modifier" */
316 #if __mips64
317 #       define MOD_D            0x00000003 /* doubleword "modifier" */
318 #endif
320 #define OP_MASK         0x000000fc
321 #define OP_EXIT         0x00000000 /* exit (status) */
322 #define OP_DELAY        0x00000008 /* delay (cycles) */
323 #define OP_RD           0x00000010 /* read (addr) */
324 #define OP_WR           0x00000014 /* write (addr, val) */
325 #define OP_RMW          0x00000018 /* read-modify-write (addr, and, or) */
326 #define OP_WAIT         0x00000020 /* wait (addr, mask, value) */
328 #define WR_INIT(mod,addr,val) \
329         .word   OP_WR|mod,PHYS_TO_UNCACHED(addr);\
330         .word   (val),0
331         
332 #define RD_INIT(mod,addr) \
333         .word   OP_RD|mod,PHYS_TO_UNCACHED(addr);\
334         .word   0,0
335         
336 #define RMW_INIT(mod,addr,and,or) \
337         .word   OP_RMW|mod,PHYS_TO_UNCACHED(addr);\
338         .word   (and),(or)
339         
340 #define WAIT_INIT(mod,addr,and,or) \
341         .word   OP_WAIT|mod,PHYS_TO_UNCACHED(addr);\
342         .word   (mask),(val)
344 #define DELAY_INIT(cycles) \
345         .word   OP_DELAY,(cycles);\
346         .word   0,0
347         
348 #define EXIT_INIT(status) \
349         .word   OP_EXIT,(status);\
350         .word   0,0
352 #define BONITO_INIT(r,v) WR_INIT(MOD_W,BONITO_BASE+/**/r,v)
353 #define BONITO_BIS(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~0,b)
354 #define BONITO_BIC(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~(b),0)
355 #define BONITO_RMW(r,c,s) RMW_INIT(MOD_W,BONITO_BASE+(r),~(c),s)
356         
357 #define CFGADDR(idsel,function,reg) ((1<<(11+(idsel)))+((function)<<8)+(reg))
358 #define _ISABWR_INIT(mod,function,isabreg,val) \
359         WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
360         RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
361         WR_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff),val)
362         
363 #define _ISABRD_INIT(mod,function,isabreg) \
364         WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
365         RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
366         RD_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff))
369 #define _ISAWR_INIT(isareg,val) \
370         WR_INIT(MOD_B,PCI_IO_SPACE+(isareg),val)
371         
372 #define _ISARD_INIT(isareg) \
373         RD_INIT(MOD_B,PCI_IO_SPACE+(isareg))
374         
376 #define ISABBWR_INIT(function,isabreg,val) \
377         _ISABWR_INIT(MOD_B,function,(isabreg),val)
378 #define ISABHWR_INIT(function,isabreg,val) \
379         _ISABWR_INIT(MOD_H,function,(isabreg),val)
380 #define ISABWWR_INIT(function,isabreg,val) \
381         _ISABWR_INIT(MOD_W,function,isabreg,val)
382 #define ISAWR_INIT(isareg,val) \
383         _ISAWR_INIT(isareg,val)
384 #define ISARD_INIT(isareg) \
385         _ISARD_INIT(isareg)
387         bal     1f      
388         nop
390         /* bonito endianess */
391         BONITO_BIC(BONITO_BONPONCFG,BONITO_BONPONCFG_CPUBIGEND)
392         BONITO_BIC(BONITO_BONGENCFG,BONITO_BONGENCFG_BYTESWAP|BONITO_BONGENCFG_MSTRBYTESWAP)
393         BONITO_BIS(BONITO_BONPONCFG, BONITO_BONPONCFG_IS_ARBITER)
394         
395         /*
396          * In certain situations it is possible for the Bonito ASIC
397          * to come up with the PCI registers uninitialised, so do them here
398          */
399 #define PCI_CLASS_BRIDGE                0x06
400 #define PCI_CLASS_SHIFT                 24
401 #define PCI_SUBCLASS_BRIDGE_HOST        0x00
402 #define PCI_SUBCLASS_SHIFT              16
403 #define PCI_COMMAND_IO_ENABLE           0x00000001
404 #define PCI_COMMAND_MEM_ENABLE          0x00000002
405 #define PCI_COMMAND_MASTER_ENABLE       0x00000004
406 #define PCI_COMMAND_STATUS_REG          0x04
407 #define PCI_MAP_IO                      0X00000001
408 #define PCI_DEV_I82371                  17
409 #define PCI_CFG_SPACE                   BONITO_PCICFG_BASE
411         BONITO_INIT(BONITO_PCICLASS,(PCI_CLASS_BRIDGE << PCI_CLASS_SHIFT) | (PCI_SUBCLASS_BRIDGE_HOST << PCI_SUBCLASS_SHIFT))
412         BONITO_INIT(BONITO_PCICMD, BONITO_PCICMD_PERR_CLR|BONITO_PCICMD_SERR_CLR|BONITO_PCICMD_MABORT_CLR|BONITO_PCICMD_MTABORT_CLR|BONITO_PCICMD_TABORT_CLR|BONITO_PCICMD_MPERR_CLR)
413         BONITO_INIT(BONITO_PCILTIMER, 0)
414         BONITO_INIT(BONITO_PCIBASE0, 0)
415         BONITO_INIT(BONITO_PCIBASE1, 0)
416         BONITO_INIT(BONITO_PCIBASE2, 0)
417         BONITO_INIT(BONITO_PCIEXPRBASE, 0)
418         BONITO_INIT(BONITO_PCIINT, 0)
420         BONITO_BIS(BONITO_PCICMD, BONITO_PCICMD_PERRRESPEN)
421         
422         BONITO_BIS(BONITO_PCICMD, PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE)
423         
424         /* enable i/o buffer cache and other go faster bits */
425         BONITO_BIS(BONITO_BONGENCFG, \
426                         BONITO_BONGENCFG_BUSERREN| \
427                         BONITO_BONGENCFG_PREFETCHEN| \
428                         BONITO_BONGENCFG_WBEHINDEN| \
429                         BONITO_BONGENCFG_PCIQUEUE| \
430                         BONITO_BONGENCFG_SNOOPEN)
431         
432        BONITO_BIC(BONITO_BONGENCFG, 0x80)  #½ûÖ¹iobc
434 #      BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_BUSERREN)
436         /* Set debug mode */
437         BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_DEBUGMODE)
439         /******** added to void init southbridge*/
440         EXIT_INIT(0) 
441 #if 0
442         /* Turn most special purpose pins into GPIO; set ISA mode */
443         ISABWWR_INIT(0, I82371_GENCFG, I82371_GENCFG_CFG)
444         
445         /* disable RTC & KBD chip selects */
446         ISABHWR_INIT(0, I82371_XBCS, 0)
447         
448         /* Enable PCI 2.1 timing support */
449         ISABBWR_INIT(0, I82371_DLC, I82371_DLC_DT /* | I82371_DLC_PR */ | I82371_DLC_USBPR | I82371_DLC_DTTE)
451         /* Set top of memory to 16MB, so all ISA bus master & DMA
452            accesses are forwarded to PCI mem space
453          */
454         ISABBWR_INIT(0, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_LBIOS | I82371_TOM_FWD_AB | I82371_TOM_FWD_89)
455         
456         /* Set the SMB base address */
457         ISABWWR_INIT(3, I82371_PCI3_SMBBA, SMB_PORT|PCI_MAP_IO)
458         /* enable the host controller */
459         ISABBWR_INIT(3, I82371_PCI3_SMBHSTCFG, I82371_PCI3_SMB_HST_EN)
460         /* enable the SMB IO ports */
461         ISABBWR_INIT(3, PCI_COMMAND_STATUS_REG, PCI_COMMAND_IO_ENABLE)
462         
463         ISABWWR_INIT(3, I82371_PCI3_PMBA, 0x8000|PCI_MAP_IO)
464         ISABBWR_INIT(3, I82371_PCI3_PMREGMISC, 0x01)
465         
466 /* 15us ISA bus refresh clock */
467 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
468         ISARD_INIT(CTC_PORT+PT_CONTROL)
469         
470         /* program i8254 ISA refresh counter */
471         ISAWR_INIT(CTC_PORT+PT_CONTROL,PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
472         ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
473         ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
475         /* program ISA ICU */
476         ISAWR_INIT(ICU1_PORT,  0x11) /* ICW1 */
477         ISAWR_INIT(ICU1_PORT+1,0x00) /* ICW2: vector */
478         ISAWR_INIT(ICU1_PORT+1,0x04) /* ICW3: cascade on IRQ2 */
479         ISAWR_INIT(ICU1_PORT+1,0x01) /* ICW4: 8086 mode */
480         ISAWR_INIT(ICU1_PORT+1,0xff) /* OCW1: mask all */
482         ISAWR_INIT(ICU2_PORT,  0x11) /* ICW1 */
483         ISAWR_INIT(ICU2_PORT+1,0x08) /* ICW2: vector */
484         ISAWR_INIT(ICU2_PORT+1,0x02) /* ICW3:  */
485         ISAWR_INIT(ICU2_PORT+1,0x01) /* ICW4: 8086 mode */
486         ISAWR_INIT(ICU2_PORT+1,0xff) /* OCW1: mask all */
487                 
488         ISAWR_INIT(ICU1_PORT+1,~(1<<2)) /* enable IRQ2 */
489         /* set up ISA devices */
490         
491         /* select logical device 1 (mouse) */
492         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
493         ISAWR_INIT(ISAPNP_MBDATA,1)
494         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
495         ISAWR_INIT(ISAPNP_MBDATA,1)
496                                                                                
497         /* select logical device 4 (parallel) */
498         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
499         ISAWR_INIT(ISAPNP_MBDATA,4)
500         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
501         ISAWR_INIT(ISAPNP_MBDATA,(ECP_PORT>>8) & 0xff)
502         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
503         ISAWR_INIT(ISAPNP_MBDATA,ECP_PORT & 0xff)
504         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IRQ_DESC0+ISAPNP_IRQ_CONTROL)
505         ISAWR_INIT(ISAPNP_MBDATA,ISAPNP_IRQ_HIGH)
506         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
507         ISAWR_INIT(ISAPNP_MBDATA,1)
508                                                                                
509         /* select logical device 5 (COM2) */
510         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
511         ISAWR_INIT(ISAPNP_MBDATA,5)
512         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
513         ISAWR_INIT(ISAPNP_MBDATA,1)
515         /* select logical device 6 (COM1) */
516         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
517         ISAWR_INIT(ISAPNP_MBDATA,6)
518         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
519         ISAWR_INIT(ISAPNP_MBDATA,1)
520 #endif                                                                       
522                                                                         
523         EXIT_INIT(0)
525 #define Init_Op 0
526 #define Init_A0 4
527 #define Init_A1 8
528 #define Init_A2 12
529 #define Init_Size       16
531 1:      move a0,ra
532 reginit:                        /* local name */
533         lw      t3, Init_Op(a0)
534         lw      t0, Init_A0(a0)
535         and     t4,t3,OP_MASK
536         
537         
538         /* 
539          * EXIT(STATUS) 
540          */
541         bne     t4, OP_EXIT, 8f
542         nop
543         move    v0,t0
544         b       .done
545         nop
546         
547         /* 
548          * DELAY(CYCLES) 
549          */
550 8:      bne     t4, OP_DELAY, 8f
551         nop
552 1:      bnez    t0,1b
553         subu    t0,1
554         b       .next
555         nop     
556         /* 
557          * READ(ADDR) 
558          */
559 8:      bne     t4,OP_RD,8f
560         nop
561         and     t4,t3,MOD_MASK
562         
563         bne     t4,MOD_B,1f
564         nop
565         lbu     t5,0(t0)
566         b       .next
567         nop
568 1:      bne     t4,MOD_H,1f
569         nop
570         lhu     t5,0(t0)
571         b       .next
572         nop
573 1:      bne     t4,MOD_W,1f
574         nop
575 #if __mips64
576         lwu     t5,0(t0)
577 #else 
578         lw      t5,0(t0)
579 #endif
580         b       .next
581         nop
582 1:      
583 #if __mips64
584         lw      t5,0(t0)
585         b       .next
586         nop
587 #else
588         b       .fatal
589         nop
590 #endif
591         
592         /* 
593          * WRITE(ADDR,VAL) 
594          */
595 8:      bne     t4,OP_WR,8f
596         nop
597         lw      t1,Init_A1(a0)
598         and     t4,t3,MOD_MASK
599         
600         bne     t4,MOD_B,1f
601         nop
602         sb      t1,0(t0)
603         b       .next
604         nop
605 1:      bne     t4,MOD_H,1f
606         nop
607         sh      t1,0(t0)
608         b       .next
609         nop
610 1:      bne     t4,MOD_W,1f
611         nop
612         sw      t1,0(t0)
613         b       .next
614         nop
615         
616 1:      
617 #if __mips64
618         sd      t1,0(t0)
619         b       .next
620         nop
621 #else
622         b       .fatal
623         nop
624 #endif
625                 
626         
627         /* 
628          * RMW(ADDR,AND,OR) 
629          */
630 8:      bne     t4,OP_RMW,8f
631         nop
632         lw      t1,Init_A1(a0)
633         lw      t2,Init_A2(a0)
634         and     t4,t3,MOD_MASK
635         
636         bne     t4,MOD_B,1f
637         nop
638         lbu     t4,0(t0)
639         and     t4,t1
640         or      t4,t2
641         sb      t4,0(t0)
642         b       .next
643         nop
644 1:      bne     t4,MOD_H,1f
645         nop
646         lhu     t4,0(t0)
647         and     t4,t1
648         or      t4,t2
649         sh      t4,0(t0)
650         b       .next
651         nop
652 1:      bne     t4,MOD_W,1f
653         nop
654         lw      t4,0(t0)
655         and     t4,t1
656         or      t4,t2
657         sw      t4,0(t0)
658         b       .next
659         nop
660         
661 1:              
662 #if __mips64
663         ld      t4,0(t0)
664         and     t4,t1
665         or      t4,t2
666         sd      t4,0(t0)
667         b       .next
668         nop
669 #else   
670         b       .fatal
671         nop
672 #endif
673                 
674         
675         /* 
676          * WAIT(ADDR,MASK,VAL) 
677          */
678 8:      bne     t4,OP_WAIT,8f
679         nop
680         lw      t1,Init_A1(a0)
681         lw      t2,Init_A2(a0)
682         and     t4,t3,MOD_MASK
683         
684         bne     t4,MOD_B,1f
685         nop
686 3:      lbu     t4,0(t0)
687         and     t4,t1
688         bne     t4,t2,3b
689         nop
690         b       .next
691         nop
692 1:      bne     t4,MOD_H,1f
693         nop
694 3:      lhu     t4,0(t0)
695         and     t4,t1
696         bne     t4,t2,3b
697         nop
698         b       .next
699         nop
700 1:      bne     t4,MOD_W,1f
701         nop
702 3:      lw      t4,0(t0)
703         and     t4,t1
704         bne     t4,t2,3b
705         nop
706         b       .next
707         nop
708 1:              
709 #if __mips64
710 3:      ld      t4,0(t0)
711         and     t4,t1
712         bne     t4,t2,3b
713         nop
714         b       .next
715         nop
716 #else   
717         b       .fatal  
718         nop
719 #endif
720         
721         
722 .next:  addu    a0,Init_Size
723         b       reginit 
724         nop     
725         
727 .fatal: b .done
728         nop
729         bal     stuck
730         nop
731 .done:  
732         /* Initialise other low-level I/O devices */
734         bal     initserial
735         nop
736         
738         PRINTSTR("\r\nPMON2000 MIPS Initializing. Standby...\r\n")
740         PRINTSTR("ERRORPC=")
741         mfc0    a0, COP_0_ERROR_PC
742         bal     hexserial
743         nop
745         PRINTSTR(" CONFIG=")
746         mfc0    a0, COP_0_CONFIG
747         bal     hexserial
748         nop
749         PRINTSTR("\r\n")
750         
751         PRINTSTR(" PRID=")
752         mfc0    a0, COP_0_PRID
753         bal     hexserial
754         nop
755         PRINTSTR("\r\n")
757         PRINTSTR("Raw word read of SMB base address: ");
758         li      a0,CFGADDR(PCI_DEV_I82371,3,I82371_PCI3_SMBBA)
759         li      a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
760         and     a2,a0,0xffff
761         or      a1,a2
762         srl     a0,16
763         li      a2,BONITO_BASE+BONITO_PCIMAP_CFG
764         sw      a0,BONITO_PCIMAP_CFG(bonito)
765         lw      zero,BONITO_PCIMAP_CFG(bonito)
766         lw      a0,(a1)
767         
768         li      a1,2
769         bal     hexserial
770         nop
771         PRINTSTR("\r\n")        
772         
773 #if 0
774         PRINTSTR("Raw word read of SMB HSTCFG: ");
775         li      a0,CFGADDR(PCI_DEV_I82371,3,I82371_PCI3_SMBHSTCFG) # byte???
776         li      a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
777         and     a2,a0,0xffff
778         or      a1,a2
779         srl     a0,16
780         li      a2,BONITO_BASE+BONITO_PCIMAP_CFG
781         sw      a0,BONITO_PCIMAP_CFG(bonito)
782         lw      zero,BONITO_PCIMAP_CFG(bonito)
783         lhu     a0,(a1)
784         
785         li      a1,2
786         bal     hexserial
787         nop
788         PRINTSTR("\r\n")        
789         
790         PRINTSTR("Raw word read of SMB IO ENABLE: ");
791         li      a0,CFGADDR(PCI_DEV_I82371,3,PCI_COMMAND_STATUS_REG)
792         li      a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
793         and     a2,a0,0xffff
794         or      a1,a2
795         srl     a0,16
796         li      a2,BONITO_BASE+BONITO_PCIMAP_CFG
797         sw      a0,BONITO_PCIMAP_CFG(bonito)
798         lw      zero,BONITO_PCIMAP_CFG(bonito)
799         lw      a0,(a1)
800         
801         li      a1,2
802         bal     hexserial
803         nop
804         PRINTSTR("\r\n")        
805 #endif
807         b       skipdimm
808         nop
810         bal     i2cdump
811         nop
812         
813 PRINTSTR("DIMM read\n")
814 #ifdef DEBUG_DIMM_SPD
815   /*test i2c */
816   li    t4,0
817 loop:
818         li      a0,0
819         move    a1,t4
820         bal     i2cread
821         nop
822         move    a0,v0
823         bal     hexserial
824         nop
825         PRINTSTR("\r\n")
827         addu    t4,1
829         li      t0,255
830         bltu    t4,t0,loop
831         nop
832 #endif
833         /* 
834          * Now determine DRAM configuration and size by
835          * reading the I2C EEROM on the DIMMS
836          */
837         li      msize,0
840         /* start with SODIMM #0 */
841         li      a0,0
842         li      sdCfg,0
843         
844 .nextdimm:
845         li      sdShape,0
846         
847         /* read DIMM memory type (must be SDRAM) */
848         li      a1,2
849         bal     i2cread
850         nop
851         bne     v0,4,.nodimm
852         nop
853         PRINTSTR("read memory type\r\n")
854         /* read DIMM memory size per side */
855         li      a1,31
856         bal     i2cread
857         nop
858         beqz    v0,.nodimm
859         nop
860         sll     tmpsize,v0,22           # multiply by 4M
861         
862         PRINTSTR("read memory size per side\r\n")
863         /* read DIMM number of rows */
864         li      a1,3
865         bal     i2cread
866         nop     
867         subu    v0,11
868         bgtu    v0,14-11,.nodimm
869         nop
870         sll     v0,BONITO_SDCFG_AROWBITS_SHIFT
871         and     v0,BONITO_SDCFG_AROWBITS
872         or      sdShape,v0
873         
874         PRINTSTR("read number of rows\r\n")
875 2:      /* read DIMM number of cols */
876         li      a1,4
877         bal     i2cread
878         nop
879         subu    v0,8
880         bgtu    v0,11-8,.nodimm
881         nop
882         sll     v0,BONITO_SDCFG_ACOLBITS_SHIFT
883         and     v0,BONITO_SDCFG_ACOLBITS
884         or      sdShape,v0
885         
886         PRINTSTR("read number of col\r\n")
887 2:      /* read DIMM number of blocks-per-dram */
888         li      a1,17
889         bal     i2cread
890         nop
891         beq     v0,2,2f
892         nop
893         bne     v0,4,.nodimm
894         nop
895         or      sdShape,BONITO_SDCFG_ABANKBIT
896         
897         PRINTSTR("read blocks per dram\r\n")
898 2:      /* read DIMM number of sides (banks) */
899         li      a1,5
900         bal     i2cread
901         nop
902         beq     v0,1,2f
903         nop
904         bne     v0,2,.nodimm
905         nop
906         or      sdShape,BONITO_SDCFG_ASIDES
907         sll     tmpsize,1       # msize *= 2    
908         
909         PRINTSTR("read number of sides\r\n")
910 2:      /* read DIMM width */
911         li      a1,6
912         bal     i2cread
913         nop
914         bleu    v0,36,2f
915         nop
916         bgtu    v0,72,.nodimm
917         nop
918         or      sdShape,BONITO_SDCFG_AWIDTH64
919         
920         PRINTSTR("read width\r\n")
921 2:      addu    msize,tmpsize
922         b       2f
923         nop     
924 .nodimm:
925 #ifdef DBGSBD
926         move    dbg,a0
927         PRINTSTR ("\r\niNo DIMM in slot ")
928         move    a0,dbg
929         bal     hexserial
930         nop
931         PRINTSTR("\r\n")
932         move    a0,dbg
933 #endif  
934         or      sdShape,BONITO_SDCFG_AABSENT
935 2:      beqz    a0,1f
936         nop
937         sll     sdShape,BONITO_SDCFG_BROWBITS_SHIFT
938 1:      or      sdCfg,sdShape
939         
940         move dbg,a0
941         PRINTSTR("DIMM0 in slot")
942         move a0,dbg
943         bal     hexserial
944         nop
945         PRINTSTR("\r\n")
946         move a0,dbg
947         PRINTSTR("DIMM1...\n")
948         move a0,dbg
950         addu    a0,1
951         bltu    a0,2,.nextdimm
952         nop
953         PRINTSTR("DIMM SIZE=")
954         move    a0,msize
955         bal     hexserial
956         nop
957         PRINTSTR("\r\n")
958         /* If we are running in SDRAM, chop 4MB off the memory size,
959            and don't modify sdCfg register (assume someone in 
960            PCI-world has already set it up). */
961         lw      t0,BONITO_BONPONCFG(bonito)
962         and     t0,BONITO_BONPONCFG_ROMBOOT
963         bne     t0,BONITO_BONPONCFG_ROMBOOT_SDRAM,1f
964         nop
965         beqz    msize,2f        # already zero!
966         nop
967         subu    msize,-1
968         b       2f
969         nop
970 1:      sw      sdCfg,BONITO_SDCFG(bonito)
971         
972 2:      b       3f      
973         nop
974 skipdimm:
975         li      msize,0x10000000
976         li      sdCfg,0x0c082091
977         sw      sdCfg,BONITO_SDCFG(bonito)
979 #if 1//def DBGSBD
980         PRINTSTR("sdcfg=");
981         move    a0,sdCfg
982         bal     hexserial
983         nop
984         PRINTSTR("\r\n")
985         
986 #endif
988         li      t1,0            # accumulate pcimembasecfg settings
989                 
990         /* set bar0 mask and translation to point to SDRAM */
991         sub     t0,msize,1
992         not     t0
993         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_MASK_SHIFT
994         and     t0,BONITO_PCIMEMBASECFG_MEMBASE0_MASK
995         or      t1,t0
996         
997         li      t0,0x00000000
998         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_TRANS_SHIFT
999         and     t0,BONITO_PCIMEMBASECFG_MEMBASE0_TRANS
1000         or      t1,t0
1001         or      t1,BONITO_PCIMEMBASECFG_MEMBASE0_CACHED
1003         /* set bar1 to minimum size to conserve PCI space */
1004         li      t0, ~0
1005         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_MASK_SHIFT
1006         and     t0,BONITO_PCIMEMBASECFG_MEMBASE1_MASK
1007         or      t1,t0
1008         
1009         li      t0,0x00000000
1010         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_TRANS_SHIFT
1011         and     t0,BONITO_PCIMEMBASECFG_MEMBASE1_TRANS
1012         or      t1,t0
1013         or      t1,BONITO_PCIMEMBASECFG_MEMBASE1_CACHED
1015         sw      t1,BONITO_PCIMEMBASECFG(bonito)
1017         /* enable configuration cycles now */
1018         lw      t0,BONITO_BONPONCFG(bonito)
1019         and     t0,~BONITO_BONPONCFG_CONFIG_DIS
1020         sw      t0,BONITO_BONPONCFG(bonito)
1022         PRINTSTR("Init SDRAM Done!\r\n");
1025  *  Reset and initialize caches to a known state.
1026  */
1027 #define IndexStoreTagI  0x08
1028 #define IndexStoreTagD  0x09
1029 #define IndexStoreTagS  0x0b
1030 #define IndexStoreTagT  0x0a
1031 #define FillI           0x14
1034  *  RM7000 config register bits.
1035  */
1036 #define CF_7_SE         (1 << 3)        /* Secondary cache enable */
1037 #define CF_7_SC         (1 << 31)       /* Secondary cache not present */
1038 #define CF_7_TE         (1 << 12)       /* Tertiary cache enable */
1039 #define CF_7_TC         (1 << 17)       /* Tertiary cache not present */
1040 #define CF_7_TS         (3 << 20)       /* Tertiary cache size */
1041 #define CF_7_TS_AL      20              /* Shift to align */
1042 #define NOP8 nop;nop;nop;nop;nop;nop;nop;nop
1043 do_caches:
1044         TTYDBG("Sizing caches...\r\n");
1046         mfc0    t3, COP_0_CONFIG        /* t3 = original config */
1047         and     t3, 0xffffeff0          /* Make sure coherency is OK */
1049         and     t3, ~(CF_7_TE|CF_7_SE|CF_7_TC|CF_7_SC)  /* disable L2/L3 cache */
1050         mtc0    t3, COP_0_CONFIG
1051 #if 0
1052         li      t2, 4096
1054         srl     t1, t3, 9
1055         and     t1, 3
1057         sllv    s3, t2, t1              /* s3 = I cache size */
1059         and     t1, t3, 0x20
1060         srl     t1, t1, 1
1061         addu    s4, t1, 16              /* s4 = I cache line size */
1063         srl     t1, t3, 6
1064         and     t1, 3
1065         sllv    s5, t2, t1              /* s5 = D cache size */
1067         and     t1, t3, 0x10
1068         addu    s6, t1, 16              /* s6 = D cache line size */
1069 #endif
1070         TTYDBG("Init caches...\r\n")
1071 #if 0
1072         li      s7, 0                   /* no L2 cache */
1073         li      s8, 0                   /* no L3 cache */
1074 #endif
1076 #       TTYDBG("godson2 caches found\r\n")
1077        bal     godson1_cache_init
1078        nop
1080 #ifdef DEBUG_LOCORE
1081         TTYDBG("Init caches done, cfg = ")
1082         mfc0    a0, COP_0_CONFIG
1083         bal     hexserial
1084         nop
1085         TTYDBG("\r\n\r\n")
1086 #endif
1088         TTYDBG("Copy PMON to execute location...\r\n")
1089 #ifdef DEBUG_LOCORE
1090         TTYDBG("  start = 0x")
1091         la      a0, start
1092         bal     hexserial
1093         nop
1094         TTYDBG("\r\n  copytoram = 0x")
1095         la      a0, copytoram
1096         addu    a0, s0
1097         bal     hexserial
1098         nop
1099         TTYDBG("\r\n  s0 = 0x")
1100         move    a0, s0
1101         bal     hexserial
1102         nop
1103         TTYDBG("\r\n")
1104 #endif
1105         la      a0, start
1106         li      a1, 0xbfc00000
1107         la      a2, _edata
1108         or      a0, 0xa0000000
1109         or      a2, 0xa0000000
1110         subu    t1, a2, a0
1111         srl t1, t1, 2
1113         move    t0, a0
1114         move    t1, a1
1115         move    t2, a2
1117         /* copy text section */
1118         
1119 1:      and     t3,t0,0x0000ffff
1120         bnez    t3,2f
1121         nop
1122         move    a0,t0
1123         bal     hexserial
1124         nop
1125         li      a0,'\r'
1126         bal     tgt_putchar
1127         nop
1128 2:      lw      t3, 0(t1)
1129         nop
1130         sw      t3, 0(t0)
1131         addu    t0, 4
1132         addu    t1, 4
1133         bne t2, t0, 1b
1134         nop
1136         PRINTSTR("\ncopy text section done.\r\n")
1137         
1138         /* Clear BSS */
1139         la      a0, _edata
1140         la      a2, _end
1141 2:      sw      zero, 0(a0)
1142         bne a2, a0, 2b
1143         addu    a0, 4
1146         TTYDBG("Copy PMON to execute location done.\r\n")
1148         /*sw    0, CpuTertiaryCacheSize*/ /* Set L3 cache size */
1149         
1150         move    a0,     msize
1151         srl     a0,20
1152         la      v0, initmips
1153         jalr    v0
1154         nop
1155 stuck:
1156 #ifdef DEBUG_LOCORE
1157         TTYDBG("Dumping GT64240 setup.\r\n")
1158         TTYDBG("offset----data------------------------.\r\n")
1159         li      s3, 0
1161         move    a0, s3
1162         bal     hexserial
1163         nop
1164         TTYDBG(": ")
1166         add     a0, s3, bonito
1167         lw      a0, 0(a0)
1168         bal     hexserial
1169         addiu   s3, 4
1170         TTYDBG(" ")
1171         li      a0, 0xfff
1172         and     a0, s3
1173         beqz    a0, 3f
1174         li      a0, 0x01f
1175         and     a0, s3
1176         bnez    a0, 2b
1177         TTYDBG("\r\n")
1178         b       1b
1179         nop
1181         b       3b
1182         nop
1184 #else
1185         b       stuck
1186         nop
1187 #endif
1189  *  Clear the TLB. Normally called from start.S.
1190  */
1191 #if __mips64
1192 #define MTC0 dmtc0
1193 #else 
1194 #define MTC0 mtc0
1195 #endif
1196 LEAF(CPU_TLBClear)
1197         li      a3, 0                   # First TLB index.
1199         li      a2, PG_SIZE_4K
1200         MTC0   a2, COP_0_TLB_PG_MASK   # Whatever...
1203         MTC0   zero, COP_0_TLB_HI       # Clear entry high.
1204         MTC0   zero, COP_0_TLB_LO0      # Clear entry low0.
1205         MTC0   zero, COP_0_TLB_LO1      # Clear entry low1.
1207         mtc0    a3, COP_0_TLB_INDEX     # Set the index.
1208         addiu   a3, 1
1209         li      a2, 64
1210         nop
1211         nop
1212         tlbwi                           # Write the TLB
1214         bne     a3, a2, 1b
1215         nop
1217         jr      ra
1218         nop
1219 END(CPU_TLBClear)
1222  *  Set up the TLB. Normally called from start.S.
1223  */
1224 LEAF(CPU_TLBInit)
1225         li      a3, 0                   # First TLB index.
1227         li      a2, PG_SIZE_16M
1228         MTC0   a2, COP_0_TLB_PG_MASK   # All pages are 16Mb.
1231         and     a2, a0, PG_SVPN
1232         MTC0   a2, COP_0_TLB_HI # Set up entry high.
1234         move    a2, a0
1235         srl     a2, a0, PG_SHIFT 
1236         and     a2, a2, PG_FRAME
1237         ori     a2, PG_IOPAGE
1238         MTC0   a2, COP_0_TLB_LO0        # Set up entry low0.
1239         addu    a2, (0x01000000 >> PG_SHIFT)
1240         MTC0   a2, COP_0_TLB_LO1        # Set up entry low1.
1242         mtc0    a3, COP_0_TLB_INDEX     # Set the index.
1243         addiu   a3, 1
1244         li      a2, 0x02000000
1245         subu    a1, a2
1246         nop
1247         tlbwi                           # Write the TLB
1249         bgtz    a1, 1b
1250         addu    a0, a2                  # Step address 32Mb.
1252         jr      ra
1253         nop
1254 END(CPU_TLBInit)
1257  * Simple character printing routine used before full initialization
1258  */
1259 #if 0
1260 #define         TXWAIT  0x100000
1261 LEAF(tgt_putchar)
1262         /* blocking transmit, with timeout */
1263         li      t0,TXWAIT                       # timeout
1264 1:      lbu     t1,PHYS_TO_UNCACHED(0x1fd002fd)       # get LSR
1265         and     t1,0x20                 # tx ready?
1266         bnez    t1,1f                           # yup - go and write
1267         nop
1268         subu    t0,1                            # continue until timeout
1269         bnez    t0,1b
1270         nop
1271 1:      sb      a0,PHYS_TO_UNCACHED(0x1fd002f8)               # write data
1272         li      t0,TXWAIT                       # timeout
1273 1:      lbu     t1,PHYS_TO_UNCACHED(0x1fd003fd)       # get LSR
1274         and     t1,0x20                 # tx ready?
1275         bnez    t1,1f                           # yup - go and write
1276         nop
1277         subu    t0,1                            # continue until timeout
1278         bnez    t0,1b
1279         nop
1280 1:      sb      a0,PHYS_TO_UNCACHED(0x1fd003f8)               # write data
1281         j       ra
1282         nop
1283 END(tgt_putchar)
1284 #endif
1286 LEAF(stringserial)
1287         move    a2, ra
1288         addu    a1, a0, s0
1289         lbu     a0, 0(a1)
1291         beqz    a0, 2f
1292         nop
1293         bal     tgt_putchar
1294         addiu   a1, 1
1295         b       1b
1296         lbu     a0, 0(a1)
1299         j       a2
1300         nop
1301 END(stringserial)
1302 LEAF(outstring)
1303         move    a2, ra
1304         move    a1, a0
1305         lbu     a0, 0(a1)
1307         beqz    a0, 2f
1308         nop
1309         bal     tgt_putchar
1310         addiu   a1, 1
1311         b       1b
1312         lbu     a0, 0(a1)
1315         j       a2
1316         nop
1317 END(outstring)
1318 LEAF(hexserial)
1319         move    a2, ra
1320         move    a1, a0
1321         li      a3, 7
1323         rol     a0, a1, 4
1324         move    a1, a0
1325         and     a0, 0xf
1326         la      v0, hexchar
1327         addu    v0, s0
1328         addu    v0, a0
1329         bal     tgt_putchar
1330         lbu     a0, 0(v0)
1332         bnez    a3, 1b
1333         addu    a3, -1
1335         j       a2
1336         nop
1337 END(hexserial)
1338 LEAF(tgt_putchar)
1339 #       la      v0, COM1_BASE_ADDR
1340         la      v0, COM3_BASE_ADDR
1342         lbu     v1, NSREG(NS16550_LSR)(v0)
1343         and     v1, LSR_TXRDY
1344         beqz    v1, 1b
1345         nop
1347         sb      a0, NSREG(NS16550_DATA)(v0)
1349         j       ra
1350         nop     
1351 END(tgt_putchar)
1352 /* baud rate definitions, matching include/termios.h */
1353 #define B0      0
1354 #define B50     50      
1355 #define B75     75
1356 #define B110    110
1357 #define B134    134
1358 #define B150    150
1359 #define B200    200
1360 #define B300    300
1361 #define B600    600
1362 #define B1200   1200
1363 #define B1800   1800
1364 #define B2400   2400
1365 #define B4800   4800
1366 #define B9600   9600
1367 #define B19200  19200
1368 #define B38400  38400
1369 #define B57600  57600
1370 #define B115200 115200
1372 LEAF(initserial)
1373 #       la      v0, COM1_BASE_ADDR
1374         la      v0, COM3_BASE_ADDR
1376         li      v1, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4
1377         sb      v1, NSREG(NS16550_FIFO)(v0)
1378         li      v1, CFCR_DLAB
1379         sb      v1, NSREG(NS16550_CFCR)(v0)
1380         li      v1, NS16550HZ/(16*CONS_BAUD)
1381         sb      v1, NSREG(NS16550_DATA)(v0)
1382         srl     v1, 8
1383         sb      v1, NSREG(NS16550_IER)(v0)
1384         li      v1, CFCR_8BITS
1385         sb      v1, NSREG(NS16550_CFCR)(v0)
1386         li      v1, MCR_DTR|MCR_RTS
1387         sb      v1, NSREG(NS16550_MCR)(v0)
1388         li      v1, 0x0
1389         sb      v1, NSREG(NS16550_IER)(v0)
1391 #       move    v1, v0
1392 #       la      v0, COM2_BASE_ADDR
1393 #       bne     v0, v1, 1b
1394 #       nop
1396         j       ra
1397         nop
1398 END(initserial)
1400 #define SMBOFFS(reg) I82371_SMB_SMB##reg
1402 LEAF(i2cdump)
1403         move    t4,ra
1404         
1405         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1406         lbu     a0,SMBOFFS(HSTSTS)(a0)
1407         li      a1,1
1408         bal     hexserial
1409         nop
1410         PRINTSTR("\r\n")
1411                 
1412         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1413         lbu     a0,SMBOFFS(SLVSTS)(a0)
1414         li      a1,1
1415         bal     hexserial
1416         nop
1417         PRINTSTR("\r\n")
1418         
1419         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1420         lbu     a0,SMBOFFS(HSTCNT)(a0)
1421         li      a1,1
1422         bal     hexserial
1423         nop
1424         PRINTSTR("\r\n")
1425         
1426         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1427         lbu     a0,SMBOFFS(HSTCMD)(a0)
1428         li      a1,1
1429         bal     hexserial
1430         nop
1431         PRINTSTR("\r\n")
1432         
1433         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1434         lbu     a0,SMBOFFS(HSTADD)(a0)
1435         li      a1,1
1436         bal     hexserial
1437         nop
1438         PRINTSTR("\r\n")
1439         
1440         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1441         lbu     a0,SMBOFFS(HSTDAT0)(a0)
1442         li      a1,1
1443         bal     hexserial
1444         nop
1445         PRINTSTR("\r\n")
1446         
1447         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1448         lbu     a0,SMBOFFS(HSTDAT1)(a0)
1449         li      a1,1
1450         bal     hexserial
1451         nop
1452         PRINTSTR("\r\n")
1453         
1454         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1455         lbu     a0,SMBOFFS(BLKDAT)(a0)
1456         li      a1,1
1457         bal     hexserial
1458         nop
1459         PRINTSTR("\r\n")
1460         
1461         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1462         lbu     a0,SMBOFFS(SLVCNT)(a0)
1463         li      a1,1
1464         bal     hexserial
1465         nop
1466         PRINTSTR("\r\n")
1467         
1468         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1469         lbu     a0,SMBOFFS(SHDWCMD)(a0)
1470         li      a1,1
1471         bal     hexserial
1472         nop
1473         PRINTSTR("\r\n")
1474         
1475         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1476         lbu     a0,SMBOFFS(SLVEVT)(a0)
1477         li      a1,1
1478         bal     hexserial
1479         nop
1480         PRINTSTR("\r\n")
1481         
1482         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1483         lbu     a0,SMBOFFS(SLVDAT)(a0)
1484         li      a1,1
1485         bal     hexserial
1486         nop
1487         PRINTSTR("\r\n")
1488         
1489         jr      t4
1490         nop
1491 END(i2cdump)
1495 LEAF(i2cread)
1496         li      t0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1498         lbu     t1,SMBOFFS(HSTSTS)(t0)
1499         and     t1,~(I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER)
1500         sb      t1,SMBOFFS(HSTSTS)(t0)
1501         
1502         sll     t1,a0,1
1503         or      t1,0xa1         # DIMM base address and read bit
1504         sb      t1,SMBOFFS(HSTADD)(t0)
1505         sb      a1,SMBOFFS(HSTCMD)(t0)
1506         
1507         
1508         li      t1,I82371_SMB_START|I82371_SMB_BDRW
1509         sb      t1,SMBOFFS(HSTCNT)(t0)
1511         li      t3,10000        
1512 1:      lbu     t1,SMBOFFS(HSTSTS)(t0)
1513         and     t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER
1514         bnez    t2,1f
1515         nop
1516         sub     t3,1
1517         bnez    t3,1b
1518         nop
1519         b       9f              
1520         nop
1521 1:      
1522         # clear pending errors/interrupts
1523         sb      t1,SMBOFFS(HSTSTS)(t0)
1524         
1525         and     t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR
1526         bnez    t2,9f
1527         nop
1528         lbu     v0,SMBOFFS(HSTDAT0)(t0)
1529         j       ra
1530         nop
1531         
1532 9:      li      v0,-1
1533         j       ra
1534         nop
1535 END(i2cread)    
1537 __main:
1538         j       ra
1539         nop
1542         .rdata
1543 transmit_pat_msg:
1544         .asciz  "\r\nInvalid transmit pattern.  Must be DDDD or DDxDDx\r\n"
1545 v200_msg:
1546         .asciz  "\r\nPANIC! Unexpected TLB refill exception!\r\n"
1547 v280_msg:
1548         .asciz  "\r\nPANIC! Unexpected XTLB refill exception!\r\n"
1549 v380_msg:
1550         .asciz  "\r\nPANIC! Unexpected General exception!\r\n"
1551 v400_msg:
1552         .asciz  "\r\nPANIC! Unexpected Interrupt exception!\r\n"
1553 hexchar:
1554         .ascii  "0123456789abcdef"
1556         .text
1557         .align  2
1559  *   I2C Functions used in early startup code to get SPD info from
1560  *   SDRAM modules. This code must be entirely PIC and RAM independent.
1561  */
1563 /* Delay macro */
1564 #define DELAY(count)    \
1565         li v0, count;   \
1566 99:                     \
1567         bnz     vo, 99b;\
1568         addiu   v0, -1
1571 #define I2C_INT_ENABLE  0x80
1572 #define I2C_ENABLE      0x40
1573 #define I2C_ACK         0x04
1574 #define I2C_INT_FLAG    0x08
1575 #define I2C_STOP_BIT    0x10
1576 #define I2C_START_BIT   0x20
1578 #define I2C_AMOD_RD     0x01
1580 #define BUS_ERROR                               0x00
1581 #define START_CONDITION_TRA                     0x08
1582 #define RSTART_CONDITION_TRA                    0x10
1583 #define ADDR_AND_WRITE_BIT_TRA_ACK_REC          0x18
1584 #define ADDR_AND_READ_BIT_TRA_ACK_REC           0x40
1585 #define SLAVE_REC_WRITE_DATA_ACK_TRA            0x28
1586 #define MAS_REC_READ_DATA_ACK_NOT_TRA           0x58
1588 #define Index_Store_Tag_D                       0x05
1589 #define Index_Invalidate_I                      0x00
1590 #define Index_Writeback_Inv_D                   0x01
1592 LEAF(godson1_cache_init)
1593 ####part 2####
1594         .set mips3
1595 cache_detect_2way:
1596         mfc0    t4, COP_0_CONFIG
1597         andi    t5, t4, 0x0e00
1598         srl     t5, t5, 9
1599         andi    t6, t4, 0x01c0
1600         srl     t6, t6, 6
1601         addiu   t6, t6, 11
1602         addiu   t5, t5, 11
1603         addiu   t4, $0, 1
1604         sllv    t6, t4, t6
1605         sllv    t5, t4, t5
1606         addiu   t7, $0, 2
1607 ####part 3####
1608         lui     a0, 0x8000
1609         addu    a1, $0, t5
1610         addu    a2, $0, t6
1611 cache_init_d2way:
1612 #a0=0x80000000, a1=icache_size, a2=dcache_size
1613 #a3, v0 and v1 used as local registers
1614         mtc0    $0, COP_0_TAG_HI
1615         addu    v0, $0, a0
1616         addu    v1, a0, a2
1617 1:      slt     a3, v0, v1
1618         beq     a3, $0, 1f
1619         nop
1620         mtc0    $0, COP_0_TAG_LO
1621         cache   Index_Store_Tag_D, 0x0(v0)
1622         mtc0    $0, COP_0_TAG_LO
1623         cache   Index_Store_Tag_D, 0x1(v0)
1624         beq     $0, $0, 1b
1625         addiu   v0, v0, 0x20
1627 cache_flush_i2way:
1628         addu    v0, $0, a0
1629         addu    v1, a0, a1
1630 1:      slt     a3, v0, v1
1631         beq     a3, $0, 1f
1632         nop
1633         cache   Index_Invalidate_I, 0x0(v0)
1634 #       cache   Index_Invalidate_I, 0x1(v0)
1635         beq     $0, $0, 1b
1636         addiu   v0, v0, 0x20
1638 cache_flush_d2way:
1639         addu    v0, $0, a0
1640         addu    v1, a0, a2
1641 1:      slt     a3, v0, v1
1642         beq     a3, $0, 1f
1643         nop
1644         cache   Index_Writeback_Inv_D, 0x0(v0)
1645         cache   Index_Writeback_Inv_D, 0x1(v0)
1646         beq     $0, $0, 1b
1647         addiu   v0, v0, 0x20
1649 cache_init_finish:
1650         nop
1651         jr      ra
1652         nop
1654 cache_init_panic:
1655         TTYDBG("cache init panic\r\n");
1656 1:      b       1b
1657         nop
1658         .set mips2
1659 END(godson1_cache_init)
1660 LEAF(nullfunction)
1661         jr ra
1662         nop
1663 END(nullfunction)