Deleted Added
full compact
aicasm.c (8876) aicasm.c (13177)
1/*+M*************************************************************************
2 * Adaptec AIC7770/AIC7870 sequencer code assembler.
3 *
4 * Copyright (c) 1994 John Aycock
5 * The University of Calgary Department of Computer Science.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38 * <label>*
39 * <label>* <undef-sym> = <value>
40 * <label>* <opcode> <operand>*
41 *
42 * A <label> is an <undef-sym> ending in a colon. Spaces, tabs, and commas
43 * are token separators.
44 *
45 *-M*************************************************************************/
1/*+M*************************************************************************
2 * Adaptec AIC7770/AIC7870 sequencer code assembler.
3 *
4 * Copyright (c) 1994 John Aycock
5 * The University of Calgary Department of Computer Science.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38 * <label>*
39 * <label>* <undef-sym> = <value>
40 * <label>* <opcode> <operand>*
41 *
42 * A <label> is an <undef-sym> ending in a colon. Spaces, tabs, and commas
43 * are token separators.
44 *
45 *-M*************************************************************************/
46static char id[] = "$Id: aic7xxx_asm.c,v 1.8 1995/04/15 21:45:56 gibbs Exp $";
46static char id[] = "$Id: aic7xxx_asm.c,v 1.9 1995/05/30 07:57:33 rgrimes Exp $";
47#include <ctype.h>
48#include <stdio.h>
49#include <string.h>
50#include <stdlib.h>
51#include <unistd.h>
47#include <ctype.h>
48#include <stdio.h>
49#include <string.h>
50#include <stdlib.h>
51#include <unistd.h>
52#include <fcntl.h>
52
53#define MEMORY 448
54#define MAXLINE 1024
55#define MAXTOKEN 32
56#define ADOTOUT "a.out"
57#define NOVALUE -1
58
59/*
60 * AIC-7770/AIC-7870 register definitions
61 */
62#define R_SINDEX 0x65
63#define R_ALLONES 0x69
64#define R_ALLZEROS 0x6a
65#define R_NONE 0x6a
66
67int debug;
68int lineno, LC;
69char *filename;
53
54#define MEMORY 448
55#define MAXLINE 1024
56#define MAXTOKEN 32
57#define ADOTOUT "a.out"
58#define NOVALUE -1
59
60/*
61 * AIC-7770/AIC-7870 register definitions
62 */
63#define R_SINDEX 0x65
64#define R_ALLONES 0x69
65#define R_ALLZEROS 0x6a
66#define R_NONE 0x6a
67
68int debug;
69int lineno, LC;
70char *filename;
70FILE *ifp, *ofp;
71unsigned char M[MEMORY][4];
72
73void
74error(char *s)
75{
76 fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno);
77 exit(EXIT_FAILURE);
78}

--- 139 unchanged lines hidden (view full) ---

218{
219 int i;
220 char *p, *quote;
221 static char buf[MAXLINE];
222 static char *a[MAXTOKEN];
223
224 i = 0;
225
71unsigned char M[MEMORY][4];
72
73void
74error(char *s)
75{
76 fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno);
77 exit(EXIT_FAILURE);
78}

--- 139 unchanged lines hidden (view full) ---

