1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate#include <mdb/mdb_kreg.h>
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate/*
34*7c478bd9Sstevel@tonic-gate * Kernel function call invocation
35*7c478bd9Sstevel@tonic-gate */
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate#if !defined(__lint)
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate	.section	RODATA
40*7c478bd9Sstevel@tonic-gate	.align		8
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate	/*
43*7c478bd9Sstevel@tonic-gate	 * A jump table containing the addresses for register argument copy
44*7c478bd9Sstevel@tonic-gate	 * code.
45*7c478bd9Sstevel@tonic-gate	 */
46*7c478bd9Sstevel@tonic-gatecopyargs:
47*7c478bd9Sstevel@tonic-gate	.xword	cp0arg
48*7c478bd9Sstevel@tonic-gate	.xword	cp1arg
49*7c478bd9Sstevel@tonic-gate	.xword	cp2arg
50*7c478bd9Sstevel@tonic-gate	.xword	cp3arg
51*7c478bd9Sstevel@tonic-gate	.xword	cp4arg
52*7c478bd9Sstevel@tonic-gate	.xword	cp5arg
53*7c478bd9Sstevel@tonic-gatecopyargsend:
54*7c478bd9Sstevel@tonic-gate	.xword	cp6arg
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate#endif	/* __lint */
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate#if defined(__lint)
59*7c478bd9Sstevel@tonic-gate/*ARGSUSED*/
60*7c478bd9Sstevel@tonic-gateuintptr_t
61*7c478bd9Sstevel@tonic-gatekaif_invoke(uintptr_t funcva, uint_t argc, const uintptr_t *argv,
62*7c478bd9Sstevel@tonic-gate    kreg_t g6, kreg_t g7)
63*7c478bd9Sstevel@tonic-gate{
64*7c478bd9Sstevel@tonic-gate	return (0);
65*7c478bd9Sstevel@tonic-gate}
66*7c478bd9Sstevel@tonic-gate#else
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate	ENTRY_NP(kaif_invoke)
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate	save	%sp, -SA(MINFRAME), %sp
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate	/*
73*7c478bd9Sstevel@tonic-gate	 * Will registers suffice, or do we need to put excess args (>6) on the
74*7c478bd9Sstevel@tonic-gate	 * stack?
75*7c478bd9Sstevel@tonic-gate	 */
76*7c478bd9Sstevel@tonic-gate	sub	%i1, 6, %i1	! %i1 is now num regs over 6 (if any)
77*7c478bd9Sstevel@tonic-gate	brgz,pn	%i1, savestackargs
78*7c478bd9Sstevel@tonic-gate	sllx	%i1, 3, %i1	! (argc - 6) * 8
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate	/*
81*7c478bd9Sstevel@tonic-gate	 * We have fewer than six arguments.  Below, starting at the cp6arg
82*7c478bd9Sstevel@tonic-gate	 * label, we've got code that'll copy these arguments to the out
83*7c478bd9Sstevel@tonic-gate	 * registers in descending order (%o5 is copied, then %o4, and so on).
84*7c478bd9Sstevel@tonic-gate	 * We only want to move valid arguments, so we'll jump into this copy
85*7c478bd9Sstevel@tonic-gate	 * code just before it copies our highest arg.  If we have four args,
86*7c478bd9Sstevel@tonic-gate	 * for example, we'll jump to cp4arg.
87*7c478bd9Sstevel@tonic-gate	 *
88*7c478bd9Sstevel@tonic-gate	 * %i6 is now a negative word-scaled offset, which we can use to
89*7c478bd9Sstevel@tonic-gate	 * retrieve the appropriate address from the jump table.  We start at
90*7c478bd9Sstevel@tonic-gate	 * bottom of the table, and let the negative offset jump back to the
91*7c478bd9Sstevel@tonic-gate	 * correct location.  If we have four arguments, %i1 will be -16.
92*7c478bd9Sstevel@tonic-gate	 * Starting from copyargs+48 (the address of the last slot), we get
93*7c478bd9Sstevel@tonic-gate	 * copyargs+32, which contains the address (cp4arg) to be used to copy
94*7c478bd9Sstevel@tonic-gate	 * four arguments.
95*7c478bd9Sstevel@tonic-gate	 */
96*7c478bd9Sstevel@tonic-gate	setx	copyargsend, %l1, %l0
97*7c478bd9Sstevel@tonic-gate	ldx	[%l0 + %i1], %l0
98*7c478bd9Sstevel@tonic-gate	jmp	%l0
99*7c478bd9Sstevel@tonic-gate	nop
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gatesavestackargs:
102*7c478bd9Sstevel@tonic-gate	/*
103*7c478bd9Sstevel@tonic-gate	 * We have more than six arguments, and will thus need to allocate space
104*7c478bd9Sstevel@tonic-gate	 * for the seventh and beyond on the stack.  %i1 is the number of bytes
105*7c478bd9Sstevel@tonic-gate	 * needed to hold the seventh and higher arguments.
106*7c478bd9Sstevel@tonic-gate	 */
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate	/* Allocate swap space - %i1 rounded up to STACK_ALIGN */
109*7c478bd9Sstevel@tonic-gate	add	%i1, STACK_ALIGN/2, %g1
110*7c478bd9Sstevel@tonic-gate	and	%g1, -STACK_ALIGN, %g1
111*7c478bd9Sstevel@tonic-gate	sub	%sp, %g1, %sp
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate	add	%i2, 6*8, %l0			! %l0 is &argv[6]
114*7c478bd9Sstevel@tonic-gate	add	%sp, STACK_BIAS+MINFRAME, %l1	! %l1 is base of stack reg save
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate	/*
117*7c478bd9Sstevel@tonic-gate	 * Copy arguments to the stack.  %i1 is the offset from the seventh arg
118*7c478bd9Sstevel@tonic-gate	 * in argv and the offset from the base of the stack save area.
119*7c478bd9Sstevel@tonic-gate	 */
120*7c478bd9Sstevel@tonic-gate	sub	%i1, 8, %i1
121*7c478bd9Sstevel@tonic-gate1:
122*7c478bd9Sstevel@tonic-gate	ldx	[%l0 + %i1], %l2
123*7c478bd9Sstevel@tonic-gate	stx	%l2, [%l1 + %i1]
124*7c478bd9Sstevel@tonic-gate	brnz,pt	%i1, 1b
125*7c478bd9Sstevel@tonic-gate	sub	%i1, 8, %i1
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate	/*
128*7c478bd9Sstevel@tonic-gate	 * Copy the register arguments.  The argc <= 6 case will be jumping to
129*7c478bd9Sstevel@tonic-gate	 * one of these labels.
130*7c478bd9Sstevel@tonic-gate	 */
131*7c478bd9Sstevel@tonic-gatecp6arg:	ldx	[%i2 + 5*8], %o5
132*7c478bd9Sstevel@tonic-gatecp5arg:	ldx	[%i2 + 4*8], %o4
133*7c478bd9Sstevel@tonic-gatecp4arg:	ldx	[%i2 + 3*8], %o3
134*7c478bd9Sstevel@tonic-gatecp3arg:	ldx	[%i2 + 2*8], %o2
135*7c478bd9Sstevel@tonic-gatecp2arg:	ldx	[%i2 + 1*8], %o1
136*7c478bd9Sstevel@tonic-gatecp1arg:	ldx	[%i2 + 0*8], %o0
137*7c478bd9Sstevel@tonic-gatecp0arg:
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate	mov	%g6, %l0
140*7c478bd9Sstevel@tonic-gate	mov	%i3, %g6	! Restore PROC_REG for kernel call
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate	mov	%g7, %l1
143*7c478bd9Sstevel@tonic-gate	mov	%i4, %g7	! Restore THREAD_REG for kernel call
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate	jmpl	%i0, %o7	! Make call
146*7c478bd9Sstevel@tonic-gate	nop
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate	mov	%l0, %g6
149*7c478bd9Sstevel@tonic-gate	mov	%l1, %g7
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate	ret
152*7c478bd9Sstevel@tonic-gate	restore	%g0, %o0, %o0
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gate	SET_SIZE(kaif_invoke)
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate#endif
157