xref: /inferno-os/lib/acid/gpa (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1//
2//	generate ``General Purpose Ascii'' file for HP logic analyser
3//
4//	usage: gpa()
5//	note: output has to be postprocessed with "sed 's/0x//g' "...
6//
7
8defn functions(start, end)
9{
10	print("[FUNCTIONS]\n");
11	pc = start;
12	while pc < end do {
13		bnd = fnbound(pc);
14		print(pc\a, "\t", bnd[0], "..", bnd[1]-1, "\n");
15		pc = bnd[1];
16	}
17	print("\n");
18}
19
20defn variables(start, end)
21{
22	print("[VARIABLES]\n");
23	// TODO: how do we get this one?
24	print("\n");
25}
26
27defn sourcelines(start, end)
28{
29	local pc, curfile, curline, newfile, newline;
30
31	print("[SOURCE LINES]\n");
32	pc = txtstart;
33	curfile = "<no-file>";
34	curline = -1;
35	while pc < txtend do {
36		newfile = pcfile(pc);
37		newline = pcline(pc);
38		if newfile != curfile then {
39			if curline != -1 then
40				print("\n");
41			print("File: ", newfile, "\n");
42			curfile = newfile;
43		}
44		if newline != curline then {
45			print(newline, "\t", pc, "\n");
46			curline = newline;
47		}
48		pc++;
49	}
50	print("\n");
51}
52
53defn gpa()
54{
55	local l, ent, txtstart, txtend, datastart, dataend, pc, bnd;
56
57	print("[SECTIONS]\n");
58	l = map();
59	while l do {
60		ent = head l;
61		if ent[0] == "text" || ent[0] == "data" then {
62			if ent[0] == "text" then {
63				txtstart = ent[1];
64				txtend = ent[2];
65			}
66			else {
67				datastart = ent[1];
68				dataend = ent[2];
69			}
70			print(ent[0], "\t", ent[1], "..", ent[2]-1, "\n");
71		}
72		l = tail l;
73	}
74	print("\n");
75
76	functions(txtstart, txtend);
77//	variables(datastart, dataend);
78	sourcelines(datastart, dataend);
79
80	print("[START ADDRESS]\n");
81	print(txtstart, "\n");
82	print("\n");
83}
84
85defn acidinit()
86{
87	gpa();
88}
89