about summary refs log tree commit diff stats
path: root/subx/019syscalls.cc
blob: 4e6d58883dc5ed895a69f77b2d27b775f725a816 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
:(before "End Initialize Op Names(name)")
put(name, "cd", "software interrupt");

:(before "End Single-Byte Opcodes")
case 0xcd: {  // int imm8 (software interrupt)
  trace(90, "run") << "syscall" << end();
  uint8_t code = next();
  if (code != 0x80) {
    raise << "Unimplemented interrupt code " << HEXBYTE << code << '\n' << end();
    raise << "  Only `int 80h` supported for now.\n" << end();
    break;
  }
  process_int80();
  break;
}

:(code)
void process_int80() {
  switch (Reg[EAX].u) {
  case 1:
    exit(/*exit code*/Reg[EBX].u);
    break;
  case 3:
    Reg[EAX].i = read(/*file descriptor*/Reg[EBX].u, /*memory buffer*/mem_addr_u8(Reg[ECX].u), /*size*/Reg[EDX].u);
    break;
  case 4:
    Reg[EAX].i = write(/*file descriptor*/Reg[EBX].u, /*memory buffer*/mem_addr_u8(Reg[ECX].u), /*size*/Reg[EDX].u);
    break;
  default:
    raise << HEXWORD << EIP << ": unimplemented syscall " << Reg[EAX].u << '\n' << end();
  }
}

:(before "End Includes")
#include <unistd.h>
ass="p">></td><td>&nbsp;</td> <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="ranger.ext.accumulator.html">accumulator</a><br> <a href="ranger.ext.debug.html">debug</a><br> </td><td width="25%" valign=top><a href="ranger.ext.get_all_modules.html">get_all_modules</a><br> <a href="ranger.ext.human_readable.html">human_readable</a><br> </td><td width="25%" valign=top><a href="ranger.ext.openstruct.html">openstruct</a><br> <a href="ranger.ext.relpath.html">relpath</a><br> </td><td width="25%" valign=top><a href="ranger.ext.shutil_generatorized.html">shutil_generatorized</a><br> <a href="ranger.ext.waitpid_no_intr.html">waitpid_no_intr</a><br> </td></tr></table></td></tr></table> </body></html>