From 9c1056f531217f3c1c12b3b3a648ca1cffe4beab Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 29 Mar 2019 00:47:30 -0700 Subject: 5033 --- html/subx/019functions.cc.html | 212 +++++++++++++++++++++++------------------ 1 file changed, 117 insertions(+), 95 deletions(-) (limited to 'html/subx/019functions.cc.html') diff --git a/html/subx/019functions.cc.html b/html/subx/019functions.cc.html index 4008c175..0ad5ce43 100644 --- a/html/subx/019functions.cc.html +++ b/html/subx/019functions.cc.html @@ -15,8 +15,6 @@ body { font-size:12pt; font-family: monospace; color: #000000; background-color: a { color:inherit; } * { font-size:12pt; font-size: 1em; } .CommentedCode { color: #8a8a8a; } -.traceContains { color: #005f00; } -.PreProc { color: #c000c0; } .LineNr { } .Constant { color: #008787; } .Delimiter { color: #c000c0; } @@ -60,99 +58,123 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/master/subx/019functions.cc
- 1 //:: call
- 2 
- 3 :(before "End Initialize Op Names")
- 4 put_new(Name, "e8", "call disp32 (call)");
- 5 
- 6 :(scenario call_disp32)
- 7 % Reg[ESP].u = 0x64;
- 8 == 0x1
- 9 # op  ModR/M  SIB   displacement  immediate
-10   e8                              a0 00 00 00  # call function offset at 0x000000a0
-11   # next EIP is 6
-12 +run: call imm32 0x000000a0
-13 +run: decrementing ESP to 0x00000060
-14 +run: pushing value 0x00000006
-15 +run: jumping to 0x000000a6
-16 
-17 :(before "End Single-Byte Opcodes")
-18 case 0xe8: {  // call disp32 relative to next EIP
-19   const int32_t offset = next32();
-20   ++Callstack_depth;
-21   trace(Callstack_depth+1, "run") << "call imm32 0x" << HEXWORD << offset << end();
-22 //?   cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';
-23   push(EIP);
-24   EIP += offset;
-25   trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
-26   break;
-27 }
-28 
-29 //:
-30 
-31 :(scenario call_r32)
-32 % Reg[ESP].u = 0x64;
-33 % Reg[EBX].u = 0x000000a0;
-34 == 0x1
-35 # op  ModR/M  SIB   displacement  immediate
-36   ff  d3                                       # call function offset at EBX
-37   # next EIP is 3
-38 +run: call to r/m32
-39 +run: r/m32 is EBX
-40 +run: decrementing ESP to 0x00000060
-41 +run: pushing value 0x00000003
-42 +run: jumping to 0x000000a3
-43 
-44 :(before "End Op ff Subops")
-45 case 2: {  // call function pointer at r/m32
-46   trace(Callstack_depth+1, "run") << "call to r/m32" << end();
-47   const int32_t* offset = effective_address(modrm);
-48   push(EIP);
-49   EIP += *offset;
-50   trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
-51   ++Callstack_depth;
-52   break;
-53 }
-54 
-55 :(scenario call_mem_at_r32)
-56 % Reg[ESP].u = 0x64;
-57 % Reg[EBX].u = 0x2000;
-58 == 0x1  # code segment
-59 # op  ModR/M  SIB   displacement  immediate
-60   ff  13                                       # call function offset at *EBX
-61   # next EIP is 3
-62 == 0x2000  # data segment
-63 a0 00 00 00  # 0xa0
-64 +run: call to r/m32
-65 +run: effective address is 0x00002000 (EBX)
-66 +run: decrementing ESP to 0x00000060
-67 +run: pushing value 0x00000003
-68 +run: jumping to 0x000000a3
-69 
-70 //:: ret
-71 
-72 :(before "End Initialize Op Names")
-73 put_new(Name, "c3", "return from most recent unfinished call (ret)");
-74 
-75 :(scenario ret)
-76 % Reg[ESP].u = 0x2000;
-77 == 0x1  # code segment
-78 # op  ModR/M  SIB   displacement  immediate
-79   c3
-80 == 0x2000  # data segment
-81 10 00 00 00  # 0x10
-82 +run: return
-83 +run: popping value 0x00000010
-84 +run: jumping to 0x00000010
-85 
-86 :(before "End Single-Byte Opcodes")
-87 case 0xc3: {  // return from a call
-88   trace(Callstack_depth+1, "run") << "return" << end();
-89   --Callstack_depth;
-90   EIP = pop();
-91   trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
-92   break;
-93 }
+  1 //:: call
+  2 
+  3 :(before "End Initialize Op Names")
+  4 put_new(Name, "e8", "call disp32 (call)");
+  5 
+  6 :(code)
+  7 void test_call_disp32() {
+  8   Reg[ESP].u = 0x64;
+  9   run(
+ 10       "== 0x1\n"  // code segment
+ 11       // op     ModR/M  SIB   displacement  immediate
+ 12       "  e8                                 a0 00 00 00 \n"  // call function offset at 0x000000a0
+ 13       // next EIP is 6
+ 14   );
+ 15   CHECK_TRACE_CONTENTS(
+ 16       "run: call imm32 0x000000a0\n"
+ 17       "run: decrementing ESP to 0x00000060\n"
+ 18       "run: pushing value 0x00000006\n"
+ 19       "run: jumping to 0x000000a6\n"
+ 20   );
+ 21 }
+ 22 
+ 23 :(before "End Single-Byte Opcodes")
+ 24 case 0xe8: {  // call disp32 relative to next EIP
+ 25   const int32_t offset = next32();
+ 26   ++Callstack_depth;
+ 27   trace(Callstack_depth+1, "run") << "call imm32 0x" << HEXWORD << offset << end();
+ 28 //?   cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';
+ 29   push(EIP);
+ 30   EIP += offset;
+ 31   trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+ 32   break;
+ 33 }
+ 34 
+ 35 //:
+ 36 
+ 37 :(code)
+ 38 void test_call_r32() {
+ 39   Reg[ESP].u = 0x64;
+ 40   Reg[EBX].u = 0x000000a0;
+ 41   run(
+ 42       "== 0x1\n"  // code segment
+ 43       // op     ModR/M  SIB   displacement  immediate
+ 44       "  ff     d3                                      \n"  // call function offset at EBX
+ 45       // next EIP is 3
+ 46   );
+ 47   CHECK_TRACE_CONTENTS(
+ 48       "run: call to r/m32\n"
+ 49       "run: r/m32 is EBX\n"
+ 50       "run: decrementing ESP to 0x00000060\n"
+ 51       "run: pushing value 0x00000003\n"
+ 52       "run: jumping to 0x000000a3\n"
+ 53   );
+ 54 }
+ 55 
+ 56 :(before "End Op ff Subops")
+ 57 case 2: {  // call function pointer at r/m32
+ 58   trace(Callstack_depth+1, "run") << "call to r/m32" << end();
+ 59   const int32_t* offset = effective_address(modrm);
+ 60   push(EIP);
+ 61   EIP += *offset;
+ 62   trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+ 63   ++Callstack_depth;
+ 64   break;
+ 65 }
+ 66 
+ 67 :(code)
+ 68 void test_call_mem_at_r32() {
+ 69   Reg[ESP].u = 0x64;
+ 70   Reg[EBX].u = 0x2000;
+ 71   run(
+ 72       "== 0x1\n"  // code segment
+ 73       // op     ModR/M  SIB   displacement  immediate
+ 74       "  ff     13                                      \n"  // call function offset at *EBX
+ 75       // next EIP is 3
+ 76       "== 0x2000\n"  // data segment
+ 77       "a0 00 00 00\n"  // 0x000000a0
+ 78   );
+ 79   CHECK_TRACE_CONTENTS(
+ 80       "run: call to r/m32\n"
+ 81       "run: effective address is 0x00002000 (EBX)\n"
+ 82       "run: decrementing ESP to 0x00000060\n"
+ 83       "run: pushing value 0x00000003\n"
+ 84       "run: jumping to 0x000000a3\n"
+ 85   );
+ 86 }
+ 87 
+ 88 //:: ret
+ 89 
+ 90 :(before "End Initialize Op Names")
+ 91 put_new(Name, "c3", "return from most recent unfinished call (ret)");
+ 92 
+ 93 :(code)
+ 94 void test_ret() {
+ 95   Reg[ESP].u = 0x2000;
+ 96   run(
+ 97       "== 0x1\n"  // code segment
+ 98       // op     ModR/M  SIB   displacement  immediate
+ 99       "  c3                                           \n"  // return
+100       "== 0x2000\n"  // data segment
+101       "10 00 00 00\n"  // 0x00000010
+102   );
+103   CHECK_TRACE_CONTENTS(
+104       "run: return\n"
+105       "run: popping value 0x00000010\n"
+106       "run: jumping to 0x00000010\n"
+107   );
+108 }
+109 
+110 :(before "End Single-Byte Opcodes")
+111 case 0xc3: {  // return from a call
+112   trace(Callstack_depth+1, "run") << "return" << end();
+113   --Callstack_depth;
+114   EIP = pop();
+115   trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
+116   break;
+117 }
 
-- cgit 1.4.1-2-gfad0