Allow loading binary images in simulator. Fix instruction decoding.
This commit is contained in:
parent
a853e8eaad
commit
ee74cfc5f9
57
dsim.c
57
dsim.c
|
@ -3,6 +3,11 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint16_t ram[0x10000];
|
||||
uint16_t ra, rb, rc, rx, ry, rz, ri, rj;
|
||||
uint16_t rpc, rsp, rex, ria;
|
||||
|
@ -47,8 +52,6 @@ void reset()
|
|||
running = true;
|
||||
}
|
||||
|
||||
typedef void (*dev_t)(void);
|
||||
|
||||
struct dev_entry {
|
||||
uint32_t vendor;
|
||||
uint32_t product;
|
||||
|
@ -471,8 +474,8 @@ void next()
|
|||
ir = ram[rpc++];
|
||||
|
||||
opcode = ir & 0x001f;
|
||||
a = (ir >> 5) & 0x001f;
|
||||
b = (ir >> 10) & 0x003f;
|
||||
a = (ir >> 10) & 0x003f;
|
||||
b = (ir >> 5) & 0x001f;
|
||||
|
||||
if (opcode == 0) { /* special instruction */
|
||||
f = sops[b];
|
||||
|
@ -492,9 +495,49 @@ void next()
|
|||
ticks++;
|
||||
}
|
||||
|
||||
int main()
|
||||
int load_image(char *filename)
|
||||
{
|
||||
reset();
|
||||
while (running) next();
|
||||
int fd;
|
||||
ssize_t r;
|
||||
ssize_t pos;
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
for (pos=0;;) {
|
||||
r = read(fd, &ram[pos], sizeof(ram));
|
||||
if (r > 0)
|
||||
pos += r;
|
||||
else {
|
||||
close(fd);
|
||||
if (r == 0)
|
||||
return pos;
|
||||
else
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dump_ram(uint16_t addr, uint16_t count)
|
||||
{
|
||||
uint16_t i, a;
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
a = (addr + i) % sizeof(ram);
|
||||
if ((i % 8) == 0)
|
||||
printf("\n%04x: ", a);
|
||||
printf("%04x ", ram[a]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc > 1) {
|
||||
load_image(argv[1]);
|
||||
dump_ram(0, 32);
|
||||
reset();
|
||||
while (running) next();
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue