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 /*
24*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
25*7c478bd9Sstevel@tonic-gate  * All rights reserved.
26*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include <stdio.h>
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <fcode/private.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate /*
35*7c478bd9Sstevel@tonic-gate  * Return a pointer to the allocated instance data.
36*7c478bd9Sstevel@tonic-gate  * If the data was initialised then return a pointer to the initialisation
37*7c478bd9Sstevel@tonic-gate  * buffer otherwise return a pointer to the un-init data.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate token_t *
alloc_instance_data(fcode_env_t * env,int init,int n,int * offset)40*7c478bd9Sstevel@tonic-gate alloc_instance_data(fcode_env_t *env, int init, int n, int *offset)
41*7c478bd9Sstevel@tonic-gate {
42*7c478bd9Sstevel@tonic-gate 	int ptr;
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 	*offset = ptr = MYSELF->device->data_size[init];
45*7c478bd9Sstevel@tonic-gate 	MYSELF->device->data_size[init] += n;
46*7c478bd9Sstevel@tonic-gate 	if (init == INIT_DATA)
47*7c478bd9Sstevel@tonic-gate 		return (&MYSELF->device->init_data[ptr]);
48*7c478bd9Sstevel@tonic-gate 	else
49*7c478bd9Sstevel@tonic-gate 		return (&MYSELF->data[init][ptr]);
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate token_t *
get_instance_address(fcode_env_t * env)53*7c478bd9Sstevel@tonic-gate get_instance_address(fcode_env_t *env)
54*7c478bd9Sstevel@tonic-gate {
55*7c478bd9Sstevel@tonic-gate 	int which;
56*7c478bd9Sstevel@tonic-gate 	token_t *ptr;
57*7c478bd9Sstevel@tonic-gate 	token_t offset;
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate 	CHECK_DEPTH(env, 1, "get_instance_address");
60*7c478bd9Sstevel@tonic-gate 	ptr = (token_t *) POP(DS);
61*7c478bd9Sstevel@tonic-gate 	offset = *ptr;
62*7c478bd9Sstevel@tonic-gate 	if (offset < 0) {
63*7c478bd9Sstevel@tonic-gate 		offset = -offset;
64*7c478bd9Sstevel@tonic-gate 		which = UINIT_DATA;
65*7c478bd9Sstevel@tonic-gate 	} else {
66*7c478bd9Sstevel@tonic-gate 		which = INIT_DATA;
67*7c478bd9Sstevel@tonic-gate 	}
68*7c478bd9Sstevel@tonic-gate 	return (&MYSELF->data[which][offset]);
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate void
fetch_instance_data(fcode_env_t * env)72*7c478bd9Sstevel@tonic-gate fetch_instance_data(fcode_env_t *env)
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate 	token_t *ptr;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	CHECK_DEPTH(env, 1, "get_instance_data");
77*7c478bd9Sstevel@tonic-gate 	ptr = get_instance_address(env);
78*7c478bd9Sstevel@tonic-gate 	PUSH(DS, *ptr);
79*7c478bd9Sstevel@tonic-gate }
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate void
set_instance_data(fcode_env_t * env)82*7c478bd9Sstevel@tonic-gate set_instance_data(fcode_env_t *env)
83*7c478bd9Sstevel@tonic-gate {
84*7c478bd9Sstevel@tonic-gate 	token_t *ptr;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	CHECK_DEPTH(env, 2, "set_instance_data");
87*7c478bd9Sstevel@tonic-gate 	ptr = get_instance_address(env);
88*7c478bd9Sstevel@tonic-gate 	*ptr = POP(DS);
89*7c478bd9Sstevel@tonic-gate }
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate void
address_instance_data(fcode_env_t * env)92*7c478bd9Sstevel@tonic-gate address_instance_data(fcode_env_t *env)
93*7c478bd9Sstevel@tonic-gate {
94*7c478bd9Sstevel@tonic-gate 	token_t *ptr;
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	CHECK_DEPTH(env, 1, "address_instance_data");
97*7c478bd9Sstevel@tonic-gate 	ptr = get_instance_address(env);
98*7c478bd9Sstevel@tonic-gate 	PUSH(DS, (fstack_t) ptr);
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate void
instance_variable(fcode_env_t * env)102*7c478bd9Sstevel@tonic-gate instance_variable(fcode_env_t *env)
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	token_t *ptr;
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	PUSH(DS, (fstack_t) WA);
107*7c478bd9Sstevel@tonic-gate 	ptr = get_instance_address(env);
108*7c478bd9Sstevel@tonic-gate 	PUSH(DS, (fstack_t) ptr);
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate void
idefer_exec(fcode_env_t * env)112*7c478bd9Sstevel@tonic-gate idefer_exec(fcode_env_t *env)
113*7c478bd9Sstevel@tonic-gate {
114*7c478bd9Sstevel@tonic-gate 	CHECK_DEPTH(env, 1, "idefer_exec");
115*7c478bd9Sstevel@tonic-gate 	fetch_instance_data(env);
116*7c478bd9Sstevel@tonic-gate 	execute(env);
117*7c478bd9Sstevel@tonic-gate }
118