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;
102 printf("%d\n", 0xffffff);
103 printf("%u\n", 0xffffffU);
104 printf("%li\n",0xffffffL);
105 printf("%lu\n",0xffffffUL);
109 printf("argv[%d] = \"%s\"\n",i,argv[i]);
110 for(i=0;user_info[i];i++)
111 printf("user_info[%d] = \"%s\"\n",i,user_info[i]);
113 printf("getenv(\"USER\") = \"%s\"\n",getenv("USER"));
114 printf("getenv(\"HOME\") = \"%s\"\n",getenv("HOME"));
115 printf("getenv(\"TZ\") = \"%s\"\n",getenv("TZ"));
119 printf("%s %s %d\n",tzname[0],tzname[1],(int)_timezone);
121 printf("Running ctime\n");
123 printf("ctime returned: %p\n",s);
124 printf("Current time: %s",s);
126 printf("Trying to open /nonexistent\n");
127 fd = open("/nonexistent",O_RDONLY);
128 if(fd < 0) perror("open");
131 printf("Tyring to mkdir .mkdirtest\n");
132 if(mkdir(".mkdirtest",0700) < 0) perror("mkdir");
134 printf("Trying to opendir /\n");
137 while((dent=readdir(dir))!=NULL)
138 printf("\t[%s] %lu\n",dent->d_name,dent->d_ino);
146 printf("Sleeping...\n");
151 fd = open("test.txt",O_RDONLY);
153 printf("Opened test.txt\n");
154 n = read(fd,sbuf,sizeof(sbuf));
156 if(n < 0) perror("read");
158 printf("buf: %s\n",buf);
160 printf("Char %d: [%x]\n",i,sbuf[i]);
165 static double f = 1.574;
174 printf("%e\n",fabs(f));
184 fprintf(stderr,"Eating up all available memory\n");
185 while(malloc(1024*1024) != NULL) total ++;
186 fprintf(stderr,"Ate up %d megs\n",total);
189 __attribute__((constructor)) static void my_ctor() { printf("Constructor!\n"); }
190 __attribute__((destructor)) static void my_dtor() { printf("Destructor!\n"); }
192 int callme(int a1,int a2, int a3, int a4, int a5, int a6) __attribute__((section(".text")));
193 int callme(int a1,int a2, int a3, int a4, int a5, int a6) {
194 printf("You said: %d %d %d %d %d %d\n",a1,a2,a3,a4,a5,a6);
195 return a1+a2+a3+a4+a5+a6;
198 void echo(const char *string, int count) __attribute__((section(".text")));
199 void echo(const char *string, int count) {
202 printf("%d: %s\n",i,string);
205 void backinmips() __attribute__((section(".text")));
207 fprintf(stderr,"In backinmips() in mips\n");