Commit 1b35a57b authored by David S. Miller's avatar David S. Miller
Browse files

sparc32: Kill off software 32-bit multiply/divide routines.



For the explicit calls to .udiv/.umul in assembler, I made a
mechanical (read as: safe) transformation.  I didn't attempt
to make any simplifications.

In particular, __ndelay and __udelay can be simplified significantly.
Some of the %y reads are unnecessary and these routines have no need
any longer for allocating a register window, they can be leaf
functions.

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2119ff6d
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -1161,11 +1161,13 @@ fpload:
	.globl	__ndelay
__ndelay:
	save	%sp, -STACKFRAME_SZ, %sp
	mov	%i0, %o0
	call	.umul			! round multiplier up so large ns ok
	mov	%i0, %o0		! round multiplier up so large ns ok
	mov	0x1ae, %o1		! 2**32 / (1 000 000 000 / HZ)
	call	.umul
	umul	%o0, %o1, %o0
	rd	%y, %o1
	mov	%i1, %o1		! udelay_val
	umul	%o0, %o1, %o0
	rd	%y, %o1
	ba	delay_continue
	 mov	%o1, %o0		! >>32 later for better resolution

@@ -1174,18 +1176,21 @@ __udelay:
	save	%sp, -STACKFRAME_SZ, %sp
	mov	%i0, %o0
	sethi	%hi(0x10c7), %o1	! round multiplier up so large us ok
	call	.umul
	or	%o1, %lo(0x10c7), %o1	! 2**32 / 1 000 000
	call	.umul
	umul	%o0, %o1, %o0
	rd	%y, %o1
	mov	%i1, %o1		! udelay_val
	umul	%o0, %o1, %o0
	rd	%y, %o1
	sethi	%hi(0x028f4b62), %l0	! Add in rounding constant * 2**32,
	or	%g0, %lo(0x028f4b62), %l0
	addcc	%o0, %l0, %o0		! 2**32 * 0.009 999
	bcs,a	3f
	 add	%o1, 0x01, %o1
3:
	call	.umul
	mov	HZ, %o0			! >>32 earlier for wider range
	umul	%o0, %o1, %o0
	rd	%y, %o1

delay_continue:
	cmp	%o0, 0x0
+0 −45
Original line number Diff line number Diff line
@@ -746,51 +746,6 @@ sun4d_init:
	/* Fall through to sun4m_init */

sun4m_init:

#define PATCH_IT(dst, src)	\
	set	(dst), %g5;	\
	set	(src), %g4;	\
	ld	[%g4], %g3;	\
	st	%g3, [%g5];	\
	ld	[%g4+0x4], %g3;	\
	st	%g3, [%g5+0x4];

	/* Signed multiply. */
	PATCH_IT(.mul, .mul_patch)
	PATCH_IT(.mul+0x08, .mul_patch+0x08)

	/* Signed remainder. */
	PATCH_IT(.rem, .rem_patch)
	PATCH_IT(.rem+0x08, .rem_patch+0x08)
	PATCH_IT(.rem+0x10, .rem_patch+0x10)
	PATCH_IT(.rem+0x18, .rem_patch+0x18)
	PATCH_IT(.rem+0x20, .rem_patch+0x20)
	PATCH_IT(.rem+0x28, .rem_patch+0x28)

	/* Signed division. */
	PATCH_IT(.div, .div_patch)
	PATCH_IT(.div+0x08, .div_patch+0x08)
	PATCH_IT(.div+0x10, .div_patch+0x10)
	PATCH_IT(.div+0x18, .div_patch+0x18)
	PATCH_IT(.div+0x20, .div_patch+0x20)

	/* Unsigned multiply. */
	PATCH_IT(.umul, .umul_patch)
	PATCH_IT(.umul+0x08, .umul_patch+0x08)

	/* Unsigned remainder. */
	PATCH_IT(.urem, .urem_patch)
	PATCH_IT(.urem+0x08, .urem_patch+0x08)
	PATCH_IT(.urem+0x10, .urem_patch+0x10)
	PATCH_IT(.urem+0x18, .urem_patch+0x18)

	/* Unsigned division. */
	PATCH_IT(.udiv, .udiv_patch)
	PATCH_IT(.udiv+0x08, .udiv_patch+0x08)
	PATCH_IT(.udiv+0x10, .udiv_patch+0x10)

#undef PATCH_IT

/* Ok, the PROM could have done funny things and apple cider could still
 * be sitting in the fault status/address registers.  Read them all to
 * clear them so we don't get magic faults later on.
+0 −3
Original line number Diff line number Diff line
@@ -32,9 +32,6 @@ extern void cpu_probe(void);
/* traps_32.c */
extern void handle_hw_divzero(struct pt_regs *regs, unsigned long pc,
                              unsigned long npc, unsigned long psr);
/* muldiv.c */
extern int do_user_muldiv (struct pt_regs *, unsigned long);

