Commit e7a11f1a authored by Keith Packard's avatar Keith Packard

Merge remote-tracking branch 'newlib/master'

parents d810b103 1f34405f
......@@ -61,4 +61,30 @@
# define HAVE_CALL_INDIRECT
#endif
/* A and R profiles (and legacy Arm).
Current Program Status Register (CPSR)
M[4:0] Mode bits. M[4] is always 1 for 32-bit modes.
T[5] 1: Thumb, 0: ARM instruction set
F[6] 1: disables FIQ
I[7] 1: disables IRQ
A[8] 1: disables imprecise aborts
E[9] 0: Little-endian, 1: Big-endian
J[24] 1: Jazelle instruction set
*/
#define CPSR_M_USR 0x00 /* User mode. */
#define CPSR_M_FIQ 0x01 /* Fast Interrupt mode. */
#define CPSR_M_IRQ 0x02 /* Interrupt mode. */
#define CPSR_M_SVR 0x03 /* Supervisor mode. */
#define CPSR_M_MON 0x06 /* Monitor mode. */
#define CPSR_M_ABT 0x07 /* Abort mode. */
#define CPSR_M_HYP 0x0A /* Hypervisor mode. */
#define CPSR_M_UND 0x0B /* Undefined mode. */
#define CPSR_M_SYS 0x0F /* System mode. */
#define CPSR_M_32BIT 0x10 /* 32-bit mode. */
#define CPSR_T_BIT 0x20 /* Thumb bit. */
#define CPSR_F_MASK 0x40 /* FIQ bit. */
#define CPSR_I_MASK 0x80 /* IRQ bit. */
#define CPSR_M_MASK 0x0F /* Mode mask except M[4]. */
#endif /* _LIBGLOSS_ARM_H */
This diff is collapsed.
......@@ -18,30 +18,30 @@
#include "swi.h"
/* Forward prototypes. */
int _system (const char *);
int _rename (const char *, const char *);
int _isatty (int);
int _system (const char *);
int _rename (const char *, const char *);
int _isatty (int);
clock_t _times (struct tms *);
int _gettimeofday (struct timeval *, void *);
int _unlink (const char *);
int _link (const char *, const char *);
int _stat (const char *, struct stat *);
int _fstat (int, struct stat *);
int _gettimeofday (struct timeval *, void *);
int _unlink (const char *);
int _link (const char *, const char *);
int _stat (const char *, struct stat *);
int _fstat (int, struct stat *);
int _swistat (int fd, struct stat * st);
void * _sbrk (ptrdiff_t);
pid_t _getpid (void);
int _close (int);
clock_t _clock (void);
int _swiclose (int);
int _open (const char *, int, ...);
int _swiopen (const char *, int);
int _write (int, const void *, size_t);
int _swiwrite (int, const void *, size_t);
_off_t _lseek (int, _off_t, int);
_off_t _swilseek (int, _off_t, int);
int _read (int, void *, size_t);
int _swiread (int, void *, size_t);
void initialise_monitor_handles (void);
void * _sbrk (ptrdiff_t);
pid_t _getpid (void);
int _close (int);
clock_t _clock (void);
int _swiclose (int);
int _open (const char *, int, ...);
int _swiopen (const char *, int);
int _write (int, const void *, size_t);
int _swiwrite (int, const void *, size_t);
_off_t _lseek (int, _off_t, int);
_off_t _swilseek (int, _off_t, int);
int _read (int, void *, size_t);
int _swiread (int, void *, size_t);
void initialise_monitor_handles (void);
static int checkerror (int);
static int error (int);
......@@ -143,7 +143,7 @@ initialise_monitor_handles (void)
int i;
/* Open the standard file descriptors by opening the special
* teletype device, ":tt", read-only to obtain a descritpor for
* teletype device, ":tt", read-only to obtain a descriptor for
* standard input and write-only to obtain a descriptor for standard
* output. Finally, open ":tt" in append mode to obtain a descriptor
* for standard error. Since this is a write mode, most kernels will
......@@ -154,7 +154,7 @@ initialise_monitor_handles (void)
#ifdef ARM_RDI_MONITOR
int volatile block[3];
block[0] = (int) ":tt";
block[2] = 3; /* length of filename */
block[1] = 0; /* mode "r" */
......@@ -351,17 +351,15 @@ checkerror (int result)
len, is the length in bytes to read.
Returns the number of bytes *not* written. */
int
_swiread (int fh,
void * ptr,
size_t len)
_swiread (int fh, void * ptr, size_t len)
{
#ifdef ARM_RDI_MONITOR
int block[3];
block[0] = fh;
block[1] = (int) ptr;
block[2] = (int) len;
return checkerror (do_AngelSWI (AngelSWI_Reason_Read, block));
#else
register int r0 asm("r0");
......@@ -381,9 +379,7 @@ _swiread (int fh,
Translates the return of _swiread into
bytes read. */
int __attribute__((weak))
_read (int fd,
void * ptr,
size_t len)
_read (int fd, void * ptr, size_t len)
{
int res;
struct fdent *pfd;
......@@ -409,9 +405,7 @@ _read (int fd,
/* fd, is a user file descriptor. */
off_t
_swilseek (int fd,
off_t ptr,
int dir)
_swilseek (int fd, off_t ptr, int dir)
{
off_t res;
struct fdent *pfd;
......@@ -447,7 +441,7 @@ _swilseek (int fd,
}
dir = SEEK_SET;
}
#ifdef ARM_RDI_MONITOR
int block[2];
if (dir == SEEK_END)
......@@ -458,7 +452,7 @@ _swilseek (int fd,
return -1;
ptr += res;
}
/* This code only does absolute seeks. */
block[0] = pfd->handle;
block[1] = (int) ptr;
......@@ -494,9 +488,7 @@ _swilseek (int fd,
}
off_t
_lseek (int fd,
off_t ptr,
int dir)
_lseek (int fd, off_t ptr, int dir)
{
return _swilseek (fd, ptr, dir);
}
......@@ -504,18 +496,15 @@ _lseek (int fd,
/* fh, is a valid internal file handle.
Returns the number of bytes *not* written. */
int
_swiwrite (
int fh,
const void * ptr,
size_t len)
_swiwrite (int fh, const void * ptr, size_t len)
{
#ifdef ARM_RDI_MONITOR
int block[3];
block[0] = fh;
block[1] = (int) ptr;
block[2] = (int) len;
return checkerror (do_AngelSWI (AngelSWI_Reason_Write, block));
#else
register int r0 asm("r0");
......@@ -533,9 +522,7 @@ _swiwrite (
/* fd, is a user file descriptor. */
int __attribute__((weak))
_write (int fd,
const void * ptr,
size_t len)
_write (int fd, const void * ptr, size_t len)
{
int res;
struct fdent *pfd;
......@@ -593,7 +580,7 @@ _swiopen (const char * path, int flags)
}
}
/* The flags are Unix-style, so we need to convert them. */
/* The flags are Unix-style, so we need to convert them. */
#ifdef O_BINARY
if (flags & O_BINARY)
aflags |= 1;
......@@ -611,25 +598,24 @@ _swiopen (const char * path, int flags)
if (flags & O_APPEND)
{
/* Can't ask for w AND a; means just 'a'. */
aflags &= ~4;
aflags &= ~4; /* Can't ask for w AND a; means just 'a'. */
aflags |= 8;
}
#ifdef ARM_RDI_MONITOR
block[0] = (int) path;
block[2] = strlen (path);
block[1] = aflags;
fh = do_AngelSWI (AngelSWI_Reason_Open, block);
#else
asm ("mov r0,%2; mov r1, %3; swi %a1; mov %0, r0"
: "=r"(fh)
: "i" (SWI_Open),"r"(path),"r"(aflags)
: "r0","r1");
#endif
/* Return a user file descriptor or an error. */
if (fh >= 0)
{
......@@ -707,15 +693,15 @@ uint __heap_limit = 0xcafedead;
void * __attribute__((weak))
_sbrk (ptrdiff_t incr)
{
extern char end asm ("end"); /* Defined by the linker. */
extern char end asm ("end"); /* Defined by the linker. */
static char * heap_end;
char * prev_heap_end;
char * prev_heap_end;
if (heap_end == NULL)
heap_end = & end;
prev_heap_end = heap_end;
if ((heap_end + incr > stack_ptr)
/* Honour heap limit if it's valid. */
|| (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit))
......@@ -726,14 +712,14 @@ _sbrk (ptrdiff_t incr)
extern void abort (void);
_write (1, "_sbrk: Heap and stack collision\n", 32);
abort ();
#else
errno = ENOMEM;
return (void *) -1;
#endif
}
heap_end += incr;
return (void *) prev_heap_end;
......@@ -784,13 +770,13 @@ _stat (const char *fname, struct stat *st)
{
int fd, res;
memset (st, 0, sizeof (* st));
/* The best we can do is try to open the file readonly.
If it exists, then we can guess a few things about it. */
/* The best we can do is try to open the file readonly. If it exists,
then we can guess a few things about it. */
if ((fd = _open (fname, O_RDONLY)) == -1)
return -1;
st->st_mode |= S_IFREG | S_IREAD;
res = _swistat (fd, st);
/* Not interested in the error. */
/* Not interested in the error. */
_close (fd);
return res;
}
......@@ -880,7 +866,7 @@ _times (struct tms * tp)
tp->tms_cutime = 0; /* user time, children */
tp->tms_cstime = 0; /* system time, children */
}
return timeval;
};
......
......@@ -182,6 +182,7 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
}
......@@ -135,6 +135,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -135,6 +135,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -137,6 +137,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -143,6 +143,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
PROVIDE (end = .);
_end = .;
......
......@@ -144,6 +144,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
PROVIDE (end = .);
_end = .;
......
......@@ -145,6 +145,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
PROVIDE (end = .);
_end = .;
......
......@@ -95,6 +95,7 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
}
......@@ -99,6 +99,7 @@ SECTIONS
. = __stack ;
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -137,6 +137,7 @@ SECTIONS
. = __stack ;
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -98,6 +98,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -95,6 +95,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -133,6 +133,7 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
}
......@@ -137,6 +137,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
end = .;
_end = .;
......
......@@ -144,6 +144,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
PROVIDE (end = .);
_end = .;
......
......@@ -146,6 +146,7 @@ SECTIONS
*(COMMON)
}
. = ALIGN(4);
PROVIDE (end = .);
_end = .;
......
......@@ -61,7 +61,7 @@ SCRIPTS = $(srcdir)/msp430-sim.ld
SCRIPTS += $(srcdir)/msp430xl-sim.ld
SCRIPTS += $(srcdir)/intr_vectors.ld
CRT = gcrt0.o crt0.o crt0-minrt.o crtn.o crtn-minrt.o
CRT = gcrt0.o crt0.o
SIM_BSP = libsim.a
LIB_NOSYS = libnosys.a
LIB_CRT = libcrt.a
......@@ -85,7 +85,6 @@ CRT_OBJS = \
crt_movedata.o \
crt_move_highdata.o \
crt_main.o \
crt_main_minrt.o \
crt_callexit.o \
crt_run_init_array.o \
crt_run_preinit_array.o \
......@@ -102,12 +101,6 @@ all: $(CRT) $(SIM_BSP) $(LIB_NOSYS) $(LIB_CRT) copy_scripts_to_objdir
crt_%.o : crt0.S
$(CC) -DL$* -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -o $@
crt0-minrt.o : crt0.S
$(CC) -DL0 -DMINRT -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -o $@
crtn-minrt.o : crtn.S
$(CC) -DL0 -DMINRT -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -o $@
# Override .S.o rule to pass assembler debugging flags
.S.o:
$(CC) -DL0 -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $<
......
......@@ -52,28 +52,25 @@ __msp430_resetvec_hook:
START_CRT_FUNC 0000 start
.refsym __msp430_resetvec_hook
#ifdef MINRT
.refsym __crt0_call_just_main
#else
.refsym __crt0_call_init_then_main
#endif
.refsym __crt0_call_main
mov_ #__stack, R1
END_CRT_FUNC start
#endif
;; Some of the CRT functions below will only be present in the final linked
;; executable if the assembler decides they are needed. It will only define
;; the symbol necessary to prevent them being garbage collected by the linker
;; if the file being assembled has a specific section.
;; The CRT functions this applies to are:
;; init_bss, movedata, move_highdata, init_highbss, run_init_array,
;; run_preinit_array, run_fini_array and run_array.
;; The CRT functions below will only be present in the final linked
;; executable if the assembler decides they are needed. The assembler will
;; only define the symbol necessary to prevent them being garbage collected
;; by the linker if the file being assembled has a specific section,
;; or some other criteria is met.
;; The exception to this is __crt0_call_exit. GCC will include this function
;; if it detects that main() has an epilogue. For example, if main() has a
;; while(1) loop at the end, GCC will not generate an epilogue (since it won't
;; return) and __crt0_call_exit won't be included.
#if Lbss
;; Note - this section is only included in the startup code of the
;; application if it is needed. It is responsible for initializing
;; the contents of the .bss section.
;; This function is responsible for initializing the contents of the
;; .bss section.
START_CRT_FUNC 0100 init_bss
......@@ -91,9 +88,8 @@ END_CRT_FUNC init_bss
#ifdef __MSP430X_LARGE__
#if Lhigh_bss
;; Note - this section is only included in the startup code of the
;; application if it is needed. It is responsible for initializing
;; the contents of the .upper.bss section.
;; This function is responsible for initializing the contents of the
;; .upper.bss section.
START_CRT_FUNC 0200 init_highbss
......@@ -112,8 +108,7 @@ END_CRT_FUNC init_highbss
#if Lmovedata
;; Note - this section is only included in the startup code of the
;; application if it is needed. It is responsible for copying the
;; This function is responsible for copying the
;; contents of the .data section from its load address (in ROM) to
;; its run-time address (in RAM).
......@@ -136,8 +131,7 @@ END_CRT_FUNC movedata
#ifdef __MSP430X_LARGE__
#if Lmove_highdata
;; Note - this section is only included in the startup code of the application
;; if it is needed. It is responsible either for making sure that the
;; This function is responsible for making sure that the
;; contents of the .upper.data section have their correct startup values.
;; If a copy of the .upper.data section is stored in ROM then this means
;; copying the contents into HIFRAM. If a copy of .upper.data is stored in a
......@@ -175,44 +169,62 @@ END_CRT_FUNC move_highdata
#endif /* Lmove_highdata */
#endif /* __MSP430X_LARGE__ */
#if Lrun_preinit_array
;; This function is responsible for setting up the arguments
;; required for __crt0_run_array, to run the functions in .preinit_array.
START_CRT_FUNC 0500 run_preinit_array
mov_ #__preinit_array_start, R4
mov_ #__preinit_array_end, R5
mov_ #PTRsz, R6
call_ #__crt0_run_array
#if Lmain_minrt
;; Note - this section is only included in the startup code of the
;; application if it is needed. It is responsible for just calling
;; main. No initialization code is called first, and main is not
;; expected to return.
END_CRT_FUNC run_preinit_array
#endif /* Lrun_preinit_array */
START_CRT_FUNC 0600 call_just_main
#if Lrun_init_array
;; This function is responsible for setting up the arguments
;; required for __crt0_run_array, to run the functions in .init_array.
START_CRT_FUNC 0600 run_init_array
clr.w R12 ; Set argc == 0
call_ #main
END_CRT_FUNC call_just_main
#endif /* Lmain_minrt */
mov_ #__init_array_start, R4
mov_ #__init_array_end, R5
mov_ #PTRsz, R6
call_ #__crt0_run_array
END_CRT_FUNC run_init_array
#endif /* Lrun_init_array */
#if Lmain
;; Note - this section is only included in the startup code of the
;; application if it is needed. It is responsible for calling the
;; initialization code - constructors, etc - and then main. If main
;; returns then the following section should be present to catch it.
;; FIXME: There are currently no program termination routines executed for
;; msp430.
#if 0
#if Lrun_fini_array
;; Ensure global C++ destructors in .fini_array are called on exit
;; by registering __crt0_run_fini_array with atexit.
START_CRT_FUNC 0700 register_fini_array
mov_ #__crt0_run_fini_array, R12
call_ #atexit
END_CRT_FUNC register_fini_array
#endif /* Lrun_fini_array */
#endif /* 0 */
START_CRT_FUNC 0700 call_init_then_main
#if Lmain
;; This function is always included and calls main().
call_ #__msp430_init
START_CRT_FUNC 0800 call_main
clr.w R12 ; Set argc == 0
call_ #main
END_CRT_FUNC call_init_then_main
END_CRT_FUNC call_main
#endif /* Lmain */
#if Lcallexit
;; Note - this section is only included in the startup code of the
;; application if it is needed. It is responsible for calling exit
;; once main has finished.
;; This function is responsible for calling exit once main has finished.
START_CRT_FUNC 0800 call_exit
START_CRT_FUNC 0900 call_exit
call_ #_exit
......@@ -221,46 +233,15 @@ END_CRT_FUNC call_exit
;----------------------------------------
#ifndef MINRT
#if Lrun_preinit_array
;; Note - this section is only included in the startup code of the application
;; if it is needed. It is responsible for setting up the arguments
;; required for __crt0_run_array, to run the functions in .preinit_array.
START_CRT_FUNC 0910 run_preinit_array
mov_ #__preinit_array_start, R4
mov_ #__preinit_array_end, R5
mov_ #PTRsz, R6
br_ #__crt0_run_array
END_CRT_FUNC run_preinit_array
#endif /* Lrun_preinit_array */
#if Lrun_init_array
;; Note - this section is only included in the startup code of the application
;; if it is needed. It is responsible for setting up the arguments
;; required for __crt0_run_array, to run the functions in .init_array.
START_CRT_FUNC 0920 run_init_array
mov_ #__init_array_start, R4
mov_ #__init_array_end, R5
mov_ #PTRsz, R6
br_ #__crt0_run_array
END_CRT_FUNC run_init_array
#endif /* Lrun_init_array */
#if Lrun_fini_array
;; Note - this section is only included in the startup code of the application
;; if it is needed. It is responsible for setting up the arguments
;; This function is responsible for setting up the arguments
;; required for __crt0_run_array, to run the functions in .fini_array.
START_CRT_FUNC 0930 run_fini_array
START_CRT_FUNC 1000 run_fini_array
mov_ #__fini_array_start, R4
mov_ #__fini_array_end, R5
mov_ #-PTRsz, R6
br_ #__crt0_run_array
call_ #__crt0_run_array
END_CRT_FUNC run_fini_array
#endif /* Lrun_fini_array */
......@@ -268,7 +249,7 @@ END_CRT_FUNC run_fini_array
#if Lrun_array
;; Note - this section is only included in the startup code of the application
;; if it is needed by one of the above run_*_array functions.
START_CRT_FUNC 0980 run_array
START_CRT_FUNC 1100 run_array
cmp_ R4, R5
jeq _msp430_run_done
......@@ -282,27 +263,3 @@ END_CRT_FUNC run_array
_msp430_run_done:
ret_
#endif /* Lrun_array */
;----------------------------------------
#if L0
.section .init,"ax"
.global __msp430_init
__msp430_init:
.section .fini,"ax"
.global __msp430_fini
__msp430_fini:
call_ #__crt0_run_fini_array
;; If this function is not defined externally, we don't need it to do
;; anything.
.text
.weak __crt0_run_fini_array
__crt0_run_fini_array:
ret_
#endif
#endif /* not MINRT */
/* Copyright (c) 2013 Red Hat, Inc. All rights reserved.
This copyrighted material is made available to anyone wishing to use, modify,
copy, or redistribute it subject to the terms and conditions of the BSD
License. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license
is available at http://www.opensource.org/licenses. Any Red Hat trademarks that
are incorporated in the source code or documentation are not subject to the BSD
License and may only be used or replicated with the express permission of
Red Hat, Inc.
*/
#include "memmodel.h"
#ifndef MINRT
.section .init,"ax"
call_ #__crt0_run_preinit_array
call_ #__crt0_run_init_array
ret_
.global __msp430_init_end
__msp430_init_end:
.section .fini,"ax"
ret_
.global __msp430_fini_end
__msp430_fini_end:
.text
;; If these functions are not defined externally, we don't need them to do
;; anything.
.balign 2
.weak __crt0_run_preinit_array
.weak __crt0_run_init_array