chipcon_cstartup.s51 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /**************************************************************************************************
  2. Filename: chipcon_cstartup.s51
  3. Revised: $Date: 2010-01-28 17:00:06 -0800 (Thu, 28 Jan 2010) $
  4. Revision: $Revision: 21615 $
  5. Description: Contains the code executed before the C/EC++ "main"
  6. function is called. The code is designed to run on any
  7. processor based on the 8051 architecture.
  8. Copyright 2005-2007 Texas Instruments Incorporated. All rights reserved.
  9. IMPORTANT: Your use of this Software is limited to those specific rights
  10. granted under the terms of a software license agreement between the user
  11. who downloaded the software, his/her employer (which must be your employer)
  12. and Texas Instruments Incorporated (the "License"). You may not use this
  13. Software unless you agree to abide by the terms of the License. The License
  14. limits your use, and you acknowledge, that the Software may not be modified,
  15. copied or distributed unless embedded on a Texas Instruments microcontroller
  16. or used solely and exclusively in conjunction with a Texas Instruments radio
  17. frequency transceiver, which is integrated into your product. Other than for
  18. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  19. works of, modify, distribute, perform, display or sell this Software and/or
  20. its documentation for any purpose.
  21. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  22. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  23. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  24. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  25. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  26. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  27. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  28. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  29. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  30. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  31. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  32. Should you have any questions regarding your right to use this Software,
  33. contact Texas Instruments Incorporated at www.TI.com.
  34. **************************************************************************************************/
  35. /******************************************************************************
  36. Copyright 2004-2005 IAR Systems. All rights reserved.
  37. Updated by Chipcon to not clear ?CBANK at init.
  38. ******************************************************************************/
  39. #include "iar_common.h"
  40. PROGRAM CSTARTUP
  41. PUBLIC __program_start
  42. EXTERN ?B0
  43. EXTERNS_FOR_ALL_DPTR_SYMBOLS()
  44. REQUIRE ?B0
  45. REQUIRE __call_main
  46. #if (__NUMBER_OF_DPTRS__ > 1)
  47. REQUIRE ?RESET_DPS
  48. #endif
  49. #if (__CORE__ == __CORE_EXTENDED1__)
  50. REQUIRE __call_init_extended1
  51. #endif
  52. ; Uncomment this when rom-monitor requires 3 NOPS between statements.
  53. ; REQUIRE ?ROM_MONITOR_NOPS
  54. RSEG REGISTERS:NOROOT:DATA
  55. PUBLIC ?REGISTERS
  56. ?REGISTERS:
  57. //------------------------------------------------------------------------
  58. // The C stack segment. Should be mapped into internal data RAM
  59. //
  60. // ISTACK: Should be mapped into internal data RAM
  61. // PSTACK: Should be mapped into external data RAM page
  62. // XSTACK: Should be mapped into external data RAM
  63. // EXT_STACK: Should be mapped into external data RAM
  64. //
  65. //------------------------------------------------------------------------
  66. // The C stack is used for LCALL's and temporary storage for
  67. // code generator help-routines (math etc). The stack will be
  68. // located after all other internal RAM variables if the stan-
  69. // dard linking procedure is followed. Note that C interrupt
  70. // routines can double stack size demands.
  71. //
  72. //------------------------------------------------------------------------
  73. RSEG ISTACK:NOROOT:IDATA
  74. PUBLIC ?ISTACK_START
  75. ?ISTACK_START:
  76. RSEG PSTACK:NOROOT:XDATA
  77. PUBLIC ?PSTACK_START
  78. ?PSTACK_START:
  79. RSEG XSTACK:NOROOT:XDATA
  80. PUBLIC ?XSTACK_START
  81. ?XSTACK_START:
  82. RSEG EXT_STACK:NOROOT:XDATA
  83. PUBLIC ?EXT_STACK_START
  84. ?EXT_STACK_START:
  85. //------------------------------------------------------------------------
  86. //
  87. // Define reset vector.
  88. //
  89. //------------------------------------------------------------------------
  90. COMMON INTVEC:CODE:ROOT(0)
  91. // The reset vector must be located at address zero, the reset
  92. // vector is located first in the INTVEC segment. This segment
  93. // must thus be located at address zero. Be carefull if using
  94. // assembler sequences located with the ASEG directive, which may
  95. // prevent the INTVEC segment from being located at address zero.
  96. // Not enforcing location at address 0 for boot loader for OAD.
  97. // LIMIT SFB(INTVEC),0,0,"The INTVEC segment must begin at address zero"
  98. ?reset_vector:
  99. DB 0x02 ; LJMP
  100. #if defined(START_INIT_IN_FAR)
  101. DB BYTE3(__program_start)
  102. #endif
  103. DB high(__program_start)
  104. DB low(__program_start)
  105. //------------------------------------------------------------------------
  106. //
  107. // Initialize the chip to suit IAR ICC8051 Compiler
  108. //
  109. //------------------------------------------------------------------------
  110. RSEG CSTART:CODE:ROOT
  111. EXTERN ?REGISTER_BANK
  112. REQUIRE ?ISTACK_START
  113. REQUIRE ?REGISTERS
  114. REQUIRE ?reset_vector
  115. __program_start:
  116. MOV PSW,#(?REGISTER_BANK << 3)
  117. //------------------------------------------------------------------------
  118. //
  119. // Reset of bank registers and stack pointers
  120. // ==========================================
  121. //
  122. // ?RESET_SP: Resets the IDATA stack pointer
  123. // ?RESET_ESP: Resets the extended stack pointer
  124. // ?RESET_PSP: Resets the PDATA stack pointer
  125. // ?RESET_XSP: Resets the XDATA stack pointer
  126. //
  127. // ?RESET_CODE_BANK: Resets the current code bank register
  128. // ?RESET_PDATA_BANK: Resets the high byte of PDATA page register
  129. //
  130. // ?RESET_DPS: Resets the DPTR selector (point at DPTR0)
  131. //
  132. //------------------------------------------------------------------------
  133. //------------------------------------------------------------------------
  134. //
  135. // Reset idata or extended stack pointer
  136. // extended stack pointer if the extended stack is used
  137. // otherwise, the ordinary stack pointer
  138. //
  139. //------------------------------------------------------------------------
  140. #if (defined(__EXTENDED_STACK__) )
  141. //
  142. // Reset extended stack pointer
  143. //
  144. PUBLIC ?RESET_ESP
  145. REQUIRE ?EXT_STACK_START
  146. EXTERN ?ESP
  147. ?RESET_ESP:
  148. MOV SP,#low(sfb(EXT_STACK))
  149. MOV ?ESP,#high(sfb(EXT_STACK))
  150. #else
  151. //
  152. // Reset idata stack pointer
  153. //
  154. PUBLIC ?RESET_SP
  155. REQUIRE ?ISTACK_START
  156. ?RESET_SP:
  157. MOV SP,#SFB(ISTACK)
  158. #endif
  159. //------------------------------------------------------------------------
  160. //
  161. // Reset pdata stack pointer
  162. //
  163. //------------------------------------------------------------------------
  164. RSEG CSTART:CODE:NOROOT
  165. PUBLIC ?RESET_PSP
  166. EXTERN ?PSP
  167. REQUIRE ?PSTACK_START
  168. REQUIRE ?RESET_PDATA_BANK
  169. EXTERN ?PSTACK
  170. ?RESET_PSP:
  171. MOV ?PSP,#low(sfe(PSTACK))
  172. //------------------------------------------------------------------------
  173. //
  174. // Reset xdata stack pointer
  175. //
  176. //------------------------------------------------------------------------
  177. RSEG CSTART:CODE:NOROOT
  178. PUBLIC ?RESET_XSP
  179. EXTERN ?XSP
  180. REQUIRE ?XSTACK_START
  181. EXTERN ?XSTACK
  182. ?RESET_XSP:
  183. MOV ?XSP,#low(sfe(XSTACK))
  184. MOV ?XSP+1,#high(sfe(XSTACK))
  185. //------------------------------------------------------------------------
  186. //
  187. // Reset code bank
  188. //
  189. //------------------------------------------------------------------------
  190. #if ( (__CODE_MODEL__ == __CM_BANKED__) || ( __CODE_MODEL__ == __CM_NEAR__ ) )
  191. RSEG CSTART:CODE:NOROOT
  192. PUBLIC ?RESET_CODE_BANK
  193. EXTERN ?CBANK
  194. ?RESET_CODE_BANK:
  195. NOP
  196. // MOV ?CBANK,#0x00
  197. #endif
  198. //------------------------------------------------------------------------
  199. //
  200. // Reset pdata page
  201. //
  202. //------------------------------------------------------------------------
  203. RSEG CSTART:CODE:NOROOT
  204. PUBLIC ?RESET_PDATA_BANK
  205. EXTERN ?PBANK
  206. EXTERN ?PBANK_NUMBER
  207. ?RESET_PDATA_BANK:
  208. MOV ?PBANK,#?PBANK_NUMBER
  209. #if (defined ( __EXTENDED_DPTR__))
  210. EXTERN ?PBANK_EXT
  211. ?RESET_PDATA_BANK_EXT:
  212. MOV ?PBANK_EXT,#0x00
  213. #endif
  214. //------------------------------------------------------------------------
  215. //
  216. // Reset data pointer select register
  217. //
  218. //------------------------------------------------------------------------
  219. #if (__NUMBER_OF_DPTRS__ > 1)
  220. RSEG CSTART:CODE:NOROOT
  221. PUBLIC ?RESET_DPS
  222. EXTERN ?DPS
  223. ?RESET_DPS:
  224. MOV ?DPS,#0x00
  225. #endif
  226. //------------------------------------------------------------------------
  227. //
  228. // Initialize the extended1 core
  229. //
  230. //------------------------------------------------------------------------
  231. #if (__CORE__ == __CORE_EXTENDED1__)
  232. REQUIRE __call_init_extended1
  233. RSEG CSTART:CODE:NOROOT
  234. PUBLIC __call_init_extended1
  235. EXTERN __init_extended1
  236. __call_init_extended1:
  237. DB 0x12 ; LCALL
  238. #if defined(START_INIT_IN_FAR)
  239. DB BYTE3(__init_extended1)
  240. #endif
  241. DB high(__init_extended1)
  242. DB low(__init_extended1)
  243. #endif
  244. //------------------------------------------------------------------------
  245. //
  246. // Jump to the code that performs the rest of the system initialization
  247. // before calling main().
  248. //
  249. //------------------------------------------------------------------------
  250. RSEG CSTART:CODE:NOROOT
  251. EXTERN ?cmain
  252. __call_main:
  253. LJMP ?cmain
  254. ENDMOD
  255. ;----------------------------------------------------------------;
  256. ; Virtual registers ;
  257. ; ================= ;
  258. ; Below is some segment needed for the IAR ICC C/EC++ compiler ;
  259. ; ;
  260. ; BREG : A segment for 8 bit registers for use by the compiler. ;
  261. ; ?B0 is the first register. ;
  262. ; VREG : Segement that holds up to 32 virtual registers for ;
  263. ; use by the compiler. ?V0 is the first register. ;
  264. ; PSP : Segment containing the PDATA stack pointer (?PSP) ;
  265. ; XSP : Segment containing the XDATA stack pointer (?XSP) ;
  266. ; ;
  267. ;----------------------------------------------------------------;
  268. ; NOTE: The XLINK varialbe _NR_OF_VIRTUAL_REGISTERS must be ;
  269. ; defined to set the size for the VREG segment. ;
  270. ;----------------------------------------------------------------;
  271. MODULE VIRTUAL_REGISTERS
  272. PUBLIC ?B0
  273. PUBLIC ?V0
  274. PUBLIC ?PSP
  275. PUBLIC ?XSP
  276. RSEG BREG:BIT:NOROOT
  277. ?B0:
  278. DS 8
  279. RSEG VREG:DATA:NOROOT
  280. EXTERN _NR_OF_VIRTUAL_REGISTERS
  281. ?V0:
  282. DS 0
  283. RSEG PSP:DATA:NOROOT
  284. EXTERN ?RESET_PSP
  285. REQUIRE ?RESET_PSP
  286. ?PSP:
  287. DS 1
  288. RSEG XSP:DATA:NOROOT
  289. EXTERN ?RESET_XSP
  290. REQUIRE ?RESET_XSP
  291. ?XSP:
  292. DS 2
  293. ENDMOD ; VIRTUAL_REGISTERS
  294. ;----------------------------------------------------------------;
  295. ; Register banks ;
  296. ; ================= ;
  297. ; Below is some segment needed for the IAR ICC C/EC++ compiler ;
  298. ; ;
  299. ; The register banks will only be included if the #pragma ;
  300. ; register_bank is used for the corresponding register bank ;
  301. ; ;
  302. ;----------------------------------------------------------------;
  303. MODULE REGISTER_BANK0
  304. PUBLIC __REG_BANK_0
  305. ASEGN __REG_BANK0:DATA,0x00
  306. __REG_BANK_0:
  307. DS 8
  308. ENDMOD
  309. MODULE REGISTER_BANK1
  310. PUBLIC __REG_BANK_1
  311. ASEGN __REG_BANK1:DATA,0x08
  312. __REG_BANK_1:
  313. DS 8
  314. ENDMOD
  315. MODULE REGISTER_BANK2
  316. PUBLIC __REG_BANK_2
  317. ASEGN __REG_BANK2:DATA,0x10
  318. __REG_BANK_2:
  319. DS 8
  320. ENDMOD
  321. MODULE REGISTER_BANK3
  322. PUBLIC __REG_BANK_3
  323. ASEGN __REG_BANK3:DATA,0x18
  324. __REG_BANK_3:
  325. DS 8
  326. ENDMOD ; REGISTER_BANK3
  327. END