* added compilers lcc and bcc (linux86)
[mascara-docs.git] / i86 / mtx / mtx / samples / LAB5.timer / USER / ucode.c
blobb55aff7fdf537865e0fba35291ae166c3543e983
1 // ucode.c file
3 char *cmd[]={"getpid", "ps", "chname", "kmode", "switch", "wait", "die",
4 "fork", "exec", "color", 0};
6 int show_menu()
8 printf("************************* Menu *****************************\n");
9 printf("* ps chname kmode switch wait die fork exec color *\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 syscall(1, 0, 0);
37 int chname()
39 char s[64];
40 printf("\ninput new name : ");
41 gets(s);
42 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 syscall(3, 0, 0);
50 printf("proc %d back from Kernel\n", getpid());
53 int kswitch()
55 printf("proc %d enter Kernel to switch proc\n", getpid());
56 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 die()
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 exit(v) int v;
82 syscall(99, v, 0);
85 int ufork()
87 int child;
88 child = syscall(7,0,0,0);
89 if (child)
90 printf("parent % return form fork, child=%d\n", getpid(), child);
91 else
92 printf("child %d return from fork, child=%d\n", getpid(), child);
95 int uexec()
97 int r;
98 char filename[32];
99 printf("\nenter exec filename : ");
100 gets(filename);
101 r = syscall(8,filename,0,0);
102 printf("exec failed\n");
105 int chcolor()
107 int y;
108 printf("\ninput color [r|g|c|y] ; ");
109 y = getc();
110 syscall(9,y,0);
113 int putc(c) char c;
115 return syscall(10, c, 0, 0);
118 int invalid(name) char *name;
120 printf("Invalid command : %s\n", name);