Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft version for THUMB mode support. #332

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
402 changes: 201 additions & 201 deletions ports/cortex_a7/gnu/example_build/build_threadx.bat

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ports/cortex_a7/gnu/example_build/build_threadx_sample.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
arm-none-eabi-gcc -c -g -mcpu=cortex-a7 reset.S
arm-none-eabi-gcc -c -g -mcpu=cortex-a7 crt0.S
arm-none-eabi-gcc -c -g -mcpu=cortex-a7 tx_initialize_low_level.S
arm-none-eabi-gcc -c -g -DTHUMB_MODE -mthumb-interwork -mthumb -mcpu=cortex-a7 tx_initialize_low_level.S
arm-none-eabi-gcc -c -g -mcpu=cortex-a7 MP_GIC.s
arm-none-eabi-gcc -c -g -mcpu=cortex-a7 MP_PrivateTimer.s
arm-none-eabi-gcc -c -g -mcpu=cortex-a7 V7.s
Expand Down
33 changes: 18 additions & 15 deletions ports/cortex_a7/gnu/example_build/crt0.S
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@

.syntax unified
#if defined(THUMB_MODE)
.thumb
#else
.arm
#endif

/* .text is used instead of .section .text so it works with arm-aout too. */
.text
.code 32
.align 0

#if defined(THUMB_MODE)
.thumb_func
#endif
.global _mainCRTStartup
_mainCRTStartup:
#if defined(THUMB_MODE)
.thumb_func
#endif
.global _start
_start:
#if defined(THUMB_MODE)
.thumb_func
#endif
.global start
start:
_start:
_mainCRTStartup:

/* Start by setting up a stack */
/* Set up the stack pointer to a fixed value */
Expand Down Expand Up @@ -69,24 +84,12 @@ _mainCRTStartup:
.word _fini
#endif */
/* Return ... */
#ifdef __APCS_26__
movs pc, lr
#else
#ifdef __THUMB_INTERWORK
bx lr
#else
mov pc, lr
#endif
#endif

.global _fini
.type _fini,function
_fini:
#ifdef __THUMB_INTERWORK
BX lr // Return to caller
#else
MOV pc, lr // Return to caller
#endif

/* Workspace for Angel calls. */
.data
Expand Down
54 changes: 30 additions & 24 deletions ports/cortex_a7/gnu/example_build/tx_initialize_low_level.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
#include "tx_user.h"
#endif

.syntax unified
#if defined(THUMB_MODE)
.thumb
#else
.arm
#endif

SVC_MODE = 0xD3 // Disable IRQ/FIQ SVC mode
IRQ_MODE = 0xD2 // Disable IRQ/FIQ IRQ mode
Expand All @@ -48,22 +53,6 @@ SYS_STACK_SIZE = 1024 // System stack size
.global enableCaches
.global init_private_timer
.global start_private_timer
/* Define the 16-bit Thumb mode veneer for _tx_initialize_low_level for
applications calling this function from to 16-bit Thumb mode. */

.text
.align 2
.thumb
.global $_tx_initialize_low_level
.type $_tx_initialize_low_level,function
$_tx_initialize_low_level:
BX pc // Switch to 32-bit mode
NOP //
.arm
STMFD sp!, {lr} // Save return address
BL _tx_initialize_low_level // Call _tx_initialize_low_level function
LDMFD sp!, {lr} // Recover saved return address
BX lr // Return to 16-bit caller

.text
.align 2
Expand Down Expand Up @@ -113,6 +102,9 @@ $_tx_initialize_low_level:
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/
#if defined(THUMB_MODE)
.thumb_func
#endif
.global _tx_initialize_low_level
.type _tx_initialize_low_level,function
_tx_initialize_low_level:
Expand Down Expand Up @@ -201,34 +193,42 @@ _stack_error_loop:
BL start_private_timer

POP {lr}
#ifdef __THUMB_INTERWORK

BX lr // Return to caller
#else
MOV pc, lr // Return to caller
#endif

/* Define shells for each of the interrupt vectors. */

#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_undefined
__tx_undefined:
B __tx_undefined // Undefined handler

.global __tx_swi_interrupt
__tx_swi_interrupt:
B __tx_swi_interrupt // Software interrupt handler

#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_prefetch_handler
__tx_prefetch_handler:
B __tx_prefetch_handler // Prefetch exception handler

#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_abort_handler
__tx_abort_handler:
B __tx_abort_handler // Abort exception handler

#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_reserved_handler
__tx_reserved_handler:
B __tx_reserved_handler // Reserved exception handler

#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_irq_handler
.global __tx_irq_processing_return
__tx_irq_handler:
Expand Down Expand Up @@ -302,6 +302,9 @@ by_pass_timer_interrupt:


#ifdef TX_ENABLE_FIQ_SUPPORT
#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_fiq_handler
.global __tx_fiq_processing_return
__tx_fiq_handler:
Expand Down Expand Up @@ -336,6 +339,9 @@ __tx_fiq_processing_return:


#else
#if defined(THUMB_MODE)
.thumb_func
#endif
.global __tx_fiq_handler
__tx_fiq_handler:
B __tx_fiq_handler // FIQ interrupt handler
Expand Down
47 changes: 20 additions & 27 deletions ports/cortex_a7/gnu/src/tx_thread_context_restore.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
#include "tx_user.h"
#endif

.arm

#ifdef TX_ENABLE_FIQ_SUPPORT
SVC_MODE = 0xD3 // Disable IRQ/FIQ, SVC mode
IRQ_MODE = 0xD2 // Disable IRQ/FIQ, IRQ mode
.syntax unified
#if defined(THUMB_MODE)
.thumb
#else
SVC_MODE = 0x93 // Disable IRQ, SVC mode
IRQ_MODE = 0x92 // Disable IRQ, IRQ mode
.arm
#endif

SVC_MODE = 0x13 // SVC mode
IRQ_MODE = 0x12 // IRQ mode

.global _tx_thread_system_state
.global _tx_thread_current_ptr
.global _tx_thread_execute_ptr
Expand All @@ -45,7 +45,6 @@ IRQ_MODE = 0x92 // Disable IRQ, IRQ mode
/* No 16-bit Thumb mode veneer code is needed for _tx_thread_context_restore
since it will never be called 16-bit mode. */

.arm
.text
.align 2
/**************************************************************************/
Expand Down Expand Up @@ -129,9 +128,9 @@ _tx_thread_context_restore:
/* Just recover the saved registers and return to the point of
interrupt. */

LDMIA sp!, {r0, r10, r12, lr} // Recover SPSR, POI, and scratch regs
POP {r0, r10, r12, lr} // Recover SPSR, POI, and scratch regs
MSR SPSR_cxsf, r0 // Put SPSR back
LDMIA sp!, {r0-r3} // Recover r0-r3
POP {r0-r3} // Recover r0-r3
MOVS pc, lr // Return to point of interrupt

__tx_thread_not_nested_restore:
Expand Down Expand Up @@ -160,26 +159,23 @@ __tx_thread_no_preempt_restore:
/* Pickup the saved stack pointer. */

/* Recover the saved context and return to the point of interrupt. */
LDMIA sp!, {r0, r10, r12, lr} // Recover SPSR, POI, and scratch regs
POP {r0, r10, r12, lr} // Recover SPSR, POI, and scratch regs
MSR SPSR_cxsf, r0 // Put SPSR back
LDMIA sp!, {r0-r3} // Recover r0-r3
POP {r0-r3} // Recover r0-r3
MOVS pc, lr // Return to point of interrupt

__tx_thread_preempt_restore:

