2007-12-11 Joel Sherrill <joel.sherrill@OARcorp.com>

* thumb_isr.c: Style.
This commit is contained in:
Joel Sherrill
2007-12-11 23:03:29 +00:00
parent 1c62f16987
commit c922ec6c65
2 changed files with 99 additions and 89 deletions

View File

@@ -1,3 +1,7 @@
2007-12-11 Joel Sherrill <joel.sherrill@OARcorp.com>
* thumb_isr.c: Style.
2007-11-26 Ray Xu <rayx.cn@gmail.com> 2007-11-26 Ray Xu <rayx.cn@gmail.com>
* thumb_isr.c: Remove extra debug information, Change function * thumb_isr.c: Remove extra debug information, Change function

View File

@@ -1,5 +1,5 @@
/* /*
* The thumb mode do not support multi-level ISR, only disable and enable * Thumb mode does not support multi-level ISR, only disable and enable.
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
@@ -16,11 +16,11 @@
* *
* _CPU_ISR_Get_level_Thumb - returns the current interrupt level * _CPU_ISR_Get_level_Thumb - returns the current interrupt level
*/ */
uint32_t _CPU_ISR_Get_level_Thumb(void) __attribute__ ((naked)); uint32_t _CPU_ISR_Get_level_Thumb(void) __attribute__ ((naked));
uint32_t _CPU_ISR_Disable_Thumb(void ) __attribute__ ((naked)); uint32_t _CPU_ISR_Disable_Thumb(void ) __attribute__ ((naked));
void _CPU_ISR_Enable_Thumb(int _level ) __attribute__ ((naked)); void _CPU_ISR_Enable_Thumb(int _level ) __attribute__ ((naked));
void _CPU_ISR_Flash_Thumb(int _level ) __attribute__ ((naked)); void _CPU_ISR_Flash_Thumb(int _level ) __attribute__ ((naked));
void _CPU_ISR_Set_level_Thumb(int new_level ) __attribute__ ((naked)); void _CPU_ISR_Set_level_Thumb(int new_level ) __attribute__ ((naked));
/* /*
* prevent multipule enable/disable ISR * prevent multipule enable/disable ISR
@@ -32,7 +32,6 @@ void _CPU_ISR_Set_level_Thumb(int new_level ) __attribute__ ((naked));
* Set the CPSR bit 6,7 to 0 enables FIQ and IRQ * Set the CPSR bit 6,7 to 0 enables FIQ and IRQ
*/ */
#define str(x) #x #define str(x) #x
#define xstr(x) str(x) #define xstr(x) str(x)
#define L(x) #x "_" xstr(__LINE__) #define L(x) #x "_" xstr(__LINE__)
@@ -40,22 +39,22 @@ void _CPU_ISR_Set_level_Thumb(int new_level ) __attribute__ ((naked));
/* /*
* Switch to ARM mode Veneer,ugly but safe * Switch to ARM mode Veneer,ugly but safe
*/ */
#define TO_ARM_MODE(x) \ #define TO_ARM_MODE(x) \
asm volatile ( \ asm volatile ( \
".code 16 \n" \ ".code 16 \n" \
L(x) "_thumb: \n" \ L(x) "_thumb: \n" \
".align 2 \n" \ ".align 2 \n" \
"push {lr} \n" \ "push {lr} \n" \
"adr %0, "L(x) "_arm \n" \ "adr %0, "L(x) "_arm \n" \
"bl " L(x)" \n" \ "bl " L(x)" \n" \
"pop {pc} \n" \ "pop {pc} \n" \
".balign 4 \n" \ ".balign 4 \n" \
L(x) ": \n" \ L(x) ": \n" \
"bx %0 \n" \ "bx %0 \n" \
"nop \n" \ "nop \n" \
".pool \n" \ ".pool \n" \
".code 32 \n" \ ".code 32 \n" \
L(x) "_arm: \n" \ L(x) "_arm: \n" \
: "=&r" (reg)) : "=&r" (reg))
/* /*
@@ -64,64 +63,71 @@ void _CPU_ISR_Set_level_Thumb(int new_level ) __attribute__ ((naked));
*/ */
uint32_t _CPU_ISR_Disable_Thumb(void ) uint32_t _CPU_ISR_Disable_Thumb(void )
{ {
int reg=0; int reg=0;
TO_ARM_MODE(disable);
asm volatile ( \ TO_ARM_MODE(disable);
".code 32 \n" \ asm volatile(
"STMDB sp!, {r1} \n" \ ".code 32 \n"
"MRS r0, CPSR \n" \ "STMDB sp!, {r1} \n"
"DISABLE_ARM: \n" \ "MRS r0, CPSR \n"
"ORR r1, r0, #0xc0 \n" \ "DISABLE_ARM: \n"
"MSR CPSR, r1 \n" \ "ORR r1, r0, #0xc0 \n"
"pop {r1} \n" \ "MSR CPSR, r1 \n"
"BX LR \n" \ "pop {r1} \n"
".code 16 \n" ); "BX LR \n"
} ".code 16 \n"
);
}
/* /*
* Enable interrupts to the previous level (returned by _CPU_ISR_Disable_Thumb). * Enable interrupts to the previous level (returned by
* _CPU_ISR_Disable_Thumb).
* This indicates the end of an RTEMS critical section. The parameter * This indicates the end of an RTEMS critical section. The parameter
* _level is not modified. I do not think _level is useful in this * _level is not modified. I do not think _level is useful in this
*/ */
void _CPU_ISR_Enable_Thumb(int _level ) void _CPU_ISR_Enable_Thumb(int _level )
{ {
int reg=0; int reg=0;
TO_ARM_MODE(enable);
asm volatile ( \ TO_ARM_MODE(enable);
".code 32 \n" \ asm volatile(
"ENABLE_ARM: \n" \ ".code 32 \n"
"MSR CPSR, %0 \n" \ "ENABLE_ARM: \n"
/* Return back to thumb.*/ \ "MSR CPSR, %0 \n"
"BX R14 \n" \ /* Return back to thumb.*/
".code 16 \n" \ "BX R14 \n"
: : "r"(_level)); ".code 16 \n"
} : : "r"(_level)
);
}
/* /*
* This temporarily restores the interrupt to _level before immediately * This temporarily restores the interrupt to _level before immediately
* disabling them again. This is used to divide long RTEMS critical * disabling them again. This is used to divide long RTEMS critical
* sections into two or more parts. The parameter _level is not * sections into two or more parts. The parameter _level is not
* modified. * modified.
*/ */
void _CPU_ISR_Flash_Thumb(int _level ) void _CPU_ISR_Flash_Thumb(int _level )
{ {
int reg=0; int reg=0;
TO_ARM_MODE(flash);
asm volatile ( \ TO_ARM_MODE(flash);
".code 32 \n" \ asm volatile(
"FLASH_ARM: \n" \ ".code 32 \n"
"MRS %0, CPSR \n" \ "FLASH_ARM: \n"
"BIC %0, %0, #0xC0 \n" \ "MRS %0, CPSR \n"
/* enable the irq*/ \ "BIC %0, %0, #0xC0 \n"
"MSR CPSR_c, %0 \n" \ /* enable the irq*/
"ORR %0, %0, #0xc0 \n" \ "MSR CPSR_c, %0 \n"
"MSR CPSR_c, %0 \n" \ "ORR %0, %0, #0xc0 \n"
"BX R14 \n" \ "MSR CPSR_c, %0 \n"
".code 16 \n" \ "BX R14 \n"
:"=&r"(reg) : "r" (_level)); ".code 16 \n"
} :"=&r"(reg) : "r" (_level)
);
}
/* /*
* Map interrupt level in task mode onto the hardware that the CPU * Map interrupt level in task mode onto the hardware that the CPU
@@ -137,20 +143,20 @@ void _CPU_ISR_Flash_Thumb(int _level )
* ARM/Thumb dont distinguishd the interrupt levels * ARM/Thumb dont distinguishd the interrupt levels
*/ */
void _CPU_ISR_Set_level_Thumb(int new_level ) void _CPU_ISR_Set_level_Thumb(int new_level)
{ {
int reg = 0; /* to avoid warning */ \ int reg = 0; /* to avoid warning */
TO_ARM_MODE(SetISR); \ TO_ARM_MODE(SetISR);
asm volatile (\ asm volatile (\
".code 32 \n" \ ".code 32 \n" \
"SET_LEVEL_ARM: \n" \ "SET_LEVEL_ARM: \n" \
"MRS %0, CPSR \n" \ "MRS %0, CPSR \n" \
"BIC %0, %0, #0xC0 \n" \ "BIC %0, %0, #0xC0 \n" \
"MSR CPSR_c, %0 \n" \ "MSR CPSR_c, %0 \n" \
"BX lr \n" \ "BX lr \n" \
".code 16 \n" \ ".code 16 \n" \
: "=r" (reg) \ : "=r" (reg) \
: "0" (reg)); : "0" (reg));
} }
uint32_t _CPU_ISR_Get_level_Thumb( void ) uint32_t _CPU_ISR_Get_level_Thumb( void )
@@ -158,14 +164,14 @@ uint32_t _CPU_ISR_Get_level_Thumb( void )
uint32_t reg = 0; /* to avoid warning */ uint32_t reg = 0; /* to avoid warning */
TO_ARM_MODE(GetISR); \ TO_ARM_MODE(GetISR); \
asm volatile (\ asm volatile (\
".code 32 \n" \ ".code 32 \n" \
"GET_ISR_ARM: \n" \ "GET_ISR_ARM: \n" \
"MRS r0, cpsr \n" \ "MRS r0, cpsr \n" \
"AND r0, r0, #0xC0 \n" \ "AND r0, r0, #0xC0 \n" \
"EOR r0, r0, #0xC0 \n" \ "EOR r0, r0, #0xC0 \n" \
"BX LR \n" \ "BX LR \n" \
".code 16 \n" \ ".code 16 \n" \
".thumb_func \n" ); ".thumb_func \n" );
} }
#endif #endif