xref: /titanic_51/usr/src/ucbcmd/sbcp/sbcp.s (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29	.file	"%M%"
30
31#include <sys/asm_linkage.h>
32#include <sys/syscall.h>
33
34#define	PIC_SETUP(r)						\
35	mov	%o7, %g1;					\
369:	call	8f;						\
37	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r;	\
388:	or	%r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r;	\
39	add	%r, %o7, %r;					\
40	mov	%g1, %o7
41
42#define	FUNC(x) \
43	.section	".text"; \
44	.align	4; \
45	.type	x, #function; \
46x:
47
48#define	ENOSYS	90		/* 4.x ENOSYS */
49
50/* derived from <sys/exechdr.h>, which we can't include */
51#define	A_MAGIC	0x02	/* offset of a_magic field */
52#define	A_ENTRY	0x14	/* offset of a_entry field */
53#define	ZMAGIC	0413	/* magic number for demand paged executable */
54
55	.global	atexit, errno
56
57!
58!	_start - execution starts here (after the runtime linker runs)
59!
60!	The SPARC ABI defines our "environment" at this point, see page 3-34.
61!	Register the exit handler, register the trap0 handler, find the
62!	entry point, and jump to it.  We depend on the stack (argv, envp)
63!	being compatible between 4.x and 5.x.  We also depend on the
64!	runtime linker to set up ``environ''.
65!
66
67ENTRY_NP(_start)
68	tst	%g1			! is there a handler to register?
69	bz	1f			! no
70	nop
71	mov	%g1, %o0
72	call	atexit			! yes, register it with atexit()
73	nop
741:
75
76	! give the kernel the address of our trap0 handler
77
78	PIC_SETUP(g2)
79	ld	[%g2+trap0], %g1
80	ta	9
81
82	! jump to the main program's entry point
83
84	sethi   %hi(0x2000), %o0
85	lduh    [%o0 + A_MAGIC], %g1
86	cmp     %g1, ZMAGIC		! is it a ZMAGIC executable?
87	be,a    1f			! yes,
88	ld      [%o0 + A_ENTRY], %o0	!   get entry point
891:					! else, assume entry point is 0x2000
90	jmp	%o0
91	nop
92	SET_SIZE(_start)
93
94!
95!	trap0 - glue between 4.x syscall trap and 5.x BCP routine
96!
97!	enter with:
98!		%g1	syscall number
99!		%g6	return address (after trap instruction)
100!
101!	We used to use %g7, but that conflicts with threading code
102!	which uses %g7 as the curthread pointer.  That is why we
103!	changed to using %g6 instead.
104!
105!	We use an extra window to save the %o registers we're entered
106!	with (which the 4.x system call stubs depend on) and to allow
107!	recursive traps (e.g., from a signal handler).
108!
109
110FUNC(trap0)
111	save	%sp, -SA(MINFRAME), %sp
112	tst	%g1
113	be	1f
114	nop
115	mov	%i0, %o0
116	mov	%i1, %o1
117	mov	%i2, %o2
118	mov	%i3, %o3
119	mov	%i4, %o4
120	mov	%i5, %o5
121	ba,a	2f
1221:
123	! indir syscall
124	mov	%i0, %g1
125	mov	%i1, %o0
126	mov	%i2, %o1
127	mov	%i3, %o2
128	mov	%i4, %o3
129	mov	%i5, %o4
130	ld	[%fp + MINFRAME], %o5
1312:
132	sll	%g1, 4, %l1
133	PIC_SETUP(l0)
134	ld	[%l0+sysent], %l0
135	add	%l1, %l0, %l1
136	jmp	%l1			! jump into branch table
137	nop
138	SET_SIZE(trap0)
139
140FUNC(trap0rtn)
141	cmp	%o0, -1
142	bne	1f
143	addcc	%g0, %g0, %g0		! psr &= ~C
144	PIC_SETUP(o1)
145	ld	[%o1+errno], %o1
146	ld	[%o1], %o0
147	subcc	%g0, 1, %g0		! psr |= C
1481:
149	mov	%o0, %i0
150	restore
151	jmp	%g6
152	nop
153	SET_SIZE(trap0rtn)
154
155!
156!	nullsys
157!
158FUNC(nullsys)
159	clr	%o0
160	b,a	trap0rtn
161	SET_SIZE(nullsys)
162
163!
164!	nosys
165!
166FUNC(nosys)
167	set	ENOSYS, %o1
168	PIC_SETUP(g2)
169	ld	[%g2+errno], %g2
170	st	%o1, [%g2]
171	set	-1, %o0
172	b,a	trap0rtn
173	SET_SIZE(nosys)
174
175!
176!	Have to #include the sysent table and stubs so that all
177!	symbols referenced between here and there are "static"
178!	to this module so the assembler can resolve them without
179!	the linker needing to deal with them at run time.
180!
181#include "sysent.s"
182