idbg.c
3.01 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "romloader.h"
#include "arcs.h"
#include <idbg.h>
#define MAXIDBGCMDS 30
#define DO_ENV 0x45454545 /* first record */
extern int _ArcsLoad(char *, unsigned long, int (**)(), unsigned long *);
extern int sprintf(char *, const char *, ...);
static void init_str(struct string_list *);
static new_str1(char *, register struct string_list *);
void _GetSymTable(int *,int *);
void _GetSymSize(int *);
int _MaxSyms = SYMMAX;
int _NameTabSize = NAMESIZ;
struct dbstbl _DbgTab[SYMMAX] = {0};
char _NameTab[NAMESIZ] = {0};
static dbgoff_t _CommondTab[MAXIDBGCMDS];
static struct string_list _DebuggerArgv;
void
_LoadDebugger(int argc, char **argv, void *start_pc)
{
char *colon, *symName = "symmon.IP22";
int (*init_pc)(int, char **, char **, void *);
char pcstring[24];
char bootPath[64];
long error;
unsigned long lowaddr;
char **strptrs;
strcpy(bootPath, argv[0]);
if ((colon = strchr(bootPath, ':')) != NULL)
strcpy(colon+1, symName);
else if ((colon = strchr(bootPath, ')')) != NULL)
strcpy(colon+1, symName);
else
strcpy(bootPath, symName);
/* put the addr for the debugger to return to into the environ */
sprintf (pcstring, "startpc=0x%x", start_pc);
init_str(&_DebuggerArgv);
new_str1(pcstring, &_DebuggerArgv);
/* load the symmon */
if ((error = _ArcsLoad(bootPath, 0, &init_pc, &lowaddr)) != 0) {
_ArcsPerror(error, bootPath);
return;
}
(*init_pc)(_DebuggerArgv.strcnt, _DebuggerArgv.strptrs, 0, 0);
}
void
_SetupDebugger(char *romPath)
{
unsigned long romFD, count;
long error;
dbgoff_t *dp;
/* download symbol tables */
strcat(romPath, ".sym");
if (((error = _ArcsOpen(romPath, OpenReadOnly, &romFD)) != 0) ||
((error = _ArcsRead(romFD,
(void *)&_DbgTab, _NameTabSize+_MaxSyms, &count)) != 0)){
return;
}
/*
* initialize the debug block which contains a pointer
* to _CommondTab[MAXIDBGCMDS]. _CommondTab is the table of
* commands that symmon calls
*/
dp = _CommondTab;
if (SPB->DebugBlock) {
db_t *d = (db_t *) SPB->DebugBlock;
d->db_idbgbase = (int)dp;
}
dp->s_type = DO_ENV;
dp++;
/* Give dbgmon address of _DbgTab & _NameTab */
dp->s_func = _GetSymTable;
strcpy(dp->s_name, "symtab");
dp++;
/* Give dbgmon the size of _DbgTab */
dp->s_func = _GetSymSize;
strcpy(dp->s_name, "symsize");
dp++;
}
/*
* init_str -- initialize string_list
*/
static void
init_str(register struct string_list *slp)
{
slp->strp = slp->strbuf;
slp->strcnt = 0;
slp->strptrs[0] = 0;
}
/*
* new_str1 -- add new string to string list
*/
static
new_str1(char *strp, register struct string_list *slp)
{
register int len;
if (slp->strcnt >= MAXSTRINGS - 1) {
return(-1);
}
len = strlen(strp) + 1;
if (slp->strp + len >= &slp->strbuf[STRINGBYTES]) {
return(-1);
}
slp->strptrs[slp->strcnt++] = slp->strp;
slp->strptrs[slp->strcnt] = 0;
strcpy(slp->strp, strp);
slp->strp += len;
return(0);
}
void
_GetSymTable(int *db,int *name )
{
*db = (int)&_DbgTab[0];
*name = (int)&_NameTab[0];
}
void
_GetSymSize( int *size )
{
*size = (int)_MaxSyms;
}