diff options
author | Sandra Loosemore <sandra@codesourcery.com> | 2006-05-23 02:26:10 +0400 |
---|---|---|
committer | Sandra Loosemore <sandra@codesourcery.com> | 2006-05-23 02:26:10 +0400 |
commit | 398cdf8781eae8f1863444bd96a21c28622d3dcf (patch) | |
tree | 3fb2421d27a0e3fe5231215f91dd6f1d4be18d01 | |
parent | 998982571e2dd30da4a157974f6c67a526d249f3 (diff) |
Add semihosting support for BDM mode on ColdFire
-rw-r--r-- | ChangeLog.csl | 28 | ||||
-rw-r--r-- | libgloss/m68k/Makefile.in | 18 | ||||
-rw-r--r-- | libgloss/m68k/bdm-close.c | 22 | ||||
-rw-r--r-- | libgloss/m68k/bdm-exit.c | 9 | ||||
-rw-r--r-- | libgloss/m68k/bdm-fstat.c | 28 | ||||
-rw-r--r-- | libgloss/m68k/bdm-isatty.c | 22 | ||||
-rw-r--r-- | libgloss/m68k/bdm-isrs.c | 2 | ||||
-rw-r--r-- | libgloss/m68k/bdm-isv.c | 4 | ||||
-rw-r--r-- | libgloss/m68k/bdm-lseek.c | 30 | ||||
-rw-r--r-- | libgloss/m68k/bdm-open.c | 40 | ||||
-rw-r--r-- | libgloss/m68k/bdm-outbyte.c | 7 | ||||
-rw-r--r-- | libgloss/m68k/bdm-read.c | 26 | ||||
-rw-r--r-- | libgloss/m68k/bdm-rename.c | 29 | ||||
-rw-r--r-- | libgloss/m68k/bdm-semihost.h | 37 | ||||
-rw-r--r-- | libgloss/m68k/bdm-stat.c | 32 | ||||
-rw-r--r-- | libgloss/m68k/bdm-system.c | 25 | ||||
-rw-r--r-- | libgloss/m68k/bdm-unlink.c | 25 | ||||
-rw-r--r-- | libgloss/m68k/bdm-write.c | 26 | ||||
-rw-r--r-- | newlib/configure.host | 4 |
19 files changed, 387 insertions, 27 deletions
diff --git a/ChangeLog.csl b/ChangeLog.csl index 704f8abcf..e5122bfd5 100644 --- a/ChangeLog.csl +++ b/ChangeLog.csl @@ -1,3 +1,31 @@ +2006-05-22 Sandra Loosemore <sandra@codesourcery.com> + + * libgloss/m68k/bdm-semihost.h: Add new constants for additional + semihosting functions. Add new BDM_TRAP macro to encapsulate + inline asm. + * libgloss/m68k/bdm-exit.c (_exit): Use new BDM_TRAP macro. + * libgloss/m68k/bdm-outbyte.c (outbyte): Ditto. + * libgloss/m68k/bdm-isrs.c, libgloss/m68k/bdm-isv.c: Former BDM_TRAP + now called BDM_TRAPNUM. + * libgloss/m68k/bdm-gdb.h, libgloss/m68k/bdm-gdb.c: New files + containing declarations and conversion functions for GDB's fileio + protocol. + * libgloss/m68k/bdm-close.c: New file to define corresponding function. + * libgloss/m68k/bdm-fstat.c: Ditto. + * libgloss/m68k/bdm-gettimeofday.c: Ditto. + * libgloss/m68k/bdm-isatty.c: Ditto. + * libgloss/m68k/bdm-lseek.c: Ditto. + * libgloss/m68k/bdm-open.c: Ditto. + * libgloss/m68k/bdm-read.c: Ditto. + * libgloss/m68k/bdm-rename.c: Ditto. + * libgloss/m68k/bdm-stat.c: Ditto. + * libgloss/m68k/bdm-system.c: Ditto. + * libgloss/m68k/bdm-unlink.c: Ditto. + * libgloss/m68k/bdm-write.c Ditto. + * libgloss/m68k/Makefile.in: Add dependencies for new files. + * newlib/configure.host: Tell it we have _rename and _system when + building m68k-unknown-elf. + 2006-05-04 Paul Brook <paul@codesourcery.com> * libc/sys/arm/Makefile.am (lib_a_SOURCES): Add aeabi_memclr.c, diff --git a/libgloss/m68k/Makefile.in b/libgloss/m68k/Makefile.in index 7096fa4cf..59c192619 100644 --- a/libgloss/m68k/Makefile.in +++ b/libgloss/m68k/Makefile.in @@ -127,8 +127,13 @@ DBUG_OBJS= dbug-exit.o dbug-inbyte.o dbug-outbyte.o # here's all the BDM semihosting stuff # BDM_BSP= libbdm.a -BDM_OBJS= bdm-exit.o bdm-inbyte.o bdm-outbyte.o bdm-isv.o \ - bdm-semihost.o $(patsubst %,bdm-%.o,${BDM_ISRS}) +BDM_OBJS= bdm-isv.o bdm-semihost.o $(BDM_SYSOBJS) \ + $(patsubst %,bdm-%.o,${BDM_ISRS}) +BDM_OTHER_OBJS= getpid.o kill.o sbrk.o print.o putnum.o +BDM_SYSOBJS= bdm-close.o bdm-exit.o bdm-fstat.o bdm-gdb.o \ + bdm-gettimeofday.o bdm-inbyte.o bdm-isatty.o bdm-lseek.o \ + bdm-open.o bdm-outbyte.o bdm-read.o bdm-rename.o \ + bdm-stat.o bdm-system.o bdm-unlink.o bdm-write.o BDM_ISRS= other_interrupt reset access_error address_error \ illegal_instruction divide_by_zero privilege_violation \ trace unimplemented_line_a_opcode unimplemented_line_f_opcode \ @@ -179,8 +184,8 @@ ${DBUG_BSP}: $(OBJS) ${DBUG_OBJS} ${AR} ${ARFLAGS} $@ $(OBJS) ${DBUG_OBJS} ${RANLIB} $@ -${BDM_BSP}: $(OBJS) ${BDM_OBJS} - ${AR} ${ARFLAGS} $@ $(OBJS) ${BDM_OBJS} +${BDM_BSP}: $(BDM_OTHER_OBJS) ${BDM_OBJS} + ${AR} ${ARFLAGS} $@ $(BDM_OTHER_OBJS) ${BDM_OBJS} ${RANLIB} $@ ${MVME135_BSP}: $(OBJS) ${MVME135_OBJS} @@ -191,9 +196,10 @@ ${MVME162_BSP}: $(OBJS) ${MVME162_OBJS} ${AR} ${ARFLAGS} $@ $(OBJS) ${MVME162_OBJS} ${RANLIB} $@ + +$(BDM_SYSOBJS): %.o: %.c bdm-semihost.h bdm-gdb.h + $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) -c $< -o $@ bdm-isv.o : bdm-isv.c bdm-semihost.h -bdm-exit.o : bdm-exit.c bdm-semihost.h -bdm-outbyte.o : bdm-outbyte.c bdm-semihost.h bdm-semihost.o : bdm-semihost.c $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) -c $< -o $@ -fomit-frame-pointer diff --git a/libgloss/m68k/bdm-close.c b/libgloss/m68k/bdm-close.c new file mode 100644 index 000000000..25ed55076 --- /dev/null +++ b/libgloss/m68k/bdm-close.c @@ -0,0 +1,22 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <unistd.h> +#include <errno.h> + +/* + * close -- close a file descriptor. + * input parameters: + * 0 : file descriptor + * output parameters: + * 0 : result + * 1 : errno + */ + +int close (int fd) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) fd; + BDM_TRAP (BDM_CLOSE, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-exit.c b/libgloss/m68k/bdm-exit.c index 05212d9d5..71fa3af26 100644 --- a/libgloss/m68k/bdm-exit.c +++ b/libgloss/m68k/bdm-exit.c @@ -15,6 +15,7 @@ */ #include "bdm-semihost.h" +#include "bdm-gdb.h" /* * _exit -- Exit from the application. @@ -23,9 +24,7 @@ void __attribute__ ((noreturn)) _exit (int code) { while (1) - __asm__ __volatile__ ("move.l %0,%/" BDM_ARG_REG "\n" - "moveq %1,%/" BDM_FUNC_REG "\n" - "trap %2" - :: "rmi" (code), "n" (BDM_EXIT), "n" (BDM_TRAP) - : BDM_FUNC_REG,BDM_ARG_REG,BDM_RESULT_REG,"memory"); + { + BDM_TRAP (BDM_EXIT, code); + } } diff --git a/libgloss/m68k/bdm-fstat.c b/libgloss/m68k/bdm-fstat.c new file mode 100644 index 000000000..63a60939b --- /dev/null +++ b/libgloss/m68k/bdm-fstat.c @@ -0,0 +1,28 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <errno.h> + +/* + * fstat -- get file information + * input parameters: + * 0 : file descriptor + * 1 : stat buf ptr + * output parameters: + * 0 : result + * 1 : errno + */ + +int fstat (int fd, struct stat *buf) +{ + gdb_parambuf_t parameters; + struct gdb_stat gbuf; + parameters[0] = (uint32_t) fd; + parameters[1] = (uint32_t) &gbuf; + BDM_TRAP (BDM_FSTAT, (uint32_t)parameters); + convert_from_gdb_stat (&gbuf, buf); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-isatty.c b/libgloss/m68k/bdm-isatty.c new file mode 100644 index 000000000..0c4dadc0d --- /dev/null +++ b/libgloss/m68k/bdm-isatty.c @@ -0,0 +1,22 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <unistd.h> +#include <errno.h> + +/* + * isatty -- check if fd is a terminal + * input parameters: + * 0 : file descriptor + * output parameters: + * 0 : result + * 1 : errno + */ + +int isatty (int fd) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) fd; + BDM_TRAP (BDM_ISATTY, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-isrs.c b/libgloss/m68k/bdm-isrs.c index c44b42c8e..7ee9fbaa0 100644 --- a/libgloss/m68k/bdm-isrs.c +++ b/libgloss/m68k/bdm-isrs.c @@ -22,7 +22,7 @@ interrupt occurs. All they do is stop the debugger to give the user the opportunity to determine where the problem was. - User trap BDM_TRAP (15) is used for semi hosting support. + User trap BDM_TRAPNUM (15) is used for semi hosting support. If you replace this one, semihosting will cease to function. */ diff --git a/libgloss/m68k/bdm-isv.c b/libgloss/m68k/bdm-isv.c index daa481a55..b6a7e02b6 100644 --- a/libgloss/m68k/bdm-isv.c +++ b/libgloss/m68k/bdm-isv.c @@ -18,7 +18,7 @@ code for the interrupt vector. All but one of the interrupts are user replaceable. - User trap BDM_TRAP (15) is used for semi hosting support. + User trap BDM_TRAPNUM (15) is used for semi hosting support. If you replace this one, semihosting will cease to function. */ #include "bdm-semihost.h" @@ -144,5 +144,5 @@ void software_init_hook (void) __interrupt_vector[61] = &__unsupported_instruction; /* Install the special handler. */ - __interrupt_vector[0x20 + BDM_TRAP] = &__bdm_semihosting; + __interrupt_vector[0x20 + BDM_TRAPNUM] = &__bdm_semihosting; } diff --git a/libgloss/m68k/bdm-lseek.c b/libgloss/m68k/bdm-lseek.c new file mode 100644 index 000000000..f25b6384c --- /dev/null +++ b/libgloss/m68k/bdm-lseek.c @@ -0,0 +1,30 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <sys/types.h> +#include <unistd.h> +#include <errno.h> + +/* + * lseek -- reposition a file descriptor + * input parameters: + * 0 : file descriptor + * 1 : high word of offset + * 2 : low word of offset + * 3 : seek flag + * output parameters: + * 0 : high word of result + * 1 : low word of result + * 2 : errno + */ + +off_t lseek (int fd, off_t offset, int whence) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) fd; + parameters[1] = (uint32_t) ((offset >> 32) & 0xffffffff); + parameters[2] = (uint32_t) (offset & 0xffffffff); + parameters[3] = convert_to_gdb_lseek_flags (whence); + BDM_TRAP (BDM_LSEEK, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[2]); + return ((uint64_t)parameters[0] << 32) & ((uint64_t)parameters[1]); +} diff --git a/libgloss/m68k/bdm-open.c b/libgloss/m68k/bdm-open.c new file mode 100644 index 000000000..ee7f191ad --- /dev/null +++ b/libgloss/m68k/bdm-open.c @@ -0,0 +1,40 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdarg.h> +#include <string.h> +#include <errno.h> + +/* + * open -- Open a file. + * input parameters: + * 0 : fname ptr + * 1 : fname length + * 2 : flags + * 3 : mode + * output parameters: + * 0 : result + * 1 : errno + */ + +int open (const char *fname, int flags, ...) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) fname; + parameters[1] = strlen (fname) + 1; + parameters[2] = convert_to_gdb_open_flags (flags); + if (flags & O_CREAT) + { + va_list ap; + va_start (ap, flags); + parameters[3] = convert_to_gdb_mode_t (va_arg (ap, mode_t)); + va_end (ap); + } + else + parameters[3] = 0; + BDM_TRAP (BDM_OPEN, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-outbyte.c b/libgloss/m68k/bdm-outbyte.c index 032aaf16c..536c77717 100644 --- a/libgloss/m68k/bdm-outbyte.c +++ b/libgloss/m68k/bdm-outbyte.c @@ -23,10 +23,5 @@ void outbyte (char c) { int code = c & 0xff; - - __asm__ __volatile__ ("move.l %0,%/" BDM_ARG_REG "\n" - "moveq %1,%/" BDM_FUNC_REG "\n" - "trap %2" - :: "rmi" (code), "n" (BDM_PUTCHAR), "n" (BDM_TRAP) - : BDM_FUNC_REG,BDM_ARG_REG,BDM_RESULT_REG,"memory"); + BDM_TRAP (BDM_OUTBYTE, code); } diff --git a/libgloss/m68k/bdm-read.c b/libgloss/m68k/bdm-read.c new file mode 100644 index 000000000..bc87c65fa --- /dev/null +++ b/libgloss/m68k/bdm-read.c @@ -0,0 +1,26 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <unistd.h> +#include <errno.h> + +/* + * read -- read from a file descriptor + * input parameters: + * 0 : file descriptor + * 1 : buf ptr + * 2 : count + * output parameters: + * 0 : result + * 1 : errno + */ + +ssize_t read (int fd, void *buf, size_t count) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) fd; + parameters[1] = (uint32_t) buf; + parameters[2] = (uint32_t) count; + BDM_TRAP (BDM_READ, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-rename.c b/libgloss/m68k/bdm-rename.c new file mode 100644 index 000000000..01a730942 --- /dev/null +++ b/libgloss/m68k/bdm-rename.c @@ -0,0 +1,29 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <stdio.h> +#include <string.h> +#include <errno.h> + +/* + * rename -- rename a file + * input parameters: + * 0 : oldname ptr + * 1 : oldname length + * 2 : newname ptr + * 3 : newname length + * output parameters: + * 0 : result + * 1 : errno + */ + +int _rename (const char *oldpath, const char *newpath) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) oldpath; + parameters[1] = (uint32_t) strlen (oldpath) + 1; + parameters[2] = (uint32_t) newpath; + parameters[3] = (uint32_t) strlen (newpath) + 1; + BDM_TRAP (BDM_RENAME, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-semihost.h b/libgloss/m68k/bdm-semihost.h index 414a6b52c..43f4dcfe0 100644 --- a/libgloss/m68k/bdm-semihost.h +++ b/libgloss/m68k/bdm-semihost.h @@ -18,18 +18,41 @@ instruction. This wakes the debugger to perform some action. */ /* This is the semihosting trap hander */ -#define BDM_TRAP 15 +#define BDM_TRAPNUM 15 /* This register holds the function enumeration for a semihosting command. */ #define BDM_FUNC_REG "d0" -/* This register holds the argument for the semihosting call. */ + +/* This register holds the argument for the semihosting call. For most + functions, this is a pointer to a block of memory that holds the input + and output parameters for the remote file i/o operation. */ #define BDM_ARG_REG "d1" -/* This register holds the result of a semihosting call. */ -#define BDM_RESULT_REG "d0" -/* Program exit. Argument is exit code. */ +/* Codes for BDM_FUNC_REG. */ + #define BDM_EXIT 0 +#define BDM_OUTBYTE 1 +#define BDM_OPEN 2 +#define BDM_CLOSE 3 +#define BDM_READ 4 +#define BDM_WRITE 5 +#define BDM_LSEEK 6 +#define BDM_RENAME 7 +#define BDM_UNLINK 8 +#define BDM_STAT 9 +#define BDM_FSTAT 10 +#define BDM_GETTIMEOFDAY 11 +#define BDM_ISATTY 12 +#define BDM_SYSTEM 13 + + +/* Here is the macro that generates the trap. */ + +#define BDM_TRAP(func, arg) \ + __asm__ __volatile__ ("move.l %0,%/" BDM_ARG_REG "\n" \ + "moveq %1,%/" BDM_FUNC_REG "\n" \ + "trap %2" \ + :: "rmi" (arg), "n" (func), "n" (BDM_TRAPNUM) \ + : BDM_FUNC_REG,BDM_ARG_REG,"memory") -/* Output char to console. Argument is char to print. */ -#define BDM_PUTCHAR 1 diff --git a/libgloss/m68k/bdm-stat.c b/libgloss/m68k/bdm-stat.c new file mode 100644 index 000000000..890dfad03 --- /dev/null +++ b/libgloss/m68k/bdm-stat.c @@ -0,0 +1,32 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <errno.h> + +/* + * stat -- get file information + * input parameters: + * 0 : filename ptr + * 1 : filename length + * 2 : stat buf ptr + * output parameters: + * 0 : result + * 1 : errno + */ + + +int stat (const char *filename, struct stat *buf) +{ + gdb_parambuf_t parameters; + struct gdb_stat gbuf; + parameters[0] = (uint32_t) filename; + parameters[1] = (uint32_t) strlen (filename) + 1; + parameters[2] = (uint32_t) &gbuf; + BDM_TRAP (BDM_STAT, (uint32_t)parameters); + convert_from_gdb_stat (&gbuf, buf); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-system.c b/libgloss/m68k/bdm-system.c new file mode 100644 index 000000000..cc472cd52 --- /dev/null +++ b/libgloss/m68k/bdm-system.c @@ -0,0 +1,25 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +/* + * system: execute command on (remote) host + * input parameters: + * 0 : command ptr + * 1 : command length + * output parameters: + * 0 : result + * 1 : errno + */ + +int _system (const char *command) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) command; + parameters[1] = (uint32_t) strlen (command) + 1; + BDM_TRAP (BDM_SYSTEM, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-unlink.c b/libgloss/m68k/bdm-unlink.c new file mode 100644 index 000000000..75e5da78f --- /dev/null +++ b/libgloss/m68k/bdm-unlink.c @@ -0,0 +1,25 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <stdio.h> +#include <string.h> +#include <errno.h> + +/* + * unlink -- unlink (delete) a file + * input parameters: + * 0 : filename ptr + * 1 : filename length + * output parameters: + * 0 : result + * 1 : errno + */ + +int unlink (const char *path) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) path; + parameters[1] = (uint32_t) strlen (path) + 1; + BDM_TRAP (BDM_UNLINK, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/libgloss/m68k/bdm-write.c b/libgloss/m68k/bdm-write.c new file mode 100644 index 000000000..d1c390e26 --- /dev/null +++ b/libgloss/m68k/bdm-write.c @@ -0,0 +1,26 @@ +#include "bdm-semihost.h" +#include "bdm-gdb.h" +#include <unistd.h> +#include <errno.h> + +/* + * write -- write to a file descriptor + * input parameters: + * 0 : file descriptor + * 1 : buf ptr + * 2 : count + * output parameters: + * 0 : result + * 1 : errno + */ + +ssize_t write (int fd, const void *buf, size_t count) +{ + gdb_parambuf_t parameters; + parameters[0] = (uint32_t) fd; + parameters[1] = (uint32_t) buf; + parameters[2] = (uint32_t) count; + BDM_TRAP (BDM_WRITE, (uint32_t)parameters); + errno = convert_from_gdb_errno (parameters[1]); + return parameters[0]; +} diff --git a/newlib/configure.host b/newlib/configure.host index d85e8ad2c..cad506edb 100644 --- a/newlib/configure.host +++ b/newlib/configure.host @@ -594,6 +594,10 @@ case "${host}" in m68hc11-*-*|m6811-*-*|m68hc12-*-*|m6812-*-*) newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES" ;; + m68k-unknown-elf) + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; mcore-*-*) syscall_dir=syscalls ;; |