* added compilers lcc and bcc (linux86)
[mascara-docs.git] / i86 / mtx / mtx / samples / LAB5_FS / USER / ucode.c
bloba54105b9c609c7433f1765182eec76c655a89ea5
1 // ucode.c file
3 char *cmd[]={"getpid", "ps", "chname", "kmode", "switch", "wait", "exit",
4 "fork", "exec", "sh", 0};
6 int show_menu()
8 printf("************************* Menu ***************************\n");
9 printf("* ps chname kmode switch wait exit fork exec sh *\n");
10 /* 1 2 3 4 5 6 7 8 9 */
11 printf("**********************************************************\n");
14 int find_cmd(name) char *name;
16 int i; char *p;
17 i = 0; p = cmd[0];
18 while (p){
19 if (strcmp(p, name)==0)
20 return i;
21 i++; p = cmd[i];
23 return(-1);
27 int getpid()
29 return syscall(0,0,0);
32 int ps()
34 return syscall(1, 0, 0);
37 int chname()
39 char s[64];
40 printf("\ninput new name : ");
41 gets(s);
42 return syscall(2, s, 0);
45 int kmode()
47 printf("kmode : enter Kmode via INT 80\n");
48 printf("proc %d going K mode ....\n", getpid());
49 return syscall(3, 0, 0);
50 printf("proc %d back from Kernel\n", getpid());
53 int uswitch()
55 printf("proc %d enter Kernel to switch proc\n", getpid());
56 return syscall(4,0,0);
57 printf("proc %d back from Kernel\n", getpid());
60 int uwait()
62 int child, exitValue;
63 printf("proc %d enter Kernel to wait for a child to die\n", getpid());
64 child = syscall(5, &exitValue, 0);
65 printf("proc %d back from wait, dead child=%d", getpid(), child);
66 if (child>=0)
67 printf("exitValue=%d", exitValue);
68 printf("\n");
71 int uexit()
73 char exitValue;
74 printf("\nenter an exitValue (0-9) : ");
75 exitValue=getc() - '0';
76 printf("enter kernel to die with exitValue=%d\n");
77 syscall(6,exitValue,0);
80 int ufork()
82 int child;
83 child = syscall(7,0,0,0);
84 if (child)
85 printf("parent % return form fork, child=%d\n", getpid(), child);
86 else
87 printf("child %d return from fork, child=%d\n", getpid(), child);
90 int uexec()
92 int r;
93 char filename[32];
94 printf("\nenter exec filename : ");
95 gets(filename);
96 r = syscall(8,filename,0,0);
97 printf("exec failed\n");
102 /******** simple MTX syscalls ********/
104 int wait(status) int *status;
106 return syscall(5,status, 0,0);
109 int exit(value) int value;
111 return syscall(6,value,0,0);
114 int fork()
116 return syscall(7,0,0,0);
119 int exec(name) char *name;
121 return syscall(8,name,0,0);
124 // putc() syscall #10 to MTX kernel ==> putc() in VID.c
125 int putc(c) char c;
127 return syscall(10,c,0,0);
130 int getc()
132 return syscall(11,0,0,0) & 0x7F;
135 int invalid(name) char *name;
137 printf("Invalid command : %s\n", name);
142 /******** syscalls to file system in MTX kernel *********/
143 char pathname[64];
145 int mkdir(name) char *name;
147 return syscall(21, name, 30);
150 int rmdir(name) char *name;
152 return syscall(22, name, 30);
155 int creat(name) char *name;
157 return syscall(23, name, 30);
160 int rm(name) char *name;
162 return syscall(24, name, 30);
166 int chdir(name) char *name;
168 return syscall(25, name, 30);
171 int pwd()
173 int r;
174 char cwd[64];
175 r = syscall(26, cwd, 0);
176 cwd[r]=0;
177 printf("%s\n",cwd);
180 int getcwd(cwdname) char *cwdname;
182 return syscall(26, cwdname, 0);
185 int stat(filename, sPtr) char *filename; struct stat *sPtr;
187 return syscall(27, filename, sPtr);
190 int open(file, mode) char *file; int mode;
192 return syscall(28, file, mode);
195 int close(fd) int fd;
197 return syscall(29, fd);
200 int read(fd, buf, nbytes) int fd, nbytes; char *buf;
202 return syscall(30, fd, buf, nbytes);
205 int write(fd, buf, nbytes) int fd, nbytes; char *buf;
207 return syscall(31, fd, buf, nbytes);
210 long lseek(fd, offset, ww) int fd; long offset; int ww;
212 return syscall(32, fd, (long)offset, ww);
215 int chmod(mode) int mode;
217 return syscall(33, mode,0,0);
220 int chown(uid) int uid;
222 return syscall(34,uid,0,0);
225 int dup(oldfd) int oldfd;
227 return syscall(35, oldfd, 0);
230 int dup2(oldfd,newfd) int oldfd, newfd;
232 return syscall(36, oldfd, newfd);