start_gcc.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /****************************************************************
  2. KPIT Cummins Infosystems Ltd, Pune, India.
  3. This program is distributed in the hope that it will be useful,
  4. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  6. *****************************************************************/
  7. /* Start-up code for M16C targets only */
  8. .text
  9. .global _start
  10. .type _start, @function
  11. _start:
  12. ldc #_istack, isp /* set interrupt stack pointer */
  13. #ifndef EXT_RAM
  14. mov.b #0x02,0x0a /* write enable in protect register */
  15. mov.b #0x00,0x04 /* set processer mode :single chip mode */
  16. /* 0x04 is the address of processor mode register 0 */
  17. mov.b #0x00,0x0a /* write disable in protect register */
  18. #endif
  19. #if EXT_RAM
  20. mov.w #0x000a,a0 /* Write enable in protect register */
  21. mov.b #0xff,[a0]
  22. mov.w #0x04,a0 /* Memory expansion mode, WRH/WRL/RD signals */
  23. mov.b #0x05,[a0]
  24. mov.w #0x05,a0 /* Insert wait, no limit in on-chip memory */
  25. mov.b #0x88,[a0]
  26. mov.w #0x08,a0 /* Enable all the CS signals with wait */
  27. mov.b #0x0F,[a0]
  28. mov.w #0x0a,a0 /* write disable in protect register */
  29. mov.b #0x00,[a0]
  30. #endif
  31. ; ldc #0x0080,flg /* select USER STACK POINTER (BIT7=1,USP) (BIT7=0,ISP) */
  32. ; ldc #_ustack,sp /* set user stack pointer */
  33. /* INTERRUPT VECTOR ADDRESS definition */
  34. ldc #0xF, intbh /* load upper 4 bits of variable vector address in intbh */
  35. ldc #0xA000, intbl /* load lower 16 bits of variable vector address in intbl */
  36. fset I /* ADD THIS TO ENABLE INTERRUPTS */
  37. /* call the hardware initialiser */
  38. ; jsr.a _hw_initialise
  39. /* load data section from ROM to RAM */
  40. mov.b #%hi8(_mdata),r1h /* move upper 4 bits of the 20 bit address (_mdata) to, r1h */
  41. mov.w #%lo16(_mdata),a0 /* move lower 16 bits of the 20 bit address (_mdata) to,a0 */
  42. mov.w #_data,a1 /* store the start address of data section in, A1 */
  43. mov.w #_edata,r3 /* store the end address of data section in R3 */
  44. sub.w a1,r3 /* R3=R3-A1. Store size of data section in R3 */
  45. mov.w r3,r2 /* Store size of data section in R2 */
  46. smovf.b
  47. /* bss initialisation : zero out bss */
  48. mov.b #0x00,R0L /* load R0L reg with 0x0 (value at which bss section will be initialised) */
  49. mov.w #_bss, a1 /* store the start address of bss in A1 */
  50. mov.w #_ebss, a0 /* store the end address of bss in A0 */
  51. sub.w a1,a0 /* (A0 = A0-A1) */
  52. mov.w a0,r3 /* Store size of bss section in reg R3 */
  53. sstr.b
  54. #if EXT_RAM
  55. /* load fdata section from ROM to External RAM only if EXT_RAM is defined */
  56. pushc sp /*store stack pointer in stack */
  57. popc fb /*copy the stack pointer in frame base register */
  58. push.w #%hi16(_mdata) /* offset of -2 from fb: store higher 16 bits of _mdata */
  59. push.w #%lo16(_mdata) /* offset of -4 from fb: store lower 16 bits of _mdata */
  60. mov.w #_edata,r0 /* end address of data section */
  61. mov.w #_data,r1 /* start address of data section */
  62. sub.w r1,r0 /* size of data section in r0 */
  63. add.w r0,-4[fb] /* store the lower 16 bits of source address on stack */
  64. adc.w #0,-2[fb] /* store the higher 4 bits of source address on stack */
  65. push.w #%hi16(_fdata) /* offset -6 from fp: store the higher 4 bits of destination address on stack */
  66. push.w #%lo16(_fdata) /* offset -8 from fp: store the lower 16 bits of destination address on stack */
  67. push.w #%hi16(_efdata) /* offset -10 from fp: higher 16 bits of _efdata */
  68. push.w #%lo16(_efdata) /* offset -12 from fp: lower 16 bits of _efdata */
  69. label1:
  70. cmp.w -6[fb],-10[fb] /* Compare higher 16 bits of _fdata and _efdata */
  71. jnz label2
  72. cmp.w -8[fb],-12[fb] /* Compare lower 16 bits of _fdata and _efdata */
  73. jeq init_fdata_end
  74. label2:
  75. mov.w -2[fb],a1 /* Copy higher 16 bits of source in A1 */
  76. mov.w -4[fb],a0 /* Copy lower 16 bits of source in A1 */
  77. lde.b [a1a0],r0l /* Copy contents of a1a0 in r0l */
  78. mov.w -6[fb],a1 /* Copy higher 16 bits of destination in A1 */
  79. mov.w -8[fb],a0 /* Copy lower 16 bits of destination in A0 */
  80. ste.b r0l,[a1a0] /* store r0l contents at [a1a0] */
  81. add.w #0x01,-4[fb] /* increment lower 16 bits of source */
  82. adcf.w -2[fb] /* add carry to higher 16 bits of source */
  83. add.w #0x01,-8[fb] /* increment lower 16 bits of destination */
  84. adcf.w -6[fb] /* add carry to higher 16 bits of destination */
  85. jmp.b label1
  86. init_fdata_end:
  87. pop.w r0 /* clean stack */
  88. pop.w r0
  89. pop.w r0
  90. pop.w r0
  91. pop.w r0
  92. pop.w r0
  93. /* Zero out fbss section */
  94. push.w #%hi16(_fbss) /* offset of -2 from fb: higher 16 bits of _fbss */
  95. push.w #%lo16(_fbss) /* offset of -4 from fb: lower 16 bits of _fbss */
  96. push.w #%hi16(_efbss) /* offset of -6 from fb: higer 16 bits of _efbss */
  97. push.w #%lo16(_efbss) /* offset of -8 from fb: lower 16 bits of _efbss */
  98. mov.b #0x00,r0l
  99. label3:
  100. cmp.w -2[fb],-6[fb] /* Compare higher 16 bits of _fdata and _efdata */
  101. jnz label4
  102. cmp.w -4[fb],-8[fb] /* Compare lower 16 bits of _fdata and _efdata */
  103. jeq init_fbss_end
  104. label4:
  105. mov.w -2[fb],a1 /* Copy higher 16 bits of source in A1 */
  106. mov.w -4[fb],a0 /* Copy lower 16 bits of source in A1 */
  107. ste.b r0l,[a1a0] /* store r0l contents at [a1a0] */
  108. add.w #0x01,-4[fb] /* increment lower 16 bits of _fbss */
  109. adcf.w -2[fb] /* add carry to higher 16 bits of _fbss */
  110. jmp.b label3
  111. init_fbss_end:
  112. pop.w r0 /* clean stack */
  113. pop.w r0
  114. pop.w r0
  115. pop.w r0
  116. #endif
  117. /* start user program */
  118. jsr.a _main
  119. .end