summaryrefslogtreecommitdiffstats
path: root/disass.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-01-31 21:55:33 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-01-31 21:55:33 +0100
commit258c9ef71e45c8e6dff9ee708ce51681dc90ecf9 (patch)
tree78a99cc9919ee1a9c8d586c2ebbe168dfb5193d2 /disass.c
downloadebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.tar
ebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.tar.gz
ebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.tar.bz2
ebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.tar.lz
ebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.tar.xz
ebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.tar.zst
ebs-258c9ef71e45c8e6dff9ee708ce51681dc90ecf9.zip
Diffstat (limited to 'disass.c')
-rw-r--r--disass.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/disass.c b/disass.c
new file mode 100644
index 0000000..c52c154
--- /dev/null
+++ b/disass.c
@@ -0,0 +1,45 @@
+#include <ebs.c>
+#include <sys/mman.h>
+#include <error.h>
+#include <errno.h>
+#include <poll.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#define S0(x) ((x) ? (x) : "")
+int main (int argc, char ** argv) {
+ int r = 0;
+ struct ebs ebs;
+ ebs_init(&ebs);
+ if (argc != 1+1)
+ error_at_line(1, 0, __FILE__, __LINE__, "%s program.ebs", S0(argv[0]));
+ int pfd = open(argv[1], O_RDONLY | O_CLOEXEC);
+ if (pfd == -1)
+ error_at_line(2, errno, __FILE__, __LINE__, "open(%s)", argv[1]);
+ struct stat statbuf;
+ if (fstat(pfd, &statbuf) == -1) {
+ error_at_line(0, errno, __FILE__, __LINE__, "fstat(pfd, &statbuf)");
+ r = 3;
+ goto r;
+ }
+ if (!(ebs.pm_velikost = statbuf.st_size)) {
+ error_at_line(0, errno, __FILE__, __LINE__, "!(ebs.pm_velikost = statbuf.st_size)");
+ r = 4;
+ goto r;
+ }
+ if (!(ebs.pm = mmap(NULL, ebs.pm_velikost, PROT_READ, MAP_SHARED, pfd, 0))) {
+ error_at_line(0, errno, __FILE__, __LINE__, "!mmap(NULL, ebs.pm_velikost, PROT_READ, MAP_SHARED, pfd, 0)");
+ r = 5;
+ goto r;
+ }
+ for (unsigned i = 0; i <= 0xffff; i++) {
+ struct inštrukcija š = inštrukcija(&ebs, i);
+ printf("0x%04x\t%s\t0x%02x\t0x%02x\t0x%02x%02x\n", i, operacija_str[š.operacija], š.vir, š.destinacija, š.dobesedno[0], š.dobesedno[1]);
+ }
+ r:
+ if (ebs.pm && munmap(ebs.pm, ebs.pm_velikost) == -1)
+ error_at_line(0, errno, __FILE__, __LINE__, "munmap(ebs.pm, ebs.pm_velikost)");
+ close(pfd);
+ pfd = -1;
+ return r;
+}