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