7 #include <sys/unistd.h>
10 #include <sys/signal.h>
15 char *user_info[1024];
18 extern int _call_java(int a, int b, int c, int d);
22 int main(int argc, char **argv) {
29 printf("Entered main()\n");
31 if(argc > 1 && strcmp(argv[1],"calltest")==0) {
32 printf("pausing for call test\n");
34 printf("unpaused from call test\n");
37 char *s = (char*)_call_java(i,0,0,0);
38 printf("_call_java(%d,0,0,0) = \"%s\" (%d chars)\n",i,s,strlen(s));
41 fd = _call_java(4,0,0,0);
44 fprintf(stderr,"fd: %i\n",fd);
47 fprintf(fp,"It worked! fp is %p - Hello, Java!\n",fp);
50 fprintf(stderr,"fdopen failed\n");
54 fprintf(stderr,"fd == -1\n");
57 printf("In main() in MIPS\n");
59 printf("Back in main() in MIPS\n");
60 } else if(argc > 2 && strcmp(argv[1],"fdtest")==0) {
61 printf("opening %s\n",argv[2]);
62 fd = open(argv[2],O_RDONLY);
63 if(fd < 0) { perror("open"); exit(1); }
65 printf("reading up to 64 bytes\n");
67 if(n < 0) {perror("read"); exit(1); }
68 printf("read %d bytes\n",n);
69 for(i=0;i<n;i++) if(buf[i]=='\n' || buf[i]=='\r') { buf[i] = '\0'; break; }
70 printf("Read \"%s\"...\n",n == 0 ? NULL : buf);
72 printf("seeking back to pos 4...\n");
73 if(lseek(fd,4,SEEK_SET) < 0) { perror("lseek"); exit(1); }
75 printf("reading up to 64 bytes\n");
77 if(n < 0) {perror("read"); exit(1); }
78 printf("read %d bytes\n",n);
79 for(i=0;i<n;i++) if(buf[i]=='\n' || buf[i]=='\r') { buf[i] = '\0'; break; }
80 printf("Read \"%s\"...\n",n == 0 ? NULL : buf);
82 printf("reading up to 64 bytes\n");
84 if(n < 0) {perror("read"); exit(1); }
85 printf("read %d bytes\n",n);
86 for(i=0;i<n;i++) if(buf[i]=='\n' || buf[i]=='\r') { buf[i] = '\0'; break; }
87 printf("Read \"%s\"...\n",n == 0 ? NULL : buf);
88 } else if(argc > 1 && strcmp(argv[1],"fptest")==0) {
96 printf("argv[%d] = \"%s\"\n",i,argv[i]);
97 for(i=0;user_info[i];i++)
98 printf("user_info[%d] = \"%s\"\n",i,user_info[i]);
100 printf("getenv(\"USER\") = \"%s\"\n",getenv("USER"));
101 printf("getenv(\"HOME\") = \"%s\"\n",getenv("HOME"));
102 printf("getenv(\"TZ\") = \"%s\"\n",getenv("TZ"));
106 printf("%s %s %d\n",tzname[0],tzname[1],(int)_timezone);
107 printf("Current time: %s",ctime(&now));
109 printf("Trying to open /nonexistent\n");
110 fd = open("/nonexistent",O_RDONLY);
111 if(fd < 0) perror("open");
114 printf("Tyring to mkdir .mkdirtest\n");
115 if(mkdir(".mkdirtest",0700) < 0) perror("mkdir");
117 printf("Trying to opendir /\n");
120 while((dent=readdir(dir))!=NULL)
121 printf("\t[%s] %lu\n",dent->d_name,dent->d_ino);
128 printf("Sleeping...\n");
135 wchar_t wstring[] = L"My wchar_t string";
136 printf("sizeof(wstring) = %u wcslen(wstring) = %u",sizeof(wstring),wcslen(wstring));
146 fprintf(stderr,"Eating up all available memory\n");
147 while(malloc(1024*1024) != NULL) total ++;
148 fprintf(stderr,"Ate up %d megs\n",total);
151 __attribute__((constructor)) static void my_ctor() { printf("Constructor!\n"); }
152 __attribute__((destructor)) static void my_dtor() { printf("Destructor!\n"); }
154 int callme(int a1,int a2, int a3, int a4, int a5, int a6) __attribute__((section(".text")));
155 int callme(int a1,int a2, int a3, int a4, int a5, int a6) {
156 printf("You said: %d %d %d %d %d %d\n",a1,a2,a3,a4,a5,a6);
157 return a1+a2+a3+a4+a5+a6;
160 void echo(const char *string, int count) __attribute__((section(".text")));
161 void echo(const char *string, int count) {
164 printf("%d: %s\n",i,string);
167 void backinmips() __attribute__((section(".text")));
169 fprintf(stderr,"In backinmips() in mips\n");