/* irq_32.c */
extern struct irqaction static_irqaction[];
extern int static_irq_count;
+1 −20
Original line number Diff line number Diff line
@@ -32,26 +32,11 @@ static void *module_map(unsigned long size)
				GFP_KERNEL, PAGE_KERNEL, -1,
				__builtin_return_address(0));
}

static char *dot2underscore(char *name)
{
	return name;
}
#else
static void *module_map(unsigned long size)
{
	return vmalloc(size);
}

/* Replace references to .func with _Func */
static char *dot2underscore(char *name)
{
	if (name[0] == '.') {
		name[0] = '_';
                name[1] = toupper(name[1]);
	}
	return name;
}
#endif /* CONFIG_SPARC64 */

void *module_alloc(unsigned long size)
@@ -93,12 +78,8 @@ int module_frob_arch_sections(Elf_Ehdr *hdr,

	for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
		if (sym[i].st_shndx == SHN_UNDEF) {
			if (ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER) {
			if (ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER)
				sym[i].st_shndx = SHN_ABS;
			} else {
				char *name = strtab + sym[i].st_name;
				dot2underscore(name);
			}
		}
	}
	return 0;

arch/sparc/kernel/muldiv.c

deleted100644 → 0
+0 −238
Original line number Diff line number Diff line
/*
 * muldiv.c: Hardware multiply/division illegal instruction trap
 *		for sun4c/sun4 (which do not have those instructions)
 *
 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
 *
 * 2004-12-25	Krzysztof Helt (krzysztof.h1@wp.pl) 
 *		- fixed registers constrains in inline assembly declarations
 */

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <asm/ptrace.h>
#include <asm/processor.h>
#include <asm/uaccess.h>

#include "kernel.h"

/* #define DEBUG_MULDIV */

static inline int has_imm13(int insn)
{
	return (insn & 0x2000);
}

static inline int is_foocc(int insn)
{
	return (insn & 0x800000);
}

static inline int sign_extend_imm13(int imm)
{
	return imm << 19 >> 19;
}

static inline void advance(struct pt_regs *regs)
{
	regs->pc   = regs->npc;
	regs->npc += 4;
}

static inline void maybe_flush_windows(unsigned int rs1, unsigned int rs2,
				       unsigned int rd)
{
	if(rs2 >= 16 || rs1 >= 16 || rd >= 16) {
		/* Wheee... */
		__asm__ __volatile__("save %sp, -0x40, %sp\n\t"
				     "save %sp, -0x40, %sp\n\t"
				     "save %sp, -0x40, %sp\n\t"
				     "save %sp, -0x40, %sp\n\t"
				     "save %sp, -0x40, %sp\n\t"
				     "save %sp, -0x40, %sp\n\t"
				     "save %sp, -0x40, %sp\n\t"
				     "restore; restore; restore; restore;\n\t"
				     "restore; restore; restore;\n\t");
	}
}

#define fetch_reg(reg, regs) ({						\
	struct reg_window32 __user *win;					\
	register unsigned long ret;					\
									\
	if (!(reg)) ret = 0;						\
	else if ((reg) < 16) {						\
		ret = regs->u_regs[(reg)];				\
	} else {							\
		/* Ho hum, the slightly complicated case. */		\
		win = (struct reg_window32 __user *)regs->u_regs[UREG_FP];\
		if (get_user (ret, &win->locals[(reg) - 16])) return -1;\
	}								\
	ret;								\
})

static inline int
store_reg(unsigned int result, unsigned int reg, struct pt_regs *regs)
{
	struct reg_window32 __user *win;

	if (!reg)
		return 0;
	if (reg < 16) {
		regs->u_regs[reg] = result;
		return 0;
	} else {
		/* need to use put_user() in this case: */
		win = (struct reg_window32 __user *) regs->u_regs[UREG_FP];
		return (put_user(result, &win->locals[reg - 16]));
	}
}

/* Should return 0 if mul/div emulation succeeded and SIGILL should
 * not be issued.
 */
