Alpha support from libc.

This commit is contained in:
cgd 1995-02-13 21:49:11 +00:00
parent 537b309ca7
commit e133097a8e
4 changed files with 304 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/* $NetBSD: DEFS.h,v 1.1 1995/02/13 21:49:11 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include <machine/asm.h>

View File

@ -0,0 +1,52 @@
# $Id: Makefile.inc,v 1.1 1995/02/13 21:49:12 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \
random.c
# `source' files built from m4 source
SRCS+= __divqu.S __divq.S __divlu.S __divl.S
SRCS+= __remqu.S __remq.S __remlu.S __reml.S
CLEANFILES+= __divqu.S __divq.S __divlu.S __divl.S
CLEANFILES+= __remqu.S __remq.S __remlu.S __reml.S
__divqu.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__divqu')define(OP,\`div')define(S,\`false')"; \
echo "define(WORDSIZE,64)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__divq.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__divq')define(OP,\`div')define(S,\`true')"; \
echo "define(WORDSIZE,64)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__divlu.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__divlu')define(OP,\`div')define(S,\`false')"; \
echo "define(WORDSIZE,32)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__divl.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__divl')define(OP,\`div')define(S,\`true')"; \
echo "define(WORDSIZE,32)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__remqu.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__remqu')define(OP,\`rem')define(S,\`false')"; \
echo "define(WORDSIZE,64)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__remq.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__remq')define(OP,\`rem')define(S,\`true')"; \
echo "define(WORDSIZE,64)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__remlu.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__remlu')define(OP,\`rem')define(S,\`false')"; \
echo "define(WORDSIZE,32)"; cat ${.ALLSRC}) | m4 > ${.TARGET}
__reml.S: ${.CURDIR}/arch/alpha/divrem.m4
@echo 'building ${.TARGET} from ${.ALLSRC}'
@(echo "define(NAME,\`__reml')define(OP,\`rem')define(S,\`true')"; \
echo "define(WORDSIZE,32)"; cat ${.ALLSRC}) | m4 > ${.TARGET}

View File

@ -0,0 +1,53 @@
/* $NetBSD: SYS.h,v 1.1 1995/02/13 21:49:13 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include <machine/asm.h>
#include <sys/syscall.h>
#define CALLSYS(num) \
CONST(num, v0); \
call_pal 0x83; /* op_callsys */
#define SYSCALL_NOLABEL(x) \
CALLSYS(SYS_/**/x); \
beq a3, 9f; \
br gp, 8f; \
8: SETGP(gp); \
lda at_reg, cerror; \
jmp zero, (at_reg); \
9:
#define SYSCALL(x) LEAF(x, 0 /* XXX */); SYSCALL_NOLABEL(x);
#define RSYSCALL(x) SYSCALL(x); RET; END(x);
#define PSEUDO(x,y) \
LEAF(x,0); /* unknown # of args */ \
CALLSYS(SYS_/**/y); \
RET; \
END(x);

View File

@ -0,0 +1,169 @@
/* $NetBSD: divrem.m4,v 1.1 1995/02/13 21:49:14 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
/*
* Division and remainder.
*
* The use of m4 is modeled after the sparc code, but the algorithm is
* simple binary long division.
*
* Note that the loops could probably benefit from unrolling.
*/
/*
* M4 Parameters
* NAME name of function to generate
* OP OP=div: t10 / t11 -> t12; OP=rem: t10 % t11 -> t12
* S S=true: signed; S=false: unsigned [XXX NOT YET]
* WORDSIZE total number of bits
*/
define(A, `t10')
define(B, `t11')
define(RESULT, `t12')
define(BIT, `t0')
define(I, `t1')
define(CC, `t2')
define(T_0, `t3')
ifelse(S, `true', `define(SIGN, `t4')')
#include "DEFS.h"
LEAF(NAME, 0) /* XXX */
lda sp, -48(sp)
stq BIT, 0(sp)
stq I, 8(sp)
stq CC, 16(sp)
stq T_0, 24(sp)
ifelse(S, `true',
` stq SIGN, 32(sp)')
mov zero, RESULT /* Initialize result to zero */
ifelse(S, `true',
`
/* Compute sign of result. If either is negative, this is easy. */
or A, B, SIGN /* not the sign, but... */
bgt SIGN, Ldoit /* neither negative? do it! */
ifelse(OP, `div',
` xor A, B, SIGN /* THIS is the sign! */
', ` mov A, SIGN /* sign follows A. */
')
bge A, LnegB /* see if A is negative */
/* A is negative; flip it. */
subq zero, A, A
bge B, Ldoit /* see if B is negative */
LnegB:
/* B is definitely negative, no matter how we got here. */
subq zero, B, B
Ldoit:
')
/* kill the special cases. */
beq B, Ldotrap /* division by zero! XXX */
1: cmpult A, B, CC /* A < B? */
/* RESULT is already zero, from above. A is untouched. */
bne CC, Lret_result
cmpeq A, B, CC /* A == B? */
cmovne CC, 1, RESULT
cmovne CC, zero, A
bne CC, Lret_result
/*
* Find out how many bits of zeros are at the beginning of the divisor.
*/
LBbits:
CONST(1, T_0) /* I = 0; BIT = 1<<WORDSIZE-1 */
mov zero, I
sll T_0, WORDSIZE-1, BIT
LBloop:
and B, BIT, CC /* if bit in B is set, done. */
bne CC, LAbits
addq I, 1, I /* increment I, shift bit */
srl BIT, 1, BIT
cmplt I, WORDSIZE-1, CC /* if I leaves one bit, done. */
bne CC, LBloop
LAbits:
beq I, Ldodiv /* If I = 0, divide now. */
CONST(1, T_0) /* BIT = 1<<WORDSIZE-1 */
sll T_0, WORDSIZE-1, BIT
LAloop:
and A, BIT, CC /* if bit in A is set, done. */
bne CC, Ldodiv
subq I, 1, I /* decrement I, shift bit */
srl BIT, 1, BIT
bne I, LAloop /* If I != 0, loop again */
Ldodiv:
sll B, I, B /* B <<= i */
CONST(1, T_0)
sll T_0, I, BIT
Ldivloop:
cmpult A, B, CC
or RESULT, BIT, T_0
cmoveq CC, T_0, RESULT
subq A, B, T_0
cmoveq CC, T_0, A
srl BIT, 1, BIT
srl B, 1, B
beq A, Lret_result
bne BIT, Ldivloop
Lret_result:
ifelse(OP, `div',
`', ` mov A, RESULT
')
ifelse(S, `true',
`
/* Check to see if we should negate it. */
subqv zero, RESULT, T_0
cmovlt SIGN, T_0, RESULT
')
ldq BIT, 0(sp)
ldq I, 8(sp)
ldq CC, 16(sp)
ldq T_0, 24(sp)
ifelse(S, `true',
` ldq SIGN, 32(sp)')
lda sp, 48(sp)
ret zero, (t9), 1
Ldotrap:
CONST(-2, a0) /* This is the signal to SIGFPE! */
call_pal PAL_gentrap
br zero, Lret_result
END(NAME)