Migrates plain ThreadX to the upstream RISC-V ports
Keeps the Moonlight startup objects local to the board. Updates the plain and SMP VP regression harnesses for the new ThreadX revision and replaces generated ISR hooks with direct callbacks.
This commit is contained in:
1 parent
26fd407a1e
commit
d404e17e5a
22 files changed
+148
-2311
No files matched your search
@@ -1,371 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CSR_H
|
||||
#define CSR_H
|
||||
|
||||
// Machine Status Register, mstatus
|
||||
#define MSTATUS_MPP_MASK (3L << 11) // previous mode.
|
||||
#define MSTATUS_MPP_M (3L << 11)
|
||||
#define MSTATUS_MPP_S (1L << 11)
|
||||
#define MSTATUS_MPP_U (0L << 11)
|
||||
#define MSTATUS_MIE (1L << 3) // machine-mode interrupt enable.
|
||||
#define MSTATUS_MPIE (1L << 7)
|
||||
#define MSTATUS_FS (1L << 13)
|
||||
|
||||
// Machine-mode Interrupt Enable
|
||||
#define MIE_MTIE (1L << 7)
|
||||
#define MIE_MSIE (1L << 3)
|
||||
#define MIE_MEIE (1L << 11)
|
||||
#define MIE_STIE (1L << 5) // supervisor timer
|
||||
#define MIE_SSIE (1L << 1)
|
||||
#define MIE_SEIE (1L << 9)
|
||||
|
||||
// Supervisor Status Register, sstatus
|
||||
#define SSTATUS_SPP (1L << 8) // Previous mode, 1=Supervisor, 0=User
|
||||
#define SSTATUS_SPIE (1L << 5) // Supervisor Previous Interrupt Enable
|
||||
#define SSTATUS_UPIE (1L << 4) // User Previous Interrupt Enable
|
||||
#define SSTATUS_SIE (1L << 1) // Supervisor Interrupt Enable
|
||||
#define SSTATUS_UIE (1L << 0) // User Interrupt Enable
|
||||
#define SSTATUS_SPIE (1L << 5)
|
||||
#define SSTATUS_UPIE (1L << 4)
|
||||
|
||||
// Supervisor Interrupt Enable
|
||||
#define SIE_SEIE (1L << 9) // external
|
||||
#define SIE_STIE (1L << 5) // timer
|
||||
#define SIE_SSIE (1L << 1) // software
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static inline uint64_t riscv_get_core()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, mhartid" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_mstatus()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, mstatus" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_mstatus(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw mstatus, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// machine exception program counter, holds the
|
||||
// instruction address to which a return from
|
||||
// exception will go.
|
||||
static inline void riscv_writ_mepc(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw mepc, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_sstatus()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, sstatus" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_sstatus(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw sstatus, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// Supervisor Interrupt Pending
|
||||
static inline uint64_t riscv_get_sip()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, sip" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_sip(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw sip, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_sie()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, sie" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_sie(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw sie, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_mie()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, mie" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_mie(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw mie, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// supervisor exception program counter, holds the
|
||||
// instruction address to which a return from
|
||||
// exception will go.
|
||||
static inline void riscv_writ_sepc(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw sepc, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_sepc()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, sepc" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// Machine Exception Delegation
|
||||
static inline uint64_t riscv_get_medeleg()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, medeleg" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_medeleg(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw medeleg, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// Machine Interrupt Delegation
|
||||
static inline uint64_t riscv_get_mideleg()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, mideleg" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_mideleg(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw mideleg, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// Supervisor Trap-Vector Base Address
|
||||
// low two bits are mode.
|
||||
static inline void riscv_writ_stvec(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw stvec, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_stvec()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, stvec" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// Supervisor Timer Comparison Register
|
||||
static inline uint64_t riscv_get_stimecmp()
|
||||
{
|
||||
uint64_t x;
|
||||
// asm volatile("csrr %0, stimecmp" : "=r" (x) );
|
||||
asm volatile("csrr %0, 0x14d" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_stimecmp(uint64_t x)
|
||||
{
|
||||
// asm volatile("csrw stimecmp, %0" : : "r" (x));
|
||||
asm volatile("csrw 0x14d, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// Machine Environment Configuration Register
|
||||
static inline uint64_t riscv_get_menvcfg()
|
||||
{
|
||||
uint64_t x;
|
||||
// asm volatile("csrr %0, menvcfg" : "=r" (x) );
|
||||
asm volatile("csrr %0, 0x30a" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_menvcfg(uint64_t x)
|
||||
{
|
||||
// asm volatile("csrw menvcfg, %0" : : "r" (x));
|
||||
asm volatile("csrw 0x30a, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// Physical Memory Protection
|
||||
static inline void riscv_writ_pmpcfg0(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw pmpcfg0, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline void riscv_writ_pmpaddr0(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw pmpaddr0, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
// supervisor address translation and protection;
|
||||
// holds the address of the page table.
|
||||
static inline void riscv_writ_satp(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw satp, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_satp()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, satp" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// Supervisor Trap Cause
|
||||
static inline uint64_t riscv_get_scause()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, scause" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// Supervisor Trap Value
|
||||
static inline uint64_t riscv_get_stval()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, stval" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// Machine-mode Counter-Enable
|
||||
static inline void riscv_writ_mcounteren(uint64_t x)
|
||||
{
|
||||
asm volatile("csrw mcounteren, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_mcounteren()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, mcounteren" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// machine-mode cycle counter
|
||||
static inline uint64_t riscv_get_time()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("csrr %0, time" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// enable device interrupts
|
||||
static inline void riscv_sintr_on()
|
||||
{
|
||||
uint64_t sstatus = riscv_get_sstatus();
|
||||
sstatus |= SSTATUS_SIE;
|
||||
riscv_writ_sstatus(sstatus);
|
||||
}
|
||||
|
||||
// disable device interrupts
|
||||
static inline void riscv_sintr_off()
|
||||
{
|
||||
uint64_t sstatus = riscv_get_sstatus();
|
||||
sstatus &= (~SSTATUS_SIE);
|
||||
riscv_writ_sstatus(sstatus);
|
||||
}
|
||||
|
||||
// are device interrupts enabled?
|
||||
static inline int riscv_sintr_get()
|
||||
{
|
||||
uint64_t x = riscv_get_sstatus();
|
||||
return (x & SSTATUS_SIE) != 0;
|
||||
}
|
||||
|
||||
static inline void riscv_sintr_restore(int x)
|
||||
{
|
||||
if (x)
|
||||
riscv_sintr_on();
|
||||
else
|
||||
riscv_sintr_off();
|
||||
}
|
||||
|
||||
// enable device interrupts
|
||||
static inline void riscv_mintr_on()
|
||||
{
|
||||
uint64_t mstatus = riscv_get_mstatus();
|
||||
mstatus |= MSTATUS_MIE;
|
||||
riscv_writ_mstatus(mstatus);
|
||||
}
|
||||
|
||||
// disable device interrupts
|
||||
static inline void riscv_mintr_off()
|
||||
{
|
||||
uint64_t mstatus = riscv_get_mstatus();
|
||||
mstatus &= (~MSTATUS_MIE);
|
||||
riscv_writ_mstatus(mstatus);
|
||||
}
|
||||
|
||||
// are device interrupts enabled?
|
||||
static inline int riscv_mintr_get()
|
||||
{
|
||||
uint64_t x = riscv_get_mstatus();
|
||||
return (x & MSTATUS_MIE) != 0;
|
||||
}
|
||||
|
||||
static inline void riscv_mintr_restore(int x)
|
||||
{
|
||||
if (x)
|
||||
riscv_mintr_on();
|
||||
else
|
||||
riscv_mintr_off();
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_sp()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("mv %0, sp" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// read and write tp, the thread pointer, which xv6 uses to hold
|
||||
// this core's hartid (core number), the index into cpus[].
|
||||
static inline uint64_t riscv_get_tp()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("mv %0, tp" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void riscv_writ_tp(uint64_t x)
|
||||
{
|
||||
asm volatile("mv tp, %0" : : "r"(x));
|
||||
}
|
||||
|
||||
static inline uint64_t riscv_get_ra()
|
||||
{
|
||||
uint64_t x;
|
||||
asm volatile("mv %0, ra" : "=r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
// flush the TLB.
|
||||
static inline void sfence_vma()
|
||||
{
|
||||
// the zero, zero means flush all TLB entries.
|
||||
asm volatile("sfence.vma zero, zero");
|
||||
}
|
||||
|
||||
#endif // __ASSEMBLER__
|
||||
|
||||
#endif
|
||||
@@ -1,425 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** Port Specific */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* PORT SPECIFIC C INFORMATION RELEASE */
|
||||
/* */
|
||||
/* tx_port.h RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file contains data type definitions that make the ThreadX */
|
||||
/* real-time kernel function identically on a variety of different */
|
||||
/* processor architectures. For example, the size or number of bits */
|
||||
/* in an "int" data type vary between microprocessor architectures and */
|
||||
/* even C compilers for the same microprocessor. ThreadX does not */
|
||||
/* directly use native C data types. Instead, ThreadX creates its */
|
||||
/* own special types that can be mapped to actual data types by this */
|
||||
/* file to guarantee consistency in the interface and functionality. */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TX_PORT_H
|
||||
#define TX_PORT_H
|
||||
|
||||
#ifdef __ASSEMBLER__
|
||||
|
||||
#if __riscv_xlen == 64
|
||||
#define SLL32 sllw
|
||||
#define STORE sd
|
||||
#define LOAD ld
|
||||
#define LWU lwu
|
||||
#define LOG_REGBYTES 3
|
||||
#else
|
||||
#define SLL32 sll
|
||||
#define STORE sw
|
||||
#define LOAD lw
|
||||
#define LWU lw
|
||||
#define LOG_REGBYTES 2
|
||||
#endif
|
||||
#define REGBYTES (1 << LOG_REGBYTES)
|
||||
|
||||
#define TX_CONTEXT_ALIGN(size) (((size) + 15) & -16)
|
||||
|
||||
/* Keep the existing hard-float enable policy. Save the full hardware register
|
||||
* width, even when the calling convention uses narrower floating-point values.
|
||||
*/
|
||||
#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
|
||||
#define TX_CONTEXT_FP_ENABLED 1
|
||||
#if __riscv_flen == 64
|
||||
#define TX_FP_BYTES 8
|
||||
#define TX_FP_LOAD fld
|
||||
#define TX_FP_STORE fsd
|
||||
#elif __riscv_flen == 32
|
||||
#define TX_FP_BYTES 4
|
||||
#define TX_FP_LOAD flw
|
||||
#define TX_FP_STORE fsw
|
||||
#else
|
||||
#error "Unsupported RISC-V floating-point register width"
|
||||
#endif
|
||||
#else
|
||||
#define TX_CONTEXT_FP_ENABLED 0
|
||||
#define TX_FP_BYTES 0
|
||||
#endif
|
||||
|
||||
/* Integer slots 0..30 contain the interrupt context; slot 31 is padding.
|
||||
* Voluntary switches use slots 0..14; slot 15 is padding. Starting the FP
|
||||
* areas at these boundaries aligns double registers on RV32 as well as RV64.
|
||||
*/
|
||||
#define TX_INTERRUPT_FP_BASE (32 * REGBYTES)
|
||||
#define TX_SOLICITED_FP_BASE (16 * REGBYTES)
|
||||
#define TX_INTERRUPT_FP_OFFSET(n) (TX_INTERRUPT_FP_BASE + (n) * TX_FP_BYTES)
|
||||
/* Solicited FP indices: fs0, fs1, fs2, ... fs11 (not architectural numbers). */
|
||||
#define TX_SOLICITED_FP_OFFSET(n) (TX_SOLICITED_FP_BASE + (n) * TX_FP_BYTES)
|
||||
#define TX_INTERRUPT_FCSR_OFFSET TX_INTERRUPT_FP_OFFSET(32)
|
||||
#define TX_SOLICITED_FCSR_OFFSET TX_SOLICITED_FP_OFFSET(12)
|
||||
|
||||
/* fcsr follows the FP registers and occupies one REGBYTES slot because
|
||||
* it is accessed with integer LOAD/STORE. Round the complete frame up to
|
||||
* 16 bytes so allocating or releasing it preserves stack alignment. Without
|
||||
* FP support, the frame contains only the integer slots and their padding.
|
||||
*/
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
#define TX_INTERRUPT_FRAME_SIZE TX_CONTEXT_ALIGN(TX_INTERRUPT_FCSR_OFFSET + REGBYTES)
|
||||
#define TX_SOLICITED_FRAME_SIZE TX_CONTEXT_ALIGN(TX_SOLICITED_FCSR_OFFSET + REGBYTES)
|
||||
#else
|
||||
#define TX_INTERRUPT_FRAME_SIZE TX_INTERRUPT_FP_BASE
|
||||
#define TX_SOLICITED_FRAME_SIZE TX_SOLICITED_FP_BASE
|
||||
#endif
|
||||
|
||||
#else /*not __ASSEMBLER__ */
|
||||
|
||||
/* Determine if the optional ThreadX user define file should be used. */
|
||||
|
||||
#ifdef TX_INCLUDE_USER_DEFINE_FILE
|
||||
|
||||
/* Yes, include the user defines in tx_user.h. The defines in this file may
|
||||
alternately be defined on the command line. */
|
||||
|
||||
#include "tx_user.h"
|
||||
#endif
|
||||
|
||||
/* Define compiler library include files. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Define ThreadX basic types for this port. */
|
||||
|
||||
#define VOID void
|
||||
typedef char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long long ULONG64;
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
#define ULONG64_DEFINED
|
||||
|
||||
/* Define the priority levels for ThreadX. Legal values range
|
||||
from 32 to 1024 and MUST be evenly divisible by 32. */
|
||||
|
||||
#ifndef TX_MAX_PRIORITIES
|
||||
#define TX_MAX_PRIORITIES 32
|
||||
#endif
|
||||
|
||||
/* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
|
||||
thread creation is less than this value, the thread create call will return an error. */
|
||||
|
||||
#ifndef TX_MINIMUM_STACK
|
||||
#define TX_MINIMUM_STACK 1024 /* Minimum stack size for this port */
|
||||
#endif
|
||||
|
||||
/* Define the system timer thread's default stack size and priority. These are only applicable
|
||||
if TX_TIMER_PROCESS_IN_ISR is not defined. */
|
||||
|
||||
#ifndef TX_TIMER_THREAD_STACK_SIZE
|
||||
#define TX_TIMER_THREAD_STACK_SIZE 1024 /* Default timer thread stack size */
|
||||
#endif
|
||||
|
||||
#ifndef TX_TIMER_THREAD_PRIORITY
|
||||
#define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */
|
||||
#endif
|
||||
|
||||
/* Define various constants for the ThreadX RISC-V port. */
|
||||
|
||||
#define TX_INT_DISABLE 0x00000000 /* Disable interrupts value */
|
||||
#define TX_INT_ENABLE 0x00000008 /* Enable interrupt value */
|
||||
|
||||
/* Define the clock source for trace event entry time stamp. The following two item are port specific.
|
||||
For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
|
||||
source constants would be:
|
||||
|
||||
#define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024)
|
||||
#define TX_TRACE_TIME_MASK 0x0000FFFFUL
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TX_TRACE_TIME_SOURCE
|
||||
#define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time
|
||||
#endif
|
||||
#ifndef TX_TRACE_TIME_MASK
|
||||
#define TX_TRACE_TIME_MASK 0xFFFFFFFFUL
|
||||
#endif
|
||||
|
||||
/* Define the port specific options for the _tx_build_options variable. This variable indicates
|
||||
how the ThreadX library was built. */
|
||||
|
||||
#define TX_PORT_SPECIFIC_BUILD_OPTIONS 0
|
||||
|
||||
/* Define the in-line initialization constant so that modules with in-line
|
||||
initialization capabilities can prevent their initialization from being
|
||||
a function call. */
|
||||
|
||||
#define TX_INLINE_INITIALIZATION
|
||||
|
||||
/* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
|
||||
disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack
|
||||
checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
|
||||
define is negated, thereby forcing the stack fill which is necessary for the stack checking
|
||||
logic. */
|
||||
|
||||
#ifdef TX_ENABLE_STACK_CHECKING
|
||||
#undef TX_DISABLE_STACK_FILLING
|
||||
#endif
|
||||
|
||||
/* Define the TX_THREAD control block extensions for this port. The main reason
|
||||
for the multiple macros is so that backward compatibility can be maintained with
|
||||
existing ThreadX kernel awareness modules. */
|
||||
|
||||
#define TX_THREAD_EXTENSION_0
|
||||
#define TX_THREAD_EXTENSION_1
|
||||
#define TX_THREAD_EXTENSION_2
|
||||
#define TX_THREAD_EXTENSION_3
|
||||
|
||||
/* Define the port extensions of the remaining ThreadX objects. */
|
||||
|
||||
#define TX_BLOCK_POOL_EXTENSION
|
||||
#define TX_BYTE_POOL_EXTENSION
|
||||
#define TX_EVENT_FLAGS_GROUP_EXTENSION
|
||||
#define TX_MUTEX_EXTENSION
|
||||
#define TX_QUEUE_EXTENSION
|
||||
#define TX_SEMAPHORE_EXTENSION
|
||||
#define TX_TIMER_EXTENSION
|
||||
|
||||
/* Define the user extension field of the thread control block. Nothing
|
||||
additional is needed for this port so it is defined as white space. */
|
||||
|
||||
#ifndef TX_THREAD_USER_EXTENSION
|
||||
#define TX_THREAD_USER_EXTENSION
|
||||
#endif
|
||||
|
||||
/* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
|
||||
tx_thread_shell_entry, and tx_thread_terminate. */
|
||||
|
||||
#define TX_THREAD_CREATE_EXTENSION(thread_ptr)
|
||||
#define TX_THREAD_DELETE_EXTENSION(thread_ptr)
|
||||
#define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
|
||||
#define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
|
||||
|
||||
/* Define automated regression test extensions. These are required for the
|
||||
ThreadX regression tests. */
|
||||
|
||||
typedef unsigned int TEST_FLAG;
|
||||
extern TEST_FLAG threadx_byte_allocate_loop_test;
|
||||
extern TEST_FLAG threadx_byte_release_loop_test;
|
||||
extern TEST_FLAG threadx_mutex_suspension_put_test;
|
||||
extern TEST_FLAG threadx_mutex_suspension_priority_test;
|
||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||
extern TEST_FLAG threadx_delete_timer_thread;
|
||||
#endif
|
||||
|
||||
extern void abort_and_resume_byte_allocating_thread(void);
|
||||
extern void abort_all_threads_suspended_on_mutex(void);
|
||||
extern void suspend_lowest_priority(void);
|
||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||
extern void delete_timer_thread(void);
|
||||
#endif
|
||||
extern TEST_FLAG test_stack_analyze_flag;
|
||||
extern TEST_FLAG test_initialize_flag;
|
||||
extern TEST_FLAG test_forced_mutex_timeout;
|
||||
|
||||
#ifdef TX_REGRESSION_TEST
|
||||
|
||||
/* Define extension macros for automated coverage tests. */
|
||||
|
||||
#define TX_BYTE_ALLOCATE_EXTENSION \
|
||||
if (threadx_byte_allocate_loop_test == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
pool_ptr->tx_byte_pool_owner = TX_NULL; \
|
||||
threadx_byte_allocate_loop_test = ((TEST_FLAG)0); \
|
||||
}
|
||||
|
||||
#define TX_BYTE_RELEASE_EXTENSION \
|
||||
if (threadx_byte_release_loop_test == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
threadx_byte_release_loop_test = ((TEST_FLAG)0); \
|
||||
abort_and_resume_byte_allocating_thread(); \
|
||||
}
|
||||
|
||||
#define TX_MUTEX_PUT_EXTENSION_1 \
|
||||
if (threadx_mutex_suspension_put_test == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
threadx_mutex_suspension_put_test = ((TEST_FLAG)0); \
|
||||
abort_all_threads_suspended_on_mutex(); \
|
||||
}
|
||||
|
||||
#define TX_MUTEX_PUT_EXTENSION_2 \
|
||||
if (test_forced_mutex_timeout == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
test_forced_mutex_timeout = ((TEST_FLAG)0); \
|
||||
_tx_thread_wait_abort(mutex_ptr->tx_mutex_suspension_list); \
|
||||
}
|
||||
|
||||
#define TX_MUTEX_PRIORITY_CHANGE_EXTENSION \
|
||||
if (threadx_mutex_suspension_priority_test == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
threadx_mutex_suspension_priority_test = ((TEST_FLAG)0); \
|
||||
suspend_lowest_priority(); \
|
||||
}
|
||||
|
||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||
|
||||
#define TX_TIMER_INITIALIZE_EXTENSION(a) \
|
||||
if (threadx_delete_timer_thread == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
threadx_delete_timer_thread = ((TEST_FLAG)0); \
|
||||
delete_timer_thread(); \
|
||||
(a) = ((UINT)1); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define TX_THREAD_STACK_ANALYZE_EXTENSION \
|
||||
if (test_stack_analyze_flag == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
thread_ptr->tx_thread_id = ((TEST_FLAG)0); \
|
||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
||||
} \
|
||||
else if (test_stack_analyze_flag == ((TEST_FLAG)2)) \
|
||||
{ \
|
||||
stack_ptr = thread_ptr->tx_thread_stack_start; \
|
||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
||||
} \
|
||||
else if (test_stack_analyze_flag == ((TEST_FLAG)3)) \
|
||||
{ \
|
||||
*stack_ptr = TX_STACK_FILL; \
|
||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
test_stack_analyze_flag = ((TEST_FLAG)0); \
|
||||
}
|
||||
|
||||
#define TX_INITIALIZE_KERNEL_ENTER_EXTENSION \
|
||||
if (test_initialize_flag == ((TEST_FLAG)1)) \
|
||||
{ \
|
||||
test_initialize_flag = ((TEST_FLAG)0); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Define the ThreadX object creation extensions for the remaining objects. */
|
||||
|
||||
#define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
|
||||
#define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
|
||||
#define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
|
||||
#define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
|
||||
#define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
|
||||
#define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
|
||||
#define TX_TIMER_CREATE_EXTENSION(timer_ptr)
|
||||
|
||||
/* Define the ThreadX object deletion extensions for the remaining objects. */
|
||||
|
||||
#define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
|
||||
#define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
|
||||
#define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
|
||||
#define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
|
||||
#define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
|
||||
#define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
|
||||
#define TX_TIMER_DELETE_EXTENSION(timer_ptr)
|
||||
|
||||
/* Define ThreadX interrupt lockout and restore macros for protection on
|
||||
access of critical kernel information. The restore interrupt macro must
|
||||
restore the interrupt posture of the running thread prior to the value
|
||||
present prior to the disable macro. In most cases, the save area macro
|
||||
is used to define a local function save area for the disable and restore
|
||||
macros. */
|
||||
|
||||
#ifdef TX_DISABLE_INLINE
|
||||
|
||||
ULONG _tx_thread_interrupt_control(unsigned int new_posture);
|
||||
|
||||
#define TX_INTERRUPT_SAVE_AREA register ULONG tx_saved_posture;
|
||||
|
||||
#define TX_DISABLE tx_saved_posture = _tx_thread_interrupt_control(TX_INT_DISABLE);
|
||||
#define TX_RESTORE _tx_thread_interrupt_control(tx_saved_posture);
|
||||
|
||||
#else
|
||||
|
||||
#define TX_INTERRUPT_SAVE_AREA ULONG tx_saved_posture;
|
||||
/* Atomically read mstatus into tx_saved_posture and clear bit 3 of mstatus. */
|
||||
#define TX_DISABLE \
|
||||
{ \
|
||||
__asm__ volatile("csrrci %0, mstatus, 0x08" : "=r"(tx_saved_posture) : : "memory"); \
|
||||
};
|
||||
/* We only care about mstatus.mie (bit 3), so mask tx_saved_posture and write to mstatus. */
|
||||
#define TX_RESTORE \
|
||||
{ \
|
||||
register ULONG __tempmask = tx_saved_posture & 0x08; \
|
||||
__asm__ volatile("csrrs x0, mstatus, %0" : : "r"(__tempmask) : "memory"); \
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* Define the interrupt lockout macros for each ThreadX object. */
|
||||
|
||||
#define TX_BLOCK_POOL_DISABLE TX_DISABLE
|
||||
#define TX_BYTE_POOL_DISABLE TX_DISABLE
|
||||
#define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE
|
||||
#define TX_MUTEX_DISABLE TX_DISABLE
|
||||
#define TX_QUEUE_DISABLE TX_DISABLE
|
||||
#define TX_SEMAPHORE_DISABLE TX_DISABLE
|
||||
|
||||
/* Define the version ID of ThreadX. This may be utilized by the application. */
|
||||
|
||||
#ifdef TX_THREAD_INIT
|
||||
CHAR _tx_version_id[] = "Copyright (c) 2024 Microsoft Corporation. * ThreadX RISC-V64/GNU Version 6.4.2 *";
|
||||
#else
|
||||
extern CHAR _tx_version_id[];
|
||||
#endif
|
||||
|
||||
#endif /*not __ASSEMBLER__ */
|
||||
#endif
|
||||
@@ -69,6 +69,11 @@
|
||||
#ifndef TX_USER_H
|
||||
#define TX_USER_H
|
||||
|
||||
#if __riscv_xlen == 64 && !defined(__ASSEMBLER__)
|
||||
/* NetX Duo uses this field to pass pointers to IP helper threads. */
|
||||
#define TX_THREAD_USER_EXTENSION void *tx_thread_extension_ptr;
|
||||
#endif
|
||||
|
||||
/* Define various build options for the ThreadX port. The application should either make changes
|
||||
here by commenting or un-commenting the conditional compilation defined OR supply the defines
|
||||
though the compiler's equivalent of the -D option.
|
||||
|
||||
Reference in new issue
Block a user