1/**************************************************************************/ 2/* */ 3/* Copyright (c) Microsoft Corporation. All rights reserved. */ 4/* */ 5/* This software is licensed under the Microsoft Software License */ 6/* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8/* and in the root directory of this software. */ 9/* */ 10/**************************************************************************/ 11 12 13/**************************************************************************/ 14/**************************************************************************/ 15/** */ 16/** ThreadX Component */ 17/** */ 18/** Thread */ 19/** */ 20/**************************************************************************/ 21/**************************************************************************/ 22 23 .text 24 .align 4 25/**************************************************************************/ 26/* */ 27/* FUNCTION RELEASE */ 28/* */ 29/* _tx_thread_stack_build Cortex-Mx/GHS */ 30/* 6.1.7 */ 31/* AUTHOR */ 32/* */ 33/* Scott Larson, Microsoft Corporation */ 34/* */ 35/* DESCRIPTION */ 36/* */ 37/* This function builds a stack frame on the supplied thread's stack. */ 38/* The stack frame results in a fake interrupt return to the supplied */ 39/* function pointer. */ 40/* */ 41/* INPUT */ 42/* */ 43/* thread_ptr Pointer to thread control blk */ 44/* function_ptr Pointer to return function */ 45/* */ 46/* OUTPUT */ 47/* */ 48/* None */ 49/* */ 50/* CALLS */ 51/* */ 52/* None */ 53/* */ 54/* CALLED BY */ 55/* */ 56/* _tx_thread_create Create thread service */ 57/* */ 58/* RELEASE HISTORY */ 59/* */ 60/* DATE NAME DESCRIPTION */ 61/* */ 62/* 06-02-2021 Scott Larson Initial Version 6.1.7 */ 63/* */ 64/**************************************************************************/ 65// VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID)) 66// { 67 .globl _tx_thread_stack_build 68_tx_thread_stack_build: 69 70 /* Build a fake interrupt frame. The form of the fake interrupt stack 71 on the Cortex-M should look like the following after it is built: 72 73 Stack Top: 74 LR Interrupted LR (LR at time of PENDSV) 75 r4 Initial value for r4 76 r5 Initial value for r5 77 r6 Initial value for r6 78 r7 Initial value for r7 79 r8 Initial value for r8 80 r9 Initial value for r9 81 r10 Initial value for r10 82 r11 Initial value for r11 83 r0 Initial value for r0 (Hardware stack starts here!!) 84 r1 Initial value for r1 85 r2 Initial value for r2 86 r3 Initial value for r3 87 r12 Initial value for r12 88 lr Initial value for lr 89 pc Initial value for pc 90 xPSR Initial value for xPSR 91 92 Stack Bottom: (higher memory address) */ 93 94 LDR r2, [r0, #16] // Pickup end of stack area 95 BIC r2, r2, #0x7 // Align frame for 8-byte alignment 96 SUB r2, r2, #68 // Subtract frame size 97 LDR r3, =0xFFFFFFFD // Build initial LR value 98 STR r3, [r2, #0] // Save on the stack 99 100 /* Actually build the stack frame. */ 101 102 MOV r3, #0 // Build initial register value 103 STR r3, [r2, #4] // Store initial r4 104 STR r3, [r2, #8] // Store initial r5 105 STR r3, [r2, #12] // Store initial r6 106 STR r3, [r2, #16] // Store initial r7 107 STR r3, [r2, #20] // Store initial r8 108 STR r3, [r2, #24] // Store initial r9 109 STR r3, [r2, #28] // Store initial r10 110 STR r3, [r2, #32] // Store initial r11 111 112 /* Hardware stack follows. */ 113 114 STR r3, [r2, #36] // Store initial r0 115 STR r3, [r2, #40] // Store initial r1 116 STR r3, [r2, #44] // Store initial r2 117 STR r3, [r2, #48] // Store initial r3 118 STR r3, [r2, #52] // Store initial r12 119 MOV r3, #0xFFFFFFFF // Poison EXC_RETURN value 120 STR r3, [r2, #56] // Store initial lr 121 STR r1, [r2, #60] // Store initial pc 122 MOV r3, #0x01000000 // Only T-bit need be set 123 STR r3, [r2, #64] // Store initial xPSR 124 125 /* Setup stack pointer. */ 126 // thread_ptr -> tx_thread_stack_ptr = r2; 127 128 STR r2, [r0, #8] // Save stack pointer in thread's 129 // control block 130 BX lr // Return to caller 131// } 132 .type _tx_thread_stack_build,$function 133 .size _tx_thread_stack_build,.-_tx_thread_stack_build 134