7 Doff= 4, /* offset into Cpline.bytes of data */
9 Memsize= 1<<16, /* max size of 186 memory */
12 int dump, image, noload, nostart;
23 char* rdcpline(Biobuf*, Cpline*);
29 fprint(2, "usage: %s [-0123] file\n", argv0);
34 loadimage(char* file, int mfd)
39 if((fd = open(file, OREAD)) < 0)
40 sysfatal("opening %s: %r", file);
44 n = read(fd, buf, sizeof(buf));
46 sysfatal("read %s: %r", file);
48 if((r = write(mfd, buf, n)) != n)
49 sysfatal("write %s: %d != %d: %r", file, n, r);
55 loadhex(char* file, int mfd)
65 b = Bopen(file, OREAD);
67 sysfatal("opening %s: %r", file);
71 for(done = 0; !done; lineno++){
72 err = rdcpline(b, &c);
74 sysfatal("%s line %d: %s", file, lineno, err);
78 if(addr + c.dlen > Memsize)
79 sysfatal("addr out of range: %lux-%lux", addr, addr+c.dlen);
80 if(seek(mfd, addr, 0) < 0)
81 sysfatal("seeking to %lud: %r", addr);
82 if(write(mfd, c.bytes+Doff, c.dlen) != c.dlen)
83 sysfatal("writing: %r");
84 if(seek(mfd, addr, 0) < 0)
85 sysfatal("seeking to %lud: %r", addr);
86 if(read(mfd, buf, c.dlen) != c.dlen)
87 sysfatal("reading: %r");
88 if(memcmp(buf, c.bytes+Doff, c.dlen) != 0)
89 print("readback error at %lux\n", addr);
91 print("%8.8lux: %d\n", addr, c.dlen);
93 case 1: /* termination */
97 seg = ((c.bytes[Doff]<<8) | c.bytes[Doff+1]) <<4;
99 sysfatal("seg out of range: %lux", seg);
101 print("seg %8.8lux\n", seg);
103 default: /* ignore */
105 print("bad type %d\n", c.type);
113 main(int argc, char **argv)
151 sprint(file, "#G/astar%dctl", unit);
152 cfd = open(file, ORDWR);
154 sysfatal("opening %s", file);
155 sprint(file, "#G/astar%dmem", unit);
156 mfd = open(file, ORDWR);
158 sysfatal("opening %s", file);
160 if(write(cfd, "download", 8) != 8)
161 sysfatal("requesting download: %r");
164 mfd = create("/tmp/astarmem", ORDWR, 0664);
166 sysfatal("creating /tmp/astarmem: %r");
170 loadimage(argv[0], mfd);
172 /* zero out the memory */
174 loadhex(argv[0], mfd);
178 if(noload == 0 && nostart == 0)
179 if(write(cfd, "run", 3) != 3)
180 sysfatal("requesting run: %r");
193 memset(buf, 0, sizeof buf);
194 for(i = 0; i < Memsize; i += n){
195 if(seek(fd, i, 0) < 0)
196 sysfatal("seeking to %ux: %r", i);
197 n = write(fd, buf, sizeof buf);
200 if(seek(fd, i, 0) < 0)
201 sysfatal("seeking to %ux: %r", i);
202 n = read(fd, buf2, sizeof buf2);
205 if(memcmp(buf, buf2, sizeof buf) != 0)
206 print("error zeroing mem at %ux\n", i);
208 print("zero'd %d bytes\n", i);
214 if(c <= '9' && c >= '0')
216 if(c <= 'f' && c >= 'a')
217 return (c - 'a') + 10;
218 if(c <= 'F' && c >= 'A')
219 return (c - 'A') + 10;
224 rdcpline(Biobuf *b, Cpline *cpl)
231 cp = Brdline(b, '\n');
234 ep = cp + Blinelen(b);
237 return "bad load line";
241 for(p = cp; p < ep;){
252 fprint(2, "checksum %ux\n", csum);
253 return "bad checksum";
256 cpl->dlen = cpl->bytes[0];
257 if(cpl->dlen + 5 != up - cpl->bytes){
258 fprint(2, "%d %ld\n", cpl->dlen + 5, up - cpl->bytes);
259 return "bad data length";
262 cpl->addr = (cpl->bytes[1]<<8) | cpl->bytes[2];
263 cpl->type = cpl->bytes[3];