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