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/**   Initialize                                                          */
19/**                                                                       */
20/**************************************************************************/
21/**************************************************************************/
22
23    .section .data
24    .global  __tx_free_memory_start
25__tx_free_memory_start:
26
27
28    .section .text
29/**************************************************************************/
30/*                                                                        */
31/*  FUNCTION                                               RELEASE        */
32/*                                                                        */
33/*    _tx_initialize_low_level                           RISC-V64/GNU     */
34/*                                                           6.2.1        */
35/*  AUTHOR                                                                */
36/*                                                                        */
37/*    Scott Larson, Microsoft Corporation                                 */
38/*                                                                        */
39/*  DESCRIPTION                                                           */
40/*                                                                        */
41/*    This function is responsible for any low-level processor            */
42/*    initialization, including setting up interrupt vectors, setting     */
43/*    up a periodic timer interrupt source, saving the system stack       */
44/*    pointer for use in ISR processing later, and finding the first      */
45/*    available RAM memory address for tx_application_define.             */
46/*                                                                        */
47/*  INPUT                                                                 */
48/*                                                                        */
49/*    None                                                                */
50/*                                                                        */
51/*  OUTPUT                                                                */
52/*                                                                        */
53/*    None                                                                */
54/*                                                                        */
55/*  CALLS                                                                 */
56/*                                                                        */
57/*    None                                                                */
58/*                                                                        */
59/*  CALLED BY                                                             */
60/*                                                                        */
61/*    _tx_initialize_kernel_enter           ThreadX entry function        */
62/*                                                                        */
63/*  RELEASE HISTORY                                                       */
64/*                                                                        */
65/*    DATE              NAME                      DESCRIPTION             */
66/*                                                                        */
67/*  03-08-2023      Scott Larson            Initial Version 6.2.1         */
68/*                                                                        */
69/**************************************************************************/
70/* VOID   _tx_initialize_low_level(VOID)
71{  */
72    .global  _tx_initialize_low_level
73_tx_initialize_low_level:
74    sd      sp, _tx_thread_system_stack_ptr, t0     // Save system stack pointer
75
76    la      t0, __tx_free_memory_start              // Pickup first free address
77    sd      t0, _tx_initialize_unused_memory, t1    // Save unused memory address
78
79#ifdef __riscv_flen
80    fscsr x0
81#endif
82
83    ret
84
85
86    /* Define the actual timer interrupt/exception handler.  */
87
88    .global  timer1_plic_IRQHandler
89    //.global  __minterrupt_000007
90    //EXTWEAK __require_minterrupt_vector_table
91timer1_plic_IRQHandler:
92//__minterrupt_000007:
93    //REQUIRE __require_minterrupt_vector_table
94
95
96    /* Before calling _tx_thread_context_save, we have to allocate an interrupt
97       stack frame and save the current value of x1 (ra). */
98//#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
99//    addi    sp, sp, -520                            // Allocate space for all registers - with floating point enabled
100//#else
101//    addi    sp, sp, -256                            // Allocate space for all registers - without floating point enabled
102//#endif
103//    sd      x1, 224(sp)                             // Store RA
104//    call    _tx_thread_context_save                 // Call ThreadX context save
105
106    /* Call the ThreadX timer routine.  */
107    call    _tx_timer_interrupt                     // Call timer interrupt handler
108    call    timer1_interrupt
109    ret
110    /* Timer interrupt processing is done, jump to ThreadX context restore.  */
111//    j       _tx_thread_context_restore              // Jump to ThreadX context restore function. Note: this does not return!
112