Annotation of coherent/b/lib/libc/sys/i386/mkscall.c, revision 1.1.1.1

1.1       root        1: /* Copyright (c) Bureau d'Etudes Ciaran O'Donnell,1987,1990,1991 */
                      2: /*
                      3:  * mkscall.c - to make sys-call interface routine
                      4:  * usage : mkscall name number nargs [-r rel-num]
                      5:  *        mkscall -f file
                      6:  */    
                      7: #include <stdio.h>
                      8: #include <ctype.h>
                      9: 
                     10: char *usage = "usage: mkscall name number nargs [flags] [-r rel]\n";
                     11: 
                     12: struct _args {
                     13: 
                     14:        char *a_name;   /* function name        */      
                     15:        short a_num;    /* system call number   */
                     16:        short a_arg;    /* arg-count            */ 
                     17:        short a_flag;   /* various flags - FLAG0 -> rval in d1. */
                     18:                        /*                 FLAG1 -> arg = *arg  */
                     19:        char *a_rel;    /* ident string         */
                     20: };
                     21: 
                     22: #define FLAG0  0x01
                     23: #define FLAG1  0x02
                     24:  
                     25: main(argc, argv)
                     26: register argc;
                     27: register char *argv[];
                     28: {
                     29: 
                     30:        struct _args args;
                     31:        register char *fname = 0;       /* input file for arg list */
                     32: 
                     33:        if(argc < 4){
                     34: 
                     35:                if(argc == 3 && argv[1][0] == '-' && argv[1][1] == 'f') {
                     36:                        fname = argv[2];
                     37:                }
                     38:                else {
                     39:                        fprintf(stderr,usage);
                     40:                        exit(1);
                     41:                }
                     42:        }
                     43: 
                     44:        
                     45:        if(fname == (char *)0) {
                     46: 
                     47:                args.a_name = argv[1];
                     48:                args.a_num = atoi(argv[2]);
                     49:                args.a_arg = atoi(argv[3]);
                     50:        
                     51:                if(argc > 4) {
                     52:                        args.a_flag = atoi(argv[4]);
                     53:                }
                     54: 
                     55:                mk_func(&args);
                     56: 
                     57: 
                     58:        } else {
                     59: 
                     60:                register FILE *ffd;
                     61:                register lcount;
                     62:                register st;
                     63: 
                     64:                if((ffd = fopen(fname, "r")) == NULL) {
                     65: 
                     66:                        fprintf(stderr, "mkscall: can't open %s\n", fname);
                     67:                        exit(2);
                     68:                }
                     69: 
                     70:                for(lcount = 1; st = getargs(ffd, &args); lcount++) {
                     71: 
                     72:                        if(st == -1)
                     73:                                fprintf(stderr,
                     74:                                "mkscall: file %s, line %d discarded\n",
                     75:                                                         fname, lcount);
                     76: 
                     77:                        else
                     78:                                mk_func(&args);
                     79:                }
                     80:        }
                     81: 
                     82:        exit(0);
                     83: }
                     84: 
                     85: 
                     86: /*
                     87:  * make system call routine.
                     88:  */
                     89: 
                     90: 
                     91: mk_func(arg)
                     92: register struct _args *arg;
                     93: {
                     94: 
                     95:        register FILE *fd;
                     96:        register count;
                     97:        char file[20];
                     98:        register flag;
                     99: 
                    100:        flag = arg->a_flag;
                    101: 
                    102:        if(arg->a_arg > 6) {
                    103:                fprintf(stderr, "mkscall: func %s, too much args\n",
                    104:                                                         arg->a_name);
                    105:                return(-1);
                    106:        }
                    107: 
                    108:        /* check arg count for flag = FLAG1 (arg = *arg) */
                    109:        if((flag & FLAG1) && (arg->a_arg > 1)) {
                    110: 
                    111:                fprintf(stderr,
                    112:                 "mkscall: func %s, only one arg allowed with flag 0x%02x.\n",
                    113:                                         arg->a_name, flag & FLAG1);
                    114:                return(-1);
                    115:        }
                    116: 
                    117:        strcpy(file, arg->a_name);
                    118:        strcat(file, ".s");
                    119: 
                    120:        if((fd = fopen(file, "w")) == NULL) {
                    121: 
                    122:                fprintf(stderr, "mkscall: can't create %s\n", file);
                    123:                return(-1);
                    124:        }
                    125: 
                    126: 
                    127:        fprintf(fd, "/ C library - %s\n",  arg->a_name);
                    128: 
                    129:        fprintf(fd,"\n  .globl  %s", arg->a_name);
                    130:        fprintf(fd,"\n  .globl  .cerror");
                    131: 
                    132:        fprintf(fd,"\n\n%s:\n", arg->a_name);
                    133:        
                    134:        if(flag & FLAG1) {              /* arg must be *arg */
                    135: 
                    136:                fprintf(fd,"    movl    4(%%esp),%%edx\n");
                    137:                fprintf(fd,"    movl    (%%edx),%%edx\n");
                    138:                fprintf(fd,"    movl    %%edx,4(%%esp)\n");
                    139:        }
                    140: 
                    141:        /* put system-call number in d0 */
                    142:        fprintf(fd, "   movl    $%d,%%eax\n", arg->a_num);
                    143:        fprintf(fd, "   lcall   $0x7,$0\n");
                    144:        fprintf(fd,"    jc      .cerror\n");
                    145: 
                    146:        if(flag & FLAG0) {              /* rval in d1 */
                    147:  
                    148:                fprintf(fd, "\n movl    %%edx,%%eax\n");  
                    149:        }
                    150: 
                    151:        fprintf(fd,"    ret\n");
                    152:        fflush(fd);
                    153:        fclose(fd);
                    154: 
                    155:        return(0);
                    156: }
                    157: 
                    158: /*
                    159:  * get a line from input file and cracks args.
                    160:  */
                    161: 
                    162: #define BFS 20
                    163: char bfnam[BFS];
                    164: 
                    165: getargs(fd, arg)       
                    166: register FILE *fd;
                    167: register struct _args *arg;
                    168: {
                    169:        register char buff[80];
                    170: 
                    171:        arg->a_name = NULL;
                    172:        arg->a_num = arg->a_arg = arg->a_flag = 0;
                    173: 
                    174: more : if(fgets(buff, 80, fd) == NULL) {
                    175: 
                    176:                return(0);
                    177:        }
                    178: 
                    179:        else {
                    180: 
                    181:                char *get_word();
                    182:                register char *w;
                    183: 
                    184: 
                    185:                if(*buff == '#') {
                    186:                        goto more;              /* skip comment line */
                    187:                }
                    188: 
                    189:                if(w = get_word(buff)) {
                    190:                        strncpy(bfnam, w, BFS-1);
                    191:                        arg->a_name = bfnam;    /* get func name */
                    192:                }
                    193:                else
                    194:                        goto error;
                    195: 
                    196:                if(w = get_word(w + strlen(w) + 1))
                    197:                        arg->a_num = atoi(w);   /* get sys-call number */
                    198:                else
                    199:                        goto error;
                    200: 
                    201:                if(w = get_word(w + strlen(w) + 1))
                    202:                        arg->a_arg = atoi(w);   /* get arg count */
                    203:                else
                    204:                        goto error;
                    205: 
                    206:                if(w = get_word(w + strlen(w) + 1))
                    207:                        arg->a_flag = atoi(w);  /* get flags    */
                    208: 
                    209:                
                    210:                return(1);
                    211:        }
                    212: 
                    213: error :
                    214:        return(-1);
                    215: }
                    216: 
                    217: 
                    218: /*
                    219:  * get next string from buff and terminate it by a null.
                    220:  */
                    221: 
                    222: char * 
                    223: get_word(buff)
                    224: register char *buff;
                    225: {
                    226:        register char *w = (char *)0;
                    227:        register c;
                    228: 
                    229:        while((c = *buff)) {
                    230: 
                    231:                if(c == '#')            /* rest of the line is comment */
                    232:                        break;
                    233: 
                    234:                if(isspace(c)) {
                    235: 
                    236:                        if(w)
                    237:                        {
                    238:                                *buff = '\0';
                    239:                                break;
                    240:                        }
                    241: 
                    242:                } else if(!w)
                    243:                        w = buff;
                    244: 
                    245:                buff++;
                    246:        }
                    247: 
                    248:        return(w);
                    249: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.