/ components / freertos / test / test_context_save_clobber.S
test_context_save_clobber.S
 1  /* Helper function for the test case in test_context_save_clobber.c */
 2  
 3  #if defined(__XTENSA__)
 4  #include "xtensa/config/core-isa.h"
 5  #if defined(XCHAL_HAVE_WINDOWED)
 6  
 7      .data
 8  recursion_count:
 9      .word 0
10  
11      .text
12      .global     test_context_save_clober_func
13      .type       test_context_save_clober_func,@function
14      .align      4
15  
16  /* This function recursively calls itself via call4, making sure each frame
17   * uses only 4 registers. For this reason, recursion count can not be
18   * a function argument (it would have to be in a6) and is placed into .data
19   * section above.
20   */
21  test_context_save_clober_func:
22      entry a1, 16
23  
24      /* load recursion count from memory */
25      movi a3, recursion_count
26      l32i a2, a3, 0
27  
28      /* if it is zero, initialize it to 16 (=64 physical registers / 4 registers per call) */
29      bnez a2, 1f
30      movi a2, 16
31  1:
32  
33      /* decrement the counter and write it back */
34      addi a2, a2, -1
35      s32i a2, a3, 0
36  
37      /* counter not zero? do a recursive call */
38      beqz a2, wait
39      call4 test_context_save_clober_func
40      j end
41  
42  wait:
43      /* Counter has reached zero, and we have 16 frames on the stack.
44       * Delay for a few seconds, expecting in interrupt to happen.
45       */
46      movi a3, 100000000
47  1:
48      addi a3, a3, -1
49      bnez a3, 1b
50  
51  end:
52      retw
53  
54  #endif // XCHAL_HAVE_WINDOWED
55  #endif // __XTENSA__