crt0.S
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:9k
源码类别:

DVD

开发平台:

C/C++

  1. //
  2. // FILE
  3. // crt0.S
  4. // 
  5. // DESCRIPTION
  6. // initialize system and jump to C program
  7. //
  8. #include "regdef.h"
  9. #include "gpio.h"
  10. #include "config.h"
  11. #include "regmapa.h"
  12. #include "user_init.h"
  13. #define PROBE_SDRAM
  14. #define CLEAR_STACK
  15. //#define SDRAM_DBG
  16. //#define BOOTSTRAP_STAMP
  17. //#define BOOTSTRAP_SETUP_UART
  18. //#define BOOTSTRAP_WRITE_UART
  19. #define STATUS_ENDIAN_LITTLE    (0<<25)
  20. #define STATUS_SETUP            STATUS_COP0|STATUS_ENDIAN_LITTLE|STATUS_BEV
  21.                                 // | STATUS_COP3        
  22.                                 // | STATUS_BEV         
  23.                                 // | STATUS_ENDIAN_BIG
  24. //
  25. // Debug
  26. // terry,2005/1/31 09:56AM
  27. #ifdef SDRAM_DBG
  28. #define BOOTSTRAP_SETUP_UART
  29. #define BOOTSTRAP_WRITE_UART
  30. #endif
  31. //
  32. // HWCFG
  33. //
  34. #ifdef  SPHE8202
  35. #ifdef  SPHE8202_NONSHARED
  36. #ifdef  SDRAM_BUS_32BITS
  37. #define HWCFG_SET   0x3f       // 32-bit SDRAM 8-bit ROM mode f (non-shared)
  38. #else
  39. #define HWCFG_SET   0x1f       // 16-bit SDRAM 8-bit ROM mode f (non-shared)
  40. #endif
  41. #else
  42. #ifdef  SDRAM_BUS_32BITS
  43. #define HWCFG_SET   0x31       // 32-bit SDRAM 8-bit ROM mode 1 (shared)
  44. #else
  45. #define HWCFG_SET   0x11       // 16-bit SDRAM 8-bit ROM mode 1 (shared)
  46. #endif
  47. #endif
  48. #else
  49. // ORIGINAL 8200
  50. #ifdef  SDRAM_BUS_32BITS
  51. #define HWCFG_SET   1          // hw config fig.1 MPEG+servo+32b
  52. #else
  53. #define HWCFG_SET   2          // hw config fig.2 MPEG+servo+16b
  54. #endif
  55. #endif
  56. //
  57. // STAMPS
  58. //
  59. #define STAMP_STARTUP           (0<<8)
  60. #define STAMP_SDRAM_MRS         (1<<8)
  61. #define STAMP_SDRAM_PROBE       (2<<8)
  62. #define STAMP_SDRAM_PROBE_ERROR (STAMP_SDRAM_PROBE|0xf0)
  63. #define STAMP_CLEAR_STACK       (5<<8)
  64. #define STAMP_SETUP_GP          (6<<8)
  65. #define STAMP_ROMINIT           (7<<8)
  66. #define STAMP_MAIN              (9<<8)
  67. #ifdef BOOTSRAP_STAMP
  68. #define WRITESTAMP(n) 
  69.         .set noat; 
  70.         li AT,(n); 
  71.         sw AT,RF_STAMP(s6); 
  72.         .set at
  73. #else
  74. #define WRITESTAMP(n)
  75. #endif
  76. #define WAIT(n)     
  77.         .set noat; li AT,(n); 100: addiu AT,-1; bnez AT,100b; .set at
  78. #define TX_EMPTY    (1<<6)
  79. #define WAITUART()  
  80.         .set noat; 100: lw AT,RF_UART0_LSR(s6); andi AT,TX_EMPTY; beqz AT,100b; .set at
  81. #define PUTC(c)     
  82.         WAITUART(); 
  83.         .set noat; li AT,(c); sw AT,RF_UART0_DATA(s6); .set at
  84. #define PUTCR(c)     
  85.         WAITUART(); 
  86.         sw c,RF_UART0_DATA(s6)
  87. // PUTA0_0
  88. // write v0(v1) to UART (v1 should be radix-table)
  89. #define PUTA0_0 
  90.         andi v1,0x0f; add v1,v0; lbu v1,(v1); PUTCR(v1)
  91. // PUTA0
  92. // write a0 to UART
  93.         .extern radix_table
  94. #define PUTA0  
  95.         la  v0,radix_table;     
  96.         srl v1,a0,28; PUTA0_0; 
  97.         srl v1,a0,24; PUTA0_0; 
  98.         srl v1,a0,20; PUTA0_0; 
  99.         srl v1,a0,16; PUTA0_0; 
  100.         srl v1,a0,12; PUTA0_0; 
  101.         srl v1,a0,8; PUTA0_0;  
  102.         srl v1,a0,4; PUTA0_0;  
  103.         srl v1,a0,0; PUTA0_0;  
  104.         PUTC(0x0d); PUTC(0x0a)
  105.                 .text
  106.                 .global     start
  107.                 .global     __main
  108.                 .global     s_gp
  109.                 .global     set_sdram_timing
  110.                 .global     set_sdram_timing_low
  111.                 .extern     _stkbtm
  112.                 .rdata    
  113. s_gp:           .word    _gp
  114. s_rominit:      .word    rominit
  115.                 .text
  116. #ifdef SPHE1000
  117. //
  118. // Definition for sunplus's processors
  119. //
  120. #define PRID_SUNPLUS_LX4189 (0x9B407286)
  121. #define PRID_SUNPLUS_MIPZ (0x97350120)
  122. //
  123. // void start_4189
  124. //
  125. .ent start_4189
  126. start_4189:
  127. li s0, 0x10101010
  128. bne t8, s0, start_4189
  129. jr t9
  130. .end start_4189
  131. #endif
  132. //
  133. // void start(void)
  134. //
  135. // *no-return*
  136. //
  137.                 .ent     start
  138. start:
  139.                 // ENABLE COP0/3
  140.                 mfc0    t1, C0_STATUS
  141.                 li      t0, STATUS_SETUP
  142.                 mtc0    t0, C0_STATUS
  143.                 nop
  144.                 nop
  145.                 
  146.                 // setup register-file pointer
  147.                 li      s6, RGST_OFFSET
  148.                 //
  149.                 // Setup hardware configuration
  150.                 //
  151. #ifdef SPHE1000
  152.                 mfc0 t1, C0_PRID
  153.                 li      t2, PRID_SUNPLUS_LX4189
  154.                 beq     t1, t2, start_4189
  155.                 // write HWCFG
  156.                 lw      a0, RF_HW_CFG(s6)
  157.                 ori     a0, a0, (0x8000)
  158.                 sw      a0, RF_HW_CFG_CHG(s6)
  159. 1:              lw      t2, RF_HW_CFG_CHG(s6)           // wait update HWCFG
  160.                 andi    t2, (1<<11)
  161.                 bnez    t2, 1b
  162. #else
  163.                 // write HWCFG
  164.                 li      t1, ('X'<<8)|HWCFG_SET
  165.                 sw      t1, RF_HW_CFG_CHG(s6)           // write HWCFG
  166. 1:              lw      t2, RF_HW_CFG_CHG(s6)           // wait update HWCFG
  167.                 andi    t2, (1<<11)
  168.                 bnez    t2, 1b
  169. #ifdef  BOOT_HALF
  170.                 // change sysclk back to 114.75*2
  171.                 li      t1, 4
  172.                 li      t2, 2
  173.                 sw      t1, RF_SYSCLK_DIV_SEL(s6)
  174.                 sw      t2, RF_SYSCLK_SEL(s6)
  175.                 li      t3, 1000
  176. 1:              addiu   t3, -1
  177.                 bnez    t3, 1b
  178.                 sw      zero, RF_SYSCLK_DIV_SEL(s6)     // (2,0) (229.5, 114.75*2)
  179. #else
  180.                 // change sysclk back to 108mhz
  181.                 li      t1, 4
  182.                 li      t2, 1
  183.                 sw      t1, RF_SYSCLK_DIV_SEL(s6)
  184.                 sw      t2, RF_SYSCLK_SEL(s6)
  185.                 li      t3, 1000
  186. 1:              addiu   t3, -1
  187.                 bnez    t3, 1b
  188.                 sw      zero, RF_SYSCLK_DIV_SEL(s6)     // (1,0)
  189. #endif
  190. #endif
  191.                 // reset sub-systems
  192.                 li      t1, 0xffe0
  193.                 li      t2, 0xffff
  194.                 sw      t1, RF_RESET(s6)                // reset #1 
  195.                 sw      t2, RF_RESET2(s6)               // reset #2
  196.                 sw      zero, RF_RESET(s6)              // freerun #1
  197.                 sw      zero, RF_RESET2(s6)             // freerun #2
  198.                 nop; nop; nop; nop;                     // must delay??
  199.                 WRITESTAMP(STAMP_STARTUP)
  200. #if 0
  201.                 li      t1, ROM_CFG_VAL
  202.                 sw      t1, ROM_CONFIG(s6)
  203. #endif
  204. #ifdef  BOOTSTRAP_SETUP_UART
  205.                 // init uart
  206.                 li      t1, 0
  207.                 li      t2, 58                          // 115200@108MHz
  208.                 sw      t1, RF_UART0_DIV_H(s6)
  209.                 sw      t2, RF_UART0_DIV_L(s6)
  210.                 sw      t1, RF_UART1_DIV_H(s6)
  211.                 sw      t2, RF_UART1_DIV_L(s6)
  212. #endif
  213. #ifdef  BOOTSTRAP_WRITE_UART
  214.                 PUTC('T'); PUTC('S'); PUTC('T');
  215.                 lw a0,RF_HW_CFG(s6); PUTA0
  216.                 PUTC(0x0d); PUTC(0x0a)
  217. #endif
  218.                 //
  219.                 // Setup SDRAM controller
  220.                 //
  221.                 // setup SDRAM interface timing
  222.                 move    a0, zero
  223.                 jal     set_sdram_timing
  224.                 // setup SDRAM controller
  225.                 jal     setup_sdctrl
  226.                 // probe external SDRAM type
  227.                 WRITESTAMP(STAMP_SDRAM_PROBE)
  228.                 jal     probe_sdram_type
  229.                 // reset STK buffer 
  230.                 WRITESTAMP(STAMP_CLEAR_STACK)
  231.                 la      sp, _stkptr                     // set up stack pointer
  232. #ifdef CLEAR_STACK
  233.                 la      t0, _stkbtm        
  234.                 lui     v0, 0xfade
  235.                 ori     v0, 0xfade
  236. 1:              sw      v0, 0(t0)                        // writing initial value
  237.                 addiu   t0, 4
  238.                 bne     t0, sp, 1b
  239. #endif
  240.                 // setup others variables.
  241.                 WRITESTAMP(STAMP_SETUP_GP)
  242.                 lw      gp, s_gp                        // set up GP
  243.                 // setup
  244.                 WRITESTAMP(STAMP_ROMINIT)
  245.                 lw      t0, s_rominit                    // init ROM image of data section
  246.                 jalr    t0
  247.                 // setup others
  248.                 jal     setup_systems
  249.                 WRITESTAMP(STAMP_MAIN)
  250. #ifdef  BOOTSTRAP_WRITE_UART
  251.                 PUTC('A'); PUTC(0x0d); PUTC(0x0a)
  252. #endif
  253. #ifdef  BOOTSTRAP_TEST_SDRAM
  254.                 .extern test_sdram
  255.                 j       test_sdram
  256. #endif
  257.                 j       dvd_main                        // jump to main routine
  258.                 .end    start
  259. //
  260.                 .ent    setup_systems
  261. setup_systems:
  262.                 jr      ra
  263.                 .end    setup_systems
  264. //
  265. // INCLUDE "sdctrl.inc"
  266. // SDRAM related routines
  267. //
  268. #include "sdctrl.inc"
  269. //
  270. // __main
  271. //
  272.                 .ent    __main
  273. __main:
  274.                 lw    gp, s_gp
  275.                 jr    ra
  276.                 .end    __main