218{
219 int i;
220 char *p, *quote;
221 static char buf[MAXLINE];
222 static char *a[MAXTOKEN];
223
224 i = 0;
225
226 while (fgets(buf, sizeof(buf), ifp)) {
226 while (fgets(buf, sizeof(buf), stdin)) {
227
228 lineno += 1;
229
230 if (buf[strlen(buf)-1] != '\n')
231 error("line too long");
232
233 p = strchr(buf, '#');
234 if (p)

--- 296 unchanged lines hidden (view full) ---

531#undef RR
532#undef LX
533#undef LA
534#undef LO
535#undef I
536#undef A
537
538void
227
228 lineno += 1;
229
230 if (buf[strlen(buf)-1] != '\n')
231 error("line too long");
232
233 p = strchr(buf, '#');
234 if (p)

--- 296 unchanged lines hidden (view full) ---

531#undef RR
532#undef LX
533#undef LA
534#undef LO
535#undef I
536#undef A
537
538void
539assemble(void)
539assemble(FILE *ofile)
540{
541 int n;
542 char **a;
543 sym_t *p;
544
545 while ((a = getl(&n))) {
546
547 while (a[0][strlen(*a)-1] == ':') {

--- 6 unchanged lines hidden (view full) ---

554 a += 1;
555 n -= 1;
556 }
557
558 if (!n) /* line was all labels */
559 continue;
560
561 if (n == 3 && !strcmp("VERSION", *a))
540{
541 int n;
542 char **a;
543 sym_t *p;
544
545 while ((a = getl(&n))) {
546
547 while (a[0][strlen(*a)-1] == ':') {

--- 6 unchanged lines hidden (view full) ---

554 a += 1;
555 n -= 1;
556 }
557
558 if (!n) /* line was all labels */
559 continue;
560
561 if (n == 3 && !strcmp("VERSION", *a))
562 fprintf(ofp, "#define %s \"%s\"\n", a[1], a[2]);
562 fprintf(ofile, "#define %s \"%s\"\n", a[1], a[2]);
563 else {
564 if (n == 3 && !strcmp("=", a[1]))
565 define(*a, strtol(a[2], NULL, 0));
566 else
567 LC += crack(a, n);
568 }
569 }
570
571 backpatch();
563 else {
564 if (n == 3 && !strcmp("=", a[1]))
565 define(*a, strtol(a[2], NULL, 0));
566 else
567 LC += crack(a, n);
568 }
569 }
570
571 backpatch();
572 output(ofp);
572 output(ofile);
573
574 if (debug)
575 output(stderr);
576}
577
578int
579main(int argc, char **argv)
580{
581 int c;
573
574 if (debug)
575 output(stderr);
576}
577
578int
579main(int argc, char **argv)
580{
581 int c;
582 int pid;
583 int ifile;
584 FILE *ofile;
585 int fd[2];
582
586
587 ofile = NULL;
583 while ((c = getopt(argc, argv, "dho:vD")) != EOF) {
584 switch (c) {
585 case 'd':
586 debug = !0;
587 break;
588 case 'D':
589 {
590 char *p;
591 if ((p = strchr(optarg, '=')) != NULL) {
592 *p = '\0';
593 define(optarg, strtol(p + 1, NULL, 0));
594 }
595 else
596 define(optarg, 1);
597 break;
598 }
599 case 'o':
588 while ((c = getopt(argc, argv, "dho:vD")) != EOF) {
589 switch (c) {
590 case 'd':
591 debug = !0;
592 break;
593 case 'D':
594 {
595 char *p;
596 if ((p = strchr(optarg, '=')) != NULL) {
597 *p = '\0';
598 define(optarg, strtol(p + 1, NULL, 0));
599 }
600 else
601 define(optarg, 1);
602 break;
603 }
604 case 'o':
600 ofp = fopen(optarg, "w");
601 if (!ofp) {
605
606 if ((ofile = fopen(optarg, "w")) < 0) {
602 perror(optarg);
603 exit(EXIT_FAILURE);
604 }
605 break;
606 case 'h':
607 printf("usage: %s [-d] [-Dname] [-ooutput] input\n",
608 *argv);
609 exit(EXIT_SUCCESS);

--- 9 unchanged lines hidden (view full) ---

619 }
620
621 if (argc - optind != 1) {
622 fprintf(stderr, "%s: must have one input file\n", *argv);
623 exit(EXIT_FAILURE);
624 }
625 filename = argv[optind];
626
607 perror(optarg);
608 exit(EXIT_FAILURE);
609 }
610 break;
611 case 'h':
612 printf("usage: %s [-d] [-Dname] [-ooutput] input\n",
613 *argv);
614 exit(EXIT_SUCCESS);

--- 9 unchanged lines hidden (view full) ---

624 }
625
626 if (argc - optind != 1) {
627 fprintf(stderr, "%s: must have one input file\n", *argv);
628 exit(EXIT_FAILURE);
629 }
630 filename = argv[optind];
631
627 ifp = fopen(filename, "r");
628 if (!ifp) {
632
633 if ((ifile = open(filename, O_RDONLY)) < 0) {
629 perror(filename);
630 exit(EXIT_FAILURE);
631 }
632
634 perror(filename);
635 exit(EXIT_FAILURE);
636 }
637
633 if (!ofp) {
634 ofp = fopen(ADOTOUT, "w");
635 if (!ofp) {
638 if (!ofile) {
639 if ((ofile = fopen(ADOTOUT, "w")) < 0) {
636 perror(ADOTOUT);
637 exit(EXIT_FAILURE);
638 }
639 }
640
640 perror(ADOTOUT);
641 exit(EXIT_FAILURE);
642 }
643 }
644
641 assemble();
642 exit(EXIT_SUCCESS);
645 if (pipe(fd) < 0) {
646 perror("pipe failed");
647 exit(1);
648 }
649
650 if ((pid = fork()) < 0 ) {
651 perror("fork failed");
652 exit(1);
653 }
654 else if (pid > 0) { /* Parent */
655 close(fd[1]); /* Close write end */
656 if (fd[0] != STDIN_FILENO) {
657 if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO) {
658 perror("dup2 error on stdin");
659 exit(EXIT_FAILURE);
660 }
661 close(fd[0]);
662 }
663 assemble(ofile);
664 exit(EXIT_SUCCESS);
665 }
666 else { /* Child */
667 close(fd[0]); /* Close Read end */
668 if (fd[1] != STDOUT_FILENO) {
669 if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
670 perror("dup2 error on stdout");
671 exit(EXIT_FAILURE);
672 }
673 close(fd[1]);
674 }
675 if (ifile != STDIN_FILENO) {
676 if (dup2(ifile, STDIN_FILENO) != STDIN_FILENO) {
677 perror("dup2 error on stdin");
678 exit(EXIT_FAILURE);
679 }
680 close(ifile);
681 }
682 execl("/usr/bin/cpp", "/usr/bin/cpp", "-P", "-", "-");
683 }
684 return(EXIT_SUCCESS);
643}
685}