BSD 4_3_Net_2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Wed, 1 Mar 1989 07:48:48 +0000 (23:48 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Wed, 1 Mar 1989 07:48:48 +0000 (23:48 -0800)
Work on file usr/src/usr.bin/gas/xrealloc.c
Work on file usr/src/usr.bin/gas/xmalloc.c
Work on file usr/src/usr.bin/gas/config/vax-inst.h
Work on file usr/src/usr.bin/gas/symbols.h
Work on file usr/src/usr.bin/gas/subsegs.h
Work on file usr/src/usr.bin/gas/grot/strstr.c

Synthesized-from: CSRG/cd2/net.2

usr/src/usr.bin/gas/config/vax-inst.h [new file with mode: 0644]
usr/src/usr.bin/gas/grot/strstr.c [new file with mode: 0644]
usr/src/usr.bin/gas/subsegs.h [new file with mode: 0644]
usr/src/usr.bin/gas/symbols.h [new file with mode: 0644]
usr/src/usr.bin/gas/xmalloc.c [new file with mode: 0644]
usr/src/usr.bin/gas/xrealloc.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/gas/config/vax-inst.h b/usr/src/usr.bin/gas/config/vax-inst.h
new file mode 100644 (file)
index 0000000..4a89470
--- /dev/null
@@ -0,0 +1,77 @@
+/* vax-inst.h - GNU - Part of vax.c
+   Copyright (C) 1987 Free Software Foundation, Inc.
+
+This file is part of GAS, the GNU Assembler.
+
+GAS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 1, or (at your option)
+any later version.
+
+GAS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GAS; see the file COPYING.  If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+/*
+ * This is part of vax-ins-parse.c & friends.
+ * We want to parse a vax instruction text into a tree defined here.
+ */
+
+#define VIT_MAX_OPERANDS (6)   /* maximum number of operands in one       */
+                               /* single vax instruction                  */
+
+struct vop                     /* vax instruction operand                 */
+{
+  short int    vop_ndx;        /* -1, or index register. eg 7=[R7]        */
+  short int    vop_reg;        /* -1, or register number. eg @I^#=0xF     */
+                               /* Helps distinguish "abs" from "abs(PC)". */
+  short int    vop_mode;       /* addressing mode 4 bits. eg I^#=0x9      */
+  char         vop_short;      /* operand displacement length as written  */
+                               /* ' '=none, "bilsw"=B^I^L^S^W^.           */
+  char         vop_access;     /* 'b'branch ' 'no-instruction 'amrvw'norm */
+  char         vop_width;      /* Operand width, one of "bdfghloqw"       */
+  char *       vop_warn;       /* warning message of this operand, if any */
+  char *        vop_error;     /* say if operand is inappropriate         */
+  char *       vop_expr_begin; /* Unparsed expression, 1st char ...       */
+  char *       vop_expr_end;   /* ... last char.                          */
+  unsigned char        vop_nbytes;     /* number of bytes in datum                */
+};
+
+
+typedef long int vax_opcodeT;  /* For initialising array of opcodes       */
+                               /* Some synthetic opcodes > 16 bits!       */
+
+#define VIT_OPCODE_SYNTHETIC 0x80000000        /* Not real hardware instruction.  */
+#define VIT_OPCODE_SPECIAL   0x40000000        /* Not normal branch optimising.   */
+                                       /* Never set without ..._SYNTHETIC */
+
+#define VAX_WIDTH_UNCONDITIONAL_JUMP '-' /* These are encoded into         */
+#define VAX_WIDTH_CONDITIONAL_JUMP   '?' /* vop_width when vop_access=='b' */
+#define VAX_WIDTH_WORD_JUMP          '!' /* and VIT_OPCODE_SYNTHETIC set.  */
+#define VAX_WIDTH_BYTE_JUMP         ':' /*                                */
+
+#define VAX_JMP (0x17)         /* Useful for branch optimising. Jump instr*/
+#define VAX_PC_RELATIVE_MODE (0xef) /* Use it after VAX_JMP               */
+#define VAX_ABSOLUTE_MODE (0x9F) /* Use as @#...                          */
+#define VAX_BRB (0x11)         /* Canonical branch.                       */
+#define VAX_BRW (0x31)         /* Another canonical branch                */
+#define VAX_WIDEN_WORD (0x20)  /* Add this to byte branch to get word br. */
+#define VAX_WIDEN_LONG (0x6)   /* Add this to byte branch to get long jmp.*/
+                               /* Needs VAX_PC_RELATIVE_MODE byte after it*/
+
+struct vit                     /* vax instruction tree                    */
+{
+                               /* vit_opcode is char[] for portability.   */
+  char            vit_opcode [ sizeof (vax_opcodeT) ];
+  unsigned char    vit_opcode_nbytes; /* How long is _opcode? (chars)     */
+  unsigned char    vit_operands;/*                                        */
+  struct vop       vit_operand[VIT_MAX_OPERANDS];  /* operands             */
+  char *          vit_error;   /* "" or error text */
+};
+
+/* end: vax-inst.h */
diff --git a/usr/src/usr.bin/gas/grot/strstr.c b/usr/src/usr.bin/gas/grot/strstr.c
new file mode 100644 (file)
index 0000000..3da79a8
--- /dev/null
@@ -0,0 +1,49 @@
+/* strstr - find first occurrence of wanted in s
+   Copyright (C) 1989, Free Software Foundation.
+
+This file is part of GAS, the GNU Assembler.
+
+GAS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 1, or (at your option)
+any later version.
+
+GAS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GAS; see the file COPYING.  If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   
+
+
+#define CONST
+#define SIZET int
+
+#define        NULL    0
+
+char *                         /* found string, or NULL if none */
+strstr(s, wanted)
+CONST char *s;
+CONST char *wanted;
+{
+       register CONST char *scan;
+       register SIZET len;
+       register char firstc;
+       extern int strcmp();
+       extern SIZET strlen();
+
+       /*
+        * The odd placement of the two tests is so "" is findable.
+        * Also, we inline the first char for speed.
+        * The ++ on scan has been moved down for optimization.
+        */
+       firstc = *wanted;
+       len = strlen(wanted);
+       for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
+               if (*scan++ == '\0')
+                       return(NULL);
+       return(scan);
+}
diff --git a/usr/src/usr.bin/gas/subsegs.h b/usr/src/usr.bin/gas/subsegs.h
new file mode 100644 (file)
index 0000000..b8dbaf7
--- /dev/null
@@ -0,0 +1,65 @@
+/* subsegs.h -> subsegs.c
+   Copyright (C) 1987 Free Software Foundation, Inc.
+
+This file is part of GAS, the GNU Assembler.
+
+GAS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 1, or (at your option)
+any later version.
+
+GAS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GAS; see the file COPYING.  If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+/*
+ * For every sub-segment the user mentions in the ASsembler program,
+ * we make one struct frchain. Each sub-segment has exactly one struct frchain
+ * and vice versa.
+ *
+ * Struct frchain's are forward chained (in ascending order of sub-segment
+ * code number). The chain runs through frch_next of each subsegment.
+ * This makes it hard to find a subsegment's frags
+ * if programmer uses a lot of them. Most programs only use text0 and
+ * data0, so they don't suffer. At least this way:
+ * (1) There are no "arbitrary" restrictions on how many subsegments
+ *     can be programmed;
+ * (2) Subsegments' frchain-s are (later) chained together in the order in
+ *     which they are emitted for object file viz text then data.
+ *
+ * From each struct frchain dangles a chain of struct frags. The frags
+ * represent code fragments, for that sub-segment, forward chained.
+ */
+
+struct frchain                 /* control building of a frag chain */
+{                              /* FRCH = FRagment CHain control */
+  struct frag *        frch_root;      /* 1st struct frag in chain, or NULL */
+  struct frag *        frch_last;      /* last struct frag in chain, or NULL */
+  struct frchain * frch_next;  /* next in chain of struct frchain-s */
+  segT         frch_seg;       /* SEG_TEXT or SEG_DATA. */
+  subsegT      frch_subseg;    /* subsegment number of this chain */
+};
+
+typedef struct frchain frchainS;
+
+extern frchainS * frchain_root;        /* NULL means no frchains yet. */
+                               /* all subsegments' chains hang off here */
+
+extern frchainS * frchain_now;
+                               /* Frchain we are assembling into now */
+                               /* That is, the current segment's frag */
+                               /* chain, even if it contains no (complete) */
+                               /* frags. */
+
+extern frchainS * data0_frchainP;
+                               /* Sentinel for frchain crawling. */
+                               /* Points to the 1st data-segment frchain. */
+                               /* (Which is pointed to by the last text- */
+                               /* segment frchain.) */
+
+/* end: subsegs.h */
diff --git a/usr/src/usr.bin/gas/symbols.h b/usr/src/usr.bin/gas/symbols.h
new file mode 100644 (file)
index 0000000..5a52790
--- /dev/null
@@ -0,0 +1,42 @@
+/* symbols.h -
+   Copyright (C) 1987 Free Software Foundation, Inc.
+
+This file is part of GAS, the GNU Assembler.
+
+GAS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 1, or (at your option)
+any later version.
+
+GAS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GAS; see the file COPYING.  If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+extern struct obstack  notes; /* eg FixS live here. */
+
+#define symbol_table_lookup(name) ((symbolS *)(symbol_find (name)))
+
+extern unsigned int local_bss_counter; /* Zeroed before a pass. */
+                               /* Only used by .lcomm directive. */
+
+
+extern symbolS * symbol_rootP; /* all the symbol nodes */
+extern symbolS * symbol_lastP; /* last struct symbol we made, or NULL */
+
+extern symbolS abs_symbol;
+
+symbolS *      symbol_find();
+void           symbol_begin();
+char *         local_label_name();
+void           local_colon();
+symbolS *      symbol_new();
+void           colon();
+void           symbol_table_insert();
+symbolS *      symbol_find_or_make();
+
+/* end: symbols.h */
diff --git a/usr/src/usr.bin/gas/xmalloc.c b/usr/src/usr.bin/gas/xmalloc.c
new file mode 100644 (file)
index 0000000..78c8c7f
--- /dev/null
@@ -0,0 +1,60 @@
+/* xmalloc.c - get memory or bust
+   Copyright (C) 1987 Free Software Foundation, Inc.
+
+This file is part of GAS, the GNU Assembler.
+
+GAS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 1, or (at your option)
+any later version.
+
+GAS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GAS; see the file COPYING.  If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+/*
+NAME
+       xmalloc() - get memory or bust
+INDEX
+       xmalloc() uses malloc()
+
+SYNOPSIS
+       char *  my_memory;
+
+       my_memory = xmalloc(42); / * my_memory gets address of 42 chars * /
+
+DESCRIPTION
+
+       Use xmalloc() as an "error-free" malloc(). It does almost the same job.
+       When it cannot honour your request for memory it BOMBS your program
+       with a "virtual memory exceeded" message. Malloc() returns NULL and
+       does not bomb your program.
+
+SEE ALSO
+       malloc()
+
+*/
+#ifdef USG
+#include <malloc.h>
+#endif
+
+char * xmalloc(n)
+     long n;
+{
+  char *       retval;
+  char *       malloc();
+  void error();
+
+  if ( ! (retval = malloc ((unsigned)n)) )
+    {
+      error("virtual memory exceeded");
+    }
+  return (retval);
+}
+
+/* end: xmalloc.c */
diff --git a/usr/src/usr.bin/gas/xrealloc.c b/usr/src/usr.bin/gas/xrealloc.c
new file mode 100644 (file)
index 0000000..a5010bc
--- /dev/null
@@ -0,0 +1,61 @@
+/* xrealloc.c -new memory or bust-
+   Copyright (C) 1987 Free Software Foundation, Inc.
+
+This file is part of GAS, the GNU Assembler.
+
+GAS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 1, or (at your option)
+any later version.
+
+GAS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GAS; see the file COPYING.  If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+
+/* 
+
+NAME
+       xrealloc () - get more memory or bust
+INDEX
+       xrealloc () uses realloc ()
+SYNOPSIS
+       char   *my_memory;
+
+       my_memory = xrealloc (my_memory, 42);
+       / * my_memory gets (perhaps new) address of 42 chars * /
+
+DESCRIPTION
+
+       Use xrealloc () as an "error-free" realloc ().It does almost the same
+       job.  When it cannot honour your request for memory it BOMBS your
+       program with a "virtual memory exceeded" message.  Realloc() returns
+       NULL and does not bomb your program.
+
+SEE ALSO
+       realloc ()
+*/
+
+#ifdef USG
+#include <malloc.h>
+#endif
+
+char   *
+xrealloc (ptr, n)
+register char  *ptr;
+long    n;
+{
+    char   *realloc ();
+    void       error();
+
+    if ((ptr = realloc (ptr, (unsigned)n)) == 0)
+       error ("virtual memory exceeded");
+    return (ptr);
+}
+
+/* end: xrealloc.c */