int do_user_muldiv(struct pt_regs *regs, unsigned long pc)
{
	unsigned int insn;
	int inst;
	unsigned int rs1, rs2, rdv;

	if (!pc)
		return -1; /* This happens to often, I think */
	if (get_user (insn, (unsigned int __user *)pc))
		return -1;
	if ((insn & 0xc1400000) != 0x80400000)
		return -1;
	inst = ((insn >> 19) & 0xf);
	if ((inst & 0xe) != 10 && (inst & 0xe) != 14)
		return -1;

	/* Now we know we have to do something with umul, smul, udiv or sdiv */
	rs1 = (insn >> 14) & 0x1f;
	rs2 = insn & 0x1f;
	rdv = (insn >> 25) & 0x1f;
	if (has_imm13(insn)) {
		maybe_flush_windows(rs1, 0, rdv);
		rs2 = sign_extend_imm13(insn);
	} else {
		maybe_flush_windows(rs1, rs2, rdv);
		rs2 = fetch_reg(rs2, regs);
	}
	rs1 = fetch_reg(rs1, regs);
	switch (inst) {
	case 10: /* umul */
#ifdef DEBUG_MULDIV	
		printk ("unsigned muldiv: 0x%x * 0x%x = ", rs1, rs2);
#endif		
		__asm__ __volatile__ ("\n\t"
			"mov	%0, %%o0\n\t"
			"call	.umul\n\t"
			" mov	%1, %%o1\n\t"
			"mov	%%o0, %0\n\t"
			"mov	%%o1, %1\n\t"
			: "=r" (rs1), "=r" (rs2)
		        : "0" (rs1), "1" (rs2)
			: "o0", "o1", "o2", "o3", "o4", "o5", "o7", "cc");
#ifdef DEBUG_MULDIV
		printk ("0x%x%08x\n", rs2, rs1);
#endif
		if (store_reg(rs1, rdv, regs))
			return -1;
		regs->y = rs2;
		break;
	case 11: /* smul */
#ifdef DEBUG_MULDIV
		printk ("signed muldiv: 0x%x * 0x%x = ", rs1, rs2);
#endif
		__asm__ __volatile__ ("\n\t"
			"mov	%0, %%o0\n\t"
			"call	.mul\n\t"
			" mov	%1, %%o1\n\t"
			"mov	%%o0, %0\n\t"
			"mov	%%o1, %1\n\t"
			: "=r" (rs1), "=r" (rs2)
		        : "0" (rs1), "1" (rs2)
			: "o0", "o1", "o2", "o3", "o4", "o5", "o7", "cc");
#ifdef DEBUG_MULDIV
		printk ("0x%x%08x\n", rs2, rs1);
#endif
		if (store_reg(rs1, rdv, regs))
			return -1;
		regs->y = rs2;
		break;
	case 14: /* udiv */
#ifdef DEBUG_MULDIV
		printk ("unsigned muldiv: 0x%x%08x / 0x%x = ", regs->y, rs1, rs2);
#endif
		if (!rs2) {
#ifdef DEBUG_MULDIV
			printk ("DIVISION BY ZERO\n");
#endif
			handle_hw_divzero (regs, pc, regs->npc, regs->psr);
			return 0;
		}
		__asm__ __volatile__ ("\n\t"
			"mov	%2, %%o0\n\t"
			"mov	%0, %%o1\n\t"
			"mov	%%g0, %%o2\n\t"
			"call	__udivdi3\n\t"
			" mov	%1, %%o3\n\t"
			"mov	%%o1, %0\n\t"
			"mov	%%o0, %1\n\t"
			: "=r" (rs1), "=r" (rs2)
			: "r" (regs->y), "0" (rs1), "1" (rs2)
			: "o0", "o1", "o2", "o3", "o4", "o5", "o7",
			  "g1", "g2", "g3", "cc");
#ifdef DEBUG_MULDIV
		printk ("0x%x\n", rs1);
#endif
		if (store_reg(rs1, rdv, regs))
			return -1;
		break;
	case 15: /* sdiv */
#ifdef DEBUG_MULDIV
		printk ("signed muldiv: 0x%x%08x / 0x%x = ", regs->y, rs1, rs2);
#endif
		if (!rs2) {
#ifdef DEBUG_MULDIV
			printk ("DIVISION BY ZERO\n");
#endif
			handle_hw_divzero (regs, pc, regs->npc, regs->psr);
			return 0;
		}
		__asm__ __volatile__ ("\n\t"
			"mov	%2, %%o0\n\t"
			"mov	%0, %%o1\n\t"
			"mov	%%g0, %%o2\n\t"
			"call	__divdi3\n\t"
			" mov	%1, %%o3\n\t"
			"mov	%%o1, %0\n\t"
			"mov	%%o0, %1\n\t"
			: "=r" (rs1), "=r" (rs2)
			: "r" (regs->y), "0" (rs1), "1" (rs2)
			: "o0", "o1", "o2", "o3", "o4", "o5", "o7",
			  "g1", "g2", "g3", "cc");
#ifdef DEBUG_MULDIV
		printk ("0x%x\n", rs1);
#endif
		if (store_reg(rs1, rdv, regs))
			return -1;
		break;
	}
	if (is_foocc (insn)) {
		regs->psr &= ~PSR_ICC;
		if ((inst & 0xe) == 14) {
			/* ?div */
			if (rs2) regs->psr |= PSR_V;
		}
		if (!rs1) regs->psr |= PSR_Z;
		if (((int)rs1) < 0) regs->psr |= PSR_N;
#ifdef DEBUG_MULDIV
		printk ("psr muldiv: %08x\n", regs->psr);
#endif
	}
	advance(regs);
	return 0;
}
Loading