xref: /openbmc/linux/arch/ia64/kernel/esi_stub.S (revision e657c18a)
1/*
2 * ESI call stub.
3 *
4 * Copyright (C) 2005 Hewlett-Packard Co
5 *	Alex Williamson <alex.williamson@hp.com>
6 *
7 * Based on EFI call stub by David Mosberger.  The stub is virtually
8 * identical to the one for EFI phys-mode calls, except that ESI
9 * calls may have up to 8 arguments, so they get passed to this routine
10 * through memory.
11 *
12 * This stub allows us to make ESI calls in physical mode with interrupts
13 * turned off.  ESI calls may not support calling from virtual mode.
14 *
15 * Google for "Extensible SAL specification" for a document describing the
16 * ESI standard.
17 */
18
19/*
20 * PSR settings as per SAL spec (Chapter 8 in the "IA-64 System
21 * Abstraction Layer Specification", revision 2.6e).  Note that
22 * psr.dfl and psr.dfh MUST be cleared, despite what this manual says.
23 * Otherwise, SAL dies whenever it's trying to do an IA-32 BIOS call
24 * (the br.ia instruction fails unless psr.dfl and psr.dfh are
25 * cleared).  Fortunately, SAL promises not to touch the floating
26 * point regs, so at least we don't have to save f2-f127.
27 */
28#define PSR_BITS_TO_CLEAR						\
29	(IA64_PSR_I | IA64_PSR_IT | IA64_PSR_DT | IA64_PSR_RT |		\
30	 IA64_PSR_DD | IA64_PSR_SS | IA64_PSR_RI | IA64_PSR_ED |	\
31	 IA64_PSR_DFL | IA64_PSR_DFH)
32
33#define PSR_BITS_TO_SET							\
34	(IA64_PSR_BN)
35
36#include <asm/processor.h>
37#include <asm/asmmacro.h>
38#include <asm/export.h>
39
40/*
41 * Inputs:
42 *	in0 = address of function descriptor of ESI routine to call
43 *	in1 = address of array of ESI parameters
44 *
45 * Outputs:
46 *	r8 = result returned by called function
47 */
48GLOBAL_ENTRY(esi_call_phys)
49	.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2)
50	alloc loc1=ar.pfs,2,7,8,0
51	ld8 r2=[in0],8			// load ESI function's entry point
52	mov loc0=rp
53	.body
54	;;
55	ld8 out0=[in1],8		// ESI params loaded from array
56	;;				// passing all as inputs doesn't work
57	ld8 out1=[in1],8
58	;;
59	ld8 out2=[in1],8
60	;;
61	ld8 out3=[in1],8
62	;;
63	ld8 out4=[in1],8
64	;;
65	ld8 out5=[in1],8
66	;;
67	ld8 out6=[in1],8
68	;;
69	ld8 out7=[in1]
70	mov loc2=gp			// save global pointer
71	mov loc4=ar.rsc			// save RSE configuration
72	mov ar.rsc=0			// put RSE in enforced lazy, LE mode
73	;;
74	ld8 gp=[in0]			// load ESI function's global pointer
75	movl r16=PSR_BITS_TO_CLEAR
76	mov loc3=psr			// save processor status word
77	movl r17=PSR_BITS_TO_SET
78	;;
79	or loc3=loc3,r17
80	mov b6=r2
81	;;
82	andcm r16=loc3,r16	// get psr with IT, DT, and RT bits cleared
83	br.call.sptk.many rp=ia64_switch_mode_phys
84.ret0:	mov loc5=r19			// old ar.bsp
85	mov loc6=r20			// old sp
86	br.call.sptk.many rp=b6		// call the ESI function
87.ret1:	mov ar.rsc=0			// put RSE in enforced lazy, LE mode
88	mov r16=loc3			// save virtual mode psr
89	mov r19=loc5			// save virtual mode bspstore
90	mov r20=loc6			// save virtual mode sp
91	br.call.sptk.many rp=ia64_switch_mode_virt // return to virtual mode
92.ret2:	mov ar.rsc=loc4			// restore RSE configuration
93	mov ar.pfs=loc1
94	mov rp=loc0
95	mov gp=loc2
96	br.ret.sptk.many rp
97END(esi_call_phys)
98EXPORT_SYMBOL_GPL(esi_call_phys)
99