[uClibc-cvs] uClibc/libc/sysdeps/linux/sh64 Makefile, NONE, 1.1 __init_brk.c, NONE, 1.1 brk.c, NONE, 1.1 crt0.S, NONE, 1.1 fork.c, NONE, 1.1 longjmp.S, NONE, 1.1 sbrk.c, NONE, 1.1 setjmp.S, NONE, 1.1

Erik Andersen andersen at uclibc.org
Wed Aug 13 20:08:31 UTC 2003


Update of /var/cvs/uClibc/libc/sysdeps/linux/sh64
In directory winder:/tmp/cvs-serv6191/libc/sysdeps/linux/sh64

Added Files:
	Makefile __init_brk.c brk.c crt0.S fork.c longjmp.S sbrk.c 
	setjmp.S 
Log Message:
Patch from Paul Mundt adding uClibc sh64 support:

Here's a patch that implements the beginnings of a rudimentary sh64 port. So
far, this only works static, as I haven't done any of the ldso work yet. I've
also not touched the libpthread stuff yet either, so that's also disabled for
now.

This port was based off of some work that Sean McGoogan at SuperH did for his
initial port, but the this patch doesn't carry over too much from there
(basically the libc/sysdeps/linux/sh64/Makefile (or rather, parts of it),
the setjmp/longjmp stuff (which I had to rewrite portions of it to work with
the new toolchains), etc.).

However, for static, everything appears to work correcly, at least in a hello
world type application.




--- NEW FILE: fork.c ---
/* vi: set sw=4 ts=4: */
/*
 * fork for uClibc
 *
 * Copyright (C) 2000 by Lineo, inc.  Written by Erik Andersen
 * <andersen at lineo.com>, <andersee at debian.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Library General Public License as published by
 * the Free Software Foundation; either version 2 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 Library General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <errno.h>
#include <features.h>
#include <sys/types.h>
#include <sys/syscall.h>

#ifndef __HAS_NO_MMU__

//#define __NR_fork             2
#include <unistd.h>
_syscall0(pid_t, fork);

#endif

--- NEW FILE: setjmp.S ---
/* setjmp for SH-5.
   Copyright (C) 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The GNU C Library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */


#define _SETJMP_H
#define _ASM
#include <bits/setjmp.h>


#define	INTEGER(reg,offset)	st.q	r2, offset*8, reg
#define	DOUBLE(reg,offset)	fst.d	r2, offset*8, reg


	.file	"setjmp.S"

	.section .text64,"xa"
	.align 2

	.global	__sigsetjmp	
	.type	__sigsetjmp, at function

__sigsetjmp:
	/*
	 *	extern int __sigsetjmp(jmp_buf env, int savemask);
	 *
	 *	r2 == env
	 *	r3 == savemask
	 *	r4 == temporary
	 */

			/* callee-save registers R10-R16 */
	INTEGER(r10, __SETJMP_INT(0))
	INTEGER(r11, __SETJMP_INT(1))
	INTEGER(r12, __SETJMP_INT(2))
	INTEGER(r13, __SETJMP_INT(3))
	INTEGER(r14, __SETJMP_INT(4))
	INTEGER(r15, __SETJMP_INT(5))
	INTEGER(r16, __SETJMP_INT(6))

			/* callee-save registers R28-R35 */
	INTEGER(r28, __SETJMP_INT(7))
	INTEGER(r29, __SETJMP_INT(8))
	INTEGER(r30, __SETJMP_INT(9))
	INTEGER(r31, __SETJMP_INT(10))
	INTEGER(r32, __SETJMP_INT(11))
	INTEGER(r33, __SETJMP_INT(12))
	INTEGER(r34, __SETJMP_INT(13))
	INTEGER(r35, __SETJMP_INT(14))

			/* callee-save registers R44-R59 */
	INTEGER(r44, __SETJMP_INT(15))
	INTEGER(r45, __SETJMP_INT(16))
	INTEGER(r46, __SETJMP_INT(17))
	INTEGER(r47, __SETJMP_INT(18))
	INTEGER(r48, __SETJMP_INT(19))
	INTEGER(r49, __SETJMP_INT(20))
	INTEGER(r50, __SETJMP_INT(21))
	INTEGER(r51, __SETJMP_INT(22))
	INTEGER(r52, __SETJMP_INT(23))
	INTEGER(r53, __SETJMP_INT(24))
	INTEGER(r54, __SETJMP_INT(25))
	INTEGER(r55, __SETJMP_INT(26))
	INTEGER(r56, __SETJMP_INT(27))
	INTEGER(r57, __SETJMP_INT(28))
	INTEGER(r58, __SETJMP_INT(29))
	INTEGER(r59, __SETJMP_INT(30))

	#if __SETJMP_NUM_INT != 31
	#error	__SETJMP_NUM_INT does agree with expected value
	#endif

