From 292ccba1bbdc8c2ec6cfacefa15f19c8d215b58c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 18 Oct 2017 03:11:56 -0700 Subject: 4085 - done with first cut of the SubX VM subx: 'call' and 'return' instructions --- html/subx/016functions.cc.html | 143 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 html/subx/016functions.cc.html (limited to 'html/subx/016functions.cc.html') diff --git a/html/subx/016functions.cc.html b/html/subx/016functions.cc.html new file mode 100644 index 00000000..ee7a2311 --- /dev/null +++ b/html/subx/016functions.cc.html @@ -0,0 +1,143 @@ + + + + +Mu - subx/016functions.cc + + + + + + + + + + +
+ 1 //:: call
+ 2 
+ 3 :(scenario call_imm32)
+ 4 % Reg[ESP].u = 0x64;
+ 5 # op  ModRM   SIB   displacement  immediate
+ 6   e8                              a0 00 00 00  # call function offset at 0x000000a0
+ 7   # next EIP is 6
+ 8 +run: call imm32 0x000000a0
+ 9 +run: decrementing ESP to 0x00000060
+10 +run: pushing value 0x00000006
+11 +run: jumping to 0x000000a6
+12 
+13 :(before "End Single-Byte Opcodes")
+14 case 0xe8: {  // call imm32 relative to next EIP
+15   int32_t offset = imm32();
+16   trace(2, "run") << "call imm32 0x" << HEXWORD << offset << end();
+17   push(EIP);
+18   EIP += offset;
+19   trace(2, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+20   break;
+21 }
+22 
+23 //:
+24 
+25 :(scenario call_r32)
+26 % Reg[ESP].u = 0x64;
+27 % Reg[EBX].u = 0x000000a0;
+28 # op  ModRM   SIB   displacement  immediate
+29   ff  d3                                       # call function offset at EBX (reg 3)
+30   # next EIP is 3
+31 +run: call to effective address
+32 +run: effective address is reg 3
+33 +run: decrementing ESP to 0x00000060
+34 +run: pushing value 0x00000003
+35 +run: jumping to 0x000000a3
+36 
+37 :(before "End Op ff Subops")
+38 case 2: {  // call function pointer at r/m32
+39   trace(2, "run") << "call to effective address" << end();
+40   int32_t* offset = effective_address(modrm);
+41   push(EIP);
+42   EIP += *offset;
+43   trace(2, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+44   break;
+45 }
+46 
+47 :(scenario call_mem_at_r32)
+48 % Reg[ESP].u = 0x64;
+49 % Reg[EBX].u = 0x10;
+50 % SET_WORD_IN_MEM(0x10, 0x000000a0);
+51 # op  ModRM   SIB   displacement  immediate
+52   ff  13                                       # call function offset at *EBX (reg 3)
+53   # next EIP is 3
+54 +run: call to effective address
+55 +run: effective address is mem at address 0x10 (reg 3)
+56 +run: decrementing ESP to 0x00000060
+57 +run: pushing value 0x00000003
+58 +run: jumping to 0x000000a3
+59 
+60 //:: ret
+61 
+62 :(scenario ret)
+63 % Reg[ESP].u = 0x60;
+64 % SET_WORD_IN_MEM(0x60, 0x00000010);
+65 # op  ModRM   SIB   displacement  immediate
+66   c3
+67 +run: return
+68 +run: popping value 0x00000010
+69 +run: jumping to 0x00000010
+70 
+71 :(before "End Single-Byte Opcodes")
+72 case 0xc3: {  // return from a call
+73   trace(2, "run") << "return" << end();
+74   EIP = pop();
+75   trace(2, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+76   break;
+77 }
+
+ + + -- cgit 1.4.1-2-gfad0