From e133097a8e07502d7d9a3c0b0e1f549743352468 Mon Sep 17 00:00:00 2001 From: cgd Date: Mon, 13 Feb 1995 21:49:11 +0000 Subject: [PATCH] Alpha support from libc. --- sys/lib/libkern/arch/alpha/DEFS.h | 30 +++++ sys/lib/libkern/arch/alpha/Makefile.inc | 52 ++++++++ sys/lib/libkern/arch/alpha/SYS.h | 53 ++++++++ sys/lib/libkern/arch/alpha/divrem.m4 | 169 ++++++++++++++++++++++++ 4 files changed, 304 insertions(+) create mode 100644 sys/lib/libkern/arch/alpha/DEFS.h create mode 100644 sys/lib/libkern/arch/alpha/Makefile.inc create mode 100644 sys/lib/libkern/arch/alpha/SYS.h create mode 100644 sys/lib/libkern/arch/alpha/divrem.m4 diff --git a/sys/lib/libkern/arch/alpha/DEFS.h b/sys/lib/libkern/arch/alpha/DEFS.h new file mode 100644 index 000000000000..0d16d3972ad6 --- /dev/null +++ b/sys/lib/libkern/arch/alpha/DEFS.h @@ -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 diff --git a/sys/lib/libkern/arch/alpha/Makefile.inc b/sys/lib/libkern/arch/alpha/Makefile.inc new file mode 100644 index 000000000000..1dc4503a8a29 --- /dev/null +++ b/sys/lib/libkern/arch/alpha/Makefile.inc @@ -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} diff --git a/sys/lib/libkern/arch/alpha/SYS.h b/sys/lib/libkern/arch/alpha/SYS.h new file mode 100644 index 000000000000..738dda0ee01c --- /dev/null +++ b/sys/lib/libkern/arch/alpha/SYS.h @@ -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 +#include + +#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); diff --git a/sys/lib/libkern/arch/alpha/divrem.m4 b/sys/lib/libkern/arch/alpha/divrem.m4 new file mode 100644 index 000000000000..e8b958dcf236 --- /dev/null +++ b/sys/lib/libkern/arch/alpha/divrem.m4 @@ -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<