#if __SETJMP_NUM_DBL > 0
			/* callee-save registers FR12-FR15 */
	DOUBLE(d12, __SETJMP_DBL(0))
	DOUBLE(d14, __SETJMP_DBL(1))

			/* callee-save registers FR36-FR63 */
	DOUBLE(d36, __SETJMP_DBL(2))
	DOUBLE(d38, __SETJMP_DBL(3))
	DOUBLE(d40, __SETJMP_DBL(4))
	DOUBLE(d42, __SETJMP_DBL(5))
	DOUBLE(d44, __SETJMP_DBL(6))
	DOUBLE(d46, __SETJMP_DBL(7))
	DOUBLE(d48, __SETJMP_DBL(8))
	DOUBLE(d50, __SETJMP_DBL(9))
	DOUBLE(d52, __SETJMP_DBL(10))
	DOUBLE(d54, __SETJMP_DBL(11))
	DOUBLE(d56, __SETJMP_DBL(12))
	DOUBLE(d58, __SETJMP_DBL(13))
	DOUBLE(d60, __SETJMP_DBL(14))
	DOUBLE(d62, __SETJMP_DBL(15))

	#if __SETJMP_NUM_DBL != 16
	#error	__SETJMP_NUM_DBL does agree with expected value
	#endif

#endif	/* __SETJMP_NUM_DBL > 0 */

			/* callee-save registers TR5-TR7 */
	gettr   tr5, r4
	INTEGER(r4, __SETJMP_TRG(0))
	gettr   tr6, r4
	INTEGER(r4, __SETJMP_TRG(1))
	gettr   tr7, r4
	INTEGER(r4, __SETJMP_TRG(2))

	#if __SETJMP_NUM_TRG != 3
	#error	__SETJMP_NUM_TRG does agree with expected value
	#endif

			/* save Linkage Register (LR) for longjmp return */
	INTEGER(r18, __SETJMP_LR)

			/*
			 *	return a value of zero if call is __sigsetjmp().
			 *	This is so that caller of setjmp() knows
			 *	we have retruned via setjmp, and not via longjmp.
			 *	R0 is the result register.
			 */

	ptabs/l	r18, tr0	/* return to caller */
	movi	0, r2	/* return value */
	blink	tr0, r63


--- NEW FILE: brk.c ---
/* From libc-5.3.12 */

#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>

extern void * ___brk_addr;

extern int __init_brk (void);
extern void *_brk(void *ptr);

int brk(void * end_data_seg)
{
    if (__init_brk () == 0)
    {
		___brk_addr = _brk(end_data_seg);
		if (___brk_addr == end_data_seg)
			return 0;
		__set_errno(ENOMEM);
    }
    return -1;
}

--- NEW FILE: Makefile ---
# Makefile for uClibc
#
# Copyright (C) 2001 SuperH (UK) Ltd.
# Copyright (C) 2003 Paul Mundt <lethal at linux-sh.org>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Library General Public License as published by the Free
# Software Foundation; either version 2 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 Library General Public License for more
# details.
#
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

TOPDIR=../../../../
include $(TOPDIR)Rules.mak

CFLAGS += -I..
SFLAGS = $(CFLAGS) -D__ASSEMBLER__ -DASM_GLOBAL_DIRECTIVE=.globl

TARGET_MACHINE_TYPE=$(shell $(CC) -dumpmachine)

CRT0_SRC = crt0.S
CRT0_OBJ = crt0.o crt1.o

SSRC = setjmp.S longjmp.S 
SOBJS = $(patsubst %.S,%.o, $(SSRC))

CSRC = fork.c __init_brk.c brk.c sbrk.c
COBJS = $(patsubst %.c,%.o, $(CSRC))

OBJS = $(SOBJS) $(COBJS)


all: $(OBJS) $(LIBC)

$(LIBC): ar-target 

