diff --git a/libgloss/ChangeLog b/libgloss/ChangeLog index e2b400040..f3e323deb 100644 --- a/libgloss/ChangeLog +++ b/libgloss/ChangeLog @@ -1,3 +1,11 @@ +2006-02-07 Paul Brook + + * arm/crt0.S: Add Thumb-2 startup code. + * arm/redboot-crt0.S: Ditto. + * arm/libcfunc.c (do_AngelSWI): Use AngelSWIInsn. + * arm/swi.h (AngelSWIInsn, AngelSWIAsm): Define. + * arm/trap.S: Disable for Thumb-2. + 2006-01-18 Nathan Sidwell * mt/ms2.ld (.sram): Correct typo in section names. diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S index bea289277..823f409a4 100644 --- a/libgloss/arm/crt0.S +++ b/libgloss/arm/crt0.S @@ -18,15 +18,26 @@ /* .text is used instead of .section .text so it works with arm-aout too. */ .text +#if defined(__thumb2__) + .syntax unified + .thumb +.macro FUNC_START name + .global \name + .thumb_func +\name: +.endm +#else .code 32 +.macro FUNC_START name + .global \name +\name: +.endm +#endif .align 0 - .global _mainCRTStartup - .global _start - .global start -start: -_start: -_mainCRTStartup: + FUNC_START _mainCRTStartup + FUNC_START _start + FUNC_START start #if defined(__ELF__) && !defined(__USING_SJLJ_EXCEPTIONS__) /* Annotation for EABI unwinding tables. */ .fnstart @@ -45,7 +56,12 @@ _mainCRTStartup: /* Issue Angel SWI to read stack info */ mov r0, #AngelSWI_Reason_HeapInfo adr r1, .LC0 /* point at ptr to 4 words to receive data */ - swi AngelSWI_ARM /* We are always in ARM mode for startup */ +#if defined(__thumb2__) + bkpt AngelSWI +#else + /* We are always in ARM mode for startup */ + AngelSWIAsm AngelSWI_ARM +#endif ldr r0, .LC0 /* point at values read */ ldr sp, [r0, #8] ldr sl, [r0, #12] @@ -124,8 +140,8 @@ _mainCRTStartup: sub a3, a3, a1 /* Third arg: length of block */ -#ifdef __thumb__ /* Enter Thumb mode.... */ - +#if defined(__thumb__) && !defined(__thumb2__) + /* Enter Thumb mode.... */ add a4, pc, #1 /* Get the address of the Thumb block */ bx a4 /* Go there and start Thumb decoding */ @@ -165,7 +181,7 @@ __change_mode: #else mov r0, #AngelSWI_Reason_GetCmdLine adr r1, .LC30 /* Space for command line */ - swi AngelSWI + AngelSWIAsm AngelSWI ldr r1, .LC30 #endif /* Parse string at r1 */ @@ -287,7 +303,7 @@ __change_mode: bl FUNCTION (exit) /* Should not return. */ -#ifdef __thumb__ +#if defined(__thumb__) && !defined(__thumb2__) /* Come out of Thumb mode. This code should be redundant. */ mov a4, pc diff --git a/libgloss/arm/libcfunc.c b/libgloss/arm/libcfunc.c index ffad2e7e0..4f131939a 100644 --- a/libgloss/arm/libcfunc.c +++ b/libgloss/arm/libcfunc.c @@ -15,7 +15,7 @@ static inline int do_AngelSWI (int reason, void * arg) { int value; - asm volatile ("mov r0, %1; mov r1, %2; swi %a3; mov %0, r0" + asm volatile ("mov r0, %1; mov r1, %2; " AngelSWIInsn " %a3; mov %0, r0" : "=r" (value) /* Outputs */ : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */ : "r0", "r1", "lr" diff --git a/libgloss/arm/redboot-crt0.S b/libgloss/arm/redboot-crt0.S index f2963eeb4..d059c226e 100644 --- a/libgloss/arm/redboot-crt0.S +++ b/libgloss/arm/redboot-crt0.S @@ -12,11 +12,23 @@ .text /* Setup the assembly entry point. */ - .code 32 - .globl SYM_NAME(start) - .globl SYM_NAME(_start) -SYM_NAME(start): -SYM_NAME(_start): +#ifdef __thumb2__ +.macro FUNC_START name + .global \name + .thumb_func +\name: +.endm + .syntax unified + .thumb +#else +.macro FUNC_START name + .global \name +\name: +.endm + .code 32 +#endif + FUNC_START SYM_NAME(start) + FUNC_START SYM_NAME(_start) mov fp, #0 /* Null frame pointer. */ mov r7, #0 /* Null frame pointer for Thumb. */ @@ -46,7 +58,7 @@ SYM_NAME(_start): /* Nothing to left to clear. */ #endif -#ifdef __thumb__ /* Enter Thumb mode. */ +#if defined(__thumb__) && !defined(__thumb2__) /* Enter Thumb mode. */ add a4, pc, #1 /* Get the address of the Thumb block. */ bx a4 /* Go there and start Thumb decoding. */ diff --git a/libgloss/arm/swi.h b/libgloss/arm/swi.h index 15c3866a1..f5c910313 100644 --- a/libgloss/arm/swi.h +++ b/libgloss/arm/swi.h @@ -33,6 +33,14 @@ #else #define AngelSWI AngelSWI_ARM #endif +/* For Thumb-2 code use the BKPT instruction instead of SWI. */ +#ifdef __thumb2__ +#define AngelSWIInsn "bkpt" +#define AngelSWIAsm bkpt +#else +#define AngelSWIInsn "swi" +#define AngelSWIAsm swi +#endif /* The reason codes: */ #define AngelSWI_Reason_Open 0x01 diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c index 456b68129..a6d2f747e 100644 --- a/libgloss/arm/syscalls.c +++ b/libgloss/arm/syscalls.c @@ -99,7 +99,7 @@ static inline int do_AngelSWI (int reason, void * arg) { int value; - asm volatile ("mov r0, %1; mov r1, %2; swi %a3; mov %0, r0" + asm volatile ("mov r0, %1; mov r1, %2; " AngelSWIInsn " %a3; mov %0, r0" : "=r" (value) /* Outputs */ : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */ : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" diff --git a/libgloss/arm/trap.S b/libgloss/arm/trap.S index 328fabca5..21b6937f9 100644 --- a/libgloss/arm/trap.S +++ b/libgloss/arm/trap.S @@ -1,4 +1,5 @@ /* Run-time exception support */ +#if !defined(__thumb2__) #include "swi.h" /* .text is used instead of .section .text so it works with arm-aout too. */ @@ -91,3 +92,4 @@ __rt_stkovf_split_big: @ We now know how much extra stack the function requires. @ Terminate the program for the moment: swi SWI_Exit +#endif