portasm_Hx2.s85 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. ;/*
  2. ; * FreeRTOS Kernel V10.4.6
  3. ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. ; *
  5. ; * SPDX-License-Identifier: MIT
  6. ; *
  7. ; * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. ; * this software and associated documentation files (the "Software"), to deal in
  9. ; * the Software without restriction, including without limitation the rights to
  10. ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. ; * the Software, and to permit persons to whom the Software is furnished to do so,
  12. ; * subject to the following conditions:
  13. ; *
  14. ; * The above copyright notice and this permission notice shall be included in all
  15. ; * copies or substantial portions of the Software.
  16. ; *
  17. ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. ; *
  24. ; * https://www.FreeRTOS.org
  25. ; * https://github.com/FreeRTOS
  26. ; *
  27. ; */
  28. ; Note: Select the correct include files for the device used by the application.
  29. #include "FreeRTOSConfig.h"
  30. ;------------------------------------------------------------------------------
  31. ; Functions used by scheduler
  32. ;------------------------------------------------------------------------------
  33. EXTERN vTaskSwitchContext
  34. EXTERN xTaskIncrementTick
  35. ; Variables used by scheduler
  36. ;------------------------------------------------------------------------------
  37. EXTERN pxCurrentTCB
  38. EXTERN usCriticalNesting
  39. ; Functions implemented in this file
  40. ;------------------------------------------------------------------------------
  41. PUBLIC vPortYield
  42. PUBLIC vPortStart
  43. ; Security ID definition
  44. ;------------------------------------------------------------------------------
  45. #define CG_SECURITY0 0FFH
  46. #define CG_SECURITY1 0FFH
  47. #define CG_SECURITY2 0FFH
  48. #define CG_SECURITY3 0FFH
  49. #define CG_SECURITY4 0FFH
  50. #define CG_SECURITY5 0FFH
  51. #define CG_SECURITY6 0FFH
  52. #define CG_SECURITY7 0FFH
  53. #define CG_SECURITY8 0FFH
  54. #define CG_SECURITY9 0FFH
  55. ; Tick ISR Prototype
  56. ;------------------------------------------------------------------------------
  57. PUBWEAK `??MD_INTTM0EQ0??INTVEC 544`
  58. PUBLIC MD_INTTM0EQ0
  59. MD_INTTM0EQ0 SYMBOL "MD_INTTM0EQ0"
  60. `??MD_INTTM0EQ0??INTVEC 544` SYMBOL "??INTVEC 544", MD_INTTM0EQ0
  61. ;------------------------------------------------------------------------------
  62. ; portSAVE_CONTEXT MACRO
  63. ; Saves the context of the remaining general purpose registers
  64. ; and the usCriticalNesting Value of the active Task onto the task stack
  65. ; saves stack pointer to the TCB
  66. ;------------------------------------------------------------------------------
  67. portSAVE_CONTEXT MACRO
  68. #if configDATA_MODE == 1 ; Using the Tiny data model
  69. prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},76,sp ; save general purpose registers
  70. sst.w r19,72[ep]
  71. sst.w r18,68[ep]
  72. sst.w r17,64[ep]
  73. sst.w r16,60[ep]
  74. sst.w r15,56[ep]
  75. sst.w r14,52[ep]
  76. sst.w r13,48[ep]
  77. sst.w r12,44[ep]
  78. sst.w r11,40[ep]
  79. sst.w r10,36[ep]
  80. sst.w r9,32[ep]
  81. sst.w r8,28[ep]
  82. sst.w r7,24[ep]
  83. sst.w r6,20[ep]
  84. sst.w r5,16[ep]
  85. sst.w r4,12[ep]
  86. #else ; Using the Small/Large data model
  87. prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},72,sp ; save general purpose registers
  88. sst.w r19,68[ep]
  89. sst.w r18,64[ep]
  90. sst.w r17,60[ep]
  91. sst.w r16,56[ep]
  92. sst.w r15,52[ep]
  93. sst.w r14,48[ep]
  94. sst.w r13,44[ep]
  95. sst.w r12,40[ep]
  96. sst.w r11,36[ep]
  97. sst.w r10,32[ep]
  98. sst.w r9,28[ep]
  99. sst.w r8,24[ep]
  100. sst.w r7,20[ep]
  101. sst.w r6,16[ep]
  102. sst.w r5,12[ep]
  103. #endif /* configDATA_MODE */
  104. sst.w r2,8[ep]
  105. sst.w r1,4[ep]
  106. MOVHI hi1(usCriticalNesting),r0,r1 ; save usCriticalNesting value to stack
  107. ld.w lw1(usCriticalNesting)[r1],r2
  108. sst.w r2,0[ep]
  109. MOVHI hi1(pxCurrentTCB),r0,r1 ; save SP to top of current TCB
  110. ld.w lw1(pxCurrentTCB)[r1],r2
  111. st.w sp,0[r2]
  112. ENDM
  113. ;------------------------------------------------------------------------------
  114. ;------------------------------------------------------------------------------
  115. ; portRESTORE_CONTEXT MACRO
  116. ; Gets stack pointer from the current TCB
  117. ; Restores the context of the usCriticalNesting value and general purpose
  118. ; registers of the selected task from the task stack
  119. ;------------------------------------------------------------------------------
  120. portRESTORE_CONTEXT MACRO
  121. MOVHI hi1(pxCurrentTCB),r0,r1 ; get Stackpointer address
  122. ld.w lw1(pxCurrentTCB)[r1],sp
  123. MOV sp,r1
  124. ld.w 0[r1],sp ; load stackpointer
  125. MOV sp,ep ; set stack pointer to element pointer
  126. sld.w 0[ep],r1 ; load usCriticalNesting value from stack
  127. MOVHI hi1(usCriticalNesting),r0,r2
  128. st.w r1,lw1(usCriticalNesting)[r2]
  129. sld.w 4[ep],r1 ; restore general purpose registers
  130. sld.w 8[ep],r2
  131. #if configDATA_MODE == 1 ; Using Tiny data model
  132. sld.w 12[ep],r4
  133. sld.w 16[ep],r5
  134. sld.w 20[ep],r6
  135. sld.w 24[ep],r7
  136. sld.w 28[ep],r8
  137. sld.w 32[ep],r9
  138. sld.w 36[ep],r10
  139. sld.w 40[ep],r11
  140. sld.w 44[ep],r12
  141. sld.w 48[ep],r13
  142. sld.w 52[ep],r14
  143. sld.w 56[ep],r15
  144. sld.w 60[ep],r16
  145. sld.w 64[ep],r17
  146. sld.w 68[ep],r18
  147. sld.w 72[ep],r19
  148. dispose 76,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}
  149. #else ; Using Small/Large data model
  150. sld.w 12[ep],r5
  151. sld.w 16[ep],r6
  152. sld.w 20[ep],r7
  153. sld.w 24[ep],r8
  154. sld.w 28[ep],r9
  155. sld.w 32[ep],r10
  156. sld.w 36[ep],r11
  157. sld.w 40[ep],r12
  158. sld.w 44[ep],r13
  159. sld.w 48[ep],r14
  160. sld.w 52[ep],r15
  161. sld.w 56[ep],r16
  162. sld.w 60[ep],r17
  163. sld.w 64[ep],r18
  164. sld.w 68[ep],r19
  165. dispose 72,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
  166. #endif /* configDATA_MODE */
  167. ENDM
  168. ;------------------------------------------------------------------------------
  169. ;------------------------------------------------------------------------------
  170. ; Restore the context of the first task that is going to run.
  171. ;
  172. ; Input: NONE
  173. ;
  174. ; Call: CALL vPortStart
  175. ;
  176. ; Output: NONE
  177. ;------------------------------------------------------------------------------
  178. RSEG CODE:CODE
  179. vPortStart:
  180. portRESTORE_CONTEXT ; Restore the context of whichever task the ...
  181. ld.w 0[sp],lp
  182. ldsr lp,5 ; restore PSW
  183. DI
  184. ld.w 4[sp],lp ; restore LP
  185. ld.w 8[sp],lp ; restore LP
  186. ADD 0x0C,sp ; set SP to right position
  187. EI
  188. jmp [lp]
  189. ;------------------------------------------------------------------------------
  190. ;------------------------------------------------------------------------------
  191. ; Port Yield function to check for a Task switch in the cooperative and
  192. ; preemptive mode
  193. ;
  194. ; Input: NONE
  195. ;
  196. ; Call: CALL vPortYield
  197. ;
  198. ; Output: NONE
  199. ;------------------------------------------------------------------------------
  200. RSEG CODE:CODE
  201. vPortYield:
  202. add -0x0C,sp ; prepare stack to save necessary values
  203. st.w lp,8[sp] ; store LP to stack
  204. stsr 0,r31
  205. st.w lp,4[sp] ; store EIPC to stack
  206. stsr 1,lp
  207. st.w lp,0[sp] ; store EIPSW to stack
  208. portSAVE_CONTEXT ; Save the context of the current task.
  209. jarl vTaskSwitchContext,lp ; Call the scheduler.
  210. portRESTORE_CONTEXT ; Restore the context of whichever task the ...
  211. ; ... scheduler decided should run.
  212. ld.w 0[sp],lp ; restore EIPSW from stack
  213. ldsr lp,1
  214. ld.w 4[sp],lp ; restore EIPC from stack
  215. ldsr lp,0
  216. ld.w 8[sp],lp ; restore LP from stack
  217. add 0x0C,sp ; set SP to right position
  218. RETI
  219. ;------------------------------------------------------------------------------
  220. ;------------------------------------------------------------------------------
  221. ; Perform the necessary steps of the Tick Count Increment and Task Switch
  222. ; depending on the chosen kernel configuration
  223. ;
  224. ; Input: NONE
  225. ;
  226. ; Call: ISR
  227. ;
  228. ; Output: NONE
  229. ;------------------------------------------------------------------------------
  230. #if configUSE_PREEMPTION == 1 ; use preemptive kernel mode
  231. MD_INTTM0EQ0:
  232. add -0x0C,sp ; prepare stack to save necessary values
  233. st.w lp,8[sp] ; store LP to stack
  234. stsr 0,r31
  235. st.w lp,4[sp] ; store EIPC to stack
  236. stsr 1,lp
  237. st.w lp,0[sp] ; store EIPSW to stack
  238. portSAVE_CONTEXT ; Save the context of the current task.
  239. jarl xTaskIncrementTick,lp ; Call the timer tick function.
  240. jarl vTaskSwitchContext,lp ; Call the scheduler.
  241. portRESTORE_CONTEXT ; Restore the context of whichever task the ...
  242. ; ... scheduler decided should run.
  243. ld.w 0[sp],lp ; restore EIPSW from stack
  244. ldsr lp,1
  245. ld.w 4[sp],lp ; restore EIPC from stack
  246. ldsr lp,0
  247. ld.w 8[sp],lp ; restore LP from stack
  248. add 0x0C,sp ; set SP to right position
  249. RETI
  250. ;------------------------------------------------------------------------------
  251. #else ; use cooperative kernel mode
  252. MD_INTTM0EQ0:
  253. prepare {lp,ep},8,sp
  254. sst.w r1,4[ep]
  255. sst.w r5,0[ep]
  256. jarl xTaskIncrementTick,lp ; Call the timer tick function.
  257. sld.w 0[ep],r5
  258. sld.w 4[ep],r1
  259. dispose 8,{lp,ep}
  260. RETI
  261. #endif /* configUSE_PREEMPTION */
  262. ;------------------------------------------------------------------------------
  263. COMMON INTVEC:CODE:ROOT(2)
  264. ORG 544
  265. `??MD_INTTM0EQ0??INTVEC 544`:
  266. JR MD_INTTM0EQ0
  267. RSEG NEAR_ID:CONST:SORT:NOROOT(2)
  268. `?<Initializer for usCriticalNesting>`:
  269. DW 10
  270. COMMON INTVEC:CODE:ROOT(2)
  271. ORG 40H
  272. `??vPortYield??INTVEC 40`:
  273. JR vPortYield
  274. ;------------------------------------------------------------------------------
  275. ; set microcontroller security ID
  276. COMMON INTVEC:CODE:ROOT(2)
  277. ORG 70H
  278. `SECUID`:
  279. DB CG_SECURITY0
  280. DB CG_SECURITY1
  281. DB CG_SECURITY2
  282. DB CG_SECURITY3
  283. DB CG_SECURITY4
  284. DB CG_SECURITY5
  285. DB CG_SECURITY6
  286. DB CG_SECURITY7
  287. DB CG_SECURITY8
  288. DB CG_SECURITY9
  289. ; set microcontroller Option bytes
  290. COMMON INTVEC:CODE:ROOT(2)
  291. ORG 122
  292. `OPTBYTES`:
  293. DB 0xFD
  294. DB 0xFF
  295. DB 0xFF
  296. DB 0xFF
  297. DB 0xFF
  298. DB 0xFF
  299. #if configOCD_USAGE == 1
  300. COMMON INTVEC:CODE:ROOT(4)
  301. ORG 0x230
  302. PUBLIC ROM_INT2
  303. ROM_INT2:
  304. DB 0xff, 0xff, 0xff, 0xff
  305. DB 0xff, 0xff, 0xff, 0xff
  306. DB 0xff, 0xff, 0xff, 0xff
  307. DB 0xff, 0xff, 0xff, 0xff
  308. COMMON INTVEC:CODE:ROOT(4)
  309. ORG 0x60
  310. PUBLIC ROM_INT
  311. ROM_INT:
  312. DB 0xff, 0xff, 0xff, 0xff
  313. DB 0xff, 0xff, 0xff, 0xff
  314. DB 0xff, 0xff, 0xff, 0xff
  315. DB 0xff, 0xff, 0xff, 0xff
  316. #endif /* configOCD_USAGE */
  317. END