xref: /titanic_51/usr/src/lib/efcode/fcdriver/fcdebug.c (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
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) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <strings.h>
35 
36 #include <fcode/private.h>
37 #include <fcode/log.h>
38 
39 #include <fcdriver/fcdriver.h>
40 
41 static void
42 dump_private(fcode_env_t *env)
43 {
44 	common_data_t *cdp;
45 	private_data_t *p;
46 
47 	if (env->current_device) {
48 		p = env->current_device->private;
49 		if (p) {
50 			cdp = p->common;
51 		} else
52 			cdp = NULL;
53 	} else {
54 		cdp = env->private;
55 		p = NULL;
56 	}
57 
58 	if (cdp == NULL) {
59 		log_message(MSG_ERROR, "dump_private: NULL private ptr!\n");
60 		return;
61 	}
62 
63 	log_message(MSG_DEBUG, "Private Data:\n");
64 	log_message(MSG_DEBUG, "Progname:  %s\n", cdp->Progname);
65 	log_message(MSG_DEBUG, "fcode_fd:  %8p\n", cdp->fcode_fd);
66 	log_message(MSG_DEBUG, "attach:    %llx\n", cdp->attach);
67 	log_message(MSG_DEBUG, "Params:    (%8p)\n", &cdp->fc);
68 	log_message(MSG_DEBUG, "  size:    %d\n", cdp->fc.fcode_size);
69 	log_message(MSG_DEBUG, "  unit:    %s\n", cdp->fc.unit_address);
70 	if (p != NULL) {
71 		log_message(MSG_DEBUG, "Node:      %p\n", p->node);
72 		log_message(MSG_DEBUG, "Parent:    %p\n", p->parent);
73 		log_message(MSG_DEBUG, "upload:    %d\n", p->upload);
74 		log_message(MSG_DEBUG, "debug:     %8x\n", p->debug);
75 	}
76 }
77 
78 static void
79 trigger(fcode_env_t *env)
80 {
81 	common_data_t *cdp = (common_data_t *)env->private;
82 
83 	ASSERT(cdp);
84 
85 	cdp->fcode_fd = open("/dev/fcode", O_RDONLY);
86 	if (cdp->fcode_fd >= 0) {
87 		log_message(MSG_INFO, "Trigger...");
88 		if (!fc_get_request(cdp))
89 			log_message(MSG_ERROR, "fc_get_request failed\n");
90 		else
91 			log_message(MSG_INFO, "\n");
92 	} else
93 		forth_abort(env, "Can't open /dev/fcode\n");
94 }
95 
96 static void
97 do_trigger(fcode_env_t *env)
98 {
99 	trigger(env);
100 	build_tree(env);
101 	install_builtin_nodes(env);
102 }
103 
104 #pragma init(_init)
105 
106 static void
107 _init(void)
108 {
109 	fcode_env_t *env = initial_env;
110 
111 	ASSERT(env);
112 	NOTICE;
113 
114 	FORTH(0,	"dump-private",		dump_private);
115 	FORTH(0,	"trigger",		do_trigger);
116 }
117