summaryrefslogtreecommitdiff
path: root/usr/src/lib/efcode/fcdriver/fcdebug.c
blob: fee58574ebcff0a2628ace4a01cfc85c88f68a3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 1999 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>

#include <fcode/private.h>
#include <fcode/log.h>

#include <fcdriver/fcdriver.h>

static void
dump_private(fcode_env_t *env)
{
	common_data_t *cdp;
	private_data_t *p;

	if (env->current_device) {
		p = env->current_device->private;
		if (p) {
			cdp = p->common;
		} else
			cdp = NULL;
	} else {
		cdp = env->private;
		p = NULL;
	}

	if (cdp == NULL) {
		log_message(MSG_ERROR, "dump_private: NULL private ptr!\n");
		return;
	}

	log_message(MSG_DEBUG, "Private Data:\n");
	log_message(MSG_DEBUG, "Progname:  %s\n", cdp->Progname);
	log_message(MSG_DEBUG, "fcode_fd:  %8p\n", cdp->fcode_fd);
	log_message(MSG_DEBUG, "attach:    %llx\n", cdp->attach);
	log_message(MSG_DEBUG, "Params:    (%8p)\n", &cdp->fc);
	log_message(MSG_DEBUG, "  size:    %d\n", cdp->fc.fcode_size);
	log_message(MSG_DEBUG, "  unit:    %s\n", cdp->fc.unit_address);
	if (p != NULL) {
		log_message(MSG_DEBUG, "Node:      %p\n", p->node);
		log_message(MSG_DEBUG, "Parent:    %p\n", p->parent);
		log_message(MSG_DEBUG, "upload:    %d\n", p->upload);
		log_message(MSG_DEBUG, "debug:     %8x\n", p->debug);
	}
}

static void
trigger(fcode_env_t *env)
{
	common_data_t *cdp = (common_data_t *)env->private;

	ASSERT(cdp);

	cdp->fcode_fd = open("/dev/fcode", O_RDONLY);
	if (cdp->fcode_fd >= 0) {
		log_message(MSG_INFO, "Trigger...");
		if (!fc_get_request(cdp))
			log_message(MSG_ERROR, "fc_get_request failed\n");
		else
			log_message(MSG_INFO, "\n");
	} else
		forth_abort(env, "Can't open /dev/fcode\n");
}

static void
do_trigger(fcode_env_t *env)
{
	trigger(env);
	build_tree(env);
	install_builtin_nodes(env);
}

#pragma init(_init)

static void
_init(void)
{
	fcode_env_t *env = initial_env;

	ASSERT(env);
	NOTICE;

	FORTH(0,	"dump-private",		dump_private);
	FORTH(0,	"trigger",		do_trigger);
}