Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. /* $Id: c018i.c,v 1.7 2006/11/15 22:53:12 moshtaa Exp $ */
  2.  
  3. /* Copyright (c)1999 Microchip Technology */
  4.  
  5. /* MPLAB-C18 startup code, including initialized data */
  6.  
  7. /* external reference to __init() function */
  8. extern void __init (void);
  9. /* external reference to the user's main routine */
  10. extern void main (void);
  11. /* prototype for the startup function */
  12. void _entry (void);
  13. void _startup (void);
  14. /* prototype for the initialized data setup */
  15. void _do_cinit (void);
  16.  
  17. extern volatile near unsigned long short TBLPTR;
  18. extern near unsigned FSR0;
  19. extern near char __FPFLAGS;
  20. #define RND 6
  21.  
  22. #pragma code _entry_scn=0x000000
  23. void
  24. _entry (void)
  25. {
  26. _asm goto _startup _endasm
  27.  
  28. }
  29. #pragma code _startup_scn
  30. void
  31. _startup (void)
  32. {
  33. _asm
  34. // Initialize the stack pointer
  35. lfsr 1, _stack
  36. lfsr 2, _stack
  37.  
  38. clrf TBLPTRU, 0 // 1st silicon doesn't do this on POR
  39.  
  40. bcf __FPFLAGS,RND,0 // Initialize rounding flag for floating point libs
  41.  
  42. _endasm
  43. _do_cinit ();
  44.  
  45. loop:
  46.  
  47. // If user defined __init is not found, the one in clib.lib will be used
  48. __init ();
  49.  
  50. // Call the user's main routine
  51. main ();
  52.  
  53. goto loop;
  54. } /* end _startup() */
  55.  
  56. /* MPLAB-C18 initialized data memory support */
  57. /* The linker will populate the _cinit table */
  58. extern far rom struct
  59. {
  60. unsigned short num_init;
  61. struct _init_entry
  62. {
  63. unsigned long from;
  64. unsigned long to;
  65. unsigned long size;
  66. }
  67. entries[];
  68. }
  69. _cinit;
  70.  
  71. #pragma code _cinit_scn
  72. void
  73. _do_cinit (void)
  74. {
  75. /* we'll make the assumption in the following code that these statics
  76. * will be allocated into the same bank.
  77. */
  78. static short long prom;
  79. static unsigned short curr_byte;
  80. static unsigned short curr_entry;
  81. static short long data_ptr;
  82.  
  83. // Initialized data...
  84. TBLPTR = (short long)&_cinit;
  85. _asm
  86. movlb data_ptr
  87. tblrdpostinc
  88. movf TABLAT, 0, 0
  89. movwf curr_entry, 1
  90. tblrdpostinc
  91. movf TABLAT, 0, 0
  92. movwf curr_entry+1, 1
  93. _endasm
  94. //while (curr_entry)
  95. //{
  96. test:
  97. _asm
  98. bnz 3
  99. tstfsz curr_entry, 1
  100. bra 1
  101. _endasm
  102. goto done;
  103. /* Count down so we only have to look up the data in _cinit
  104. * once.
  105. *
  106. * At this point we know that TBLPTR points to the top of the current
  107. * entry in _cinit, so we can just start reading the from, to, and
  108. * size values.
  109. */
  110. _asm
  111. /* read the source address */
  112. tblrdpostinc
  113. movf TABLAT, 0, 0
  114. movwf prom, 1
  115. tblrdpostinc
  116. movf TABLAT, 0, 0
  117. movwf prom+1, 1
  118. tblrdpostinc
  119. movf TABLAT, 0, 0
  120. movwf prom+2, 1
  121. /* skip a byte since it's stored as a 32bit int */
  122. tblrdpostinc
  123. /* read the destination address directly into FSR0 */
  124. tblrdpostinc
  125. movf TABLAT, 0, 0
  126. movwf FSR0L, 0
  127. tblrdpostinc
  128. movf TABLAT, 0, 0
  129. movwf FSR0H, 0
  130. /* skip two bytes since it's stored as a 32bit int */
  131. tblrdpostinc
  132. tblrdpostinc
  133. /* read the destination address directly into FSR0 */
  134. tblrdpostinc
  135. movf TABLAT, 0, 0
  136. movwf curr_byte, 1
  137. tblrdpostinc
  138. movf TABLAT, 0, 0
  139. movwf curr_byte+1, 1
  140. /* skip two bytes since it's stored as a 32bit int */
  141. tblrdpostinc
  142. tblrdpostinc
  143. _endasm
  144. //prom = data_ptr->from;
  145. //FSR0 = data_ptr->to;
  146. //curr_byte = (unsigned short) data_ptr->size;
  147. /* the table pointer now points to the next entry. Save it
  148. * off since we'll be using the table pointer to do the copying
  149. * for the entry.
  150. */
  151. data_ptr = TBLPTR;
  152.  
  153. /* now assign the source address to the table pointer */
  154. TBLPTR = prom;
  155.  
  156. /* do the copy loop */
  157. _asm
  158. // determine if we have any more bytes to copy
  159. movlb curr_byte
  160. movf curr_byte, 1, 1
  161. copy_loop:
  162. bnz 2 // copy_one_byte
  163. movf curr_byte + 1, 1, 1
  164. bz 7 // done_copying
  165.  
  166. copy_one_byte:
  167. tblrdpostinc
  168. movf TABLAT, 0, 0
  169. movwf POSTINC0, 0
  170.  
  171. // decrement byte counter
  172. decf curr_byte, 1, 1
  173. bc -8 // copy_loop
  174. decf curr_byte + 1, 1, 1
  175. bra -7 // copy_one_byte
  176.  
  177. done_copying:
  178.  
  179. _endasm
  180. /* restore the table pointer for the next entry */
  181. TBLPTR = data_ptr;
  182. /* next entry... */
  183. curr_entry--;
  184. goto test;
  185. done:
  186. ;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement