Main Page   Compound List   File List   Compound Members   File Members  

system.c

Go to the documentation of this file.
00001 /*
00002  Copyright (c) 1992-1993 The Regents of the University of California.
00003  All rights reserved.  See copyright.h for copyright notice and limitation 
00004  of liability and disclaimer of warranty provisions.
00005  */
00006 
00007 #include "copyright.h"
00008 #include <stdio.h>
00009 #include <syscall.h>
00010 #include "int.h"
00011 
00012 extern int Reg[];
00013 extern char mem[];
00014 extern int Traptrace;
00015 
00016 char *u_to_int_addr();
00017 
00018 /* handle system calls */
00019 system_break()
00020 {
00021         if  ( Traptrace )
00022                 printf("**breakpoint ");
00023         system_trap();
00024 }
00025 
00026 system_trap()
00027 {
00028         int o0, o1, o2;         /* user out register values */
00029         int syscallno;
00030         extern long lseek();
00031 
00032         if  ( Traptrace )
00033         {
00034                 printf("**System call %d\n", Reg[2]);
00035                 dump_reg();
00036         }
00037 
00038 /*      if (Reg[1] == 0)
00039 /*      {                       /* SYS_indir */
00040 /*              syscallno = Reg[8];     /* out reg 0 */
00041 /*              o0 = Reg[9];
00042 /*              o1 = Reg[10];
00043 /*              o2 = Reg[11];
00044 /*      }
00045 /*      else    /* */
00046         {
00047                 syscallno = Reg[2];
00048                 o0 = Reg[4];
00049                 o1 = Reg[5];
00050                 o2 = Reg[6];
00051         }
00052 
00053         switch (syscallno)
00054         {
00055                 case SYS_exit:  /*1*/
00056                         printstatistics();
00057                         fflush(stdout);
00058                         exit(0);
00059                         break;
00060                 case SYS_read:  /*3*/
00061                         Reg[1] = 
00062                                 read(u_to_int_fd(o0), u_to_int_addr(o1), o2);
00063                         break;
00064                 case SYS_write: /*4*/
00065                         Reg[1] = 
00066                                 write(u_to_int_fd(o0), u_to_int_addr(o1), o2);
00067                         break;
00068 
00069                 case SYS_open:  /*5*/
00070                         Reg[1] = open(u_to_int_addr(o0), o1, o2); /* */
00071                         break;
00072 
00073                 case SYS_close: /*6*/
00074                         Reg[1] = 0;     /* hack */
00075                         break;
00076 
00077                 case 17:        /* 17 */
00078                         /* old sbreak. where did it go? */
00079                         Reg[1] = ((o0 / 8192) + 1) * 8192;
00080                         break;
00081 
00082                 case SYS_lseek: /*19*/
00083                         Reg[1] = (int) lseek(u_to_int_fd(o0), (long) o1, o2);
00084                         break;
00085 
00086                 case SYS_ioctl:/* 54 */
00087                         {       /* copied from sas -- I don't understand yet. */
00088                                 /* see dave weaver */
00089 #define IOCPARM_MASK    0x7f    /* parameters must be < 128 bytes */
00090                                 int size = (o1 >> 16) & IOCPARM_MASK;
00091                                 char ioctl_group = (o1 >> 8) & 0x00ff;
00092                                 if ((ioctl_group == 't') && (size == 8))
00093                                 {
00094                                         size = 6;
00095                                         o1 = (o1 & ~((IOCPARM_MASK << 16))) 
00096                                            | (size << 16);
00097                                 }
00098                         }
00099                         Reg[1] = ioctl(u_to_int_fd(o0),o1,u_to_int_addr(o2));
00100                         Reg[1] = 0;     /* hack */
00101                         break;
00102 
00103                 case SYS_fstat:         /* 62 */
00104                         Reg[1] = fstat(o1, o2);
00105                         break;
00106 
00107                 case SYS_getpagesize:   /* 64 */
00108                         Reg[1] = getpagesize();
00109                         break;
00110 
00111                 default:
00112                         printf("Unknown System call %d\n", syscallno);
00113                         if  ( ! Traptrace )
00114                                 dump_reg();
00115                         exit(2);
00116                         break;
00117         }
00118         if  ( Traptrace )
00119         {
00120                 printf("**Afterwards:\n");
00121                 dump_reg();
00122         }
00123 }
00124 
00125 char *u_to_int_addr(ptr)
00126 int ptr;
00127 {       /* convert a user pointer to the real address   */
00128         /* used in the interpreter                      */
00129 
00130          return ((char *) ((int) mem - memoffset  + ptr));
00131 }
00132 
00133 u_to_int_fd(fd)
00134 {
00135         if (fd > 2)
00136         {
00137                 /*
00138                 printf("No general file descriptors yet\n");
00139                 exit(2);
00140                 */
00141         }
00142         return (fd);            /* assume we can handle it for now */
00143 }

Generated on Mon Feb 10 09:54:47 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees