├── commands ├── ar.c ├── basename.c ├── c86 │ └── make.bat ├── cal.c ├── cat.c ├── cc.c ├── chmem.c ├── chmod.c ├── chown.c ├── clr.c ├── cmp.c ├── comm.c ├── cp.c ├── date.c ├── dd.c ├── df.c ├── dosread.c ├── echo.c ├── getlf.c ├── grep.c ├── gres.c ├── head.c ├── kill.c ├── libpack.c ├── libupack.c ├── ln.c ├── login.c ├── lpr.c ├── ls.c ├── make.c ├── makefile ├── mined.h ├── mined1.c ├── mined2.c ├── mkdir.c ├── mkfs.c ├── mknod.c ├── mount.c ├── mv.c ├── od.c ├── passwd.c ├── pr.c ├── pwd.c ├── rev.c ├── rm.c ├── rmdir.c ├── roff.c ├── sh1.c ├── sh2.c ├── sh3.c ├── sh4.c ├── sh5.c ├── shar.c ├── size.c ├── sleep.c ├── sort.c ├── split.c ├── stty.c ├── su.c ├── sum.c ├── sync.c ├── tail.c ├── tar.c ├── tee.c ├── time.c ├── touch.c ├── tr.c ├── umount.c ├── uniq.c ├── update.c ├── wc.c └── x.c ├── doc └── read_me ├── fs ├── buf.h ├── c86 │ ├── _link.bat │ ├── linklist │ └── make.bat ├── cache.c ├── const.h ├── dev.h ├── device.c ├── file.h ├── filedes.c ├── fproc.h ├── glo.h ├── inode.c ├── inode.h ├── link.c ├── main.c ├── minix │ ├── makefile │ └── makefile.at ├── misc.c ├── mount.c ├── open.c ├── param.h ├── path.c ├── pipe.c ├── protect.c ├── putc.c ├── read.c ├── stadir.c ├── super.c ├── super.h ├── table.c ├── time.c ├── type.h ├── utility.c └── write.c ├── h ├── callnr.h ├── com.h ├── const.h ├── error.h ├── sgtty.h ├── signal.h ├── stat.h └── type.h ├── include ├── blocksiz.h ├── ctype.h ├── errno.h ├── grp.h ├── lib.h ├── mined.h ├── pwd.h ├── regexp.h ├── setjmp.h ├── sgtty.h ├── sh.h ├── signal.h ├── stat.h └── stdio.h ├── kernel ├── _link.bat ├── at_wini.c ├── clock.c ├── const.h ├── dmp.c ├── floppy.c ├── glo.h ├── klib88.asm ├── klib88.s ├── linklist ├── main.c ├── make.bat ├── makefile ├── memory.c ├── minix │ ├── makefile │ └── makefile.at ├── mpx88.asm ├── mpx88.s ├── printer.c ├── proc.c ├── proc.h ├── system.c ├── table.c ├── tty.c ├── type.h ├── wini.c └── xt_wini.c ├── lib ├── abort.c ├── abs.c ├── access.c ├── alarm.c ├── atoi.c ├── atol.c ├── bcopy.c ├── brk.c ├── brk2.c ├── brksize.s ├── c86 │ ├── brksize.asm │ ├── catchsig.asm │ ├── crtso.asm │ ├── csv.asm │ ├── end.asm │ ├── getutil.asm │ ├── head.asm │ ├── make.bat │ ├── prologue.h │ ├── sendrec.asm │ └── setjmp.asm ├── call.c ├── catchsig.s ├── chdir.c ├── chmod.c ├── chown.c ├── chroot.c ├── cleanup.c ├── close.c ├── creat.c ├── crtso.s ├── crypt.c ├── csv.s ├── ctype.c ├── doprintf.c ├── doscanf.c ├── dup.c ├── dup2.c ├── end.s ├── exec.c ├── exit.c ├── fclose.c ├── fflush.c ├── fgets.c ├── fopen.c ├── fork.c ├── fprintf.c ├── fputs.c ├── fread.c ├── freopen.c ├── fseek.c ├── fstat.c ├── ftell.c ├── fwrite.c ├── getc.c ├── getegid.c ├── getenv.c ├── geteuid.c ├── getgid.c ├── getgrent.c ├── getpass.c ├── getpid.c ├── getpwent.c ├── gets.c ├── getuid.c ├── getutil.s ├── head.s ├── index.c ├── ioctl.c ├── isatty.c ├── itoa.c ├── kill.c ├── link.c ├── lseek.c ├── malloc.c ├── message.c ├── minix │ ├── crtso.s │ ├── end.s │ ├── head.s │ └── setjmp.s ├── mknod.c ├── mktemp.c ├── mount.c ├── open.c ├── pause.c ├── perror.c ├── pipe.c ├── printdat.c ├── printk.c ├── prints.c ├── putc.c ├── rand.c ├── read.c ├── read_me ├── regexp.c ├── regsub.c ├── rindex.c ├── run ├── scanf.c ├── sendrec.s ├── setbuf.c ├── setgid.c ├── setjmp.s ├── setuid.c ├── signal.c ├── sleep.c ├── sprintf.c ├── stat.c ├── stb.c ├── stderr.c ├── stime.c ├── strcat.c ├── strcmp.c ├── strcpy.c ├── strlen.c ├── strncat.c ├── strncmp.c ├── strncpy.c ├── sync.c ├── syslib.c ├── time.c ├── times.c ├── umask.c ├── umount.c ├── ungetc.c ├── unlink.c ├── utime.c ├── wait.c └── write.c ├── mm ├── alloc.c ├── break.c ├── c86 │ ├── _link.bat │ ├── linklist │ └── make.bat ├── const.h ├── exec.c ├── forkexit.c ├── getset.c ├── glo.h ├── main.c ├── makefile ├── minix │ ├── makefile │ └── makefile.at ├── mproc.h ├── param.h ├── putc.c ├── signal.c ├── table.c ├── type.h └── utility.c ├── readme.txt ├── test ├── c86 │ └── nullfile ├── makefile ├── minix │ └── makefile ├── run ├── t10a.c ├── t11a.c ├── t11b.c ├── t15a.c ├── t16a.c ├── t16b.c ├── test0.c ├── test1.c ├── test10.c ├── test11.c ├── test2.c ├── test3.c ├── test4.c ├── test5.c ├── test6.c ├── test7.c ├── test8.c └── test9.c └── tools ├── bootblok.s ├── build.c ├── c86 ├── _bootblo.bat ├── _build.bat ├── _dos2out.bat ├── _fsck.bat ├── _image.bat ├── _init.bat ├── _mkfs.bat ├── bootblok ├── bootblok.asm ├── diskio.asm ├── dos2out.c ├── fsck1.asm └── make.bat ├── changeme ├── fsck.c ├── fsck1.s ├── getcore.c ├── init.c ├── makefile ├── minix ├── makefile └── makefile.at ├── mkfs.c ├── passwd ├── proto.dis ├── proto.ram ├── proto.use ├── proto.usr ├── r.c ├── rc.at ├── run ├── setup1 ├── setup2 ├── setup3 ├── ttys └── versions /commands/basename.c: -------------------------------------------------------------------------------- 1 | /* basename - print the last part of a path: Author: Blaine Garfolo */ 2 | 3 | #define NULL 0 4 | 5 | main(argc,argv) 6 | 7 | int argc; 8 | char *argv[]; 9 | { 10 | int j,suflen; 11 | char *c; 12 | char *d; 13 | extern char *rindex(); 14 | 15 | if (argc < 2) { 16 | std_err("Usage: basename string [suffix] \n"); 17 | exit(1); 18 | } 19 | c=argv[1]; 20 | d = rindex(argv[1],'/'); 21 | if (d == NULL) 22 | d = argv[1]; 23 | else 24 | d++; 25 | 26 | if (argc == 2) { /* if no suffix */ 27 | prints("%s \n",d); 28 | exit(0); 29 | } else { /* if suffix is present */ 30 | c = d; 31 | suflen = strlen(argv[2]); 32 | j = strlen(c) - suflen; 33 | if (strcmp(c+j, argv[2]) == 0) *(c+j) = 0; 34 | } 35 | prints("%s \n",c); 36 | } 37 | -------------------------------------------------------------------------------- /commands/c86/make.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | :begin 3 | if "%1"=="" goto eind 4 | echo/ 5 | echo Compiling %1 for Minix 6 | cc1 %1 > %1.lst 7 | if errorlevel 1 goto fout 8 | cc2 %1 >> %1.lst 9 | if errorlevel 1 goto fout 10 | cc3 %1 >> %1.lst 11 | if errorlevel 1 goto fout 12 | cc4 %1 >> %1.lst 13 | if errorlevel 1 goto fout 14 | link ..\lib\crtso+%1,%1,%1,..\lib\mxc86 >> %1.lst 15 | dos2out -d %1 >>%1.lst 16 | shift 17 | goto begin 18 | :fout 19 | echo +++error in compilation+++ 20 | shift 21 | goto begin 22 | :eind 23 | -------------------------------------------------------------------------------- /commands/cat.c: -------------------------------------------------------------------------------- 1 | /* cat - concatenates files Author: Andy Tanenbaum */ 2 | 3 | extern int errno; /*DEBUG*/ 4 | 5 | #include "blocksize.h" 6 | #include "stat.h" 7 | 8 | #define BUF_SIZE 512 9 | int unbuffered; 10 | char buffer[BUF_SIZE]; 11 | char *next = buffer; 12 | 13 | main(argc, argv) 14 | int argc; 15 | char *argv[]; 16 | { 17 | int i, k, m, fd1; 18 | char *p; 19 | struct stat sbuf; 20 | 21 | k = 1; 22 | /* Check for the -u flag -- unbuffered operation. */ 23 | p = argv[1]; 24 | if (argc >=2 && *p == '-' && *(p+1) == 'u') { 25 | unbuffered = 1; 26 | k = 2; 27 | } 28 | 29 | if (k >= argc) { 30 | copyfile(0, 1); 31 | flush(); 32 | exit(0); 33 | } 34 | 35 | for (i = k; i < argc; i++) { 36 | if (argv[i][0] == '-' && argv[i][1] == 0) { 37 | fd1 = 0; 38 | } else { 39 | fd1 = open(argv[i], 0); 40 | if (fd1 < 0) { 41 | std_err("cat: cannot open "); 42 | std_err(argv[i]); 43 | std_err("\n"); 44 | continue; 45 | } 46 | } 47 | copyfile(fd1, 1); 48 | if (fd1 != 0) close(fd1); 49 | } 50 | flush(); 51 | exit(0); 52 | } 53 | 54 | 55 | 56 | copyfile(fd1, fd2) 57 | int fd1, fd2; 58 | { 59 | int n, j, m; 60 | char buf[BLOCK_SIZE]; 61 | 62 | while (1) { 63 | n = read(fd1, buf, BLOCK_SIZE); 64 | if (n < 0) quit(); 65 | if (n == 0) return; 66 | if (unbuffered) { 67 | m = write(fd2, buf, n); 68 | if (m != n) quit(); 69 | } else { 70 | for (j = 0; j < n; j++) { 71 | *next++ = buf[j]; 72 | if (next == &buffer[BUF_SIZE]) { 73 | m = write(fd2, buffer, BUF_SIZE); 74 | if (m != BUF_SIZE) quit(); 75 | next = buffer; 76 | } 77 | } 78 | } 79 | } 80 | } 81 | 82 | 83 | flush() 84 | { 85 | if (next != buffer) 86 | if (write(1, buffer, next - buffer) <= 0) quit(); 87 | } 88 | 89 | 90 | quit() 91 | { 92 | perror("cat"); 93 | exit(1); 94 | } 95 | -------------------------------------------------------------------------------- /commands/chmod.c: -------------------------------------------------------------------------------- 1 | /* 2 | * chmod [mode] files 3 | * change mode of files 4 | * 5 | * by Patrick van Kleef 6 | */ 7 | 8 | main (argc, argv) 9 | int argc; 10 | char *argv[]; 11 | { 12 | int i; 13 | int status = 0; 14 | int newmode; 15 | 16 | if (argc < 3) { 17 | Usage (); 18 | } 19 | 20 | newmode = oatoi (argv[1]); 21 | 22 | for (i = 2; i < argc; i++) { 23 | if (access (argv[i], 0)) { 24 | prints ("chmod: can't access %s\n", argv[i]); 25 | status++; 26 | } 27 | else 28 | if (chmod (argv[i], newmode) < 0) { 29 | prints ("chmod: can't change %s\n", argv[i]); 30 | status++; 31 | } 32 | } 33 | exit (status); 34 | } 35 | 36 | oatoi (arg) 37 | char *arg; 38 | { 39 | register c, 40 | i; 41 | 42 | i = 0; 43 | while ((c = *arg++) >= '0' && c <= '7') 44 | i = (i << 3) + (c - '0'); 45 | if (c != '\0') 46 | Usage (); 47 | return (i); 48 | } 49 | 50 | Usage () { 51 | prints ("Usage: chmod [mode] file ...\n"); 52 | exit (255); 53 | } 54 | -------------------------------------------------------------------------------- /commands/chown.c: -------------------------------------------------------------------------------- 1 | /* 2 | * chown username file ... 3 | * 4 | * By Patrick van Kleef 5 | * 6 | */ 7 | 8 | #include "pwd.h" 9 | #include "../h/type.h" 10 | #include "stat.h" 11 | #include "stdio.h" 12 | 13 | main (argc, argv) 14 | int argc; 15 | char *argv[]; 16 | { 17 | int i, 18 | status = 0; 19 | struct passwd *pwd, *getpwnam (); 20 | struct stat stbuf; 21 | 22 | if (argc < 3) { 23 | fprintf (stderr,"Usage: chown uid file ...\n"); 24 | exit (1); 25 | } 26 | 27 | if ((pwd = getpwnam (argv[1])) == 0) { 28 | fprintf (stderr,"Unknown user id: %s\n", argv[1]); 29 | exit (4); 30 | } 31 | 32 | for (i = 2; i < argc; i++) { 33 | if (stat (argv[i], &stbuf) < 0) { 34 | perror (argv[i]); 35 | status++; 36 | } 37 | else 38 | if (chown (argv[i], pwd -> pw_uid, stbuf.st_gid) < 0) { 39 | fprintf (stderr,"%s: not changed\n", argv[i]); 40 | status++; 41 | } 42 | } 43 | exit (status); 44 | } 45 | -------------------------------------------------------------------------------- /commands/clr.c: -------------------------------------------------------------------------------- 1 | /* clr - clear the screen Author: Andy Tanenbaum */ 2 | 3 | main() 4 | { 5 | /* Clear the screen. */ 6 | 7 | prints("\033 8\033~0"); 8 | exit(0); 9 | } 10 | -------------------------------------------------------------------------------- /commands/echo.c: -------------------------------------------------------------------------------- 1 | /* echo - echo arguments Author: Andy Tanenbaum */ 2 | 3 | #define SIZE 2048 4 | char buf[SIZE]; 5 | int count; 6 | main(argc, argv) 7 | int argc; 8 | char *argv[]; 9 | { 10 | register int i, nflag; 11 | 12 | nflag = 0; 13 | if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'n') { 14 | nflag++; 15 | argc--; 16 | argv++; 17 | } 18 | 19 | for(i = 1; i < argc; i++) { 20 | collect(argv[i]); 21 | if (i < argc - 1) collect(" "); 22 | } 23 | 24 | if (nflag == 0) collect("\n"); 25 | 26 | /* Print accumulated output. */ 27 | if (count > 0) write(1, buf, count); 28 | exit(0); 29 | } 30 | 31 | collect(s) 32 | char *s; 33 | { 34 | /* Collect characters. For efficiency, write them in large chunks. */ 35 | char c; 36 | 37 | if (count == SIZE) {write(1, buf, count); count = 0;} 38 | while ( (c = *s++) != 0) { 39 | if (count < SIZE && c != '"') buf[count++] = c; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /commands/getlf.c: -------------------------------------------------------------------------------- 1 | main(argc, argv) 2 | int argc; 3 | char *argv[]; 4 | { 5 | char c; 6 | 7 | /* Echo argument, if present. */ 8 | if (argc == 2) { 9 | std_err(argv[1]); 10 | std_err("\n"); 11 | } 12 | close(0); 13 | open("/dev/tty0", 0); 14 | 15 | do { 16 | read(0, &c, 1); 17 | } while (c != '\n'); 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /commands/head.c: -------------------------------------------------------------------------------- 1 | /* head - print the first few lines of a file Author: Andy Tanenbaum */ 2 | 3 | #include "stdio.h" 4 | 5 | #define DEFAULT 10 6 | 7 | char buff[BUFSIZ]; 8 | char lbuf[256]; 9 | 10 | main(argc, argv) 11 | int argc; 12 | char *argv[]; 13 | { 14 | 15 | int n, k, nfiles; 16 | char *ptr; 17 | 18 | /* Check for flag. Only flag is -n, to say how many lines to print. */ 19 | setbuf(stdout, buff); 20 | k = 1; 21 | ptr = argv[1]; 22 | n = DEFAULT; 23 | if (*ptr++ == '-') { 24 | k++; 25 | n = atoi(ptr); 26 | if (n <= 0) usage(); 27 | } 28 | nfiles = argc - k; 29 | 30 | if (nfiles == 0) { 31 | /* Print standard input only. */ 32 | do_file(n); 33 | fflush(stdout); 34 | exit(0); 35 | } 36 | 37 | /* One or more files have been listed explicitly. */ 38 | while (k < argc) { 39 | fclose(stdin); 40 | if (nfiles > 1) prints("==> %s <==\n", argv[k]); 41 | if (fopen(argv[k], "r") == NULL) 42 | prints("head: cannot open %s\n", argv[k]); 43 | else 44 | do_file(n); 45 | k++; 46 | if (k < argc) prints("\n"); 47 | } 48 | fflush(stdout); 49 | exit(0); 50 | } 51 | 52 | 53 | 54 | do_file(n) 55 | int n; 56 | { 57 | /* Print the first 'n' lines of a file. */ 58 | while (n--) do_line(); 59 | } 60 | 61 | 62 | do_line() 63 | { 64 | /* Print one line. */ 65 | 66 | char c, *cp; 67 | cp = lbuf; 68 | while ( (c = getc(stdin)) != '\n') *cp++ = c; 69 | *cp++ = '\n'; 70 | *cp++ = 0; 71 | prints("%s",lbuf); 72 | } 73 | 74 | 75 | usage() 76 | { 77 | std_err("Usage: head [-n] [file ...]\n"); 78 | exit(1); 79 | } 80 | 81 | -------------------------------------------------------------------------------- /commands/kill.c: -------------------------------------------------------------------------------- 1 | /* kill - send a signal to a process Author: Adri Koppes */ 2 | 3 | #include "../h/signal.h" 4 | 5 | main(argc,argv) 6 | int argc; 7 | char **argv; 8 | { 9 | int proc, signal = SIGTERM; 10 | 11 | if (argc < 2) usage(); 12 | if (*argv[1] == '-') { 13 | signal = atoi(&argv[1][1]); 14 | *argv++; 15 | argc--; 16 | } 17 | if (!signal) signal = SIGTERM; 18 | while(--argc) { 19 | *argv++; 20 | proc = atoi(*argv); 21 | if (!proc && strcmp(*argv, "0")) 22 | usage(); 23 | if (kill(proc,signal)) { 24 | prints("Kill: %s no such process\n", itoa(proc)); 25 | exit(1); 26 | } 27 | } 28 | exit(0); 29 | } 30 | 31 | usage() 32 | { 33 | prints("usage: kill pid\n"); 34 | exit(1); 35 | } 36 | -------------------------------------------------------------------------------- /commands/ln.c: -------------------------------------------------------------------------------- 1 | /* ln - link a file Author: Andy Tanenbaum */ 2 | 3 | #include "stat.h" 4 | char name[17]; 5 | struct stat stb; 6 | 7 | main(argc, argv) 8 | int argc; 9 | char **argv; 10 | { 11 | char *file1, *file2; 12 | 13 | if (argc < 2 || argc > 3) usage(); 14 | if (access(argv[1], 0) < 0) { 15 | std_err("ln: cannot access "); 16 | std_err(argv[1]); 17 | std_err("\n"); 18 | exit(1); 19 | } 20 | if (stat(argv[1], &stb) >= 0 && (stb.st_mode & S_IFMT) == S_IFDIR) usage(); 21 | file1 = argv[1]; 22 | 23 | /* "ln file" means "ln file ." */ 24 | if (argc == 2) 25 | file2 = "."; 26 | else 27 | file2 = argv[2]; 28 | 29 | 30 | 31 | /* Check to see if target is a directory. */ 32 | if (stat(file2, &stb) >= 0 && (stb.st_mode & S_IFMT) == S_IFDIR) { 33 | strcpy(name, file2); 34 | strcat(name, "/"); 35 | strcat(name, last_comp(file1)); 36 | file2 = name; 37 | } 38 | 39 | if (link(file1, file2)) { 40 | std_err("ln: Can't link\n"); 41 | exit(1); 42 | } 43 | exit(0); 44 | } 45 | 46 | char *last_comp(s) 47 | char *s; 48 | { 49 | /* Return pointer to last component of string. */ 50 | int n; 51 | n = strlen(s); 52 | while (n--) 53 | if (*(s+n) == '/') return(s+n+1); 54 | return(s); 55 | } 56 | 57 | 58 | usage() 59 | { 60 | std_err("Usage: ln file1 [file2]\n"); 61 | exit(1); 62 | } 63 | -------------------------------------------------------------------------------- /commands/login.c: -------------------------------------------------------------------------------- 1 | /* login - log into the system Author: Patrick van Kleef */ 2 | 3 | #include "signal.h" 4 | #include "sgtty.h" 5 | #include "pwd.h" 6 | 7 | main() 8 | { 9 | char buf[30], 10 | buf1[30], 11 | *crypt(); 12 | int n, n1, bad; 13 | struct sgttyb args; 14 | struct passwd *pwd, *getpwnam(); 15 | 16 | args.sg_kill = '@'; 17 | args.sg_erase = '\b'; 18 | args.sg_flags = 06030; 19 | ioctl (0, TIOCSETP, &args); 20 | 21 | 22 | /* Get login name and passwd. */ 23 | for (;;) { 24 | bad = 0; 25 | do { 26 | write(1,"login: ",7); 27 | n = read (0, buf, 30); 28 | } while (n < 2); 29 | buf[n - 1] = 0; 30 | 31 | /* Look up login/passwd. */ 32 | if ((pwd = getpwnam (buf)) == 0) 33 | bad++; 34 | 35 | if (bad || strlen (pwd->pw_passwd) != 0) { 36 | args.sg_flags = 06020; 37 | ioctl (0, TIOCSETP, &args); 38 | write(1,"Password: ",10); 39 | n1 = read (0, buf1, 30); 40 | buf1[n1 - 1] = 0; 41 | write(1,"\n",1); 42 | args.sg_flags = 06030; 43 | ioctl (0, TIOCSETP, &args); 44 | if (bad || strcmp (pwd->pw_passwd, crypt(buf1, pwd->pw_passwd))) { 45 | write (1,"Login incorrect\n",16); 46 | continue; 47 | } 48 | } 49 | 50 | /* Successful login. */ 51 | setgid (pwd->pw_gid); 52 | setuid (pwd->pw_uid); 53 | chdir (pwd->pw_dir); 54 | if (pwd->pw_shell) { 55 | execl(pwd->pw_shell, "-", 0); 56 | } 57 | execl("/bin/sh", "-", 0); 58 | write(1,"exec failure\n",13); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /commands/lpr.c: -------------------------------------------------------------------------------- 1 | /* lpr - line printer front end Author: Andy Tanenbaum */ 2 | 3 | #include "errno.h" 4 | 5 | #define BLOCK 1024 6 | 7 | char in_buf[BLOCK], out_buf[BLOCK]; 8 | int cur_in, in_count, out_count, column; 9 | 10 | main(argc, argv) 11 | int argc; 12 | char *argv[]; 13 | { 14 | /* This program copies files to the line printer. It expands tabs and converts 15 | * line feeds to carriage returns + line feeds. 16 | */ 17 | 18 | int i, fd; 19 | 20 | close(1); 21 | if (open("/dev/lp", 1) < 0) { 22 | std_err("lpr: can't open /dev/lp\n"); 23 | exit(1); 24 | } 25 | 26 | if (argc == 1) { 27 | copy(0); /* standard input only */ 28 | } else { 29 | for (i = 1; i < argc; i++) { 30 | if ( (fd = open(argv[i],0)) < 0) { 31 | std_err("lpr: can't open "); 32 | std_err(argv[1]); 33 | std_err("\n"); 34 | exit(1); 35 | } else { 36 | copy(fd); 37 | close(fd); 38 | cur_in = 0; 39 | in_count = 0; 40 | } 41 | } 42 | } 43 | exit(0); 44 | } 45 | 46 | 47 | copy(fd) 48 | int fd; 49 | { 50 | /* Print a file, adding carriage returns and expanding tabs. */ 51 | 52 | char c; 53 | 54 | while (1) { 55 | if (cur_in == in_count) { 56 | in_count = read(fd, in_buf, BLOCK); 57 | if (in_count == 0) { flush(); return; } 58 | cur_in = 0; 59 | } 60 | c = in_buf[cur_in++]; 61 | if (c == '\n') { 62 | putc('\r'); 63 | putc('\n'); 64 | } else if (c == '\t') { 65 | do { 66 | putc(' '); 67 | } while (column & 07); 68 | } else putc(c); 69 | } 70 | } 71 | 72 | putc(c) 73 | char c; 74 | { 75 | out_buf[out_count++] = c; 76 | if (c == '\n') 77 | column = 0; 78 | else 79 | column++; 80 | if (out_count == BLOCK) { 81 | flush(); 82 | } 83 | } 84 | 85 | flush() 86 | { 87 | int n, count = 0; 88 | 89 | if (out_count == 0) return; 90 | while (1) { 91 | n = write(1, out_buf, out_count); 92 | if (n == out_count) break; 93 | if (n != EAGAIN) { 94 | std_err("Printer error\n"); 95 | exit(1); 96 | } 97 | if (count > 5) { 98 | std_err("Printer keeps returning busy status\n"); 99 | exit(1); 100 | } 101 | count++; 102 | sleep(1); 103 | } 104 | out_count = 0; 105 | } 106 | -------------------------------------------------------------------------------- /commands/makefile: -------------------------------------------------------------------------------- 1 | # To make 'cp', type: make f=cp 2 | # To make 'ls', type: make f=ls 3 | # To make 'cat', type: make f=cat 4 | # Get the idea? 5 | 6 | l=/usr/lib 7 | i=/usr/include 8 | CFLAGS= -I/usr/include -F 9 | 10 | file: $l/libc.a $f.s 11 | @cc -o bin/$f $f.s 12 | @chmem =2048 bin/$f >/dev/null 13 | @echo "$f done ." 14 | 15 | mined: mined1.s mined2.s $i/mined.h 16 | @asld -o bin/mined $l/crtso.s mined1.s mined2.s $l/libc.a $l/end.s 17 | 18 | shobj = sh1.s sh2.s sh3.s sh4.s sh5.s 19 | sh: $(shobj) $i/sh.h 20 | @asld -o bin/sh $l/crtso.s $(shobj) $l/libc.a $l/end.s 21 | 22 | -------------------------------------------------------------------------------- /commands/mkdir.c: -------------------------------------------------------------------------------- 1 | /* mkdir - make a directory Author: Adri Koppes */ 2 | 3 | #include "signal.h" 4 | 5 | int error = 0; 6 | 7 | main(argc, argv) 8 | int argc; 9 | char **argv; 10 | { 11 | if (argc < 2) { 12 | std_err("Usage: mkdir directory...\n"); 13 | exit(1); 14 | } 15 | signal(SIGHUP, SIG_IGN); 16 | signal(SIGINT, SIG_IGN); 17 | signal(SIGQUIT, SIG_IGN); 18 | signal(SIGTERM, SIG_IGN); 19 | while (--argc) 20 | makedir(*++argv); 21 | if (error) 22 | exit(1); 23 | } 24 | 25 | makedir(dirname) 26 | char *dirname; 27 | { 28 | char dots[128], parent[128]; 29 | int sl = 0, i = 0; 30 | 31 | while (dirname[i]) 32 | if (dirname[i++] == '/') 33 | sl = i; 34 | strncpy(parent, dirname, sl); 35 | parent[sl] = '\0'; 36 | strcat(parent, "."); 37 | if (access(parent, 2)) { 38 | stderr3("mkdir: can't access ", parent, "\n"); 39 | exit(1); 40 | } 41 | if (mknod(dirname, 040777, 0)) { 42 | stderr3("mkdir: can't create ", dirname, "\n"); 43 | error++; 44 | return; 45 | } 46 | chown(dirname, getuid(), getgid()); 47 | strcpy(dots, dirname); 48 | strcat(dots, "/."); 49 | if (link(dirname, dots)) { 50 | stderr3("mkdir: can't link ", dots, " to "); 51 | stderr3(dirname, "\n", ""); 52 | error++; 53 | unlink(dirname); 54 | return; 55 | } 56 | strcat(dots, "."); 57 | if (link(parent, dots)) { 58 | stderr3("mkdir: can't link ", dots, " to "); 59 | stderr3(parent, "\n", ""); 60 | error++; 61 | dots[strlen(dots)] = '\0'; 62 | unlink(dots); 63 | unlink(dirname); 64 | return; 65 | } 66 | } 67 | 68 | stderr3(s1, s2, s3) 69 | char *s1, *s2, *s3; 70 | { 71 | std_err(s1); 72 | std_err(s2); 73 | std_err(s3); 74 | } 75 | -------------------------------------------------------------------------------- /commands/mknod.c: -------------------------------------------------------------------------------- 1 | /* mknod - build a special file Author: Andy Tanenbaum */ 2 | 3 | main(argc, argv) 4 | int argc; 5 | char *argv[]; 6 | { 7 | /* mknod name b/c major minor makes a node. */ 8 | 9 | int mode, major, minor; 10 | 11 | if (argc != 5) badcomm(); 12 | if (*argv[2] != 'b' && *argv[2] != 'c') badcomm(); 13 | mode = (*argv[2] == 'b' ? 060666 : 020666); 14 | major = atoi(argv[3]); 15 | minor = atoi(argv[4]); 16 | if (major < 0 || minor < 0) badcomm(); 17 | if (mknod(argv[1], mode, (major<<8) | minor) < 0) 18 | perror("mknod"); 19 | exit(0); 20 | } 21 | 22 | int atoi(p) 23 | char *p; 24 | { 25 | /* Ascii to integer conversion. */ 26 | int c, n; 27 | 28 | n = 0; 29 | while (c = *p++) { 30 | if (c < '0' || c > '9') return (-1); 31 | n = 10 * n + (c - '0'); 32 | } 33 | return(n); 34 | } 35 | 36 | badcomm() 37 | { 38 | std_err("Usage: mknod name b/c major minor\n"); 39 | exit(1); 40 | } 41 | -------------------------------------------------------------------------------- /commands/mount.c: -------------------------------------------------------------------------------- 1 | /* mount - mount a file system Author: Andy Tanenbaum */ 2 | 3 | #include "errno.h" 4 | extern int errno; 5 | 6 | main(argc, argv) 7 | int argc; 8 | char *argv[]; 9 | { 10 | 11 | int ro; 12 | 13 | if (argc < 3 || argc > 4) usage(); 14 | if (argc == 4 && *argv[3] != '-' && *(argv[3]+1) != 'r') usage(); 15 | ro = (argc == 4 ? 1 : 0); 16 | if (mount(argv[1], argv[2], ro) < 0) { 17 | if (errno == EINVAL) { 18 | std_err("mount: "); 19 | std_err(argv[1]); 20 | std_err(" is not a valid file system.\n"); 21 | } else { 22 | perror("mount"); 23 | } 24 | exit(1); 25 | } 26 | std_err(argv[1]); 27 | std_err(" mounted\n"); 28 | exit(0); 29 | } 30 | 31 | 32 | usage() 33 | { 34 | std_err("Usage: mount special name [-r]\n"); 35 | exit(1); 36 | } 37 | -------------------------------------------------------------------------------- /commands/pwd.c: -------------------------------------------------------------------------------- 1 | /* pwd - print working directory Author: Adri Koppes */ 2 | 3 | #include "stat.h" 4 | 5 | struct direct { 6 | unsigned short d_ino; 7 | char d_name[14]; 8 | } 9 | main() 10 | { 11 | register int fd; 12 | register char name[128], *n; 13 | char *last_index(); 14 | struct stat s, st; 15 | struct direct d; 16 | 17 | *name = 0; 18 | stat(".", &s); 19 | do { 20 | if ((fd = open("..",0)) < 0) { 21 | prints("Can't open ..\n"); 22 | exit(1); 23 | } 24 | st.st_dev = s.st_dev; 25 | st.st_ino = s.st_ino; 26 | st.st_mode = s.st_mode; 27 | st.st_nlink = s.st_nlink; 28 | st.st_uid = s.st_uid; 29 | st.st_gid = s.st_gid; 30 | st.st_rdev = s.st_rdev; 31 | st.st_size = s.st_size; 32 | st.st_atime = s.st_atime; 33 | st.st_mtime = s.st_mtime; 34 | st.st_ctime = s.st_ctime; 35 | stat("..", &s); 36 | chdir(".."); 37 | if (s.st_dev == st.st_dev) 38 | do 39 | if (read(fd, (char *)&d, sizeof(struct direct)) < sizeof(struct direct)) { 40 | prints("Can't read ..\n"); 41 | exit(1); 42 | } 43 | while(d.d_ino != st.st_ino); 44 | else 45 | do { 46 | if (read(fd, (char *)&d, sizeof(struct direct)) < sizeof(struct direct)) { 47 | prints("Can't read ..\n"); 48 | exit(1); 49 | } 50 | stat(d.d_name, &s); 51 | } while ((s.st_dev != st.st_dev) || (s.st_ino != st.st_ino)); 52 | close(fd); 53 | if (strcmp(".",d.d_name)) { 54 | strcat(name,"/"); 55 | strcat(name,d.d_name); 56 | } 57 | } while ((s.st_ino != st.st_ino) || (s.st_dev != st.st_dev)); 58 | if (!*name) 59 | prints("/"); 60 | else 61 | while (n = last_index(name, '/')) { 62 | prints(n); 63 | *n = 0; 64 | } 65 | prints(name); 66 | prints("\n"); 67 | exit(0); 68 | } 69 | 70 | 71 | char * 72 | last_index (string, ch) 73 | register char *string; 74 | register char ch; 75 | { 76 | register char *retval = 0; 77 | 78 | for (; *string; *string++) 79 | if (*string == ch) 80 | retval = string; 81 | return (retval); 82 | } 83 | -------------------------------------------------------------------------------- /commands/rev.c: -------------------------------------------------------------------------------- 1 | /* rev - reverse an ASCII line Authors: Paul Polderman & Michiel Huisjes */ 2 | 3 | #include "blocksize.h" 4 | 5 | #ifndef NULL 6 | #define NULL 0 7 | #endif 8 | 9 | #ifndef EOF 10 | #define EOF ((char) -1) 11 | #endif 12 | 13 | 14 | int fd; /* File descriptor from file currently being read */ 15 | 16 | main(argc, argv) 17 | int argc; 18 | char *argv[]; 19 | { 20 | register unsigned short i; 21 | 22 | if (argc == 1) { /* If no arguments given, take stdin as input */ 23 | fd = 0; 24 | rev(); 25 | exit(0); 26 | } 27 | for (i = 1; i < argc; i++) { /* Reverse each line in arguments */ 28 | if ((fd = open(argv[i], 0)) < 0) { 29 | std_err("Cannot open "); 30 | std_err(argv[i]); 31 | std_err("\n"); 32 | continue; 33 | } 34 | rev(); 35 | close(fd); 36 | } 37 | exit(0); 38 | } 39 | 40 | 41 | 42 | 43 | rev() 44 | { 45 | char output[BLOCK_SIZE]; /* Contains a reversed line */ 46 | register unsigned short i; /* Index in output array */ 47 | 48 | do { 49 | i = BLOCK_SIZE - 1; 50 | while ((output[i] = nextchar()) != '\n' && output[i] != EOF) 51 | i--; 52 | write(1, &output[i + 1], BLOCK_SIZE - 1 - i); /* Write reversed line*/ 53 | if (output[i] == '\n') /* and write a '\n' */ 54 | write(1, "\n", 1); 55 | } while (output[i] != EOF); 56 | } 57 | 58 | 59 | 60 | 61 | char buf[BLOCK_SIZE]; 62 | nextchar() /* Does a sort of buffered I/O */ 63 | { 64 | static int n = 0; /* Read count */ 65 | static int i; /* Index in input buffer to next character */ 66 | 67 | if (--n <= 0) { /* We've had this block. Read in next block */ 68 | n = read(fd, buf, BLOCK_SIZE); 69 | i = 0; /* Reset index in array */ 70 | } 71 | return((n <= 0) ? EOF : buf[i++]); /* Return -1 on EOF */ 72 | } 73 | 74 | -------------------------------------------------------------------------------- /commands/rmdir.c: -------------------------------------------------------------------------------- 1 | /* rmdir - remove a directory Author: Adri Koppes */ 2 | 3 | #include "../include/signal.h" 4 | #include "../include/stat.h" 5 | 6 | struct direct { 7 | unsigned short d_ino; 8 | char d_name[14]; 9 | }; 10 | int error = 0; 11 | 12 | main (argc, argv) 13 | register int argc; 14 | register char **argv; 15 | { 16 | if (argc < 2) { 17 | prints ("Usage: rmdir dir ...\n"); 18 | exit (1); 19 | } 20 | signal (SIGHUP, SIG_IGN); 21 | signal (SIGINT, SIG_IGN); 22 | signal (SIGQUIT, SIG_IGN); 23 | signal (SIGTERM, SIG_IGN); 24 | while (--argc) 25 | remove (*++argv); 26 | if (error) 27 | exit (1); 28 | } 29 | 30 | remove (dirname) 31 | char *dirname; 32 | { 33 | struct direct d; 34 | struct stat s, 35 | cwd; 36 | register int fd = 0, sl = 0; 37 | char dots[128]; 38 | 39 | if (stat (dirname, &s)) { 40 | stderr2(dirname, " doesn't exist\n"); 41 | error++; 42 | return; 43 | } 44 | if ((s.st_mode & S_IFMT) != S_IFDIR) { 45 | stderr2(dirname, " not a directory\n"); 46 | error++; 47 | return; 48 | } 49 | strcpy (dots, dirname); 50 | while (dirname[fd]) 51 | if (dirname[fd++] == '/') 52 | sl = fd; 53 | dots[sl] = '\0'; 54 | if (access (dots, 2)) { 55 | stderr2(dirname, " no permission\n"); 56 | error++; 57 | return; 58 | } 59 | stat ("", &cwd); 60 | if ((s.st_ino == cwd.st_ino) && (s.st_dev == cwd.st_dev)) { 61 | std_err ("rmdir: can't remove current directory\n"); 62 | error++; 63 | return; 64 | } 65 | if ((fd = open (dirname, 0)) < 0) { 66 | stderr2("can't read ", dirname); 67 | std_err("\n"); 68 | error++; 69 | return; 70 | } 71 | while (read (fd, (char *) & d, sizeof (struct direct)) == sizeof (struct direct)) 72 | if (d.d_ino != 0) 73 | if (strcmp (d.d_name, ".") && strcmp (d.d_name, "..")) { 74 | stderr2(dirname, " not empty\n"); 75 | close(fd); 76 | error++; 77 | return; 78 | } 79 | close (fd); 80 | strcpy (dots, dirname); 81 | strcat (dots, "/."); 82 | unlink (dots); 83 | strcat (dots, "."); 84 | unlink (dots); 85 | if (unlink (dirname)) { 86 | stderr2("can't remove ", dirname); 87 | std_err("\n"); 88 | error++; 89 | return; 90 | } 91 | } 92 | 93 | stderr2(s1, s2) 94 | char *s1, *s2; 95 | { 96 | std_err("rmdir: "); 97 | std_err(s1); 98 | std_err(s2); 99 | } 100 | -------------------------------------------------------------------------------- /commands/shar.c: -------------------------------------------------------------------------------- 1 | /* shar - make a shell archive Author: Michiel Husijes */ 2 | 3 | 4 | #include "blocksize.h" 5 | 6 | #define IO_SIZE (10 * BLOCK_SIZE) 7 | 8 | char input[IO_SIZE]; 9 | char output[IO_SIZE]; 10 | int index = 0; 11 | 12 | main(argc, argv) 13 | int argc; 14 | register char *argv[]; 15 | { 16 | register int i; 17 | int fd; 18 | 19 | for (i = 1; i < argc; i++) { 20 | if ((fd = open(argv[i], 0)) < 0) { 21 | write(2, "Cannot open ", 12); 22 | write(2, argv[i], strlen(argv[i])); 23 | write(2, ".\n", 2); 24 | } 25 | else { 26 | print("echo x - "); 27 | print(argv[i]); 28 | print("\ngres '^X' '' > "); 29 | print(argv[i]); 30 | print(" << '/'\n"); 31 | cat(fd); 32 | } 33 | } 34 | if (index) write(1, output, index); 35 | exit(0); 36 | } 37 | 38 | cat(fd) 39 | int fd; 40 | { 41 | static char *current, *last; 42 | register int r = 0; 43 | register char *cur_pos = current; 44 | 45 | putchar('X'); 46 | for (; ;) { 47 | if (cur_pos == last) { 48 | if ((r = read(fd, input, IO_SIZE)) <= 0) 49 | break; 50 | last = &input[r]; 51 | cur_pos = input; 52 | } 53 | putchar(*cur_pos); 54 | if (*cur_pos++ == '\n' && cur_pos != last) 55 | putchar('X'); 56 | } 57 | print("/\n"); 58 | (void) close(fd); 59 | current = cur_pos; 60 | } 61 | 62 | print(str) 63 | register char *str; 64 | { 65 | while (*str) 66 | putchar(*str++); 67 | } 68 | 69 | putchar(c) 70 | register char c; 71 | { 72 | output[index++] = c; 73 | if (index == IO_SIZE) { 74 | write(1, output, index); 75 | index = 0; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /commands/size.c: -------------------------------------------------------------------------------- 1 | /* size - tell size of an object file Author: Andy Tanenbaum */ 2 | 3 | #define HLONG 8 /* # longs in the header */ 4 | #define TEXT 2 5 | #define DATA 3 6 | #define BSS 4 7 | #define CHMEM 6 8 | #define MAGIC 0x0301 /* magic number for an object file */ 9 | #define SEPBIT 0x00200000 /* this bit is set for separate I/D */ 10 | 11 | int heading; /* set when heading printed */ 12 | int error; 13 | 14 | main(argc, argv) 15 | int argc; 16 | char *argv[]; 17 | { 18 | int i; 19 | 20 | if (argc == 1) { 21 | size("a.out"); 22 | exit(error); 23 | } 24 | 25 | for (i = 1; i < argc; i++) size(argv[i]); 26 | exit(error); 27 | } 28 | 29 | 30 | 31 | size(name) 32 | char *name; 33 | { 34 | int fd, separate; 35 | long head[HLONG], dynam, allmem; 36 | 37 | if ( (fd = open(name, 0)) < 0) { 38 | stderr3("size: can't open ", name, "\n"); 39 | return; 40 | } 41 | 42 | if (read(fd, head, sizeof(head)) != sizeof(head) ) { 43 | stderr3("size: ", name, ": header too short\n"); 44 | error = 1; 45 | close(fd); 46 | return; 47 | } 48 | 49 | if ( (head[0] & 0xFFFF) != MAGIC) { 50 | stderr3("size: ", name, " not an object file\n"); 51 | close(fd); 52 | return; 53 | } 54 | 55 | separate = (head[0] & SEPBIT ? 1 : 0); 56 | dynam = head[CHMEM] - head[TEXT] - head[DATA] - head[BSS]; 57 | if (separate) dynam += head[TEXT]; 58 | allmem = (separate ? head[CHMEM] + head[TEXT] : head[CHMEM]); 59 | if (heading++ == 0) 60 | prints(" text\t data\t bss\t stack\tmemory\n"); 61 | printf("%6D\t%6D\t%6D\t%6D\t%6D\t%s\n",head[TEXT], head[DATA], head[BSS], 62 | dynam, allmem, name); 63 | close(fd); 64 | } 65 | 66 | stderr3(s1, s2, s3) 67 | char *s1, *s2, *s3; 68 | { 69 | std_err(s1); 70 | std_err(s2); 71 | std_err(s3); 72 | error = 1; 73 | } 74 | -------------------------------------------------------------------------------- /commands/sleep.c: -------------------------------------------------------------------------------- 1 | /* sleep - suspend a process for x sec Author: Andy Tanenbaum */ 2 | 3 | main(argc, argv) 4 | int argc; 5 | char *argv[]; 6 | { 7 | register seconds; 8 | register char c; 9 | 10 | seconds = 0; 11 | 12 | if (argc != 2) { 13 | std_err("Usage: sleep time\n"); 14 | exit(1); 15 | } 16 | 17 | while (c = *(argv[1])++) { 18 | if (c < '0' || c > '9') { 19 | std_err("sleep: bad arg\n"); 20 | exit(1); 21 | } 22 | seconds = 10 * seconds + (c - '0'); 23 | } 24 | 25 | /* Now sleep. */ 26 | sleep(seconds); 27 | exit(0); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /commands/split.c: -------------------------------------------------------------------------------- 1 | /* split - split a file Author: Michiel Huisjes */ 2 | 3 | #include "blocksize.h" 4 | 5 | int cut_line = 1000; 6 | int infile; 7 | char out_file[100]; 8 | char *suffix; 9 | 10 | main(argc, argv) 11 | int argc; 12 | char **argv; 13 | { 14 | unsigned short i; 15 | 16 | out_file[0] = 'x'; 17 | infile = -1; 18 | 19 | if (argc > 4) 20 | usage(); 21 | for (i = 1; i < argc; i++) { 22 | if (argv[i][0] == '-') { 23 | if (argv[i][1] >= '0' && argv[i][1] <= '9' 24 | && cut_line == 1000) 25 | cut_line = atoi(argv[i]); 26 | else if (argv[i][1] == '\0' && infile == -1) 27 | infile = 0; 28 | else 29 | usage(); 30 | } 31 | else if (infile == -1) { 32 | if ((infile = open(argv[i], 0)) < 0) { 33 | std_err("Cannot open input file.\n"); 34 | exit (1); 35 | } 36 | } 37 | else 38 | strcpy(out_file, argv[i]); 39 | } 40 | if (infile == -1) 41 | infile = 0; 42 | strcat(out_file, "aa"); 43 | for (suffix = out_file; *suffix; suffix++) 44 | ; 45 | suffix--; 46 | /* Appendix now points to last `a' of "aa". We have to decrement it by one */ 47 | *suffix = 'a' - 1; 48 | split(); 49 | exit(0); 50 | } 51 | 52 | split() 53 | { 54 | char buf[BLOCK_SIZE]; 55 | register char *index, *base; 56 | register int n; 57 | int fd; 58 | long lines = 0L; 59 | 60 | fd = newfile(); 61 | while ((n = read(infile, buf, BLOCK_SIZE)) > 0) { 62 | base = index = buf; 63 | while (--n >= 0) { 64 | if (*index++ == '\n') 65 | if (++lines % cut_line == 0) { 66 | if (write(fd, base, index-base) != index-base) 67 | quit(); 68 | base = index; 69 | close(fd); 70 | fd = newfile(); 71 | } 72 | } 73 | if (write(fd, base, index - base) != index - base) quit(); 74 | } 75 | } 76 | 77 | newfile() 78 | { 79 | int fd; 80 | 81 | if (++*suffix > 'z') { /* Increment letter */ 82 | *suffix = 'a'; /* Reset last letter */ 83 | ++*(suffix - 1); /* Previous letter must be incremented*/ 84 | /* E.g. was `filename.az' */ 85 | /* Now `filename.ba' */ 86 | } 87 | if ((fd = creat(out_file, 0644)) < 0) { 88 | std_err("Cannot create new file.\n"); 89 | exit(2); 90 | } 91 | return fd; 92 | } 93 | 94 | usage () 95 | { 96 | std_err("Usage: split [-n] [file [name]].\n"); 97 | exit(1); 98 | } 99 | 100 | quit() 101 | { 102 | std_err("split: write error\n"); 103 | exit(1); 104 | } 105 | -------------------------------------------------------------------------------- /commands/su.c: -------------------------------------------------------------------------------- 1 | /* su - become super-user Author: Patrick van Kleef */ 2 | 3 | #include "sgtty.h" 4 | #include "stdio.h" 5 | #include "pwd.h" 6 | 7 | main (argc, argv) 8 | int argc; 9 | char *argv[]; 10 | { 11 | register char *name; 12 | char *crypt (); 13 | char *shell = "/bin/sh"; 14 | int nr; 15 | char password[14]; 16 | struct sgttyb args; 17 | register struct passwd *pwd; 18 | struct passwd *getpwnam (); 19 | 20 | if (argc > 1) 21 | name = argv[1]; 22 | else 23 | name = "root"; 24 | 25 | if ((pwd = getpwnam (name)) == 0) { 26 | std_err("Unknown id: "); 27 | std_err(name); 28 | std_err("\n"); 29 | exit (1); 30 | } 31 | 32 | if (pwd->pw_passwd[0] != '\0' && getuid()!= 0) { 33 | std_err("Password: "); 34 | ioctl (0, TIOCGETP, &args); /* get parameters */ 35 | args.sg_flags = args.sg_flags & (~ECHO); 36 | ioctl (0, TIOCSETP, &args); 37 | nr = read (0, password, 14); 38 | password[nr - 1] = 0; 39 | putc('\n',stderr); 40 | args.sg_flags = args.sg_flags | ECHO; 41 | ioctl (0, TIOCSETP, &args); 42 | if (strcmp (pwd->pw_passwd, crypt (password, pwd->pw_passwd))) { 43 | std_err("Sorry\n"); 44 | exit (2); 45 | } 46 | } 47 | setgid (pwd->pw_gid); 48 | setuid (pwd->pw_uid); 49 | if (pwd->pw_shell[0]) 50 | shell = pwd->pw_shell; 51 | execn (shell); 52 | std_err("No shell\n"); 53 | exit (3); 54 | } 55 | -------------------------------------------------------------------------------- /commands/sum.c: -------------------------------------------------------------------------------- 1 | /* sum - checksum a file Author: Martin C. Atkins */ 2 | 3 | /* 4 | * This program was written by: 5 | * Martin C. Atkins, 6 | * University of York, 7 | * Heslington, 8 | * York. Y01 5DD 9 | * England 10 | * and is released into the public domain, on the condition 11 | * that this comment is always included without alteration. 12 | */ 13 | 14 | #define BUFSIZ (512) 15 | 16 | int rc = 0; 17 | 18 | char *defargv[] = { "-", 0 }; 19 | 20 | main(argc,argv) 21 | int argc; 22 | char *argv[]; 23 | { 24 | int fd; 25 | 26 | if (*++argv == 0) 27 | argv = defargv; 28 | for (; *argv; argv++) { 29 | if (argv[0][0] == '-' && argv[0][1] == '\0') 30 | fd = 0; 31 | else 32 | fd = open(*argv, 0); 33 | 34 | if (fd == -1) { 35 | error("can't open ",*argv); 36 | rc = 1; 37 | continue; 38 | } 39 | sum(fd, (argc > 2) ? *argv : (char *)0); 40 | if (fd != 0) close(fd); 41 | } 42 | exit(rc); 43 | } 44 | 45 | error(s,f) 46 | char *s,*f; 47 | { 48 | 49 | std_err("sum: "); 50 | std_err(s); 51 | 52 | if (f) std_err(f); 53 | std_err("\n"); 54 | } 55 | 56 | sum(fd,fname) 57 | int fd; 58 | char *fname; 59 | { 60 | char buf[BUFSIZ]; 61 | int i,n; 62 | int size = 0; 63 | unsigned crc = 0; 64 | unsigned tmp; 65 | 66 | while((n = read(fd,buf,BUFSIZ)) > 0) { 67 | for (i = 0; i < n; i++) { 68 | crc = (crc>>1) + ((crc&1) ? 0x8000 : 0); 69 | tmp = buf[i] & 0377; 70 | crc += tmp; 71 | crc &= 0xffff; 72 | size++; 73 | } 74 | } 75 | 76 | if (n < 0) { 77 | if (fname) 78 | error("read error on ", fname); 79 | else 80 | error("read error", (char *)0); 81 | rc = 1; 82 | return; 83 | } 84 | putd(crc,5,1); 85 | putd((size+BUFSIZ-1)/BUFSIZ, 6, 0); 86 | if (fname) prints(" %s", fname); 87 | prints("\n"); 88 | } 89 | 90 | putd(number, fw, zeros) 91 | int number,fw,zeros; 92 | { 93 | /* Put a decimal number, in a field width, to stdout. */ 94 | 95 | char buf[10]; 96 | int n; 97 | unsigned num; 98 | 99 | num = (unsigned) number; 100 | for (n = 0; n < fw; n++) { 101 | if (num || n == 0) { 102 | buf[fw-n-1] = '0' + num%10; 103 | num /= 10; 104 | } else 105 | buf[fw-n-1] = zeros ? '0' : ' '; 106 | } 107 | buf[fw] = 0; 108 | prints("%s", buf); 109 | } 110 | -------------------------------------------------------------------------------- /commands/sync.c: -------------------------------------------------------------------------------- 1 | /* sync - flush the file system buffers. Author: Andy Tanenbaum */ 2 | 3 | main() {sync();} /* First prize in shortest useful program contest. */ 4 | -------------------------------------------------------------------------------- /commands/tee.c: -------------------------------------------------------------------------------- 1 | /* tee - pipe fitting Author: Paul Polderman */ 2 | 3 | #include "blocksize.h" 4 | #include "signal.h" 5 | 6 | #define MAXFD 18 7 | 8 | int fd[MAXFD]; 9 | 10 | main(argc, argv) 11 | int argc; 12 | char **argv; 13 | { 14 | char iflag = 0, aflag = 0; 15 | char buf[BLOCK_SIZE]; 16 | int i, s, n; 17 | 18 | argv++; --argc; 19 | while (argc > 0 && argv[0][0] == '-') { 20 | switch (argv[0][1]) { 21 | case 'i': /* Interrupt turned off. */ 22 | iflag++; 23 | break; 24 | case 'a': /* Append to outputfile(s), 25 | * instead of overwriting them. 26 | */ 27 | aflag++; 28 | break; 29 | default: 30 | std_err("Usage: tee [-i] [-a] [files].\n"); 31 | exit(1); 32 | } 33 | argv++; 34 | --argc; 35 | } 36 | fd[0] = 1; /* Always output to stdout. */ 37 | for (s = 1; s < MAXFD && argc > 0; --argc, argv++) { 38 | if ((fd[s] = open(*argv, 2)) < 0 && 39 | (fd[s] = creat(*argv, 0666)) < 0) { 40 | std_err("Cannot open output file: "); 41 | std_err(*argv); 42 | std_err("\n"); 43 | exit(2); 44 | } 45 | s++; 46 | } 47 | 48 | if (iflag) 49 | signal(SIGINT, SIG_IGN); 50 | for (i = 1; i < s; i++) { /* Don't lseek stdout. */ 51 | if (aflag) 52 | lseek(fd[i], 0L, 2); 53 | } 54 | 55 | while ((n = read(0, buf, BLOCK_SIZE)) > 0) { 56 | for (i = 0; i < s; i++) 57 | write(fd[i], buf, n); 58 | } 59 | 60 | for (i = 0; i < s; i++) /* Close all fd's */ 61 | close(fd[i]); 62 | exit(0); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /commands/touch.c: -------------------------------------------------------------------------------- 1 | 2 | #include "stat.h" 3 | #include "errno.h" 4 | int no_creat = 0; 5 | 6 | main(argc,argv) 7 | int argc; 8 | char *argv[]; 9 | { 10 | char *path; 11 | int i =1; 12 | 13 | if (argc == 1) usage(); 14 | while ( i < argc ) { 15 | if (argv[i][0] == '-') { 16 | if (argv[i][1] == 'f') { 17 | i+=1; 18 | } else if (argv[i][1] == 'c') { 19 | no_creat = 1; 20 | i+=1; 21 | } else { 22 | usage(); 23 | } 24 | } else { 25 | path=argv[i]; 26 | i+=1; 27 | if (doit(path) > 0) { 28 | std_err("touch: cannot touch "); 29 | std_err(path); 30 | std_err("\n"); 31 | } 32 | } 33 | } 34 | exit(0); 35 | } 36 | 37 | 38 | doit(name) 39 | char *name; 40 | { 41 | int fd; 42 | long *t, tim; 43 | struct stat buf; 44 | unsigned short tmp; 45 | long tvp[2]; 46 | extern long time(); 47 | 48 | if (!access(name,0)) { /* change date if possible */ 49 | stat(name, &buf); 50 | tmp = (buf.st_mode & S_IFREG); 51 | if (tmp != S_IFREG) return(1); 52 | 53 | tim = time(0L); 54 | tvp[0] = tim; 55 | tvp[1] = tim; 56 | if (!utime(name,tvp)) 57 | return(0); 58 | else 59 | return(1); 60 | 61 | } else { 62 | /* file does not exist */ 63 | if (no_creat == 1) 64 | return(0); 65 | else if ( (fd = creat(name, 0777)) < 0) { 66 | return(1); 67 | } else { 68 | close(fd); 69 | return(0); 70 | } 71 | } 72 | } 73 | 74 | 75 | usage() 76 | { 77 | std_err("Usage: touch [-c] file...\n"); 78 | exit(1); 79 | } 80 | 81 | std_err(s) 82 | { prints("%s",s); 83 | } 84 | -------------------------------------------------------------------------------- /commands/umount.c: -------------------------------------------------------------------------------- 1 | /* umount - unmount a file system Author: Andy Tanenbaum */ 2 | 3 | #include "errno.h" 4 | 5 | extern int errno; 6 | 7 | main(argc, argv) 8 | int argc; 9 | char *argv[]; 10 | { 11 | 12 | if (argc != 2) usage(); 13 | if (umount(argv[1]) < 0) { 14 | if (errno == EINVAL) 15 | std_err("Device not mounted\n"); 16 | else 17 | perror("umount"); 18 | exit(1); 19 | } 20 | std_err(argv[1]); 21 | std_err(" unmounted\n"); 22 | exit(0); 23 | } 24 | 25 | usage() 26 | { 27 | std_err("Usage: umount special\n"); 28 | exit(1); 29 | } 30 | -------------------------------------------------------------------------------- /commands/update.c: -------------------------------------------------------------------------------- 1 | /* update - do sync periodically Author: Andy Tanenbaum */ 2 | 3 | #include "signal.h" 4 | 5 | main() 6 | { 7 | int fd, buf[2]; 8 | 9 | 10 | /* Disable SIGTERM */ 11 | signal(SIGTERM, SIG_IGN); 12 | 13 | /* Open some files to hold their inodes in core. */ 14 | close(0); 15 | close(1); 16 | close(2); 17 | 18 | open("/bin", 0); 19 | open("/lib", 0); 20 | open("/etc", 0); 21 | open("/tmp", 0); 22 | 23 | 24 | /* Flush the cache every 30 seconds. */ 25 | while (1) { 26 | sync(); 27 | sleep(30); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /commands/x.c: -------------------------------------------------------------------------------- 1 | char buf[30000]; 2 | main() 3 | { 4 | int i, n; 5 | 6 | while(1) { 7 | n = read(0, buf,30000); 8 | for (i=0; ifs.lst 4 | dos2out -d fs >>fs.lst 5 | echo/ 6 | echo FS done. Check the .lst-files for errors. 7 | pause 8 | echo on 9 | for %%f in (*.lst) do type %%f 10 | -------------------------------------------------------------------------------- /fs/c86/linklist: -------------------------------------------------------------------------------- 1 | main+open+read+write+pipe+device+path+ 2 | mount+link+super+inode+cache+filedes+stadir+ 3 | protect+time+misc+utility+table+putc 4 | fs 5 | fs 6 | ..\lib\mxc86 7 | 8 | -------------------------------------------------------------------------------- /fs/dev.h: -------------------------------------------------------------------------------- 1 | /* Device table. This table is indexed by major device number. It provides 2 | * the link between major device numbers and the routines that process them. 3 | */ 4 | 5 | EXTERN struct dmap { 6 | int (*dmap_open)(); 7 | int (*dmap_rw)(); 8 | int (*dmap_close)(); 9 | int dmap_task; 10 | } dmap[]; 11 | 12 | -------------------------------------------------------------------------------- /fs/file.h: -------------------------------------------------------------------------------- 1 | /* This is the filp table. It is an intermediary between file descriptors and 2 | * inodes. A slot is free if filp_count == 0. 3 | */ 4 | 5 | EXTERN struct filp { 6 | mask_bits filp_mode; /* RW bits, telling how file is opened */ 7 | int filp_count; /* how many file descriptors share this slot? */ 8 | struct inode *filp_ino; /* pointer to the inode */ 9 | file_pos filp_pos; /* file position */ 10 | } filp[NR_FILPS]; 11 | 12 | #define NIL_FILP (struct filp *) 0 /* indicates absence of a filp slot */ 13 | -------------------------------------------------------------------------------- /fs/fproc.h: -------------------------------------------------------------------------------- 1 | /* This is the per-process information. A slot is reserved for each potential 2 | * process. Thus NR_PROCS must be the same as in the kernel. It is not possible 3 | * or even necessary to tell when a slot is free here. 4 | */ 5 | 6 | EXTERN struct fproc { 7 | mask_bits fp_umask; /* mask set by umask system call */ 8 | struct inode *fp_workdir; /* pointer to working directory's inode */ 9 | struct inode *fp_rootdir; /* pointer to current root dir (see chroot) */ 10 | struct filp *fp_filp[NR_FDS]; /* the file descriptor table */ 11 | uid fp_realuid; /* real user id */ 12 | uid fp_effuid; /* effective user id */ 13 | gid fp_realgid; /* real group id */ 14 | gid fp_effgid; /* effective group id */ 15 | dev_nr fs_tty; /* major/minor of controlling tty */ 16 | int fp_fd; /* place to save fd if rd/wr can't finish */ 17 | char *fp_buffer; /* place to save buffer if rd/wr can't finish */ 18 | int fp_nbytes; /* place to save bytes if rd/wr can't finish */ 19 | char fp_suspended; /* set to indicate process hanging */ 20 | char fp_revived; /* set to indicate process being revived */ 21 | char fp_task; /* which task is proc suspended on */ 22 | } fproc[NR_PROCS]; 23 | 24 | /* Field values. */ 25 | #define NOT_SUSPENDED 0 /* process is not suspended on pipe or task */ 26 | #define SUSPENDED 1 /* process is suspended on pipe or task */ 27 | #define NOT_REVIVING 0 /* process is not being revived */ 28 | #define REVIVING 1 /* process is being revived from suspension */ 29 | -------------------------------------------------------------------------------- /fs/glo.h: -------------------------------------------------------------------------------- 1 | /* File System global variables */ 2 | EXTERN struct fproc *fp; /* pointer to caller's fproc struct */ 3 | EXTERN int super_user; /* 1 if caller is super_user, else 0 */ 4 | EXTERN int dont_reply; /* normally 0; set to 1 to inhibit reply */ 5 | EXTERN int susp_count; /* number of procs suspended on pipe */ 6 | EXTERN int reviving; /* number of pipe processes to be revived */ 7 | EXTERN file_pos rdahedpos; /* position to read ahead */ 8 | EXTERN struct inode *rdahed_inode; /* pointer to inode to read ahead */ 9 | 10 | /* The parameters of the call are kept here. */ 11 | EXTERN message m; /* the input message itself */ 12 | EXTERN message m1; /* the output message used for reply */ 13 | EXTERN int who; /* caller's proc number */ 14 | EXTERN int fs_call; /* system call number */ 15 | EXTERN char user_path[MAX_PATH];/* storage for user path name */ 16 | 17 | /* The following variables are used for returning results to the caller. */ 18 | EXTERN int err_code; /* temporary storage for error number */ 19 | 20 | EXTERN char fstack[FS_STACK_BYTES]; /* the File System's stack. */ 21 | -------------------------------------------------------------------------------- /fs/inode.h: -------------------------------------------------------------------------------- 1 | /* Inode table. This table holds inodes that are currently in use. In some 2 | * cases they have been opened by an open() or creat() system call, in other 3 | * cases the file system itself needs the inode for one reason or another, 4 | * such as to search a directory for a path name. 5 | * The first part of the struct holds fields that are present on the 6 | * disk; the second part holds fields not present on the disk. 7 | * The disk inode part is also declared in "type.h" as 'd_inode'. 8 | */ 9 | 10 | EXTERN struct inode { 11 | unshort i_mode; /* file type, protection, etc. */ 12 | uid i_uid; /* user id of the file's owner */ 13 | file_pos i_size; /* current file size in bytes */ 14 | real_time i_modtime; /* when was file data last changed */ 15 | gid i_gid; /* group number */ 16 | links i_nlinks; /* how many links to this file */ 17 | zone_nr i_zone[NR_ZONE_NUMS]; /* zone numbers for direct, ind, and dbl ind */ 18 | 19 | /* The following items are not present on the disk. */ 20 | dev_nr i_dev; /* which device is the inode on */ 21 | inode_nr i_num; /* inode number on its (minor) device */ 22 | short int i_count; /* # times inode used; 0 means slot is free */ 23 | char i_dirt; /* CLEAN or DIRTY */ 24 | char i_pipe; /* set to I_PIPE if pipe */ 25 | char i_mount; /* this bit is set if file mounted on */ 26 | char i_seek; /* set on LSEEK, cleared on READ/WRITE */ 27 | } inode[NR_INODES]; 28 | 29 | 30 | #define NIL_INODE (struct inode *) 0 /* indicates absence of inode slot */ 31 | 32 | /* Field values. Note that CLEAN and DIRTY are defined in "const.h" */ 33 | #define NO_PIPE 0 /* i_pipe is NO_PIPE if inode is not a pipe */ 34 | #define I_PIPE 1 /* i_pipe is I_PIPE if inode is a pipe */ 35 | #define NO_MOUNT 0 /* i_mount is NO_MOUNT if file not mounted on */ 36 | #define I_MOUNT 1 /* i_mount is I_MOUNT if file mounted on */ 37 | #define NO_SEEK 0 /* i_seek = NO_SEEK if last op was not SEEK */ 38 | #define ISEEK 1 /* i_seek = ISEEK if last op was SEEK */ 39 | -------------------------------------------------------------------------------- /fs/param.h: -------------------------------------------------------------------------------- 1 | /* The following names are synonyms for the variables in the input message. */ 2 | #define acc_time m.m2_l1 3 | #define addr m.m1_i3 4 | #define buffer m.m1_p1 5 | #define cd_flag m.m1_i2 6 | #define child m.m1_i2 7 | #define co_mode m.m1_i1 8 | #define eff_grp_id m.m1_i3 9 | #define eff_user_id m.m1_i3 10 | #define erki m.m1_p1 11 | #define fd m.m1_i1 12 | #define fd2 m.m1_i2 13 | #define ioflags m.m1_i3 14 | #define group m.m1_i3 15 | #define real_grp_id m.m1_i2 16 | #define ls_fd m.m2_i1 17 | #define mk_mode m.m1_i2 18 | #define mode m.m3_i2 19 | #define name m.m3_p1 20 | #define name1 m.m1_p1 21 | #define name2 m.m1_p2 22 | #define name_length m.m3_i1 23 | #define name1_length m.m1_i1 24 | #define name2_length m.m1_i2 25 | #define nbytes m.m1_i2 26 | #define offset m.m2_l1 27 | #define owner m.m1_i2 28 | #define parent m.m1_i1 29 | #define pathname m.m3_ca1 30 | #define pro m.m1_i1 31 | #define rd_only m.m1_i3 32 | #define real_user_id m.m1_i2 33 | #define request m.m1_i2 34 | #define sig m.m1_i2 35 | #define slot1 m.m1_i1 36 | #define tp m.m2_l1 37 | #define update_time m.m2_l2 38 | #define utime_file m.m2_p1 39 | #define utime_length m.m2_i1 40 | #define whence m.m2_i2 41 | 42 | /* The following names are synonyms for the variables in the output message. */ 43 | #define reply_type m1.m_type 44 | #define reply_l1 m1.m2_l1 45 | #define reply_i1 m1.m1_i1 46 | #define reply_i2 m1.m1_i2 47 | #define reply_t1 m1.m4_l1 48 | #define reply_t2 m1.m4_l2 49 | #define reply_t3 m1.m4_l3 50 | #define reply_t4 m1.m4_l4 51 | -------------------------------------------------------------------------------- /fs/putc.c: -------------------------------------------------------------------------------- 1 | /* FS must occasionally print some message. It uses the standard library 2 | * routine printf(), which calls putc() and flush. Library 3 | * versions of these routines do printing by sending messages to FS. Here 4 | * obviously can't do that, so FS calls the TTY task directly. 5 | */ 6 | 7 | #include "../h/const.h" 8 | #include "../h/type.h" 9 | #include "../h/com.h" 10 | 11 | #define STDOUTPUT 1 /* file descriptor for standard output */ 12 | #define BUFSIZE 100 /* print buffer size */ 13 | 14 | PRIVATE int bufcount; /* # characters in the buffer */ 15 | PRIVATE char printbuf [BUFSIZE]; /* output is buffered here */ 16 | PRIVATE message putchmsg; /* used for message to TTY task */ 17 | 18 | /*===========================================================================* 19 | * putc * 20 | *===========================================================================*/ 21 | PUBLIC putc(c) 22 | char c; 23 | { 24 | 25 | if (c == 0) { 26 | flush(); 27 | return; 28 | } 29 | printbuf[bufcount++] = c; 30 | if (bufcount == BUFSIZE) flush(); 31 | if (c == '\n') flush(); 32 | } 33 | 34 | 35 | /*===========================================================================* 36 | * flush * 37 | *===========================================================================*/ 38 | PRIVATE flush() 39 | { 40 | /* Flush the print buffer. */ 41 | 42 | 43 | if (bufcount == 0) return; 44 | putchmsg.m_type = TTY_WRITE; 45 | putchmsg.PROC_NR = 1; 46 | putchmsg.TTY_LINE = 0; 47 | putchmsg.ADDRESS = printbuf; 48 | putchmsg.COUNT = bufcount; 49 | sendrec(TTY, &putchmsg); 50 | bufcount = 0; 51 | } 52 | -------------------------------------------------------------------------------- /fs/super.h: -------------------------------------------------------------------------------- 1 | /* Super block table. The root file system and every mounted file system 2 | * has an entry here. The entry holds information about the sizes of the bit 3 | * maps and inodes. The s_ninodes field gives the number of inodes available 4 | * for files and directories, including the root directory. Inode 0 is 5 | * on the disk, but not used. Thus s_ninodes = 4 means that 5 bits will be 6 | * used in the bit map, bit 0, which is always 1 and not used, and bits 1-4 7 | * for files and directories. The disk layout is: 8 | * 9 | * Item # blocks 10 | * boot block 1 11 | * super block 1 12 | * inode map s_imap_blocks 13 | * zone map s_zmap_blocks 14 | * inodes (s_ninodes + 1 + INODES_PER_BLOCK - 1)/INODES_PER_BLOCK 15 | * unused whatever is needed to fill out the current zone 16 | * data zones (s_nzones - s_firstdatazone) << s_log_zone_size 17 | * 18 | * A super_block slot is free if s_dev == NO_DEV. 19 | */ 20 | 21 | 22 | EXTERN struct super_block { 23 | inode_nr s_ninodes; /* # usable inodes on the minor device */ 24 | zone_nr s_nzones; /* total device size, including bit maps etc */ 25 | unshort s_imap_blocks; /* # of blocks used by inode bit map */ 26 | unshort s_zmap_blocks; /* # of blocks used by zone bit map */ 27 | zone_nr s_firstdatazone; /* number of first data zone */ 28 | short int s_log_zone_size; /* log2 of blocks/zone */ 29 | file_pos s_max_size; /* maximum file size on this device */ 30 | int s_magic; /* magic number to recognize super-blocks */ 31 | 32 | /* The following items are only used when the super_block is in memory. */ 33 | struct buf *s_imap[I_MAP_SLOTS]; /* pointers to the in-core inode bit map */ 34 | struct buf *s_zmap[ZMAP_SLOTS]; /* pointers to the in-core zone bit map */ 35 | dev_nr s_dev; /* whose super block is this? */ 36 | struct inode *s_isup; /* inode for root dir of mounted file sys */ 37 | struct inode *s_imount; /* inode mounted on */ 38 | real_time s_time; /* time of last update */ 39 | char s_rd_only; /* set to 1 iff file sys mounted read only */ 40 | char s_dirt; /* CLEAN or DIRTY */ 41 | } super_block[NR_SUPERS]; 42 | 43 | #define NIL_SUPER (struct super_block *) 0 44 | -------------------------------------------------------------------------------- /fs/type.h: -------------------------------------------------------------------------------- 1 | /* Type definitions local to the File System. */ 2 | 3 | typedef struct { /* directory entry */ 4 | inode_nr d_inum; /* inode number */ 5 | char d_name[NAME_SIZE]; /* character string */ 6 | } dir_struct; 7 | 8 | /* Declaration of the disk inode used in rw_inode(). */ 9 | typedef struct { /* disk inode. Memory inode is in "inotab.h" */ 10 | mask_bits i_mode; /* file type, protection, etc. */ 11 | uid i_uid; /* user id of the file's owner */ 12 | file_pos i_size; /* current file size in bytes */ 13 | real_time i_modtime; /* when was file data last changed */ 14 | gid i_gid; /* group number */ 15 | links i_nlinks; /* how many links to this file */ 16 | zone_nr i_zone[NR_ZONE_NUMS]; /* block nums for direct, ind, and dbl ind */ 17 | } d_inode; 18 | -------------------------------------------------------------------------------- /h/callnr.h: -------------------------------------------------------------------------------- 1 | #define NCALLS 69 /* number of system calls allowed */ 2 | 3 | #define EXIT 1 4 | #define FORK 2 5 | #define READ 3 6 | #define WRITE 4 7 | #define OPEN 5 8 | #define CLOSE 6 9 | #define WAIT 7 10 | #define CREAT 8 11 | #define LINK 9 12 | #define UNLINK 10 13 | #define CHDIR 12 14 | #define TIME 13 15 | #define MKNOD 14 16 | #define CHMOD 15 17 | #define CHOWN 16 18 | #define BRK 17 19 | #define STAT 18 20 | #define LSEEK 19 21 | #define GETPID 20 22 | #define MOUNT 21 23 | #define UMOUNT 22 24 | #define SETUID 23 25 | #define GETUID 24 26 | #define STIME 25 27 | #define ALARM 27 28 | #define FSTAT 28 29 | #define PAUSE 29 30 | #define UTIME 30 31 | #define ACCESS 33 32 | #define SYNC 36 33 | #define KILL 37 34 | #define DUP 41 35 | #define PIPE 42 36 | #define TIMES 43 37 | #define SETGID 46 38 | #define GETGID 47 39 | #define SIGNAL 48 40 | #define IOCTL 54 41 | #define EXEC 59 42 | #define UMASK 60 43 | #define CHROOT 61 44 | 45 | /* The following are not system calls, but are processed like them. */ 46 | #define KSIG 64 /* kernel detected a signal */ 47 | #define UNPAUSE 65 /* to MM or FS: check for EINTR */ 48 | #define BRK2 66 /* to MM: used to say how big FS & INIT are */ 49 | #define REVIVE 67 /* to FS: revive a sleeping process */ 50 | #define TASK_REPLY 68 /* to FS: reply code from tty task */ 51 | -------------------------------------------------------------------------------- /h/error.h: -------------------------------------------------------------------------------- 1 | /* Error codes. They are negative since a few system calls, such as READ, can 2 | * either return a positive number indicating success, or an error code. 3 | */ 4 | 5 | #define NERROR 34 6 | #define OK 0 7 | #define ERROR -1 8 | #define EPERM -1 9 | #define ENOENT -2 10 | #define ESRCH -3 11 | #define EINTR -4 12 | #define EIO -5 13 | #define ENXIO -6 14 | #define E2BIG -7 15 | #define ENOEXEC -8 16 | #define EBADF -9 17 | #define ECHILD -10 18 | #define EAGAIN -11 19 | #define ENOMEM -12 20 | #define EACCES -13 21 | #define EFAULT -14 22 | #define ENOTBLK -15 23 | #define EBUSY -16 24 | #define EEXIST -17 25 | #define EXDEV -18 26 | #define ENODEV -19 27 | #define ENOTDIR -20 28 | #define EISDIR -21 29 | #define EINVAL -22 30 | #define ENFILE -23 31 | #define EMFILE -24 32 | #define ENOTTY -25 33 | #define ETXTBSY -26 34 | #define EFBIG -27 35 | #define ENOSPC -28 36 | #define ESPIPE -29 37 | #define EROFS -30 38 | #define EMLINK -31 39 | #define EPIPE -32 40 | #define EDOM -33 41 | #define ERANGE -34 42 | 43 | #define E_LOCKED -101 44 | #define E_BAD_CALL -102 45 | #define E_LONG_STRING -103 46 | #define EOF -104 /* End Of File - used by drivers */ 47 | 48 | /* The following error codes are generated by the kernel itself. */ 49 | #define E_BAD_DEST -1 /* destination address illegal */ 50 | #define E_BAD_SRC -2 /* source address illegal */ 51 | #define E_TRY_AGAIN -3 /* can't send-- tables full */ 52 | #define E_OVERRUN -4 /* interrupt for task that is not waiting */ 53 | #define E_BAD_BUF -5 /* message buf outside caller's addr space */ 54 | #define E_TASK -6 /* can't send to task */ 55 | #define E_NO_MESSAGE -7 /* RECEIVE failed: no message present */ 56 | #define E_NO_PERM -8 /* ordinary users can't send to tasks */ 57 | #define E_BAD_FCN -9 /* only valid fcns are SEND, RECEIVE, BOTH */ 58 | #define E_BAD_ADDR -10 /* bad address given to utility routine */ 59 | #define E_BAD_PROC -11 /* bad proc number given to utility */ 60 | -------------------------------------------------------------------------------- /h/sgtty.h: -------------------------------------------------------------------------------- 1 | /* Data structures for IOCTL. */ 2 | 3 | struct sgttyb { 4 | char sg_ispeed; /* input speed (not used) */ 5 | char sg_ospeed; /* output speed (not used) */ 6 | char sg_erase; /* erase character */ 7 | char sg_kill; /* kill character */ 8 | int sg_flags; /* mode flags */ 9 | }; 10 | 11 | struct tchars { 12 | char t_intrc; /* SIGINT char */ 13 | char t_quitc; /* SIGQUIT char */ 14 | char t_startc; /* start output (initially CTRL-Q) */ 15 | char t_stopc; /* stop output (initially CTRL-S) */ 16 | char t_eofc; /* EOF (initially CTRL-D) */ 17 | char t_brkc; /* input delimiter (like nl) */ 18 | }; 19 | 20 | /* Fields in t_flags. */ 21 | #define XTABS 0006000 /* do tab expansion */ 22 | #define RAW 0000040 /* enable raw mode */ 23 | #define CRMOD 0000020 /* map lf to cr + lf */ 24 | #define ECHO 0000010 /* echo input */ 25 | #define CBREAK 0000002 /* enable cbreak mode */ 26 | #define COOKED 0000000 /* neither CBREAK nor RAW */ 27 | 28 | #define TIOCGETP (('t'<<8) | 8) 29 | #define TIOCSETP (('t'<<8) | 9) 30 | #define TIOCGETC (('t'<<8) | 18) 31 | #define TIOCSETC (('t'<<8) | 17) 32 | -------------------------------------------------------------------------------- /h/signal.h: -------------------------------------------------------------------------------- 1 | #define NR_SIGS 16 /* number of signals used */ 2 | #define NSIG 16 /* number of signals used */ 3 | 4 | #define SIGHUP 1 /* hangup */ 5 | #define SIGINT 2 /* interrupt (DEL) */ 6 | #define SIGQUIT 3 /* quit (ASCII FS) */ 7 | #define SIGILL 4 /* illegal instruction (not reset when caught)*/ 8 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ 9 | #define SIGIOT 6 /* IOT instruction */ 10 | #define SIGEMT 7 /* EMT instruction */ 11 | #define SIGFPE 8 /* floating point exception */ 12 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 13 | #define SIGBUS 10 /* bus error */ 14 | #define SIGSEGV 11 /* segmentation violation */ 15 | #define SIGSYS 12 /* bad argument to system call */ 16 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ 17 | #define SIGALRM 14 /* alarm clock */ 18 | #define SIGTERM 15 /* software termination signal from kill */ 19 | 20 | #define STACK_FAULT 16 /* used by kernel to signal stack fault */ 21 | 22 | int (*signal())(); 23 | #define SIG_DFL (int (*)())0 24 | #define SIG_IGN (int (*)())1 25 | -------------------------------------------------------------------------------- /h/stat.h: -------------------------------------------------------------------------------- 1 | struct stat { 2 | short int st_dev; 3 | unsigned short st_ino; 4 | unsigned short st_mode; 5 | short int st_nlink; 6 | short int st_uid; 7 | short int st_gid; 8 | short int st_rdev; 9 | long st_size; 10 | long st_atime; 11 | long st_mtime; 12 | long st_ctime; 13 | }; 14 | 15 | /* Some common definitions. */ 16 | #define S_IFMT 0170000 /* type of file */ 17 | #define S_IFDIR 0040000 /* directory */ 18 | #define S_IFCHR 0020000 /* character special */ 19 | #define S_IFBLK 0060000 /* block special */ 20 | #define S_IFREG 0100000 /* regular */ 21 | #define S_ISUID 04000 /* set user id on execution */ 22 | #define S_ISGID 02000 /* set group id on execution */ 23 | #define S_ISVTX 01000 /* save swapped text even after use */ 24 | #define S_IREAD 00400 /* read permission, owner */ 25 | #define S_IWRITE 00200 /* write permission, owner */ 26 | #define S_IEXEC 00100 /* execute/search permission, owner */ 27 | -------------------------------------------------------------------------------- /include/blocksiz.h: -------------------------------------------------------------------------------- 1 | #define BLOCK_SIZE 1024 /* file system data block size */ 2 | -------------------------------------------------------------------------------- /include/ctype.h: -------------------------------------------------------------------------------- 1 | extern char _ctype_[]; 2 | 3 | #define _U 0001 4 | #define _L 0002 5 | #define _N 0004 6 | #define _S 0010 7 | #define _P 0020 8 | #define _C 0040 9 | #define _X 0100 10 | 11 | #define isalpha(c) ((_ctype_+1)[c]&(_U|_L)) 12 | #define isupper(c) ((_ctype_+1)[c]&_U) 13 | #define islower(c) ((_ctype_+1)[c]&_L) 14 | #define isdigit(c) ((_ctype_+1)[c]&_N) 15 | #define isxdigit(c) ((_ctype_+1)[c]&(_N|_X)) 16 | #define isspace(c) ((_ctype_+1)[c]&_S) 17 | #define ispunct(c) ((_ctype_+1)[c]&_P) 18 | #define isalnum(c) ((_ctype_+1)[c]&(_U|_L|_N)) 19 | #define isprint(c) ((_ctype_+1)[c]&(_P|_U|_L|_N)) 20 | #define iscntrl(c) ((_ctype_+1)[c]&_C) 21 | #define isascii(c) ((unsigned)(c)<=0177) 22 | -------------------------------------------------------------------------------- /include/errno.h: -------------------------------------------------------------------------------- 1 | #define OK 0 2 | #define ERROR 1 3 | #define EPERM 1 4 | #define ENOENT 2 5 | #define ESRCH 3 6 | #define EINTR 4 7 | #define EIO 5 8 | #define ENXIO 6 9 | #define E2BIG 7 10 | #define ENOEXEC 8 11 | #define EBADF 9 12 | #define ECHILD 10 13 | #define EAGAIN 11 14 | #define ENOMEM 12 15 | #define EACCES 13 16 | #define EFAULT 14 17 | #define ENOTBLK 15 18 | #define EBUSY 16 19 | #define EEXIST 17 20 | #define EXDEV 18 21 | #define ENODEV 19 22 | #define ENOTDIR 20 23 | #define EISDIR 21 24 | #define EINVAL 22 25 | #define ENFILE 23 26 | #define EMFILE 24 27 | #define ENOTTY 25 28 | #define ETXTBSY 26 29 | #define EFBIG 27 30 | #define ENOSPC 28 31 | #define ESPIPE 29 32 | #define EROFS 30 33 | #define EMLINK 31 34 | #define EPIPE 32 35 | #define EDOM 33 36 | #define ERANGE 34 37 | 38 | #define E_LOCKED 101 39 | #define E_BAD_CALL 102 40 | #define E_LONG_STRING 103 41 | 42 | -------------------------------------------------------------------------------- /include/grp.h: -------------------------------------------------------------------------------- 1 | struct group { 2 | char *name; 3 | char *passwd; 4 | int gid; 5 | }; 6 | -------------------------------------------------------------------------------- /include/lib.h: -------------------------------------------------------------------------------- 1 | #include "../h/const.h" 2 | #include "../h/type.h" 3 | #include "../h/error.h" 4 | #include "../h/callnr.h" 5 | 6 | extern message M; 7 | 8 | #define MM 0 9 | #define FS 1 10 | 11 | extern int callm1(), callm3(), callx(), len(); 12 | extern int errno; 13 | extern int begsig(); /* interrupts all vector here */ 14 | -------------------------------------------------------------------------------- /include/pwd.h: -------------------------------------------------------------------------------- 1 | struct passwd { 2 | char *pw_name; 3 | char *pw_passwd; 4 | int pw_uid; 5 | int pw_gid; 6 | char *pw_gecos; 7 | char *pw_dir; 8 | char *pw_shell; 9 | }; 10 | -------------------------------------------------------------------------------- /include/regexp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Definitions etc. for regexp(3) routines. 3 | * 4 | * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], 5 | * not the System V one. 6 | */ 7 | #define void int 8 | #define CHARBITS 0377 9 | #define strchr index 10 | #define NSUBEXP 10 11 | typedef struct regexp { 12 | char *startp[NSUBEXP]; 13 | char *endp[NSUBEXP]; 14 | char regstart; /* Internal use only. */ 15 | char reganch; /* Internal use only. */ 16 | char *regmust; /* Internal use only. */ 17 | int regmlen; /* Internal use only. */ 18 | char program[1]; /* Unwarranted chumminess with compiler. */ 19 | } regexp; 20 | 21 | extern regexp *regcomp(); 22 | extern int regexec(); 23 | extern void regsub(); 24 | extern void regerror(); 25 | -------------------------------------------------------------------------------- /include/setjmp.h: -------------------------------------------------------------------------------- 1 | #define _JBLEN 3 2 | typedef int jmp_buf[_JBLEN]; 3 | -------------------------------------------------------------------------------- /include/sgtty.h: -------------------------------------------------------------------------------- 1 | /* Data structures for IOCTL. */ 2 | 3 | struct sgttyb { 4 | char sg_ispeed; /* input speed (not used) */ 5 | char sg_ospeed; /* output speed (not used) */ 6 | char sg_erase; /* erase character */ 7 | char sg_kill; /* kill character */ 8 | int sg_flags; /* mode flags */ 9 | }; 10 | 11 | struct tchars { 12 | char t_intrc; /* SIGINT char */ 13 | char t_quitc; /* SIGQUIT char */ 14 | char t_startc; /* start output (initially CTRL-Q) */ 15 | char t_stopc; /* stop output (initially CTRL-S) */ 16 | char t_eofc; /* EOF (initially CTRL-D) */ 17 | char t_brkc; /* input delimiter (like nl) */ 18 | }; 19 | 20 | /* Fields in t_flags. */ 21 | #define XTABS 0006000 /* do tab expansion */ 22 | #define RAW 0000040 /* enable raw mode */ 23 | #define CRMOD 0000020 /* map lf to cr + lf */ 24 | #define ECHO 0000010 /* echo input */ 25 | #define CBREAK 0000002 /* enable cbreak mode */ 26 | #define COOKED 0000000 /* neither CBREAK nor RAW */ 27 | 28 | #define TIOCGETP (('t'<<8) | 8) 29 | #define TIOCSETP (('t'<<8) | 9) 30 | #define TIOCGETC (('t'<<8) | 18) 31 | #define TIOCSETC (('t'<<8) | 17) 32 | -------------------------------------------------------------------------------- /include/signal.h: -------------------------------------------------------------------------------- 1 | #define NR_SIGS 16 /* number of signals used */ 2 | #define NSIG 16 /* number of signals used */ 3 | 4 | #define SIGHUP 1 /* hangup */ 5 | #define SIGINT 2 /* interrupt (DEL) */ 6 | #define SIGQUIT 3 /* quit (ASCII FS) */ 7 | #define SIGILL 4 /* illegal instruction (not reset when caught)*/ 8 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ 9 | #define SIGIOT 6 /* IOT instruction */ 10 | #define SIGEMT 7 /* EMT instruction */ 11 | #define SIGFPE 8 /* floating point exception */ 12 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 13 | #define SIGBUS 10 /* bus error */ 14 | #define SIGSEGV 11 /* segmentation violation */ 15 | #define SIGSYS 12 /* bad argument to system call */ 16 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ 17 | #define SIGALRM 14 /* alarm clock */ 18 | #define SIGTERM 15 /* software termination signal from kill */ 19 | 20 | #define STACK_FAULT 16 /* used by kernel to signal stack fault */ 21 | 22 | int (*signal())(); 23 | #define SIG_DFL (int (*)())0 24 | #define SIG_IGN (int (*)())1 25 | -------------------------------------------------------------------------------- /include/stat.h: -------------------------------------------------------------------------------- 1 | struct stat { 2 | short int st_dev; 3 | unsigned short st_ino; 4 | unsigned short st_mode; 5 | short int st_nlink; 6 | short int st_uid; 7 | short int st_gid; 8 | short int st_rdev; 9 | long st_size; 10 | long st_atime; 11 | long st_mtime; 12 | long st_ctime; 13 | }; 14 | 15 | /* Some common definitions. */ 16 | #define S_IFMT 0170000 /* type of file */ 17 | #define S_IFDIR 0040000 /* directory */ 18 | #define S_IFCHR 0020000 /* character special */ 19 | #define S_IFBLK 0060000 /* block special */ 20 | #define S_IFREG 0100000 /* regular */ 21 | #define S_ISUID 04000 /* set user id on execution */ 22 | #define S_ISGID 02000 /* set group id on execution */ 23 | #define S_ISVTX 01000 /* save swapped text even after use */ 24 | #define S_IREAD 00400 /* read permission, owner */ 25 | #define S_IWRITE 00200 /* write permission, owner */ 26 | #define S_IEXEC 00100 /* execute/search permission, owner */ 27 | -------------------------------------------------------------------------------- /include/stdio.h: -------------------------------------------------------------------------------- 1 | #define BUFSIZ 1024 2 | #define NFILES 20 3 | #define NULL 0 4 | #define EOF (-1) 5 | #define CMASK 0377 6 | 7 | #define READMODE 1 8 | #define WRITEMODE 2 9 | #define UNBUFF 4 10 | #define _EOF 8 11 | #define _ERR 16 12 | #define IOMYBUF 32 13 | #define PERPRINTF 64 14 | #define STRINGS 128 15 | 16 | #ifndef FILE 17 | 18 | extern struct _io_buf { 19 | int _fd; 20 | int _count; 21 | int _flags; 22 | char *_buf; 23 | char *_ptr; 24 | } *_io_table[NFILES]; 25 | 26 | 27 | #endif /* FILE */ 28 | 29 | #define FILE struct _io_buf 30 | 31 | 32 | #define stdin (_io_table[0]) 33 | #define stdout (_io_table[1]) 34 | #define stderr (_io_table[2]) 35 | 36 | #define getchar() getc(stdin) 37 | #define putchar(c) putc(c,stdout) 38 | #define puts(s) fputs(s,stdout) 39 | #define fgetc(f) getc(f) 40 | #define fputc(c,f) putc(c,f) 41 | #define feof(p) (((p)->_flags & _EOF) != 0) 42 | #define ferror(p) (((p)->_flags & _ERR) != 0) 43 | #define fileno(p) ((p)->_fd) 44 | #define rewind(f) fseek(f, 0L, 0) 45 | #define testflag(p,x) ((p)->_flags & (x)) 46 | 47 | /* If you want a stream to be flushed after each printf use: 48 | * 49 | * perprintf(stream); 50 | * 51 | * If you want to stop with this kind of buffering use: 52 | * 53 | * noperprintf(stream); 54 | */ 55 | 56 | #define noperprintf(p) ((p)->_flags &= ~PERPRINTF) 57 | #define perprintf(p) ((p)->_flags |= PERPRINTF) 58 | -------------------------------------------------------------------------------- /kernel/_link.bat: -------------------------------------------------------------------------------- 1 | echo/ 2 | echo Linking kernel 3 | link/m mpx88+ < linklist >kernel.lst 4 | dos2out -d kernel >> kernel.lst 5 | echo/ 6 | echo Kernel done. Check the .LST-files for errors 7 | pause 8 | echo on 9 | for %%f in (*.lst) do type %%f 10 | 11 | -------------------------------------------------------------------------------- /kernel/glo.h: -------------------------------------------------------------------------------- 1 | /* Global variables used in the kernel. */ 2 | 3 | /* Clocks and timers */ 4 | EXTERN real_time realtime; /* real time clock */ 5 | EXTERN int lost_ticks; /* incremented when clock int can't send mess*/ 6 | 7 | /* Processes, signals, and messages. */ 8 | EXTERN int cur_proc; /* current process */ 9 | EXTERN int prev_proc; /* previous process */ 10 | EXTERN int sig_procs; /* number of procs with p_pending != 0 */ 11 | EXTERN message int_mess; /* interrupt routines build message here */ 12 | 13 | /* CPU type. */ 14 | EXTERN int olivetti; /* TRUE for Olivetti-style keyboard */ 15 | EXTERN int pc_at; /* PC-AT type diskette drives (360K/1.2M) ? */ 16 | 17 | /* The kernel and task stacks. */ 18 | EXTERN struct t_stack { 19 | int stk[TASK_STACK_BYTES/sizeof(int)]; 20 | } t_stack[NR_TASKS - 1]; /* task stacks; task = -1 never really runs */ 21 | 22 | EXTERN char k_stack[K_STACK_BYTES]; /* The kernel stack. */ 23 | -------------------------------------------------------------------------------- /kernel/linklist: -------------------------------------------------------------------------------- 1 | main+proc+system+clock+memory+floppy+ 2 | wini+tty+printer+table+klib88+dmp 3 | kernel 4 | kernel 5 | ..\lib\mxc86 6 | -------------------------------------------------------------------------------- /kernel/makefile: -------------------------------------------------------------------------------- 1 | # The kernel directory contains files xt_wini.c and at_wini.c. Before running 2 | # make you must copy one of these to wini.c, depending on whether you have a 3 | # PC or an AT. You must do this even if you do not have a hard disk.. 4 | CFLAGS = -Di8088 -O 5 | h=../h 6 | l=../lib 7 | 8 | obj = mpx88.o main.o proc.o system.o tty.o clock.o memory.o floppy.o wini.o \ 9 | printer.o table.o klib88.o dmp.o 10 | 11 | kernel: makefile $(obj) $l/libc.a 12 | @echo "Start linking Kernel" 13 | @ld -o kernel $(obj) $l/libc.a $l/end.o 14 | @echo "Kernel done" 15 | 16 | klib88.o: klib88.s 17 | as -o klib88.o klib88.s 18 | 19 | mpx88.o: mpx88.s 20 | as -o mpx88.o mpx88.s 21 | 22 | clock.o: const.h type.h $h/const.h $h/type.h 23 | clock.o: $h/callnr.h 24 | clock.o: $h/com.h 25 | clock.o: $h/error.h 26 | clock.o: $h/signal.h 27 | clock.o: glo.h 28 | clock.o: proc.h 29 | 30 | floppy.o: const.h type.h $h/const.h $h/type.h 31 | floppy.o: $h/callnr.h 32 | floppy.o: $h/com.h 33 | floppy.o: $h/error.h 34 | floppy.o: glo.h 35 | floppy.o: proc.h 36 | 37 | 38 | dmp.o: const.h type.h $h/const.h $h/type.h 39 | dmp.o: $h/callnr.h 40 | dmp.o: $h/com.h 41 | dmp.o: $h/error.h 42 | dmp.o: glo.h 43 | dmp.o: proc.h 44 | 45 | main.o: const.h type.h $h/const.h $h/type.h 46 | main.o: $h/callnr.h 47 | main.o: $h/com.h 48 | main.o: $h/error.h 49 | main.o: glo.h 50 | main.o: proc.h 51 | 52 | memory.o: const.h type.h $h/const.h $h/type.h 53 | memory.o: $h/callnr.h 54 | memory.o: $h/com.h 55 | memory.o: $h/error.h 56 | memory.o: proc.h 57 | 58 | printer.o: const.h type.h $h/const.h $h/type.h 59 | printer.o: $h/callnr.h 60 | printer.o: $h/com.h 61 | printer.o: $h/error.h 62 | 63 | proc.o: const.h type.h $h/const.h $h/type.h 64 | proc.o: $h/callnr.h 65 | proc.o: $h/com.h 66 | proc.o: $h/error.h 67 | proc.o: glo.h 68 | proc.o: proc.h 69 | 70 | system.o: const.h type.h $h/const.h $h/type.h 71 | system.o: $h/callnr.h 72 | system.o: $h/com.h 73 | system.o: $h/error.h 74 | system.o: $h/signal.h 75 | system.o: glo.h 76 | system.o: proc.h 77 | 78 | table.o: const.h type.h $h/const.h $h/type.h 79 | table.o: glo.h 80 | table.o: proc.h 81 | 82 | tty.o: const.h type.h $h/const.h $h/type.h 83 | tty.o: $h/callnr.h 84 | tty.o: $h/com.h 85 | tty.o: $h/error.h 86 | tty.o: $h/sgtty.h 87 | tty.o: $h/signal.h 88 | tty.o: glo.h 89 | tty.o: proc.h 90 | 91 | wini.o: const.h type.h $h/const.h $h/type.h 92 | wini.o: $h/callnr.h 93 | wini.o: $h/com.h 94 | wini.o: $h/error.h 95 | wini.o: proc.h 96 | -------------------------------------------------------------------------------- /kernel/minix/makefile: -------------------------------------------------------------------------------- 1 | # The kernel directory contains files xt_wini.c and at_wini.c. Before running 2 | # make you must copy one of these to wini.c, depending on whether you have a 3 | # PC or an AT. You must do this even if you do not have a hard disk.. 4 | CFLAGS= -Di8088 -w -F -T. 5 | h=../h 6 | l=/usr/lib 7 | 8 | obj = mpx88.s main.s proc.s system.s tty.s clock.s memory.s floppy.s wini.s \ 9 | printer.s table.s klib88.s dmp.s 10 | 11 | kernel: makefile $(obj) $l/libc.a 12 | @echo "Start linking Kernel. /lib/cem will be removed to make space on RAM disk" 13 | @rm -f /lib/cem /tmp/* 14 | @asld -o kernel $(obj) $l/libc.a $l/end.s 15 | @echo "Kernel done. Please restore /lib/cem manually" 16 | 17 | clock.s: const.h type.h $h/const.h $h/type.h 18 | clock.s: $h/callnr.h 19 | clock.s: $h/com.h 20 | clock.s: $h/error.h 21 | clock.s: $h/signal.h 22 | clock.s: glo.h 23 | clock.s: proc.h 24 | 25 | floppy.s: const.h type.h $h/const.h $h/type.h 26 | floppy.s: $h/callnr.h 27 | floppy.s: $h/com.h 28 | floppy.s: $h/error.h 29 | floppy.s: glo.h 30 | floppy.s: proc.h 31 | 32 | 33 | dmp.s: const.h type.h $h/const.h $h/type.h 34 | dmp.s: $h/callnr.h 35 | dmp.s: $h/com.h 36 | dmp.s: $h/error.h 37 | dmp.s: glo.h 38 | dmp.s: proc.h 39 | 40 | main.s: const.h type.h $h/const.h $h/type.h 41 | main.s: $h/callnr.h 42 | main.s: $h/com.h 43 | main.s: $h/error.h 44 | main.s: glo.h 45 | main.s: proc.h 46 | 47 | memory.s: const.h type.h $h/const.h $h/type.h 48 | memory.s: $h/callnr.h 49 | memory.s: $h/com.h 50 | memory.s: $h/error.h 51 | memory.s: proc.h 52 | 53 | printer.s: const.h type.h $h/const.h $h/type.h 54 | printer.s: $h/callnr.h 55 | printer.s: $h/com.h 56 | printer.s: $h/error.h 57 | 58 | proc.s: const.h type.h $h/const.h $h/type.h 59 | proc.s: $h/callnr.h 60 | proc.s: $h/com.h 61 | proc.s: $h/error.h 62 | proc.s: glo.h 63 | proc.s: proc.h 64 | 65 | system.s: const.h type.h $h/const.h $h/type.h 66 | system.s: $h/callnr.h 67 | system.s: $h/com.h 68 | system.s: $h/error.h 69 | system.s: $h/signal.h 70 | system.s: glo.h 71 | system.s: proc.h 72 | 73 | table.s: const.h type.h $h/const.h $h/type.h 74 | table.s: glo.h 75 | table.s: proc.h 76 | 77 | tty.s: const.h type.h $h/const.h $h/type.h 78 | tty.s: $h/callnr.h 79 | tty.s: $h/com.h 80 | tty.s: $h/error.h 81 | tty.s: $h/sgtty.h 82 | tty.s: $h/signal.h 83 | tty.s: glo.h 84 | tty.s: proc.h 85 | 86 | wini.s: const.h type.h $h/const.h $h/type.h 87 | wini.s: $h/callnr.h 88 | wini.s: $h/com.h 89 | wini.s: $h/error.h 90 | wini.s: proc.h 91 | -------------------------------------------------------------------------------- /kernel/minix/makefile.at: -------------------------------------------------------------------------------- 1 | CFLAGS= -Di8088 -w -F -T. 2 | h=../h 3 | l=/usr/lib 4 | 5 | obj = mpx88.s main.s proc.s system.s tty.s clock.s memory.s floppy.s wini.s \ 6 | printer.s table.s klib88.s dmp.s 7 | 8 | kernel: makefile $(obj) $l/libc.a 9 | @echo "Start linking Kernel. " 10 | @rm -f /tmp/* 11 | @asld -o kernel -T. $(obj) $l/libc.a $l/end.s 12 | @echo "Kernel done. " 13 | 14 | clock.s: const.h type.h $h/const.h $h/type.h 15 | clock.s: $h/callnr.h 16 | clock.s: $h/com.h 17 | clock.s: $h/error.h 18 | clock.s: $h/signal.h 19 | clock.s: glo.h 20 | clock.s: proc.h 21 | 22 | floppy.s: const.h type.h $h/const.h $h/type.h 23 | floppy.s: $h/callnr.h 24 | floppy.s: $h/com.h 25 | floppy.s: $h/error.h 26 | floppy.s: proc.h 27 | 28 | 29 | dmp.s: const.h type.h $h/const.h $h/type.h 30 | dmp.s: $h/callnr.h 31 | dmp.s: $h/com.h 32 | dmp.s: $h/error.h 33 | dmp.s: glo.h 34 | dmp.s: proc.h 35 | 36 | main.s: const.h type.h $h/const.h $h/type.h 37 | main.s: $h/callnr.h 38 | main.s: $h/com.h 39 | main.s: $h/error.h 40 | main.s: glo.h 41 | main.s: proc.h 42 | 43 | memory.s: const.h type.h $h/const.h $h/type.h 44 | memory.s: $h/callnr.h 45 | memory.s: $h/com.h 46 | memory.s: $h/error.h 47 | memory.s: proc.h 48 | 49 | printer.s: const.h type.h $h/const.h $h/type.h 50 | printer.s: $h/callnr.h 51 | printer.s: $h/com.h 52 | printer.s: $h/error.h 53 | 54 | proc.s: const.h type.h $h/const.h $h/type.h 55 | proc.s: $h/callnr.h 56 | proc.s: $h/com.h 57 | proc.s: $h/error.h 58 | proc.s: glo.h 59 | proc.s: proc.h 60 | 61 | system.s: const.h type.h $h/const.h $h/type.h 62 | system.s: $h/callnr.h 63 | system.s: $h/com.h 64 | system.s: $h/error.h 65 | system.s: $h/signal.h 66 | system.s: glo.h 67 | system.s: proc.h 68 | 69 | table.s: const.h type.h $h/const.h $h/type.h 70 | table.s: glo.h 71 | table.s: proc.h 72 | 73 | tty.s: const.h type.h $h/const.h $h/type.h 74 | tty.s: $h/callnr.h 75 | tty.s: $h/com.h 76 | tty.s: $h/error.h 77 | tty.s: $h/sgtty.h 78 | tty.s: $h/signal.h 79 | tty.s: proc.h 80 | 81 | wini.s: const.h type.h $h/const.h $h/type.h 82 | wini.s: $h/callnr.h 83 | wini.s: $h/com.h 84 | wini.s: $h/error.h 85 | wini.s: proc.h 86 | -------------------------------------------------------------------------------- /kernel/mpx88.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdevic/minix1/3475e7ed91a3ff3f8862b2543059580a01c1b1a7/kernel/mpx88.asm -------------------------------------------------------------------------------- /kernel/proc.h: -------------------------------------------------------------------------------- 1 | /* Here is the declaration of the process table. Three assembly code routines 2 | * reference fields in it. They are restart(), save(), and csv(). When 3 | * changing 'proc', be sure to change the field offsets built into the code. 4 | * It contains the process' registers, memory map, accounting, and message 5 | * send/receive information. 6 | */ 7 | 8 | EXTERN struct proc { 9 | int p_reg[NR_REGS]; /* process' registers */ 10 | int *p_sp; /* stack pointer */ 11 | struct pc_psw p_pcpsw; /* pc and psw as pushed by interrupt */ 12 | int p_flags; /* P_SLOT_FREE, SENDING, RECEIVING, etc. */ 13 | struct mem_map p_map[NR_SEGS];/* memory map */ 14 | int *p_splimit; /* lowest legal stack value */ 15 | int p_pid; /* process id passed in from MM */ 16 | 17 | real_time user_time; /* user time in ticks */ 18 | real_time sys_time; /* sys time in ticks */ 19 | real_time child_utime; /* cumulative user time of children */ 20 | real_time child_stime; /* cumulative sys time of children */ 21 | real_time p_alarm; /* time of next alarm in ticks, or 0 */ 22 | 23 | struct proc *p_callerq; /* head of list of procs wishing to send */ 24 | struct proc *p_sendlink; /* link to next proc wishing to send */ 25 | message *p_messbuf; /* pointer to message buffer */ 26 | int p_getfrom; /* from whom does process want to receive? */ 27 | 28 | struct proc *p_nextready; /* pointer to next ready process */ 29 | int p_pending; /* bit map for pending signals 1-16 */ 30 | } proc[NR_TASKS+NR_PROCS]; 31 | 32 | /* Bits for p_flags in proc[]. A process is runnable iff p_flags == 0 */ 33 | #define P_SLOT_FREE 001 /* set when slot is not in use */ 34 | #define NO_MAP 002 /* keeps unmapped forked child from running */ 35 | #define SENDING 004 /* set when process blocked trying to send */ 36 | #define RECEIVING 010 /* set when process blocked trying to recv */ 37 | 38 | #define proc_addr(n) &proc[NR_TASKS + n] 39 | #define NIL_PROC (struct proc *) 0 40 | 41 | EXTERN struct proc *proc_ptr; /* &proc[cur_proc] */ 42 | EXTERN struct proc *bill_ptr; /* ptr to process to bill for clock ticks */ 43 | EXTERN struct proc *rdy_head[NQ]; /* pointers to ready list headers */ 44 | EXTERN struct proc *rdy_tail[NQ]; /* pointers to ready list tails */ 45 | 46 | EXTERN unsigned busy_map; /* bit map of busy tasks */ 47 | EXTERN message *task_mess[NR_TASKS+1]; /* ptrs to messages for busy tasks */ 48 | -------------------------------------------------------------------------------- /kernel/table.c: -------------------------------------------------------------------------------- 1 | /* The object file of "table.c" contains all the data. In the *.h files, 2 | * declared variables appear with EXTERN in front of them, as in 3 | * 4 | * EXTERN int x; 5 | * 6 | * Normally EXTERN is defined as extern, so when they are included in another 7 | * file, no storage is allocated. If the EXTERN were not present, but just 8 | * say, 9 | * 10 | * int x; 11 | * 12 | * then including this file in several source files would cause 'x' to be 13 | * declared several times. While some linkers accept this, others do not, 14 | * so they are declared extern when included normally. However, it must 15 | * be declared for real somewhere. That is done here, but redefining 16 | * EXTERN as the null string, so the inclusion of all the *.h files in 17 | * table.c actually generates storage for them. All the initialized 18 | * variables are also declared here, since 19 | * 20 | * extern int x = 4; 21 | * 22 | * is not allowed. If such variables are shared, they must also be declared 23 | * in one of the *.h files without the initialization. 24 | */ 25 | 26 | #include "../h/const.h" 27 | #include "../h/type.h" 28 | #include "const.h" 29 | #include "type.h" 30 | #undef EXTERN 31 | #define EXTERN 32 | #include "glo.h" 33 | #include "proc.h" 34 | 35 | extern int sys_task(), clock_task(), mem_task(), floppy_task(), 36 | winchester_task(), tty_task(), printer_task(); 37 | 38 | /* The startup routine of each task is given below, from -NR_TASKS upwards. 39 | * The order of the names here MUST agree with the numerical values assigned to 40 | * the tasks in ../h/com.h. 41 | */ 42 | int (*task[NR_TASKS+INIT_PROC_NR+1])() = { 43 | printer_task, tty_task, winchester_task, floppy_task, mem_task, 44 | clock_task, sys_task, 0, 0, 0, 0 45 | }; 46 | -------------------------------------------------------------------------------- /kernel/type.h: -------------------------------------------------------------------------------- 1 | /* The 'pc_psw' struct is machine dependent. It must contain the information 2 | * pushed onto the stack by an interrupt, in the same format as the hardware 3 | * creates and expects. It is used for storing the interrupt status after a 4 | * trap or interrupt, as well as for causing interrupts for signals. 5 | */ 6 | 7 | 8 | #ifdef i8088 9 | struct pc_psw { 10 | int (*pc)(); /* storage for program counter */ 11 | phys_clicks cs; /* code segment register */ 12 | unsigned psw; /* program status word */ 13 | }; 14 | 15 | /* This struct is used to build data structure pushed by kernel upon signal. */ 16 | struct sig_info { 17 | int signo; /* sig number at end of stack */ 18 | struct pc_psw sigpcpsw; 19 | }; 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/abort.c: -------------------------------------------------------------------------------- 1 | abort() 2 | { 3 | exit(99); 4 | } 5 | -------------------------------------------------------------------------------- /lib/abs.c: -------------------------------------------------------------------------------- 1 | abs(i){ 2 | return i < 0 ? -i : i; 3 | } 4 | -------------------------------------------------------------------------------- /lib/access.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int access(name, mode) 4 | char *name; 5 | int mode; 6 | { 7 | return callm3(FS, ACCESS, mode, name); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /lib/alarm.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int alarm(sec) 4 | unsigned sec; 5 | { 6 | return callm1(MM, ALARM, (int) sec, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/atoi.c: -------------------------------------------------------------------------------- 1 | #define isascii(c) (((unsigned) (c) & 0xFF) < 0200) 2 | 3 | /* For all the following functions the parameter must be ASCII */ 4 | 5 | #define _between(a,b,c) ((unsigned) ((b) - (a)) < (c) - (a)) 6 | 7 | #define isupper(c) _between('A', c, 'Z') 8 | #define islower(c) _between('a', c, 'z') 9 | #define isdigit(c) _between('0', c, '9') 10 | #define isprint(c) _between(' ', c, '~') 11 | 12 | /* The others are problematic as the parameter may only be evaluated once */ 13 | 14 | static _c_; /* used to store the evaluated parameter */ 15 | 16 | #define isalpha(c) (isupper(_c_ = (c)) || islower(_c_)) 17 | #define isalnum(c) (isalpha(c) || isdigit(_c_)) 18 | #define _isblank(c) ((_c_ = (c)) == ' ' || _c_ == '\t') 19 | #define isspace(c) (_isblank(c) || _c_=='\r' || _c_=='\n' || _c_=='\f') 20 | #define iscntrl(c) ((_c_ = (c)) == 0177 || _c_ < ' ') 21 | 22 | atoi(s) 23 | register char *s; 24 | { 25 | register int total = 0; 26 | register unsigned digit; 27 | register minus = 0; 28 | 29 | while (isspace(*s)) 30 | s++; 31 | if (*s == '-') { 32 | s++; 33 | minus = 1; 34 | } 35 | while ((digit = *s++ - '0') < 10) { 36 | total *= 10; 37 | total += digit; 38 | } 39 | return(minus ? -total : total); 40 | } 41 | -------------------------------------------------------------------------------- /lib/atol.c: -------------------------------------------------------------------------------- 1 | #include "../include/ctype.h" 2 | 3 | long atol(s) 4 | register char *s; 5 | { 6 | register long total = 0; 7 | register unsigned digit; 8 | register minus = 0; 9 | 10 | while (isspace(*s)) 11 | s++; 12 | if (*s == '-') { 13 | s++; 14 | minus = 1; 15 | } 16 | while ((digit = *s++ - '0') < 10) { 17 | total *= 10; 18 | total += digit; 19 | } 20 | return(minus ? -total : total); 21 | } 22 | -------------------------------------------------------------------------------- /lib/bcopy.c: -------------------------------------------------------------------------------- 1 | bcopy(old, new, n) 2 | register char *old, *new; 3 | int n; 4 | { 5 | /* Copy a block of data. */ 6 | 7 | while (n--) *new++ = *old++; 8 | } 9 | -------------------------------------------------------------------------------- /lib/brk.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | extern char *brksize; 4 | 5 | PUBLIC char *brk(addr) 6 | char *addr; 7 | { 8 | int k; 9 | 10 | k = callm1(MM, BRK, 0, 0, 0, addr, NIL_PTR, NIL_PTR); 11 | if (k == OK) { 12 | brksize = M.m2_p1; 13 | return(NIL_PTR); 14 | } else { 15 | return( (char*) -1 ); 16 | } 17 | } 18 | 19 | 20 | PUBLIC char *sbrk(incr) 21 | char *incr; 22 | { 23 | char *newsize, *oldsize; 24 | extern int endv, dorgv; 25 | 26 | oldsize = brksize; 27 | newsize = brksize + (int) incr; 28 | if (brk(newsize) == 0) 29 | return(oldsize); 30 | else 31 | return( (char *) -1 ); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /lib/brk2.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC brk2() 4 | { 5 | char *p1, *p2; 6 | 7 | p1 = (char *) get_size(); 8 | callm1(MM, BRK2, 0, 0, 0, p1, p2, NIL_PTR); 9 | } 10 | -------------------------------------------------------------------------------- /lib/brksize.s: -------------------------------------------------------------------------------- 1 | .data 2 | .globl endbss, _brksize 3 | _brksize: .word endbss 4 | -------------------------------------------------------------------------------- /lib/c86/brksize.asm: -------------------------------------------------------------------------------- 1 | Title brksize - dynamic end of bss 2 | 3 | ; Note: as opposed to the symbol 'end' which statically sets the end 4 | ; of the unitialized (allocated) data, brksize can set this 5 | ; dynamically. It is used by the memory-allocator to allocate 6 | ; free memory on top of the bss. Thus stack and heap grow 7 | ; towards eachother. 8 | ; 9 | ; This symbol is (must be) declared in crtso.asm which defines 10 | ; the load-model for C86-programs under Minix. 11 | 12 | END 13 | -------------------------------------------------------------------------------- /lib/c86/catchsig.asm: -------------------------------------------------------------------------------- 1 | title catchsig - C86 version 2 | page,132 3 | 4 | INCLUDE ..\lib\prologue.h 5 | 6 | PUBLIC begsig 7 | EXTRN vectab:WORD, M:WORD 8 | 9 | 10 | @CODE SEGMENT 11 | ASSUME CS:@CODE,DS:DGROUP 12 | 13 | MTYPE = 2 ; M+mtype = &M.m_type 14 | begsig: 15 | push ax ; after interrupt, save all regs 16 | push bx 17 | push cx 18 | push dx 19 | push si 20 | push di 21 | push bp 22 | push ds 23 | push es 24 | mov bp,sp 25 | mov bx,18[bp] ; bx = signal number 26 | dec bx ; vectab[0] is for sig 1 27 | add bx,bx ; pointers are two bytes on 8088 28 | mov bx,vectab[bx] ; bx = address of routine to call 29 | push M+mtype ; push status of last system call 30 | push ax ; func called with signal number as arg 31 | call bx 32 | back: 33 | pop ax ; get signal number off stack 34 | pop M+mtype ; restore status of previous system call 35 | pop es ; signal handling finished 36 | pop ds 37 | pop bp 38 | pop di 39 | pop si 40 | pop dx 41 | pop cx 42 | pop bx 43 | pop ax 44 | pop dummy ; remove signal number from stack 45 | iret 46 | @CODE ENDS 47 | 48 | @DATAI SEGMENT 49 | dummy DW 0 50 | @DATAI ENDS 51 | 52 | END ; end of assembly-file 53 | -------------------------------------------------------------------------------- /lib/c86/crtso.asm: -------------------------------------------------------------------------------- 1 | Title $MAIN C-86 run-time start-off for Minix 2 | page,132 3 | 4 | 5 | 6 | PUBLIC @end, brksize, edata, $main, environ, kamikaze 7 | EXTRN main:NEAR, exit:NEAR 8 | 9 | INCLUDE ..\lib\prologue.h 10 | 11 | STACKSIZE EQU 2560 ; default stack is 5 Kb (2K words) 12 | 13 | 14 | 15 | @CODE SEGMENT 16 | ASSUME CS:@CODE,DS:DGROUP 17 | 18 | ; This is the C run-time start-off routine. It's job is to take the 19 | ; arguments as put on the stack by EXEC, and to parse them and set them up the 20 | ; way main expects them. 21 | ; 22 | 23 | $main: 24 | mov ax,DGROUP ; force relocation of data & bss 25 | mov bx,sp ; set stackframe pointer (ds=ss) 26 | mov cx,[bx] ; get argc 27 | add bx,2 ; point at next parameter 28 | mov ax,cx 29 | inc ax ; calculate envp 30 | shl ax,1 31 | add ax,bx 32 | mov environ,ax ; save envp 33 | push ax ; stack envp 34 | push bx ; stack argv 35 | push cx ; stack argc 36 | 37 | call main ; call main (arc,argv,envp) 38 | 39 | add sp,6 40 | push ax ; stack program-termination status 41 | call exit ; this will never return 42 | 43 | ; DEBUG from here on 44 | 45 | kamikaze: int 3 46 | ret 47 | 48 | @CODE ENDS 49 | 50 | 51 | @DATAC SEGMENT 52 | brksize DW offset dgroup:@END+2 ; dynamic changeable end of bss 53 | environ DW 0 ; save environment pointer here 54 | @DATAC ENDS 55 | 56 | @DATAT SEGMENT ; DATAT holds nothing. The label just 57 | edata label byte ; tells us where the initialized data 58 | @DATAT ENDS ; (.data) ends. 59 | 60 | @DATAV SEGMENT ; DATAV holds nothing. The label in 61 | @end label byte ; the segment just tells us where 62 | @DATAV ENDS ; the data+bss ends. 63 | 64 | @STACK SEGMENT BYTE STACK 'STACK' 65 | DW STACKSIZE dup(?) ; add stack segment to bss 66 | @STACK ENDS 67 | 68 | 69 | END $main ; program entry-point (could be anywhere) 70 | -------------------------------------------------------------------------------- /lib/c86/csv.asm: -------------------------------------------------------------------------------- 1 | Title csv - C86 version 2 | 3 | 4 | ; Note: csv is a symbol generated by the Minix and PC-IX C-compilers. 5 | ; It is used to do procedure entry/exit. The .s version checks 6 | ; the stack. In C86 no such symbol is generated by the compiler 7 | ; so we can't use these routines. 8 | ; 9 | ; If you want to do stack-checking, you can use the procedure 10 | ; '$entry'. This symbol is generated by C86 when you specify 11 | ; the '-t' flag when compiling. This routine is primairily ment 12 | ; for stack-tracing etc. You must adapt csv then for C86 and call 13 | ; it $entry. $entry is called after push bp and allocation for 14 | ; local storage (sub sp,nn) 15 | 16 | END 17 | -------------------------------------------------------------------------------- /lib/c86/end.asm: -------------------------------------------------------------------------------- 1 | Title end - end of bss for C86 2 | 3 | ; Note: This static symbol is the address of the end of the unitialized data 4 | ; In C86 this symbol is (and must be) declarfed in crtso.asm, which 5 | ; defines the load-model of a program. Its name there is '@END' because 6 | ; 'END' is a reserved assembler symbol. C86 knows that these symbols 7 | ; must be prepended by the @-sign (so in a C-program you must just 8 | ; csall it 'end'). 9 | 10 | END 11 | -------------------------------------------------------------------------------- /lib/c86/getutil.asm: -------------------------------------------------------------------------------- 1 | title GetUtil - C86 version 2 | page,132 3 | 4 | 5 | INCLUDE ..\lib\prologue.h 6 | 7 | PUBLIC get_base, get_size, get_tot_ 8 | EXTRN brksize:WORD, @end:byte 9 | 10 | 11 | @CODE SEGMENT 12 | ASSUME CS:@CODE,DS:DGROUP 13 | 14 | ;======================================================================== 15 | ; utilities 16 | ;======================================================================== 17 | 18 | get_base: ; return click at which prog starts 19 | mov ax,ds 20 | ret 21 | 22 | get_size: ; return prog size in bytes [text+data+bss] 23 | mov ax,offset dgroup:@end ; end is label at end of bss 24 | ret 25 | 26 | ; Find out how much memory the machine has, including vectors, kernel MM, etc. 27 | get_tot_: 28 | cli 29 | push es 30 | push di 31 | mov ax,8192 ; start search at 128K [8192 clicks] 32 | sub di,di 33 | y1: mov es,ax 34 | mov es:[di],0A5A4h ; write random bit pattern to memory 35 | xor bx,bx 36 | mov bx,es:[di] ; read back pattern just written 37 | cmp bx,0A5A4h ; compare with expected value 38 | jne y2 ; if different, no memory present 39 | add ax,4096 ; advance counter by 64K 40 | cmp ax,0A000h ; stop seaching at 640K 41 | jne y1 42 | y2: pop di 43 | pop es 44 | sti 45 | ret 46 | 47 | @CODE ENDS 48 | 49 | END ; end of assembly-file 50 | -------------------------------------------------------------------------------- /lib/c86/head.asm: -------------------------------------------------------------------------------- 1 | title Head - Start-off for initt, mm and fs (C86-compiler) 2 | page ,132 3 | 4 | EXTRN main:NEAR 5 | PUBLIC $main, data_org, brksize, sp_limit, @end 6 | EXTRN stackpt:word 7 | 8 | INCLUDE ..\lib\prologue.h 9 | 10 | 11 | @CODE SEGMENT 12 | assume cs:@code,ds:dgroup 13 | 14 | $main: jmp short L0 15 | ORG 10h ; kernel uses this area as stack for inital IRET 16 | L0:mov sp,dgroup:stackpt 17 | call main 18 | L1:jmp L1 ; this will never be executed 19 | mov ax,DGROUP ; force relocation for dos2out (never executed) 20 | 21 | @CODE ENDS 22 | 23 | 24 | @DATAB SEGMENT ; fs needs to know where build stuffed table 25 | data_org DW 0DADAh ; 0xDADA is magic number for build 26 | DW 7 dup(0) ; first 8 words of MM, FS, INIT are for stack 27 | brksize DW offset dgroup:@END ; first free memory 28 | sp_limit DW 0 29 | @DATAB ENDS 30 | 31 | @DATAV SEGMENT ; DATAV holds nothing. The label in 32 | @END label byte ; the segment just tells us where 33 | @DATAV ENDS ; the data+bss ends. 34 | 35 | @STACK SEGMENT BYTE STACK 'STACK' 36 | @STACK ENDS ; Add stack to satisfy DOS-linker 37 | 38 | END $main ; end of assembly & entry-point 39 | -------------------------------------------------------------------------------- /lib/c86/make.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | :begin 3 | if "%1"=="" goto eind 4 | echo/ 5 | echo Compiling %1 6 | cc1 %1 > %1.lst 7 | if errorlevel 1 goto err 8 | cc2 %1 >> %1.lst 9 | if errorlevel 1 goto err 10 | cc3 %1 >> %1.lst 11 | if errorlevel 1 goto err 12 | cc4 %1 >> %1.lst 13 | if errorlevel 1 goto err 14 | shift 15 | goto begin 16 | :err 17 | echo +++error in compilation+++ 18 | shift 19 | goto begin 20 | :eind 21 | if '%BATCH%'=='LIB' makelib 22 | -------------------------------------------------------------------------------- /lib/c86/prologue.h: -------------------------------------------------------------------------------- 1 | 2 | ; prologue.h 3 | ; standard prologue for c86 assembly code 4 | ; This file defines the correct ordering of segments 5 | 6 | @CODE SEGMENT BYTE PUBLIC 'CODE' ; text segment 7 | @CODE ENDS 8 | @DATAB SEGMENT PARA PUBLIC 'DATAB' ; data segment 9 | @DATAB ENDS 10 | @DATAC SEGMENT BYTE PUBLIC 'DATAC' ; data segment 11 | @DATAC ENDS 12 | @DATAI SEGMENT BYTE PUBLIC 'DATAI' ; data segment 13 | @DATAI ENDS 14 | @DATAT SEGMENT BYTE PUBLIC 'DATAT' ; bss segment 15 | @DATAT ENDS 16 | @DATAU SEGMENT BYTE PUBLIC 'DATAU' ; bss segment 17 | @DATAU ENDS 18 | @DATAV SEGMENT BYTE PUBLIC 'DATAV' ; bss segment 19 | @DATAV ENDS 20 | 21 | 22 | DGROUP GROUP @DATAB,@DATAC,@DATAI,@DATAT,@DATAU,@DATAV 23 | -------------------------------------------------------------------------------- /lib/c86/sendrec.asm: -------------------------------------------------------------------------------- 1 | title Send/Receive - C86 version 2 | page,132 3 | 4 | INCLUDE ..\lib\prologue.h 5 | 6 | PUBLIC send, receive, send_rec, sendrec 7 | 8 | 9 | ; The following definitions are from ../h/com.h 10 | 11 | _SEND = 1 12 | _RECEIVE= 2 13 | _BOTH = 3 14 | _SYSVEC = 32 15 | 16 | 17 | @CODE SEGMENT 18 | ASSUME CS:@CODE,DS:DGROUP 19 | 20 | ;======================================================================== 21 | ; send and receive 22 | ;======================================================================== 23 | ; send(), receive(), send_rec() all save bp, but destroy ax, bx, and cx. 24 | 25 | send: mov cx,_SEND ; send(dest, ptr) 26 | jmp L0 27 | 28 | receive: 29 | mov cx,_RECEIVE ; receive(src, ptr) 30 | jmp L0 31 | 32 | sendrec: 33 | send_rec: 34 | mov cx,_BOTH ; send_rec(srcdest, ptr) 35 | jmp L0 36 | 37 | L0: push bp ; save bp 38 | mov bp,sp ; can't index off sp 39 | mov ax,4[bp] ; ax = dest-src 40 | mov bx,6[bp] ; bx = message pointer 41 | int _SYSVEC ; trap to the kernel 42 | pop bp ; restore bp 43 | ret ; return 44 | 45 | @CODE ENDS 46 | 47 | END ; end of assembly-file 48 | -------------------------------------------------------------------------------- /lib/c86/setjmp.asm: -------------------------------------------------------------------------------- 1 | title setjmp/longjmp - C86 version 2 | page,132 3 | 4 | INCLUDE ..\lib\prologue.h 5 | 6 | PUBLIC setjmp, longjmp 7 | EXTRN exit:near 8 | 9 | 10 | ; struct jmpbuf { 11 | ; int bp; 12 | ; int sp; 13 | ; int ret-addr 14 | ; } 15 | 16 | JMPERR EQU -99 ; call exit(JMPERR) when jmp-error 17 | 18 | @CODE SEGMENT 19 | ASSUME CS:@CODE,DS:DGROUP 20 | setjmp: 21 | mov bx,sp 22 | mov ax,[bx] ; ret-addr. 23 | mov bx,2[bx] ; addr of jmp-struct 24 | mov [bx],bp 25 | mov 2[bx],sp 26 | mov 4[bx],ax 27 | xor ax,ax 28 | ret 29 | 30 | longjmp: 31 | mov bp,sp ; set new frame pointer to sp 32 | mov bx,4[bp] ; get address of jmp-structure 33 | mov ax,6[bp] ; get ret-code 34 | or ax,ax 35 | jne L1 36 | inc ax ; return code may not be zero 37 | L1: mov sp,[bx+2] 38 | mov bp,[bx] 39 | or bp,bp ; test if last frame-pointer (error) 40 | jne L2 ; else execute the longjmp 41 | mov ax,JMPERR 42 | push ax 43 | call exit ; should never return 44 | hlt 45 | L2: mov bx,[bx+4] 46 | jmp [bx] 47 | @CODE ENDS 48 | 49 | END 50 | -------------------------------------------------------------------------------- /lib/call.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int errno; /* place where error numbers go */ 4 | 5 | PUBLIC int callm1(proc, syscallnr, int1, int2, int3, ptr1, ptr2, ptr3) 6 | int proc; /* FS or MM */ 7 | int syscallnr; /* which system call */ 8 | int int1; /* first integer parameter */ 9 | int int2; /* second integer parameter */ 10 | int int3; /* third integer parameter */ 11 | char *ptr1; /* pointer parameter */ 12 | char *ptr2; /* pointer parameter */ 13 | char *ptr3; /* pointer parameter */ 14 | { 15 | /* Send a message and get the response. The 'M.m_type' field of the 16 | * reply contains a value (>= 0) or an error code (<0). Use message format m1. 17 | */ 18 | M.m1_i1 = int1; 19 | M.m1_i2 = int2; 20 | M.m1_i3 = int3; 21 | M.m1_p1 = ptr1; 22 | M.m1_p2 = ptr2; 23 | M.m1_p3 = ptr3; 24 | return callx(proc, syscallnr); 25 | } 26 | 27 | 28 | 29 | 30 | 31 | PUBLIC int callm3(proc, syscallnr, int1, name) 32 | int proc; /* FS or MM */ 33 | int syscallnr; /* which system call */ 34 | int int1; /* integer parameter */ 35 | char *name; /* string */ 36 | { 37 | /* This form of system call is used for those calls that contain at most 38 | * one integer parameter along with a string. If the string fits in the 39 | * message, it is copied there. If not, a pointer to it is passed. 40 | */ 41 | register int k; 42 | register char *rp; 43 | k = len(name); 44 | M.m3_i1 = k; 45 | M.m3_i2 = int1; 46 | M.m3_p1 = name; 47 | rp = &M.m3_ca1[0]; 48 | if (k <= M3_STRING) while (k--) *rp++ = *name++; 49 | return callx(proc, syscallnr); 50 | } 51 | 52 | 53 | 54 | 55 | 56 | PUBLIC int callx(proc, syscallnr) 57 | int proc; /* FS or MM */ 58 | int syscallnr; /* which system call */ 59 | { 60 | /* Send a message and get the response. The 'M.m_type' field of the 61 | * reply contains a value (>= 0) or an error code (<0). 62 | */ 63 | int k; 64 | 65 | M.m_type = syscallnr; 66 | k = sendrec(proc, &M); 67 | if (k != OK) return(k); /* send itself failed */ 68 | if (M.m_type < 0) {errno = -M.m_type; return(-1);} 69 | return(M.m_type); 70 | } 71 | 72 | 73 | 74 | 75 | 76 | PUBLIC int len(s) 77 | register char *s; /* character string whose length is needed */ 78 | { 79 | /* Return the length of a character string, including the 0 at the end. */ 80 | register int k; 81 | 82 | k = 0; 83 | while (*s++ != 0) k++; 84 | return(k+1); /* return length including the 0-byte at end */ 85 | } 86 | -------------------------------------------------------------------------------- /lib/catchsig.s: -------------------------------------------------------------------------------- 1 | .globl _begsig 2 | .globl _vectab, _M 3 | mtype = 2 | M+mtype = &M.m_type 4 | _begsig: 5 | push ax | after interrupt, save all regs 6 | push bx 7 | push cx 8 | push dx 9 | push si 10 | push di 11 | push bp 12 | push ds 13 | push es 14 | mov bx,sp 15 | mov bx,18(bx) | bx = signal number 16 | mov ax,bx | ax = signal number 17 | dec bx | vectab[0] is for sig 1 18 | add bx,bx | pointers are two bytes on 8088 19 | mov bx,_vectab(bx) | bx = address of routine to call 20 | push _M+mtype | push status of last system call 21 | push ax | func called with signal number as arg 22 | call (bx) 23 | back: 24 | pop ax | get signal number off stack 25 | pop _M+mtype | restore status of previous system call 26 | pop es | signal handling finished 27 | pop ds 28 | pop bp 29 | pop di 30 | pop si 31 | pop dx 32 | pop cx 33 | pop bx 34 | pop ax 35 | pop dummy | remove signal number from stack 36 | iret 37 | 38 | .data 39 | dummy: .word 0 40 | -------------------------------------------------------------------------------- /lib/chdir.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int chdir(name) 4 | char *name; 5 | { 6 | return callm3(FS, CHDIR, 0, name); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /lib/chmod.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int chmod(name, mode) 4 | char* name; 5 | int mode; 6 | { 7 | return callm3(FS, CHMOD, mode, name); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /lib/chown.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int chown(name, owner, grp) 4 | char *name; 5 | int owner, grp; 6 | { 7 | return callm1(FS, CHOWN, len(name), owner, grp, name, NIL_PTR, NIL_PTR); 8 | } 9 | -------------------------------------------------------------------------------- /lib/chroot.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int chroot(name) 4 | char* name; 5 | { 6 | return callm3(FS, CHROOT, 0, name); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /lib/cleanup.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | _cleanup() 4 | { 5 | register int i; 6 | 7 | for ( i = 0 ; i < NFILES ; i++ ) 8 | if ( _io_table[i] != NULL ) 9 | fflush(_io_table[i]); 10 | } 11 | -------------------------------------------------------------------------------- /lib/close.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int close(fd) 4 | int fd; 5 | { 6 | return callm1(FS, CLOSE, fd, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /lib/creat.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int creat(name, mode) 4 | char* name; 5 | int mode; 6 | { 7 | return callm3(FS, CREAT, mode, name); 8 | } 9 | -------------------------------------------------------------------------------- /lib/crtso.s: -------------------------------------------------------------------------------- 1 | | This is the C run-time start-off routine. It's job is to take the 2 | | arguments as put on the stack by EXEC, and to parse them and set them up the 3 | | way _main expects them. 4 | 5 | .globl _main, _exit, crtso, _environ 6 | .globl begtext, begdata, begbss, endtext, enddata, endbss 7 | .text 8 | begtext: 9 | crtso: mov bx,sp 10 | mov cx,(bx) 11 | add bx,*2 12 | mov ax,cx 13 | inc ax 14 | shl ax,#1 15 | add ax,bx 16 | mov _environ,ax | save envp in environ 17 | push ax | push environ 18 | push bx | push argv 19 | push cx | push argc 20 | call _main 21 | add sp,*6 22 | push ax | push exit status 23 | call _exit 24 | 25 | .data 26 | begdata: 27 | _environ: .word 0 28 | .bss 29 | begbss: 30 | -------------------------------------------------------------------------------- /lib/crypt.c: -------------------------------------------------------------------------------- 1 | char *crypt(pw, salt) 2 | char *pw, *salt; 3 | { 4 | static char buf[14]; 5 | register char bits[67]; 6 | register int i; 7 | register int j, rot; 8 | 9 | for (i=0; i < 67; i++) 10 | bits[i] = 0; 11 | if (salt[1] == 0) 12 | salt[1] = salt[0]; 13 | rot = (salt[1] * 4 - salt[0]) % 128; 14 | for (i=0; *pw && i < 8; i++) { 15 | for (j=0; j < 7; j++) 16 | bits[i+j*8] = (*pw & (1 << j) ? 1 : 0); 17 | bits[i+56] = (salt[i / 4] & (1 << (i % 4)) ? 1 : 0); 18 | pw++; 19 | } 20 | bits[64] = (salt[0] & 1 ? 1 : 0); 21 | bits[65] = (salt[1] & 1 ? 1 : 0); 22 | bits[66] = (rot & 1 ? 1 : 0); 23 | while (rot--) { 24 | for (i=65; i >= 0; i--) 25 | bits[i+1] = bits[i]; 26 | bits[0] = bits[66]; 27 | } 28 | for (i=0; i < 12; i++) { 29 | buf[i+2] = 0; 30 | for (j=0; j < 6; j++) 31 | buf[i+2] |= (bits[i*6+j] ? (1 << j) : 0); 32 | buf[i+2] += 48; 33 | if (buf[i+2] > '9') buf[i+2] += 7; 34 | if (buf[i+2] > 'Z') buf[i+2] += 6; 35 | } 36 | buf[0] = salt[0]; 37 | buf[1] = salt[1]; 38 | buf[13] = '\0'; 39 | return(buf); 40 | } 41 | -------------------------------------------------------------------------------- /lib/csv.s: -------------------------------------------------------------------------------- 1 | WRITE = 4 2 | FS = 1 3 | 4 | |*===========================================================================* 5 | |* csv & cret * 6 | |*===========================================================================* 7 | | This version of csv replaces the standard one. It checks sp. 8 | .globl csv, cret, _sp_limit, _sendrec, _M 9 | csv: pop bx | bx = return address 10 | push bp | stack old frame pointer 11 | mov bp,sp | set new frame pointer to sp 12 | push di | save di 13 | push si | save si 14 | sub sp,ax | ax = # bytes of local variables 15 | cmp sp,_sp_limit | has stack overflowed? 16 | jb csv.err | jump if stack overflow 17 | jmp (bx) | normal return: copy bx to pc 18 | 19 | csv.err: | come here if stack overflow 20 | mov _M+2,#WRITE | m_type 21 | mov _M+4,#2 | file descriptor 2 is std error 22 | mov _M+6,#15 | prepare to print error message 23 | mov _M+10,#stkovmsg | error message 24 | mov ax,#_M | prepare to call sendrec(FS, &M); 25 | push ax | push second parameter 26 | mov ax,#FS | prepare to push first parameter 27 | push ax | push first parameter 28 | call _sendrec | write(fd, stkovmsg, 15); 29 | add sp,#4 | clean up stack 30 | L0: jmp L0 | hang forever 31 | 32 | cret: lea sp,*-4(bp) 33 | pop si 34 | pop di 35 | pop bp 36 | ret 37 | 38 | .data 39 | _sp_limit: .word 0 | stack limit default is 0 40 | stkovmsg: .asciz "Stack overflow\n" 41 | -------------------------------------------------------------------------------- /lib/ctype.c: -------------------------------------------------------------------------------- 1 | #include "../include/ctype.h" 2 | 3 | char _ctype_[] = { 4 | 0, 5 | _C, _C, _C, _C, _C, _C, _C, _C, 6 | _C, _S, _S, _S, _S, _S, _C, _C, 7 | _C, _C, _C, _C, _C, _C, _C, _C, 8 | _C, _C, _C, _C, _C, _C, _C, _C, 9 | _S, _P, _P, _P, _P, _P, _P, _P, 10 | _P, _P, _P, _P, _P, _P, _P, _P, 11 | _N, _N, _N, _N, _N, _N, _N, _N, 12 | _N, _N, _P, _P, _P, _P, _P, _P, 13 | _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, 14 | _U, _U, _U, _U, _U, _U, _U, _U, 15 | _U, _U, _U, _U, _U, _U, _U, _U, 16 | _U, _U, _U, _P, _P, _P, _P, _P, 17 | _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, 18 | _L, _L, _L, _L, _L, _L, _L, _L, 19 | _L, _L, _L, _L, _L, _L, _L, _L, 20 | _L, _L, _L, _P, _P, _P, _P, _C 21 | }; 22 | -------------------------------------------------------------------------------- /lib/doscanf.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdevic/minix1/3475e7ed91a3ff3f8862b2543059580a01c1b1a7/lib/doscanf.c -------------------------------------------------------------------------------- /lib/dup.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int dup(fd) 4 | int fd; 5 | { 6 | return callm1(FS, DUP, fd, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/dup2.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int dup2(fd, fd2) 4 | int fd, fd2; 5 | { 6 | return callm1(FS, DUP, fd+0100, fd2, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/end.s: -------------------------------------------------------------------------------- 1 | .globl endtext, enddata, endbss 2 | .text 3 | endtext: 4 | .data 5 | enddata: 6 | .bss 7 | endbss: 8 | -------------------------------------------------------------------------------- /lib/exec.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | char *nullptr[1]; /* the EXEC calls need a zero pointer */ 4 | 5 | PUBLIC int execl(name, arg0) 6 | char *name; 7 | char *arg0; 8 | { 9 | return execve(name, &arg0, nullptr); 10 | } 11 | 12 | PUBLIC int execle(name, argv) 13 | char *name, *argv; 14 | { 15 | char **p; 16 | p = (char **) &argv; 17 | while (*p++) /* null statement */ ; 18 | return execve(name, &argv, *p); 19 | } 20 | 21 | PUBLIC int execv(name, argv) 22 | char *name, *argv[]; 23 | { 24 | return execve(name, argv, nullptr); 25 | } 26 | 27 | 28 | PUBLIC int execve(name, argv, envp) 29 | char *name; /* pointer to name of file to be executed */ 30 | char *argv[]; /* pointer to argument array */ 31 | char *envp[]; /* pointer to environment */ 32 | { 33 | char stack[MAX_ISTACK_BYTES]; 34 | char **argorg, **envorg, *hp, **ap, *p; 35 | int i, nargs, nenvps, stackbytes, ptrsize, offset; 36 | 37 | /* Count the argument pointers and environment pointers. */ 38 | nargs = 0; 39 | nenvps = 0; 40 | argorg = argv; 41 | envorg = envp; 42 | while (*argorg++ != NIL_PTR) nargs++; 43 | while (*envorg++ != NIL_PTR) nenvps++; 44 | ptrsize = sizeof(NIL_PTR); 45 | 46 | /* Prepare to set up the initial stack. */ 47 | hp = &stack[(nargs + nenvps + 3) * ptrsize]; 48 | if (hp + nargs + nenvps >= &stack[MAX_ISTACK_BYTES]) return(E2BIG); 49 | ap = (char **) stack; 50 | *ap++ = (char *) nargs; 51 | 52 | /* Prepare the argument pointers and strings. */ 53 | for (i = 0; i < nargs; i++) { 54 | offset = hp - stack; 55 | *ap++ = (char *) offset; 56 | p = *argv++; 57 | while (*p) { 58 | *hp++ = *p++; 59 | if (hp >= &stack[MAX_ISTACK_BYTES]) return(E2BIG); 60 | } 61 | *hp++ = (char) 0; 62 | } 63 | *ap++ = NIL_PTR; 64 | 65 | /* Prepare the environment pointers and strings. */ 66 | for (i = 0; i < nenvps; i++) { 67 | offset = hp - stack; 68 | *ap++ = (char *) offset; 69 | p = *envp++; 70 | while (*p) { 71 | *hp++ = *p++; 72 | if (hp >= &stack[MAX_ISTACK_BYTES]) return(E2BIG); 73 | } 74 | *hp++ = (char) 0; 75 | } 76 | *ap++ = NIL_PTR; 77 | stackbytes = ( ( (hp - stack) + ptrsize - 1)/ptrsize) * ptrsize; 78 | return callm1(MM_PROC_NR, EXEC, len(name), stackbytes, 0,name, stack,NIL_PTR); 79 | } 80 | 81 | 82 | PUBLIC execn(name) 83 | char *name; /* pointer to file to be exec'd */ 84 | { 85 | /* Special version used when there are no args and no environment. This call 86 | * is principally used by INIT, to avoid having to allocate MAX_ISTACK_BYTES. 87 | */ 88 | 89 | char stack[4]; 90 | 91 | stack[0] = 0; 92 | stack[1] = 0; 93 | stack[2] = 0; 94 | stack[3] = 0; 95 | return callm1(MM_PROC_NR, EXEC, len(name), 4, 0, name, stack, NIL_PTR); 96 | } 97 | -------------------------------------------------------------------------------- /lib/exit.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int exit(status) 4 | int status; 5 | { 6 | return callm1(MM, EXIT, status, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/fclose.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | fclose(fp) 4 | FILE *fp; 5 | { 6 | register int i; 7 | 8 | for (i=0; i= NFILES) 14 | return(EOF); 15 | fflush(fp); 16 | close(fp->_fd); 17 | if ( testflag(fp,IOMYBUF) && fp->_buf ) 18 | free( fp->_buf ); 19 | free(fp); 20 | return(NULL); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lib/fflush.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | fflush(iop) 5 | FILE *iop; 6 | { 7 | int count; 8 | 9 | if ( testflag(iop,UNBUFF) || !testflag(iop,WRITEMODE) ) 10 | return(0); 11 | 12 | if ( iop->_count <= 0 ) 13 | return(0); 14 | 15 | count = write(iop->_fd,iop->_buf,iop->_count); 16 | 17 | if ( count == iop->_count) { 18 | iop->_count = 0; 19 | iop->_ptr = iop->_buf; 20 | return(count); 21 | } 22 | 23 | iop->_flags |= _ERR; 24 | return(EOF); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lib/fgets.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | char *fgets(str, n, file) 5 | char *str; 6 | unsigned n; 7 | FILE *file; 8 | { 9 | register int ch; 10 | register char *ptr; 11 | 12 | ptr = str; 13 | while ( --n > 0 && (ch = getc(file)) != EOF){ 14 | *ptr++ = ch; 15 | if ( ch == '\n') 16 | break; 17 | } 18 | if (ch == EOF && ptr==str) 19 | return(NULL); 20 | *ptr = '\0'; 21 | return(str); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /lib/fopen.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | #define PMODE 0644 4 | 5 | 6 | FILE *fopen(name,mode) 7 | char *name , *mode; 8 | { 9 | register int i; 10 | FILE *fp; 11 | char *malloc(); 12 | int fd, 13 | flags = 0; 14 | 15 | for (i = 0; _io_table[i] != 0 ; i++) 16 | if ( i >= NFILES ) 17 | return(NULL); 18 | 19 | switch(*mode){ 20 | 21 | case 'w': 22 | flags |= WRITEMODE; 23 | if (( fd = creat (name,PMODE)) < 0) 24 | return(NULL); 25 | break; 26 | 27 | case 'a': 28 | flags |= WRITEMODE; 29 | if (( fd = open(name,1)) < 0 ) 30 | return(NULL); 31 | lseek(fd,0L,2); 32 | break; 33 | 34 | case 'r': 35 | flags |= READMODE; 36 | if (( fd = open (name,0)) < 0 ) 37 | return(NULL); 38 | break; 39 | 40 | default: 41 | return(NULL); 42 | } 43 | 44 | 45 | if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) 46 | return(NULL); 47 | 48 | 49 | fp->_count = 0; 50 | fp->_fd = fd; 51 | fp->_flags = flags; 52 | fp->_buf = malloc( BUFSIZ ); 53 | if ( fp->_buf == NULL ) 54 | fp->_flags |= UNBUFF; 55 | else 56 | fp->_flags |= IOMYBUF; 57 | 58 | fp->_ptr = fp->_buf; 59 | _io_table[i] = fp; 60 | return(fp); 61 | } 62 | -------------------------------------------------------------------------------- /lib/fork.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int fork() 4 | { 5 | return callm1(MM, FORK, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 6 | } 7 | -------------------------------------------------------------------------------- /lib/fprintf.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | fprintf (file, fmt, args) 4 | FILE *file; 5 | char *fmt; 6 | int args; 7 | { 8 | _doprintf (file, fmt, &args); 9 | if ( testflag(file,PERPRINTF) ) 10 | fflush(file); 11 | } 12 | 13 | 14 | printf (fmt, args) 15 | char *fmt; 16 | int args; 17 | { 18 | _doprintf (stdout, fmt, &args); 19 | if ( testflag(stdout,PERPRINTF) ) 20 | fflush(stdout); 21 | } 22 | -------------------------------------------------------------------------------- /lib/fputs.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | fputs(s,file) 4 | register char *s; 5 | FILE *file; 6 | { 7 | while ( *s ) 8 | putc(*s++,file); 9 | } 10 | -------------------------------------------------------------------------------- /lib/fread.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | fread(ptr, size, count, file) 4 | char *ptr; 5 | unsigned size, count; 6 | FILE *file; 7 | { 8 | register int c; 9 | unsigned ndone = 0, s; 10 | 11 | ndone = 0; 12 | if (size) 13 | while ( ndone < count ) { 14 | s = size; 15 | do { 16 | if ((c = getc(file)) != EOF) 17 | *ptr++ = (char) c; 18 | else 19 | return(ndone); 20 | } while (--s); 21 | ndone++; 22 | } 23 | return(ndone); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /lib/freopen.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | FILE *freopen(name,mode,stream) 4 | char *name,*mode; 5 | FILE *stream; 6 | { 7 | FILE *fopen(); 8 | 9 | if ( fclose(stream) != 0 ) 10 | return NULL; 11 | 12 | return fopen(name,mode); 13 | } 14 | -------------------------------------------------------------------------------- /lib/fseek.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | fseek(iop, offset, where) 5 | FILE *iop; 6 | long offset; 7 | { 8 | int count; 9 | long lseek(); 10 | long pos; 11 | 12 | iop->_flags &= ~(_EOF | _ERR); 13 | /* Clear both the end of file and error flags */ 14 | 15 | if ( testflag(iop,READMODE) ) { 16 | if ( where < 2 && iop->_buf && !testflag(iop,UNBUFF) ) { 17 | count = iop->_count; 18 | pos = offset; 19 | 20 | if ( where == 0 ) 21 | pos += count - lseek(fileno(iop), 0L,1) - 1; 22 | /*^^^ This caused the problem : - 1 corrected 23 | it */ 24 | else 25 | offset -= count; 26 | 27 | if ( count > 0 && pos <= count 28 | && pos >= iop->_buf - iop->_ptr ) { 29 | iop->_ptr += (int) pos; 30 | iop->_count -= (int) pos; 31 | return(0); 32 | } 33 | } 34 | pos = lseek(fileno(iop), offset, where); 35 | iop->_count = 0; 36 | } else if ( testflag(iop,WRITEMODE) ) { 37 | fflush(iop); 38 | pos = lseek(fileno(iop), offset, where); 39 | } 40 | return((pos == -1) ? -1 : 0 ); 41 | } 42 | -------------------------------------------------------------------------------- /lib/fstat.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int fstat(fd, buffer) 4 | int fd; 5 | char *buffer; 6 | { 7 | int n; 8 | n = callm1(FS, FSTAT, fd, 0, 0, buffer, NIL_PTR, NIL_PTR); 9 | return(n); 10 | } 11 | -------------------------------------------------------------------------------- /lib/ftell.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | long ftell(iop) 5 | FILE *iop; 6 | { 7 | long result; 8 | long lseek(); 9 | int adjust = 0; 10 | 11 | if ( testflag(iop,READMODE) ) 12 | adjust -= iop->_count; 13 | else if ( testflag(iop,WRITEMODE) && iop->_buf && !testflag(iop,UNBUFF)) 14 | adjust = iop->_ptr - iop->_buf; 15 | else 16 | return(-1); 17 | 18 | result = lseek(fileno(iop), 0L, 1); 19 | 20 | if ( result < 0 ) 21 | return ( result ); 22 | 23 | result += (long) adjust; 24 | return(result); 25 | } 26 | -------------------------------------------------------------------------------- /lib/fwrite.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | fwrite(ptr, size, count, file) 4 | unsigned size, count; 5 | char *ptr; 6 | FILE *file; 7 | { 8 | unsigned s; 9 | unsigned ndone = 0; 10 | 11 | if (size) 12 | while ( ndone < count ) { 13 | s = size; 14 | do { 15 | putc(*ptr++, file); 16 | if (ferror(file)) 17 | return(ndone); 18 | } 19 | while (--s); 20 | ndone++; 21 | } 22 | return(ndone); 23 | } 24 | -------------------------------------------------------------------------------- /lib/getc.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | 5 | getc(iop) 6 | FILE *iop; 7 | { 8 | int ch; 9 | 10 | if ( testflag(iop, (_EOF | _ERR ))) 11 | return (EOF); 12 | 13 | if ( !testflag(iop, READMODE) ) 14 | return (EOF); 15 | 16 | if (--iop->_count <= 0){ 17 | 18 | if ( testflag(iop, UNBUFF) ) 19 | iop->_count = read(iop->_fd,&ch,1); 20 | else 21 | iop->_count = read(iop->_fd,iop->_buf,BUFSIZ); 22 | 23 | if (iop->_count <= 0){ 24 | if (iop->_count == 0) 25 | iop->_flags |= _EOF; 26 | else 27 | iop->_flags |= _ERR; 28 | 29 | return (EOF); 30 | } 31 | else 32 | iop->_ptr = iop->_buf; 33 | } 34 | 35 | if (testflag(iop,UNBUFF)) 36 | return (ch & CMASK); 37 | else 38 | return (*iop->_ptr++ & CMASK); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /lib/getegid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC gid getegid() 4 | { 5 | int k; 6 | k = callm1(MM, GETGID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | if (k < 0) return ( (gid) k); 8 | return( (gid) M.m2_i1); 9 | } 10 | -------------------------------------------------------------------------------- /lib/getenv.c: -------------------------------------------------------------------------------- 1 | #define NULL (char *) 0 2 | char *getenv(name) 3 | register char *name; 4 | { 5 | extern char **environ; 6 | register char **v = environ, *p, *q; 7 | 8 | while ((p = *v) != NULL) { 9 | q = name; 10 | while (*p++ == *q) 11 | if (*q++ == 0) 12 | continue; 13 | if (*(p - 1) != '=') 14 | continue; 15 | return(p); 16 | } 17 | return(0); 18 | } 19 | -------------------------------------------------------------------------------- /lib/geteuid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC uid geteuid() 4 | { 5 | int k; 6 | k = callm1(MM, GETUID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | if (k < 0) return ( (uid) k); 8 | return ((uid) M.m2_i1); 9 | } 10 | -------------------------------------------------------------------------------- /lib/getgid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC gid getgid() 4 | { 5 | int k; 6 | k = callm1(MM, GETGID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | return( (gid) k); 8 | } 9 | -------------------------------------------------------------------------------- /lib/getgrent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * get entry from group file 3 | * 4 | * By: Patrick van Kleef 5 | */ 6 | 7 | #include "../include/grp.h" 8 | 9 | #define PRIVATE static 10 | 11 | PRIVATE char _gr_file[] = "/etc/group"; 12 | PRIVATE char _grbuf[256]; 13 | PRIVATE char _buffer[1024]; 14 | PRIVATE char *_pnt; 15 | PRIVATE char *_buf; 16 | PRIVATE int _gfd = -1; 17 | PRIVATE int _bufcnt; 18 | PRIVATE struct group grp; 19 | 20 | setgrent () 21 | { 22 | if (_gfd >= 0) 23 | lseek (_gfd, 0L, 0); 24 | else 25 | _gfd = open (_gr_file, 0); 26 | 27 | _bufcnt = 0; 28 | return (_gfd); 29 | } 30 | 31 | 32 | endgrent () 33 | { 34 | if (_gfd >= 0) 35 | close (_gfd); 36 | 37 | _gfd = -1; 38 | _bufcnt = 0; 39 | } 40 | 41 | 42 | static getline () 43 | { 44 | if (_gfd < 0 && setgrent () < 0) 45 | return (0); 46 | 47 | _buf = _grbuf; 48 | do { 49 | if (--_bufcnt <= 0){ 50 | if ((_bufcnt = read (_gfd, _buffer, 1024)) <= 0) 51 | return (0); 52 | else 53 | _pnt = _buffer; 54 | } 55 | *_buf++ = *_pnt++; 56 | } while (*_pnt != '\n'); 57 | _pnt++; 58 | _bufcnt--; 59 | *_buf = 0; 60 | _buf = _grbuf; 61 | return (1); 62 | } 63 | 64 | static skip_period () 65 | { 66 | while (*_buf != ':') 67 | _buf++; 68 | *_buf++ = '\0'; 69 | } 70 | 71 | struct group *getgrent () 72 | { 73 | if (getline () == 0) 74 | return (0); 75 | 76 | grp.name = _buf; 77 | skip_period (); 78 | grp.passwd = _buf; 79 | skip_period (); 80 | grp.gid = atoi (_buf); 81 | skip_period (); 82 | return (&grp); 83 | } 84 | 85 | struct group *getgrnam (name) 86 | char *name; 87 | { 88 | struct group *grp; 89 | 90 | setgrent (); 91 | while ((grp = getgrent ()) != 0) 92 | if (!strcmp (grp -> name, name)) 93 | break; 94 | endgrent (); 95 | if (grp != 0) 96 | return (grp); 97 | else 98 | return (0); 99 | } 100 | 101 | struct group *getgrgid (gid) 102 | int gid; 103 | { 104 | struct group *grp; 105 | 106 | setgrent (); 107 | while ((grp = getgrent ()) != 0) 108 | if (grp -> gid == gid) 109 | break; 110 | endgrent (); 111 | if (grp != 0) 112 | return (grp); 113 | else 114 | return (0); 115 | } 116 | -------------------------------------------------------------------------------- /lib/getpass.c: -------------------------------------------------------------------------------- 1 | #include "../h/sgtty.h" 2 | 3 | static char pwdbuf[9]; 4 | 5 | char * getpass(prompt) 6 | char *prompt; 7 | { 8 | int i = 0; 9 | struct sgttyb tty; 10 | 11 | prints(prompt); 12 | ioctl(0, TIOCGETP, &tty); 13 | tty.sg_flags = 06020; 14 | ioctl(0, TIOCSETP, &tty); 15 | i = read(0, pwdbuf, 9); 16 | while (pwdbuf[i - 1] != '\n') 17 | read(0, &pwdbuf[i - 1], 1); 18 | pwdbuf[i - 1] = '\0'; 19 | tty.sg_flags = 06030; 20 | ioctl(0, TIOCSETP, &tty); 21 | prints("\n"); 22 | return(pwdbuf); 23 | } 24 | -------------------------------------------------------------------------------- /lib/getpid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int getpid() 4 | { 5 | return callm1(MM, GETPID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 6 | } 7 | -------------------------------------------------------------------------------- /lib/getpwent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * get entry from password file 3 | * 4 | * By Patrick van Kleef 5 | * 6 | */ 7 | 8 | 9 | #include "../include/pwd.h" 10 | 11 | #define PRIVATE static 12 | 13 | 14 | PRIVATE char _pw_file[] = "/etc/passwd"; 15 | PRIVATE char _pwbuf[256]; 16 | PRIVATE char _buffer[1024]; 17 | PRIVATE char *_pnt; 18 | PRIVATE char *_buf; 19 | PRIVATE int _pw = -1; 20 | PRIVATE int _bufcnt; 21 | PRIVATE struct passwd pwd; 22 | 23 | setpwent() 24 | { 25 | if (_pw >= 0) 26 | lseek (_pw, 0L, 0); 27 | else 28 | _pw = open (_pw_file, 0); 29 | 30 | _bufcnt = 0; 31 | return (_pw); 32 | } 33 | 34 | 35 | endpwent () 36 | { 37 | if (_pw >= 0) 38 | close (_pw); 39 | 40 | _pw = -1; 41 | _bufcnt = 0; 42 | } 43 | 44 | static getline () 45 | { 46 | if (_pw < 0 && setpwent () < 0) 47 | return (0); 48 | _buf = _pwbuf; 49 | do { 50 | if (--_bufcnt <= 0){ 51 | if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0) 52 | return (0); 53 | else 54 | _pnt = _buffer; 55 | } 56 | *_buf++ = *_pnt++; 57 | } while (*_pnt != '\n'); 58 | _pnt++; 59 | _bufcnt--; 60 | *_buf = 0; 61 | _buf = _pwbuf; 62 | return (1); 63 | } 64 | 65 | static skip_period () 66 | { 67 | while (*_buf != ':') 68 | _buf++; 69 | 70 | *_buf++ = '\0'; 71 | } 72 | 73 | struct passwd *getpwent () 74 | { 75 | if (getline () == 0) 76 | return (0); 77 | 78 | pwd.name = _buf; 79 | skip_period (); 80 | pwd.passwd = _buf; 81 | skip_period (); 82 | pwd.uid = atoi (_buf); 83 | skip_period (); 84 | pwd.gid = atoi (_buf); 85 | skip_period (); 86 | pwd.gecos = _buf; 87 | skip_period (); 88 | pwd.dir = _buf; 89 | skip_period (); 90 | pwd.shell = _buf; 91 | 92 | return (&pwd); 93 | } 94 | 95 | struct passwd *getpwnam (name) 96 | char *name; 97 | { 98 | struct passwd *pwd; 99 | 100 | setpwent (); 101 | while ((pwd = getpwent ()) != 0) 102 | if (!strcmp (pwd -> name, name)) 103 | break; 104 | endpwent (); 105 | if (pwd != 0) 106 | return (pwd); 107 | else 108 | return (0); 109 | } 110 | 111 | struct passwd *getpwuid (uid) 112 | int uid; 113 | { 114 | struct passwd *pwd; 115 | 116 | setpwent (); 117 | while ((pwd = getpwent ()) != 0) 118 | if (pwd -> uid == uid) 119 | break; 120 | endpwent (); 121 | if (pwd != 0) 122 | return (pwd); 123 | else 124 | return (0); 125 | } 126 | -------------------------------------------------------------------------------- /lib/gets.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | char *gets(str) 4 | char *str; 5 | { 6 | register int ch; 7 | register char *ptr; 8 | 9 | ptr = str; 10 | while ((ch = getc(stdin)) != EOF && ch != '\n') 11 | *ptr++ = ch; 12 | 13 | if (ch == EOF && ptr==str) 14 | return(NULL); 15 | *ptr = '\0'; 16 | return(str); 17 | } 18 | -------------------------------------------------------------------------------- /lib/getuid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC uid getuid() 4 | { 5 | int k; 6 | k = callm1(MM, GETUID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | return( (uid) k); 8 | } 9 | -------------------------------------------------------------------------------- /lib/getutil.s: -------------------------------------------------------------------------------- 1 | .globl _get_base, _get_size, _get_tot_mem 2 | .globl endbss 3 | 4 | |*========================================================================* 5 | | utilities * 6 | |*========================================================================* 7 | _get_base: | return click at which prog starts 8 | mov ax,ds 9 | ret 10 | 11 | _get_size: | return prog size in bytes (text+data+bss) 12 | mov ax,#endbss | end is compiler label at end of bss 13 | ret 14 | 15 | | Find out how much memory the machine has, including vectors, kernel MM, etc. 16 | _get_tot_mem: 17 | cli 18 | push es 19 | push di 20 | mov ax,#8192 | start search at 128K (8192 clicks) 21 | sub di,di 22 | L1: mov es,ax 23 | seg es 24 | mov (di),#0xA5A4 | write random bit pattern to memory 25 | xor bx,bx 26 | seg es 27 | mov bx,(di) | read back pattern just written 28 | cmp bx,#0xA5A4 | compare with expected value 29 | jne L2 | if different, no memory present 30 | add ax,#4096 | advance counter by 64K 31 | cmp ax,#0xA000 | stop seaching at 640K 32 | jne L1 33 | L2: pop di 34 | pop es 35 | sti 36 | ret 37 | -------------------------------------------------------------------------------- /lib/head.s: -------------------------------------------------------------------------------- 1 | .globl _main, _stackpt, begtext, begdata, begbss, _data_org, _exit 2 | .text 3 | begtext: 4 | jmp L0 5 | .zerow 7 | kernel uses this area as stack for inital IRET 6 | L0: mov sp,_stackpt 7 | call _main 8 | L1: jmp L1 | this will never be executed 9 | _exit: jmp _exit | this will never be executed either 10 | .data 11 | begdata: 12 | _data_org: | fs needs to know where build stuffed table 13 | .word 0xDADA,0,0,0,0,0,0,0 | first 8 words of MM, FS, INIT are for stack 14 | | 0xDADA is magic number for build 15 | .bss 16 | begbss: 17 | -------------------------------------------------------------------------------- /lib/index.c: -------------------------------------------------------------------------------- 1 | char *index(s, c) 2 | register char *s, c; 3 | { 4 | do { 5 | if (*s == c) 6 | return(s); 7 | } while (*s++ != 0); 8 | return(0); 9 | } 10 | -------------------------------------------------------------------------------- /lib/ioctl.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | #include "../h/com.h" 3 | #include "../include/sgtty.h" 4 | 5 | PUBLIC int ioctl(fd, request, u) 6 | int fd; 7 | int request; 8 | union { 9 | struct sgttyb *argp; 10 | struct tchars *argt; 11 | } u; 12 | 13 | { 14 | int n; 15 | long erase, kill, intr, quit, xon, xoff, eof, brk; 16 | 17 | M.TTY_REQUEST = request; 18 | M.TTY_LINE = fd; 19 | 20 | switch(request) { 21 | case TIOCSETP: 22 | erase = u.argp->sg_erase & 0377; 23 | kill = u.argp->sg_kill & 0377; 24 | M.TTY_SPEK = (erase << 8) | kill; 25 | M.TTY_FLAGS = u.argp->sg_flags; 26 | n = callx(FS, IOCTL); 27 | return(n); 28 | 29 | case TIOCSETC: 30 | intr = u.argt->t_intrc & 0377; 31 | quit = u.argt->t_quitc & 0377; 32 | xon = u.argt->t_startc & 0377; 33 | xoff = u.argt->t_stopc & 0377; 34 | eof = u.argt->t_eofc & 0377; 35 | brk = u.argt->t_brkc & 0377; /* not used at the moment */ 36 | M.TTY_SPEK = (intr<<24) | (quit<<16) | (xon<<8) | (xoff<<0); 37 | M.TTY_FLAGS = (eof<<8) | (brk<<0); 38 | n = callx(FS, IOCTL); 39 | return(n); 40 | 41 | case TIOCGETP: 42 | n = callx(FS, IOCTL); 43 | u.argp->sg_erase = (M.TTY_SPEK >> 8) & 0377; 44 | u.argp->sg_kill = (M.TTY_SPEK >> 0) & 0377; 45 | u.argp->sg_flags = M.TTY_FLAGS; 46 | return(n); 47 | 48 | case TIOCGETC: 49 | n = callx(FS, IOCTL); 50 | u.argt->t_intrc = (M.TTY_SPEK >> 24) & 0377; 51 | u.argt->t_quitc = (M.TTY_SPEK >> 16) & 0377; 52 | u.argt->t_startc = (M.TTY_SPEK >> 8) & 0377; 53 | u.argt->t_stopc = (M.TTY_SPEK >> 0) & 0377; 54 | u.argt->t_eofc = (M.TTY_FLAGS >> 8) & 0377; 55 | u.argt->t_brkc = (M.TTY_FLAGS >> 8) & 0377; 56 | return(n); 57 | 58 | default: 59 | n = -1; 60 | errno = -(EINVAL); 61 | return(n); 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /lib/isatty.c: -------------------------------------------------------------------------------- 1 | #include "../include/stat.h" 2 | 3 | int isatty(fd) 4 | int fd; 5 | { 6 | struct stat s; 7 | 8 | fstat(fd, &s); 9 | if ( (s.st_mode&S_IFMT) == S_IFCHR) 10 | return(1); 11 | else 12 | return(0); 13 | } 14 | -------------------------------------------------------------------------------- /lib/itoa.c: -------------------------------------------------------------------------------- 1 | /* Integer to ASCII for signed decimal integers. */ 2 | 3 | static int next; 4 | static char qbuf[8]; 5 | 6 | char *itoa(n) 7 | int n; 8 | { 9 | register int r, k; 10 | int flag = 0; 11 | 12 | next = 0; 13 | if (n < 0) { 14 | qbuf[next++] = '-'; 15 | n = -n; 16 | } 17 | if (n == 0) { 18 | qbuf[next++] = '0'; 19 | } else { 20 | k = 10000; 21 | while (k > 0) { 22 | r = n/k; 23 | if (flag || r > 0) { 24 | qbuf[next++] = '0' + r; 25 | flag = 1; 26 | } 27 | n -= r * k; 28 | k = k/10; 29 | } 30 | } 31 | qbuf[next] = 0; 32 | return(qbuf); 33 | } 34 | -------------------------------------------------------------------------------- /lib/kill.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int kill(proc, sig) 4 | int proc; /* which process is to be sent the signal */ 5 | int sig; /* signal number */ 6 | { 7 | return callm1(MM, KILL, proc, sig, 0, NIL_PTR, NIL_PTR, NIL_PTR); 8 | } 9 | -------------------------------------------------------------------------------- /lib/link.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int link(name, name2) 4 | char *name, *name2; 5 | { 6 | return callm1(FS, LINK, len(name), len(name2), 0, name, name2, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/lseek.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC long lseek(fd, offset, whence) 4 | int fd; 5 | long offset; 6 | int whence; 7 | { 8 | int k; 9 | M.m2_i1 = fd; 10 | M.m2_l1 = offset; 11 | M.m2_i2 = whence; 12 | k = callx(FS, LSEEK); 13 | if (k != OK) return( (long) k); /* send itself failed */ 14 | return(M.m2_l1); 15 | } 16 | -------------------------------------------------------------------------------- /lib/malloc.c: -------------------------------------------------------------------------------- 1 | 2 | #define CLICK_SIZE 16 3 | typedef unsigned short vir_bytes; 4 | extern bcopy(); 5 | 6 | #define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1)) 7 | #define BUSY 1 8 | #define NEXT(p) (* (char **) (p)) 9 | 10 | extern char *sbrk(); 11 | static char *bottom, *top; 12 | 13 | static grow(len) 14 | unsigned len; 15 | { 16 | register char *p; 17 | 18 | p = (char *) ALIGN((vir_bytes) top + sizeof(char *) + len, CLICK_SIZE) 19 | - sizeof(char *); 20 | if (p < top || brk(p) < 0) 21 | return(0); 22 | top = p; 23 | for (p = bottom; NEXT(p) != 0; p = (char *) (* (vir_bytes *) p & ~BUSY)) 24 | ; 25 | NEXT(p) = top; 26 | NEXT(top) = 0; 27 | return(1); 28 | } 29 | 30 | char *malloc(size) 31 | unsigned size; 32 | { 33 | register char *p, *next, *new; 34 | register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *); 35 | 36 | if ((p = bottom) == 0) { 37 | top = bottom = p = sbrk(sizeof(char *)); 38 | NEXT(top) = 0; 39 | } 40 | while ((next = NEXT(p)) != 0) 41 | if ((vir_bytes) next & BUSY) /* already in use */ 42 | p = (char *) ((vir_bytes) next & ~BUSY); 43 | else { 44 | while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) 45 | next = new; 46 | if (next - p >= len) { /* fits */ 47 | if ((new = p + len) < next) /* too big */ 48 | NEXT(new) = next; 49 | NEXT(p) = (char *) ((vir_bytes) new | BUSY); 50 | return(p + sizeof(char *)); 51 | } 52 | p = next; 53 | } 54 | return grow(len) ? malloc(size) : 0; 55 | } 56 | 57 | char *realloc(old, size) 58 | char *old; 59 | unsigned size; 60 | { 61 | register char *p = old - sizeof(char *), *next, *new; 62 | register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *), n; 63 | 64 | next = (char *) (* (vir_bytes *) p & ~BUSY); 65 | n = next - old; /* old size */ 66 | while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) 67 | next = new; 68 | if (next - p >= len) { /* does it still fit */ 69 | if ((new = p + len) < next) { /* even too big */ 70 | NEXT(new) = next; 71 | NEXT(p) = (char *) ((vir_bytes) new | BUSY); 72 | } 73 | else 74 | NEXT(p) = (char *) ((vir_bytes) next | BUSY); 75 | return(old); 76 | } 77 | if ((new = malloc(size)) == 0) /* it didn't fit */ 78 | return(0); 79 | bcopy(old, new, n); /* n < size */ 80 | * (vir_bytes *) p &= ~BUSY; 81 | return(new); 82 | } 83 | 84 | free(p) 85 | char *p; 86 | { 87 | * (vir_bytes *) (p - sizeof(char *)) &= ~BUSY; 88 | } 89 | -------------------------------------------------------------------------------- /lib/message.c: -------------------------------------------------------------------------------- 1 | #include "../h/const.h" 2 | #include "../h/type.h" 3 | 4 | message M; 5 | -------------------------------------------------------------------------------- /lib/minix/crtso.s: -------------------------------------------------------------------------------- 1 | | This is the C run-time start-off routine. It's job is to take the 2 | | arguments as put on the stack by EXEC, and to parse them and set them up the 3 | | way _main expects them. 4 | 5 | .globl _main, _exit, crtso, _environ 6 | .globl begtext, begdata, begbss, endtext, enddata, endbss 7 | .text 8 | begtext: 9 | crtso: mov bx,sp 10 | mov cx,(bx) 11 | add bx,*2 12 | mov ax,cx 13 | inc ax 14 | shl ax,#1 15 | add ax,bx 16 | mov _environ,ax | save envp in environ 17 | push ax | push environ 18 | push bx | push argv 19 | push cx | push argc 20 | call _main 21 | add sp,*6 22 | push ax | push exit status 23 | call _exit 24 | 25 | .data 26 | begdata: 27 | _environ: .word 0 28 | .bss 29 | begbss: 30 | -------------------------------------------------------------------------------- /lib/minix/end.s: -------------------------------------------------------------------------------- 1 | .globl endtext, enddata, endbss, _end, _edata 2 | .text 3 | endtext: 4 | .data 5 | enddata: 6 | _edata: 7 | .bss 8 | endbss: 9 | _end: 10 | -------------------------------------------------------------------------------- /lib/minix/head.s: -------------------------------------------------------------------------------- 1 | .globl _main, _stackpt, begtext, begdata, begbss, _data_org, _exit 2 | .text 3 | begtext: 4 | jmp L0 5 | .zerow 7 | kernel uses this area as stack for inital IRET 6 | L0: mov sp,_stackpt 7 | call _main 8 | L1: jmp L1 | this will never be executed 9 | _exit: jmp _exit | this will never be executed either 10 | .data 11 | begdata: 12 | _data_org: | fs needs to know where build stuffed table 13 | .word 0xDADA,0,0,0,0,0,0,0 | first 16 words of MM, FS, INIT are for stack 14 | | 0xDADA is magic number for build 15 | .bss 16 | begbss: 17 | -------------------------------------------------------------------------------- /lib/minix/setjmp.s: -------------------------------------------------------------------------------- 1 | .globl _setjmp, _longjmp 2 | .text 3 | _setjmp: mov bx,sp 4 | mov ax,(bx) 5 | mov bx,*2(bx) 6 | mov (bx),bp 7 | mov *2(bx),sp 8 | mov *4(bx),ax 9 | xor ax,ax 10 | ret 11 | 12 | _longjmp: xor ax,ax 13 | push bp 14 | mov bp,sp 15 | mov bx,*4(bp) 16 | mov ax,*6(bp) 17 | or ax,ax 18 | jne L1 19 | inc ax 20 | L1: mov cx,(bx) 21 | L2: cmp cx,*0(bp) 22 | je L3 23 | mov bp,*0(bp) 24 | or bp,bp 25 | jne L2 26 | hlt 27 | L3: 28 | mov bp,*0(bp) 29 | mov sp,*2(bx) 30 | mov cx,*4(bx) 31 | mov bx,sp 32 | mov (bx),cx 33 | ret 34 | 35 | 36 | -------------------------------------------------------------------------------- /lib/mknod.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int mknod(name, mode, addr) 4 | char *name; 5 | int mode, addr; 6 | { 7 | return callm1(FS, MKNOD, len(name), mode, addr, name, NIL_PTR, NIL_PTR); 8 | } 9 | -------------------------------------------------------------------------------- /lib/mktemp.c: -------------------------------------------------------------------------------- 1 | /* mktemp - make a name for a temporary file */ 2 | 3 | char *mktemp(template) 4 | char *template; 5 | { 6 | int pid, k; 7 | char *p; 8 | 9 | pid = getpid(); /* get process id as semi-unique number */ 10 | p = template; 11 | while (*p++) ; /* find end of string */ 12 | p--; /* backup to last character */ 13 | 14 | /* Replace XXXXXX at end of template with pid. */ 15 | while (*--p == 'X') { 16 | *p = '0' + (pid % 10); 17 | pid = pid/10; 18 | } 19 | return(template); 20 | } 21 | -------------------------------------------------------------------------------- /lib/mount.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int mount(special, name, rwflag) 4 | char *name, *special; 5 | int rwflag; 6 | { 7 | return callm1(FS, MOUNT, len(special), len(name), rwflag, special, name, NIL_PTR); 8 | } 9 | -------------------------------------------------------------------------------- /lib/open.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int open(name, mode) 4 | char* name; 5 | int mode; 6 | { 7 | return callm3(FS, OPEN, mode, name); 8 | } 9 | -------------------------------------------------------------------------------- /lib/pause.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int pause() 4 | { 5 | return callm1(MM, PAUSE, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 6 | } 7 | -------------------------------------------------------------------------------- /lib/perror.c: -------------------------------------------------------------------------------- 1 | /* perror(s) print the current error message. */ 2 | 3 | #include "../h/error.h" 4 | extern int errno; 5 | char *error_message[NERROR+1] = { 6 | "Error 0", 7 | "Not owner", 8 | "No such file or directory", 9 | "No such process", 10 | "Interrupted system call", 11 | "I/O error", 12 | "No such device or address", 13 | "Arg list too long", 14 | "Exec format error", 15 | "Bad file number", 16 | "No children", 17 | "No more processes", 18 | "Not enough core", 19 | "Permission denied", 20 | "Bad address", 21 | "Block device required", 22 | "Mount device busy", 23 | "File exists", 24 | "Cross-device link", 25 | "No such device", 26 | "Not a directory", 27 | "Is a directory", 28 | "Invalid argument", 29 | "File table overflow", 30 | "Too many open files", 31 | "Not a typewriter", 32 | "Text file busy", 33 | "File too large", 34 | "No space left on device", 35 | "Illegal seek", 36 | "Read-only file system", 37 | "Too many links", 38 | "Broken pipe", 39 | "Math argument", 40 | "Result too large" 41 | }; 42 | 43 | 44 | perror(s) 45 | char *s; 46 | { 47 | if (errno < 0 || errno > NERROR) { 48 | write(2, "Invalid errno\n", 14); 49 | } else { 50 | write(2, s, slen(s)); 51 | write(2, ": ", 2); 52 | write(2, error_message[errno], slen(error_message[errno])); 53 | write(2, "\n", 1); 54 | } 55 | } 56 | 57 | static int slen(s) 58 | char *s; 59 | { 60 | int k = 0; 61 | 62 | while (*s++) k++; 63 | return(k); 64 | } 65 | -------------------------------------------------------------------------------- /lib/pipe.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int pipe(fild) 4 | int fild[2]; 5 | { 6 | int k; 7 | k = callm1(FS, PIPE, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 8 | if (k >= 0) { 9 | fild[0] = M.m1_i1; 10 | fild[1] = M.m1_i2; 11 | return(0); 12 | } else 13 | return(k); 14 | } 15 | -------------------------------------------------------------------------------- /lib/printdat.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | char __stdin[BUFSIZ]; 4 | char __stdout[BUFSIZ]; 5 | 6 | struct _io_buf _stdin = { 7 | 0, 0, READMODE , __stdin, __stdin 8 | }; 9 | 10 | struct _io_buf _stdout = { 11 | 1, 0, WRITEMODE + PERPRINTF, __stdout, __stdout 12 | }; 13 | 14 | struct _io_buf _stderr = { 15 | 2, 0, WRITEMODE + UNBUFF, NULL, NULL 16 | }; 17 | 18 | struct _io_buf *_io_table[NFILES] = { 19 | &_stdin, 20 | &_stdout, 21 | &_stderr, 22 | 0 23 | }; 24 | -------------------------------------------------------------------------------- /lib/printk.c: -------------------------------------------------------------------------------- 1 | /* This is a special version of printf. It is used only by the operating 2 | * system itself, and should never be included in user programs. The name 3 | * printk never appears in the operating system, because the macro printf 4 | * has been defined as printk there. 5 | */ 6 | 7 | 8 | #define MAXDIGITS 12 9 | 10 | printk(s, arglist) 11 | char *s; 12 | int *arglist; 13 | { 14 | int w, k, r, *valp; 15 | unsigned u; 16 | long l, *lp; 17 | char a[MAXDIGITS], *p, *p1, c; 18 | 19 | valp = (int *) &arglist; 20 | while (*s != '\0') { 21 | if (*s != '%') { 22 | putc(*s++); 23 | continue; 24 | } 25 | 26 | w = 0; 27 | s++; 28 | while (*s >= '0' && *s <= '9') { 29 | w = 10 * w + (*s - '0'); 30 | s++; 31 | } 32 | 33 | lp = (long *) valp; 34 | 35 | switch(*s) { 36 | case 'd': k = *valp++; l = k; r = 10; break; 37 | case 'o': k = *valp++; u = k; l = u; r = 8; break; 38 | case 'x': k = *valp++; u = k; l = u; r = 16; break; 39 | case 'D': l = *lp++; r = 10; valp = (int *) lp; break; 40 | case 'O': l = *lp++; r = 8; valp = (int *) lp; break; 41 | case 'X': l = *lp++; r = 16; valp = (int *) lp; break; 42 | case 'c': k = *valp++; putc(k); s++; continue; 43 | case 's': p = (char *) *valp++; 44 | p1 = p; 45 | while(c = *p++) putc(c); s++; 46 | if ( (k = w - (p-p1-1)) > 0) while (k--) putc(' '); 47 | continue; 48 | default: putc('%'); putc(*s++); continue; 49 | } 50 | 51 | k = bintoascii(l, r, a); 52 | if ( (r = w - k) > 0) while(r--) putc(' '); 53 | for (r = k - 1; r >= 0; r--) putc(a[r]); 54 | s++; 55 | } 56 | } 57 | 58 | 59 | 60 | static int bintoascii(num, radix, a) 61 | long num; 62 | int radix; 63 | char a[MAXDIGITS]; 64 | { 65 | 66 | int i, n, hit, negative; 67 | 68 | negative = 0; 69 | if (num == 0) {a[0] = '0'; return(1);} 70 | if (num < 0 && radix == 10) {num = -num; negative++;} 71 | for (n = 0; n < MAXDIGITS; n++) a[n] = 0; 72 | n = 0; 73 | 74 | do { 75 | if (radix == 10) {a[n] = num % 10; num = (num -a[n])/10;} 76 | if (radix == 8) {a[n] = num & 0x7; num = (num >> 3) & 0x1FFFFFFF;} 77 | if (radix == 16) {a[n] = num & 0xF; num = (num >> 4) & 0x0FFFFFFF;} 78 | n++; 79 | } while (num != 0); 80 | 81 | /* Convert to ASCII. */ 82 | hit = 0; 83 | for (i = n - 1; i >= 0; i--) { 84 | if (a[i] == 0 && hit == 0) { 85 | a[i] = ' '; 86 | } else { 87 | if (a[i] < 10) 88 | a[i] += '0'; 89 | else 90 | a[i] += 'A' - 10; 91 | hit++; 92 | } 93 | } 94 | if (negative) a[n++] = '-'; 95 | return(n); 96 | } 97 | -------------------------------------------------------------------------------- /lib/prints.c: -------------------------------------------------------------------------------- 1 | /* prints() is like printf(), except that it can only handle %s and %c. It 2 | * cannot print any of the numeric types such as %d, %o, etc. It has the 3 | * advantage of not requiring the runtime code for converting binary numbers 4 | * to ASCII, which saves 1K bytes in the object program. Since many of the 5 | * small utilities do not need numeric printing, they all use prints. 6 | */ 7 | 8 | 9 | #define TRUNC_SIZE 128 10 | char Buf[TRUNC_SIZE], *Bufp; 11 | 12 | #define OUT 1 13 | 14 | prints(s, arglist) 15 | register char *s; 16 | int *arglist; 17 | { 18 | register w; 19 | int k, r, *valp; 20 | char *p, *p1, c; 21 | 22 | Bufp = Buf; 23 | valp = (int *) &arglist; 24 | while (*s != '\0') { 25 | if (*s != '%') { 26 | put(*s++); 27 | continue; 28 | } 29 | 30 | w = 0; 31 | s++; 32 | while (*s >= '0' && *s <= '9') { 33 | w = 10 * w + (*s - '0'); 34 | s++; 35 | } 36 | 37 | 38 | switch(*s) { 39 | case 'c': k = *valp++; put(k); s++; continue; 40 | case 's': p = (char *) *valp++; 41 | p1 = p; 42 | while(c = *p++) put(c); s++; 43 | if ( (k = w - (p-p1-1)) > 0) while (k--) put(' '); 44 | continue; 45 | default: put('%'); put(*s++); continue; 46 | } 47 | 48 | } 49 | write(OUT, Buf, Bufp - Buf); /* write everything in one blow. */ 50 | } 51 | 52 | static put(c) 53 | char c; 54 | { 55 | if (Bufp < &Buf[TRUNC_SIZE]) *Bufp++ = c; 56 | } 57 | -------------------------------------------------------------------------------- /lib/putc.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | putc(ch, iop) 5 | char ch; 6 | FILE *iop; 7 | { 8 | int n, 9 | didwrite = 0; 10 | 11 | if (testflag(iop, (_ERR | _EOF))) 12 | return (EOF); 13 | 14 | if ( !testflag(iop,WRITEMODE)) 15 | return(EOF); 16 | 17 | if ( testflag(iop,UNBUFF)){ 18 | n = write(iop->_fd,&ch,1); 19 | iop->_count = 1; 20 | didwrite++; 21 | } 22 | else{ 23 | *iop->_ptr++ = ch; 24 | if ((++iop->_count) >= BUFSIZ && !testflag(iop,STRINGS) ){ 25 | n = write(iop->_fd,iop->_buf,iop->_count); 26 | iop->_ptr = iop->_buf; 27 | didwrite++; 28 | } 29 | } 30 | 31 | if (didwrite){ 32 | if (n<=0 || iop->_count != n){ 33 | if (n < 0) 34 | iop->_flags |= _ERR; 35 | else 36 | iop->_flags |= _EOF; 37 | return (EOF); 38 | } 39 | iop->_count=0; 40 | } 41 | return(0); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /lib/rand.c: -------------------------------------------------------------------------------- 1 | static long seed = 1L; 2 | 3 | int rand() 4 | { 5 | seed = (1103515245L * seed + 12345) & 0x7FFFFFFF; 6 | return((int) (seed & 077777)); 7 | } 8 | -------------------------------------------------------------------------------- /lib/read.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int read(fd, buffer, nbytes) 4 | int fd; 5 | char *buffer; 6 | int nbytes; 7 | { 8 | int n; 9 | n = callm1(FS, READ, fd, nbytes, 0, buffer, NIL_PTR, NIL_PTR); 10 | return(n); 11 | } 12 | -------------------------------------------------------------------------------- /lib/read_me: -------------------------------------------------------------------------------- 1 | The sources to the library are contained in an archive to save disk space. 2 | Since MINIX uses a minimum of 1K for each file, no matter how small, 3 | the sources take up less space when packed together in an archive. To 4 | extract them, make sure there is at least 120K of free disk space, and type: 5 | ar xv libsrc.a 6 | -------------------------------------------------------------------------------- /lib/regsub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * regsub 3 | * 4 | * Copyright (c) 1986 by University of Toronto. 5 | * Written by Henry Spencer. Not derived from licensed software. 6 | * 7 | * Permission is granted to anyone to use this software for any 8 | * purpose on any computer system, and to redistribute it freely, 9 | * subject to the following restrictions: 10 | * 11 | * 1. The author is not responsible for the consequences of use of 12 | * this software, no matter how awful, even if they arise 13 | * from defects in it. 14 | * 15 | * 2. The origin of this software must not be misrepresented, either 16 | * by explicit claim or by omission. 17 | * 18 | * 3. Altered versions must be plainly marked as such, and must not 19 | * be misrepresented as being the original software. 20 | */ 21 | #include "../include/stdio.h" 22 | #include "../include/regexp.h" 23 | /* 24 | * The first byte of the regexp internal "program" is actually this magic 25 | * number; the start node begins in the second byte. 26 | */ 27 | #define MAGIC 0234 28 | 29 | 30 | #define CHARBITS 0377 31 | #ifndef CHARBITS 32 | #define UCHARAT(p) ((int)*(unsigned char *)(p)) 33 | #else 34 | #define UCHARAT(p) ((int)*(p)&CHARBITS) 35 | #endif 36 | 37 | /* 38 | - regsub - perform substitutions after a regexp match 39 | */ 40 | regsub(prog, source, dest) 41 | regexp *prog; 42 | char *source; 43 | char *dest; 44 | { 45 | register char *src; 46 | register char *dst; 47 | register char c; 48 | register int no; 49 | register int len; 50 | extern char *strncpy(); 51 | 52 | if (prog == NULL || source == NULL || dest == NULL) { 53 | regerror("NULL parm to regsub"); 54 | return; 55 | } 56 | if (UCHARAT(prog->program) != MAGIC) { 57 | regerror("damaged regexp fed to regsub"); 58 | return; 59 | } 60 | 61 | src = source; 62 | dst = dest; 63 | while ((c = *src++) != '\0') { 64 | if (c == '&') 65 | no = 0; 66 | else if (c == '\\' && '0' <= *src && *src <= '9') 67 | no = *src++ - '0'; 68 | else 69 | no = -1; 70 | 71 | if (no < 0) { /* Ordinary character. */ 72 | if (c == '\\' && (*src == '\\' || *src == '&')) 73 | c = *src++; 74 | *dst++ = c; 75 | } else if (prog->startp[no] != NULL && prog->endp[no] != NULL) { 76 | len = prog->endp[no] - prog->startp[no]; 77 | strncpy(dst, prog->startp[no], len); 78 | dst += len; 79 | if (len !=0 && *(dst-1) == '\0') { /* strncpy hit NUL. */ 80 | regerror("damaged match string"); 81 | return; 82 | } 83 | } 84 | } 85 | *dst++ = '\0'; 86 | } 87 | -------------------------------------------------------------------------------- /lib/rindex.c: -------------------------------------------------------------------------------- 1 | char *rindex(s, c) 2 | register char *s, c; 3 | { 4 | register char *result; 5 | 6 | result = 0; 7 | do 8 | if (*s == c) 9 | result = s; 10 | while (*s++ != 0); 11 | return(result); 12 | } 13 | -------------------------------------------------------------------------------- /lib/run: -------------------------------------------------------------------------------- 1 | for i in *.s 2 | do as -o `basename $i .s`.o $i 3 | done 4 | for i in *.c 5 | do cc -c -O $i 6 | done 7 | ar r lib.a `lorder *.o | tsort 2>/dev/null` 8 | echo "lib.a done." 9 | -------------------------------------------------------------------------------- /lib/sendrec.s: -------------------------------------------------------------------------------- 1 | | See ../h/com.h for C definitions 2 | SEND = 1 3 | RECEIVE = 2 4 | BOTH = 3 5 | SYSVEC = 32 6 | 7 | |*========================================================================* 8 | | send and receive * 9 | |*========================================================================* 10 | | send(), receive(), sendrec() all save bp, but destroy ax, bx, and cx. 11 | .globl _send, _receive, _sendrec 12 | _send: mov cx,*SEND | send(dest, ptr) 13 | jmp L0 14 | 15 | _receive: 16 | mov cx,*RECEIVE | receive(src, ptr) 17 | jmp L0 18 | 19 | _sendrec: 20 | mov cx,*BOTH | sendrec(srcdest, ptr) 21 | jmp L0 22 | 23 | L0: push bp | save bp 24 | mov bp,sp | can't index off sp 25 | mov ax,4(bp) | ax = dest-src 26 | mov bx,6(bp) | bx = message pointer 27 | int SYSVEC | trap to the kernel 28 | pop bp | restore bp 29 | ret | return 30 | 31 | -------------------------------------------------------------------------------- /lib/setbuf.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | 4 | setbuf(iop, buffer) 5 | FILE *iop; 6 | char *buffer; 7 | { 8 | if ( iop->_buf && testflag(iop,IOMYBUF) ) 9 | free(iop->_buf); 10 | 11 | iop->_flags &= ~(IOMYBUF | UNBUFF | PERPRINTF); 12 | 13 | iop->_buf = buffer; 14 | 15 | if ( iop->_buf == NULL ) 16 | iop->_flags |= UNBUFF; 17 | 18 | iop->_ptr = iop->_buf; 19 | iop->_count = 0; 20 | } 21 | -------------------------------------------------------------------------------- /lib/setgid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int setgid(grp) 4 | int grp; 5 | { 6 | return callm1(MM, SETGID, grp, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/setjmp.s: -------------------------------------------------------------------------------- 1 | .globl _setjmp, _longjmp 2 | .globl csv 3 | .text 4 | _setjmp: mov bx,sp 5 | mov ax,(bx) 6 | mov bx,*2(bx) 7 | mov (bx),bp 8 | mov *2(bx),sp 9 | mov *4(bx),ax 10 | xor ax,ax 11 | ret 12 | 13 | _longjmp: xor ax,ax 14 | call csv 15 | mov bx,*4(bp) 16 | mov ax,*6(bp) 17 | or ax,ax 18 | jne L1 19 | inc ax 20 | L1: mov cx,(bx) 21 | L2: cmp cx,*0(bp) 22 | je L3 23 | mov bp,*0(bp) 24 | or bp,bp 25 | jne L2 26 | hlt 27 | L3: mov di,*-2(bp) 28 | mov si,*-4(bp) 29 | mov bp,*0(bp) 30 | mov sp,*2(bx) 31 | mov cx,*4(bx) 32 | mov bx,sp 33 | mov (bx),cx 34 | ret 35 | -------------------------------------------------------------------------------- /lib/setuid.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int setuid(usr) 4 | int usr; 5 | { 6 | return callm1(MM, SETUID, usr, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/signal.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | #include "../include/signal.h" 3 | 4 | int (*vectab[NR_SIGS])(); /* array of functions to catch signals */ 5 | 6 | /* The definition of signal really should be 7 | * PUBLIC int (*signal(signr, func))() 8 | * but some compilers refuse to accept this, even though it is correct. 9 | * The only thing to do if you are stuck with such a defective compiler is 10 | * change it to 11 | * PUBLIC int *signal(signr, func) 12 | * and change ../h/signal.h accordingly. 13 | */ 14 | 15 | PUBLIC int (*signal(signr, func))() 16 | int signr; /* which signal is being set */ 17 | int (*func)(); /* pointer to function that catches signal */ 18 | { 19 | int r,(*old)(); 20 | 21 | old = vectab[signr - 1]; 22 | vectab[signr - 1] = func; 23 | M.m6_i1 = signr; 24 | M.m6_f1 = ( (func == SIG_IGN || func == SIG_DFL) ? func : begsig); 25 | r = callx(MM, SIGNAL); 26 | return( (r < 0 ? (int (*)()) r : old) ); 27 | } 28 | -------------------------------------------------------------------------------- /lib/sleep.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | #include "../include/signal.h" 3 | 4 | PRIVATE alfun(){} /* used with sleep() below */ 5 | PUBLIC sleep(n) 6 | int n; 7 | { 8 | /* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */ 9 | signal(SIGALRM, alfun); 10 | alarm(n); 11 | pause(); 12 | } 13 | -------------------------------------------------------------------------------- /lib/sprintf.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | char *sprintf(buf,format,args) 4 | char *buf, *format; 5 | int args; 6 | { 7 | FILE _tempfile; 8 | 9 | _tempfile._fd = -1; 10 | _tempfile._flags = WRITEMODE + STRINGS; 11 | _tempfile._buf = buf; 12 | _tempfile._ptr = buf; 13 | 14 | _doprintf(&_tempfile,format,&args); 15 | putc('\0',&_tempfile); 16 | 17 | return buf; 18 | } 19 | -------------------------------------------------------------------------------- /lib/stat.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int stat(name, buffer) 4 | char *name; 5 | char *buffer; 6 | { 7 | int n; 8 | n = callm1(FS, STAT, len(name), 0, 0, name, buffer, NIL_PTR); 9 | return(n); 10 | } 11 | -------------------------------------------------------------------------------- /lib/stb.c: -------------------------------------------------------------------------------- 1 | /* library routine for copying structs with unpleasant alignment */ 2 | 3 | __stb(n, f, t) 4 | register char *f, *t; register int n; 5 | { 6 | if (n > 0) 7 | do 8 | *t++ = *f++; 9 | while (--n); 10 | } 11 | -------------------------------------------------------------------------------- /lib/stderr.c: -------------------------------------------------------------------------------- 1 | std_err(s) 2 | char *s; 3 | { 4 | char *p = s; 5 | 6 | while(*p != 0) p++; 7 | write(2, s, p - s); 8 | } 9 | -------------------------------------------------------------------------------- /lib/stime.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int stime(top) 4 | long *top; 5 | { 6 | M.m2_l1 = *top; 7 | return callx(FS, STIME); 8 | } 9 | -------------------------------------------------------------------------------- /lib/strcat.c: -------------------------------------------------------------------------------- 1 | char *strcat(s1, s2) 2 | register char *s1, *s2; 3 | { 4 | /* Append s2 to the end of s1. */ 5 | 6 | char *original = s1; 7 | 8 | /* Find the end of s1. */ 9 | while (*s1 != 0) s1++; 10 | 11 | /* Now copy s2 to the end of s1. */ 12 | while (*s2 != 0) *s1++ = *s2++; 13 | *s1 = 0; 14 | return(original); 15 | } 16 | -------------------------------------------------------------------------------- /lib/strcmp.c: -------------------------------------------------------------------------------- 1 | int strcmp(s1, s2) 2 | register char *s1, *s2; 3 | { 4 | /* Compare 2 strings. */ 5 | 6 | while (1) { 7 | if (*s1 != *s2) return(*s1 - *s2); 8 | if (*s1 == 0) return(0); 9 | s1++; 10 | s2++; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/strcpy.c: -------------------------------------------------------------------------------- 1 | char *strcpy(s1, s2) 2 | register char *s1, *s2; 3 | { 4 | /* Copy s2 to s1. */ 5 | char *original = s1; 6 | 7 | while (*s2 != 0) *s1++ = *s2++; 8 | *s1 = 0; 9 | return(original); 10 | } 11 | -------------------------------------------------------------------------------- /lib/strlen.c: -------------------------------------------------------------------------------- 1 | int strlen(s) 2 | char *s; 3 | { 4 | /* Return length of s. */ 5 | 6 | char *original = s; 7 | 8 | while (*s != 0) s++; 9 | return(s - original); 10 | } 11 | -------------------------------------------------------------------------------- /lib/strncat.c: -------------------------------------------------------------------------------- 1 | char *strncat(s1, s2, n) 2 | register char *s1, *s2; 3 | int n; 4 | { 5 | /* Append s2 to the end of s1, but no more than n characters */ 6 | 7 | char *original = s1; 8 | 9 | if (n == 0) return(s1); 10 | 11 | /* Find the end of s1. */ 12 | while (*s1 != 0) s1++; 13 | 14 | /* Now copy s2 to the end of s1. */ 15 | while (*s2 != 0) { 16 | *s1++ = *s2++; 17 | if (--n == 0) break; 18 | } 19 | *s1 = 0; 20 | return(original); 21 | } 22 | -------------------------------------------------------------------------------- /lib/strncmp.c: -------------------------------------------------------------------------------- 1 | int strncmp(s1, s2, n) 2 | register char *s1, *s2; 3 | int n; 4 | { 5 | /* Compare two strings, but at most n characters. */ 6 | 7 | while (1) { 8 | if (*s1 != *s2) return(*s1 - *s2); 9 | if (*s1 == 0 || --n == 0) return(0); 10 | s1++; 11 | s2++; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/strncpy.c: -------------------------------------------------------------------------------- 1 | char *strncpy(s1, s2, n) 2 | register char *s1, *s2; 3 | int n; 4 | { 5 | /* Copy s2 to s1, but at most n characters. */ 6 | 7 | char *original = s1; 8 | 9 | while (*s2 != 0) { 10 | *s1++ = *s2++; 11 | if (--n == 0) break; 12 | } 13 | *s1 = 0; 14 | return(original); 15 | } 16 | -------------------------------------------------------------------------------- /lib/sync.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int sync() 4 | { 5 | return callm1(FS, SYNC, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 6 | } 7 | -------------------------------------------------------------------------------- /lib/time.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC long time(tp) 4 | long *tp; 5 | { 6 | int k; 7 | long l; 8 | k = callm1(FS, TIME, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 9 | if (M.m_type < 0 || k != OK) {errno = -M.m_type; return(-1L);} 10 | l = M.m2_l1; 11 | if (tp != (long *) 0) *tp = l; 12 | return(l); 13 | } 14 | -------------------------------------------------------------------------------- /lib/times.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | struct tbuf { long b1, b2, b3, b4;}; 4 | PUBLIC int times(buf) 5 | struct tbuf *buf; 6 | { 7 | int k; 8 | k = callm1(FS, TIMES, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 9 | buf->b1 = M.m4_l1; 10 | buf->b2 = M.m4_l2; 11 | buf->b3 = M.m4_l3; 12 | buf->b4 = M.m4_l4; 13 | return(k); 14 | } 15 | -------------------------------------------------------------------------------- /lib/umask.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int umask(complmode) 4 | int complmode; 5 | { 6 | return callm1(FS, UMASK, complmode, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 7 | } 8 | -------------------------------------------------------------------------------- /lib/umount.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int umount(name) 4 | char* name; 5 | { 6 | return callm3(FS, UMOUNT, 0, name); 7 | } 8 | -------------------------------------------------------------------------------- /lib/ungetc.c: -------------------------------------------------------------------------------- 1 | #include "../include/stdio.h" 2 | 3 | ungetc(ch, iop) 4 | int ch; 5 | FILE *iop; 6 | { 7 | if ( ch < 0 || !testflag(iop,READMODE) || testflag(iop,UNBUFF) ) 8 | return( EOF ); 9 | 10 | if ( iop->_count >= BUFSIZ) 11 | return(EOF); 12 | 13 | if ( iop->_ptr == iop->_buf) 14 | iop->_ptr++; 15 | 16 | iop->_count++; 17 | *--iop->_ptr = ch; 18 | return(ch); 19 | } 20 | -------------------------------------------------------------------------------- /lib/unlink.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int unlink(name) 4 | char *name; 5 | { 6 | return callm3(FS, UNLINK, 0, name); 7 | } 8 | -------------------------------------------------------------------------------- /lib/utime.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int utime(name, timp) 4 | char *name; 5 | long timp[2]; 6 | { 7 | M.m2_i1 = len(name); 8 | M.m2_l1 = timp[0]; 9 | M.m2_l2 = timp[1]; 10 | M.m2_p1 = name; 11 | return callx(FS, UTIME); 12 | } 13 | -------------------------------------------------------------------------------- /lib/wait.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int wait(status) 4 | int *status; 5 | { 6 | int k; 7 | k = callm1(MM, WAIT, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); 8 | *status = M.m2_i1; 9 | return(k); 10 | } 11 | -------------------------------------------------------------------------------- /lib/write.c: -------------------------------------------------------------------------------- 1 | #include "../include/lib.h" 2 | 3 | PUBLIC int write(fd, buffer, nbytes) 4 | char *buffer; 5 | int nbytes; 6 | { 7 | return callm1(FS, WRITE, fd, nbytes, 0, buffer, NIL_PTR, NIL_PTR); 8 | } 9 | -------------------------------------------------------------------------------- /mm/c86/_link.bat: -------------------------------------------------------------------------------- 1 | echo Linking memory manager 2 | link/m ..\lib\head+ link.lst 3 | dos2out mm >dos2out.lst >dos2out.lst 4 | echo/ 5 | echo MM done. Check the .lst-files for errors. 6 | pause 7 | echo on 8 | for %%f in (*.lst) do type %%f 9 | -------------------------------------------------------------------------------- /mm/c86/linklist: -------------------------------------------------------------------------------- 1 | main+forkexit+break+exec+signal+ 2 | getset+alloc+utility+table+putc 3 | mm 4 | mm 5 | ..\lib\mxc86 6 | -------------------------------------------------------------------------------- /mm/const.h: -------------------------------------------------------------------------------- 1 | /* Constants used by the Memory Manager. */ 2 | 3 | #define ZEROBUF_SIZE 1024 /* buffer size for erasing memory */ 4 | 5 | /* Size of MM's stack depends mostly on do_exec(). */ 6 | #if ZEROBUF_SIZE > MAX_PATH 7 | #define MM_STACK_BYTES MAX_ISTACK_BYTES + ZEROBUF_SIZE + 384 8 | #else 9 | #define MM_STACK_BYTES MAX_ISTACK_BYTES + MAX_PATH + 384 10 | #endif 11 | 12 | #define NO_MEM (phys_clicks)0 /* returned by alloc_mem() with mem is up */ 13 | 14 | #ifdef i8088 15 | #define PAGE_SIZE 16 /* how many bytes in a page */ 16 | #define MAX_PAGES 4096 /* how many pages in the virtual addr space */ 17 | #define HDR_SIZE 32 /* # bytes in the exec file header */ 18 | #endif 19 | 20 | #define printf printk 21 | -------------------------------------------------------------------------------- /mm/getset.c: -------------------------------------------------------------------------------- 1 | /* This file handles the 4 system calls that get and set uids and gids. 2 | * It also handles getpid(). The code for each one is so tiny that it hardly 3 | * seemed worthwhile to make each a separate function. 4 | */ 5 | 6 | #include "../h/const.h" 7 | #include "../h/type.h" 8 | #include "../h/callnr.h" 9 | #include "../h/error.h" 10 | #include "const.h" 11 | #include "glo.h" 12 | #include "mproc.h" 13 | #include "param.h" 14 | 15 | /*===========================================================================* 16 | * do_getset * 17 | *===========================================================================*/ 18 | PUBLIC int do_getset() 19 | { 20 | /* Handle GETUID, GETGID, GETPID, SETUID, SETGID. The three GETs return 21 | * their primary results in 'r'. GETUID and GETGID also return secondary 22 | * results (the effective IDs) in 'result2', which is returned to the user. 23 | */ 24 | 25 | register struct mproc *rmp = mp; 26 | register int r; 27 | 28 | switch(mm_call) { 29 | case GETUID: 30 | r = rmp->mp_realuid; 31 | result2 = rmp->mp_effuid; 32 | break; 33 | 34 | case GETGID: 35 | r = rmp->mp_realgid; 36 | result2 = rmp->mp_effgid; 37 | break; 38 | 39 | case GETPID: 40 | r = mproc[who].mp_pid; 41 | result2 = mproc[rmp->mp_parent].mp_pid; 42 | break; 43 | 44 | case SETUID: 45 | if (rmp->mp_realuid != usr_id && rmp->mp_effuid != SUPER_USER) 46 | return(EPERM); 47 | rmp->mp_realuid = usr_id; 48 | rmp->mp_effuid = usr_id; 49 | tell_fs(SETUID, who, usr_id, usr_id); 50 | r = OK; 51 | break; 52 | 53 | case SETGID: 54 | if (rmp->mp_realgid != grpid && rmp->mp_effuid != SUPER_USER) 55 | return(EPERM); 56 | rmp->mp_realgid = grpid; 57 | rmp->mp_effgid = grpid; 58 | tell_fs(SETGID, who, grpid, grpid); 59 | r = OK; 60 | break; 61 | } 62 | 63 | return(r); 64 | } 65 | -------------------------------------------------------------------------------- /mm/glo.h: -------------------------------------------------------------------------------- 1 | /* Global variables. */ 2 | EXTERN struct mproc *mp; /* ptr to 'mproc' slot of current process */ 3 | EXTERN int dont_reply; /* normally 0; set to 1 to inhibit reply */ 4 | EXTERN int procs_in_use; /* how many processes are marked as IN_USE */ 5 | 6 | /* The parameters of the call are kept here. */ 7 | EXTERN message mm_in; /* the incoming message itself is kept here. */ 8 | EXTERN message mm_out; /* the reply message is built up here. */ 9 | EXTERN int who; /* caller's proc number */ 10 | EXTERN int mm_call; /* caller's proc number */ 11 | 12 | /* The following variables are used for returning results to the caller. */ 13 | EXTERN int err_code; /* temporary storage for error number */ 14 | EXTERN int result2; /* secondary result */ 15 | EXTERN char *res_ptr; /* result, if pointer */ 16 | 17 | EXTERN char mm_stack[MM_STACK_BYTES]; /* MM's stack */ 18 | 19 | -------------------------------------------------------------------------------- /mm/makefile: -------------------------------------------------------------------------------- 1 | CFLAGS= -Di8088 -O 2 | h=../h 3 | l=../lib 4 | 5 | obj = main.o forkexit.o break.o exec.o signal.o getset.o \ 6 | alloc.o utility.o table.o putc.o 7 | 8 | mm: makefile $l/head.o $(obj) $l/libc.a $l/end.o 9 | @echo "Start linking MM" 10 | @ld -o mm $l/head.o $(obj) $l/libc.a $l/end.o 11 | @echo "MM done" 12 | 13 | 14 | alloc.o: const.h $h/const.h $h/type.h 15 | 16 | break.o: const.h $h/const.h $h/type.h 17 | break.o: $h/error.h 18 | break.o: $h/signal.h 19 | break.o: glo.h 20 | break.o: mproc.h 21 | break.o: param.h 22 | 23 | exec.o: const.h $h/const.h $h/type.h 24 | exec.o: $h/callnr.h 25 | exec.o: $h/error.h 26 | exec.o: $h/stat.h 27 | exec.o: glo.h 28 | exec.o: mproc.h 29 | exec.o: param.h 30 | 31 | forkexit.o: const.h $h/const.h $h/type.h 32 | forkexit.o: $h/callnr.h 33 | forkexit.o: $h/error.h 34 | forkexit.o: glo.h 35 | forkexit.o: mproc.h 36 | forkexit.o: param.h 37 | 38 | getset.o: const.h $h/const.h $h/type.h 39 | getset.o: $h/callnr.h 40 | getset.o: $h/error.h 41 | getset.o: glo.h 42 | getset.o: mproc.h 43 | getset.o: param.h 44 | 45 | main.o: const.h $h/const.h $h/type.h 46 | main.o: $h/callnr.h 47 | main.o: $h/com.h 48 | main.o: $h/error.h 49 | main.o: glo.h 50 | main.o: mproc.h 51 | main.o: param.h 52 | 53 | putc.o: $h/const.h $h/type.h 54 | putc.o: $h/com.h 55 | 56 | signal.o: const.h $h/const.h $h/type.h 57 | signal.o: $h/callnr.h 58 | signal.o: $h/com.h 59 | signal.o: $h/error.h 60 | signal.o: $h/signal.h 61 | signal.o: $h/stat.h 62 | signal.o: glo.h 63 | signal.o: mproc.h 64 | signal.o: param.h 65 | 66 | table.o: const.h $h/const.h $h/type.h 67 | table.o: $h/callnr.h 68 | table.o: glo.h 69 | table.o: mproc.h 70 | table.o: param.h 71 | 72 | utility.o: const.h $h/const.h $h/type.h 73 | utility.o: $h/callnr.h 74 | utility.o: $h/com.h 75 | utility.o: $h/error.h 76 | utility.o: $h/stat.h 77 | utility.o: glo.h 78 | utility.o: mproc.h 79 | -------------------------------------------------------------------------------- /mm/minix/makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Di8088 -w -F -T. 2 | h=../h 3 | l=/usr/lib 4 | 5 | obj = main.s forkexit.s break.s exec.s signal.s getset.s \ 6 | alloc.s utility.s table.s putc.s 7 | 8 | mm: makefile $l/head.s $(obj) $l/libc.a $l/end.s 9 | @echo "Start linking MM. /lib/cem will be removed to make space on RAM disk" 10 | @rm -f /lib/cem /tmp/* 11 | @asld -o mm $l/head.s $(obj) $l/libc.a $l/end.s 12 | @echo "MM done. Please restore /lib/cem manually" 13 | 14 | 15 | alloc.s: const.h $h/const.h $h/type.h 16 | 17 | break.s: const.h $h/const.h $h/type.h 18 | break.s: $h/error.h 19 | break.s: $h/signal.h 20 | break.s: glo.h 21 | break.s: mproc.h 22 | break.s: param.h 23 | 24 | exec.s: const.h $h/const.h $h/type.h 25 | exec.s: $h/callnr.h 26 | exec.s: $h/error.h 27 | exec.s: $h/stat.h 28 | exec.s: glo.h 29 | exec.s: mproc.h 30 | exec.s: param.h 31 | 32 | forkexit.s: const.h $h/const.h $h/type.h 33 | forkexit.s: $h/callnr.h 34 | forkexit.s: $h/error.h 35 | forkexit.s: glo.h 36 | forkexit.s: mproc.h 37 | forkexit.s: param.h 38 | 39 | getset.s: const.h $h/const.h $h/type.h 40 | getset.s: $h/callnr.h 41 | getset.s: $h/error.h 42 | getset.s: glo.h 43 | getset.s: mproc.h 44 | getset.s: param.h 45 | 46 | main.s: const.h $h/const.h $h/type.h 47 | main.s: $h/callnr.h 48 | main.s: $h/com.h 49 | main.s: $h/error.h 50 | main.s: glo.h 51 | main.s: mproc.h 52 | main.s: param.h 53 | 54 | putc.s: $h/const.h $h/type.h 55 | putc.s: $h/com.h 56 | 57 | signal.s: const.h $h/const.h $h/type.h 58 | signal.s: $h/callnr.h 59 | signal.s: $h/com.h 60 | signal.s: $h/error.h 61 | signal.s: $h/signal.h 62 | signal.s: $h/stat.h 63 | signal.s: glo.h 64 | signal.s: mproc.h 65 | signal.s: param.h 66 | 67 | table.s: const.h $h/const.h $h/type.h 68 | table.s: $h/callnr.h 69 | table.s: glo.h 70 | table.s: mproc.h 71 | table.s: param.h 72 | 73 | utility.s: const.h $h/const.h $h/type.h 74 | utility.s: $h/callnr.h 75 | utility.s: $h/com.h 76 | utility.s: $h/error.h 77 | utility.s: $h/stat.h 78 | utility.s: glo.h 79 | utility.s: mproc.h 80 | -------------------------------------------------------------------------------- /mm/minix/makefile.at: -------------------------------------------------------------------------------- 1 | CFLAGS = -Di8088 -w -F -T. 2 | h=../h 3 | l=/usr/lib 4 | 5 | obj = main.s forkexit.s break.s exec.s signal.s getset.s \ 6 | alloc.s utility.s table.s putc.s 7 | 8 | mm: makefile $l/head.s $(obj) $l/libc.a $l/end.s 9 | @echo "Start linking MM. " 10 | @rm -f /tmp/* 11 | @asld -o mm -T. $l/head.s $(obj) $l/libc.a $l/end.s 12 | @echo "MM done. " 13 | 14 | 15 | alloc.s: const.h $h/const.h $h/type.h 16 | 17 | break.s: const.h $h/const.h $h/type.h 18 | break.s: $h/error.h 19 | break.s: $h/signal.h 20 | break.s: glo.h 21 | break.s: mproc.h 22 | break.s: param.h 23 | 24 | exec.s: const.h $h/const.h $h/type.h 25 | exec.s: $h/callnr.h 26 | exec.s: $h/error.h 27 | exec.s: $h/stat.h 28 | exec.s: glo.h 29 | exec.s: mproc.h 30 | exec.s: param.h 31 | 32 | forkexit.s: const.h $h/const.h $h/type.h 33 | forkexit.s: $h/callnr.h 34 | forkexit.s: $h/error.h 35 | forkexit.s: glo.h 36 | forkexit.s: mproc.h 37 | forkexit.s: param.h 38 | 39 | getset.s: const.h $h/const.h $h/type.h 40 | getset.s: $h/callnr.h 41 | getset.s: $h/error.h 42 | getset.s: glo.h 43 | getset.s: mproc.h 44 | getset.s: param.h 45 | 46 | main.s: const.h $h/const.h $h/type.h 47 | main.s: $h/callnr.h 48 | main.s: $h/com.h 49 | main.s: $h/error.h 50 | main.s: glo.h 51 | main.s: mproc.h 52 | main.s: param.h 53 | 54 | putc.s: $h/const.h $h/type.h 55 | putc.s: $h/com.h 56 | 57 | signal.s: const.h $h/const.h $h/type.h 58 | signal.s: $h/callnr.h 59 | signal.s: $h/com.h 60 | signal.s: $h/error.h 61 | signal.s: $h/signal.h 62 | signal.s: $h/stat.h 63 | signal.s: glo.h 64 | signal.s: mproc.h 65 | signal.s: param.h 66 | 67 | table.s: const.h $h/const.h $h/type.h 68 | table.s: $h/callnr.h 69 | table.s: glo.h 70 | table.s: mproc.h 71 | table.s: param.h 72 | 73 | utility.s: const.h $h/const.h $h/type.h 74 | utility.s: $h/callnr.h 75 | utility.s: $h/com.h 76 | utility.s: $h/error.h 77 | utility.s: $h/stat.h 78 | utility.s: glo.h 79 | utility.s: mproc.h 80 | -------------------------------------------------------------------------------- /mm/mproc.h: -------------------------------------------------------------------------------- 1 | /* This table has one slot per process. It contains all the memory management 2 | * information for each process. Among other things, it defines the text, data 3 | * and stack segments, uids and gids, and various flags. The kernel and file 4 | * systems have tables that are also indexed by process, with the contents 5 | * of corresponding slots referring to the same process in all three. 6 | */ 7 | 8 | EXTERN struct mproc { 9 | struct mem_map mp_seg[NR_SEGS]; /* points to text, data, stack */ 10 | char mp_exitstatus; /* storage for status when process exits */ 11 | char mp_sigstatus; /* storage for signal # for killed processes */ 12 | int mp_pid; /* process id */ 13 | int mp_parent; /* index of parent process */ 14 | int mp_procgrp; /* process group (used for signals) */ 15 | 16 | /* Real and effective uids and gids. */ 17 | uid mp_realuid; /* process' real uid */ 18 | uid mp_effuid; /* process' effective uid */ 19 | gid mp_realgid; /* process' real gid */ 20 | gid mp_effgid; /* process' effective gid */ 21 | 22 | /* Bit maps for signals. */ 23 | unshort mp_ignore; /* 1 means ignore the signal, 0 means don't */ 24 | unshort mp_catch; /* 1 means catch the signal, 0 means don't */ 25 | int (*mp_func)(); /* all signals vectored to a single user fcn */ 26 | 27 | unsigned mp_flags; /* flag bits */ 28 | } mproc[NR_PROCS]; 29 | 30 | /* Flag values */ 31 | #define IN_USE 001 /* set when 'mproc' slot in use */ 32 | #define WAITING 002 /* set by WAIT system call */ 33 | #define HANGING 004 /* set by EXIT system call */ 34 | #define PAUSED 010 /* set by PAUSE system call */ 35 | #define ALARM_ON 020 /* set when SIGALRM timer started */ 36 | #define SEPARATE 040 /* set if file is separate I & D space */ 37 | -------------------------------------------------------------------------------- /mm/param.h: -------------------------------------------------------------------------------- 1 | /* The following names are synonyms for the variables in the input message. */ 2 | #define addr mm_in.m1_p1 3 | #define exec_name mm_in.m1_p1 4 | #define exec_len mm_in.m1_i1 5 | #define func mm_in.m6_f1 6 | #define grpid (gid) mm_in.m1_i1 7 | #define kill_sig mm_in.m1_i2 8 | #define namelen mm_in.m1_i1 9 | #define pid mm_in.m1_i1 10 | #define seconds mm_in.m1_i1 11 | #define sig mm_in.m6_i1 12 | #define stack_bytes mm_in.m1_i2 13 | #define stack_ptr mm_in.m1_p2 14 | #define status mm_in.m1_i1 15 | #define usr_id (uid) mm_in.m1_i1 16 | 17 | /* The following names are synonyms for the variables in the output message. */ 18 | #define reply_type mm_out.m_type 19 | #define reply_i1 mm_out.m2_i1 20 | #define reply_p1 mm_out.m2_p1 21 | -------------------------------------------------------------------------------- /mm/putc.c: -------------------------------------------------------------------------------- 1 | /* MM must occasionally print some message. It uses the standard library 2 | * routine prink(). (The name "printf" is really a macro defined as "printk"). 3 | * Printing is done by calling the TTY task directly, not going through FS. 4 | */ 5 | 6 | #include "../h/const.h" 7 | #include "../h/type.h" 8 | #include "../h/com.h" 9 | 10 | #define STD_OUTPUT 1 /* file descriptor for standard output */ 11 | #define BUF_SIZE 100 /* print buffer size */ 12 | 13 | PRIVATE int buf_count; /* # characters in the buffer */ 14 | PRIVATE char print_buf[BUF_SIZE]; /* output is buffered here */ 15 | PRIVATE message putch_msg; /* used for message to TTY task */ 16 | 17 | /*===========================================================================* 18 | * putc * 19 | *===========================================================================*/ 20 | PUBLIC putc(c) 21 | char c; 22 | { 23 | 24 | /* Accumulate another character. If '\n' or buffer full, print it. */ 25 | print_buf[buf_count++] = c; 26 | if (buf_count == BUF_SIZE) F_l_u_s_h(); 27 | if (c == '\n') F_l_u_s_h(); 28 | } 29 | 30 | 31 | /*===========================================================================* 32 | * F_l_u_s_h * 33 | *===========================================================================*/ 34 | PRIVATE F_l_u_s_h() 35 | { 36 | /* Flush the print buffer by calling TTY task. */ 37 | 38 | if (buf_count == 0) return; 39 | putch_msg.m_type = TTY_WRITE; 40 | putch_msg.PROC_NR = 0; 41 | putch_msg.TTY_LINE = 0; 42 | putch_msg.ADDRESS = print_buf; 43 | putch_msg.COUNT = buf_count; 44 | sendrec(TTY, &putch_msg); 45 | buf_count = 0; 46 | } 47 | -------------------------------------------------------------------------------- /mm/type.h: -------------------------------------------------------------------------------- 1 | /* If there were any type definitions local to the Memory Manager, they would 2 | * be here. This file is included only for symmetry with the kernel and File 3 | * System, which do have some local type definitions. 4 | */ 5 | 6 | #include "../h/type.h" 7 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | Minix 1 2 | 3 | Andy Tanenbaum first released MINIX 1 in 1987 as an appendix to the book, Operating Systems: Design and Implementation 4 | -------------------------------------------------------------------------------- /test/c86/nullfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdevic/minix1/3475e7ed91a3ff3f8862b2543059580a01c1b1a7/test/c86/nullfile -------------------------------------------------------------------------------- /test/makefile: -------------------------------------------------------------------------------- 1 | # To make 'test0', type: make f=test0 2 | # To make 'test1', type: make f=test1 3 | # To make 'test2', type: make f=test2 4 | # Get the idea? 5 | 6 | CFLAGS = -O -I../include 7 | h=../h 8 | l=../lib 9 | 10 | file: $l/libc.a $f.o 11 | @ld -s -o $f $l/crtso.o $f.o $l/libc.a $l/end.o 12 | 13 | -------------------------------------------------------------------------------- /test/minix/makefile: -------------------------------------------------------------------------------- 1 | # To make 'test0', type: make f=test0 2 | # To make 'test1', type: make f=test1 3 | # To make 'test2', type: make f=test2 4 | # Get the idea? 5 | 6 | l=/usr/lib 7 | 8 | CFLAGS = -I/usr/include -F 9 | 10 | file: $l/libc.a $f.s 11 | @asld -o $f $l/crtso.s $f.s $l/libc.a $l/end.s 12 | 13 | -------------------------------------------------------------------------------- /test/run: -------------------------------------------------------------------------------- 1 | test0 2 | test1 3 | test2 4 | test3 5 | test4 6 | test5 7 | test6 8 | test7 9 | test8 10 | test9 11 | test10 12 | test11 13 | echo All tests completed. 14 | -------------------------------------------------------------------------------- /test/t10a.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | exit(0); 4 | } 5 | -------------------------------------------------------------------------------- /test/t11a.c: -------------------------------------------------------------------------------- 1 | main(argc, argv, envp) 2 | int argc; 3 | char *argv[], *envp[]; 4 | { 5 | /* See if arguments passed ok. */ 6 | 7 | char aa[4]; 8 | 9 | if (diff(argv[0], "t11a")) e(21); 10 | if (diff(argv[1], "arg0")) e(22); 11 | if (diff(argv[2], "arg1")) e(23); 12 | if (diff(argv[3], "arg2")) e(24); 13 | if (diff(envp[0], "spring")) e(25); 14 | if (diff(envp[1], "summer")) e(26); 15 | if (argc != 4) e(27); 16 | 17 | /* Now see if the files are ok. */ 18 | if (read(3, aa, 1000) != 2) e(28); 19 | if (aa[0] != 7 || aa[1] != 9) e(29); 20 | 21 | if (getuid() == 10) e(30); 22 | if (geteuid() != 10) e(31); 23 | if (getgid() == 20) e(32); 24 | if (getegid() != 20) e(33); 25 | 26 | if (open("t1", 0) < 0) e(34); 27 | if (open("t2", 0) < 0) e(35); 28 | exit(100); 29 | } 30 | 31 | diff(s1, s2) 32 | char *s1, *s2; 33 | { 34 | while (1) { 35 | if (*s1 == 0 && *s2 == 0) return(0); 36 | if (*s1 != *s2) return(1); 37 | s1++; 38 | s2++; 39 | } 40 | } 41 | 42 | e(n) 43 | int n; 44 | { 45 | printf("Error %d\n", n); 46 | } 47 | -------------------------------------------------------------------------------- /test/t11b.c: -------------------------------------------------------------------------------- 1 | main(argc, argv) 2 | int argc; 3 | char *argv[]; 4 | { 5 | /* See if arguments passed ok. */ 6 | 7 | 8 | if (diff(argv[0], "t11b")) e(31); 9 | if (diff(argv[1], "abc")) e(32); 10 | if (diff(argv[2], "defghi")) e(33); 11 | if (diff(argv[3], "j")) e(34); 12 | if (argv[4] != 0) e(35); 13 | if (argc != 4) e(36); 14 | 15 | exit(75); 16 | } 17 | 18 | diff(s1, s2) 19 | char *s1, *s2; 20 | { 21 | while (1) { 22 | if (*s1 == 0 && *s2 == 0) return(0); 23 | if (*s1 != *s2) return(1); 24 | s1++; 25 | s2++; 26 | } 27 | } 28 | 29 | e(n) 30 | int n; 31 | { 32 | printf("Error %d\n", n); 33 | } 34 | -------------------------------------------------------------------------------- /test/t15a.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | exit(0); 4 | } 5 | -------------------------------------------------------------------------------- /test/t16a.c: -------------------------------------------------------------------------------- 1 | main(argc, argv, envp) 2 | int argc; 3 | char *argv[], *envp[]; 4 | { 5 | /* See if arguments passed ok. */ 6 | 7 | char aa[4]; 8 | 9 | if (diff(argv[0], "t4a")) e(21); 10 | if (diff(argv[1], "arg0")) e(22); 11 | if (diff(argv[2], "arg1")) e(23); 12 | if (diff(argv[3], "arg2")) e(24); 13 | if (diff(envp[0], "spring")) e(25); 14 | if (diff(envp[1], "summer")) e(26); 15 | if (argc != 4) e(27); 16 | 17 | /* Now see if the files are ok. */ 18 | if (read(3, aa, 1000) != 2) e(28); 19 | if (aa[0] != 7 || aa[1] != 9) e(29); 20 | 21 | if (getuid() == 10) e(30); 22 | if (geteuid() != 10) e(31); 23 | if (getgid() == 20) e(32); 24 | if (getegid() != 20) e(33); 25 | 26 | if (open("t1", 0) < 0) e(34); 27 | if (open("t2", 0) < 0) e(35); 28 | exit(100); 29 | } 30 | 31 | diff(s1, s2) 32 | char *s1, *s2; 33 | { 34 | while (1) { 35 | if (*s1 == 0 && *s2 == 0) return(0); 36 | if (*s1 != *s2) return(1); 37 | s1++; 38 | s2++; 39 | } 40 | } 41 | 42 | e(n) 43 | int n; 44 | { 45 | printf("Error %d\n", n); 46 | } 47 | -------------------------------------------------------------------------------- /test/t16b.c: -------------------------------------------------------------------------------- 1 | main(argc, argv) 2 | int argc; 3 | char *argv[]; 4 | { 5 | /* See if arguments passed ok. */ 6 | 7 | 8 | if (diff(argv[0], "t4b")) e(31); 9 | if (diff(argv[1], "abc")) e(32); 10 | if (diff(argv[2], "defghi")) e(33); 11 | if (diff(argv[3], "j")) e(34); 12 | if (argv[4] != 0) e(35); 13 | if (argc != 4) e(36); 14 | 15 | exit(75); 16 | } 17 | 18 | diff(s1, s2) 19 | char *s1, *s2; 20 | { 21 | while (1) { 22 | if (*s1 == 0 && *s2 == 0) return(0); 23 | if (*s1 != *s2) return(1); 24 | s1++; 25 | s2++; 26 | } 27 | } 28 | 29 | e(n) 30 | int n; 31 | { 32 | printf("Error %d\n", n); 33 | } 34 | -------------------------------------------------------------------------------- /test/test1.c: -------------------------------------------------------------------------------- 1 | #include "signal.h" 2 | 3 | int glov, gct; 4 | extern int errno; 5 | int errct; 6 | extern long lseek(); 7 | char initstack[2048]; 8 | 9 | 10 | main() 11 | { 12 | int i; 13 | 14 | printf("Test 1 "); 15 | 16 | for (i = 0; i < 15; i++) { 17 | test10(); 18 | test11(); 19 | } 20 | if (errct == 0) 21 | printf("ok\n"); 22 | else 23 | printf(" %d errors\n", errct); 24 | exit(0); 25 | } 26 | 27 | test10() 28 | { 29 | int i, n, pid; 30 | 31 | n = 4; 32 | for (i = 0; i < n; i++) { 33 | if ( (pid=fork()) ) { 34 | if (pid < 0) { printf("\nTest 1 fork failed\n"); exit(1);} 35 | parent(); 36 | } else 37 | child(i); 38 | } 39 | } 40 | 41 | parent() 42 | { 43 | 44 | int n; 45 | 46 | n = getpid(); 47 | wait(&n); 48 | } 49 | 50 | child(i) 51 | int i; 52 | { 53 | int n; 54 | 55 | n = getpid(); 56 | exit(i); 57 | } 58 | 59 | test11() 60 | { 61 | int i, k; 62 | 63 | for (i = 0; i < 4; i++) { 64 | glov = 0; 65 | if ( (k=fork())) { 66 | if (k < 0){printf("Test 1 fork failed\n"); exit(1);} 67 | parent1(k); 68 | } else 69 | child1(k); 70 | } 71 | } 72 | 73 | 74 | parent1(childpid) 75 | int childpid; 76 | { 77 | 78 | int func(), n; 79 | 80 | for (n = 0; n < 5000; n++) ; 81 | kill(childpid, 2); 82 | wait(&n); 83 | } 84 | 85 | func() 86 | { 87 | glov++; 88 | gct++; 89 | } 90 | child1(k) 91 | int k; 92 | { 93 | signal(2, func); 94 | while (glov == 0) ; 95 | exit(gct); 96 | } 97 | 98 | 99 | 100 | e(n) 101 | int n; 102 | { 103 | printf("\nError %d errno=%d ", n, errno); 104 | perror(""); 105 | errct++; 106 | } 107 | 108 | 109 | -------------------------------------------------------------------------------- /test/test10.c: -------------------------------------------------------------------------------- 1 | char *name[] = {"t10a","t10b","t10c","t10d","t10e","t10f","t10g","t10h","t10i","t10j"}; 2 | 3 | extern int errno; 4 | int errct; 5 | long prog[300]; 6 | int psize; 7 | 8 | main() 9 | { 10 | int i, n, pid; 11 | 12 | printf("Test 10 "); 13 | pid = getpid(); 14 | 15 | /* Create files t10b ... t10h */ 16 | mkfiles(); 17 | 18 | if (getpid() == pid) if (fork() == 0) {execl("t10a", 0); exit(0);} 19 | if (getpid() == pid) if (fork() == 0) {execl("t10b", 0); exit(0);} 20 | if (getpid() == pid) if (fork() == 0) {execl("t10c", 0); exit(0);} 21 | if (getpid() == pid) if (fork() == 0) {execl("t10d", 0); exit(0);} 22 | 23 | for (i = 0; i < 60; i++) { 24 | spawn( rand()&07); 25 | } 26 | for (i = 0; i < 4; i++) wait(&n); 27 | if (errct == 0) 28 | printf("ok\n"); 29 | else 30 | printf(" %d errors\n", errct); 31 | rmfiles(); 32 | exit(0); 33 | } 34 | 35 | spawn(n) 36 | int n; 37 | { 38 | int pid, k; 39 | 40 | if (pid =fork()) { 41 | wait(&n); /* wait for some child (any one) */ 42 | } else { 43 | k = execl(name[n], 0); 44 | errct++; 45 | printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno); 46 | rmfiles(); 47 | exit(0); 48 | printf("Worse yet, EXIT didn't exit\n"); 49 | } 50 | } 51 | 52 | mkfiles() 53 | { 54 | int fd; 55 | fd = open("t10a",0); 56 | if (fd < 0) {printf("Can't open t10a\n"); exit(1);} 57 | psize = read(fd, prog, 300*4); 58 | cr_file("t10b", 1600); 59 | cr_file("t10c", 1400); 60 | cr_file("t10d", 2300); 61 | cr_file("t10e", 3100); 62 | cr_file("t10f", 2400); 63 | cr_file("t10g", 1700); 64 | cr_file("t10h", 1500); 65 | cr_file("t10i", 4000); 66 | cr_file("t10j", 2250); 67 | close(fd); 68 | } 69 | 70 | 71 | cr_file(name, size) 72 | char *name; 73 | int size; 74 | 75 | { 76 | int fd; 77 | 78 | prog[6] = (long) size; 79 | fd = creat(name, 0755); 80 | write(fd, prog, psize); 81 | close(fd); 82 | } 83 | 84 | rmfiles() 85 | { 86 | unlink("t10b"); 87 | unlink("t10c"); 88 | unlink("t10d"); 89 | unlink("t10e"); 90 | unlink("t10f"); 91 | unlink("t10g"); 92 | unlink("t10h"); 93 | unlink("t10i"); 94 | unlink("t10j"); 95 | } 96 | -------------------------------------------------------------------------------- /test/test11.c: -------------------------------------------------------------------------------- 1 | char *envp[3] = {"spring", "summer", 0}; 2 | 3 | extern errno; 4 | int errct; 5 | 6 | main() 7 | { 8 | int i; 9 | 10 | printf("Test 11 "); 11 | for (i = 0; i<9; i++) { 12 | test110(); 13 | test111(); 14 | } 15 | if (errct == 0) 16 | printf("ok\n"); 17 | else 18 | printf(" %d errors\n", errct); 19 | exit(0); 20 | } 21 | 22 | 23 | e(n) 24 | int n; 25 | { 26 | printf("\nError %d. errno = %d ",n, errno); 27 | perror(""); 28 | errct++; 29 | } 30 | 31 | 32 | 33 | test110() 34 | { 35 | /* Test exec */ 36 | int n, fd, fd1, i; 37 | char aa[4]; 38 | 39 | 40 | if (fork()) { 41 | wait(&n); 42 | if (n != 25600) e(1); 43 | unlink("t1"); 44 | unlink("t2"); 45 | } else { 46 | if (chown("t11a", 10, 20) < 0) e(2); 47 | chmod("t11a", 0666); 48 | 49 | /* The following call should fail because the mode has no X bits on. 50 | * If a bug lets it unexpectedly succeed, the child will print an 51 | * error message since the arguments are wrong. 52 | */ 53 | execl("t11a", 0, envp); /* should fail -- no X bits on */ 54 | 55 | /* Control should come here after the failed execl(). */ 56 | chmod("t11a", 06555); 57 | if ( (fd = creat("t1", 0600)) != 3) e(3); 58 | if (close(fd) < 0) e(4); 59 | if (open("t1", 2) != 3) e(5); 60 | if (chown("t1", 10, 99) < 0) e(6); 61 | if ( (fd = creat("t2", 0060)) != 4) e(7); 62 | if (close(fd) < 0) e(8); 63 | if (open("t2", 2) != 4) e(9); 64 | if (chown("t2", 99, 20) < 0) e(10); 65 | if (setgid(6) < 0) e(11); 66 | if (setuid(5) < 0) e(12); 67 | if (getuid() != 5) e(13); 68 | if (geteuid() != 5) e(14); 69 | if (getgid() != 6) e(15); 70 | if (getegid() != 6) e(16); 71 | aa[0] = 3; aa[1] = 5; aa[2] = 7; aa[3] = 9; 72 | if (write(3, aa, 4) != 4) e(17); 73 | lseek(3, 2L, 0); 74 | execle("t11a", "t11a", "arg0", "arg1", "arg2", 0, envp); 75 | e(18); 76 | printf("Can't exec t11a\n"); 77 | exit(3); 78 | } 79 | } 80 | 81 | 82 | 83 | test111() 84 | { 85 | int n; 86 | char *argv[5]; 87 | 88 | if (fork()) { 89 | wait(&n); 90 | if (n != (75<<8)) e(20); 91 | } else { 92 | /* Child tests execv. */ 93 | argv[0] = "t11b"; 94 | argv[1] = "abc"; 95 | argv[2] = "defghi"; 96 | argv[3] = "j"; 97 | argv[4] = 0; 98 | execv("t11b", argv); 99 | e(19); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /test/test2.c: -------------------------------------------------------------------------------- 1 | 2 | extern errno; 3 | int kk=0; 4 | 5 | char buf[2048]; 6 | main() 7 | { 8 | int i; 9 | 10 | printf("Test 2 "); 11 | for (i = 0; i<19; i++) { 12 | test20(); 13 | } 14 | printf("ok\n"); 15 | exit(0); 16 | } 17 | 18 | 19 | test20() 20 | { 21 | /* Test pipes */ 22 | 23 | int fd[2]; 24 | int n, i, j, ij, q=0, nn, m=0, k; 25 | 26 | if (pipe(fd) <0) {printf("pipe error. errno= %d\n", errno); exit(0);} 27 | 28 | i = fork(); 29 | if (i <0) { printf("fork failed\n"); exit(0);} 30 | if (i != 0) { 31 | /* Parent code */ 32 | close(fd[0]); 33 | for (i=0; i<2048; i++) buf[i] = i & 0377; 34 | for (q=0; q<8; q++) { 35 | if(write(fd[1], buf, 2048)<0){ 36 | printf("write pipe err. errno=%d\n",errno); 37 | exit(0); 38 | } 39 | } 40 | close(fd[1]); 41 | wait(&q); 42 | if (q != 256*58) {printf("wrong exit code %d\n",q); exit(0);} 43 | } else { 44 | /* Child code */ 45 | close(fd[1]); 46 | for (q=0; q<32; q++) { 47 | n = read(fd[0], buf, 512); 48 | if (n!=512){printf("read yielded %d bytes, not 512\n",n); exit(0);} 49 | for (j=0; j 0) e(1); 32 | kill(getpid(), SIGQUIT); 33 | } 34 | 35 | 36 | 37 | 38 | 39 | e(n) 40 | int n; 41 | { 42 | printf("Subtest %d, error %d errno=%d ", testnr, n, errno); 43 | perror(""); 44 | errct++; 45 | } 46 | -------------------------------------------------------------------------------- /test/test8.c: -------------------------------------------------------------------------------- 1 | #include "stat.h" 2 | extern int errno; 3 | int testnr; 4 | extern long lseek(); 5 | 6 | 7 | main() 8 | { 9 | int i; 10 | 11 | printf("Test 8 "); 12 | for (i = 0; i < 4; i++) { 13 | test80(); 14 | } 15 | printf("ok\n"); 16 | } 17 | 18 | 19 | 20 | test80() 21 | { 22 | /* Test mknod, chdir, chmod, chown, access. */ 23 | 24 | int i, j; 25 | struct stat s; 26 | 27 | testnr = 0; 28 | for (j=0; j < 2; j++) { 29 | umask(0); 30 | 31 | if (chdir("/") < 0) e(1); 32 | if (mknod("dir", 040700, 0) < 0) e(2); 33 | if (link("/", "/dir/..") < 0) e(3); 34 | if ( mknod("T3a", 0777, 0) < 0) e(4); 35 | if (mknod("/dir/T3b", 0777, 0) < 0) e(5); 36 | if (mknod("dir/T3c", 0777, 0) < 0) e(6); 37 | if ((i=open("/dir/T3b",0)) < 0) e(7); 38 | if (close(i) < 0) e(8); 39 | if ((i=open("dir/T3c", 0)) < 0) e(9); 40 | if (close(i) < 0) e(10); 41 | if (chdir("dir") < 0) e(11); 42 | if ((i=open("T3b",0)) < 0) e(12); 43 | if (close(i) < 0) e(13); 44 | if ((i=open("../T3a", 0)) < 0) e(14); 45 | if (close(i) < 0 ) e(15); 46 | if ((i=open("../dir/../dir/../dir/../dir/../dir/T3c", 0)) < 0) e(16); 47 | if (close(i) < 0) e(17); 48 | 49 | if (chmod("../dir/../dir/../dir/../dir/../T3a", 0123) < 0) e(18); 50 | if (stat("../dir/../dir/../dir/../T3a", &s) < 0) e(19); 51 | if((s.st_mode & 077777) != 0123) e(20); 52 | if (chmod("../dir/../dir/../T3a", 0456) < 0) e(21); 53 | if (stat("../T3a", &s) < 0) e(22); 54 | if((s.st_mode & 077777) != 0456) e(23); 55 | if (chown("../dir/../dir/../T3a", 20,30) < 0) e(24); 56 | if (stat("../T3a", &s) < 0) e(25); 57 | if(s.st_uid != 20) e(26); 58 | if(s.st_gid != 30) e(27); 59 | 60 | if ((i=open("/T3c", 0)) >= 0) e(28); 61 | if ((i=open("/T3a", 0)) < 0) e(29); 62 | if (close(i) < 0) e(30); 63 | 64 | if (access("/T3a", 4) < 0) e(31); 65 | if (access("/dir/T3b", 4) < 0) e(32); 66 | if (access("/dir/T3d", 4) >= 0) e(33); 67 | 68 | if (unlink("T3b") < 0) e(34); 69 | if (unlink("T3c") < 0) e(35); 70 | if (unlink("..") < 0) e(36); 71 | if (chdir("/") < 0) e(37); 72 | if (unlink("dir") < 0) e(38); 73 | if (unlink("/T3a") < 0) e(39); 74 | } 75 | 76 | } 77 | 78 | 79 | 80 | e(n) 81 | int n; 82 | { 83 | printf("Subtest %d, error %d errno=%d ", testnr, n, errno); 84 | perror(""); 85 | } 86 | -------------------------------------------------------------------------------- /tools/c86/_bootblo.bat: -------------------------------------------------------------------------------- 1 | masm bootblok,,nul,nul > bootblok.lst 2 | link bootblok,,nul,nul >>bootblok.lst 3 | exe2bin bootblok.exe bootblok.bin >>bootblok.lst 4 | del bootblok.exe >nul 5 | del bootblok.obj >nul 6 | if "%batch%" == "MINIX" make minix 7 | -------------------------------------------------------------------------------- /tools/c86/_build.bat: -------------------------------------------------------------------------------- 1 | if "%1" == "-l" goto link 2 | if exist diskio.obj goto cc 3 | masm diskio,,nul,nul >build.lst 4 | :cc 5 | if exist build.obj goto link 6 | cc1 -dMSDOS build >> build.lst 7 | if errorlevel 1 goto einde 8 | cc2 build >> build.lst 9 | if errorlevel 1 goto einde 10 | cc3 build >> build.lst 11 | if errorlevel 1 goto einde 12 | cc4 build >> build.lst 13 | if errorlevel 1 goto einde 14 | :link 15 | link/m build+diskio,,,\lib\c86\C86s2s.lib >> build.lst 16 | :einde 17 | -------------------------------------------------------------------------------- /tools/c86/_dos2out.bat: -------------------------------------------------------------------------------- 1 | if exist dos2out.obj goto link 2 | cc1 dos2out >> dos2out.lst 3 | if errorlevel 1 goto fout 4 | cc2 dos2out >> dos2out.lst 5 | if errorlevel 1 goto fout 6 | cc3 dos2out >> dos2out.lst 7 | if errorlevel 1 goto fout 8 | cc4 dos2out >> dos2out.lst 9 | if errorlevel 1 goto fout 10 | :link 11 | link/m dos2out,,,\lib\c86\C86s2s.lib >> dos2out.lst 12 | -------------------------------------------------------------------------------- /tools/c86/_fsck.bat: -------------------------------------------------------------------------------- 1 | echo/ 2 | if "%1"=="-b" goto asm 3 | if "%1"=="-m" goto asm 4 | if "%1"=="-d" goto asm 5 | echo No switch specified for linkage. 6 | echo Switches are: 7 | echo -b link for boot-diskette 8 | echo -m link as a minix-program 9 | echo -d link as a dos-program 10 | echo Note that the appropriate symbol must be 11 | echo defined in both fsck.c and fsck1.asm 12 | echo Optionally you can specify '-l', which 13 | echo will only link fsck. 14 | goto eind 15 | :asm 16 | if "%2"=="-l" goto link 17 | if exist fsck1.obj goto c1 18 | masm fsck1,,nul,nul >fsck.lst 19 | :c1 20 | if exist fsck.obj goto link 21 | cc1 fsck >fsck.lst 22 | if errorlevel 1 goto fout 23 | cc2 fsck >>fsck.lst 24 | if errorlevel 1 goto fout 25 | cc3 fsck >>fsck.lst 26 | if errorlevel 1 goto fout 27 | cc4 fsck >>fsck.lst 28 | if errorlevel 1 goto fout 29 | :link 30 | if not "%1"=="-b" goto m 31 | echo Linking (boot version) 32 | link/m fsck1+fsck,fsck,fsck,..\lib\mxc86 >>fsck.lst 33 | dos2out -d fsck >>fsck.lst 34 | goto eind 35 | :m 36 | if not "%1"=="-m" goto d 37 | echo Linking (minix version) 38 | link/m ..\lib\crtso+fsck+fsck1,fsck,fsck,..\lib\mxc86 >>fsck.lst 39 | dos2out -d fsck >>fsck.lst 40 | goto eind 41 | :d 42 | if not "%1"=="-d" goto fout 43 | echo Linking (dos version) 44 | link/m fsck+fsck1,,,\lib\c86\c86s2s.lib >>fsck.lst 45 | goto eind 46 | :fout 47 | echo/ 48 | echo error in compilation 49 | :eind 50 | -------------------------------------------------------------------------------- /tools/c86/_image.bat: -------------------------------------------------------------------------------- 1 | build bootblok.bin ..\kernel\kernel.out ..\mm\mm.out ..\fs\fs.out init.out fsck.out %1 2 | -------------------------------------------------------------------------------- /tools/c86/_init.bat: -------------------------------------------------------------------------------- 1 | if "%1"=="-l" goto link 2 | if exist init.obj goto link 3 | cc1 init >init.lst 4 | if errorlevel 1 goto fout 5 | cc2 init >>init.lst 6 | if errorlevel 1 goto fout 7 | cc3 init >>init.lst 8 | if errorlevel 1 goto fout 9 | cc4 init >>init.lst 10 | if errorlevel 1 goto fout 11 | :link 12 | link/m ..\lib\head+init,init,init,..\lib\mxc86 >>init.lst 13 | dos2out -d init >>init.lst 14 | echo/ 15 | echo Init done. Hit reurn to see list file. 16 | pause 17 | echo on 18 | type init.lst 19 | -------------------------------------------------------------------------------- /tools/c86/_mkfs.bat: -------------------------------------------------------------------------------- 1 | if "%1"=="-l" goto link 2 | cc1 -dDOS mkfs 3 | if errorlevel 1 goto fout 4 | cc2 mkfs 5 | if errorlevel 1 goto fout 6 | cc3 mkfs 7 | if errorlevel 1 goto fout 8 | cc4 mkfs 9 | if errorlevel 1 goto fout 10 | :link 11 | link mkfs+diskio,mkfs,nul,\lib\c86\c86s2s.lib 12 | goto ok 13 | :fout 14 | pause error in compilation 15 | :ok 16 | -------------------------------------------------------------------------------- /tools/c86/bootblok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdevic/minix1/3475e7ed91a3ff3f8862b2543059580a01c1b1a7/tools/c86/bootblok -------------------------------------------------------------------------------- /tools/c86/diskio.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdevic/minix1/3475e7ed91a3ff3f8862b2543059580a01c1b1a7/tools/c86/diskio.asm -------------------------------------------------------------------------------- /tools/c86/make.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | echo/ 3 | echo Making: %1 4 | echo/ 5 | _%1.bat %2 %3 %4 %5 %6 %7 %8 %9 6 | -------------------------------------------------------------------------------- /tools/changeme: -------------------------------------------------------------------------------- 1 | : The default stack size is 1K. The following commands need more. 2 | b=../commands/bin 3 | t=../test 4 | chmem =2000 $b/cc 5 | chmem =2000 $b/time 6 | chmem =2000 $b/tail 7 | chmem =40000 $b/cpp 8 | chmem =52000 $b/cem 9 | chmem =20000 $b/opt 10 | chmem =30000 $b/cg 11 | chmem =30000 $b/sort 12 | chmem =30000 $b/asld 13 | chmem =16000 $b/mkfs 14 | chmem =8000 $b/dd 15 | chmem =8000 $b/rmdir 16 | chmem =8000 $b/mkdir 17 | chmem =32000 $b/dosread 18 | chmem =20000 $b/make 19 | chmem =8000 $b/gres 20 | chmem =8000 $b/grep 21 | chmem =8000 $b/sh 22 | chmem =8000 $b/gres 23 | chmem =8000 $b/mv 24 | chmem =8000 $b/rm 25 | chmem =8000 $b/pr 26 | chmem =64000 $b/libpack 27 | chmem =64000 $b/libupack 28 | chmem =64000 $b/mined 29 | chmem =8000 $t/test0 30 | chmem =8000 $t/test1 31 | chmem =8000 $t/test2 32 | chmem =8000 $t/test3 33 | chmem =8000 $t/test4 34 | chmem =8000 $t/test5 35 | chmem =8000 $t/test6 36 | chmem =8000 $t/test7 37 | chmem =8000 $t/test8 38 | chmem =8000 $t/test9 39 | chmem =8000 $t/test10 40 | chmem =8000 $t/test11 41 | chmem =8000 $t/t10a 42 | chmem =8000 $t/t11a 43 | chmem =8000 $t/t11b 44 | chmem =8000 $b/df 45 | -------------------------------------------------------------------------------- /tools/getcore.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | int fd, fd1, n; 4 | char buf[512], buf1[1536]; 5 | 6 | fd = open("/dev/fd0", 0); 7 | read(fd, buf1,3*512); 8 | fd1 = creat("core.0", 0777); 9 | write(fd1, buf1, 3*512); 10 | close(fd1); 11 | fd1 = creat("core", 0777); 12 | do { 13 | n = read(fd, buf, 512); 14 | write(fd1, buf, n); 15 | } while (n > 0); 16 | } 17 | -------------------------------------------------------------------------------- /tools/passwd: -------------------------------------------------------------------------------- 1 | root::0:0::/: 2 | daemon:*:1:1::/etc: 3 | bin:*:2:2::/bin: 4 | ast::8:3::/usr/ast: 5 | -------------------------------------------------------------------------------- /tools/proto.ram: -------------------------------------------------------------------------------- 1 | boot 2 | 240 95 3 | d--777 2 1 4 | bin d--755 2 1 5 | cat ---755 2 1 ../commands/bin/cat 6 | cc ---755 2 1 ../commands/bin/cc 7 | cp ---755 2 1 ../commands/bin/cp 8 | getlf ---755 2 1 ../commands/bin/getlf 9 | kill ---755 2 1 ../commands/bin/kill 10 | ls ---755 2 1 ../commands/bin/ls 11 | mkdir -u-755 0 1 ../commands/bin/mkdir 12 | mined ---755 2 1 ../commands/bin/mined 13 | rm ---755 2 1 ../commands/bin/rm 14 | sh ---755 2 1 ../commands/bin/sh 15 | sync ---755 2 1 ../commands/bin/sync 16 | $ 17 | dev d--755 2 1 18 | ram b--640 2 1 1 0 640 19 | mem b--640 2 1 1 1 640 20 | kmem b--640 2 1 1 2 640 21 | null b--666 2 1 1 3 0 22 | fd0 b--666 2 1 2 0 360 23 | fd1 b--666 2 1 2 1 360 24 | at0 b--666 2 1 2 0 1200 25 | at1 b--666 2 1 2 1 1200 26 | hd0 b--600 2 1 3 0 0 27 | hd1 b--600 2 1 3 1 0 28 | hd2 b--600 2 1 3 2 0 29 | hd3 b--600 2 1 3 3 0 30 | hd4 b--600 2 1 3 4 0 31 | tty0 c--666 2 1 4 0 32 | tty c--666 2 1 5 0 33 | lp c--222 2 1 6 0 34 | $ 35 | etc d--755 2 1 36 | mount -u-755 0 1 ../commands/bin/mount 37 | umount -u-755 0 1 ../commands/bin/umount 38 | update ---755 2 1 ../commands/bin/update 39 | passwd ---644 2 1 passwd 40 | rc ---644 2 1 rc 41 | message ---644 2 1 message 42 | ttys ---644 2 1 ttys 43 | $ 44 | lib d--755 2 1 45 | cpp ---755 2 1 ../commands/bin/cpp 46 | cem ---755 2 1 ../commands/bin/cem 47 | $ 48 | tmp d--777 2 1 49 | $ 50 | user d--755 2 1 51 | $ 52 | usr d--755 2 1 53 | $ 54 | $ 55 | -------------------------------------------------------------------------------- /tools/proto.use: -------------------------------------------------------------------------------- 1 | boot 2 | 360 127 3 | d--755 1 1 4 | ast d--755 8 3 5 | .profile ---644 8 3 profile 6 | $ 7 | bin d--755 2 1 8 | gres ---755 2 1 ../commands/bin/gres 9 | rev ---755 2 1 ../commands/bin/rev 10 | roff ---755 2 1 ../commands/bin/roff 11 | shar ---755 2 1 ../commands/bin/shar 12 | tar ---755 2 1 ../commands/bin/tar 13 | $ 14 | test d--777 2 1 15 | test0 -u-755 0 1 ../test/test0 16 | test1 -u-755 0 1 ../test/test1 17 | test2 -u-755 0 1 ../test/test2 18 | test3 -u-755 0 1 ../test/test3 19 | test4 -u-755 0 1 ../test/test4 20 | test5 -u-755 0 1 ../test/test5 21 | test6 -u-755 0 1 ../test/test6 22 | test7 -u-755 0 1 ../test/test7 23 | test8 -u-755 0 1 ../test/test8 24 | test9 -u-755 0 1 ../test/test9 25 | test10 -u-755 0 1 ../test/test10 26 | t10a -u-755 0 1 ../test/t10a 27 | test11 -u-755 0 1 ../test/test11 28 | t11a -u-755 0 1 ../test/t11a 29 | t11b -u-755 0 1 ../test/t11b 30 | test0.c ---644 2 1 ../test/test0.c 31 | test1.c ---644 2 1 ../test/test1.c 32 | test2.c ---644 2 1 ../test/test2.c 33 | test3.c ---644 2 1 ../test/test3.c 34 | test4.c ---644 2 1 ../test/test4.c 35 | test5.c ---644 2 1 ../test/test5.c 36 | test6.c ---644 2 1 ../test/test6.c 37 | test7.c ---644 2 1 ../test/test7.c 38 | test8.c ---644 2 1 ../test/test8.c 39 | test9.c ---644 2 1 ../test/test9.c 40 | test10.c ---644 2 1 ../test/test10.c 41 | t10a.c ---644 2 1 ../test/t10a.c 42 | test11.c ---644 2 1 ../test/test11.c 43 | t11a.c ---644 2 1 ../test/t11a.c 44 | t11b.c ---644 2 1 ../test/t11b.c 45 | run ---755 2 1 ../test/run 46 | MINIX d--755 2 1 ../test/MINIX 47 | makefile ---644 2 1 ../test/MINIX/makefile 48 | $ 49 | $ 50 | commands d--755 2 1 51 | mined.h ---644 2 1 ../include/mined.h 52 | mined1.c ---644 2 1 ../commands/mined1.c 53 | mined2.c ---644 2 1 ../commands/mined2.c 54 | sh.h ---644 2 1 ../include/sh.h 55 | sh1.c ---644 2 1 ../commands/sh1.c 56 | sh2.c ---644 2 1 ../commands/sh2.c 57 | sh3.c ---644 2 1 ../commands/sh3.c 58 | sh4.c ---644 2 1 ../commands/sh4.c 59 | sh5.c ---644 2 1 ../commands/sh5.c 60 | $ 61 | doc d--755 2 1 62 | READ_ME ---644 2 1 ../doc/READ_ME 63 | $ 64 | $ 65 | -------------------------------------------------------------------------------- /tools/proto.usr: -------------------------------------------------------------------------------- 1 | boot 2 | 360 95 3 | d--755 1 1 4 | ast d--755 8 3 5 | .profile ---644 8 3 profile 6 | $ 7 | bin d--755 2 1 8 | ar ---755 2 1 ../commands/bin/ar 9 | asld ---755 2 1 ../commands/bin/asld 10 | basename ---755 2 1 ../commands/bin/basename 11 | chmem ---755 2 1 ../commands/bin/chmem 12 | chmod ---755 2 1 ../commands/bin/chmod 13 | chown ---755 2 1 ../commands/bin/chown 14 | clr ---755 2 1 ../commands/bin/clr 15 | cmp ---755 2 1 ../commands/bin/cmp 16 | comm ---755 2 1 ../commands/bin/comm 17 | date ---755 2 1 ../commands/bin/date 18 | dd ---755 2 1 ../commands/bin/dd 19 | df -u-755 0 1 ../commands/bin/df 20 | dosread ---755 2 1 ../commands/bin/dosread 21 | echo ---755 2 1 ../commands/bin/echo 22 | grep ---755 2 1 ../commands/bin/grep 23 | head ---755 2 1 ../commands/bin/head 24 | libpack ---755 2 1 ../commands/bin/libpack 25 | libupack ---755 2 1 ../commands/bin/libupack 26 | ln ---755 2 1 ../commands/bin/ln 27 | login ---755 2 1 ../commands/bin/login 28 | lpr ---755 2 1 ../commands/bin/lpr 29 | make ---755 2 1 ../commands/bin/make 30 | mkfs ---755 2 1 ../commands/bin/mkfs 31 | mknod ---755 2 1 ../commands/bin/mknod 32 | mv ---755 2 1 ../commands/bin/mv 33 | od ---755 2 1 ../commands/bin/od 34 | passwd -u-755 0 1 ../commands/bin/passwd 35 | pr ---755 2 1 ../commands/bin/pr 36 | pwd ---755 2 1 ../commands/bin/pwd 37 | rmdir -u-755 0 1 ../commands/bin/rmdir 38 | size ---755 2 1 ../commands/bin/size 39 | sleep ---755 2 1 ../commands/bin/sleep 40 | sort ---755 2 1 ../commands/bin/sort 41 | split ---755 2 1 ../commands/bin/split 42 | stty ---755 2 1 ../commands/bin/stty 43 | su -u-755 0 1 ../commands/bin/su 44 | sum ---755 2 1 ../commands/bin/sum 45 | tail ---755 2 1 ../commands/bin/tail 46 | tee ---755 2 1 ../commands/bin/tee 47 | time ---755 2 1 ../commands/bin/time 48 | touch ---755 2 1 ../commands/bin/touch 49 | tr ---755 2 1 ../commands/bin/tr 50 | true ---755 2 1 ../commands/bin/true 51 | uniq ---755 2 1 ../commands/bin/uniq 52 | wc ---755 2 1 ../commands/bin/wc 53 | $ 54 | include d--755 2 1 55 | blocksize.h ---644 2 1 ../include/blocksize.h 56 | errno.h ---644 2 1 ../include/errno.h 57 | sgtty.h ---644 2 1 ../include/sgtty.h 58 | signal.h ---644 2 1 ../include/signal.h 59 | stat.h ---644 2 1 ../include/stat.h 60 | setjmp.h ---644 2 1 ../include/setjmp.h 61 | stdio.h ---644 2 1 ../include/stdio.h 62 | $ 63 | lib d--755 2 1 64 | cg ---755 2 1 ../commands/bin/cg 65 | opt ---755 2 1 ../commands/bin/opt 66 | crtso.s ---755 2 1 ../lib/MINIX/crtso.s 67 | end.s ---755 2 1 ../lib/MINIX/end.s 68 | head.s ---755 2 1 ../lib/MINIX/head.s 69 | libc.a ---755 2 1 ../commands/bin/libc.a 70 | $ 71 | $ 72 | -------------------------------------------------------------------------------- /tools/r.c: -------------------------------------------------------------------------------- 1 | long hexin(), addr, lseek(); 2 | short sval; 3 | char c; 4 | 5 | main(argc, argv) 6 | int argc; 7 | char *argv[]; 8 | { 9 | int fd,ct; 10 | 11 | if (argc == 2) 12 | fd = open(argv[1], 0); 13 | else 14 | fd = open("core.88",0); 15 | if (fd <0) {perror("can't open core file"); exit();} 16 | while (1) { 17 | addr = hexin(); 18 | addr = addr & ~0xF; 19 | ct = 0; 20 | if (c==',') ct = hexin(); 21 | do { 22 | wrl(fd, addr); 23 | addr += 16; 24 | } while (--ct > 0); 25 | } 26 | } 27 | long hexin() 28 | { 29 | /* Read in a hex character string and return its value.*/ 30 | long n = 0; 31 | int digits = 0; 32 | 33 | while (1) { 34 | c = getchar(); 35 | if (digits==0 && c == '\n') return(addr); 36 | if (digits==0 && c == -1) exit(); 37 | digits++; 38 | if (c >= '0' && c <= '9') {n = (n<<4)+(c - '0'); continue;} 39 | if (c >= 'a' && c <= 'f') {n = (n<<4)+(10 + c - 'a'); continue;} 40 | if (c >= 'A' && c <= 'F') {n = (n<<4)+(10 + c - 'A'); continue;} 41 | return(n); 42 | } 43 | } 44 | hex(x) 45 | short x; 46 | { /* Print x in hex */ 47 | 48 | int i,k; 49 | char c1; 50 | 51 | for (i=0; i<4; i++) { 52 | k = (x >> (12-4*i)) & 017; 53 | c1 = (k <= 9 ? k+060 : k -10 + 'A'); 54 | printf("%c", c1); 55 | } 56 | printf(" "); 57 | } 58 | 59 | 60 | wrl(fd, address) 61 | int fd; 62 | long address; 63 | { 64 | int i; 65 | printf("%5lx: ",address); 66 | if (lseek(fd, address,0)!= address) {perror("Can't seek"); exit();} 67 | for (i=0; i<8; i++) { 68 | read(fd,&sval,2); 69 | hex(sval); 70 | } 71 | printf("\n"); 72 | } 73 | -------------------------------------------------------------------------------- /tools/rc.at: -------------------------------------------------------------------------------- 1 | /bin/getlf "Please insert /usr diskette in drive 0. Then hit RETURN." 2 | /etc/mount /dev/at0 /usr 3 | /usr/bin/date -q