Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!inria!litp!pda From: pda@litp.ibp.fr (Pierre DAVID) Newsgroups: comp.sys.handhelds Subject: Saturn Assembler (Part 1/8) Message-ID: <3302@litp.ibp.fr> Date: 5 Jul 90 16:20:49 GMT Reply-To: pda@litp.ibp.fr.UUCP (Pierre DAVID) Organization: M.A.S.I., Universite P. & M. Curie, Paris, FRANCE Lines: 2422 #---------------------------------- cut here ---------------------------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Pierre David on Sun Jul 1 12:32:48 1990 # # This archive contains: # areuh areuh/cpy # areuh/linker areuh/dump # areuh/doc areuh/equ # areuh/load areuh/msg # areuh/jmpdoc areuh/assembler # areuh/cpy/a2lex.c areuh/cpy/a2rs.c # areuh/cpy/copy.h areuh/linker/mdep.c # areuh/linker/exp.c areuh/linker/err.h # areuh/linker/common.h areuh/linker/lutil.c # areuh/linker/lpass.c areuh/linker/lmain.c # # Error checking via wc(1) will be performed. LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH echo mkdir - areuh mkdir areuh chmod 755 areuh echo mkdir - areuh/cpy mkdir areuh/cpy chmod 755 areuh/cpy echo mkdir - areuh/linker mkdir areuh/linker chmod 755 areuh/linker echo mkdir - areuh/dump mkdir areuh/dump chmod 755 areuh/dump echo mkdir - areuh/doc mkdir areuh/doc chmod 755 areuh/doc echo mkdir - areuh/equ mkdir areuh/equ chmod 755 areuh/equ echo mkdir - areuh/load mkdir areuh/load chmod 755 areuh/load echo mkdir - areuh/msg mkdir areuh/msg chmod 755 areuh/msg echo mkdir - areuh/jmpdoc mkdir areuh/jmpdoc chmod 755 areuh/jmpdoc echo mkdir - areuh/assembler mkdir areuh/assembler chmod 755 areuh/assembler echo x - areuh/cpy/a2lex.c cat >areuh/cpy/a2lex.c <<'@EOF' /* * Authors : * Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet) * Janick TAILLANDIER * * This program can be freely used or distributed as long as this * note is kept. * * This program is provided "as is". */ #include "copy.h" char outname [100] ; FILE *fpdev ; init () { #ifdef unix fpdev = stdout ; #else sprintf (outname, "%s.lex", file) ; if ((fpdev = fopen (outname, "wb")) == NULL) error (ERROPN, outname) ; #endif } output (c) uchar c ; { putc ((int) c, fpdev) ; if (ferror (fpdev)) error (ERRWRT, outname) ; } term () { if (fclose (fpdev)) error (ERRCLO, outname) ; } @EOF set `wc -lwc areuh/cpy/a2rs.c <<'@EOF' /* * Authors : * Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet) * Janick TAILLANDIER * * This program can be freely used or distributed as long as this * note is kept. * * This program is provided "as is". */ #include "copy.h" #include union REGS inregs, outregs ; init () { inregs.h.ah = 0 ; inregs.h.al = 0xe3 ; inregs.x.dx = 0 ; /* com1 */ int86 (0x14, &inregs, &outregs) ; } output (c) char c ; { int ok ; ok = 0 ; while (!ok) { inregs.h.ah = 0x03 ; /* get line status */ inregs.x.dx = 0x0000 ; int86 (0x14, &inregs, &outregs) ; ok = (outregs.h.al & 0x30) == 0x30 ; /* handshake lines */ } inregs.h.ah = 1 ; /* send char */ inregs.h.al = c ; inregs.x.dx = 0 ; int86 (0x14, &inregs, &outregs) ; } term () { } @EOF set `wc -lwc areuh/cpy/copy.h <<'@EOF' /* * Authors : * Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet) * Janick TAILLANDIER * * This program can be freely used or distributed as long as this * note is kept. * * This program is provided "as is". */ #include long int con () ; typedef unsigned char uchar ; typedef unsigned long int int32 ; typedef unsigned short int int16 ; #define ERRUSA 1 /* usage */ #define ERROPN 2 /* cannot open */ #define ERRNAL 3 /* not a Lex */ #define ERRCLO 4 /* cannot close */ #define ERRRD 5 /* error reading */ #define ERRWRT 6 /* error writing */ #define ERRLEN 7 /* bad REL(5) FiLeNd field */ #define ERRINT 8 /* interface error */ uchar *file ; uchar name [10] ; FILE *fp ; int16 ftype ; int32 lnib, lbyte, lsect ; uchar *pgm ; /* name of current program */ main (argc, argv) int argc ; char *argv[] ; { long int magic ; int32 l ; uchar tab [4] ; int i, j, m ; int mod ; pgm = (uchar *) argv [0] ; /* program name */ switch (argc) { case 1 : file = (uchar *) "lex" ; /* default name */ break ; case 2 : file = (uchar *) argv [1] ; break ; default : error (ERRUSA, "") ; break ; } fp = fopen (file, "rb") ; /* binary file for MS-DOS machines */ if (fp == NULL) error (ERROPN, file) ; /* get Lex file header */ fread ((char *) &magic, sizeof (long int), 1 , fp) ; if (magic!=0x1b080100) error (ERRNAL, file) ; /* not a Lex file */ for (i=0; i<8; i++) name [i] = (uchar) con (2) ; name [8] = name [9] = ' ' ; ftype = (int32) con (4) ; /* file type */ skip (12) ; /* skip date and time */ lnib = (int32)con (5) - (int32)5 ; /* get length */ lsect = (lnib + 511) / 512 ; if (ferror (fp)) /* read error */ error (ERRRD, file) ; /* initialize output channel */ init () ; /* header output */ for (i=0; i<10; i++) /* file name */ output ((uchar) name [i]) ; output ((uchar) (ftype / 256)) ; /* file type */ output ((uchar) (ftype % 256)) ; for (i=1; i<=4; i++) /* start sector */ output ((uchar) 0) ; l = lsect ; for (i=3; i>=0; i--) /* length in sectors */ { tab [i] = (uchar) l & 0xff ; l >>= 8 ; } for (i=0; i<4; i++) output (tab [i]) ; for (i=0; i<6; i++) /* date and time */ output ((uchar) 0) ; output ((uchar) 0x80) ; /* 80 */ output ((uchar) 0x01) ; /* 01 */ l = lnib ; for (i=0; i<4; i++) /* length in nibbles */ { output ((uchar) (l & (int32) 0xff)) ; l >>= 8 ; } /* data output */ lbyte = (lnib+1) >> 1 ; mod = lbyte % 256 ; for (i=1; i<=lsect; i++) { m = (i == lsect && mod != 0) ? min (256, mod) : 256 ; for (j=0; j=0; i--) res = (res << 4) | hex (buf [i]) ; return res ; } skip (n) int n ; { uchar buf [1024] ; fread (buf, n, 1, fp) ; if (ferror (fp)) error (ERRRD, file) ; if (feof (fp)) error (ERRLEN, "") ; } int min (a, b) int a, b ; { return a <= b ? a : b ; } int hex (c) uchar c ; { return (c >= 'A' && c <= 'F') ? c - 'A' + 10 : c - '0' ; } error (code, str) int code ; uchar *str ; { switch (code) { case ERRUSA : /* usage */ fprintf (stderr, "usage: %s [file]\n", pgm) ; break ; case ERROPN : /* cannot open */ fprintf (stderr, "%s: cannot open %s\n", pgm, str) ; break ; case ERRNAL : /* not a Lex */ fprintf (stderr, "%s: %s is not a lex file\n", pgm, str) ; break ; case ERRCLO : /* cannot close */ fprintf (stderr, "%s: cannot close %s\n", pgm, str) ; break ; case ERRRD : /* error reading */ fprintf (stderr, "%s: error reading %s\n", pgm, str) ; break ; case ERRWRT : /* error writing */ fprintf (stderr, "%s: error writing %s\n", pgm, str) ; break ; case ERRLEN : /* bad REL(5) FiLeNd field */ fprintf (stderr, "%s: bad REL(5) FiLeNd field\n", pgm) ; break ; case ERRINT : /* interface error */ fprintf (stderr, "%s: interface error\n", pgm) ; break ; default : fprintf (stderr, "%s: internal error\n", pgm) ; break ; } exit (1) ; } @EOF set `wc -lwc areuh/linker/mdep.c <<'@EOF' /* * Authors : * Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet) * Janick TAILLANDIER * * This program can be freely used or distributed as long as this * note is kept. * * This program is provided "as is". */ /****************************************************************************** M A C H I N E D E P E N D E N C I E S ******************************************************************************/ #include "flag.h" #if ASSEMBLER #include "aglobal.h" #else #include "lglobal.h" #endif extern struct symbol *add_label() ; #if HPUX void format_time (str) uchar *str ; { long int l ; extern long int time () ; extern char *ctime () ; l = time (0L) ; strcpy (str, ctime (&l)) ; str [strlen (str) - 1] = EOL ; } char *tab[] = { "", "/usr/lib/", "/usr/local/lib/", "/lib/", "/hp71/lib/", "/local/lib/", 0 } ; void load_file (file) uchar *file ; { int i = 0 ; uchar name [MAXLEN+1] ; saddr val ; FILE *fp ; fp = (FILE *) NULL ; while ((tab[i])&&(!fp)) { sprintf (name, "%s%s", tab[i++], file) ; fp = fopen (name, "r") ; } if (!fp) error (ERROPN, file) ; #if LINKER file = 0 ; #endif while (fscanf (fp, "%s\n%X\n", name, &val) != EOF) { #if ASSEMBLER add_label (name, val, "", LABS, 1) ; #else add_label (name, val, 1) ; #endif } if (ferror (fp)) error (ERRWRT, file) ; if (fclose (fp)) error (ERRCLO, file) ; } #include #include /* look for object file (object code or listing file) * if non existent, ok * if exists and not directory, ok * if exists and directory, then append "/" */ look_obj (fname, dfl) uchar *fname, *dfl ; { struct stat buf ; if (*fname == EOL) /* if fname == "" then default it */ strcpy (fname, dfl) ; if (!stat (fname, &buf)) /* file exists. Is it a directory ? */ { if ((buf.st_mode & S_IFMT) == S_IFDIR) sprintf (fname, "%s/%s", fname, dfl) ; } } /* build a default file name, based on "source" basename and a given * default extension. */ dfl_extension (object, source, extension) uchar *object, *source, *extension ; { uchar *pname ; strcpy (object, source) ; pname = object ; while ((*pname)&&(*pname!='.')) pname++ ; if (*pname==EOL) *pname = '.' ; strcpy (pname+1, extension) ; } #endif /* HPUX */ #if ATARI_LATTICE char skipvar ; void format_time (str) uchar *str ; { strcpy (str, "Areuh Tagada Bouzouh bouzouh areuh areuh... et toc !") ; } char *optarg ; int optind = 0, opterr = 0 ; int getopt (argc, argv, optstr) int argc ; char *argv[], *optstr ; { char *o, car ; static char *index = 0 ; extern char *strchr () ; if ((index==(char *)0)||(*(index+1)==0)) { if (++optind>argc-1) return (EOF) ; index = argv[optind] ; if (*index!='-') return (EOF) ; } car = *(++index) ; /* state 6 */ if (!(o = strchr (optstr, car))) return ('?') ; if (*(o+1)!=':') return ((int) car) ; if (*(index+1)) optarg = index+1 ; else { if (++optind>argc-1) return (EOF) ; else optarg = argv[optind] ; } index = (char *) 0 ; return ((int) car) ; } uchar *tab[] = { "", "A:", "A:\\TABLE\\", 0 } ; void load_file (file) uchar *file ; { int i = 0 ; uchar name [MAXLEN+1] ; saddr val ; FILE *fp ; fp = (FILE *) NULL ; while ((tab[i])&&(!fp)) { sprintf (name, "%s%s", tab[i++], file) ; fp = fopen (name, "r") ; } if (!fp) error (ERROPN, file) ; #if LINKER file = 0 ; #endif while (fscanf (fp, "%s\n%x\n", name, &val) != EOF) { #if ASSEMBLER add_label (name, val, "", LABS, 1) ; #else add_label (name, val, 1) ; #endif } if (fclose (fp)) error (ERRCLO, file) ; } #endif /* ATARI_LATTICE */ #if PC_MSC char skipvar ; void format_time (str) uchar *str ; { long int l ; extern long int time () ; extern char *ctime () ; time (&l) ; strcpy (str, ctime (&l)) ; str [strlen (str) - 1] = EOL ; } char *optarg ; int optind = 0, opterr = 0 ; int getopt (argc, argv, optstr) int argc ; char *argv[], *optstr ; { char *o, car ; static char *index = 0 ; extern char *strchr () ; if ((index==(char *)0)||(*(index+1)==0)) { if (++optind>argc-1) return (EOF) ; index = argv[optind] ; if (*index!='-') return (EOF) ; } car = *(++index) ; /* state 6 */ if (!(o = strchr (optstr, car))) return ('?') ; if (*(o+1)!=':') return ((int) car) ; if (*(index+1)) optarg = index+1 ; else { if (++optind>argc-1) return (EOF) ; else optarg = argv[optind] ; } index = (char *) 0 ; return ((int) car) ; } uchar *tab[] = { "", "c:", "c:\\hp71\\", "c:\\lib\\hp71\\", "c:\\lib\\", "c:\\areuh\\lib\\", 0 } ; void load_file (file) uchar *file ; { int i = 0 ; uchar name [MAXLEN+1] ; saddr val ; FILE *fp ; fp = (FILE *) NULL ; while ((tab[i])&&(!fp)) { sprintf (name, "%s%s", tab[i++], file) ; fp = fopen (name, "r") ; } if (!fp) error (ERROPN, file) ; #if LINKER file = 0 ; #endif while (fscanf (fp, "%s\n%X\n", name, &val) != EOF) { #if ASSEMBLER add_label (name, val, "", LABS, 1) ; #else add_label (name, val, 1) ; #endif } if (fclose (fp)) error (ERRCLO, file) ; } #include #include /* look for object file (object code or listing file) * if non existent, ok * if exists and not directory, ok * if exists and directory, then append "/" */ look_obj (fname, dfl) uchar *fname, *dfl ; { struct stat buf ; if (*fname == EOL) /* if fname == "" then default it */ strcpy (fname, dfl) ; if (!stat (fname, &buf)) /* file exists. Is it a directory ? */ { if ((buf.st_mode & S_IFMT) == S_IFDIR) sprintf (fname, "%s\\%s", fname, dfl) ; } } /* build a default file name, based on "source" basename and a given * default extension. */ dfl_extension (object, source, extension) uchar *object, *source, *extension ; { uchar *pname ; strcpy (object, source) ; pname = object ; while ((*pname)&&(*pname!='.')) pname++ ; if (*pname==EOL) *pname = '.' ; strcpy (pname+1, extension) ; } #endif /* PC_MSC */ @EOF set `wc -lwc areuh/linker/exp.c <<'@EOF' /* * Authors : * Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet) * Janick TAILLANDIER * * This program can be freely used or distributed as long as this * note is kept. * * This program is provided "as is". */ /****************************************************************************** TITAN ASSEMBLER EXPRESSION EVALUATION calc_expression, reduce_E, reduce_T, reduce_F, reduce_B, reduce_X, reduce_P, dec_value, hex_value, bin_value, ascii_value, label_value, apply, trunc, next_char, append_extexp ******************************************************************************/ #include "flag.h" #if ASSEMBLER #include "aglobal.h" #else #include "lglobal.h" #endif uchar extexp [4*MAXLEN] ; uchar *pexp, *pextexp ; uchar *xlabel ; int relabs ; extern saddr symbol_value() ; saddr reduce_E(), reduce_T(), reduce_F(), reduce_B(), reduce_X(), reduce_P(), dec_value(), hex_value(), bin_value(), ascii_value(), label_value(), apply(), trunc() ; void next_char(), append_extexp() ; /****************************************************************************** CALC_EXPRESSION synopsis : saddr calc_expression (exp) uchar *exp description : That's the expression evaluator. Productions used are : E -> T { {+|-} T }* T -> F { {*|/} F }* F -> B { {&|!} B }* B -> X | -X | `X (two's and one's complement) X -> N { {~|^} N }* P -> D | # | % | '' | \\ |