From 61cf16961909644dcd2874feab226ba3f74f6db8 Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Wed, 30 Aug 2006 22:24:19 +0000 Subject: 2006-08-30 Paul Brook libgloss/ * arm/Makefile.in: Change armv7m linker script generation. Add armv7m.spec. Build armv7m-crt0.o. * arm/arm.sc: New file. * arm/armv7m.specs: New file. * arm/crt0.S: Add armv7m code. * arm/elf-lm3s10x.ld: Remove. * arm/elf-lm3s301.ld: Remove. * arm/elf-lm3s31x.ld: Remove. * arm/swi.h (do_AngelSWI): Add definition. * arm/syscalls.c: Merge lazy semihosting initialization from newlib. newlib/ * libc/sys/arm/crt0.S: Add armv7m rom startup code. --- ChangeLog.csl | 17 ++++++ libgloss/arm/Makefile.in | 35 ++++++++--- libgloss/arm/arm.sc | 146 ++++++++++++++++++++++++++++++++++++++++++++ libgloss/arm/armv7m.specs | 9 +++ libgloss/arm/crt0.S | 139 +++++++++++++++++++++++++++-------------- libgloss/arm/elf-lm3s10x.ld | 13 ---- libgloss/arm/elf-lm3s301.ld | 13 ---- libgloss/arm/elf-lm3s31x.ld | 13 ---- libgloss/arm/syscalls.c | 47 ++++++++------ newlib/libc/sys/arm/crt0.S | 30 ++++++++- 10 files changed, 349 insertions(+), 113 deletions(-) create mode 100644 libgloss/arm/arm.sc create mode 100644 libgloss/arm/armv7m.specs delete mode 100644 libgloss/arm/elf-lm3s10x.ld delete mode 100644 libgloss/arm/elf-lm3s301.ld delete mode 100644 libgloss/arm/elf-lm3s31x.ld diff --git a/ChangeLog.csl b/ChangeLog.csl index 535d3789e..c1859a6e3 100644 --- a/ChangeLog.csl +++ b/ChangeLog.csl @@ -1,3 +1,20 @@ +2006-08-30 Paul Brook + + libgloss/ + * arm/Makefile.in: Change armv7m linker script generation. Add + armv7m.spec. Build armv7m-crt0.o. + * arm/arm.sc: New file. + * arm/armv7m.specs: New file. + * arm/crt0.S: Add armv7m code. + * arm/elf-lm3s10x.ld: Remove. + * arm/elf-lm3s301.ld: Remove. + * arm/elf-lm3s31x.ld: Remove. + * arm/swi.h (do_AngelSWI): Add definition. + * arm/syscalls.c: Merge lazy semihosting initialization from newlib. + + newlib/ + * libc/sys/arm/crt0.S: Add armv7m rom startup code. + 2006-08-29 Paul Brook newlib/ diff --git a/libgloss/arm/Makefile.in b/libgloss/arm/Makefile.in index 891ada8ee..cee0a6b7b 100644 --- a/libgloss/arm/Makefile.in +++ b/libgloss/arm/Makefile.in @@ -70,9 +70,6 @@ RDIMON_OBJS = rdimon-syscalls.o rdimon-libcfunc.o rdimon-trap.o RDIMON_SCRIPTS = rdimon.specs RDIMON_INSTALL = install-rdimon -LMS_SCRIPTS = cm3.ld lm3s10x.ld lm3s301.ld lm3s31x.ld -LMS_INSTALL = install-lms - CFLAGS = -g # Here is all of the eval board stuff @@ -82,6 +79,11 @@ PID_INSTALL = install-pid IQ80310_SCRIPTS = iq80310.specs IQ80310_INSTALL = install-iq80310 +ARMV7M_OBJS = armv7m-crt0.o \ + armv7m-rom.ld lm3s10x-rom.ld lm3s301-rom.ld lm3s31x-rom.ld \ + armv7m-ram.ld lm3s10x-ram.ld lm3s301-ram.ld lm3s31x-ram.ld +ARMV7M_SPECS = armv7m.specs +ARMV7M_INSTALL = install-armv7m # Host specific makefile fragment comes in here. @host_makefile_frag@ @@ -90,7 +92,7 @@ IQ80310_INSTALL = install-iq80310 # build a test program for each target board. Just trying to get # it to link is a good test, so we ignore all the errors for now. # -all: ${CRT0} ${REDBOOT_CRT0} ${REDBOOT_OBJS} ${RDPMON_CRT0} ${RDPMON_BSP} ${RDIMON_CRT0} ${RDIMON_BSP} +all: ${CRT0} ${REDBOOT_CRT0} ${REDBOOT_OBJS} ${RDPMON_CRT0} ${RDPMON_BSP} ${RDIMON_CRT0} ${RDIMON_BSP} ${ARMV7M_OBJS} # # here's where we build the test programs for each target @@ -100,6 +102,9 @@ test: # crt0.o: crt0.S +armv7m-crt0.o: crt0.S + $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) -D_ARM_V7M -o $@ -c $< + redboot-crt0.o: redboot-crt0.S redboot-syscalls.o: redboot-syscalls.c $(srcdir)/../syscall.h @@ -126,6 +131,21 @@ $(RDIMON_BSP): $(RDIMON_OBJS) ${AR} ${ARFLAGS} $@ $^ ${RANLIB} $@ +# Armv7M board files. +# ram rom stack +armv7m= 32M 32M no +lm3s10x= 2k 8k yes +lm3s301= 2k 16k yes +lm3s31x= 4k 16k yes + +%-ram.ld : arm.sc Makefile + RAM_SIZE=$(word 1,$($*)) \ + ${SHELL} $< $(word 3,$($*)) >$@ +%-rom.ld : arm.sc Makefile + RAM_SIZE=$(word 1,$($*)) \ + ROM_SIZE=$(word 2,$($*)) \ + ${SHELL} $< $(word 3,$($*)) >$@ + clean mostlyclean: rm -f a.out core *.i *.o *-test *.srec *.dis *.x $(SIM_BSP) $(IQ80310_BSP) @@ -133,7 +153,7 @@ distclean maintainer-clean realclean: clean rm -f Makefile config.status *~ .PHONY: install info install-info clean-info -install: ${CRT0_INSTALL} ${REDBOOT_INSTALL} ${RDPMON_INSTALL} ${RDIMON_INSTALL} ${IQ80310_INSTALL} ${PID_INSTALL} ${LMS_INSTALL} +install: ${CRT0_INSTALL} ${REDBOOT_INSTALL} ${RDPMON_INSTALL} ${RDIMON_INSTALL} ${IQ80310_INSTALL} ${PID_INSTALL} ${ARMV7M_INSTALL} install-crt0: ${INSTALL_DATA} ${CRT0} $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x @@ -157,8 +177,9 @@ install-pid: install-iq80310: set -e; for x in ${IQ80310_SCRIPTS}; do ${INSTALL_DATA} ${srcdir}/${objtype}$$x $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; done -install-lms: - set -e; for x in ${LMS_SCRIPTS}; do ${INSTALL_DATA} ${srcdir}/${objtype}$$x $(DESTDIR)/${tooldir}/lib${MULTISUBDIR}/$$x; done +install-armv7m: + set -e; for x in ${ARMV7M_OBJS}; do ${INSTALL_DATA} $$x $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; done + set -e; for x in ${ARMV7M_SPECS}; do ${INSTALL_DATA} ${srcdir}/$$x $(DESTDIR)/${tooldir}/lib${MULTISUBDIR}/$$x; done doc: info: diff --git a/libgloss/arm/arm.sc b/libgloss/arm/arm.sc new file mode 100644 index 000000000..b6c813a3f --- /dev/null +++ b/libgloss/arm/arm.sc @@ -0,0 +1,146 @@ +# a linker script template. +# RAM - start of board's ram +# RAM_SIZE - size of board's ram +# ROM - start of board's rom +# ROM_SIZE - size of board's rom +# $1 whether to set _stack + +test "x$1" = "xyes" && SETSTACK=1 +test -z "${RAM}" && RAM=0x20000000 +if test -z "${ROM_SIZE:+1}" ; then + NOROM=1 +else + test -z "${ROM}" && ROM=0 +fi + +cat <${ROM:+rom}${NOROM:+ram} + /* .ARM.exidx is sorted, so has to go in its own output section. */ + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } >${ROM:+rom}${NOROM:+ram} + __exidx_end = .; + _etext = .; + + .data : + { + __data_load = LOADADDR (.data); + __data_start = .; + *(.got.plt) *(.got) + *(.shdata) + *(.data .data.*) + . = ALIGN (4); + _edata = .; + } >ram ${ROM:+AT>rom} + + .bss : + { + __bss_start__ = . ; + *(.shbss) + *(.bss .bss.*) + *(COMMON) + . = ALIGN (8); + __bss_end__ = .; + _end = .; + __end = _end; + PROVIDE(end = .); + } >ram ${ROM:+AT>rom} + + .stab 0 (NOLOAD) : + { + *(.stab) + } + + .stabstr 0 (NOLOAD) : + { + *(.stabstr) + } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) } + /DISCARD/ : { *(.note.GNU-stack) ${NOROM:+*(.isr_vector)} } +} +EOF diff --git a/libgloss/arm/armv7m.specs b/libgloss/arm/armv7m.specs new file mode 100644 index 000000000..2d1e08697 --- /dev/null +++ b/libgloss/arm/armv7m.specs @@ -0,0 +1,9 @@ +%rename lib old_lib + +*startfile: +crti%O%s crtbegin%O%s armv7m-crt0%O%s + +# Put the -T here so it comes after -L search patch. +*lib: +%(old_lib) %{!T*:-T armv7m-rom.ld%s} + diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S index 823f409a4..28d2918b3 100644 --- a/libgloss/arm/crt0.S +++ b/libgloss/arm/crt0.S @@ -43,31 +43,54 @@ .fnstart #endif -/* Start by setting up a stack */ -#ifdef ARM_RDP_MONITOR + /* Start by setting up a stack */ +#ifdef _ARM_V7M + /* Copy .data into ram. */ + ldr r0, =__data_load + ldr r1, =__data_start + cmp r0, r1 /* If LMA == VMA we are running from ram. */ + beq 2f + ldr r2, =_edata + /* When running from ROM the stack pointer is set up at CPU reset. */ + /* Copy .data into RAM. */ +1: + ldr r3, [r0], #4 + str r3, [r1], #4 + cmp r1, r2 + blt 1b + b 3f +2: + /* Set the stack pointer when running from RAM. */ + ldr r0, .Lstack + cmp r0, #0 + beq 3f + mov sp, r0 +3: +#else +# ifdef ARM_RDP_MONITOR /* Issue Demon SWI to read stack info */ swi SWI_GetEnv /* Returns command line in r0 */ mov sp,r1 /* and the highest memory address in r1 */ ldr sl, .LC2 /* stack limit is at end of data */ add sl, sl, #256 /* allow slop for stack overflow handling */ /* and small frames */ -#else -#ifdef ARM_RDI_MONITOR +# else +# ifdef ARM_RDI_MONITOR /* Issue Angel SWI to read stack info */ mov r0, #AngelSWI_Reason_HeapInfo adr r1, .LC0 /* point at ptr to 4 words to receive data */ -#if defined(__thumb2__) +# if defined(__thumb2__) bkpt AngelSWI -#else +# else /* We are always in ARM mode for startup */ AngelSWIAsm AngelSWI_ARM -#endif +# endif ldr r0, .LC0 /* point at values read */ ldr sp, [r0, #8] ldr sl, [r0, #12] add sl, sl, #256 /* allow slop for stack overflow handling */ /* and small frames */ -#else +# else /* Set up the stack pointer to a fixed value */ /* Changes by toralf: - Allow linker script to provide stack via __stack symbol - see @@ -127,9 +150,11 @@ this default 64k is enough for the program being executed. However, it ensures that this simple crt0 world will not immediately cause an overflow event: */ - sub sl, r3, #64 << 10 /* Still assumes 256bytes below sl */ -#endif + sub sl, sp, #64 << 10 /* Still assumes 256bytes below sl */ +# endif +# endif #endif + /* Zero the memory in the .bss section. */ mov a2, #0 /* Second arg: fill value */ mov fp, a2 /* Null frame pointer */ @@ -152,7 +177,11 @@ __change_mode: #endif bl FUNCTION (memset) -#if !defined (ARM_RDP_MONITOR) && !defined (ARM_RDI_MONITOR) + /* For ARM V7M, we do not want to have semihosting traps in + crt0.o, so that people can use the same programs both with + and without semihosting. */ +#if ((!defined (ARM_RDP_MONITOR) && !defined (ARM_RDI_MONITOR)) \ + || defined (_ARM_V7M)) /* Changes by toralf: Taken from libgloss/m68k/crt0.S * initialize target specific stuff. Only execute these * functions it they exist. @@ -172,34 +201,31 @@ __change_mode: mov r0, #0 /* no arguments */ mov r1, #0 /* no argv either */ #else - /* Need to set up standard file handles */ - bl FUNCTION (initialise_monitor_handles) - -#ifdef ARM_RDP_MONITOR +# ifdef ARM_RDP_MONITOR swi SWI_GetEnv /* sets r0 to point to the command line */ mov r1, r0 -#else +# else mov r0, #AngelSWI_Reason_GetCmdLine adr r1, .LC30 /* Space for command line */ AngelSWIAsm AngelSWI ldr r1, .LC30 -#endif +# endif /* Parse string at r1 */ mov r0, #0 /* count of arguments so far */ /* Push a NULL argument onto the end of the list. */ -#ifdef __thumb__ +# ifdef __thumb__ push {r0} -#else +# else stmfd sp!, {r0} -#endif +# endif .LC10: /* Skip leading blanks */ -#ifdef __thumb__ +# ifdef __thumb__ ldrb r3, [r1] add r1, #1 -#else +# else ldrb r3, [r1], #1 -#endif +# endif cmp r3, #0 beq .LC12 cmp r3, #' ' @@ -207,7 +233,7 @@ __change_mode: /* See whether we are scanning a string */ cmp r3, #'"' -#ifdef __thumb__ +# ifdef __thumb__ beq .LC20 cmp r3, #'\'' bne .LC21 @@ -219,27 +245,27 @@ __change_mode: mov r2, #' ' /* terminator type */ sub r1, r1, #1 /* adjust back to point at start char */ .LC22: -#else +# else cmpne r3, #'\'' moveq r2, r3 movne r2, #' ' /* terminator type */ subne r1, r1, #1 /* adjust back to point at start char */ -#endif +# endif /* Stack a pointer to the current argument */ -#ifdef __thumb__ +# ifdef __thumb__ push {r1} -#else +# else stmfd sp!, {r1} -#endif +# endif add r0, r0, #1 .LC11: -#ifdef __thumb__ +# ifdef __thumb__ ldrb r3, [r1] add r1, #1 -#else +# else ldrb r3, [r1], #1 -#endif +# endif cmp r3, #0 beq .LC12 cmp r2, r3 /* reached terminator? */ @@ -252,7 +278,7 @@ __change_mode: .LC12: mov r1, sp /* point at stacked arg pointers */ /* We've now got the stacked args in order reverse the */ -#ifdef __thumb__ +# ifdef __thumb__ mov r2, r0 lsl r2, #2 add r2, sp @@ -272,7 +298,7 @@ __change_mode: mov r5, #7 bic r4, r5 mov sp, r4 -#else +# else add r2, sp, r0, LSL #2 /* End of args */ mov r3, sp /* Start of args */ .LC13: cmp r2, r3 @@ -283,7 +309,7 @@ __change_mode: bhi .LC13 /* Ensure doubleword stack alignment. */ bic sp, sp, #7 -#endif +# endif #endif #ifdef __USES_INITFINI__ @@ -323,21 +349,27 @@ change_back: positive offsets are supported for PC relative addresses. */ .align 0 +#ifndef _ARM_V7M .LC0: -#ifdef ARM_RDI_MONITOR +# ifdef ARM_RDI_MONITOR .word HeapBase -#else -#ifndef ARM_RDP_MONITOR +# else +# ifndef ARM_RDP_MONITOR /* Changes by toralf: Provide alternative "stack" variable whose value may be defined externally; .Lstack will be used instead of .LC0 if it points to a non-0 value. Also set up references to "hooks" that may be used by the application to provide additional init code. */ -#ifdef __pe__ +# ifdef __pe__ .word 0x800000 -#else +# else .word 0x80000 /* Top of RAM on the PIE board. */ -#endif +# endif +# endif +# endif +#endif +#if ((!defined (ARM_RDP_MONITOR) && !defined (ARM_RDI_MONITOR)) \ + || defined (_ARM_V7M)) .Lstack: .word __stack .Lhwinit: @@ -352,15 +384,17 @@ change_back: and only if, a normal version of the same symbol isn't provided e.g. by a linker script or another object file.) */ - .set __stack, 0 .set FUNCTION (hardware_init_hook), 0 .set FUNCTION (software_init_hook), 0 - .weak __stack .weak FUNCTION (hardware_init_hook) .weak FUNCTION (software_init_hook) + + /* For ARMV7M we want to error if no stack location is defined. */ +#if !defined(_ARM_V7M) + .set __stack, 0 + .weak __stack #endif - #endif #if defined(__ELF__) && !defined(__USING_SJLJ_EXCEPTIONS__) /* Protect against unhandled exceptions. */ @@ -375,7 +409,7 @@ change_back: .Lfini: .word FUNCTION(_fini) #endif -#ifdef ARM_RDI_MONITOR +#if defined(ARM_RDI_MONITOR) && !defined(_ARM_V7M) .LC30: .word CommandLine .word 255 @@ -395,3 +429,18 @@ CommandLine: .space 256,0 /* Maximum length of 255 chars handled. */ .section .idata$3 .long 0,0,0,0,0,0,0,0 #endif + +#ifdef _ARM_V7M + /* The hardware uses this vector to handle hardware resets and + exceptions. */ + .section .isr_vector, "a" + /* The value for the stack pointer at reset. */ + .word __stack + /* The value for the PC at reset. */ + .word _start + /* The value for the PC if an NMI occurs. */ + .word _nmi_isr + /* The value for the PC if a fault occurs. */ + .word _fault_isr +#endif /* _ARM_V7M */ + diff --git a/libgloss/arm/elf-lm3s10x.ld b/libgloss/arm/elf-lm3s10x.ld deleted file mode 100644 index dad433dc9..000000000 --- a/libgloss/arm/elf-lm3s10x.ld +++ /dev/null @@ -1,13 +0,0 @@ -/* Linker script for Luminary Micro LM3S101, LM3S102. */ - -MEMORY { - rom (rx) : ORIGIN = 0x00000000, LENGTH = 8K - ram (w) : ORIGIN = 0x20000000, LENGTH = 2K -} - -SECTIONS { - _stack = 0x20000000 + 2K; -} - -INCLUDE cm3.ld -INCLUDE ldscripts/armelf.xc diff --git a/libgloss/arm/elf-lm3s301.ld b/libgloss/arm/elf-lm3s301.ld deleted file mode 100644 index 9a0041203..000000000 --- a/libgloss/arm/elf-lm3s301.ld +++ /dev/null @@ -1,13 +0,0 @@ -/* Linker script for Luminary Micro LM3S301. */ - -MEMORY { - rom (rx) : ORIGIN = 0x00000000, LENGTH = 16K - ram (w) : ORIGIN = 0x20000000, LENGTH = 2K -} - -SECTIONS { - _stack = 0x20000000 + 2K; -} - -INCLUDE cm3.ld -INCLUDE ldscripts/armelf.xc diff --git a/libgloss/arm/elf-lm3s31x.ld b/libgloss/arm/elf-lm3s31x.ld deleted file mode 100644 index c5403df65..000000000 --- a/libgloss/arm/elf-lm3s31x.ld +++ /dev/null @@ -1,13 +0,0 @@ -/* Linker script for Luminary Micro LM3S315, LM3S316. */ - -MEMORY { - rom (rx) : ORIGIN = 0x00000000, LENGTH = 16K - ram (w) : ORIGIN = 0x20000000, LENGTH = 4K -} - -SECTIONS { - _stack = 0x20000000 + 4K; -} - -INCLUDE cm3.ld -INCLUDE ldscripts/armelf.xc diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c index 827d6ee3a..1df75bb90 100644 --- a/libgloss/arm/syscalls.c +++ b/libgloss/arm/syscalls.c @@ -42,29 +42,17 @@ int _lseek _PARAMS ((int, int, int)); int _swilseek _PARAMS ((int, int, int)); int _read _PARAMS ((int, char *, int)); int _swiread _PARAMS ((int, char *, int)); -void initialise_monitor_handles _PARAMS ((void)); +static void initialise_monitor_handles _PARAMS ((void)); static int wrap _PARAMS ((int)); static int error _PARAMS ((int)); static int get_errno _PARAMS ((void)); static int remap_handle _PARAMS ((int)); -static int do_AngelSWI _PARAMS ((int, void *)); static int findslot _PARAMS ((int)); /* Register name faking - works in collusion with the linker. */ register char * stack_ptr asm ("sp"); - -/* following is copied from libc/stdio/local.h to check std streams */ -extern void _EXFUN(__sinit,(struct _reent *)); -#define CHECK_INIT(ptr) \ - do \ - { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ - } \ - while (0) - /* Adjust our internal handles to stay away from std* handles. */ #define FILE_HANDLE_OFFSET (0x20) @@ -88,6 +76,8 @@ static int findslot (int fh) { int i; + + initialise_monitor_handles (); for (i = 0; i < MAX_OPEN_FILES; i ++) if (openfiles[i].handle == fh) break; @@ -118,8 +108,6 @@ do_AngelSWI (int reason, void * arg) static int remap_handle (int fh) { - CHECK_INIT(_REENT); - if (fh == STDIN_FILENO) return monitor_stdin; if (fh == STDOUT_FILENO) @@ -145,6 +133,22 @@ initialise_monitor_handles (void) * different descriptor for standard error. */ + static int initialized; + int was_initialized; + + /* We need do this only once. */ + if (initialized) + return; + +#ifndef __SINGLE_THREAD__ + __lock_acquire_recursive (__arm_monitor_handles_lock); + if (initialized) + { + __lock_release_recursive (__arm_monitor_handles_lock); + return; + } +#endif + #ifdef ARM_RDI_MONITOR int volatile block[3]; @@ -197,6 +201,11 @@ initialise_monitor_handles (void) openfiles[1].pos = 0; openfiles[2].handle = monitor_stderr; openfiles[2].pos = 0; + + initialized = 1; +#ifndef __SINGLE_THREAD__ + __lock_release_recursive (__arm_monitor_handles_lock); +#endif } static int @@ -562,7 +571,7 @@ _unlink (const char *path) { #ifdef ARM_RDI_MONITOR int block[2]; - block[0] = path; + block[0] = (int)path; block[1] = strlen(path); return wrap (do_AngelSWI (AngelSWI_Reason_Remove, block)) ? -1 : 0; #else @@ -658,7 +667,7 @@ _system (const char *s) meaning to its return value. Try to do something reasonable.... */ if (!s) return 1; /* maybe there is a shell available? we can hope. :-P */ - block[0] = s; + block[0] = (int)s; block[1] = strlen (s); e = wrap (do_AngelSWI (AngelSWI_Reason_System, block)); if ((e >= 0) && (e < 256)) @@ -683,9 +692,9 @@ _rename (const char * oldpath, const char * newpath) { #ifdef ARM_RDI_MONITOR int block[4]; - block[0] = oldpath; + block[0] = (int)oldpath; block[1] = strlen(oldpath); - block[2] = newpath; + block[2] = (int)newpath; block[3] = strlen(newpath); return wrap (do_AngelSWI (AngelSWI_Reason_Rename, block)) ? -1 : 0; #else diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S index d84983ec8..9d4f15872 100644 --- a/newlib/libc/sys/arm/crt0.S +++ b/newlib/libc/sys/arm/crt0.S @@ -45,7 +45,27 @@ /* Start by setting up a stack */ #ifdef _ARM_V7M - /* On ARM V7M, the stack pointer is set up at CPU reset. */ + /* Copy .data into ram. */ + ldr r0, =__data_load + ldr r1, =__data_start + cmp r0, r1 /* If LMA == VMA we are running from ram. */ + beq 2f + ldr r2, =_edata + /* When running from ROM the stack pointer is set up at CPU reset. */ + /* Copy .data into RAM. */ +1: + ldr r3, [r0], #4 + str r3, [r1], #4 + cmp r1, r2 + blt 1b + b 3f +2: + /* Set the stack pointer when running from RAM. */ + ldr r0, .Lstack + cmp r0, #0 + beq 3f + mov sp, r0 +3: #else # ifdef ARM_RDP_MONITOR /* Issue Demon SWI to read stack info */ @@ -278,6 +298,10 @@ change_back: # endif # endif #endif +#ifdef _ARM_V7M +.Lstack: + .word __stack +#endif #if defined(__ELF__) && !defined(__USING_SJLJ_EXCEPTIONS__) /* Protect against unhandled exceptions. */ .cantunwind @@ -317,12 +341,12 @@ CommandLine: .space 256,0 /* Maximum length of 255 chars handled. */ exceptions. */ .section .isr_vector, "a" /* The value for the stack pointer at reset. */ - .word _stack + .word __stack /* The value for the PC at reset. */ .word _start /* The value for the PC if an NMI occurs. */ .word _nmi_isr /* The value for the PC if a fault occurs. */ .word _fault_isr -#endif _ARM_V7M +#endif /* _ARM_V7M */ -- cgit v1.2.3