07-20-09-New-Syscalls

From Msim

Jump to: navigation, search

Contents

OSF_SYS_getgroups

This syscall was already defined but not implemented (Syscall: 79).

case OSF_SYS_getgroups:
 {
  int num_groups = regs->regs_R[MD_REG_A0];
  long long max_groups(num_groups);
  if(max_groups==0)
  {
   max_groups = sysconf(_SC_NGROUPS_MAX) + 1;
  }
  gid_t *groups = new gid_t[max_groups];
  
  check_error = true;
  
  regs->regs_R[MD_REG_V0] = getgroups(max_groups,groups);
  mem_bcopy(mem_fn, mem, Write, regs->regs_R[MD_REG_A1], groups, max_groups*sizeof(gid_t));
  delete [] groups;
 }
 break;

OSF_SYS_mkdir

This syscall was already defined but not implemented (Syscall: 136).

case OSF_SYS_mkdir:
{
 char name[MAXBUFSIZE];
 int mode;
 
 //copy dirname to name. get mode
 mem_strcpy(mem_fn, mem, Read, regs->regs_R[MD_REG_A0], name);
 mode = regs->regs_R[MD_REG_A1];
 
 check_error = true;
 regs->regs_R[MD_REG_V0] = mkdir(name,mode);
}
break;

OSF_SYS_readlink

This syscall was already defined but not implemented (Syscall: 58).

       case OSF_SYS_readlink:
               {
                       char buf[MAXBUFSIZE];
                       int buf_size = regs->regs_R[MD_REG_A2];
                       char read_file[buf_size];

                       //copy filename to host memory
                       mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
                       regs->regs_R[MD_REG_V0] = readlink(buf,read_file,buf_size);

                       check_error = true;
               }
               break;

OSF_SYS_kill

This syscall is largely a stub, we return a success but really don't do anything.

       case OSF_SYS_kill:
               static int first(false);
               if(!first)
               {
                       warn("OSF_SYS_kill is unsupported, returning success");
                       first = !first;
               }
               regs->regs_R[MD_REG_V0] =  0;
               check_error = true;
               break;


OSF_SYS_ioctl

ioctl requests

The ioctl requests are now constructed from the same method used on an alpha machine (rather than just using the translated value).
Original Definitions:

#define OSF_TIOCGETP            0x40067408
#define OSF_FIONREAD            0x4004667f

Now:

#define OSF_IOCPARM_MASK                0x1fff
#define OSF_IOC_VOID                    0x20000000
#define OSF_IOC_OUT                     0x40000000
#define OSF_IOC_IN                      0x80000000
#define OSF_IOC(inout,group,num,len)    (inout | ((len & OSF_IOCPARM_MASK) << 16) | ((group) << 8) | (num))
#define OSF_IO(g,n)                     OSF_IOC(OSF_IOC_VOID,   (g),    (n), 0)
#define OSF_IOR(g,n,t)                  OSF_IOC(OSF_IOC_OUT,    (g),    (n), sizeof(t))
#define OSF_IOW(g,n,t)                  OSF_IOC(OSF_IOC_IN,     (g),    (n), sizeof(t))
#define OSF_TIOCGETP                    OSF_IOR('t', 8, struct sgttyb)                  //get parameters -- gtty        (0x40067408)
#define OSF_FIONREAD                    OSF_IOR('f', 127, int)                          //get number of bytes to read   (0x4004667f)
#define OSF_TIOCISATTY                  OSF_IO('t', 94)                                 //is this a tty?                (0x2000745e)
#define OSF_TIOCGWINSZ                  OSF_IOR('t' , 104, struct osf_winsize)          //get window size               (0x40087468)

ioctl(TIOCISATTY)

Code from syscall.c, OSF_SYS_ioctl:

                       case OSF_TIOCISATTY:
                               check_error = true;
                               regs->regs_R[MD_REG_V0] = isatty(regs->regs_R[MD_REG_A0]);
                               break;

ioctl(TIOCGWINSZ)

Support for winsize: ioctl(TIOCGWINSZ):
Data Structure: //struct winsize for ioctl(TIOCGWINSZ,...)

struct osf_winsize
{
       unsigned short  ws_row;                 //rows, in characters
       unsigned short  ws_col;                 //columns, in characters
       unsigned short  ws_xpixel;              //horizontal size, pixels
       unsigned short  ws_ypixel;              //vertical size, pixels
};

Code from syscall.c, OSF_SYS_ioctl:

                       case OSF_TIOCGWINSZ:
                               osf_winsize buf;
                               regs->regs_R[MD_REG_V0] = ioctl(/* fd */(int)regs->regs_R[MD_REG_A0],/*req*/TIOCGWINSZ, &buf);
                               mem_bcopy(mem_fn, mem, Write, /* buf */regs->regs_R[MD_REG_A2], &buf, sizeof(osf_winsize));
                               check_error = true;
                               break;
Personal tools