00001
00002
00003
00004
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
00019 system_break()
00020 {
00021 if ( Traptrace )
00022 printf("**breakpoint ");
00023 system_trap();
00024 }
00025
00026 system_trap()
00027 {
00028 int o0, o1, o2;
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
00039
00040
00041
00042
00043
00044
00045
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:
00056 printstatistics();
00057 fflush(stdout);
00058 exit(0);
00059 break;
00060 case SYS_read:
00061 Reg[1] =
00062 read(u_to_int_fd(o0), u_to_int_addr(o1), o2);
00063 break;
00064 case SYS_write:
00065 Reg[1] =
00066 write(u_to_int_fd(o0), u_to_int_addr(o1), o2);
00067 break;
00068
00069 case SYS_open:
00070 Reg[1] = open(u_to_int_addr(o0), o1, o2);
00071 break;
00072
00073 case SYS_close:
00074 Reg[1] = 0;
00075 break;
00076
00077 case 17:
00078
00079 Reg[1] = ((o0 / 8192) + 1) * 8192;
00080 break;
00081
00082 case SYS_lseek:
00083 Reg[1] = (int) lseek(u_to_int_fd(o0), (long) o1, o2);
00084 break;
00085
00086 case SYS_ioctl:
00087 {
00088
00089 #define IOCPARM_MASK 0x7f
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;
00101 break;
00102
00103 case SYS_fstat:
00104 Reg[1] = fstat(o1, o2);
00105 break;
00106
00107 case SYS_getpagesize:
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 {
00128
00129
00130 return ((char *) ((int) mem - memoffset + ptr));
00131 }
00132
00133 u_to_int_fd(fd)
00134 {
00135 if (fd > 2)
00136 {
00137
00138
00139
00140
00141 }
00142 return (fd);
00143 }
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