Catch attempts to queue to unregistered ISRs
[dragonfly.git] / sys / boot / ficl / loader.c
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 2000 Daniel Capo Sobral
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: src/sys/boot/ficl/loader.c,v 1.1.2.1 2000/07/06 23:44:59 obrien Exp $
1de703da 27 * $DragonFly: src/sys/boot/ficl/loader.c,v 1.2 2003/06/17 04:28:17 dillon Exp $
984263bc
MD
28 */
29
30/*******************************************************************
31** l o a d e r . c
32** Additional FICL words designed for FreeBSD's loader
33**
34*******************************************************************/
35
36#include <stand.h>
37#include "bootstrap.h"
38#include <string.h>
39#include "ficl.h"
40
41/* FreeBSD's loader interaction words
42 *
43 * setenv ( value n name n' -- )
44 * setenv? ( value n name n' flag -- )
45 * getenv ( addr n -- addr' n' | -1 )
46 * unsetenv ( addr n -- )
47 * copyin ( addr addr' len -- )
48 * copyout ( addr addr' len -- )
49 */
50
51void
52ficlSetenv(FICL_VM *pVM)
53{
54 char *namep, *valuep, *name, *value;
55 int names, values;
56
57#if FICL_ROBUST > 1
58 vmCheckStack(pVM, 4, 0);
59#endif
60 names = stackPopINT(pVM->pStack);
61 namep = (char*) stackPopPtr(pVM->pStack);
62 values = stackPopINT(pVM->pStack);
63 valuep = (char*) stackPopPtr(pVM->pStack);
64
65 name = (char*) ficlMalloc(names+1);
66 if (!name)
67 vmThrowErr(pVM, "Error: out of memory");
68 strncpy(name, namep, names);
69 name[names] = '\0';
70 value = (char*) ficlMalloc(values+1);
71 if (!value)
72 vmThrowErr(pVM, "Error: out of memory");
73 strncpy(value, valuep, values);
74 value[values] = '\0';
75
76 setenv(name, value, 1);
77 ficlFree(name);
78 ficlFree(value);
79
80 return;
81}
82
83void
84ficlSetenvq(FICL_VM *pVM)
85{
86 char *namep, *valuep, *name, *value;
87 int names, values, overwrite;
88
89#if FICL_ROBUST > 1
90 vmCheckStack(pVM, 5, 0);
91#endif
92 overwrite = stackPopINT(pVM->pStack);
93 names = stackPopINT(pVM->pStack);
94 namep = (char*) stackPopPtr(pVM->pStack);
95 values = stackPopINT(pVM->pStack);
96 valuep = (char*) stackPopPtr(pVM->pStack);
97
98 name = (char*) ficlMalloc(names+1);
99 if (!name)
100 vmThrowErr(pVM, "Error: out of memory");
101 strncpy(name, namep, names);
102 name[names] = '\0';
103 value = (char*) ficlMalloc(values+1);
104 if (!value)
105 vmThrowErr(pVM, "Error: out of memory");
106 strncpy(value, valuep, values);
107 value[values] = '\0';
108
109 setenv(name, value, overwrite);
110 ficlFree(name);
111 ficlFree(value);
112
113 return;
114}
115
116void
117ficlGetenv(FICL_VM *pVM)
118{
119 char *namep, *name, *value;
120 int names;
121
122#if FICL_ROBUST > 1
123 vmCheckStack(pVM, 2, 2);
124#endif
125 names = stackPopINT(pVM->pStack);
126 namep = (char*) stackPopPtr(pVM->pStack);
127
128 name = (char*) ficlMalloc(names+1);
129 if (!name)
130 vmThrowErr(pVM, "Error: out of memory");
131 strncpy(name, namep, names);
132 name[names] = '\0';
133
134 value = getenv(name);
135 ficlFree(name);
136
137 if(value != NULL) {
138 stackPushPtr(pVM->pStack, value);
139 stackPushINT(pVM->pStack, strlen(value));
140 } else
141 stackPushINT(pVM->pStack, -1);
142
143 return;
144}
145
146void
147ficlUnsetenv(FICL_VM *pVM)
148{
149 char *namep, *name;
150 int names;
151
152#if FICL_ROBUST > 1
153 vmCheckStack(pVM, 2, 0);
154#endif
155 names = stackPopINT(pVM->pStack);
156 namep = (char*) stackPopPtr(pVM->pStack);
157
158 name = (char*) ficlMalloc(names+1);
159 if (!name)
160 vmThrowErr(pVM, "Error: out of memory");
161 strncpy(name, namep, names);
162 name[names] = '\0';
163
164 unsetenv(name);
165 ficlFree(name);
166
167 return;
168}
169
170void
171ficlCopyin(FICL_VM *pVM)
172{
173 void* src;
174 vm_offset_t dest;
175 size_t len;
176
177#if FICL_ROBUST > 1
178 vmCheckStack(pVM, 3, 0);
179#endif
180
181 len = stackPopINT(pVM->pStack);
182 dest = stackPopINT(pVM->pStack);
183 src = stackPopPtr(pVM->pStack);
184
185 archsw.arch_copyin(src, dest, len);
186
187 return;
188}
189
190void
191ficlCopyout(FICL_VM *pVM)
192{
193 void* dest;
194 vm_offset_t src;
195 size_t len;
196
197#if FICL_ROBUST > 1
198 vmCheckStack(pVM, 3, 0);
199#endif
200
201 len = stackPopINT(pVM->pStack);
202 dest = stackPopPtr(pVM->pStack);
203 src = stackPopINT(pVM->pStack);
204
205 archsw.arch_copyout(src, dest, len);
206
207 return;
208}
209