7 #include <sys/unistd.h>
10 #include <sys/signal.h>
16 char *user_info[1024];
19 extern int _call_java(int a, int b, int c, int d);
23 int main(int argc, char **argv) {
29 unsigned char ubuf[1024];
30 unsigned short sbuf[1024];
33 printf("Entered main()\n");
35 if(argc > 1 && strcmp(argv[1],"calltest")==0) {
36 printf("pausing for call test\n");
38 printf("unpaused from call test\n");
41 char *s = (char*)_call_java(i,0,0,0);
42 printf("_call_java(%d,0,0,0) = \"%s\" (%d chars)\n",i,s,strlen(s));
45 fd = _call_java(4,0,0,0);
48 fprintf(stderr,"fd: %i\n",fd);
51 fprintf(fp,"It worked! fp is %p - Hello, Java!\n",fp);
54 fprintf(stderr,"fdopen failed\n");
58 fprintf(stderr,"fd == -1\n");
61 printf("In main() in MIPS\n");
63 printf("Back in main() in MIPS\n");
64 } else if(argc > 2 && strcmp(argv[1],"fdtest")==0) {
65 printf("opening %s\n",argv[2]);
66 fd = open(argv[2],O_RDONLY);
67 if(fd < 0) { perror("open"); exit(1); }
69 printf("reading up to 64 bytes\n");
71 if(n < 0) {perror("read"); exit(1); }
72 printf("read %d bytes\n",n);
73 for(i=0;i<n;i++) if(buf[i]=='\n' || buf[i]=='\r') { buf[i] = '\0'; break; }
74 printf("Read \"%s\"...\n",n == 0 ? NULL : buf);
76 printf("seeking back to pos 4...\n");
77 if(lseek(fd,4,SEEK_SET) < 0) { perror("lseek"); exit(1); }
79 printf("reading up to 64 bytes\n");
81 if(n < 0) {perror("read"); exit(1); }
82 printf("read %d bytes\n",n);
83 for(i=0;i<n;i++) if(buf[i]=='\n' || buf[i]=='\r') { buf[i] = '\0'; break; }
84 printf("Read \"%s\"...\n",n == 0 ? NULL : buf);
86 printf("reading up to 64 bytes\n");
88 if(n < 0) {perror("read"); exit(1); }
89 printf("read %d bytes\n",n);
90 for(i=0;i<n;i++) if(buf[i]=='\n' || buf[i]=='\r') { buf[i] = '\0'; break; }
91 printf("Read \"%s\"...\n",n == 0 ? NULL : buf);
92 } else if(argc > 1 && strcmp(argv[1],"fptest")==0) {
98 } else if(argc > 1 && strcmp(argv[1],"nullderef")==0) {
99 volatile int *mem = 0;
101 } else if(argc > 2 && strcmp(argv[1],"crashme") == 0) {
102 volatile int *mem = (int*) atoi(argv[2]);
105 printf("%d\n", 0xffffff);
106 printf("%u\n", 0xffffffU);
107 printf("%li\n",0xffffffL);
108 printf("%lu\n",0xffffffUL);
112 printf("argv[%d] = \"%s\"\n",i,argv[i]);
113 for(i=0;user_info[i];i++)
114 printf("user_info[%d] = \"%s\"\n",i,user_info[i]);
116 printf("getenv(\"USER\") = \"%s\"\n",getenv("USER"));
117 printf("getenv(\"HOME\") = \"%s\"\n",getenv("HOME"));
118 printf("getenv(\"TZ\") = \"%s\"\n",getenv("TZ"));
122 printf("%s %s %d\n",tzname[0],tzname[1],(int)_timezone);
124 printf("Running ctime\n");
126 printf("ctime returned: %p\n",s);
127 printf("Current time: %s",s);
129 printf("Trying to open /nonexistent\n");
130 fd = open("/nonexistent",O_RDONLY);
131 if(fd < 0) perror("open");
134 printf("Tyring to mkdir .mkdirtest\n");
135 if(mkdir(".mkdirtest",0700) < 0) perror("mkdir");
137 printf("Trying to opendir .\n");
140 printf("Success!\n");
141 while((dent=readdir(dir))!=NULL) {
143 stat(dent->d_name,&statbuf);
144 printf("\t[%s] %lu %i %i\n",dent->d_name,dent->d_ino,statbuf.st_ino,statbuf.st_dev);
146 if(errno != 0) { fprintf(stderr,"readdir errno: %d\n",errno); perror("readdir"); }
154 printf("Sleeping...\n");
159 fd = open("test.txt",O_RDONLY);
161 printf("Opened test.txt\n");
162 n = read(fd,sbuf,sizeof(sbuf));
164 if(n < 0) perror("read");
166 printf("buf: %s\n",buf);
168 printf("Char %d: [%x]\n",i,sbuf[i]);
173 static double f = 1.574;
182 printf("%e\n",fabs(f));
188 memcpy(buf,"Hello, World",sizeof("Hello, World"));
194 #define HOST_BITS_PER_WIDE_INT 64
195 #define HOST_WIDE_INT long long
197 extern int ri(int n);
198 int precision = ri(8);
201 l = (precision - HOST_BITS_PER_WIDE_INT > 0
202 ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
203 (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
204 ? (((HOST_WIDE_INT) 1
205 << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
211 //printf("cwd: %s\n",getcwd(NULL,0));
212 //printf("isatty(0): %d\n",isatty(0));
213 //printf("exiting\n");
219 long long rl(long long n) { return n + zero; }
220 int ri(int n) { return n + izero; }
224 fprintf(stderr,"Eating up all available memory\n");
225 while(malloc(1024*1024) != NULL) total ++;
226 fprintf(stderr,"Ate up %d megs\n",total);
229 __attribute__((constructor)) static void my_ctor() { printf("Constructor!\n"); }
230 __attribute__((destructor)) static void my_dtor() { printf("Destructor!\n"); }
232 int callme(int a1,int a2, int a3, int a4, int a5, int a6) __attribute__((section(".text")));
233 int callme(int a1,int a2, int a3, int a4, int a5, int a6) {
234 printf("You said: %d %d %d %d %d %d\n",a1,a2,a3,a4,a5,a6);
235 return a1+a2+a3+a4+a5+a6;
238 void echo(const char *string, int count) __attribute__((section(".text")));
239 void echo(const char *string, int count) {
242 printf("%d: %s\n",i,string);
245 void backinmips() __attribute__((section(".text")));
247 fprintf(stderr,"In backinmips() in mips\n");