bf533_basiccrt.s 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /* MANAGED-BY-SYSTEM-BUILDER */
  2. /* VisualDSP++ 5.0 Update 6 */
  3. /* CRT Printer version: 5.6.0.4 */
  4. /* crtgen.exe version: 5.6.0.4 */
  5. /* VDSG version: 5.6.0.4 */
  6. /*
  7. ** bf533_basiccrt.s generated on May 08, 2012 at 10:55:43.
  8. **
  9. ** Copyright (C) 2000-2008 Analog Devices Inc., All Rights Reserved.
  10. ** This contains Analog Devices Background IP and Development IP as
  11. ** defined in the ADI/Intel Collaboration Agreement.
  12. **
  13. ** This file is generated automatically based upon the options selected
  14. ** in the Startup Code Wizard. Changes to the startup configuration
  15. ** should be made by changing the appropriate options rather than
  16. ** editing this file. Additional user code to be executed before calling
  17. ** main can be inserted between the labels .start_of_user_code1 and
  18. ** .end_of_user_code1 or .start_of_user_code2 and .end_of_user_code2.
  19. ** This code is preserved if the CRT is re-generated.
  20. **
  21. ** Configuration:-
  22. ** product_name: VisualDSP++ 5.0 Update 6
  23. ** processor: ADSP-BF533
  24. ** si_revision: automatic
  25. ** cplb_init: true
  26. ** cplb_ctrl: (
  27. ** CPLB_ENABLE_ICACHE
  28. ** CPLB_ENABLE_ICPLBS
  29. ** )
  30. ** mem_init: false
  31. ** device_init: true
  32. ** init_regs: false
  33. ** zero_return_regs: false
  34. ** use_profiling: false
  35. ** use_vdk: false
  36. ** set_clock_and_power: false
  37. **
  38. */
  39. /////////////////////////////////////////////////////////////////
  40. // blackfin-edinburgh-core
  41. #include <sys/platform.h>
  42. #include <sys/anomaly_macros_rtl.h>
  43. /////////////////////////////////////////////////////////////////
  44. // standard
  45. #define IVBh (EVT0 >> 16)
  46. #define IVBl (EVT0 & 0xFFFF)
  47. #define UNASSIGNED_VAL 0x8181
  48. #define INTERRUPT_BITS 0x400 // just IVG15
  49. #define SYSCFG_VALUE 0x30
  50. .section/DOUBLEANY program;
  51. .file_attr requiredForROMBoot;
  52. .align 2;
  53. start:
  54. /*$VDSG<insert-code-very-beginning> */
  55. .start_of_user_code_very_beginning:
  56. // Insert additional code to be executed before any other Startup Code here.
  57. // This code is preserved if the CRT is re-generated.
  58. .end_of_user_code_very_beginning:
  59. /*$VDSG<insert-code-very-beginning> */
  60. /////////////////////////////////////////////////////////////////
  61. // blackfin-edinburgh-core
  62. #if WA_05000109
  63. // Avoid Anomaly 05-00-0109
  64. R1 = SYSCFG_VALUE;
  65. SYSCFG = R1;
  66. #endif
  67. /////////////////////////////////////////////////////////////////
  68. // standard
  69. #if WA_05000229
  70. // Avoid Anomaly 05-00-0229: DMA5_CONFIG and SPI_CTL not cleared on reset.
  71. R1 = 0x400;
  72. #if defined(__ADSPBF538__) || defined(__ADSPBF539__)
  73. P0.L = SPI0_CTL & 0xFFFF;
  74. P0.H = SPI0_CTL >> 16;
  75. W[P0] = R1.L;
  76. #else
  77. P0.L = SPI_CTL & 0xFFFF;
  78. P0.H = SPI_CTL >> 16;
  79. W[P0] = R1.L;
  80. #endif
  81. P0.L = DMA5_CONFIG & 0xFFFF;
  82. P0.H = DMA5_CONFIG >> 16;
  83. R1 = 0;
  84. W[P0] = R1.L;
  85. #endif
  86. // Clear loop counters to disable hardware loops
  87. R7 = 0;
  88. LC0 = R7;
  89. LC1 = R7;
  90. // Clear the DAG Length regs, to force linear addressing
  91. L0 = R7;
  92. L1 = R7;
  93. L2 = R7;
  94. L3 = R7;
  95. // Clear ITEST_COMMAND and DTEST_COMMAND registers
  96. I0.L = (ITEST_COMMAND & 0xFFFF);
  97. I0.H = (ITEST_COMMAND >> 16);
  98. I1.L = (DTEST_COMMAND & 0xFFFF);
  99. I1.H = (DTEST_COMMAND >> 16);
  100. [I0] = R7;
  101. [I1] = R7;
  102. CSYNC;
  103. // Initialise the Event Vector table.
  104. P0.H = IVBh;
  105. P0.L = IVBl;
  106. // Install __unknown_exception_occurred in EVT so that
  107. // there is defined behaviour.
  108. P0 += 2*4; // Skip Emulation and Reset
  109. P1 = 13;
  110. R1.L = __unknown_exception_occurred;
  111. R1.H = __unknown_exception_occurred;
  112. LSETUP (.ivt,.ivt) LC0 = P1;
  113. .ivt: [P0++] = R1;
  114. // Set IVG15's handler to be the start of the mode-change
  115. // code. Then, before we return from the Reset back to user
  116. // mode, we'll raise IVG15. This will mean we stay in supervisor
  117. // mode, and continue from the mode-change point, but at a
  118. // much lower priority.
  119. P1.H = supervisor_mode;
  120. P1.L = supervisor_mode;
  121. [P0] = P1;
  122. /////////////////////////////////////////////////////////////////
  123. // cplb-handler
  124. #include "cplb.h"
  125. P1.H = _cplb_hdr;
  126. P1.L = _cplb_hdr;
  127. [P0-48] = P1; // write exception handler
  128. .extern _cplb_hdr;
  129. /////////////////////////////////////////////////////////////////
  130. // standard
  131. // Initialise the stack.
  132. // Note: this points just past the end of the section.
  133. // First write should be with [--SP].
  134. SP.L=ldf_stack_end;
  135. SP.H=ldf_stack_end;
  136. usp = sp;
  137. // We're still in supervisor mode at the moment, so the FP
  138. // needs to point to the supervisor stack.
  139. FP = SP;
  140. // Make space for incoming "parameters" for functions
  141. // we call from here:
  142. SP += -12;
  143. R0 = INTERRUPT_BITS;
  144. R0 <<= 5; // Bits 0-4 not settable.
  145. CALL.X __install_default_handlers;
  146. R1 = SYSCFG;
  147. R4 = R0; // Save modified list
  148. BITSET(R1,1);
  149. SYSCFG = R1; // Enable the cycle counter
  150. /////////////////////////////////////////////////////////////////
  151. // blackfin-edinburgh-core
  152. #if WA_05000137
  153. // Avoid Anomaly 02-00-0137
  154. // Set the port preferences of DAG0 and DAG1 to be
  155. // different; this gives better performance when
  156. // performing daul-dag operations on SDRAM.
  157. P0.L = DMEM_CONTROL & 0xFFFF;
  158. P0.H = DMEM_CONTROL >> 16;
  159. R0 = [P0];
  160. BITSET(R0, 12);
  161. BITCLR(R0, 13);
  162. [P0] = R0;
  163. CSYNC;
  164. #endif
  165. /*$VDSG<insert-code-early-startup> */
  166. .start_of_user_code1:
  167. // Insert additional code to be executed before main here.
  168. // This code is preserved if the CRT is re-generated.
  169. .end_of_user_code1:
  170. /*$VDSG<insert-code-early-startup> */
  171. /////////////////////////////////////////////////////////////////
  172. // cplb-init
  173. // initialise the CPLBs if they're needed. This was not possible
  174. // before we set up the stacks.
  175. R0 = 81; // cplb_ctrl = 81
  176. CALL.X _cplb_init;
  177. .extern _cplb_init;
  178. .type _cplb_init,STT_FUNC;
  179. .section/DOUBLEANY data1;
  180. ___cplb_ctrl:
  181. .align 4;
  182. .byte4=81;
  183. .global ___cplb_ctrl;
  184. .type ___cplb_ctrl,STT_OBJECT;
  185. .section/DOUBLEANY program;
  186. .align 2;
  187. /////////////////////////////////////////////////////////////////
  188. // standard
  189. // Enable interrupts
  190. STI R4; // Using the mask from default handlers
  191. RAISE 15;
  192. // Move the processor into user mode.
  193. P0.L=still_interrupt_in_ipend;
  194. P0.H=still_interrupt_in_ipend;
  195. RETI=P0;
  196. NOP; // Purely to prevent a stall warning
  197. still_interrupt_in_ipend:
  198. // execute RTI until we've `finished` servicing all
  199. // interrupts of priority higher than IVG15. Normally one
  200. // would expect to only have the reset interrupt in IPEND
  201. // being serviced, but occasionally when debugging this may
  202. // not be the case - if restart is hit when servicing an
  203. // interrupt.
  204. //
  205. // When we clear all bits from IPEND, we'll enter user mode,
  206. // then we'll automatically jump to supervisor_mode to start
  207. // servicing IVG15 (which we will 'service' for the whole
  208. // program, so that the program is in supervisor mode.
  209. // Need to do this to 'finish' servicing the reset interupt.
  210. RTI;
  211. supervisor_mode:
  212. [--SP] = RETI; // re-enables the interrupt system
  213. R0.L = UNASSIGNED_VAL;
  214. R0.H = UNASSIGNED_VAL;
  215. // Push a RETS and Old FP onto the stack, for sanity.
  216. [--SP]=R0;
  217. [--SP]=R0;
  218. // Make sure the FP is sensible.
  219. FP = SP;
  220. // Leave space for incoming "parameters"
  221. SP += -12;
  222. /*$VDSG<insert-code-before-device-initialization> */
  223. .start_of_user_code2:
  224. // Insert additional code to be executed before device initialization here.
  225. // This code is preserved if the CRT is re-generated.
  226. .end_of_user_code2:
  227. /*$VDSG<insert-code-before-device-initialization> */
  228. /////////////////////////////////////////////////////////////////
  229. // device-initialization
  230. // initialise the devices known about for stdio.
  231. CALL.X _init_devtab;
  232. .extern _init_devtab;
  233. .type _init_devtab,STT_FUNC;
  234. /////////////////////////////////////////////////////////////////
  235. // cplusplus
  236. CALL.X ___ctorloop; // run global scope C++ constructors
  237. .extern ___ctorloop;
  238. .type ___ctorloop,STT_FUNC;
  239. /*$VDSG<insert-code-before-main-entry> */
  240. .start_of_user_code3:
  241. // Insert additional code to be executed before main here.
  242. // This code is preserved if the CRT is re-generated.
  243. .end_of_user_code3:
  244. /*$VDSG<insert-code-before-main-entry> */
  245. /////////////////////////////////////////////////////////////////
  246. // get-args
  247. // Read command-line arguments.
  248. CALL.X __getargv;
  249. r1.l=__Argv;
  250. r1.h=__Argv;
  251. .extern __getargv;
  252. .type __getargv,STT_FUNC;
  253. .extern __Argv;
  254. .type __Argv,STT_OBJECT;
  255. /////////////////////////////////////////////////////////////////
  256. // standard
  257. // Call the application program.
  258. CALL.X _main;
  259. /////////////////////////////////////////////////////////////////
  260. // call-exit
  261. CALL.X _exit; // passing in main's return value
  262. .extern _exit;
  263. .type _exit,STT_FUNC;
  264. /////////////////////////////////////////////////////////////////
  265. // standard
  266. .start.end: // Required by the linker to know the size of the routine
  267. // that is needed for absolute placement.
  268. .global start;
  269. .type start,STT_FUNC;
  270. .global .start.end;
  271. .type .start.end,STT_FUNC;
  272. .extern _main;
  273. .type _main,STT_FUNC;
  274. .extern ldf_stack_end;
  275. .extern __unknown_exception_occurred;
  276. .type __unknown_exception_occurred,STT_FUNC;
  277. .extern __install_default_handlers;
  278. .type __install_default_handlers,STT_FUNC;
  279. /////////////////////////////////////////////////////////////////
  280. // cplusplus
  281. .section/DOUBLEANY ctor;
  282. .align 4;
  283. ___ctor_table:
  284. .byte4=0;
  285. .global ___ctor_table;
  286. .type ___ctor_table,STT_OBJECT;
  287. .section/DOUBLEANY .gdt;
  288. .align 4;
  289. ___eh_gdt:
  290. .global ___eh_gdt;
  291. .byte4=0;
  292. .type ___eh_gdt,STT_OBJECT;
  293. .section/DOUBLEANY .frt;
  294. .align 4;
  295. ___eh_frt:
  296. .global ___eh_frt;
  297. .byte4=0;
  298. .type ___eh_frt,STT_OBJECT;