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 */ 10413059f2SGrant Grundler 116c86cb82SKyle McMartin#include <asm/pdc.h> 121da177e4SLinus Torvalds#include <asm/psw.h> 13896a3756SGrant Grundler#include <asm/assembly.h> 146c86cb82SKyle McMartin#include <asm/asm-offsets.h> 151da177e4SLinus Torvalds 168e9e9844SHelge Deller#include <linux/linkage.h> 178e9e9844SHelge Deller 186c86cb82SKyle McMartin 191da177e4SLinus Torvalds .section .bss 206c86cb82SKyle McMartin 216c86cb82SKyle McMartin .export pdc_result 226c86cb82SKyle McMartin .export pdc_result2 236c86cb82SKyle McMartin .align 8 246c86cb82SKyle McMartinpdc_result: 256c86cb82SKyle McMartin .block ASM_PDC_RESULT_SIZE 266c86cb82SKyle McMartinpdc_result2: 276c86cb82SKyle McMartin .block ASM_PDC_RESULT_SIZE 286c86cb82SKyle McMartin 291da177e4SLinus Torvalds .export real_stack 301da177e4SLinus Torvalds .export real32_stack 311da177e4SLinus Torvalds .export real64_stack 321da177e4SLinus Torvalds .align 64 331da177e4SLinus Torvaldsreal_stack: 341da177e4SLinus Torvaldsreal32_stack: 351da177e4SLinus Torvaldsreal64_stack: 361da177e4SLinus Torvalds .block 8192 371da177e4SLinus Torvalds 38413059f2SGrant Grundler#ifdef CONFIG_64BIT 391da177e4SLinus Torvalds# define REG_SZ 8 401da177e4SLinus Torvalds#else 411da177e4SLinus Torvalds# define REG_SZ 4 421da177e4SLinus Torvalds#endif 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds#define N_SAVED_REGS 9 451da177e4SLinus Torvalds 461da177e4SLinus Torvaldssave_cr_space: 471da177e4SLinus Torvalds .block REG_SZ * N_SAVED_REGS 481da177e4SLinus Torvaldssave_cr_end: 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds/************************ 32-bit real-mode calls ***********************/ 521da177e4SLinus Torvalds/* This can be called in both narrow and wide kernels */ 531da177e4SLinus Torvalds 54dfcf753bSKyle McMartin .text 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* unsigned long real32_call_asm(unsigned int *sp, 571da177e4SLinus Torvalds * unsigned int *arg0p, 581da177e4SLinus Torvalds * unsigned int iodc_fn) 591da177e4SLinus Torvalds * sp is value of stack pointer to adopt before calling PDC (virt) 601da177e4SLinus Torvalds * arg0p points to where saved arg values may be found 611da177e4SLinus Torvalds * iodc_fn is the IODC function to call 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds 64f39cce65SHelge DellerENTRY_CFI(real32_call_asm) 651da177e4SLinus Torvalds STREG %rp, -RP_OFFSET(%sp) /* save RP */ 66413059f2SGrant Grundler#ifdef CONFIG_64BIT 671da177e4SLinus Torvalds callee_save 681da177e4SLinus Torvalds ldo 2*REG_SZ(%sp), %sp /* room for a couple more saves */ 691da177e4SLinus Torvalds STREG %r27, -1*REG_SZ(%sp) 701da177e4SLinus Torvalds STREG %r29, -2*REG_SZ(%sp) 711da177e4SLinus Torvalds#endif 721da177e4SLinus Torvalds STREG %sp, -REG_SZ(%arg0) /* save SP on real-mode stack */ 731da177e4SLinus Torvalds copy %arg0, %sp /* adopt the real-mode SP */ 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds /* save iodc_fn */ 761da177e4SLinus Torvalds copy %arg2, %r31 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* load up the arg registers from the saved arg area */ 791da177e4SLinus Torvalds /* 32-bit calling convention passes first 4 args in registers */ 801da177e4SLinus Torvalds ldw 0(%arg1), %arg0 /* note overwriting arg0 */ 811da177e4SLinus Torvalds ldw -8(%arg1), %arg2 821da177e4SLinus Torvalds ldw -12(%arg1), %arg3 831da177e4SLinus Torvalds ldw -4(%arg1), %arg1 /* obviously must do this one last! */ 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds tophys_r1 %sp 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds b,l rfi_virt2real,%r2 881da177e4SLinus Torvalds nop 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds b,l save_control_regs,%r2 /* modifies r1, r2, r28 */ 911da177e4SLinus Torvalds nop 921da177e4SLinus Torvalds 93413059f2SGrant Grundler#ifdef CONFIG_64BIT 941da177e4SLinus Torvalds rsm PSW_SM_W, %r0 /* go narrow */ 951da177e4SLinus Torvalds#endif 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds load32 PA(ric_ret), %r2 981da177e4SLinus Torvalds bv 0(%r31) 991da177e4SLinus Torvalds nop 1001da177e4SLinus Torvaldsric_ret: 101413059f2SGrant Grundler#ifdef CONFIG_64BIT 1021da177e4SLinus Torvalds ssm PSW_SM_W, %r0 /* go wide */ 1031da177e4SLinus Torvalds#endif 1041da177e4SLinus Torvalds /* restore CRs before going virtual in case we page fault */ 1051da177e4SLinus Torvalds b,l restore_control_regs, %r2 /* modifies r1, r2, r26 */ 1061da177e4SLinus Torvalds nop 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds b,l rfi_real2virt,%r2 1091da177e4SLinus Torvalds nop 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds tovirt_r1 %sp 1121da177e4SLinus Torvalds LDREG -REG_SZ(%sp), %sp /* restore SP */ 113413059f2SGrant Grundler#ifdef CONFIG_64BIT 1141da177e4SLinus Torvalds LDREG -1*REG_SZ(%sp), %r27 1151da177e4SLinus Torvalds LDREG -2*REG_SZ(%sp), %r29 1161da177e4SLinus Torvalds ldo -2*REG_SZ(%sp), %sp 1171da177e4SLinus Torvalds callee_rest 1181da177e4SLinus Torvalds#endif 1191da177e4SLinus Torvalds LDREG -RP_OFFSET(%sp), %rp /* restore RP */ 1201da177e4SLinus Torvalds bv 0(%rp) 1211da177e4SLinus Torvalds nop 122f39cce65SHelge DellerENDPROC_CFI(real32_call_asm) 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds# define PUSH_CR(r, where) mfctl r, %r1 ! STREG,ma %r1, REG_SZ(where) 1261da177e4SLinus Torvalds# define POP_CR(r, where) LDREG,mb -REG_SZ(where), %r1 ! mtctl %r1, r 1271da177e4SLinus Torvalds 128dfcf753bSKyle McMartin .text 129f39cce65SHelge DellerENTRY_CFI(save_control_regs) 1301da177e4SLinus Torvalds load32 PA(save_cr_space), %r28 1311da177e4SLinus Torvalds PUSH_CR(%cr24, %r28) 1321da177e4SLinus Torvalds PUSH_CR(%cr25, %r28) 1331da177e4SLinus Torvalds PUSH_CR(%cr26, %r28) 1341da177e4SLinus Torvalds PUSH_CR(%cr27, %r28) 1351da177e4SLinus Torvalds PUSH_CR(%cr28, %r28) 1361da177e4SLinus Torvalds PUSH_CR(%cr29, %r28) 1371da177e4SLinus Torvalds PUSH_CR(%cr30, %r28) 1381da177e4SLinus Torvalds PUSH_CR(%cr31, %r28) 1391da177e4SLinus Torvalds PUSH_CR(%cr15, %r28) 1401da177e4SLinus Torvalds bv 0(%r2) 1411da177e4SLinus Torvalds nop 142f39cce65SHelge DellerENDPROC_CFI(save_control_regs) 1431da177e4SLinus Torvalds 144f39cce65SHelge DellerENTRY_CFI(restore_control_regs) 1451da177e4SLinus Torvalds load32 PA(save_cr_end), %r26 1461da177e4SLinus Torvalds POP_CR(%cr15, %r26) 1471da177e4SLinus Torvalds POP_CR(%cr31, %r26) 1481da177e4SLinus Torvalds POP_CR(%cr30, %r26) 1491da177e4SLinus Torvalds POP_CR(%cr29, %r26) 1501da177e4SLinus Torvalds POP_CR(%cr28, %r26) 1511da177e4SLinus Torvalds POP_CR(%cr27, %r26) 1521da177e4SLinus Torvalds POP_CR(%cr26, %r26) 1531da177e4SLinus Torvalds POP_CR(%cr25, %r26) 1541da177e4SLinus Torvalds POP_CR(%cr24, %r26) 1551da177e4SLinus Torvalds bv 0(%r2) 1561da177e4SLinus Torvalds nop 157f39cce65SHelge DellerENDPROC_CFI(restore_control_regs) 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds/* rfi_virt2real() and rfi_real2virt() could perhaps be adapted for 1601da177e4SLinus Torvalds * more general-purpose use by the several places which need RFIs 1611da177e4SLinus Torvalds */ 162dfcf753bSKyle McMartin .text 163e55fb3e7SGrant Grundler .align 128 164f39cce65SHelge DellerENTRY_CFI(rfi_virt2real) 165*f5213b2cSHelge Deller#if !defined(BOOTLOADER) 1661da177e4SLinus Torvalds /* switch to real mode... */ 167896a3756SGrant Grundler rsm PSW_SM_I,%r0 168896a3756SGrant Grundler load32 PA(rfi_v2r_1), %r1 1691da177e4SLinus Torvalds nop 1701da177e4SLinus Torvalds nop 1711da177e4SLinus Torvalds nop 1721da177e4SLinus Torvalds nop 1731da177e4SLinus Torvalds nop 1741da177e4SLinus Torvalds 175896a3756SGrant Grundler rsm PSW_SM_Q,%r0 /* disable Q & I bits to load iia queue */ 1761da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ tail */ 1771da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ head */ 1781da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ head */ 1791da177e4SLinus Torvalds ldo 4(%r1), %r1 1801da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ tail */ 1811da177e4SLinus Torvalds load32 REAL_MODE_PSW, %r1 1821da177e4SLinus Torvalds mtctl %r1, %cr22 1831da177e4SLinus Torvalds rfi 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds nop 1861da177e4SLinus Torvalds nop 1871da177e4SLinus Torvalds nop 1881da177e4SLinus Torvalds nop 1891da177e4SLinus Torvalds nop 1901da177e4SLinus Torvalds nop 1911da177e4SLinus Torvalds nop 1921da177e4SLinus Torvalds nop 1931da177e4SLinus Torvaldsrfi_v2r_1: 1941da177e4SLinus Torvalds tophys_r1 %r2 195*f5213b2cSHelge Deller#endif /* defined(BOOTLOADER) */ 1961da177e4SLinus Torvalds bv 0(%r2) 1971da177e4SLinus Torvalds nop 198f39cce65SHelge DellerENDPROC_CFI(rfi_virt2real) 1991da177e4SLinus Torvalds 200dfcf753bSKyle McMartin .text 2011da177e4SLinus Torvalds .align 128 202f39cce65SHelge DellerENTRY_CFI(rfi_real2virt) 203*f5213b2cSHelge Deller#if !defined(BOOTLOADER) 204896a3756SGrant Grundler rsm PSW_SM_I,%r0 205896a3756SGrant Grundler load32 (rfi_r2v_1), %r1 2061da177e4SLinus Torvalds nop 2071da177e4SLinus Torvalds nop 2081da177e4SLinus Torvalds nop 2091da177e4SLinus Torvalds nop 2101da177e4SLinus Torvalds nop 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds rsm PSW_SM_Q,%r0 /* disable Q bit to load iia queue */ 2131da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ tail */ 2141da177e4SLinus Torvalds mtctl %r0, %cr17 /* Clear IIASQ head */ 2151da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ head */ 2161da177e4SLinus Torvalds ldo 4(%r1), %r1 2171da177e4SLinus Torvalds mtctl %r1, %cr18 /* IIAOQ tail */ 2181da177e4SLinus Torvalds load32 KERNEL_PSW, %r1 2191da177e4SLinus Torvalds mtctl %r1, %cr22 2201da177e4SLinus Torvalds rfi 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds nop 2231da177e4SLinus Torvalds nop 2241da177e4SLinus Torvalds nop 2251da177e4SLinus Torvalds nop 2261da177e4SLinus Torvalds nop 2271da177e4SLinus Torvalds nop 2281da177e4SLinus Torvalds nop 2291da177e4SLinus Torvalds nop 2301da177e4SLinus Torvaldsrfi_r2v_1: 2311da177e4SLinus Torvalds tovirt_r1 %r2 232*f5213b2cSHelge Deller#endif /* defined(BOOTLOADER) */ 2331da177e4SLinus Torvalds bv 0(%r2) 2341da177e4SLinus Torvalds nop 235f39cce65SHelge DellerENDPROC_CFI(rfi_real2virt) 2361da177e4SLinus Torvalds 237413059f2SGrant Grundler#ifdef CONFIG_64BIT 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds/************************ 64-bit real-mode calls ***********************/ 2401da177e4SLinus Torvalds/* This is only usable in wide kernels right now and will probably stay so */ 241dfcf753bSKyle McMartin .text 2421da177e4SLinus Torvalds /* unsigned long real64_call_asm(unsigned long *sp, 2431da177e4SLinus Torvalds * unsigned long *arg0p, 2441da177e4SLinus Torvalds * unsigned long fn) 2451da177e4SLinus Torvalds * sp is value of stack pointer to adopt before calling PDC (virt) 2461da177e4SLinus Torvalds * arg0p points to where saved arg values may be found 2471da177e4SLinus Torvalds * iodc_fn is the IODC function to call 2481da177e4SLinus Torvalds */ 249f39cce65SHelge DellerENTRY_CFI(real64_call_asm) 2501da177e4SLinus Torvalds std %rp, -0x10(%sp) /* save RP */ 2511da177e4SLinus Torvalds std %sp, -8(%arg0) /* save SP on real-mode stack */ 2521da177e4SLinus Torvalds copy %arg0, %sp /* adopt the real-mode SP */ 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds /* save fn */ 2551da177e4SLinus Torvalds copy %arg2, %r31 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds /* set up the new ap */ 2581da177e4SLinus Torvalds ldo 64(%arg1), %r29 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* load up the arg registers from the saved arg area */ 2611da177e4SLinus Torvalds /* 32-bit calling convention passes first 4 args in registers */ 2621da177e4SLinus Torvalds ldd 0*REG_SZ(%arg1), %arg0 /* note overwriting arg0 */ 2631da177e4SLinus Torvalds ldd 2*REG_SZ(%arg1), %arg2 2641da177e4SLinus Torvalds ldd 3*REG_SZ(%arg1), %arg3 2651da177e4SLinus Torvalds ldd 4*REG_SZ(%arg1), %r22 2661da177e4SLinus Torvalds ldd 5*REG_SZ(%arg1), %r21 2671da177e4SLinus Torvalds ldd 6*REG_SZ(%arg1), %r20 2681da177e4SLinus Torvalds ldd 7*REG_SZ(%arg1), %r19 2691da177e4SLinus Torvalds ldd 1*REG_SZ(%arg1), %arg1 /* do this one last! */ 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds tophys_r1 %sp 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds b,l rfi_virt2real,%r2 2741da177e4SLinus Torvalds nop 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds b,l save_control_regs,%r2 /* modifies r1, r2, r28 */ 2771da177e4SLinus Torvalds nop 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds load32 PA(r64_ret), %r2 2801da177e4SLinus Torvalds bv 0(%r31) 2811da177e4SLinus Torvalds nop 2821da177e4SLinus Torvaldsr64_ret: 2831da177e4SLinus Torvalds /* restore CRs before going virtual in case we page fault */ 2841da177e4SLinus Torvalds b,l restore_control_regs, %r2 /* modifies r1, r2, r26 */ 2851da177e4SLinus Torvalds nop 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds b,l rfi_real2virt,%r2 2881da177e4SLinus Torvalds nop 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds tovirt_r1 %sp 2911da177e4SLinus Torvalds ldd -8(%sp), %sp /* restore SP */ 2921da177e4SLinus Torvalds ldd -0x10(%sp), %rp /* restore RP */ 2931da177e4SLinus Torvalds bv 0(%rp) 2941da177e4SLinus Torvalds nop 295f39cce65SHelge DellerENDPROC_CFI(real64_call_asm) 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds#endif 2981da177e4SLinus Torvalds 299dfcf753bSKyle McMartin .text 3001da177e4SLinus Torvalds /* http://lists.parisc-linux.org/hypermail/parisc-linux/10916.html 3011da177e4SLinus Torvalds ** GCC 3.3 and later has a new function in libgcc.a for 3021da177e4SLinus Torvalds ** comparing function pointers. 3031da177e4SLinus Torvalds */ 304f39cce65SHelge DellerENTRY_CFI(__canonicalize_funcptr_for_compare) 305413059f2SGrant Grundler#ifdef CONFIG_64BIT 3061da177e4SLinus Torvalds bve (%r2) 3071da177e4SLinus Torvalds#else 3081da177e4SLinus Torvalds bv %r0(%r2) 3091da177e4SLinus Torvalds#endif 3101da177e4SLinus Torvalds copy %r26,%r28 311f39cce65SHelge DellerENDPROC_CFI(__canonicalize_funcptr_for_compare) 3128e9e9844SHelge Deller 313