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