On 10/18/2013 10:46 AM, Christian Menard wrote:
a while ago I wrote some code implementing x86s 'int' and 'int3' instructions
(review request: http://reviews.gem5.org/r/1939/). These instructions are used
to trigger software interrupts.
This feature is used by many operating systems to trigger system calls. Of
course amd64 introduced the new syscall instruction which does things faster.
But it is not always so easy to port your os to use this instruction. So in my
opinion not supporting 'int' and 'int3' is a big problem and prevents gem5
from supporting other OSes than Linux (In my case it's Fiasco.OC
http://os.inf.tu-dresden.de/fiasco/)

In the meantime I rewrote the instruction implementation. It now jumps to the
interrupt handling code in 'arch/x86/isa/insts/romutil.py' which is already
used for hardware interrupts. But my Problem is to actual call this code. In
the Decoder (x86/isa/decoder/one_byte_opcodes.isa) you can find this:

0x5: decode FullSystemInt default int_Ib() {
              0: decode IMMEDIATE {
                      // Really only the LSB matters, but the decoder
                      // will sign extend it, and there's no easy way to
                      // specify only checking the first byte.
                      0xffffffffffffff80:
                              SyscallInst::int80('xc->syscall(Rax)',
                                      IsSyscall, IsNonSpeculative,
IsSerializeAfter);
                      }
              }
As far as I understand it, it checks whether 'int 80' is used. 'int 80'
triggers a system call in Linux. So it checks for a system call and calls a
handling routine. I think this is only needed in system emulation mode. Is
this correct?

If I understand this correctly, it first checks the state of the FullSystemInt, and only if it is 0, it calls the syscall emulation code. You should see an unimplemented instruction warning in FS mode.

I'm not an expert in the ISA parser, but I think the correct way to modify the parser in you patch would be something along these lines:

0x5: decode FullSystemInt default int_Ib() {
  0: decode IMMEDIATE {
    0xffffffffffffff80:
      SyscallInst::int80('xc->syscall(Rax)',
        IsSyscall, IsNonSpeculative, IsSerializeAfter);
  }

  default: Inst::INT(Ib);
}

The FullSystemInt is 0 in SE mode and 1 in FS mode, so this should work in both modes.

The macroop should then be defined as follows:

def macroop INT_I
{
    limm foo, imm
    ...
};

The immediate should automatically be byte-sized due to the Inst::INT(Ib) call.

Try the above and update your review request. Ping me directly if I forget to look at the review request after you update it.

//Andreas

_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to