1;/*************************************************************************** 2; * Copyright (c) 2024 Microsoft Corporation 3; * 4; * This program and the accompanying materials are made available under the 5; * terms of the MIT License which is available at 6; * https://opensource.org/licenses/MIT. 7; * 8; * SPDX-License-Identifier: MIT 9; **************************************************************************/ 10; 11; 12;/**************************************************************************/ 13;/**************************************************************************/ 14;/** */ 15;/** ThreadX Component */ 16;/** */ 17;/** Thread */ 18;/** */ 19;/**************************************************************************/ 20;/**************************************************************************/ 21; 22; 23;#define TX_SOURCE_CODE 24; 25; 26;/* Include necessary system files. */ 27; 28;#include "tx_api.h" 29;#include "tx_thread.h" 30; 31; 32 .SECTION P,CODE 33;/**************************************************************************/ 34;/* */ 35;/* FUNCTION RELEASE */ 36;/* */ 37;/* _tx_thread_stack_build RXv3/CCRX */ 38;/* 6.1.11 */ 39;/* AUTHOR */ 40;/* */ 41;/* William E. Lamie, Microsoft Corporation */ 42;/* */ 43;/* DESCRIPTION */ 44;/* */ 45;/* This function builds a stack frame on the supplied thread's stack. */ 46;/* The stack frame results in a fake interrupt return to the supplied */ 47;/* function pointer. */ 48;/* */ 49;/* INPUT */ 50;/* */ 51;/* thread_ptr Pointer to thread control blk */ 52;/* function_ptr Pointer to return function */ 53;/* */ 54;/* OUTPUT */ 55;/* */ 56;/* None */ 57;/* */ 58;/* CALLS */ 59;/* */ 60;/* None */ 61;/* */ 62;/* CALLED BY */ 63;/* */ 64;/* _tx_thread_create Create thread service */ 65;/* */ 66;/* RELEASE HISTORY */ 67;/* */ 68;/* DATE NAME DESCRIPTION */ 69;/* */ 70;/* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 71;/* 10-15-2021 William E. Lamie Modified comment(s), */ 72;/* resulting in version 6.1.9 */ 73;/* 01-31-2022 William E. Lamie Modified comment(s), */ 74;/* resulting in version 6.1.10 */ 75;/* 04-25-2022 William E. Lamie Modified comment(s), */ 76;/* resulting in version 6.1.11 */ 77;/* */ 78;/**************************************************************************/ 79;VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID)) 80;{ 81 .GLB __tx_thread_stack_build 82__tx_thread_stack_build: 83; 84; 85; /* Build an interrupt frame. The form of the fake interrupt stack 86; on the Renesas RX should look like the following after it is built: 87; 88; Stack Top: ACC0 89; ACC1 90; R6 91; R7 92; R8 93; R9 94; R10 95; R11 96; R12 97; R13 98; FPSW 99; R14 100; R15 101; R3 102; R4 103; R5 104; R1 105; R2 106; PC 107; PSW 108 109; 110; Stack Bottom: (higher memory address) */ 111; 112 MOV.L 16[R1],R3 ; Pickup end of stack area 113 BCLR #0, R3 ; Mask for 4-byte alignment 114 BCLR #1, R3 115; 116; /* Build the stack frame. */ 117; 118 MOV.L #30000h, R4 119 MOV.L R4, [-R3] ; Initial PSW (SVC mode, U flag set) 120 MOV.L R2, [-R3] ; Initial PC 121 MOV.L #0, R4 122 MOV.L R4,[-R3] ; Initial R2 ... 123 MOV.L R4,[-R3] ; Initial R1 ... 124 MOV.L R4,[-R3] ; Initial R5 ... 125 MOV.L R4,[-R3] ; Initial R4 ... 126 MOV.L R4,[-R3] ; Initial R3 ... 127 MOV.L R4,[-R3] ; Initial R15 ... 128 MOV.L R4,[-R3] ; Initial R14 ... 129 MVFC FPSW, r4 130 MOV.L R4, [-R3] ; Initial FPSW 131 MOV.L #0, R4 132 MOV.L R4,[-R3] ; Initial R13 ... 133 MOV.L R4,[-R3] ; Initial R12 ... 134 MOV.L R4,[-R3] ; Initial R11 ... 135 MOV.L R4,[-R3] ; Initial R10 ... 136 MOV.L R4,[-R3] ; Initial R9 ... 137 MOV.L R4,[-R3] ; Initial R8 ... 138 MOV.L R4,[-R3] ; Initial R7 ... 139 MOV.L R4,[-R3] ; Initial R6 ... 140 141 MOV.L R4,[-R3] ; Accumulator 1 142 MOV.L R4,[-R3] 143 MOV.L R4,[-R3] 144 145 MOV.L R4,[-R3] ; Accumulator 0 146 MOV.L R4,[-R3] 147 MOV.L R4,[-R3] 148 149; /* Setup stack pointer. */ 150; thread_ptr -> tx_thread_stack_ptr = R1; 151 MOV.L R3, 8[R1] 152 ; Store initial SP in thread control block 153 RTS 154 155;} 156 .END 157 158 159