about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-08 22:47:30 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-08 22:48:47 -0700
commit6b36e4dbc7749addeebe523992e0bcb62ad6b2d5 (patch)
treee041a9099e170c84c23a352d92fcf8efd536d788
parentd9a05dfbb7ac73b31b1f3c1fb36a5324243da8a2 (diff)
downloadmu-6b36e4dbc7749addeebe523992e0bcb62ad6b2d5.tar.gz
6760
Fix a couple of subtle bugs.

- the VM was conditionally reading from the instruction stream, so that
  other bugs got masked by decoding errors.
- push-n-bytes was clobbering eax.
-rw-r--r--014indirect_addressing.cc9
-rw-r--r--302stack_allocate.subx13
-rwxr-xr-xapps/mubin388957 -> 388971 bytes
3 files changed, 13 insertions, 9 deletions
diff --git a/014indirect_addressing.cc b/014indirect_addressing.cc
index 19d4d509..fa679d6f 100644
--- a/014indirect_addressing.cc
+++ b/014indirect_addressing.cc
@@ -936,7 +936,7 @@ void test_add_r32_to_mem_at_r32_plus_disp32() {
 }
 
 :(before "End Mod Special-cases(addr)")
-case 2:  // indirect + disp32 addressing
+case 2: {  // indirect + disp32 addressing
   switch (rm) {
   default:
     addr = Reg[rm].u;
@@ -944,11 +944,16 @@ case 2:  // indirect + disp32 addressing
     break;
   // End Mod 2 Special-cases(addr)
   }
+  int32_t displacement = static_cast<int32_t>(next32());
   if (addr > 0) {
-    addr += next32();
+    addr += displacement;
     trace(Callstack_depth+1, "run") << "effective address is 0x" << HEXWORD << addr << " (after adding disp32)" << end();
   }
+  else {
+    trace(Callstack_depth+1, "run") << "null address; skipping displacement" << end();
+  }
   break;
+}
 
 :(code)
 void test_add_r32_to_mem_at_r32_plus_negative_disp32() {
diff --git a/302stack_allocate.subx b/302stack_allocate.subx
index 02ad84f2..4634039d 100644
--- a/302stack_allocate.subx
+++ b/302stack_allocate.subx
@@ -37,15 +37,12 @@ $push-n-zero-bytes:prologue:
     89/<- %ebp 4/r32/esp
 $push-n-zero-bytes:copy-ra:
     # -- esp = ebp
-    50/push-eax
-    # -- esp+8 = ebp+4
-    # -- esp+4 = ebp
-    8b/-> *(esp+4) 0/r32/eax
+    89/<- *Push-n-zero-bytes-eax 0/r32/eax
+    8b/-> *esp 0/r32/eax
     2b/subtract *(ebp+4) 4/r32/esp
-    # -- esp+4+n = ebp
-    89/<- *(esp+4) 0/r32/eax
-    58/pop-to-eax
     # -- esp+n = ebp
+    89/<- *esp 0/r32/eax
+    8b/-> *Push-n-zero-bytes-eax 0/r32/eax
 $push-n-zero-bytes:bulk-cleaning:
     89/<- *Push-n-zero-bytes-esp 4/r32/esp
     81 0/subop/add *Push-n-zero-bytes-esp 4/imm32
@@ -60,3 +57,5 @@ Push-n-zero-bytes-ebp:  # (addr int)
   0/imm32
 Push-n-zero-bytes-esp:  # (addr int)
   0/imm32
+Push-n-zero-bytes-eax:
+  0/imm32
diff --git a/apps/mu b/apps/mu
index 2cf5d31c..0a95526a 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differ
ef='#n236'>236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290