portasm_Fx3.s85 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. ; Option Byte definitions
  56. ;------------------------------------------------------------------------------
  57. #define CG_OPTION7A 0x00
  58. #define CG_OPTION7B 0x04
  59. #define OPT7C 0x00
  60. #define OPT7D 0x00
  61. #define OPT7E 0x00
  62. #define OPT7F 0x00
  63. ; Tick ISR Prototype
  64. ;------------------------------------------------------------------------------
  65. PUBWEAK `??MD_INTTM0EQ0??INTVEC 608`
  66. PUBLIC MD_INTTM0EQ0
  67. MD_INTTM0EQ0 SYMBOL "MD_INTTM0EQ0"
  68. `??MD_INTTM0EQ0??INTVEC 608` SYMBOL "??INTVEC 608", MD_INTTM0EQ0
  69. ;------------------------------------------------------------------------------
  70. ; portSAVE_CONTEXT MACRO
  71. ; Saves the context of the remaining general purpose registers
  72. ; and the usCriticalNesting Value of the active Task onto the task stack
  73. ; saves stack pointer to the TCB
  74. ;------------------------------------------------------------------------------
  75. portSAVE_CONTEXT MACRO
  76. #if configDATA_MODE == 1 ; Using the Tiny data model
  77. prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},76,sp ; save general purpose registers
  78. sst.w r19,72[ep]
  79. sst.w r18,68[ep]
  80. sst.w r17,64[ep]
  81. sst.w r16,60[ep]
  82. sst.w r15,56[ep]
  83. sst.w r14,52[ep]
  84. sst.w r13,48[ep]
  85. sst.w r12,44[ep]
  86. sst.w r11,40[ep]
  87. sst.w r10,36[ep]
  88. sst.w r9,32[ep]
  89. sst.w r8,28[ep]
  90. sst.w r7,24[ep]
  91. sst.w r6,20[ep]
  92. sst.w r5,16[ep]
  93. sst.w r4,12[ep]
  94. #else ; Using the Small/Large data model
  95. prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},72,sp ; save general purpose registers
  96. sst.w r19,68[ep]
  97. sst.w r18,64[ep]
  98. sst.w r17,60[ep]
  99. sst.w r16,56[ep]
  100. sst.w r15,52[ep]
  101. sst.w r14,48[ep]
  102. sst.w r13,44[ep]
  103. sst.w r12,40[ep]
  104. sst.w r11,36[ep]
  105. sst.w r10,32[ep]
  106. sst.w r9,28[ep]
  107. sst.w r8,24[ep]
  108. sst.w r7,20[ep]
  109. sst.w r6,16[ep]
  110. sst.w r5,12[ep]
  111. #endif /* configDATA_MODE */
  112. sst.w r2,8[ep]
  113. sst.w r1,4[ep]
  114. MOVHI hi1(usCriticalNesting),r0,r1 ; save usCriticalNesting value to stack
  115. ld.w lw1(usCriticalNesting)[r1],r2
  116. sst.w r2,0[ep]
  117. MOVHI hi1(pxCurrentTCB),r0,r1 ; save SP to top of current TCB
  118. ld.w lw1(pxCurrentTCB)[r1],r2
  119. st.w sp,0[r2]
  120. ENDM
  121. ;------------------------------------------------------------------------------
  122. ;------------------------------------------------------------------------------
  123. ; portRESTORE_CONTEXT MACRO
  124. ; Gets stack pointer from the current TCB
  125. ; Restores the context of the usCriticalNesting value and general purpose
  126. ; registers of the selected task from the task stack
  127. ;------------------------------------------------------------------------------
  128. portRESTORE_CONTEXT MACRO
  129. MOVHI hi1(pxCurrentTCB),r0,r1 ; get Stackpointer address
  130. ld.w lw1(pxCurrentTCB)[r1],sp
  131. MOV sp,r1
  132. ld.w 0[r1],sp ; load stackpointer
  133. MOV sp,ep ; set stack pointer to element pointer
  134. sld.w 0[ep],r1 ; load usCriticalNesting value from stack
  135. MOVHI hi1(usCriticalNesting),r0,r2
  136. st.w r1,lw1(usCriticalNesting)[r2]
  137. sld.w 4[ep],r1 ; restore general purpose registers
  138. sld.w 8[ep],r2
  139. #if configDATA_MODE == 1 ; Using Tiny data model
  140. sld.w 12[ep],r4
  141. sld.w 16[ep],r5
  142. sld.w 20[ep],r6
  143. sld.w 24[ep],r7
  144. sld.w 28[ep],r8
  145. sld.w 32[ep],r9
  146. sld.w 36[ep],r10
  147. sld.w 40[ep],r11
  148. sld.w 44[ep],r12
  149. sld.w 48[ep],r13
  150. sld.w 52[ep],r14
  151. sld.w 56[ep],r15
  152. sld.w 60[ep],r16
  153. sld.w 64[ep],r17
  154. sld.w 68[ep],r18
  155. sld.w 72[ep],r19
  156. dispose 76,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}
  157. #else ; Using Small/Large data model
  158. sld.w 12[ep],r5
  159. sld.w 16[ep],r6
  160. sld.w 20[ep],r7
  161. sld.w 24[ep],r8
  162. sld.w 28[ep],r9
  163. sld.w 32[ep],r10
  164. sld.w 36[ep],r11
  165. sld.w 40[ep],r12
  166. sld.w 44[ep],r13
  167. sld.w 48[ep],r14
  168. sld.w 52[ep],r15
  169. sld.w 56[ep],r16
  170. sld.w 60[ep],r17
  171. sld.w 64[ep],r18
  172. sld.w 68[ep],r19
  173. dispose 72,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
  174. #endif /* configDATA_MODE */
  175. ENDM
  176. ;------------------------------------------------------------------------------
  177. ;------------------------------------------------------------------------------
  178. ; Restore the context of the first task that is going to run.
  179. ;
  180. ; Input: NONE
  181. ;
  182. ; Call: CALL vPortStart
  183. ;
  184. ; Output: NONE
  185. ;------------------------------------------------------------------------------
  186. RSEG CODE:CODE
  187. vPortStart:
  188. portRESTORE_CONTEXT ; Restore the context of whichever task the ...
  189. ld.w 0[sp],lp
  190. ldsr lp,5 ; restore PSW
  191. DI
  192. ld.w 4[sp],lp ; restore LP
  193. ld.w 8[sp],lp ; restore LP
  194. ADD 0x0C,sp ; set SP to right position
  195. EI
  196. jmp [lp]
  197. ;------------------------------------------------------------------------------
  198. ;------------------------------------------------------------------------------
  199. ; Port Yield function to check for a Task switch in the cooperative and
  200. ; preemptive mode
  201. ;
  202. ; Input: NONE
  203. ;
  204. ; Call: CALL vPortYield
  205. ;
  206. ; Output: NONE
  207. ;------------------------------------------------------------------------------
  208. RSEG CODE:CODE
  209. vPortYield:
  210. add -0x0C,sp ; prepare stack to save necessary values
  211. st.w lp,8[sp] ; store LP to stack
  212. stsr 0,r31
  213. st.w lp,4[sp] ; store EIPC to stack
  214. stsr 1,lp
  215. st.w lp,0[sp] ; store EIPSW to stack
  216. portSAVE_CONTEXT ; Save the context of the current task.
  217. jarl vTaskSwitchContext,lp ; Call the scheduler.
  218. portRESTORE_CONTEXT ; Restore the context of whichever task the ...
  219. ; ... scheduler decided should run.
  220. ld.w 0[sp],lp ; restore EIPSW from stack
  221. ldsr lp,1
  222. ld.w 4[sp],lp ; restore EIPC from stack
  223. ldsr lp,0
  224. ld.w 8[sp],lp ; restore LP from stack
  225. add 0x0C,sp ; set SP to right position
  226. RETI
  227. ;------------------------------------------------------------------------------
  228. ;------------------------------------------------------------------------------
  229. ; Perform the necessary steps of the Tick Count Increment and Task Switch
  230. ; depending on the chosen kernel configuration
  231. ;
  232. ; Input: NONE
  233. ;
  234. ; Call: ISR
  235. ;
  236. ; Output: NONE
  237. ;------------------------------------------------------------------------------
  238. #if configUSE_PREEMPTION == 1 ; use preemptive kernel mode
  239. MD_INTTM0EQ0:
  240. add -0x0C,sp ; prepare stack to save necessary values
  241. st.w lp,8[sp] ; store LP to stack
  242. stsr 0,r31
  243. st.w lp,4[sp] ; store EIPC to stack
  244. stsr 1,lp
  245. st.w lp,0[sp] ; store EIPSW to stack
  246. portSAVE_CONTEXT ; Save the context of the current task.
  247. jarl xTaskIncrementTick,lp ; Call the timer tick function.
  248. jarl vTaskSwitchContext,lp ; Call the scheduler.
  249. portRESTORE_CONTEXT ; Restore the context of whichever task the ...
  250. ; ... scheduler decided should run.
  251. ld.w 0[sp],lp ; restore EIPSW from stack
  252. ldsr lp,1
  253. ld.w 4[sp],lp ; restore EIPC from stack
  254. ldsr lp,0
  255. ld.w 8[sp],lp ; restore LP from stack
  256. add 0x0C,sp ; set SP to right position
  257. RETI
  258. ;------------------------------------------------------------------------------
  259. #else ; use cooperative kernel mode
  260. MD_INTTM0EQ0:
  261. prepare {lp,ep},8,sp
  262. sst.w r1,4[ep]
  263. sst.w r5,0[ep]
  264. jarl xTaskIncrementTick,lp ; Call the timer tick function.
  265. sld.w 0[ep],r5
  266. sld.w 4[ep],r1
  267. dispose 8,{lp,ep}
  268. RETI
  269. #endif /* configUSE_PREEMPTION */
  270. ;------------------------------------------------------------------------------
  271. COMMON INTVEC:CODE:ROOT(2)
  272. ORG 608
  273. `??MD_INTTM0EQ0??INTVEC 608`:
  274. JR MD_INTTM0EQ0
  275. RSEG NEAR_ID:CONST:SORT:NOROOT(2)
  276. `?<Initializer for usCriticalNesting>`:
  277. DW 10
  278. COMMON INTVEC:CODE:ROOT(2)
  279. ORG 40H
  280. `??vPortYield??INTVEC 40`:
  281. JR vPortYield
  282. ;------------------------------------------------------------------------------
  283. ; set microcontroller security ID
  284. COMMON INTVEC:CODE:ROOT(2)
  285. ORG 70H
  286. `SECUID`:
  287. DB CG_SECURITY0
  288. DB CG_SECURITY1
  289. DB CG_SECURITY2
  290. DB CG_SECURITY3
  291. DB CG_SECURITY4
  292. DB CG_SECURITY5
  293. DB CG_SECURITY6
  294. DB CG_SECURITY7
  295. DB CG_SECURITY8
  296. DB CG_SECURITY9
  297. ;------------------------------------------------------------------------------
  298. ; set microcontroller option bytes
  299. COMMON INTVEC:CODE:ROOT(2)
  300. ORG 7AH
  301. `OPTBYTES`:
  302. DB CG_OPTION7A
  303. DB CG_OPTION7B
  304. DB OPT7C
  305. DB OPT7D
  306. DB OPT7E
  307. DB OPT7F
  308. END