From d13a0eeefafa0d023ecee773e2ec29625db82cc9 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Thu, 18 Feb 2010 18:53:34 +0000 Subject: The PMON code is compiled as 64 bit code but still using the old ABI (actually, a 64-bit version of the old ABI), which explains why these wrappers are needed. Update comments to match reality, and make cpp write all the code of this file. (``survival of the laziest'' motto) Keep the misleading file name though (lazyness again) --- sys/arch/loongson/loongson/pmon32.S | 140 ++++++------------------------------ 1 file changed, 23 insertions(+), 117 deletions(-) diff --git a/sys/arch/loongson/loongson/pmon32.S b/sys/arch/loongson/loongson/pmon32.S index 14786928465..7c961a8ac2c 100644 --- a/sys/arch/loongson/loongson/pmon32.S +++ b/sys/arch/loongson/loongson/pmon32.S @@ -1,4 +1,4 @@ -/* $OpenBSD: pmon32.S,v 1.3 2010/02/14 22:39:33 miod Exp $ */ +/* $OpenBSD: pmon32.S,v 1.4 2010/02/18 18:53:33 miod Exp $ */ /* * Copyright (c) 2009 Miodrag Vallat. @@ -19,19 +19,12 @@ /* * Wrapper routines to invoke PMON2000 functions from 64-bit code. * - * Since the PMON code is compiled as 32 bit code, the upper part of the - * registers may be destroyed. + * PMON is compiled as 64 bit code, using the gcc o64 ABI (similar to the o32 + * ABI, but using 64 bit registers). * - * As a result, we need to explicitely save all caller-saved registers, - * prior to invoking any PMON function. - * - * Moreover, O32 calling convention only allows up to four arguments to - * be passed through registers. It's up to the caller to never invoke - * pmon_printf() with more than four arguments; other functions are not - * affected. - * - * 64-bit (off_t) return values are preserved (by merging v1 and v0) on a - * case-by-case basis. + * As a result, only up to four arguments to functions will be passed through + * registers. It's up to the caller to never invoke pmon_printf() with more + * than four arguments; other functions are not affected. */ #include @@ -51,11 +44,10 @@ pmon_callvec: .text /* - * Note that we need to provide a 32-bit CF_SZ untouched area above sp, or - * we'll get our stack corrupted upon return. + * Note that we need to provide a CF_SZ untouched area above sp, or we'll risk + * our stack being corrupted upon return. */ - -#define PMON_WRAP(name) \ +#define PMON_WRAP(name, index) \ NNON_LEAF(name, FRAMESZ(CF_SZ + 9 * REGSZ), ra); \ PTR_SUBU sp, sp, FRAMESZ(CF_SZ + 9 * REGSZ); \ REG_S ra, CF_RA_OFFS(sp); \ @@ -68,9 +60,11 @@ pmon_callvec: REG_S s5, (5 * REGSZ + CF_SZ)(sp); \ REG_S s6, (6 * REGSZ + CF_SZ)(sp); \ REG_S s7, (7 * REGSZ + CF_SZ)(sp); \ - REG_S s8, (8 * REGSZ + CF_SZ)(sp) - -#define PMON_END(name) \ + REG_S s8, (8 * REGSZ + CF_SZ)(sp); \ + lw t0, pmon_callvec; \ + lw t0, (index) * 4 (t0); \ + jalr t0; \ + nop; \ REG_L s8, (8 * REGSZ + CF_SZ)(sp); \ REG_L s7, (7 * REGSZ + CF_SZ)(sp); \ REG_L s6, (6 * REGSZ + CF_SZ)(sp); \ @@ -86,103 +80,15 @@ pmon_callvec: nop; \ END(name) -PMON_WRAP(pmon_printf) - lw t0, pmon_callvec - lw t0, 5 * 4 (t0) - jalr t0 - nop -PMON_END(pmon_printf) - -PMON_WRAP(pmon_gets) - lw t0, pmon_callvec - lw t0, 7 * 4 (t0) - jalr t0 - nop - /* make sure the return value is sign extended */ - dsll32 v0, 0 - dsra32 v0, 0 -PMON_END(pmon_gets) - +PMON_WRAP(pmon_printf, 5) +PMON_WRAP(pmon_gets, 7) #ifdef _STANDALONE - -PMON_WRAP(pmon_cacheflush) - lw t0, pmon_callvec - lw t0, 6 * 4 (t0) - jalr t0 - nop -PMON_END(pmon_cacheflush) - -PMON_WRAP(pmon_open) - lw t0, pmon_callvec - lw t0, 0 * 4 (t0) - jalr t0 - nop -PMON_END(pmon_open) - -PMON_WRAP(pmon_close) - lw t0, pmon_callvec - lw t0, 1 * 4 (t0) - jalr t0 - nop -PMON_END(pmon_close) - -PMON_WRAP(pmon_read) - lw t0, pmon_callvec - lw t0, 2 * 4 (t0) - jalr t0 - nop -PMON_END(pmon_read) - -PMON_WRAP(pmon_lseek) - lw t0, pmon_callvec - lw t0, 4 * 4 (t0) -#if 0 - /* - * Setup arguments the way 32-bit PMON expects them. - * 64-bit mode: a0 = fd, a1 = off, a2 = whence - * 32-bit mode: a0 = fd, a2:a3 = off, 16(sp) = whence - */ - sw a2, 16(sp) -#ifdef __MIPSEB__ - dsll32 a3, a1, 0 - dsrl32 a2, a1, 0 /* a2 = hi */ - dsrl32 a3, a3, 0 /* a3 = low */ -#else - dsll32 a2, a1, 0 - dsrl32 a3, a1, 0 /* a3 = hi */ - dsrl32 a2, a2, 0 /* a2 = low */ +PMON_WRAP(pmon_open, 0) +PMON_WRAP(pmon_close, 1) +PMON_WRAP(pmon_read, 2) +PMON_WRAP(pmon_lseek, 4) +PMON_WRAP(pmon_cacheflush, 6) #endif -#endif - jalr t0 - nop -#if 0 - /* rebuild the 64 bit return value */ - dsll32 v0, 0 - dsll32 v1, 0 -#ifdef __MIPSEB__ - /* v1 = lo << 32, v0 = hi << 32 */ - dsrl32 v1, 0 -#else - /* v1 = hi << 32, v0 = lo << 32 */ - dsrl32 v0, 0 -#endif - or v0, v1, v0 -#endif -PMON_END(pmon_lseek) - -#endif - -/* - * The following routines are untested. - */ - -#if 0 - -PMON_WRAP(pmon_write) - lw t0, pmon_callvec - lw t0, 3 * 4 (t0) - jalr t0 - nop -PMON_END(pmon_write) - +#if 0 /* unused */ +PMON_WRAP(pmon_write, 3) #endif -- cgit v1.2.3