ar-target: $(OBJS) $(CRT0_OBJ)
	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
	cp $(CRT0_OBJ) $(TOPDIR)lib/

$(CRT0_OBJ): $(CRT0_SRC)
	$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
	$(STRIPTOOL) -x -R .note -R .comment $*.o

$(SOBJS): %.o : %.S
	$(CC) $(SFLAGS) -c $< -o $@
	$(STRIPTOOL) -x -R .note -R .comment $*.o

$(COBJS): %.o : %.c
	$(CC) $(CFLAGS) -c $< -o $@
	$(STRIPTOOL) -x -R .note -R .comment $*.o

headers:

clean:
	rm -f *.[oa] *~ core
	rm -f bits/sysnum.h


--- NEW FILE: __init_brk.c ---
/* From libc-5.3.12 */

#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>

void * ___brk_addr = 0;

#define __NR__brk __NR_brk
_syscall1(void *, _brk, void *, ptr);

int
__init_brk (void)
{
    if (___brk_addr == 0)
    {
		___brk_addr = _brk(0);
		if (___brk_addr == 0)
		{
		  __set_errno(ENOMEM);
		  return -1;
		}
    }
    return 0;
}

--- NEW FILE: crt0.S ---
/* Startup code for SH5 & ELF.
   Copyright (C) 1999 Free Software Foundation, Inc.
   Copyright (C) 2001 Hewlett-Packard Australia

   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The GNU C Library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

/* This is the canonical entry point, usually the first thing in the text
   segment.

	At this entry point, most registers' values are unspecified, except:

   sp		The stack contains the arguments and environment:
   		0(sp)			argc
		4(sp)			argv[0]
		...
		(4*argc)(sp)		NULL
		(4*(argc+1))(sp)	envp[0]
		...
					NULL
*/

	.file	"crt0.S"

	.globl _start
	.globl __main

	.type	__uClibc_start_main, at function

	.section .text64,"xa"
	.align 2	/* 2^2 = 4 */
	
_start:
	/* Clear the frame pointer since this is the outermost frame.  */
###	mov #0, r14	# qqq

	/* Pop argc off the stack and save a pointer to argv */
	ld.l	r15, 0, r2	/* argc */
	addi	r15, 4, r3	/* argv */

	/* set up the value for the environment pointer r4 = (argc+1)*4+argv */
	addi	r2, 1, r4	/* envp = argc + 1 */
	shlli	r4, 2, r4	/* envp = envp * 4 */
	add	r3, r4, r4	/* envp = envp + argv */

	/* call main() */
	movi	__uClibc_start_main,r17
	ptabs/l	r17,tr0
	blink	tr0,r18

	/* should never get here....*/
###	movi	abort at lh,r17
###	shori	abort at ll,r17
	ptabs/l	r17,tr0
	blink	tr0,r63	/* call abort() => (r63) do not come back ... */

	/*
	 *	The following is a stub to stop the GNU toolchain
	 *	from calling its C-RTL initialization routines.
	 */
__main:
	ptabs/l	r18,tr0
	blink	tr0,r63


--- NEW FILE: sbrk.c ---
/* From libc-5.3.12 */

#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>

extern void * ___brk_addr;

extern int __init_brk (void);
extern void *_brk(void *ptr);

void *
sbrk(intptr_t increment)
{
    if (__init_brk () == 0)
    {
		char * tmp = (char*)___brk_addr+increment;
		___brk_addr = _brk(tmp);
		if (___brk_addr == tmp)
			return tmp-increment;
		__set_errno(ENOMEM);
		return ((void *) -1);
    }
    return ((void *) -1);
}

--- NEW FILE: longjmp.S ---
/* longjmp for SH-5.
   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The GNU C Library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */


#define _SETJMP_H
#define _ASM
#include <bits/setjmp.h>


#define	INTEGER(reg,offset)	ld.q	r2, offset*8, reg
#define	DOUBLE(reg,offset)	fld.d	r2, offset*8, reg


	.file	"longjmp.S"

	.section .text64,"xa"
	.align 2

	.global	longjmp	
	.type	longjmp, at function

longjmp:
	/*
	 *	extern void longjmp(jmp_buf env, int val);
	 *
	 *	r2 == env
	 *	r3 == val
	 *	r4 == temporary
	 */

			/* callee-save registers R10-R16 */
	INTEGER(r10, __SETJMP_INT(0))
	INTEGER(r11, __SETJMP_INT(1))
	INTEGER(r12, __SETJMP_INT(2))
	INTEGER(r13, __SETJMP_INT(3))
	INTEGER(r14, __SETJMP_INT(4))
	INTEGER(r15, __SETJMP_INT(5))
	INTEGER(r16, __SETJMP_INT(6))

			/* callee-save registers R28-R35 */
	INTEGER(r28, __SETJMP_INT(7))
	INTEGER(r29, __SETJMP_INT(8))
	INTEGER(r30, __SETJMP_INT(9))
	INTEGER(r31, __SETJMP_INT(10))
	INTEGER(r32, __SETJMP_INT(11))
	INTEGER(r33, __SETJMP_INT(12))
	INTEGER(r34, __SETJMP_INT(13))
	INTEGER(r35, __SETJMP_INT(14))

			/* callee-save registers R44-R59 */
	INTEGER(r44, __SETJMP_INT(15))
	INTEGER(r45, __SETJMP_INT(16))
	INTEGER(r46, __SETJMP_INT(17))
	INTEGER(r47, __SETJMP_INT(18))
	INTEGER(r48, __SETJMP_INT(19))
	INTEGER(r49, __SETJMP_INT(20))
	INTEGER(r50, __SETJMP_INT(21))
	INTEGER(r51, __SETJMP_INT(22))
	INTEGER(r52, __SETJMP_INT(23))
	INTEGER(r53, __SETJMP_INT(24))
	INTEGER(r54, __SETJMP_INT(25))
	INTEGER(r55, __SETJMP_INT(26))
	INTEGER(r56, __SETJMP_INT(27))
	INTEGER(r57, __SETJMP_INT(28))
	INTEGER(r58, __SETJMP_INT(29))
	INTEGER(r59, __SETJMP_INT(30))

	#if __SETJMP_NUM_INT != 31
	#error	__SETJMP_NUM_INT does agree with expected value
	#endif

#if __SETJMP_NUM_DBL > 0
			/* callee-save registers FR12-FR15 */
	DOUBLE(d12, __SETJMP_DBL(0))
	DOUBLE(d14, __SETJMP_DBL(1))

			/* callee-save registers FR36-FR63 */
	DOUBLE(d36, __SETJMP_DBL(2))
	DOUBLE(d38, __SETJMP_DBL(3))
	DOUBLE(d40, __SETJMP_DBL(4))
	DOUBLE(d42, __SETJMP_DBL(5))
	DOUBLE(d44, __SETJMP_DBL(6))
	DOUBLE(d46, __SETJMP_DBL(7))
	DOUBLE(d48, __SETJMP_DBL(8))
	DOUBLE(d50, __SETJMP_DBL(9))
	DOUBLE(d52, __SETJMP_DBL(10))
	DOUBLE(d54, __SETJMP_DBL(11))
	DOUBLE(d56, __SETJMP_DBL(12))
	DOUBLE(d58, __SETJMP_DBL(13))
	DOUBLE(d60, __SETJMP_DBL(14))
	DOUBLE(d62, __SETJMP_DBL(15))

	#if __SETJMP_NUM_DBL != 16
	#error	__SETJMP_NUM_DBL does agree with expected value
	#endif

#endif	/* __SETJMP_NUM_DBL > 0 */

			/* callee-save registers TR5-TR7 */
	INTEGER(r4, __SETJMP_TRG(0))
	ptabs	r4, tr5
	INTEGER(r4, __SETJMP_TRG(1))
	ptabs	r4, tr6
	INTEGER(r4, __SETJMP_TRG(2))
	ptabs	r4, tr7

	#if __SETJMP_NUM_TRG != 3
	#error	__SETJMP_NUM_TRG does agree with expected value
	#endif

			/* restore Linkage Register (LR) for longjmp return */
	INTEGER(r18, __SETJMP_LR)
	ptabs/l	r18, tr0

			/*
			 *	must ensure longjmp() never returns 0.
			 *	if 'val' == 0, then return 1.
			 */
	cmpeq	r3, r63, r2	/* r2 = (r3==0) ? 1 : 0; */
	add.l	r3, r2, r2	/* return value */

			/* return to caller */
	blink	tr0, r63





More information about the uClibc-cvs mailing list