Initial xloong code
[xloong.git] / Targets / Bonito / Bonito / start.S.1006.1.25
blobc5dd0d265e2d16fbde1c9aa13fb18532d5491a77
1 /*      $Id: start.S.1006.1.25,v 1.1.1.1 2006/09/14 01:59:08 root 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
63 #define CONFIG_CACHE_64K_4WAY 1
65 #define tmpsize         s1
66 #define msize           s2
67 #define sdShape         s3
68 #define bonito          s4
69 #define dbg             s5
70 #define sdCfg           s6
72 #define CFG_IB 0x00000020
73 #define CFG_DB 0x00000010
74 #define CFG_C_WBACK 3
75 #define CFG_BE 0x00008000
76 #define CFG_EPMASK 0x0f000000
77 #define CFG_EPD 0x00000000
78 #define CFG_EM_R4K 0x00000000
79 #define CFG_EMMASK 0x00c00000
80 #define CFG_AD 0x00800000
82 #define CP0_CONFIG $16
83 #define CP0_TAGLO  $28
84 #define CP0_TAGHI  $29
86 #define DDR100 0x04041091
87 #define DDR266 0x0410435e
88 #define DDR300 0x041453df
90 #if 0
91 #define DEBUG_WR(num) \
92 li v0,0xbfe00170; \
93 li v1,num; \
94 sw v1,(v0);
95 #else
96 #define DEBUG_WR(num) 
97 #endif
100  *   Register usage:
102  *      s0      link versus load offset, used to relocate absolute adresses.
103  *      s1      free
104  *      s2      memory size.
105  *      s3      sdShape.
106  *      s4      Bonito base address.
107  *      s5      dbg.
108  *      s6      sdCfg.
109  *      s7      rasave.
110  *      s8      L3 Cache size.
111  */
114         .set    noreorder
115         .globl  _start
116         .globl  start
117         .globl  __main
118 _start:
119 start:
120         .globl  stack
121 stack = start - 0x4000          /* Place PMON stack below PMON start in RAM */
123 /* NOTE!! Not more that 16 instructions here!!! Right now it's FULL! */
124         mtc0    zero, COP_0_STATUS_REG
125         mtc0    zero, COP_0_CAUSE_REG
126         li      t0, SR_BOOT_EXC_VEC     /* Exception to Boostrap Location */
127         mtc0    t0, COP_0_STATUS_REG
128         la      sp, stack
129         la      gp, _gp
131         bal     uncached                /* Switch to uncached address space */
132         nop
134         bal     locate                  /* Get current execute address */
135         nop
137 uncached:
138         or      ra, UNCACHED_MEMORY_ADDR
139         j       ra
140         nop
143  *  Reboot vector usable from outside pmon.
144  */
145         .align  8
146 ext_map_and_reboot:
147         bal     CPU_TLBClear
148         nop
150         li      a0, 0xc0000000
151         li      a1, 0x40000000
152         bal     CPU_TLBInit
153         nop
154         la      v0, tgt_reboot
155         la      v1, start
156         subu    v0, v1
157         lui     v1, 0xffc0
158         addu    v0, v1
159         jr      v0
160         nop
163  *  Exception vectors here for rom, before we are up and running. Catch
164  *  whatever comes up before we have a fully fledged exception handler.
165  */
166         .align  9                       /* bfc00200 */
167         la      a0, v200_msg
168         bal     stringserial
169         nop
170         b       exc_common
172         .align  7                       /* bfc00280 */
173         la      a0, v280_msg
174         bal     stringserial
175         nop
176         b       exc_common
178 /* Cache error */
179         .align  8                       /* bfc00300 */
180         PRINTSTR("\r\nPANIC! Unexpected Cache Error exception! ")
181         mfc0    a0, COP_0_CACHE_ERR
182         bal     hexserial
183         nop
184         b       exc_common
186 /* General exception */
187         .align  7                       /* bfc00380 */
188         la      a0, v380_msg
189         bal     stringserial
190         nop
191         b       exc_common
192         
193         .align  8                       /* bfc00400 */
194         la      a0, v400_msg
195         bal     stringserial
196         nop
199         
200 exc_common:
201         PRINTSTR("\r\nCAUSE=")
202         mfc0    a0, COP_0_CAUSE_REG
203         bal     hexserial
204         nop
205         PRINTSTR("\r\nSTATUS=")
206         mfc0    a0, COP_0_STATUS_REG
207         bal     hexserial
208         nop
209         PRINTSTR("\r\nERRORPC=")
210         mfc0    a0, COP_0_ERROR_PC
211         bal     hexserial
212         nop
213         PRINTSTR("\r\nEPC=")
214         mfc0    a0, COP_0_EXC_PC
215         bal     hexserial
216         nop
217         PRINTSTR("\r\nDERR0=")
218         cfc0    a0, COP_0_DERR_0
219         bal     hexserial
220         nop
221         PRINTSTR("\r\nDERR1=")
222         cfc0    a0, COP_0_DERR_1
223         bal     hexserial
224         nop
226 //      b       ext_map_and_reboot
227         nop
228 #if 1
229         .align 8
230                 nop
231         .align 8
232         .word read
233         .word write
234         .word open
235         .word close
236         .word nullfunction
237         .word printf
238         .word vsprintf
239         .word nullfunction
240         .word nullfunction
241         .word getenv
242         .word nullfunction
243         .word nullfunction
244         .word nullfunction
245         .word nullfunction
246 #endif
249  *  We get here from executing a bal to get the PC value of the current execute
250  *  location into ra. Check to see if we run from ROM or if this is ramloaded.
251  */
252 locate:
253         la      s0,start
254         subu    s0,ra,s0
255         and     s0,0xffff0000
257         li      t0,SR_BOOT_EXC_VEC
258         mtc0    t0,COP_0_STATUS_REG
259         mtc0    zero,COP_0_CAUSE_REG
260         .set noreorder
262         li      bonito,PHYS_TO_UNCACHED(BONITO_REG_BASE)
265 #define MOD_MASK        0x00000003
266 #define MOD_B           0x00000000 /* byte "modifier" */
267 #define MOD_H           0x00000001 /* halfword "modifier" */
268 #define MOD_W           0x00000002 /* word "modifier" */
269 #if __mips64
270 #       define MOD_D            0x00000003 /* doubleword "modifier" */
271 #endif
273 #define OP_MASK         0x000000fc
274 #define OP_EXIT         0x00000000 /* exit (status) */
275 #define OP_DELAY        0x00000008 /* delay (cycles) */
276 #define OP_RD           0x00000010 /* read (addr) */
277 #define OP_WR           0x00000014 /* write (addr, val) */
278 #define OP_RMW          0x00000018 /* read-modify-write (addr, and, or) */
279 #define OP_WAIT         0x00000020 /* wait (addr, mask, value) */
281 #define WR_INIT(mod,addr,val) \
282         .word   OP_WR|mod,PHYS_TO_UNCACHED(addr);\
283         .word   (val),0
284         
285 #define RD_INIT(mod,addr) \
286         .word   OP_RD|mod,PHYS_TO_UNCACHED(addr);\
287         .word   0,0
288         
289 #define RMW_INIT(mod,addr,and,or) \
290         .word   OP_RMW|mod,PHYS_TO_UNCACHED(addr);\
291         .word   (and),(or)
292         
293 #define WAIT_INIT(mod,addr,and,or) \
294         .word   OP_WAIT|mod,PHYS_TO_UNCACHED(addr);\
295         .word   (mask),(val)
297 #define DELAY_INIT(cycles) \
298         .word   OP_DELAY,(cycles);\
299         .word   0,0
300         
301 #define EXIT_INIT(status) \
302         .word   OP_EXIT,(status);\
303         .word   0,0
305 #define BONITO_INIT(r,v) WR_INIT(MOD_W,BONITO_BASE+/**/r,v)
306 #define BONITO_BIS(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~0,b)
307 #define BONITO_BIC(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~(b),0)
308 #define BONITO_RMW(r,c,s) RMW_INIT(MOD_W,BONITO_BASE+(r),~(c),s)
309         
310 #define CFGADDR(idsel,function,reg) ((1<<(11+(idsel)))+((function)<<8)+(reg))
311 #define _ISABWR_INIT(mod,function,isabreg,val) \
312         WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
313         RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
314         WR_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff),val)
315         
316 #define _ISABRD_INIT(mod,function,isabreg) \
317         WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
318         RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
319         RD_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff))
322 #define _ISAWR_INIT(isareg,val) \
323         WR_INIT(MOD_B,PCI_IO_SPACE+(isareg),val)
324         
325 #define _ISARD_INIT(isareg) \
326         RD_INIT(MOD_B,PCI_IO_SPACE+(isareg))
327         
329 #define ISABBWR_INIT(function,isabreg,val) \
330         _ISABWR_INIT(MOD_B,function,(isabreg),val)
331 #define ISABHWR_INIT(function,isabreg,val) \
332         _ISABWR_INIT(MOD_H,function,(isabreg),val)
333 #define ISABWWR_INIT(function,isabreg,val) \
334         _ISABWR_INIT(MOD_W,function,isabreg,val)
335 #define ISAWR_INIT(isareg,val) \
336         _ISAWR_INIT(isareg,val)
337 #define ISARD_INIT(isareg) \
338         _ISARD_INIT(isareg)
340         bal     1f      
341         nop
343         /* bonito endianess */
344         BONITO_BIC(BONITO_BONPONCFG,BONITO_BONPONCFG_CPUBIGEND)
345         BONITO_BIC(BONITO_BONGENCFG,BONITO_BONGENCFG_BYTESWAP|BONITO_BONGENCFG_MSTRBYTESWAP)
346         BONITO_BIS(BONITO_BONPONCFG, BONITO_BONPONCFG_IS_ARBITER)
347         
348         /*
349          * In certain situations it is possible for the Bonito ASIC
350          * to come up with the PCI registers uninitialised, so do them here
351          */
352 #define PCI_CLASS_BRIDGE                0x06
353 #define PCI_CLASS_SHIFT                 24
354 #define PCI_SUBCLASS_BRIDGE_HOST        0x00
355 #define PCI_SUBCLASS_SHIFT              16
356 #define PCI_COMMAND_IO_ENABLE           0x00000001
357 #define PCI_COMMAND_MEM_ENABLE          0x00000002
358 #define PCI_COMMAND_MASTER_ENABLE       0x00000004
359 #define PCI_COMMAND_STATUS_REG          0x04
360 #define PCI_MAP_IO                      0X00000001
361 #define PCI_DEV_I82371                  17
362 #define PCI_CFG_SPACE                   BONITO_PCICFG_BASE
364         BONITO_INIT(BONITO_PCICLASS,(PCI_CLASS_BRIDGE << PCI_CLASS_SHIFT) | (PCI_SUBCLASS_BRIDGE_HOST << PCI_SUBCLASS_SHIFT))
365         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)
366         BONITO_INIT(BONITO_PCILTIMER, 0)
367         BONITO_INIT(BONITO_PCIBASE0, 0)
368         BONITO_INIT(BONITO_PCIBASE1, 0)
369         BONITO_INIT(BONITO_PCIBASE2, 0)
370         BONITO_INIT(BONITO_PCIEXPRBASE, 0)
371         BONITO_INIT(BONITO_PCIINT, 0)
373         BONITO_BIS(BONITO_PCICMD, BONITO_PCICMD_PERRRESPEN)
374         
375         BONITO_BIS(BONITO_PCICMD, PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE)
376         
377         /* enable i/o buffer cache and other go faster bits */
378         BONITO_BIS(BONITO_BONGENCFG, \
379                         BONITO_BONGENCFG_BUSERREN| \
380                         BONITO_BONGENCFG_PREFETCHEN| \
381                         BONITO_BONGENCFG_WBEHINDEN| \
382                         BONITO_BONGENCFG_PCIQUEUE| \
383                         BONITO_BONGENCFG_SNOOPEN)
384         
385        BONITO_BIC(BONITO_BONGENCFG, 0x80)  #½ûÖ¹iobc
387 #      BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_BUSERREN)
389         /* Set debug mode */
390         BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_DEBUGMODE)
392         /******** added to void init southbridge*/
393 #if 1
394         /* zhb init USB */
395         ISABWWR_INIT(2, 0x20, 0x8040|PCI_MAP_IO)
396         ISABWWR_INIT(2, PCI_COMMAND_STATUS_REG, 5)
398         /* zhb init floppy-disk */
399         ISABWWR_INIT(3, I82371_PCI3_DEVRESD, 0x1800)
400         ISABWWR_INIT(3, I82371_PCI3_DEVRESB, 0x20000000)
402         /* Turn most special purpose pins into GPIO; set ISA mode */
403         ISABWWR_INIT(0, I82371_GENCFG, I82371_GENCFG_CFG)
404         
405         /* disable RTC & KBD chip selects */
406 //      ISABHWR_INIT(0, I82371_XBCS, 0)
407         
408         /* Enable PCI 2.1 timing support */
409         ISABBWR_INIT(0, I82371_DLC, I82371_DLC_DT /* | I82371_DLC_PR */ | I82371_DLC_USBPR | I82371_DLC_DTTE)
411         /* Set top of memory to 16MB, so all ISA bus master & DMA
412            accesses are forwarded to PCI mem space
413          */
414         ISABBWR_INIT(0, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_LBIOS | I82371_TOM_FWD_AB | I82371_TOM_FWD_89)
415         
416         /* Set the SMB base address */
417         ISABWWR_INIT(3, I82371_PCI3_SMBBA, SMB_PORT|PCI_MAP_IO)
418         /* enable the host controller */
419         ISABBWR_INIT(3, I82371_PCI3_SMBHSTCFG, I82371_PCI3_SMB_HST_EN)
420         /* enable the SMB IO ports */
421         ISABBWR_INIT(3, PCI_COMMAND_STATUS_REG, PCI_COMMAND_IO_ENABLE)
422         
423         ISABWWR_INIT(3, I82371_PCI3_PMBA, PM_PORT|PCI_MAP_IO) /*notice*/
424         #define GPO_REG (0x34+PM_PORT)
425 #define UART1_485 (1<<17)
426 #define UART1_422 (1<<18)
427 #define UART2_485 (1<<19)
428 #define UART2_422 (1<<20)
429 #define UART1_232 (1<<21)
430 #define UART2_232 (1<<0)
431 #define LAN1_EN (1<<8)
432 #define LAN2A_EN (1<<27)
433 #define LAN2B_EN (1<<28)
434 /*ĬÈÏʹÄÜË«Íø¿¨,Á½¸ö´®¿Ú¶¼¹¤×÷ÔÚ232ģʽÏÂ*/
435         #define GPO_INITDATA  (UART1_232|UART2_232|LAN1_EN|LAN2B_EN)
436 //      WR_INIT(MOD_W,PCI_IO_SPACE+GPO_REG,GPO_INITDATA)
437         #define A82371_RST_REG 0xcf9
438 //      WR_INIT(MOD_B,PCI_IO_SPACE+82371_RST_REG,3)/*notice*/
440         ISABBWR_INIT(3, I82371_PCI3_PMREGMISC, 0x01)
441         
442 /* 15us ISA bus refresh clock */
443 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
444         ISARD_INIT(CTC_PORT+PT_CONTROL)
445         
446         /* program i8254 ISA refresh counter */
447         ISAWR_INIT(CTC_PORT+PT_CONTROL,PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
448         ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
449         ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
451         /* program ISA ICU */
452         ISAWR_INIT(ICU1_PORT,  0x11) /* ICW1 */
453         ISAWR_INIT(ICU1_PORT+1,0x00) /* ICW2: vector */
454         ISAWR_INIT(ICU1_PORT+1,0x04) /* ICW3: cascade on IRQ2 */
455         ISAWR_INIT(ICU1_PORT+1,0x01) /* ICW4: 8086 mode */
456         ISAWR_INIT(ICU1_PORT+1,0xff) /* OCW1: mask all */
458         ISAWR_INIT(ICU2_PORT,  0x11) /* ICW1 */
459         ISAWR_INIT(ICU2_PORT+1,0x08) /* ICW2: vector */
460         ISAWR_INIT(ICU2_PORT+1,0x02) /* ICW3:  */
461         ISAWR_INIT(ICU2_PORT+1,0x01) /* ICW4: 8086 mode */
462         ISAWR_INIT(ICU2_PORT+1,0xff) /* OCW1: mask all */
463                 
464         ISAWR_INIT(ICU1_PORT+1,~(1<<2)) /* enable IRQ2 */
465         /* set up ISA devices */
466         
467         /* select logical device 1 (mouse) */
468         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
469         ISAWR_INIT(ISAPNP_MBDATA,1)
470         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
471         ISAWR_INIT(ISAPNP_MBDATA,1)
472                                                                                
473         /* select logical device 4 (parallel) */
474         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
475         ISAWR_INIT(ISAPNP_MBDATA,4)
476         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
477         ISAWR_INIT(ISAPNP_MBDATA,(ECP_PORT>>8) & 0xff)
478         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
479         ISAWR_INIT(ISAPNP_MBDATA,ECP_PORT & 0xff)
480         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IRQ_DESC0+ISAPNP_IRQ_CONTROL)
481         ISAWR_INIT(ISAPNP_MBDATA,ISAPNP_IRQ_HIGH)
482         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
483         ISAWR_INIT(ISAPNP_MBDATA,1)
484                                                                                
485         /* select logical device 5 (COM2) */
486         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
487         ISAWR_INIT(ISAPNP_MBDATA,5)
488         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
489         ISAWR_INIT(ISAPNP_MBDATA,1)
491         /* select logical device 6 (COM1) */
492         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
493         ISAWR_INIT(ISAPNP_MBDATA,6)
494         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
495         ISAWR_INIT(ISAPNP_MBDATA,1)
496 #endif                                                                       
498                                                                         
499         EXIT_INIT(0)
501 #define Init_Op 0
502 #define Init_A0 4
503 #define Init_A1 8
504 #define Init_A2 12
505 #define Init_Size       16
507 1:      move a0,ra
508 reginit:                        /* local name */
509         lw      t3, Init_Op(a0)
510         lw      t0, Init_A0(a0)
511         and     t4,t3,OP_MASK
512         
513         
514         /* 
515          * EXIT(STATUS) 
516          */
517         bne     t4, OP_EXIT, 8f
518         nop
519         move    v0,t0
520         b       .done
521         nop
522         
523         /* 
524          * DELAY(CYCLES) 
525          */
526 8:      bne     t4, OP_DELAY, 8f
527         nop
528 1:      bnez    t0,1b
529         subu    t0,1
530         b       .next
531         nop     
532         /* 
533          * READ(ADDR) 
534          */
535 8:      bne     t4,OP_RD,8f
536         nop
537         and     t4,t3,MOD_MASK
538         
539         bne     t4,MOD_B,1f
540         nop
541         lbu     t5,0(t0)
542         b       .next
543         nop
544 1:      bne     t4,MOD_H,1f
545         nop
546         lhu     t5,0(t0)
547         b       .next
548         nop
549 1:      bne     t4,MOD_W,1f
550         nop
551 #if __mips64
552         lwu     t5,0(t0)
553 #else 
554         lw      t5,0(t0)
555 #endif
556         b       .next
557         nop
558 1:      
559 #if __mips64
560         lw      t5,0(t0)
561         b       .next
562         nop
563 #else
564         b       .fatal
565         nop
566 #endif
567         
568         /* 
569          * WRITE(ADDR,VAL) 
570          */
571 8:      bne     t4,OP_WR,8f
572         nop
573         lw      t1,Init_A1(a0)
574         and     t4,t3,MOD_MASK
575         
576         bne     t4,MOD_B,1f
577         nop
578         sb      t1,0(t0)
579         b       .next
580         nop
581 1:      bne     t4,MOD_H,1f
582         nop
583         sh      t1,0(t0)
584         b       .next
585         nop
586 1:      bne     t4,MOD_W,1f
587         nop
588         sw      t1,0(t0)
589         b       .next
590         nop
591         
592 1:      
593 #if __mips64
594         sd      t1,0(t0)
595         b       .next
596         nop
597 #else
598         b       .fatal
599         nop
600 #endif
601                 
602         
603         /* 
604          * RMW(ADDR,AND,OR) 
605          */
606 8:      bne     t4,OP_RMW,8f
607         nop
608         lw      t1,Init_A1(a0)
609         lw      t2,Init_A2(a0)
610         and     t4,t3,MOD_MASK
611         
612         bne     t4,MOD_B,1f
613         nop
614         lbu     t4,0(t0)
615         and     t4,t1
616         or      t4,t2
617         sb      t4,0(t0)
618         b       .next
619         nop
620 1:      bne     t4,MOD_H,1f
621         nop
622         lhu     t4,0(t0)
623         and     t4,t1
624         or      t4,t2
625         sh      t4,0(t0)
626         b       .next
627         nop
628 1:      bne     t4,MOD_W,1f
629         nop
630         lw      t4,0(t0)
631         and     t4,t1
632         or      t4,t2
633         sw      t4,0(t0)
634         b       .next
635         nop
636         
637 1:              
638 #if __mips64
639         ld      t4,0(t0)
640         and     t4,t1
641         or      t4,t2
642         sd      t4,0(t0)
643         b       .next
644         nop
645 #else   
646         b       .fatal
647         nop
648 #endif
649                 
650         
651         /* 
652          * WAIT(ADDR,MASK,VAL) 
653          */
654 8:      bne     t4,OP_WAIT,8f
655         nop
656         lw      t1,Init_A1(a0)
657         lw      t2,Init_A2(a0)
658         and     t4,t3,MOD_MASK
659         
660         bne     t4,MOD_B,1f
661         nop
662 3:      lbu     t4,0(t0)
663         and     t4,t1
664         bne     t4,t2,3b
665         nop
666         b       .next
667         nop
668 1:      bne     t4,MOD_H,1f
669         nop
670 3:      lhu     t4,0(t0)
671         and     t4,t1
672         bne     t4,t2,3b
673         nop
674         b       .next
675         nop
676 1:      bne     t4,MOD_W,1f
677         nop
678 3:      lw      t4,0(t0)
679         and     t4,t1
680         bne     t4,t2,3b
681         nop
682         b       .next
683         nop
684 1:              
685 #if __mips64
686 3:      ld      t4,0(t0)
687         and     t4,t1
688         bne     t4,t2,3b
689         nop
690         b       .next
691         nop
692 #else   
693         b       .fatal  
694         nop
695 #endif
696         
697         
698 .next:  addu    a0,Init_Size
699         b       reginit 
700         nop     
701         
703 .fatal: b .done
704         nop
705         bal     stuck
706         nop
707 .done:  
708         /* Initialise other low-level I/O devices */
710         bal     initserial
711         nop
712         
714         PRINTSTR("\r\nPMON2000 MIPS Initializing. Standby...\r\n")
715         
717         PRINTSTR("ERRORPC=")
718         mfc0    a0, COP_0_ERROR_PC
719         bal     hexserial
720         nop
722         PRINTSTR(" CONFIG=")
723         mfc0    a0, COP_0_CONFIG
724         bal     hexserial
725         nop
726         PRINTSTR("\r\n")
727         
728         PRINTSTR(" PRID=")
729         mfc0    a0, COP_0_PRID
730         bal     hexserial
731         nop
732         PRINTSTR("\r\n")
734         PRINTSTR("Raw word read of SMB base address: ");
735         li      a0,CFGADDR(PCI_DEV_I82371,3,I82371_PCI3_SMBBA)
736         li      a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
737         and     a2,a0,0xffff
738         or      a1,a2
739         srl     a0,16
740         li      a2,BONITO_BASE+BONITO_PCIMAP_CFG
741         sw      a0,BONITO_PCIMAP_CFG(bonito)
742         lw      zero,BONITO_PCIMAP_CFG(bonito)
743         lw      a0,(a1)
744         
745         li      a1,2
746         bal     hexserial
747         nop
748         PRINTSTR("\r\n")        
749         
750         
751 /***(qiaochong) memeory initialization use macro,not smbbus ***/
752                                                          /*bit 31: DDRÅäÖýáÊø±êÖ¾£¬1±íʾ½áÊø£¬Ö»¶Á*/
753 #define DDR_DQS_SELECT  (0<<30)                  /*bit 30 Ñ¡ÔñÊý¾ÝÀ´Ô´£¬0: Ë«ÑزÉÑù£»1£ºDQS²ÉÑù*/
754 #define DDR_DIMM_DIC (1<<29)           /*bit 29 ±êʶDIMM_slot0ÊÇ·ñ²åÓÐÄÚ´æÌõ¡£
755                                 0£ºÎÞ£»1£ºÓУ»*/
756 #define DDR_DIMM_MODULE_NUM (3<<27)    /*bit 28:27 DIMM0/DIMM1ÉÏMOUDLEµÄÊýÄ¿£º
757                                                                 2¡¯b00£ºDIMM1: 1; DIMM0: 1
758                                                                 2¡¯b01£ºDIMM1: 1; DIMM0: 2
759                                                                 2¡¯b10£ºDIMM1: 2; DIMM0: 1
760                                                                 2¡¯b11£ºDIMM1: 2; DIMM0: 2
761                                                                 */
762 #define DDR_IS_SEQ  (1<<26)            /*bit 26 ÒåÍ»·¢Ê½¶ÁдʱµÄ¿éÄÚ˳Ðò£¬
763                                                                 1¡¯b0£ºË³Ðò£»1¡¯b1£º½»Ì棬ÏÖÔÚÖ»Ö§³Ö½»Ì淽ʽ*/
764 #define DDR_TYPE (5<<22) /*bit 25:22 ±í2£ºDDR ¿ØÖÆÆ÷ËùÖ§³ÖµÄDDR SDRAM ¼ÆоƬÀàÐÍ
765                                                                 BITS Density Org.  Row Addr.  Col Addr.
766                                                                 0000 64Mb 16Mb X 4 DA[11:0] DA[9:0]
767                                                                         128Mb 16Mb X 8
768                                                                 0001 64Mb 8Mb X 8 DA[11:0] DA[8:0]
769                                                                         128Mb 8Mb X 16 
770                                                                 0010 64Mb 4Mb X 16 DA[11:0] DA[7:0]
771                                                                 0011 128Mb 32Mb X 4 DA[11:0] DA[11],DA[9:0]
772                                                                 0100 256Mb 64Mb X 4 DA[12:0] DA[11],DA[9:0]
773                                                                          512Mb 64Mb X 8 
774                                                                 0101 256Mb 32Mb X 8 DA[12:0] DA[9:0]
775                                                                          512Mb 32Mb X 16
776                                                                 0110 256Mb 16Mb X 16 DA[12:0] DA[8:0]
777                                                                 0111 512Mb 128Mb X 4 DA[12:0] DA[12:11],DA[9:0]
778                                                                 1000 1Gb 256Mb X 4 DA[13:0] DA[12:11],DA[9:0]
779                                                                 1001 1Gb 128Mb X 8 DA[13:0] DA[11],DA[9:0]
780                                                                 1010 1Gb 64Mb X 16 DA[13:0] DA[9:0]
781                                                                 */
782 #define DDR_tREF  (100<<10) /*bit 21:10 SDRAMˢвÙ×÷Ö®¼ä¼ÆÊý£¨Ö÷Ƶ100MHz£©£º
783                                                                 780      7.8us
784                                                                 1560     15.6us
785                                                                 SDRAMˢвÙ×÷Ö®¼ä¼ÆÊý£¨Ö÷Ƶ133MHz£©£º
786                                                                 1040      7.8us
787                                                                 2080      15.6us
788                                                                 SDRAMˢвÙ×÷Ö®¼ä¼ÆÊý£¨Ö÷Ƶ166MHz£©£º
789                                                                 1300      7.8us
790                                                                 2600      15.6us
791                                                                 */
792 #define DDR_TRCD (0<<9) /*bit 9 ÐеØÖ·ÓÐЧµ½ÁеØÖ·ÓÐЧ֮¼äÐè¾­¹ýµÄ¼ÆÊý
793                                                                 1¡¯b0   2 cycles£¨DDR100£©
794                                                                 1¡¯b1   3 cycles£¨DDR266¡¢DDR333£©*/
795 #define DDR_TRPC (1<<7) /*bit 8:7 AUTO_REFRESHµ½ACTIVEÖ®¼äÐè¾­¹ýµÄ¼ÆÊý
796                                                                 2¡¯b00  Null 
797                                                                 2¡¯b01  8 cylces £¨DDR100£©
798                                                                 2¡¯b10  10 cycles£¨DDR266£©
799                                                                 2¡¯b11  12 cycles£¨DDR333£©
800                                                                 */
801 #define DDR_TRAS (0<<6) /*bit 6 ACTIVEµ½PRECHARGEÖ®¼äÐè¾­¹ýµÄ¼ÆÊý
802                                                                 1¡¯b0   5 cycles£¨DDR100£©
803                                                                 1¡¯b1   7 cycles£¨DDR266¡¢DDR333£©  
804                                                                 */
805 #define DDR_TCAS (1<<4) /*bit 5:4 ´Ó¶ÁÃüÁîµ½µÚÒ»¸öÊý¾Ýµ½À´Ðè¾­¹ýµÄ¼ÆÊý
806                                                                 2¡¯b00  1.5 cycles
807                                                                 2¡¯b01  2 cycles
808                                                                 2¡¯b10  2.5 cycles
809                                                                 2¡¯b11  3 cycles
810                                                                 */
811 #define DDR_TWR (0<<3) /*bit 3 Ð´²Ù×÷×îºóÒ»¸öÊý¾Ýµ½PRECHARGEÖ®¼äÐè¾­¹ýµÄ¼ÆÊý
812                                                                 1¡¯b0   2 cycles£¨DDR100£©
813                                                                 1¡¯b1   3 cycles£¨DDR266¡¢DDR333£©
814                                                                 */
815 #define DDR_TRP (0<<2) /*bit 2 PRECHARGEÃüÁîÖ´ÐÐʱ¼ä¼ÆÊý
816                                                                 1¡¯b0   2 cycles£¨DDR100£©
817                                                                 1¡¯b1   3 cycles£¨DDR266¡¢DDR333£©
818                                                                 */
819 #define DDR_TRC (1<<0) /*bit 1:0 ACTIVEÓëACTIVE/AUTO_REFRESHÃüÁîÖ®¼ä¼ÆÊý
820                                                                 2¡¯b00  Null
821                                                                 2¡¯b01  7 cycles£¨DDR100£©
822                                                                 2¡¯b10  9 cycles£¨DDR266£©
823                                                                 2¡¯b11  10cycles£¨DDR333£©
824                                                                 ×¢£¨ÓÉÓÚprechargeºÍras casµÄÑÓʱ¼ÓÆðÀ´ÕýºÃÂú×ãÕâ¸öÑÓʱ£¬ËùÒÔÔÚDDR¿ØÖÆÆ÷ÀïûÓоßÌ忼ÂÇÕâ¸ö²ÎÊý£©
825                                                                 */
826 #define sdcfg_DATA DDR_DQS_SELECT|DDR_DIMM_DIC|DDR_DIMM_MODULE_NUM|DDR_IS_SEQ|DDR_TYPE|DDR_tREF|DDR_TRCD|DDR_TRPC|DDR_TRAS|DDR_TCAS|DDR_TWR|DDR_TRP|DDR_TRC
827         li  msize,512*(1<<20)
828         li  sdCfg,sdcfg_DATA
829 #       li sdCfg,0x05441091
830         sw      sdCfg,BONITO_SDCFG(bonito)
831 #if 1//def DBGSBD
832         PRINTSTR("sdcfg=");
833         move    a0,sdCfg
834         bal     hexserial
835         nop
836         PRINTSTR("\r\n");
837         PRINTSTR("msize=");
838         move    a0,msize
839         sw      a0,BONITO_MEMSIZE(bonito)
840         bal     hexserial
841         nop
842         PRINTSTR("\r\n")
843         li      msize,0x10000000        # only 256m allowed in pmon now 
844 #endif
845         li      t1,0            # accumulate pcimembasecfg settings
846                 
847         /* set bar0 mask and translation to point to SDRAM */
848         sub     t0,msize,1
849         not     t0
850         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_MASK_SHIFT
851         and     t0,BONITO_PCIMEMBASECFG_MEMBASE0_MASK
852         or      t1,t0
853         
854         li      t0,0x00000000
855         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_TRANS_SHIFT
856         and     t0,BONITO_PCIMEMBASECFG_MEMBASE0_TRANS
857         or      t1,t0
858         or      t1,BONITO_PCIMEMBASECFG_MEMBASE0_CACHED
860         /* set bar1 to minimum size to conserve PCI space */
861         li      t0, ~0
862         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_MASK_SHIFT
863         and     t0,BONITO_PCIMEMBASECFG_MEMBASE1_MASK
864         or      t1,t0
865         
866         li      t0,0x00000000
867         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_TRANS_SHIFT
868         and     t0,BONITO_PCIMEMBASECFG_MEMBASE1_TRANS
869         or      t1,t0
870         or      t1,BONITO_PCIMEMBASECFG_MEMBASE1_CACHED
872         sw      t1,BONITO_PCIMEMBASECFG(bonito)
874         /* enable configuration cycles now */
875         lw      t0,BONITO_BONPONCFG(bonito)
876         and     t0,~BONITO_BONPONCFG_CONFIG_DIS
877         sw      t0,BONITO_BONPONCFG(bonito)
879         PRINTSTR("Init SDRAM Done!\r\n");
882  *  Reset and initialize caches to a known state.
883  */
884 #define IndexStoreTagI  0x08
885 #define IndexStoreTagD  0x09
886 #define IndexStoreTagS  0x0b
887 #define IndexStoreTagT  0x0a
888 #define FillI           0x14
891  *  RM7000 config register bits.
892  */
893 #define CF_7_SE         (1 << 3)        /* Secondary cache enable */
894 #define CF_7_SC         (1 << 31)       /* Secondary cache not present */
895 #define CF_7_TE         (1 << 12)       /* Tertiary cache enable */
896 #define CF_7_TC         (1 << 17)       /* Tertiary cache not present */
897 #define CF_7_TS         (3 << 20)       /* Tertiary cache size */
898 #define CF_7_TS_AL      20              /* Shift to align */
899 #define NOP8 nop;nop;nop;nop;nop;nop;nop;nop
900 do_caches:
901         TTYDBG("Sizing caches...\r\n");
902 /* godson2 */
903         mfc0    a0, COP_0_PRID
904         andi    a0, a0, 0xff00
905         li      a1, 0x6300
906         bne     a0, a1, cache_done
907         nop
908         TTYDBG("godson2 caches found\r\n")
909         bal     godson2_cache_init
910         nop
911 cache_done:
913 #ifdef DEBUG_LOCORE
914         TTYDBG("Init caches done, cfg = ")
915         mfc0    a0, COP_0_CONFIG
916         bal     hexserial
917         nop
918         TTYDBG("\r\n")
919 #endif
921 #if 1 //ʹÄÜcache
922         mfc0   a0,COP_0_CONFIG
923         and    a0,a0,0xfffffff8
924         or     a0,a0,0x3
925         mtc0   a0,COP_0_CONFIG
926 #endif
928 //#include "testmem0.S"
929         TTYDBG("Copy PMON to execute location...\r\n")
930 #include "copypmon.S"
931         TTYDBG("Copy PMON to execute location done.\r\n")
932 //#include "test_after_copy.S"
935         li      a0, 0
936         sw      a0, CpuTertiaryCacheSize /* Set L3 cache size */
937         move    a0,msize
938         srl     a0,20
940         la      v0, initmips
941         jalr    v0
942         nop
943 stuck:
944 #ifdef DEBUG_LOCORE
945         TTYDBG("Dumping GT64240 setup.\r\n")
946         TTYDBG("offset----data------------------------.\r\n")
947         li      s3, 0
949         move    a0, s3
950         bal     hexserial
951         nop
952         TTYDBG(": ")
954         add     a0, s3, bonito
955         lw      a0, 0(a0)
956         bal     hexserial
957         addiu   s3, 4
958         TTYDBG(" ")
959         li      a0, 0xfff
960         and     a0, s3
961         beqz    a0, 3f
962         li      a0, 0x01f
963         and     a0, s3
964         bnez    a0, 2b
965         TTYDBG("\r\n")
966         b       1b
967         nop
969         b       3b
970         nop
972 #else
973         b       stuck
974         nop
975 #endif
977  *  Clear the TLB. Normally called from start.S.
978  */
979 #if __mips64
980 #define MTC0 dmtc0
981 #else 
982 #define MTC0 mtc0
983 #endif
984 LEAF(CPU_TLBClear)
985         li      a3, 0                   # First TLB index.
987         li      a2, PG_SIZE_4K
988         MTC0   a2, COP_0_TLB_PG_MASK   # Whatever...
991         MTC0   zero, COP_0_TLB_HI       # Clear entry high.
992         MTC0   zero, COP_0_TLB_LO0      # Clear entry low0.
993         MTC0   zero, COP_0_TLB_LO1      # Clear entry low1.
995         mtc0    a3, COP_0_TLB_INDEX     # Set the index.
996         addiu   a3, 1
997         li      a2, 64
998         nop
999         nop
1000         tlbwi                           # Write the TLB
1002         bne     a3, a2, 1b
1003         nop
1005         jr      ra
1006         nop
1007 END(CPU_TLBClear)
1010  *  Set up the TLB. Normally called from start.S.
1011  */
1012 LEAF(CPU_TLBInit)
1013         li      a3, 0                   # First TLB index.
1015         li      a2, PG_SIZE_16M
1016         MTC0   a2, COP_0_TLB_PG_MASK   # All pages are 16Mb.
1019         and     a2, a0, PG_SVPN
1020         MTC0   a2, COP_0_TLB_HI # Set up entry high.
1022         move    a2, a0
1023         srl     a2, a0, PG_SHIFT 
1024         and     a2, a2, PG_FRAME
1025         ori     a2, PG_IOPAGE
1026         MTC0   a2, COP_0_TLB_LO0        # Set up entry low0.
1027         addu    a2, (0x01000000 >> PG_SHIFT)
1028         MTC0   a2, COP_0_TLB_LO1        # Set up entry low1.
1030         mtc0    a3, COP_0_TLB_INDEX     # Set the index.
1031         addiu   a3, 1
1032         li      a2, 0x02000000
1033         subu    a1, a2
1034         nop
1035         tlbwi                           # Write the TLB
1037         bgtz    a1, 1b
1038         addu    a0, a2                  # Step address 32Mb.
1040         jr      ra
1041         nop
1042 END(CPU_TLBInit)
1045  * Simple character printing routine used before full initialization
1046  */
1048 LEAF(stringserial)
1049         move    a2, ra
1050         addu    a1, a0, s0
1051         lbu     a0, 0(a1)
1053         beqz    a0, 2f
1054         nop
1055         bal     tgt_putchar
1056         addiu   a1, 1
1057         b       1b
1058         lbu     a0, 0(a1)
1061         j       a2
1062         nop
1063 END(stringserial)
1064 LEAF(outstring)
1065         move    a2, ra
1066         move    a1, a0
1067         lbu     a0, 0(a1)
1069         beqz    a0, 2f
1070         nop
1071         bal     tgt_putchar
1072         addiu   a1, 1
1073         b       1b
1074         lbu     a0, 0(a1)
1077         j       a2
1078         nop
1079 END(outstring)
1080 LEAF(hexserial)
1081         move    a2, ra
1082         move    a1, a0
1083         li      a3, 7
1085         rol     a0, a1, 4
1086         move    a1, a0
1087         and     a0, 0xf
1088         la      v0, hexchar
1089         addu    v0, s0
1090         addu    v0, a0
1091         bal     tgt_putchar
1092         lbu     a0, 0(v0)
1094         bnez    a3, 1b
1095         addu    a3, -1
1097         j       a2
1098         nop
1099 END(hexserial)
1100 LEAF(tgt_putchar)
1101 #       la      v0, COM1_BASE_ADDR
1102         la      v0, COM3_BASE_ADDR
1104         lbu     v1, NSREG(NS16550_LSR)(v0)
1105         and     v1, LSR_TXRDY
1106         beqz    v1, 1b
1107         nop
1109         sb      a0, NSREG(NS16550_DATA)(v0)
1110         
1111         move    v1, v0
1112         la      v0, COM1_BASE_ADDR
1113 #       bne     v0, v1, 1b
1114         nop
1116         j       ra
1117         nop     
1118 END(tgt_putchar)
1119 /* baud rate definitions, matching include/termios.h */
1120 #define B0      0
1121 #define B50     50      
1122 #define B75     75
1123 #define B110    110
1124 #define B134    134
1125 #define B150    150
1126 #define B200    200
1127 #define B300    300
1128 #define B600    600
1129 #define B1200   1200
1130 #define B1800   1800
1131 #define B2400   2400
1132 #define B4800   4800
1133 #define B9600   9600
1134 #define B19200  19200
1135 #define B38400  38400
1136 #define B57600  57600
1137 #define B115200 115200
1139 LEAF(initserial)
1140 #       la      v0, COM1_BASE_ADDR
1141         la      v0, COM3_BASE_ADDR
1143         li      v1, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4
1144         sb      v1, NSREG(NS16550_FIFO)(v0)
1145         li      v1, CFCR_DLAB
1146         sb      v1, NSREG(NS16550_CFCR)(v0)
1147         li      v1, NS16550HZ/(16*CONS_BAUD)
1148         sb      v1, NSREG(NS16550_DATA)(v0)
1149         srl     v1, 8
1150         sb      v1, NSREG(NS16550_IER)(v0)
1151         li      v1, CFCR_8BITS
1152         sb      v1, NSREG(NS16550_CFCR)(v0)
1153         li      v1, MCR_DTR|MCR_RTS
1154         sb      v1, NSREG(NS16550_MCR)(v0)
1155         li      v1, 0x0
1156         sb      v1, NSREG(NS16550_IER)(v0)
1158         move    v1, v0
1159         la      v0, COM1_BASE_ADDR
1160 #       bne     v0, v1, 1b /*qiaochong notice*/
1161         nop
1163         j       ra
1164         nop
1165 END(initserial)
1167 #define SMBOFFS(reg) I82371_SMB_SMB##reg
1169 LEAF(i2cdump)
1170         move    t4,ra
1171         
1172         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1173         lbu     a0,SMBOFFS(HSTSTS)(a0)
1174         li      a1,1
1175         bal     hexserial
1176         nop
1177         PRINTSTR("\r\n")
1178                 
1179         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1180         lbu     a0,SMBOFFS(SLVSTS)(a0)
1181         li      a1,1
1182         bal     hexserial
1183         nop
1184         PRINTSTR("\r\n")
1185         
1186         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1187         lbu     a0,SMBOFFS(HSTCNT)(a0)
1188         li      a1,1
1189         bal     hexserial
1190         nop
1191         PRINTSTR("\r\n")
1192         
1193         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1194         lbu     a0,SMBOFFS(HSTCMD)(a0)
1195         li      a1,1
1196         bal     hexserial
1197         nop
1198         PRINTSTR("\r\n")
1199         
1200         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1201         lbu     a0,SMBOFFS(HSTADD)(a0)
1202         li      a1,1
1203         bal     hexserial
1204         nop
1205         PRINTSTR("\r\n")
1206         
1207         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1208         lbu     a0,SMBOFFS(HSTDAT0)(a0)
1209         li      a1,1
1210         bal     hexserial
1211         nop
1212         PRINTSTR("\r\n")
1213         
1214         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1215         lbu     a0,SMBOFFS(HSTDAT1)(a0)
1216         li      a1,1
1217         bal     hexserial
1218         nop
1219         PRINTSTR("\r\n")
1220         
1221         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1222         lbu     a0,SMBOFFS(BLKDAT)(a0)
1223         li      a1,1
1224         bal     hexserial
1225         nop
1226         PRINTSTR("\r\n")
1227         
1228         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1229         lbu     a0,SMBOFFS(SLVCNT)(a0)
1230         li      a1,1
1231         bal     hexserial
1232         nop
1233         PRINTSTR("\r\n")
1234         
1235         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1236         lbu     a0,SMBOFFS(SHDWCMD)(a0)
1237         li      a1,1
1238         bal     hexserial
1239         nop
1240         PRINTSTR("\r\n")
1241         
1242         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1243         lbu     a0,SMBOFFS(SLVEVT)(a0)
1244         li      a1,1
1245         bal     hexserial
1246         nop
1247         PRINTSTR("\r\n")
1248         
1249         li      a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1250         lbu     a0,SMBOFFS(SLVDAT)(a0)
1251         li      a1,1
1252         bal     hexserial
1253         nop
1254         PRINTSTR("\r\n")
1255         
1256         jr      t4
1257         nop
1258 END(i2cdump)
1262 LEAF(i2cread)
1263         li      t0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1265         lbu     t1,SMBOFFS(HSTSTS)(t0)
1266         and     t1,~(I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER)
1267         sb      t1,SMBOFFS(HSTSTS)(t0)
1268         
1269         sll     t1,a0,1
1270         or      t1,0xa1         # DIMM base address and read bit
1271         sb      t1,SMBOFFS(HSTADD)(t0)
1272         sb      a1,SMBOFFS(HSTCMD)(t0)
1273         
1274         
1275         li      t1,I82371_SMB_START|I82371_SMB_BDRW
1276         sb      t1,SMBOFFS(HSTCNT)(t0)
1278         li      t3,10000        
1279 1:      lbu     t1,SMBOFFS(HSTSTS)(t0)
1280         and     t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER
1281         bnez    t2,1f
1282         nop
1283         sub     t3,1
1284         bnez    t3,1b
1285         nop
1286         b       9f              
1287         nop
1288 1:      
1289         # clear pending errors/interrupts
1290         sb      t1,SMBOFFS(HSTSTS)(t0)
1291         
1292         and     t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR
1293         bnez    t2,9f
1294         nop
1295         lbu     v0,SMBOFFS(HSTDAT0)(t0)
1296         j       ra
1297         nop
1298         
1299 9:      li      v0,-1
1300         j       ra
1301         nop
1302 END(i2cread)    
1304 __main:
1305         j       ra
1306         nop
1309         .rdata
1310 transmit_pat_msg:
1311         .asciz  "\r\nInvalid transmit pattern.  Must be DDDD or DDxDDx\r\n"
1312 v200_msg:
1313         .asciz  "\r\nPANIC! Unexpected TLB refill exception!\r\n"
1314 v280_msg:
1315         .asciz  "\r\nPANIC! Unexpected XTLB refill exception!\r\n"
1316 v380_msg:
1317         .asciz  "\r\nPANIC! Unexpected General exception!\r\n"
1318 v400_msg:
1319         .asciz  "\r\nPANIC! Unexpected Interrupt exception!\r\n"
1320 hexchar:
1321         .ascii  "0123456789abcdef"
1323         .text
1324         .align  2
1326  *   I2C Functions used in early startup code to get SPD info from
1327  *   SDRAM modules. This code must be entirely PIC and RAM independent.
1328  */
1330 /* Delay macro */
1331 #define DELAY(count)    \
1332         li v0, count;   \
1333 99:                     \
1334         bnz     vo, 99b;\
1335         addiu   v0, -1
1338 #define I2C_INT_ENABLE  0x80
1339 #define I2C_ENABLE      0x40
1340 #define I2C_ACK         0x04
1341 #define I2C_INT_FLAG    0x08
1342 #define I2C_STOP_BIT    0x10
1343 #define I2C_START_BIT   0x20
1345 #define I2C_AMOD_RD     0x01
1347 #define BUS_ERROR                               0x00
1348 #define START_CONDITION_TRA                     0x08
1349 #define RSTART_CONDITION_TRA                    0x10
1350 #define ADDR_AND_WRITE_BIT_TRA_ACK_REC          0x18
1351 #define ADDR_AND_READ_BIT_TRA_ACK_REC           0x40
1352 #define SLAVE_REC_WRITE_DATA_ACK_TRA            0x28
1353 #define MAS_REC_READ_DATA_ACK_NOT_TRA           0x58
1355 #define Index_Store_Tag_D                       0x05
1356 #define Index_Invalidate_I                      0x00
1357 #define Index_Writeback_Inv_D                   0x01
1359 LEAF(nullfunction)
1360         jr ra
1361         nop
1362 END(nullfunction)
1364 LEAF(godson2_cache_init)
1365 ####part 2####
1366 cache_detect_size_way:
1367         mfc0    t4, CP0_CONFIG
1368         andi    t5, t4, 0x0e00
1369         srl     t5, t5, 9
1370         andi    t6, t4, 0x01c0
1371         srl     t6, t6, 6
1372         addiu   t6, t6, 11
1373         addiu   t5, t5, 11
1374         addiu   t4, $0, 1
1375         sllv    t6, t4, t6
1376         sllv    t5, t4, t5
1378         mfc0    t7, COP_0_PRID
1379         andi    t7, t7, 1
1380         srlv    t6, t6, t7              /* 4way */
1381         srlv    t5, t5, t7
1383 ####part 3####
1384         lui     a0, 0x8000
1385         addu    a1, $0, t5
1386         addu    a2, $0, t6
1387 cache_init_dway:
1388 #a0=0x80000000, a1=icache_size, a2=dcache_size
1389 #a3, v0 and v1 used as local registers
1390         mtc0    $0, CP0_TAGHI
1391         addu    v0, $0, a0
1392         addu    v1, a0, a2
1393 1:      slt     a3, v0, v1
1394         beq     a3, $0, 1f
1395         nop
1396         mtc0    $0, CP0_TAGLO
1397         cache   Index_Store_Tag_D, 0x0(v0)
1398         cache   Index_Store_Tag_D, 0x1(v0)
1399         beqzl   t7, 1b
1400         addiu   v0, v0, 0x20
1401 /* godson2c 4way */
1402         cache   Index_Store_Tag_D, 0x2(v0)
1403         cache   Index_Store_Tag_D, 0x3(v0)
1404 /* godson2c 4way */
1405         beq     $0, $0, 1b
1406         addiu   v0, v0, 0x20
1408 cache_flush_iway:
1409         addu    v0, $0, a0
1410         addu    v1, a0, a1
1411 1:      slt     a3, v0, v1
1412         beq     a3, $0, 1f
1413         nop
1414         cache   Index_Invalidate_I, 0x0(v0)
1415         beq     $0, $0, 1b
1416         addiu   v0, v0, 0x20
1418 cache_flush_dway:
1419         addu    v0, $0, a0
1420         addu    v1, a0, a2
1421 1:      slt     a3, v0, v1
1422         beq     a3, $0, 1f
1423         nop
1424         cache   Index_Writeback_Inv_D, 0x0(v0)
1425         cache   Index_Writeback_Inv_D, 0x1(v0)
1426         beqzl   t7, 1b
1427         addiu   v0, v0, 0x20
1428 /* godson2c 4way */
1429         cache   Index_Writeback_Inv_D, 0x2(v0)
1430         cache   Index_Writeback_Inv_D, 0x3(v0)
1431 /* godson2c 4way */
1432         beq     $0, $0, 1b
1433         addiu   v0, v0, 0x20
1435 cache_init_finish:
1436         nop
1437         jr      ra
1438         nop
1440 cache_init_panic:
1441         TTYDBG("cache init panic\r\n");
1442 1:      b       1b
1443         nop
1444         .end    godson2_cache_init