.extern pullNextTime\r
.extern ulTimerIncrementsForOneTick\r
.extern xISRStackTop\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-.align 8\r
-xPortStartFirstTask:\r
-\r
- la t0, vPortTrapHandler\r
- csrw mtvec, t0\r
-\r
- lw sp, pxCurrentTCB /* Load pxCurrentTCB. */\r
- lw sp, 0( sp ) /* Read sp from first TCB member. */\r
-\r
- lw x1, 0( sp ) /* Note for starting the scheduler the exception return address is used as the function return address. */\r
- lw x5, 2 * WORD_SIZE( sp ) /* t0 */\r
- lw x6, 3 * WORD_SIZE( sp ) /* t1 */\r
- lw x7, 4 * WORD_SIZE( sp ) /* t2 */\r
- lw x8, 5 * WORD_SIZE( sp ) /* s0/fp */\r
- lw x9, 6 * WORD_SIZE( sp ) /* s1 */\r
- lw x10, 7 * WORD_SIZE( sp ) /* a0 */\r
- lw x11, 8 * WORD_SIZE( sp ) /* a1 */\r
- lw x12, 9 * WORD_SIZE( sp ) /* a2 */\r
- lw x13, 10 * WORD_SIZE( sp ) /* a3 */\r
- lw x14, 11 * WORD_SIZE( sp ) /* a4 */\r
- lw x15, 12 * WORD_SIZE( sp ) /* a5 */\r
- lw x16, 13 * WORD_SIZE( sp ) /* a6 */\r
- lw x17, 14 * WORD_SIZE( sp ) /* a7 */\r
- lw x18, 15 * WORD_SIZE( sp ) /* s2 */\r
- lw x19, 16 * WORD_SIZE( sp ) /* s3 */\r
- lw x20, 17 * WORD_SIZE( sp ) /* s4 */\r
- lw x21, 18 * WORD_SIZE( sp ) /* s5 */\r
- lw x22, 19 * WORD_SIZE( sp ) /* s6 */\r
- lw x23, 20 * WORD_SIZE( sp ) /* s7 */\r
- lw x24, 21 * WORD_SIZE( sp ) /* s8 */\r
- lw x25, 22 * WORD_SIZE( sp ) /* s9 */\r
- lw x26, 23 * WORD_SIZE( sp ) /* s10 */\r
- lw x27, 24 * WORD_SIZE( sp ) /* s11 */\r
- lw x28, 25 * WORD_SIZE( sp ) /* t3 */\r
- lw x29, 26 * WORD_SIZE( sp ) /* t4 */\r
- lw x30, 27 * WORD_SIZE( sp ) /* t5 */\r
- lw x31, 28 * WORD_SIZE( sp ) /* t6 */\r
- addi sp, sp, CONTEXT_SIZE\r
- csrs mstatus, 8 /* Enable machine interrupts. */\r
- ret\r
+.extern vPortHandleInterrupt\r
\r
/*-----------------------------------------------------------*/\r
\r
\r
lui t0, 0x80000\r
addi t1,t0, 7 /* 0x80000007 == machine timer interrupt. */\r
- bne a0, t1, as_yet_unhandled\r
+ bne a0, t1, test_if_external_interrupt\r
\r
lw t0, pullMachineTimerCompareRegister /* Load address of compare register into t0. */\r
lw t1, pullNextTime /* Load the address of ullNextTime into t1. */\r
jal vTaskSwitchContext\r
j processed_source\r
\r
-as_yet_unhandled:\r
-// ebreak /* External interrupt? */\r
- j as_yet_unhandled\r
+test_if_external_interrupt:\r
+ addi t1, t1, 4 /* 0x80000007 + 4 = 0x8000000b == Machine external interrupt. */\r
+ bne a0, t1, is_exception /* Only thing left it can be. */\r
+ jal vPortHandleInterrupt\r
+ j processed_source\r
+\r
+is_exception:\r
+ ebreak\r
+ j is_exception\r
\r
processed_source:\r
lw sp, pxCurrentTCB /* Load pxCurrentTCB. */\r
addi sp, sp, CONTEXT_SIZE\r
\r
mret\r
+/*-----------------------------------------------------------*/\r
+\r
+.align 8\r
+xPortStartFirstTask:\r
+\r
+ la t0, vPortTrapHandler\r
+ csrw mtvec, t0\r
+\r
+ lw sp, pxCurrentTCB /* Load pxCurrentTCB. */\r
+ lw sp, 0( sp ) /* Read sp from first TCB member. */\r
+\r
+ lw x1, 0( sp ) /* Note for starting the scheduler the exception return address is used as the function return address. */\r
+ lw x5, 2 * WORD_SIZE( sp ) /* t0 */\r
+ lw x6, 3 * WORD_SIZE( sp ) /* t1 */\r
+ lw x7, 4 * WORD_SIZE( sp ) /* t2 */\r
+ lw x8, 5 * WORD_SIZE( sp ) /* s0/fp */\r
+ lw x9, 6 * WORD_SIZE( sp ) /* s1 */\r
+ lw x10, 7 * WORD_SIZE( sp ) /* a0 */\r
+ lw x11, 8 * WORD_SIZE( sp ) /* a1 */\r
+ lw x12, 9 * WORD_SIZE( sp ) /* a2 */\r
+ lw x13, 10 * WORD_SIZE( sp ) /* a3 */\r
+ lw x14, 11 * WORD_SIZE( sp ) /* a4 */\r
+ lw x15, 12 * WORD_SIZE( sp ) /* a5 */\r
+ lw x16, 13 * WORD_SIZE( sp ) /* a6 */\r
+ lw x17, 14 * WORD_SIZE( sp ) /* a7 */\r
+ lw x18, 15 * WORD_SIZE( sp ) /* s2 */\r
+ lw x19, 16 * WORD_SIZE( sp ) /* s3 */\r
+ lw x20, 17 * WORD_SIZE( sp ) /* s4 */\r
+ lw x21, 18 * WORD_SIZE( sp ) /* s5 */\r
+ lw x22, 19 * WORD_SIZE( sp ) /* s6 */\r
+ lw x23, 20 * WORD_SIZE( sp ) /* s7 */\r
+ lw x24, 21 * WORD_SIZE( sp ) /* s8 */\r
+ lw x25, 22 * WORD_SIZE( sp ) /* s9 */\r
+ lw x26, 23 * WORD_SIZE( sp ) /* s10 */\r
+ lw x27, 24 * WORD_SIZE( sp ) /* s11 */\r
+ lw x28, 25 * WORD_SIZE( sp ) /* t3 */\r
+ lw x29, 26 * WORD_SIZE( sp ) /* t4 */\r
+ lw x30, 27 * WORD_SIZE( sp ) /* t5 */\r
+ lw x31, 28 * WORD_SIZE( sp ) /* t6 */\r
+ addi sp, sp, CONTEXT_SIZE\r
+ csrs mstatus, 8 /* Enable machine interrupts. */\r
+ ret\r
\r
+/*-----------------------------------------------------------*/\r
\r
*-----------------------------------------------------------\r
*/\r
\r
-#ifdef __riscv64\r
- #error This is the RV32 port that supports 32-bit cores only.\r
-#endif\r
-\r
/* Type definitions. */\r
#define portSTACK_TYPE uint32_t\r
#define portBASE_TYPE long\r
/* Architecture specifics. */\r
#define portSTACK_GROWTH ( -1 )\r
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
-#define portBYTE_ALIGNMENT 16\r
+#ifdef __riscv64\r
+ #error This is the RV32 port that has not yet been adapted for 64.\r
+ #define portBYTE_ALIGNMENT 16\r
+#else\r
+ #define portBYTE_ALIGNMENT 8\r
+#endif\r
/*-----------------------------------------------------------*/\r
\r
\r
\r
/* Critical section management. */\r
#define portCRITICAL_NESTING_IN_TCB 1\r
-extern int vPortSetInterruptMask( void );\r
-extern void vPortClearInterruptMask( int );\r
extern void vTaskEnterCritical( void );\r
extern void vTaskExitCritical( void );\r
\r
#define portSET_INTERRUPT_MASK_FROM_ISR() 0\r
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue\r
-#define portDISABLE_INTERRUPTS() __asm volatile( "csrc mstatus, 8" ); __asm volatile( "fence" )\r
-#define portENABLE_INTERRUPTS() __asm volatile( "csrs mstatus, 8" ); __asm volatile( "fence" )\r
+#define portDISABLE_INTERRUPTS() __asm volatile( "csrc mstatus, 8" )\r
+#define portENABLE_INTERRUPTS() __asm volatile( "csrs mstatus, 8" )\r
#define portENTER_CRITICAL() vTaskEnterCritical()\r
#define portEXIT_CRITICAL() vTaskExitCritical()\r
\r