about summary refs log tree commit diff stats
path: root/subx/019functions.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-08-03 23:42:20 -0700
committerKartik Agaram <vc@akkartik.com>2018-08-03 23:42:37 -0700
commita066ad7ed7a64ff204d9381d701cc94e83d42f79 (patch)
treee5258558e6038b6321c468dc145e33c92cb78646 /subx/019functions.cc
parent96a09ee9f9017294313cfb6daf04864ace78ba75 (diff)
downloadmu-a066ad7ed7a64ff204d9381d701cc94e83d42f79.tar.gz
4469
Diffstat (limited to 'subx/019functions.cc')
-rw-r--r--subx/019functions.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/subx/019functions.cc b/subx/019functions.cc
new file mode 100644
index 00000000..964ca977
--- /dev/null
+++ b/subx/019functions.cc
@@ -0,0 +1,90 @@
+//:: call
+
+:(before "End Initialize Op Names(name)")
+put(name, "e8", "call disp32");
+
+:(scenario call_disp32)
+% Reg[ESP].u = 0x64;
+== 0x1
+# op  ModR/M  SIB   displacement  immediate
+  e8                              a0 00 00 00  # call function offset at 0x000000a0
+  # next EIP is 6
++run: call imm32 0x000000a0
++run: decrementing ESP to 0x00000060
++run: pushing value 0x00000006
++run: jumping to 0x000000a6
+
+:(before "End Single-Byte Opcodes")
+case 0xe8: {  // call disp32 relative to next EIP
+  int32_t offset = imm32();
+  trace(90, "run") << "call imm32 0x" << HEXWORD << offset << end();
+//?   cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';
+  push(EIP);
+  EIP += offset;
+  trace(90, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+  break;
+}
+
+//:
+
+:(scenario call_r32)
+% Reg[ESP].u = 0x64;
+% Reg[EBX].u = 0x000000a0;
+== 0x1
+# op  ModR/M  SIB   displacement  immediate
+  ff  d3                                       # call function offset at EBX
+  # next EIP is 3
++run: call to r/m32
++run: r/m32 is EBX
++run: decrementing ESP to 0x00000060
++run: pushing value 0x00000003
++run: jumping to 0x000000a3
+
+:(before "End Op ff Subops")
+case 2: {  // call function pointer at r/m32
+  trace(90, "run") << "call to r/m32" << end();
+  int32_t* offset = effective_address(modrm);
+  push(EIP);
+  EIP += *offset;
+  trace(90, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+  break;
+}
+
+:(scenario call_mem_at_r32)
+% Reg[ESP].u = 0x64;
+% Reg[EBX].u = 0x10;
+== 0x1  # code segment
+# op  ModR/M  SIB   displacement  immediate
+  ff  13                                       # call function offset at *EBX
+  # next EIP is 3
+== 0x10  # data segment
+a0 00 00 00  # 0xa0
++run: call to r/m32
++run: effective address is 0x10 (EBX)
++run: decrementing ESP to 0x00000060
++run: pushing value 0x00000003
++run: jumping to 0x000000a3
+
+//:: ret
+
+:(before "End Initialize Op Names(name)")
+put(name, "c3", "return from most recent unfinished call");
+
+:(scenario ret)
+% Reg[ESP].u = 0x60;
+== 0x1  # code segment
+# op  ModR/M  SIB   displacement  immediate
+  c3
+== 0x60  # data segment
+10 00 00 00  # 0x10
++run: return
++run: popping value 0x00000010
++run: jumping to 0x00000010
+
+:(before "End Single-Byte Opcodes")
+case 0xc3: {  // return from a call
+  trace(90, "run") << "return" << end();
+  EIP = pop();
+  trace(90, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+  break;
+}