uwx_self_context.s revision 129059
1// Copyright (c) 2003 Hewlett-Packard Development Company, L.P.
2// Permission is hereby granted, free of charge, to any person
3// obtaining a copy of this software and associated documentation
4// files (the "Software"), to deal in the Software without
5// restriction, including without limitation the rights to use,
6// copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the
8// Software is furnished to do so, subject to the following
9// conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21// OTHER DEALINGS IN THE SOFTWARE.
22
23#ifdef _LP64
24#define SWIZZLE add
25#define STPTR st8
26#else
27#define SWIZZLE addp4
28#define STPTR st4
29#endif
30
31rRP	= r14
32rPFS	= r15
33rUNAT	= r16
34rRNAT	= r17
35rENV0	= r18
36rENV1	= r19
37rENV2	= r20
38rNSLOT	= r21
39rBSP	= r22
40rPBSP	= r23
41rRSC	= r24
42rNATP	= r25
43rBIAS	= r26
44rRSC0	= r27
45rTMP1	= r28
46rTMP2	= r29
47rTMP3	= r30
48rTMP4	= r31
49rTMP5	= r8
50
51VALID_IP     = 1
52VALID_SP     = 1 << 1
53VALID_BSP    = 1 << 2
54VALID_CFM    = 1 << 3
55VALID_PREDS  = 1 << 7
56VALID_RNAT   = 1 << 10
57VALID_UNAT   = 1 << 11
58VALID_FPSR   = 1 << 12
59VALID_LC     = 1 << 13
60VALID_GRS    = 0xf << 16
61VALID_BRS    = 0x1f << 20
62VALID_BASIC4 = VALID_IP | VALID_SP | VALID_BSP | VALID_CFM
63VALID_SPEC   = VALID_PREDS | VALID_RNAT | VALID_UNAT | VALID_FPSR | VALID_LC
64VALID_BITS   = (VALID_BASIC4 | VALID_SPEC | VALID_GRS | VALID_BRS) << 32
65
66	.text
67	.proc	uwx_self_init_context
68	.global uwx_self_init_context
69uwx_self_init_context:
70	.prologue
71	alloc	rPFS = ar.pfs, 1, 0, 0, 0
72	mov	rUNAT = ar.unat
73	.body
74	SWIZZLE	rENV0 = r0, r32		// rENV0 = &env
75	;;
76	flushrs
77	extr.u	rNSLOT = rPFS, 7, 7 	// nslots = pfs.sol
78	mov	rRP = b0
79	;;
80	mov	rRSC = ar.rsc
81	add	rENV1 = 136, rENV0	// rENV1 = &env->context.gr[0]
82	add	rENV2 = 144, rENV0	// rENV2 = &env->context.gr[1]
83	;;
84	and	rRSC0 = -4, rRSC	// clear ar.rsc.mode
85	adds	rNATP = 0x1f8, r0
86	mov	rTMP1 = b1
87	;;
88	st8.spill [rENV1] = r4, 16	// env+136: r4
89	st8.spill [rENV2] = r5, 16	// env+144: r5
90	mov	rTMP2 = b2
91	;;
92	st8.spill [rENV1] = r6, 16	// env+152: r6
93	st8.spill [rENV2] = r7, 16	// env+160: r7
94	mov	rTMP3 = b3
95	;;
96	st8	[rENV1] = rTMP1, 16	// env+168: b1
97	st8	[rENV2] = rTMP2, 16	// env+176: b2
98	mov	rTMP1 = b4
99	;;
100	st8	[rENV1] = rTMP3, 16	// env+184: b3
101	st8	[rENV2] = rTMP1, 16	// env+192: b4
102	mov	rTMP2 = b5
103	;;
104	st8	[rENV1] = rTMP2		// env+200: b5
105	mov	ar.rsc = rRSC0		// enforced lazy mode
106	add	rENV1 = 8, rENV0
107	;;
108	mov	rRNAT = ar.rnat		// get copy of ar.rnat
109	movl	rTMP1 = VALID_BITS	// valid_regs: ip, sp, bsp, cfm,
110					// preds, rnat, unat, fpsr,
111					// lc, grs, brs
112					// = 0x1ff3c8f00000000
113	;;
114	mov	ar.rsc = rRSC		// restore ar.rsc
115	mov	rBSP = ar.bsp
116	add	rTMP3 = 136, rENV0	// spill_loc = &env->context.gr[0]
117	;;
118	mov	rTMP2 = ar.unat
119	nop
120	extr.u	rTMP3 = rTMP3, 3, 6	// bitpos = spill_loc{8:3}
121	;;
122	or	rNATP = rBSP, rNATP	// natp = bsp | 0x1f8
123	sub	rTMP4 = 64, rTMP3	// (64 - bitpos)
124	shr	rTMP5 = rTMP2, rTMP3	// (unat >> bitpos)
125	;;
126	sub	rBIAS = rNATP, rBSP	// bias = (natp - bsp) ...
127	nop
128	shl	rTMP2 = rTMP2, rTMP4	// (unat << (64 - bitpos))
129	;;
130	or	rTMP2 = rTMP2, rTMP5	// rotate_right(unat, bitpos)
131	extr.u	rBIAS = rBIAS, 3, 6	// ... div 8
132	mov	rTMP4 = pr
133	;;
134	st8	[rENV0] = rTMP1, 16	// env+0: valid_regs mask
135	st8	[rENV1] = rRP, 24	// env+8: ip (my rp)
136	add	rBIAS = rNSLOT, rBIAS	// bias += nslots
137	;;
138	cmp.lt	p6, p0 = 63, rBIAS	// if (63 < bias) ...
139	cmp.lt	p7, p0 = 126, rBIAS	// if (126 < bias) ...
140	nop
141	;;
142	st8	[rENV0] = r12, 48	// env+16: sp
143	st8	[rENV1] = rPFS, 40	// env+32: cfm (my pfs)
144(p6)	add	rNSLOT = 1, rNSLOT	//   ... nslots++
145	;;
146	st8	[rENV0] = rTMP4, 24	// env+64: preds
147	st8	[rENV1] = rTMP2, 24	// env+72: priunat
148(p7)	add	rNSLOT = 1, rNSLOT	//   ... nslots++
149	;;
150	st8	[rENV0] = rRNAT, -64	// env+88: rnat
151	st8	[rENV1] = rUNAT, 8	// env+96: unat
152	dep.z	rTMP3 = rNSLOT, 3, 7 	// (nslots << 3)
153	;;
154	sub	rPBSP = rBSP, rTMP3	// prev_bsp = bsp - (nslots << 3)
155	mov	rTMP3 = ar.fpsr
156	mov	rTMP1 = ar.lc
157	;;
158	st8	[rENV0] = rPBSP		// env+24: bsp (my prev bsp)
159	st8	[rENV1] = rTMP3, 8	// env+104: fpsr
160	add	rENV2 = 320, rENV2	// rENV2 = &env->context.rstate
161	;;
162	st8	[rENV1] = rTMP1		// env+112: lc
163	STPTR	[rENV2] = r0		// env+528: env->rstate = 0
164	nop
165	;;
166	mov	ar.unat = rUNAT
167	mov	ret0 = r0		// return UWX_OK
168	br.ret.sptk	b0
169	.endp
170
171