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
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.
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]
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <fcode/private.h>
35 #include <fcode/log.h>
37 #include <fcdriver/fcdriver.h>
39 static device_t
*builtin_driver_device
;
42 is_device_builtin_package(fcode_env_t
*env
, device_t
*d
)
44 return (d
== builtin_driver_device
);
47 static char *dropin_name
;
50 * do-builtin-dropin ( -- )
51 * Convoluted name just in case someone has "do-dropin" word in Fcode.
52 * Somewhat different from do-dropin in OBP, as we just load the Fcode, we
53 * don't do a byte-load.
56 do_builtin_dropin(fcode_env_t
*env
)
58 fc_cell_t len
, result
;
61 static char func_name
[] = "do-builtin-dropin";
62 extern int check_fcode_header(char *, uchar_t
*, int);
64 if (dropin_name
== NULL
) {
65 log_message(MSG_ERROR
, "%s: dropin_name not set\n", func_name
);
68 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s'\n", func_name
, dropin_name
);
69 error
= fc_run_priv(env
->private, "sunos,get-fcode-size", 1, 1,
70 fc_ptr2cell(dropin_name
), &len
);
74 log_message(MSG_WARN
, "%s: '%s' zero length Fcode\n",
75 func_name
, dropin_name
);
79 error
= fc_run_priv(env
->private, "sunos,get-fcode", 3, 1,
80 fc_ptr2cell(dropin_name
), fc_ptr2cell(buf
), len
, &result
);
86 if (check_fcode_header(dropin_name
, (uchar_t
*)buf
, len
) == 0)
87 log_message(MSG_WARN
, "%s: '%s' fcode header NOT OK\n",
88 func_name
, dropin_name
);
90 debug_msg(DEBUG_FIND_FCODE
,
91 "%s: '%s' doing byte-load len: %x\n", func_name
, dropin_name
,
93 PUSH(DS
, (fstack_t
)buf
);
99 do_builtin_file(fcode_env_t
*env
)
102 static char func_name
[] = "do-builtin-file";
105 if (dropin_name
== NULL
) {
106 log_message(MSG_ERROR
, "%s: dropin_name not set\n", func_name
);
109 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s'\n", func_name
, dropin_name
);
110 push_a_string(env
, dropin_name
);
114 debug_msg(DEBUG_FIND_FCODE
, "%s: byte-load '%s'\n", func_name
,
119 debug_msg(DEBUG_FIND_FCODE
, "%s: load_file '%s' FAIL\n",
120 func_name
, dropin_name
);
124 * We need to lookup the builtin name via an FC_RUN_PRIV call to make sure
125 * the builtin exists. If it exists, then we need to leave the xt of
126 * do-builtin-dropin on the stack and remember the name for do-dropin. This is
127 * extremely convoluted because we can't a priori populate
128 * SUNW,builtin-drivers.
131 builtin_driver_method_hook(fcode_env_t
*env
)
138 static char func_name
[] = "builtin-driver-method-hook";
141 CONVERT_PHANDLE(env
, device
, d
);
142 if (!is_device_builtin_package(env
, device
)) {
148 method
= pop_a_string(env
, NULL
);
151 * Check for file in filesystem. If it exists, we'll just try to do
154 if ((path
= search_for_fcode_file(env
, method
)) != NULL
) {
155 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s' file: '%s'\n", func_name
,
160 dropin_name
= STRDUP(path
);
161 push_a_string(env
, "do-builtin-file");
166 error
= fc_run_priv(env
->private, "sunos,get-fcode-size", 1, 1,
167 fc_ptr2cell(method
), &len
);
168 if (error
|| len
== 0) {
170 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s' NOT FOUND\n",
172 push_a_string(env
, method
);
176 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s' FOUND len: %x\n",
177 func_name
, method
, (int)len
);
181 dropin_name
= STRDUP(method
);
182 push_a_string(env
, "do-builtin-dropin");
188 make_a_node(fcode_env_t
*env
, char *name
, int finish
)
191 push_a_string(env
, name
);
198 install_package_nodes(fcode_env_t
*env
)
200 MYSELF
= open_instance_chain(env
, env
->root_node
, 0);
201 if (MYSELF
!= NULL
) {
202 make_a_node(env
, "packages", 0);
203 make_a_node(env
, "disk-label", 0);
205 make_a_node(env
, "SUNW,builtin-drivers", 0);
206 builtin_driver_device
= env
->current_device
;
209 close_instance_chain(env
, MYSELF
, 0);
216 * find-builtin-driver ( str len -- xt true | false )
219 find_builtin_driver(fcode_env_t
*env
)
223 CHECK_DEPTH(env
, 2, "find-builtin-driver");
224 push_a_string(env
, "SUNW,builtin-drivers");
236 exec_builtin_driver(fcode_env_t
*env
)
239 char *method
, *path
, *buf
;
240 fc_cell_t len
, result
;
242 static char func_name
[] = "exec-builtin-driver";
243 extern int check_fcode_header(char *, uchar_t
*, int);
245 CHECK_DEPTH(env
, 2, func_name
);
246 method
= pop_a_string(env
, NULL
);
249 * Check for file in filesystem. If it exists, we'll just try to do
252 if ((path
= search_for_fcode_file(env
, method
)) != NULL
) {
253 push_a_string(env
, path
);
258 error
= fc_run_priv(env
->private, "sunos,get-fcode-size", 1, 1,
259 fc_ptr2cell(method
), &len
);
260 if (error
|| len
== 0) {
262 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s' NOT FOUND\n",
267 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s' FOUND len: %x\n",
268 func_name
, method
, (int)len
);
270 error
= fc_run_priv(env
->private, "sunos,get-fcode", 3, 1,
271 fc_ptr2cell(method
), fc_ptr2cell(buf
), len
, &result
);
278 if (check_fcode_header(dropin_name
, (uchar_t
*)buf
, len
) == 0)
279 log_message(MSG_WARN
, "%s: '%s' fcode header NOT OK\n",
282 debug_msg(DEBUG_FIND_FCODE
, "%s: '%s' dropin Fcode: 0x%p/0x%x\n",
283 func_name
, method
, buf
, (int)len
);
284 PUSH(DS
, (fstack_t
)buf
);
293 extern void set_find_method_hook(fcode_env_t
*,
294 void (*)(fcode_env_t
*));
295 fcode_env_t
*env
= initial_env
;
301 set_find_method_hook(env
, builtin_driver_method_hook
);
303 FORTH(0, "install-package-nodes", install_package_nodes
);
304 FORTH(0, "find-builtin-driver", find_builtin_driver
);
305 FORTH(0, "exec-builtin-driver", exec_builtin_driver
);
306 FORTH(0, "builtin-driver-method-hook",
307 builtin_driver_method_hook
);
308 FORTH(0, "do-builtin-dropin", do_builtin_dropin
);
309 FORTH(0, "do-builtin-file", do_builtin_file
);