File: dump-hp700rx-rom.c

package info (click to toggle)
gxemul 0.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,152 kB
  • sloc: ansic: 111,065; sh: 972; exp: 354; makefile: 118
file content (197 lines) | stat: -rw-r--r-- 5,462 bytes parent folder | download | duplicates (3)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 *  Copyright (C) 2019  Anders Gavare.  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 *  SUCH DAMAGE.
 *
 *
 *  HP 700/RX (i960) memory range dumping tool by Anders Gavare (gavare@gmail.com)
 *
 *  Can be used to dump the 512 KB ROM at 0xfff80000 or RAM or any other interesting range.
 *
 *  Build it using i960-unknown-coff toolchain like this, to produce a b.out "module"
 *  that can be accepted by the HP 700/RX.
 *
 *	i960-unknown-coff-gcc -c dump.c -Wall
 *	i960-unknown-coff-ld dump.o -o dump --relocatable -e _entry_point_data
 *	i960-unknown-coff-objcopy dump -O b.out.little dump.bout --strip-unneeded
 *
 *
 *  The output is displayed both on the screen and on the serial port.
 *  It is sent three times. It can then relatively easily be parsed.
 *
 *  Yes, it is horrible, but it works.
 */


// #define TEST_NATIVE

#ifdef TEST_NATIVE
void logPrintf(char* format, ...) { }
#endif


// Not accurate, but at least does something.
void delay(int sec)
{
	char buf[1];
	int n = 3000;
	int i;
	
	buf[0] = 42;

	while (sec > 0) {
		for (i = 0; i < n; ++i) {
			do {
				buf[0]--;
			} while (buf[0] != 42);
		}
		sec--;
	}
}


// Dumps 16 bytes in hex and ascii, then advances ofs bytes.
void dump(int fd, char** addrp, int ofs)
{
	unsigned char* addr = *addrp;
	char buf[50];
	int i;
	
	logPrintf("%08x ", addr);
	if (fd >= 0) {
		sprintf(buf, "%08x ", addr);
		write(fd, buf, strlen(buf));
	}

	for (i = 0; i < 16; ++i) {
		logPrintf("%02x ", addr[i]);
		if (fd >= 0) {
			sprintf(buf, "%02x ", addr[i]);
			write(fd, buf, strlen(buf));
		}
	}

	for (i = 0; i < 16; ++i) {
		unsigned char c = addr[i];
		if (c < 32 || c >= 127)
			c = '_';
		logPrintf("%c", c);
		if (fd >= 0) {
			sprintf(buf, "%c", c);
			write(fd, buf, strlen(buf));
		}
	}

	logPrintf("\n");
	if (fd >= 0) {
		sprintf(buf, "\n");
		write(fd, buf, strlen(buf));
	}

	addr += ofs;
	
	*addrp = addr;
}


int f()
{
	int fd = open("/dev/serial", 2); //  (2 = UPDATE)
	int i;
	char* addr = &f;

	printf("printf: &f = %08x\n", &f);
	logPrintf("logPrintf: &f = %08x\n", &f);

	printf("printf: fd = %08x\n", fd);
	logPrintf("logPrintf: fd = %08x\n", fd);

	if (fd >= 0) {
		char *buffer = "Testing testing on /dev/serial\r\n\r\n";
		write(fd, buffer, strlen(buffer));
	}

	delay(5);

	addr = (char*) ( ((long)addr) & ~0xfffff );

	// Rough map:
	// ----------
	//
	// 0x00000000 .. 0x0fffffff = filled with 0xff and occasional 0xdb or 0xdf or 0xfb. (First 1 KB is supposed to be CPU built-in RAM.)
	// 0x1 = hang with weird graphics pattern
	// 0x20000000 .. 0x2fffffff = filled with 0xff mostly.
	// 0x30000000 .. 0x3fffffff = 2MB RAM. Actually just 2 MB which repeats itself over the entire range.
	// 0x40000000 .. 0x407fffff = 8MB RAM.
	// 0x40800000 .. 0x40ffffff = Same as first 8 MB at 0x40000000.
	// 0x41000000 .. 0x41ffffff = Video RAM (supposed to be 2 MB but NOT linearly mapped?!)
	// 0x42000000 .. 0x43ffffff = same as 0x40000000 .. 0x41ffffff etc.?
	// 0x5 = hang with weird graphics pattern
	// 0x60000000 = just hangs
	// 0x70000000 .. 0x8fffffff = OK dumpable
	// 0x90000000 = just hangs
	// 0xa0000000 = hangs with weird graphics pattern
	// 0xb0000000 = hangs with weird graphics pattern
	// 0xc0000000 = some devices (?)
	// 0xd0000000 .. 0xfff7ffff = filled with 0xff on read
	// 0xfff8xxxx = ROM
	// 0xffffff00 = Initial Boot Record (IBR), containing first instruction pointer etc.

	addr = (char*)(int)0xfff80000;

	for (;;) {
		for (i = 0; i < 16; ++i) {
			dump(fd, &addr, 0x0);
			dump(fd, &addr, 0x0);
			dump(fd, &addr, 0x10);

// These can be used when scanning through the entire 4 GB memory space for interesting regions.
//			dump(fd, &addr, 0x00100000 - 0x10);
//			dump(fd, &addr, 0x00100000 - 0x10);
		}

		if (addr == 0)
			break;
	}

	return -2;
}


#ifdef TEST_NATIVE
int main()
{
	f();
}
#endif


/*
 *  This is the weird way entry points are specified for the
 *  loadable b.out module files for the HP 700/RX. f is the actual
 *  code entry point.
 */

unsigned int entry_point_data[3] = { 0xa9ad646a, 2, (unsigned int) &f };