[PATCH] Add Blackfin support in newlib
Jeff Johnston
jjohnstn@redhat.com
Thu Oct 19 22:05:00 GMT 2006
Hi Joel,
Just to clarify. I had discussed this ahead of time with Jie and I
am ok with it. They (Analog Devices) requested to use the LGPL instead.
This is fine when segregated into bfin machine-specific directories
only. There is already an LGPL license in COPYING.NEWLIB that applies
when building x86-linux. It will be updated to apply when building for
BlackFin.
-- Jeff J.
Joel Sherrill wrote:
> I think the license on at least setjmp.S, crt0.S, and syscalls.[ch] is
> incompatible with newlib's licensing.
> These files are LGPL. I thought newlib only accept BSD (w/o
> advertising) and public domain
> code for truly embedded targets.
>
> +/* System call number for the Blackfin processor
> + Copyright (C) 2006 Analog Devices, Inc.
> +
> +This program is free software; you can redistribute it and/or
> +modify it under the terms of the GNU Lesser General Public
> +License as published by the Free Software Foundation; either
> +version 2.1 of the License, or (at your option) any later version.
> +
> +This program is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +Lesser General Public License for more details. */
>
> --joel
>
> Jeff Johnston wrote:
>
>> Hello Jie,
>>
>> Looks good, but I have a couple of issues.
>>
>> First, please put the syscalls and crt0.S into libgloss instead of
>> newlib/libc/sys/bfin. New ports no longer put syscall and startup
>> files in libc/sys. Using libgloss allows you flexibility in the
>> future to add additional bsp libraries (e.g. simulator vs real
>> processor).
>>
>> For your libc/machine/bfin Makefile.am, please look at the
>> libc/machine/fr30 directory. You should base your Makefile.am on that
>> (adding any other files to lib_a_SOURCES). This sets some flags
>> needed to ensure compilation flags are passed properly down from the
>> top-level.
>>
>> -- Jeff J.
>>
>> Jie Zhang wrote:
>>
>>> Hi,
>>>
>>> We (Analog Devices, Inc.) have ported newlib to Blackfin processor and
>>> would like to contribute back. We ported newlib mainly for testing
>>> Blackfin GCC/Binutils/GDB on simulator. We have contributed Blackfin
>>> port GCC and binutils to their respective projects. Contributing
>>> Blackfin GDB to FSF is going on.
>>>
>>> This new port is being used in our daily toolchain testing on
>>> simulator. The results seem OK.
>>>
>>> Is this port in a good shape to be accepted? Any comments are
>>> appreciated.
>>>
>>> Thanks,
>>> Jie Zhang
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> * configure.host: Add bfin support.
>>> * libc/include/machine/ieeefp.h: Define __IEEE_LITTLE_ENDIAN for
>>> bfin.
>>> * libc/include/machine/setjmp.h: Define _JBLEN for bfin.
>>> * libc/machine/bfin/access.c: New.
>>> * libc/machine/bfin/aclocal.m4: Generate.
>>> * libc/machine/bfin/configure.in: New.
>>> * libc/machine/bfin/configure: Generate.
>>> * libc/machine/bfin/Makefile.am: New.
>>> * libc/machine/bfin/Makefile.in: Generate.
>>> * libc/machine/bfin/setjmp.S: New.
>>> * libc/machine/configure.in: Add bfin support.
>>> * libc/sys/bfin/aclocal.m4: Generate.
>>> * libc/sys/bfin/configure.in: New.
>>> * libc/sys/bfin/configure: Generate.
>>> * libc/sys/bfin/crt0.S: New.
>>> * libc/sys/bfin/Makefile.am: New.
>>> * libc/sys/bfin/Makefile.in: Generate.
>>> * libc/sys/bfin/sys/syscall.h: New.
>>> * libc/sys/bfin/sys/syscalls.c: New.
>>> * libc/sys/configure.in: Add bfin support.
>>> * libc/sys/configure: Generate.
>>>
>>> diff -r -u -p -N -x CVS newlib-orig/src/newlib/configure.host
>>> newlib/src/newlib/configure.host
>>> --- newlib-orig/src/newlib/configure.host 2006-10-11
>>> 00:50:06.000000000 +0800
>>> +++ newlib/src/newlib/configure.host 2006-10-11 01:25:19.000000000
>>> +0800
>>> @@ -99,6 +99,9 @@ case "${host_cpu}" in
>>> avr*)
>>> newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED
>>> -mcall-prologues"
>>> ;;
>>> + bfin)
>>> + machine_dir=bfin
>>> + ;;
>>> cris | crisv32)
>>> machine_dir=cris
>>> ;;
>>> @@ -334,6 +337,9 @@ case "${host}" in
>>> have_crt0="no"
>>> fi
>>> ;;
>>> + bfin-*-*)
>>> + sys_dir=bfin
>>> + ;;
>>> crx*)
>>> sys_dir=
>>> ;;
>>> @@ -539,6 +545,9 @@ case "${host}" in
>>> avr*)
>>> newlib_cflags="${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY
>>> -DMISSING_SYSCALL_NAMES"
>>> ;;
>>> + bfin*)
>>> + syscall_dir=syscalls
>>> + ;;
>>> cris-*-* | crisv32-*-*)
>>> default_newlib_io_long_long="yes"
>>> newlib_cflags="${newlib_cflags} -DHAVE_RENAME -D_USE_WRITE
>>> -DCOMPACT_CTYPE"
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/include/machine/ieeefp.h
>>> newlib/src/newlib/libc/include/machine/ieeefp.h
>>> --- newlib-orig/src/newlib/libc/include/machine/ieeefp.h
>>> 2006-10-11 00:50:07.000000000 +0800
>>> +++ newlib/src/newlib/libc/include/machine/ieeefp.h 2006-10-11
>>> 01:25:19.000000000 +0800
>>> @@ -283,6 +283,10 @@
>>> #define __IEEE_LITTLE_ENDIAN
>>> #endif
>>>
>>> +#ifdef BFIN
>>> +#define __IEEE_LITTLE_ENDIAN
>>> +#endif
>>> +
>>> #ifndef __IEEE_BIG_ENDIAN
>>> #ifndef __IEEE_LITTLE_ENDIAN
>>> #error Endianess not declared!!
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/include/machine/setjmp.h
>>> newlib/src/newlib/libc/include/machine/setjmp.h
>>> --- newlib-orig/src/newlib/libc/include/machine/setjmp.h
>>> 2006-10-11 00:50:07.000000000 +0800
>>> +++ newlib/src/newlib/libc/include/machine/setjmp.h 2006-10-11
>>> 01:25:19.000000000 +0800
>>> @@ -21,6 +21,10 @@ _BEGIN_STD_C
>>> #define _JBLEN 13
>>> #endif
>>>
>>> +#ifdef bfin
>>> +#define _JBLEN 40
>>> +#endif
>>> +
>>> /* necv70 was 9 as well. */
>>>
>>> #ifdef __mc68000__
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/machine/bfin/access.c
>>> newlib/src/newlib/libc/machine/bfin/access.c
>>> --- newlib-orig/src/newlib/libc/machine/bfin/access.c 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/machine/bfin/access.c 2006-10-11
>>> 01:25:19.000000000 +0800
>>> @@ -0,0 +1,33 @@
>>> +/* This is file ACCESS.C */
>>> +/*
>>> + * Copyright (C) 1993 DJ Delorie
>>> + * All rights reserved.
>>> + *
>>> + * Redistribution and use in source and binary forms is permitted
>>> + * provided that the above copyright notice and following paragraph are
>>> + * duplicated in all such forms.
>>> + *
>>> + * This file is distributed WITHOUT ANY WARRANTY; without even the
>>> implied
>>> + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>>> + */
>>> +
>>> +#include <fcntl.h>
>>> +#include <sys/stat.h>
>>> +#include <unistd.h>
>>> +
>>> +int access(const char *fn, int flags)
>>> +{
>>> + struct stat s;
>>> + if (stat(fn, &s))
>>> + return -1;
>>> + if (s.st_mode & S_IFDIR)
>>> + return 0;
>>> + if (flags & W_OK)
>>> + {
>>> + if (s.st_mode & S_IWRITE)
>>> + return 0;
>>> + return -1;
>>> + }
>>> + return 0;
>>> +}
>>> + diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/machine/bfin/configure.in
>>> newlib/src/newlib/libc/machine/bfin/configure.in
>>> --- newlib-orig/src/newlib/libc/machine/bfin/configure.in
>>> 1970-01-01 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/machine/bfin/configure.in 2006-10-11
>>> 12:08:03.000000000 +0800
>>> @@ -0,0 +1,14 @@
>>> +dnl This is the newlib/libc/machine/bfin configure.in file.
>>> +dnl Process this file with autoconf to produce a configure script.
>>> +
>>> +AC_PREREQ(2.59)
>>> +AC_INIT([newlib],[NEWLIB_VERSION])
>>> +AC_CONFIG_SRCDIR([Makefile.am])
>>> +
>>> +dnl Can't be done in NEWLIB_CONFIGURE because that confuses
>>> automake. +AC_CONFIG_AUX_DIR(../../../..)
>>> +
>>> +NEWLIB_CONFIGURE(../../..)
>>> +
>>> +AC_CONFIG_FILES([Makefile])
>>> +AC_OUTPUT
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/machine/bfin/Makefile.am
>>> newlib/src/newlib/libc/machine/bfin/Makefile.am
>>> --- newlib-orig/src/newlib/libc/machine/bfin/Makefile.am
>>> 1970-01-01 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/machine/bfin/Makefile.am 2006-10-19
>>> 09:17:54.000000000 +0800
>>> @@ -0,0 +1,12 @@
>>> +## Process this file with automake to generate Makefile.in
>>> +
>>> +AUTOMAKE_OPTIONS = cygnus
>>> +
>>> +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
>>> +
>>> +noinst_LIBRARIES = lib.a
>>> +
>>> +lib_a_SOURCES = setjmp.S access.c
>>> +
>>> +ACLOCAL_AMFLAGS = -I ../../..
>>> +CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/machine/bfin/setjmp.S
>>> newlib/src/newlib/libc/machine/bfin/setjmp.S
>>> --- newlib-orig/src/newlib/libc/machine/bfin/setjmp.S 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/machine/bfin/setjmp.S 2006-10-19
>>> 09:27:21.000000000 +0800
>>> @@ -0,0 +1,106 @@
>>> +/* Setjmp for the Blackfin processor
>>> + Copyright (C) 2006 Analog Devices, Inc.
>>> +
>>> +This program is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU Lesser General Public
>>> +License as published by the Free Software Foundation; either
>>> +version 2.1 of the License, or (at your option) any later version.
>>> +
>>> +This program is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>>> +Lesser General Public License for more details. */
>>> +
>>> +#define _ASM
>>> +#define _SETJMP_H
>>> +
>>> +.globl ___sigsetjmp;
>>> +.align 4;
>>> +
>>> +___sigsetjmp:
>>> + [--SP] = P0; /* Save P0 */
>>> + P0 = R0;
>>> + R0 = [SP++]; + [P0 + 0x00] = R0; /* Save saved P0 */
>>> + [P0 + 0x04] = P1;
>>> + [P0 + 0x08] = P2;
>>> + [P0 + 0x0C] = P3;
>>> + [P0 + 0x10] = P4;
>>> + [P0 + 0x14] = P5;
>>> +
>>> + [P0 + 0x18] = FP; /* Frame Pointer */
>>> + [P0 + 0x1C] = SP; /* Stack Pointer */
>>> +
>>> + [P0 + 0x20] = P0; /* Data Registers */
>>> + [P0 + 0x24] = R1;
>>> + [P0 + 0x28] = R2;
>>> + [P0 + 0x2C] = R3;
>>> + [P0 + 0x30] = R4;
>>> + [P0 + 0x34] = R5;
>>> + [P0 + 0x38] = R6;
>>> + [P0 + 0x3C] = R7;
>>> +
>>> + R0 = ASTAT;
>>> + [P0 + 0x40] = R0;
>>> +
>>> + R0 = LC0; /* Loop Counters */
>>> + [P0 + 0x44] = R0;
>>> + R0 = LC1;
>>> + [P0 + 0x48] = R0;
>>> +
>>> + R0 = A0.W; /* Accumulators */
>>> + [P0 + 0x4C] = R0;
>>> + R0 = A0.X;
>>> + [P0 + 0x50] = R0;
>>> + R0 = A1.W;
>>> + [P0 + 0x54] = R0;
>>> + R0 = A1.X;
>>> + [P0 + 0x58] = R0;
>>> +
>>> + R0 = I0; /* Index Registers */
>>> + [P0 + 0x5C] = R0;
>>> + R0 = I1;
>>> + [P0 + 0x60] = R0;
>>> + R0 = I2;
>>> + [P0 + 0x64] = R0;
>>> + R0 = I3;
>>> + [P0 + 0x68] = R0;
>>> +
>>> + R0 = M0; /* Modifier Registers */
>>> + [P0 + 0x6C] = R0;
>>> + R0 = M1;
>>> + [P0 + 0x70] = R0;
>>> + R0 = M2;
>>> + [P0 + 0x74] = R0;
>>> + R0 = M3;
>>> + [P0 + 0x78] = R0;
>>> +
>>> + R0 = L0; /* Length Registers */
>>> + [P0 + 0x7c] = R0;
>>> + R0 = L1;
>>> + [P0 + 0x80] = R0;
>>> + R0 = L2;
>>> + [P0 + 0x84] = R0;
>>> + R0 = L3;
>>> + [P0 + 0x88] = R0;
>>> +
>>> + R0 = B0; /* Base Registers */
>>> + [P0 + 0x8C] = R0;
>>> + R0 = B1;
>>> + [P0 + 0x90] = R0;
>>> + R0 = B2;
>>> + [P0 + 0x94] = R0;
>>> + R0 = B3;
>>> + [P0 + 0x98] = R0;
>>> +
>>> + R0 = RETS;
>>> + [P0 + 0x9C] = R0;
>>> +
>>> + R0 = [P0 + 0x20];
>>> + CC = R1 == 1;
>>> + IF CC JUMP L$L$finished;
>>> + CALL ___sigjmp_save; +L$L$finished:
>>> + R0 = 0;
>>> + RTS;
>>> +___sigsetjmp.end:
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/machine/configure.in
>>> newlib/src/newlib/libc/machine/configure.in
>>> --- newlib-orig/src/newlib/libc/machine/configure.in 2006-10-11
>>> 00:50:07.000000000 +0800
>>> +++ newlib/src/newlib/libc/machine/configure.in 2006-10-11
>>> 14:07:56.000000000 +0800
>>> @@ -24,6 +24,7 @@ if test -n "${machine_dir}"; then
>>> case ${machine_dir} in
>>> a29k) AC_CONFIG_SUBDIRS(a29k) ;;
>>> arm) AC_CONFIG_SUBDIRS(arm) ;;
>>> + bfin) AC_CONFIG_SUBDIRS(bfin) ;;
>>> cris) AC_CONFIG_SUBDIRS(cris) ;;
>>> crx) AC_CONFIG_SUBDIRS(crx) ;;
>>> d10v) AC_CONFIG_SUBDIRS(d10v) ;;
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/sys/bfin/configure.in
>>> newlib/src/newlib/libc/sys/bfin/configure.in
>>> --- newlib-orig/src/newlib/libc/sys/bfin/configure.in 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/sys/bfin/configure.in 2006-10-11
>>> 01:39:00.000000000 +0800
>>> @@ -0,0 +1,14 @@
>>> +dnl This is the newlib/libc/sys/bfin configure.in file.
>>> +dnl Process this file with autoconf to produce a configure script.
>>> +
>>> +AC_PREREQ(2.59)
>>> +AC_INIT([newlib],[NEWLIB_VERSION])
>>> +AC_CONFIG_SRCDIR([syscalls.c])
>>> +
>>> +dnl Can't be done in NEWLIB_CONFIGURE because that confuses
>>> automake. +AC_CONFIG_AUX_DIR(../../../..)
>>> +
>>> +NEWLIB_CONFIGURE(../../..)
>>> +
>>> +AC_CONFIG_FILES([Makefile])
>>> +AC_OUTPUT
>>> diff -r -u -p -N -x CVS newlib-orig/src/newlib/libc/sys/bfin/crt0.S
>>> newlib/src/newlib/libc/sys/bfin/crt0.S
>>> --- newlib-orig/src/newlib/libc/sys/bfin/crt0.S 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/sys/bfin/crt0.S 2006-10-19
>>> 09:28:34.000000000 +0800
>>> @@ -0,0 +1,69 @@
>>> +/* Crt0.S for the Blackfin processor
>>> + Copyright (C) 2006 Analog Devices, Inc.
>>> +
>>> +This program is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU Lesser General Public
>>> +License as published by the Free Software Foundation; either
>>> +version 2.1 of the License, or (at your option) any later version.
>>> +
>>> +This program is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>>> +Lesser General Public License for more details. */
>>> +
>>> + .text
>>> + .align 2
>>> +
>>> + .global __start
>>> +__start:
>>> +
>>> + /* Start by setting up a stack */
>>> + link 0xc;
>>> + /* Zero the memory in the .bss section. */
>>> +
>>> + p0.l = __edata;
>>> + p0.h = __edata;
>>> + p1.l = __end;
>>> + p1.h = __end;
>>> + p1 -= p0;
>>> + r0 = 0;
>>> + lsetup (L$L$clear_bss, L$L$clear_bss) lc0 = p1;
>>> +L$L$clear_bss:
>>> + B [p0++] = r0;
>>> +
>>> +#ifdef __BFIN_FDPIC__
>>> + /* Set up GOT pointer. */
>>> + P0.L = __ROFIXUP_END__;
>>> + P0.H = __ROFIXUP_END__;
>>> + P4 = [P0 - 4];
>>> +#endif
>>> +
>>> + /* Need to set up standard file handles */
>>> + /* Parse string at r1 */
>>> +
>>> + p0.l = __init;
>>> + p0.h = __init; + P3 = P4; + call (p0)
>>> +
>>> + p0.l = _atexit;
>>> + p0.h = _atexit;
>>> +#ifdef __BFIN_FDPIC__
>>> + r0 = [P4 + __fini@FUNCDESC_GOT17M4] ; + P3 = P4; +#else
>>> + r0.l = __fini;
>>> + r0.h = __fini;
>>> +#endif
>>> + call (p0)
>>> +
>>> + p0.l = ___setup_argv_and_call_main;
>>> + p0.h = ___setup_argv_and_call_main; + P3 = P4; + call (p0)
>>> +
>>> + p0.l = _exit;
>>> + p0.h = _exit; + P3 = P4; + jump (p0) /* Should
>>> not return. */
>>> + nop;
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/sys/bfin/Makefile.am
>>> newlib/src/newlib/libc/sys/bfin/Makefile.am
>>> --- newlib-orig/src/newlib/libc/sys/bfin/Makefile.am 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/sys/bfin/Makefile.am 2006-10-19
>>> 09:32:56.000000000 +0800
>>> @@ -0,0 +1,14 @@
>>> +## Process this file with automake to generate Makefile.in
>>> +
>>> +AUTOMAKE_OPTIONS = cygnus
>>> +
>>> +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
>>> +
>>> +noinst_LIBRARIES = lib.a
>>> +
>>> +lib_a_SOURCES = crt0.S syscalls.c
>>> +
>>> +all: crt0.o
>>> +
>>> +ACLOCAL_AMFLAGS = -I ../../..
>>> +CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/sys/bfin/sys/syscall.h
>>> newlib/src/newlib/libc/sys/bfin/sys/syscall.h
>>> --- newlib-orig/src/newlib/libc/sys/bfin/sys/syscall.h 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/sys/bfin/sys/syscall.h 2006-10-19
>>> 09:37:10.000000000 +0800
>>> @@ -0,0 +1,52 @@
>>> +/* System call number for the Blackfin processor
>>> + Copyright (C) 2006 Analog Devices, Inc.
>>> +
>>> +This program is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU Lesser General Public
>>> +License as published by the Free Software Foundation; either
>>> +version 2.1 of the License, or (at your option) any later version.
>>> +
>>> +This program is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>>> +Lesser General Public License for more details. */
>>> +
>>> +#define SYS_exit 1
>>> +#define SYS_fork 2
>>> +#define SYS_read 3
>>> +#define SYS_write 4
>>> +#define SYS_open 5
>>> +#define SYS_close 6
>>> +#define SYS_wait4 7
>>> +#define SYS_creat 8
>>> +#define SYS_link 9
>>> +#define SYS_unlink 10
>>> +#define SYS_execv 11
>>> +#define SYS_chdir 12
>>> +
>>> +#define SYS_mknod 14
>>> +#define SYS_chmod 15
>>> +#define SYS_chown 16
>>> +
>>> +#define SYS_lseek 19
>>> +#define SYS_getpid 20
>>> +#define SYS_isatty 21
>>> +#define SYS_fstat 22
>>> +#define SYS_time 23
>>> +#define SYS_kill 24
>>> +
>>> +#define SYS_stat 38
>>> +
>>> +#define SYS_pipe 42
>>> +
>>> +#define SYS_execve 59
>>> +
>>> +#define SYS_truncate 129
>>> +#define SYS_ftruncate 130
>>> +
>>> +#define SYS_argc 172
>>> +#define SYS_argnlen 173
>>> +#define SYS_argn 174
>>> +
>>> +#define SYS_utime 201
>>> +#define SYS_wait 202
>>> diff -r -u -p -N -x CVS
>>> newlib-orig/src/newlib/libc/sys/bfin/syscalls.c
>>> newlib/src/newlib/libc/sys/bfin/syscalls.c
>>> --- newlib-orig/src/newlib/libc/sys/bfin/syscalls.c 1970-01-01
>>> 08:00:00.000000000 +0800
>>> +++ newlib/src/newlib/libc/sys/bfin/syscalls.c 2006-10-19
>>> 09:35:48.000000000 +0800
>>> @@ -0,0 +1,261 @@
>>> +/* C library support files for the Blackfin processor
>>> + Copyright (C) 2006 Analog Devices, Inc.
>>> +
>>> +This program is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU Lesser General Public
>>> +License as published by the Free Software Foundation; either
>>> +version 2.1 of the License, or (at your option) any later version.
>>> +
>>> +This program is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>>> +Lesser General Public License for more details. */
>>> +
>>> +#include <_ansi.h>
>>> +#include <sys/types.h>
>>> +#include <sys/stat.h>
>>> +#include <sys/fcntl.h>
>>> +#include <stdio.h>
>>> +#include <time.h>
>>> +#include <sys/time.h>
>>> +#include <sys/times.h>
>>> +#include "sys/syscall.h"
>>> +#include <errno.h>
>>> +#include <reent.h>
>>> +#include <unistd.h>
>>> +
>>> +register char *stack_ptr asm ("SP");
>>> +
>>> +static inline int
>>> +do_syscall (int reason, void *arg)
>>> +{
>>> + int result;
>>> + asm volatile ("[--sp] = %1; [--sp] = %2; \
>>> + r1 = [sp++]; r0 = [sp++]; \
>>> + raise 0; %0 = r0;"
>>> + : "=r" (result)
>>> + : "r" (reason), "r" (arg)
>>> + : "R0", "R1", "memory", "cc");
>>> + return result;
>>> +}
>>> +
>>> +int
>>> +_read (int file, char *ptr, int len)
>>> +{
>>> + int block[3];
>>> +
>>> + block[0] = file;
>>> + block[1] = (int) ptr;
>>> + block[2] = len;
>>> + + return do_syscall (SYS_read, block);
>>> +}
>>> +
>>> +int
>>> +_lseek (int file, int ptr, int dir)
>>> +{
>>> + int block[2];
>>> +
>>> + block[0] = file;
>>> + block[1] = ptr;
>>> +
>>> + return do_syscall (SYS_lseek, block);
>>> +}
>>> +
>>> +int
>>> +_write (int file, char *ptr, int len)
>>> +{
>>> + int block[3];
>>> + + block[0] = file;
>>> + block[1] = (int) ptr;
>>> + block[2] = len;
>>> + + return do_syscall (SYS_write, block);
>>> +}
>>> +
>>> +int
>>> +_open (const char *path, int flags)
>>> +{
>>> + int block[2];
>>> +
>>> + block[0] = (int) path;
>>> + block[1] = flags;
>>> +
>>> + return do_syscall (SYS_open, block);
>>> +}
>>> +
>>> +int
>>> +_close (int file)
>>> +{
>>> + return do_syscall (SYS_close, &file);
>>> +}
>>> +
>>> +void
>>> +_exit (int n)
>>> +{
>>> + do_syscall (SYS_exit, &n);
>>> +}
>>> +
>>> +int
>>> +_kill (int n, int m)
>>> +{
>>> + int block[2];
>>> +
>>> + block[0] = n;
>>> + block[1] = m;
>>> +
>>> + return do_syscall (SYS_kill, block);
>>> +}
>>> +
>>> +int
>>> +_getpid (int n)
>>> +{
>>> + return 1;
>>> +}
>>> +
>>> +caddr_t
>>> +_sbrk (int incr)
>>> +{
>>> + extern char end; /* Defined by the linker. */
>>> + static char *heap_end;
>>> + char *prev_heap_end;
>>> +
>>> + if (heap_end == NULL)
>>> + heap_end = &end;
>>> + + prev_heap_end = heap_end;
>>> + + if (heap_end + incr > stack_ptr)
>>> + {
>>> + /* Some of the libstdc++-v3 tests rely upon detecting
>>> + out of memory errors, so do not abort here. */
>>> +#if 0
>>> + extern void abort (void);
>>> +
>>> + _write (1, "_sbrk: Heap and stack collision\n", 32);
>>> + + abort ();
>>> +#else
>>> + errno = ENOMEM;
>>> + return (caddr_t) -1;
>>> +#endif
>>> + }
>>> + + heap_end += incr;
>>> +
>>> + return (caddr_t) prev_heap_end;
>>> +}
>>> +
>>> +extern void memset (struct stat *, int, unsigned int);
>>> +
>>> +int
>>> +_fstat (int file, struct stat * st)
>>> +{
>>> + memset (st, 0, sizeof (* st));
>>> + st->st_mode = S_IFCHR;
>>> + st->st_blksize = 1024;
>>> + return 0;
>>> +}
>>> +
>>> +int _stat (const char *fname, struct stat *st)
>>> +{
>>> + int file;
>>> +
>>> + /* 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 ((file = _open (fname, O_RDONLY)) < 0)
>>> + return -1;
>>> +
>>> + memset (st, 0, sizeof (* st));
>>> + st->st_mode = S_IFREG | S_IREAD;
>>> + st->st_blksize = 1024;
>>> + _close (file); /* Not interested in the error. */
>>> + return 0;
>>> +}
>>> +
>>> +int
>>> +_link (void)
>>> +{
>>> + return -1;
>>> +}
>>> +
>>> +int
>>> +_unlink (void)
>>> +{
>>> + return -1;
>>> +}
>>> +
>>> +void
>>> +_raise (void)
>>> +{
>>> + return;
>>> +}
>>> +
>>> +int
>>> +_gettimeofday (struct timeval *tv, struct timezone *tz)
>>> +{
>>> + tv->tv_usec = 0;
>>> + tv->tv_sec = do_syscall (SYS_time, 0);
>>> + return 0;
>>> +}
>>> +
>>> +/* Return a clock that ticks at 100Hz. */
>>> +clock_t +_times (struct tms * tp)
>>> +{
>>> + return -1;
>>> +}
>>> +
>>> +int
>>> +isatty (int fd)
>>> +{
>>> + return 1;
>>> +}
>>> +
>>> +int
>>> +_system (const char *s)
>>> +{
>>> + if (s == NULL)
>>> + return 0;
>>> + errno = ENOSYS;
>>> + return -1;
>>> +}
>>> +
>>> +int
>>> +_rename (const char * oldpath, const char * newpath)
>>> +{
>>> + errno = ENOSYS;
>>> + return -1;
>>> +}
>>> +
>>> +static inline int
>>> +__setup_argv_for_main (int argc)
>>> +{
>>> + int block[2];
>>> + char **argv;
>>> + int i = argc;
>>> +
>>> + argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
>>> +
>>> + argv[i] = NULL;
>>> + while (i--) {
>>> + block[0] = i;
>>> + argv[i] = __builtin_alloca (1 + do_syscall (SYS_argnlen, (void
>>> *)block));
>>> + block[1] = (int) argv[i];
>>> + do_syscall (SYS_argn, (void *)block);
>>> + }
>>> +
>>> + return main (argc, argv);
>>> +}
>>> +
>>> +int
>>> +__setup_argv_and_call_main ()
>>> +{
>>> + int argc = do_syscall (SYS_argc, 0);
>>> +
>>> + if (argc <= 0)
>>> + return main (argc, NULL);
>>> + else
>>> + return __setup_argv_for_main (argc);
>>> +}
>>> diff -r -u -p -N -x CVS newlib-orig/src/newlib/libc/sys/configure.in
>>> newlib/src/newlib/libc/sys/configure.in
>>> --- newlib-orig/src/newlib/libc/sys/configure.in 2006-10-11
>>> 00:50:16.000000000 +0800
>>> +++ newlib/src/newlib/libc/sys/configure.in 2006-10-11
>>> 14:06:36.000000000 +0800
>>> @@ -23,6 +23,7 @@ if test -n "${sys_dir}"; then
>>> a29khif) AC_CONFIG_SUBDIRS(a29khif) ;;
>>> arc) AC_CONFIG_SUBDIRS(arc) ;;
>>> arm) AC_CONFIG_SUBDIRS(arm) ;;
>>> + bfin) AC_CONFIG_SUBDIRS(bfin) ;;
>>> d10v) AC_CONFIG_SUBDIRS(d10v) ;;
>>> decstation) AC_CONFIG_SUBDIRS(decstation) ;;
>>> h8300hms) AC_CONFIG_SUBDIRS(h8300hms) ;;
>>
>>
>
More information about the Newlib
mailing list