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 (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#include <stdio.h>
30#include <fcode/private.h>
31#include <fcode/log.h>
32
33static int envp;
34static int envc;
35static fcode_env_t *envs[4];
36
37static void
38do_clone(fcode_env_t *cenv)
39{
40	fcode_env_t *new;
41
42	if (envc < 4) {
43		envs[envc] = env;
44		envc++;
45		new = clone_environment(cenv, NULL);
46		if (new) {
47			envs[envc] = new;
48			env = new;
49			return;
50		}
51	}
52	system_message(cenv, "clone failed");
53}
54
55static void
56do_switch(fcode_env_t *cenv)
57{
58	int bail = 4;
59	do {
60		envp = (envp+1)%4;
61		env = envs[envp];
62		bail--;
63	} while ((env == NULL) && (!bail));
64	log_message(MSG_INFO, "Env: %x\n", env);
65}
66
67static void
68do_release(fcode_env_t *cenv)
69{
70	int bail = 4;
71	destroy_environment(envs[envp]);
72	envs[envp] = NULL;
73	do {
74		envp = (envp+1)%4;
75		env = envs[envp];
76		bail--;
77	} while ((env == NULL) && (!bail));
78}
79
80#pragma init(_init)
81
82static void
83_init(void)
84{
85	fcode_env_t *env = initial_env;
86
87	ASSERT(env);
88	NOTICE;
89
90	envp = 0;
91	envc = 0;
92
93	FORTH(0,	"clone",		do_clone);
94	FORTH(0,	"switch",		do_switch);
95	FORTH(0,	"release",		do_release);
96}
97