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 <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
uint16_t ram[0x10000];
|
uint16_t ram[0x10000];
|
||||||
uint16_t ra, rb, rc, rx, ry, rz, ri, rj;
|
uint16_t ra, rb, rc, rx, ry, rz, ri, rj;
|
||||||
uint16_t rpc, rsp, rex, ria;
|
uint16_t rpc, rsp, rex, ria;
|
||||||
|
@ -47,8 +52,6 @@ void reset()
|
||||||
running = true;
|
running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void (*dev_t)(void);
|
|
||||||
|
|
||||||
struct dev_entry {
|
struct dev_entry {
|
||||||
uint32_t vendor;
|
uint32_t vendor;
|
||||||
uint32_t product;
|
uint32_t product;
|
||||||
|
@ -471,8 +474,8 @@ void next()
|
||||||
ir = ram[rpc++];
|
ir = ram[rpc++];
|
||||||
|
|
||||||
opcode = ir & 0x001f;
|
opcode = ir & 0x001f;
|
||||||
a = (ir >> 5) & 0x001f;
|
a = (ir >> 10) & 0x003f;
|
||||||
b = (ir >> 10) & 0x003f;
|
b = (ir >> 5) & 0x001f;
|
||||||
|
|
||||||
if (opcode == 0) { /* special instruction */
|
if (opcode == 0) { /* special instruction */
|
||||||
f = sops[b];
|
f = sops[b];
|
||||||
|
@ -492,9 +495,49 @@ void next()
|
||||||
ticks++;
|
ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int load_image(char *filename)
|
||||||
{
|
{
|
||||||
reset();
|
int fd;
|
||||||
while (running) next();
|
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;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue