11da177e4SLinus Torvalds/* 21da177e4SLinus Torvalds * 31da177e4SLinus Torvalds * This file is subject to the terms and conditions of the GNU General Public 41da177e4SLinus Torvalds * License. See the file "COPYING" in the main directory of this archive 51da177e4SLinus Torvalds * for more details. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Copyright (C) 2000 Hewlett Packard (Paul Bame bame@puffin.external.hp.com) 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds#include <asm/psw.h> 11*896a3756SGrant Grundler#include <asm/assembly.h> 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds .section .bss 141da177e4SLinus Torvalds .export real_stack 151da177e4SLinus Torvalds .export real32_stack 161da177e4SLinus Torvalds .export real64_stack 171da177e4SLinus Torvalds .align 64 181da177e4SLinus Torvaldsreal_stack: 191da177e4SLinus Torvaldsreal32_stack: 201da177e4SLinus Torvaldsreal64_stack: 211da177e4SLinus Torvalds .block 8192 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds#ifdef __LP64__ 241da177e4SLinus Torvalds# define REG_SZ 8 251da177e4SLinus Torvalds#else 261da177e4SLinus Torvalds# define REG_SZ 4 271da177e4SLinus Torvalds#endif 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds#define N_SAVED_REGS 9 301da177e4SLinus Torvalds 311da177e4SLinus Torvaldssave_cr_space: 321da177e4SLinus Torvalds .block REG_SZ * N_SAVED_REGS 331da177e4SLinus Torvaldssave_cr_end: 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds/************************ 32-bit real-mode calls ***********************/ 371da177e4SLinus Torvalds/* This can be called in both narrow and wide kernels */ 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds .text 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds .export real32_call_asm 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds /* unsigned long real32_call_asm(unsigned int *sp, 441da177e4SLinus Torvalds * unsigned int *arg0p, 451da177e4SLinus Torvalds * unsigned int iodc_fn) 461da177e4SLinus Torvalds * sp is value of stack pointer to adopt before calling PDC (virt) 471da177e4SLinus Torvalds * arg0p points to where saved arg values may be found 481da177e4SLinus Torvalds * iodc_fn is the IODC function to call 491da177e4SLinus Torvalds */ 501da177e4SLinus Torvalds 511da177e4SLinus Torvaldsreal32_call_asm: 521da177e4SLinus Torvalds STREG %rp, -RP_OFFSET(%sp) /* save RP */ 531da177e4SLinus Torvalds#ifdef __LP64__ 541da177e4SLinus Torvalds callee_save 551da177e4SLinus Torvalds ldo 2*REG_SZ(%sp), %sp /* room for a couple more saves */ 561da177e4SLinus Torvalds STREG %r27, -1*REG_SZ(%sp) 571da177e4SLinus Torvalds STREG %r29, -2*REG_SZ(%sp) 581da177e4SLinus Torvalds#endif 591da177e4SLinus Torvalds STREG %sp, -REG_SZ(%arg0) /* save SP on real-mode stack */ 601da177e4SLinus Torvalds copy %arg0, %sp /* adopt the real-mode SP */ 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds /* save iodc_fn */ 631da177e4SLinus Torvalds copy %arg2, %r31 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* load up the arg registers from the saved arg area */ 661da177e4SLinus Torvalds /* 32-bit calling convention passes first 4 args in registers */ 671da177e4SLinus Torvalds ldw 0(%arg1), %arg0 /* note overwriting arg0 */ 681da177e4SLinus Torvalds ldw -8(%arg1), %arg2 691da177e4SLinus Torvalds ldw -12(%arg1), %arg3 701da177e4SLinus Torvalds ldw -4(%arg1), %arg1 /* obviously must do this one last! */ 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds tophys_r1 %sp 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds b,l rfi_virt2real,%r2 751da177e4SLinus Torvalds nop 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds b,l save_control_regs,%r2 /* modifies r1, r2, r28 */ 781da177e4SLinus Torvalds nop 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds#ifdef __LP64__ 811da177e4SLinus Torvalds rsm PSW_SM_W, %r0 /* go narrow */ 821da177e4SLinus Torvalds#endif 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds load32 PA(ric_ret), %r2 851da177e4SLinus Torvalds bv 0(%r31) 861da177e4SLinus Torvalds nop 871da177e4SLinus Torvaldsric_ret: 881da177e4SLinus Torvalds#ifdef __LP64__ 891da177e4SLinus Torvalds ssm PSW_SM_W, %r0 /* go wide */ 901da177e4SLinus Torvalds#endif 911da177e4SLinus Torvalds /* restore CRs before going virtual in case we page fault */ 921da177e4SLinus Torvalds b,l restore_control_regs, %r2 /* modifies r1, r2, r26 */ 931da177e4SLinus Torvalds nop 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds b,l rfi_real2virt,%r2 961da177e4SLinus Torvalds nop 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds tovirt_r1 %sp 991da177e4SLinus Torvalds LDREG -REG_SZ(%sp), %sp /* restore SP */ 1001da177e4SLinus Torvalds#ifdef __LP64__ 1011da177e4SLinus Torvalds LDREG -1*REG_SZ(%sp), %r27 1021da177e4SLinus Torvalds LDREG -2*REG_SZ(%sp), %r29 1031da177e4SLinus Torvalds ldo -2*REG_SZ(%sp), %sp 1041da177e4SLinus Torvalds callee_rest 1051da177e4SLinus Torvalds#endif 1061da177e4SLinus Torvalds LDREG -RP_OFFSET(%sp), %rp /* restore RP */ 1071da177e4SLinus Torvalds bv 0(%rp) 1081da177e4SLinus Torvalds nop 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds# define PUSH_CR(r, where) mfctl r, %r1 ! STREG,ma %r1, REG_SZ(where) 1121da177e4SLinus Torvalds# define POP_CR(r, where) LDREG,mb -REG_SZ(where), %r1 ! mtctl %r1, r 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds .text 1151da177e4SLinus Torvaldssave_control_regs: 1161da177e4SLinus Torvalds load32 PA(save_cr_space), %r28 1171da177e4SLinus Torvalds PUSH_CR(%cr24, %r28) 1181da177e4SLinus Torvalds PUSH_CR(%cr25, %r28) 1191da177e4SLinus Torvalds PUSH_CR(%cr26, %r28) 1201da177e4SLinus Torvalds PUSH_CR(%cr27, %r28) 1211da177e4SLinus Torvalds PUSH_CR(%cr28, %r28) 1221da177e4SLinus Torvalds PUSH_CR(%cr29, %r28) 1231da177e4SLinus Torvalds PUSH_CR(%cr30, %r28) 1241da177e4SLinus Torvalds PUSH_CR(%cr31, %r28) 1251da177e4SLinus Torvalds PUSH_CR(%cr15, %r28) 1261da177e4SLinus Torvalds bv 0(%r2) 1271da177e4SLinus Torvalds nop 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvaldsrestore_control_regs: 1301da177e4SLinus Torvalds load32 PA(save_cr_end), %r26 1311da177e4SLinus Torvalds POP_CR(%cr15, %r26) 1321da177e4SLinus Torvalds POP_CR(%cr31, %r26) 1331da177e4SLinus Torvalds POP_CR(%cr30, %r26) 1341da177e4SLinus Torvalds POP_CR(%cr29, %r26) 1351da177e4SLinus Torvalds POP_CR(%cr28, %r26) 1361da177e4SLinus Torvalds POP_CR(%cr27, %r26) 1371da177e4SLinus Torvalds POP_CR(%cr26, %r26) 1381da177e4SLinus Torvalds POP_CR(%cr25, %r26) 1391da177e4SLinus Torvalds POP_CR(%cr24, %r26) 1401da177e4SLinus Torvalds bv 0(%r2) 1411da177e4SLinus Torvalds nop 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds/* rfi_virt2real() and rfi_real2virt() could perhaps be adapted for 1441da177e4SLinus Torvalds * more general-purpose use by the several places which need RFIs 1451da177e4SLinus Torvalds */ 1461da177e4SLinus Torvalds .align 128 1471da177e4SLinus Torvalds .text 1481da177e4SLinus Torvaldsrfi_virt2real: 1491da177e4SLinus Torvalds /* switch to real mode... */ 150*896a3756SGrant Grundler rsm PSW_SM_I,%r0 151*896a3756SGrant Grundler load32 PA(rfi_v2r_1), %r1 1521da177e4SLinus Torvalds nop 1531da177e4SLinus Torvalds nop 1541da177e4SLinus Torvalds nop 1551da177e4SLinus Torvalds nop 1561da177e4SLinus Torvalds nop 1571da177e4SLinus Torvalds 158*896a3756SGrant Grundler rsm PSW_SM_Q,%r0 /* disable Q & I bits to load iia queue */ 1591da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ tail */ 1601da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ head */ 1611da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ head */ 1621da177e4SLinus Torvalds ldo 4(%r1), %r1 1631da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ tail */ 1641da177e4SLinus Torvalds load32 REAL_MODE_PSW, %r1 1651da177e4SLinus Torvalds mtctl %r1, %cr22 1661da177e4SLinus Torvalds rfi 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds nop 1691da177e4SLinus Torvalds nop 1701da177e4SLinus Torvalds nop 1711da177e4SLinus Torvalds nop 1721da177e4SLinus Torvalds nop 1731da177e4SLinus Torvalds nop 1741da177e4SLinus Torvalds nop 1751da177e4SLinus Torvalds nop 1761da177e4SLinus Torvaldsrfi_v2r_1: 1771da177e4SLinus Torvalds tophys_r1 %r2 1781da177e4SLinus Torvalds bv 0(%r2) 1791da177e4SLinus Torvalds nop 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds .text 1821da177e4SLinus Torvalds .align 128 1831da177e4SLinus Torvaldsrfi_real2virt: 184*896a3756SGrant Grundler rsm PSW_SM_I,%r0 185*896a3756SGrant Grundler load32 (rfi_r2v_1), %r1 1861da177e4SLinus Torvalds nop 1871da177e4SLinus Torvalds nop 1881da177e4SLinus Torvalds nop 1891da177e4SLinus Torvalds nop 1901da177e4SLinus Torvalds nop 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds rsm PSW_SM_Q,%r0 /* disable Q bit to load iia queue */ 1931da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ tail */ 1941da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ head */ 1951da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ head */ 1961da177e4SLinus Torvalds ldo 4(%r1), %r1 1971da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ tail */ 1981da177e4SLinus Torvalds load32 KERNEL_PSW, %r1 1991da177e4SLinus Torvalds mtctl %r1, %cr22 2001da177e4SLinus Torvalds rfi 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds nop 2031da177e4SLinus Torvalds nop 2041da177e4SLinus Torvalds nop 2051da177e4SLinus Torvalds nop 2061da177e4SLinus Torvalds nop 2071da177e4SLinus Torvalds nop 2081da177e4SLinus Torvalds nop 2091da177e4SLinus Torvalds nop 2101da177e4SLinus Torvaldsrfi_r2v_1: 2111da177e4SLinus Torvalds tovirt_r1 %r2 2121da177e4SLinus Torvalds bv 0(%r2) 2131da177e4SLinus Torvalds nop 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds#ifdef __LP64__ 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds/************************ 64-bit real-mode calls ***********************/ 2181da177e4SLinus Torvalds/* This is only usable in wide kernels right now and will probably stay so */ 2191da177e4SLinus Torvalds .text 2201da177e4SLinus Torvalds .export real64_call_asm 2211da177e4SLinus Torvalds /* unsigned long real64_call_asm(unsigned long *sp, 2221da177e4SLinus Torvalds * unsigned long *arg0p, 2231da177e4SLinus Torvalds * unsigned long fn) 2241da177e4SLinus Torvalds * sp is value of stack pointer to adopt before calling PDC (virt) 2251da177e4SLinus Torvalds * arg0p points to where saved arg values may be found 2261da177e4SLinus Torvalds * iodc_fn is the IODC function to call 2271da177e4SLinus Torvalds */ 2281da177e4SLinus Torvaldsreal64_call_asm: 2291da177e4SLinus Torvalds std %rp, -0x10(%sp) /* save RP */ 2301da177e4SLinus Torvalds std %sp, -8(%arg0) /* save SP on real-mode stack */ 2311da177e4SLinus Torvalds copy %arg0, %sp /* adopt the real-mode SP */ 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds /* save fn */ 2341da177e4SLinus Torvalds copy %arg2, %r31 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds /* set up the new ap */ 2371da177e4SLinus Torvalds ldo 64(%arg1), %r29 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds /* load up the arg registers from the saved arg area */ 2401da177e4SLinus Torvalds /* 32-bit calling convention passes first 4 args in registers */ 2411da177e4SLinus Torvalds ldd 0*REG_SZ(%arg1), %arg0 /* note overwriting arg0 */ 2421da177e4SLinus Torvalds ldd 2*REG_SZ(%arg1), %arg2 2431da177e4SLinus Torvalds ldd 3*REG_SZ(%arg1), %arg3 2441da177e4SLinus Torvalds ldd 4*REG_SZ(%arg1), %r22 2451da177e4SLinus Torvalds ldd 5*REG_SZ(%arg1), %r21 2461da177e4SLinus Torvalds ldd 6*REG_SZ(%arg1), %r20 2471da177e4SLinus Torvalds ldd 7*REG_SZ(%arg1), %r19 2481da177e4SLinus Torvalds ldd 1*REG_SZ(%arg1), %arg1 /* do this one last! */ 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds tophys_r1 %sp 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds b,l rfi_virt2real,%r2 2531da177e4SLinus Torvalds nop 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds b,l save_control_regs,%r2 /* modifies r1, r2, r28 */ 2561da177e4SLinus Torvalds nop 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds load32 PA(r64_ret), %r2 2591da177e4SLinus Torvalds bv 0(%r31) 2601da177e4SLinus Torvalds nop 2611da177e4SLinus Torvaldsr64_ret: 2621da177e4SLinus Torvalds /* restore CRs before going virtual in case we page fault */ 2631da177e4SLinus Torvalds b,l restore_control_regs, %r2 /* modifies r1, r2, r26 */ 2641da177e4SLinus Torvalds nop 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds b,l rfi_real2virt,%r2 2671da177e4SLinus Torvalds nop 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds tovirt_r1 %sp 2701da177e4SLinus Torvalds ldd -8(%sp), %sp /* restore SP */ 2711da177e4SLinus Torvalds ldd -0x10(%sp), %rp /* restore RP */ 2721da177e4SLinus Torvalds bv 0(%rp) 2731da177e4SLinus Torvalds nop 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds#endif 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds .export pc_in_user_space 2781da177e4SLinus Torvalds .text 2791da177e4SLinus Torvalds /* Doesn't belong here but I couldn't find a nicer spot. */ 2801da177e4SLinus Torvalds /* Should never get called, only used by profile stuff in time.c */ 2811da177e4SLinus Torvaldspc_in_user_space: 2821da177e4SLinus Torvalds bv,n 0(%rp) 2831da177e4SLinus Torvalds nop 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds .export __canonicalize_funcptr_for_compare 2871da177e4SLinus Torvalds .text 2881da177e4SLinus Torvalds /* http://lists.parisc-linux.org/hypermail/parisc-linux/10916.html 2891da177e4SLinus Torvalds ** GCC 3.3 and later has a new function in libgcc.a for 2901da177e4SLinus Torvalds ** comparing function pointers. 2911da177e4SLinus Torvalds */ 2921da177e4SLinus Torvalds__canonicalize_funcptr_for_compare: 2931da177e4SLinus Torvalds#ifdef __LP64__ 2941da177e4SLinus Torvalds bve (%r2) 2951da177e4SLinus Torvalds#else 2961da177e4SLinus Torvalds bv %r0(%r2) 2971da177e4SLinus Torvalds#endif 2981da177e4SLinus Torvalds copy %r26,%r28 299