about summary refs log tree commit diff stats
path: root/filesystem.mu
Commit message (Collapse)AuthorAgeFilesLines
* 3483Kartik K. Agaram2016-10-081-1/+1
|
* 3389Kartik K. Agaram2016-09-171-2/+2
|
* 3380Kartik K. Agaram2016-09-171-1/+1
| | | | | One more place we were missing expanding type abbreviations: inside container definitions.
* 3379Kartik K. Agaram2016-09-171-3/+3
| | | | Can't use type abbreviations inside 'memory-should-contain'.
* 3238Kartik K. Agaram2016-08-211-2/+0
| | | | | | Clean up primitive for reading from file. Never return EOF character. Stop using null character to indicate EOF as well. Instead, always use a second product to indicate EOF, and require calls to use it.
* 3225 - testable interface for writing filesKartik K. Agaram2016-08-181-9/+15
| | | | | | | | For example usage of file operations, see filesystem.mu. Is it ugly that we don't actually write to disk unless we wait for the writing routine to exit? Maybe there's a nice way to wrap it. At any rate, all buffering is explicit, which seems a win compared to *nix.
* 3224Kartik K. Agaram2016-08-181-3/+3
|
* 3203 - testable interface for reading a fileKartik K. Agaram2016-08-161-0/+16
This commit was written by Stephen Malina. Thanks also to Stephen for running into the bug of commit 3202.
highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
//:: call

:(before "End Initialize Op Names")
put_new(Name, "e8", "call disp32 (call)");

:(code)
void test_call_disp32() {
  Mem.push_back(vma(0xbd000000));  // manually allocate memory
  Reg[ESP].u = 0xbd000064;
  run(
      "== code 0x1\n"
      // op     ModR/M  SIB   displacement  immediate
      "  e8                                 a0 00 00 00 \n"  // call function offset at 0xa0
      // next EIP is 6
  );
  CHECK_TRACE_CONTENTS(
      "run: call imm32 0x000000a0\n"
      "run: decrementing ESP to 0xbd000060\n"
      "run: pushing value 0x00000006\n"
      "run: jumping to 0x000000a6\n"
  );
}

:(before "End Single-Byte Opcodes")
case 0xe8: {  // call disp32 relative to next EIP
  const int32_t offset = next32();
  ++Callstack_depth;
  trace(Callstack_depth+1, "run") << "call imm32 0x" << HEXWORD << offset << end();
//?   cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';
  push(EIP);
  EIP += offset;
  trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
  break;
}

//:

:(code)
void test_call_r32() {
  Mem.push_back(vma(0xbd000000));  // manually allocate memory
  Reg[ESP].u = 0xbd000064;
  Reg[EBX].u = 0x000000a0;
  run(
      "== code 0x1\n"
      // op     ModR/M  SIB   displacement  immediate
      "  ff     d3                                      \n"  // call function offset at EBX
      // next EIP is 3
  );
  CHECK_TRACE_CONTENTS(
      "run: call to r/m32\n"
      "run: r/m32 is EBX\n"
      "run: decrementing ESP to 0xbd000060\n"
      "run: pushing value 0x00000003\n"
      "run: jumping to 0x000000a0\n"
  );
}

:(before "End Op ff Subops")
case 2: {  // call function pointer at r/m32
  trace(Callstack_depth+1, "run") << "call to r/m32" << end();
  const int32_t* offset = effective_address(modrm);
  push(EIP);
  EIP = *offset;
  trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
  ++Callstack_depth;
  break;
}

:(code)
void test_call_mem_at_rm32() {
  Mem.push_back(vma(0xbd000000));  // manually allocate memory
  Reg[ESP].u = 0xbd000064;
  Reg[EBX].u = 0x2000;
  run(
      "== code 0x1\n"
      // op     ModR/M  SIB   displacement  immediate
      "  ff     13                                      \n"  // call function offset at *EBX
      // next EIP is 3
      "== data 0x2000\n"
      "a0 00 00 00\n"  // 0xa0
  );
  CHECK_TRACE_CONTENTS(
      "run: call to r/m32\n"
      "run: effective address is 0x00002000 (EBX)\n"
      "run: decrementing ESP to 0xbd000060\n"
      "run: pushing value 0x00000003\n"
      "run: jumping to 0x000000a0\n"
  );
}

//:: ret

:(before "End Initialize Op Names")
put_new(Name, "c3", "return from most recent unfinished call (ret)");

:(code)
void test_ret() {
  Mem.push_back(vma(0xbd000000));  // manually allocate memory
  Reg[ESP].u = 0xbd000064;
  write_mem_u32(Reg[ESP].u, 0x10);
  run(
      "== code 0x1\n"
      // op     ModR/M  SIB   displacement  immediate
      "  c3                                           \n"  // return
      "== data 0x2000\n"
      "10 00 00 00\n"  // 0x10
  );
  CHECK_TRACE_CONTENTS(
      "run: return\n"
      "run: popping value 0x00000010\n"
      "run: jumping to 0x00000010\n"
  );
}

:(before "End Single-Byte Opcodes")
case 0xc3: {  // return from a call
  trace(Callstack_depth+1, "run") << "return" << end();
  --Callstack_depth;
  EIP = pop();
  trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
  break;
}