LDMIA sp!, {r3, r10, r12, lr} // Recover temporarily saved registers
POP {r3, r10, r12, lr} // Recover temporarily saved registers
MOV r1, lr // Save lr (point of interrupt)
MOV r2, #SVC_MODE // Build SVC mode CPSR
MSR CPSR_c, r2 // Enter SVC mode
CPS #SVC_MODE // Enter SVC mode
STR r1, [sp, #-4]! // Save point of interrupt
STMDB sp!, {r4-r12, lr} // Save upper half of registers
PUSH {r4-r12, lr} // Save upper half of registers
MOV r4, r3 // Save SPSR in r4
MOV r2, #IRQ_MODE // Build IRQ mode CPSR
MSR CPSR_c, r2 // Enter IRQ mode
LDMIA sp!, {r0-r3} // Recover r0-r3
MOV r5, #SVC_MODE // Build SVC mode CPSR
MSR CPSR_c, r5 // Enter SVC mode
STMDB sp!, {r0-r3} // Save r0-r3 on thread's stack
CPS #IRQ_MODE // Enter IRQ mode
POP {r0-r3} // Recover r0-r3
CPS #SVC_MODE // Enter SVC mode
PUSH {r0-r3} // Save r0-r3 on thread's stack

LDR r1, =_tx_thread_current_ptr // Pickup address of current thread ptr
LDR r0, [r1] // Pickup current thread pointer
Expand All @@ -192,13 +188,11 @@ __tx_thread_preempt_restore:
STR r2, [sp, #-4]! // Save FPSCR
VSTMDB sp!, {D16-D31} // Save D16-D31
VSTMDB sp!, {D0-D15} // Save D0-D15

_tx_skip_irq_vfp_save:

#endif

MOV r3, #1 // Build interrupt stack type
STMDB sp!, {r3, r4} // Save interrupt stack type and SPSR
PUSH {r3, r4} // Save interrupt stack type and SPSR
STR sp, [r0, #8] // Save stack pointer in thread control
// block

Expand All @@ -223,6 +217,5 @@ __tx_thread_dont_save_ts:
__tx_thread_idle_system_restore:

/* Just return back to the scheduler! */
MOV r0, #SVC_MODE // Build SVC mode CPSR
MSR CPSR_c, r0 // Enter SVC mode
CPS #SVC_MODE // Enter SVC mode
B _tx_thread_schedule // Return to scheduler
24 changes: 15 additions & 9 deletions ports/cortex_a7/gnu/src/tx_thread_context_save.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include "tx_user.h"
#endif

.syntax unified
#if defined(THUMB_MODE)
.thumb
#else
.arm
#endif

.global _tx_thread_system_state
.global _tx_thread_current_ptr
.global __tx_irq_processing_return
Expand All @@ -31,7 +38,6 @@
/* No 16-bit Thumb mode veneer code is needed for _tx_thread_context_save
since it will never be called 16-bit mode. */

.arm
.text
.align 2
/**************************************************************************/
Expand Down Expand Up @@ -90,7 +96,7 @@ _tx_thread_context_save:

/* Check for a nested interrupt condition. */

STMDB sp!, {r0-r3} // Save some working registers
PUSH {r0-r3} // Save some working registers
#ifdef TX_ENABLE_FIQ_SUPPORT
CPSID if // Disable FIQ interrupts
#endif
Expand All @@ -101,15 +107,15 @@ _tx_thread_context_save:

/* Nested interrupt condition. */

ADD r2, r2, #1 // Increment the interrupt counter
ADD r2, #1 // Increment the interrupt counter
STR r2, [r3] // Store it back in the variable

/* Save the rest of the scratch registers on the stack and return to the
calling ISR. */

MRS r0, SPSR // Pickup saved SPSR
SUB lr, lr, #4 // Adjust point of interrupt
STMDB sp!, {r0, r10, r12, lr} // Store other registers
SUB lr, #4 // Adjust point of interrupt
PUSH {r0, r10, r12, lr} // Store other registers

/* Return to the ISR. */

Expand All @@ -129,7 +135,7 @@ _tx_thread_context_save:
__tx_thread_not_nested_save:

/* Otherwise, not nested, check to see if a thread was running. */
ADD r2, r2, #1 // Increment the interrupt counter
ADD r2, #1 // Increment the interrupt counter
STR r2, [r3] // Store it back in the variable
LDR r1, =_tx_thread_current_ptr // Pickup address of current thread ptr
LDR r0, [r1] // Pickup current thread pointer
Expand All @@ -140,8 +146,8 @@ __tx_thread_not_nested_save:
/* Save minimal context of interrupted thread. */

MRS r2, SPSR // Pickup saved SPSR
SUB lr, lr, #4 // Adjust point of interrupt
STMDB sp!, {r2, r10, r12, lr} // Store other registers
SUB lr, #4 // Adjust point of interrupt
PUSH {r2, r10, r12, lr} // Store other registers

MOV r10, #0 // Clear stack limit

Expand Down Expand Up @@ -174,5 +180,5 @@ __tx_thread_idle_system_save:
POP {lr} // Recover ISR lr
#endif

ADD sp, sp, #16 // Recover saved registers
ADD sp, #16 // Recover saved registers
B __tx_irq_processing_return // Continue IRQ processing
Loading
Loading