From e9398c13fd09fb7eddfcd7d4c414cfc59bb13de6 Mon Sep 17 00:00:00 2001 From: Ludovic Jacomme Date: Sun, 23 May 2004 13:57:39 +0000 Subject: [PATCH] - Add the MIPS assembler written by Pirouz B. in the Alliance CVS tree --- alliance/src/mips_asm/Makefile.am | 1 + alliance/src/mips_asm/configure.in | 40 + alliance/src/mips_asm/src/Makefile.am | 23 + alliance/src/mips_asm/src/mips_defs.h | 169 ++ alliance/src/mips_asm/src/mips_globals.c | 32 + alliance/src/mips_asm/src/mips_l.l | 571 +++++++ alliance/src/mips_asm/src/mips_lex.h | 41 + alliance/src/mips_asm/src/mips_type.h | 37 + alliance/src/mips_asm/src/mips_util.c | 124 ++ alliance/src/mips_asm/src/mips_y.y | 1847 ++++++++++++++++++++++ alliance/src/mips_asm/src/mips_yacc.h | 67 + 11 files changed, 2952 insertions(+) create mode 100644 alliance/src/mips_asm/Makefile.am create mode 100644 alliance/src/mips_asm/configure.in create mode 100644 alliance/src/mips_asm/src/Makefile.am create mode 100644 alliance/src/mips_asm/src/mips_defs.h create mode 100644 alliance/src/mips_asm/src/mips_globals.c create mode 100644 alliance/src/mips_asm/src/mips_l.l create mode 100644 alliance/src/mips_asm/src/mips_lex.h create mode 100644 alliance/src/mips_asm/src/mips_type.h create mode 100644 alliance/src/mips_asm/src/mips_util.c create mode 100644 alliance/src/mips_asm/src/mips_y.y create mode 100644 alliance/src/mips_asm/src/mips_yacc.h diff --git a/alliance/src/mips_asm/Makefile.am b/alliance/src/mips_asm/Makefile.am new file mode 100644 index 00000000..af437a64 --- /dev/null +++ b/alliance/src/mips_asm/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/alliance/src/mips_asm/configure.in b/alliance/src/mips_asm/configure.in new file mode 100644 index 00000000..39cf51ac --- /dev/null +++ b/alliance/src/mips_asm/configure.in @@ -0,0 +1,40 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(src/mips_globals.c) + +MIPS_ASM_MAJOR_VERSION=1 +MIPS_ASM_MINOR_VERSION=0 +MIPS_ASM_VERSION=$MIPS_ASM_MAJOR_VERSION.$MIPS_ASM_MINOR_VERSION + +AC_SUBST(MIPS_ASM_MAJOR_VERSION) +AC_SUBST(MIPS_ASM_MINOR_VERSION) +AC_SUBST(MIPS_ASM_VERSION) + +# For automake. +VERSION=$MIPS_ASM_VERSION +PACKAGE=mips_asm + +dnl Initialize automake stuff +AM_INIT_AUTOMAKE($PACKAGE, $VERSION) + +dnl Checks for programs. +AC_PROG_CXX +AC_PROG_CC +AC_PROG_RANLIB +ALC_CXX_PROBLEMATIC_OLD_VERSION +AM_PROG_LEX +AC_PROG_YACC +AC_PROG_MAKE_SET + +dnl Checks for libraries. +dnl Check for -lm librarie. These should always be present. +AC_CHECK_LIB(m, exp) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +AM_ALLIANCE + +AC_OUTPUT([ +Makefile +src/Makefile +]) diff --git a/alliance/src/mips_asm/src/Makefile.am b/alliance/src/mips_asm/src/Makefile.am new file mode 100644 index 00000000..12630e19 --- /dev/null +++ b/alliance/src/mips_asm/src/Makefile.am @@ -0,0 +1,23 @@ +## Process this file with automake to produce Makefile.in + +YACC = @YACC@ -d + +INCLUDES = -I$(top_srcdir)/src + +AM_CXXFLAGS = @ALLIANCE_CFLAGS@ +AM_CFLAGS = @ALLIANCE_CFLAGS@ + +bin_PROGRAMS = mips_asm + +mips_asm_LDADD = @ALLIANCE_LIBS@ \ + -lBeh -lMut + +mips_asm_SOURCES = mips_defs.h mips_y.y mips_l.l mips_globals.c mips_lex.h mips_type.h mips_yacc.h mips_util.c + +mips_y.c mips_y.h : $(srcdir)/mips_y.y + $(YACC) -d $(YFLAGS) $(srcdir)/mips_y.y && sed -e "s/yy/mipsyy/g" -e "s/YY/mipsYY/g" y.tab.c > mips_y.c && sed -e "s/yy/mipsyy/g" -e "s/YY/mipsYY/g" y.tab.h > mips_y.h + +mips_l.c : $(srcdir)/mips_l.l mips_y.h + $(LEX) -t $(srcdir)/mips_l.l | sed -e "s/yy/mipsyy/g" -e "s/YY/mipsYY/g" > mips_l.c + +CLEANFILES = y.tab.c y.tab.h mips.c diff --git a/alliance/src/mips_asm/src/mips_defs.h b/alliance/src/mips_asm/src/mips_defs.h new file mode 100644 index 00000000..5ffc07a7 --- /dev/null +++ b/alliance/src/mips_asm/src/mips_defs.h @@ -0,0 +1,169 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* ###--------------------------------------------------------------### */ +/* file : mips_defs.h */ +/* date : Dec 6 1999 */ +/* version : v0.3 */ +/* author : Pirouz BAZARGAN SABET */ +/* description : MIPS assembler - defines (operation codes) */ +/* ###--------------------------------------------------------------### */ + +#define MPS_PLSDFN 0 /* add */ +#define MPS_MNSDFN 1 /* subtract */ +#define MPS_SHLDFN 2 /* shift left */ +#define MPS_SHRDFN 3 /* shift right */ +#define MPS_ORDFN 4 /* logical or */ +#define MPS_ANDDFN 5 /* logical and */ +#define MPS_XORDFN 6 /* logical exclusive or */ +#define MPS_MULDFN 7 /* multiply */ +#define MPS_DIVDFN 8 /* divide */ + + /* ### ---------------------------------------------------- ### */ + /* instruction set table: */ + /* Opcods in lower case are MIPS instructions */ + /* Opcods in upper case are application specific */ + /* */ + /* */ + /* primary opcod (31 downto 26): */ + /* | 0 1 2 3 4 5 6 7 */ + /* --+-----+-----+-----+-----+-----+-----+-----+-----+ */ + /* 0 |speci|bcond| j | jal | beq | bne |blez |bgtz | */ + /* 1 |addi |addui|slti |sltui|andi | ori |xori | lui | */ + /* 2 |cop0 | + | + | + | | + | | | */ + /* 3 | | | | | | | | | */ + /* 4 | lb | lh | + | lw | lbu | lhu | + |SWAP | */ + /* 5 | sb | sh | + | sw | | | + | | */ + /* 6 | + | + | + | + |Seqi |Snei |Slei |Sgti | */ + /* 7 | + | + | + | + |Sgei |Sgeui|Sleui|Sgtui| */ + /* */ + /* */ + /* special opcod extension (5 downto 0): */ + /* | 0 1 2 3 4 5 6 7 */ + /* --+-----+-----+-----+-----+-----+-----+-----+-----+ */ + /* 0 | sll | | srl | sra |sllv | |srlv |srav | */ + /* 1 | jr |jalr | | |sysca|break| |SLEEP| */ + /* 2 |mfhi |mthi |mflo |mtlo | | | | | */ + /* 3 | + | + | + | + | | | | | */ + /* 4 | add |addu | sub |subu | and | or | xor | nor | */ + /* 5 | | | slt |sltu | | | | | */ + /* 6 | | | | | + | + | + | + | */ + /* 7 | | | | | + | + | + | + | */ + /* */ + /* */ + /* bcond opcod extension (20 downto 16): */ + /* | 0 1 2 3 4 5 6 7 */ + /* --+-----+-----+-----+-----+-----+-----+-----+-----+ */ + /* 0 |bltz |bgez | | | | | | | */ + /* 1 | | | | | | | | | */ + /* 2 |bltza|bgeza| | | | | | | */ + /* 3 | | | | | | | | | */ + /* */ + /* */ + /* cop0 opcod extension (22, 21, 16, 25, 24, 23): */ + /* | 0 1 2 3 4 5 6 7 */ + /* --+-----+-----+-----+-----+-----+-----+-----+-----+ */ + /* 0 | mf | mt | + | + | c0 | c0 | c0 | c0 | */ + /* 1 | mf | mt | + | + | c0 | c0 | c0 | c0 | */ + /* 2 | | | | | c0 | c0 | c0 | c0 | */ + /* 3 | | | | | c0 | c0 | c0 | c0 | */ + /* 4 | + | + | | | c0 | c0 | c0 | c0 | */ + /* 5 | + | + | | | c0 | c0 | c0 | c0 | */ + /* 6 | | | | | c0 | c0 | c0 | c0 | */ + /* 7 | | | | | c0 | c0 | c0 | c0 | */ + /* */ + /* */ + /* c0 cop0 extension extension (4 downto 0): */ + /* | 0 1 2 3 4 5 6 7 */ + /* --+-----+-----+-----+-----+-----+-----+-----+-----+ */ + /* 0 | + | + | + | | | | + | | */ + /* 1 | + | | | | | | | | */ + /* 2 |rstfe| | | | | | | | */ + /* 3 | + | | | | | | | | */ + /* */ + /* ### ---------------------------------------------------- ### */ + +#define _ADD 0x00000020 /* Mips architecture */ +#define _ADDI 0x20000000 /* Mips architecture */ +#define _ADDU 0x00000021 /* Mips architecture */ +#define _ADDIU 0x24000000 /* Mips architecture */ +#define _AND 0x00000024 /* Mips architecture */ +#define _ANDI 0x30000000 /* Mips architecture */ +#define _BEQ 0x10000000 /* Mips architecture */ +#define _BGEZ 0x04010000 /* Mips architecture */ +#define _BGEZAL 0x04110000 /* Mips architecture */ +#define _BGTZ 0x1C000000 /* Mips architecture */ +#define _BLEZ 0x18000000 /* Mips architecture */ +#define _BLTZ 0x04000000 /* Mips architecture */ +#define _BLTZAL 0x04100000 /* Mips architecture */ +#define _BNE 0x14000000 /* Mips architecture */ +#define _BREAK 0x0000000D /* Mips architecture */ +#define _J 0x08000000 /* Mips architecture */ +#define _JAL 0x0C000000 /* Mips architecture */ +#define _JALR 0x00000009 /* Mips architecture */ +#define _JR 0x00000008 /* Mips architecture */ +#define _LB 0x80000000 /* Mips architecture */ +#define _LBU 0x90000000 /* Mips architecture */ +#define _LH 0x84000000 /* Mips architecture */ +#define _LHU 0x94000000 /* Mips architecture */ +#define _LUI 0x3C000000 /* Mips architecture */ +#define _LW 0x8C000000 /* Mips architecture */ +#define _MFC0 0x40000000 /* Mips architecture */ +#define _MFHI 0x00000010 /* Mips architecture */ +#define _MFLO 0x00000012 /* Mips architecture */ +#define _MTC0 0x40800000 /* Mips architecture */ +#define _MTHI 0x00000011 /* Mips architecture */ +#define _MTLO 0x00000013 /* Mips architecture */ +#define _NOR 0x00000027 /* Mips architecture */ +#define _OR 0x00000025 /* Mips architecture */ +#define _ORI 0x34000000 /* Mips architecture */ +#define _RSTFE 0x42000010 /* Mips architecture */ +#define _SB 0xA0000000 /* Mips architecture */ +#define _SH 0xA4000000 /* Mips architecture */ +#define _SLEEP 0x0000000F /* Mips architecture */ +#define _SLL 0x00000000 /* Mips architecture */ +#define _SLLV 0x00000004 /* Mips architecture */ +#define _SLT 0x0000002A /* Mips architecture */ +#define _SLTI 0x28000000 /* Mips architecture */ +#define _SLTU 0x0000002B /* Mips architecture */ +#define _SLTIU 0x2C000000 /* Mips architecture */ +#define _SRA 0x00000003 /* Mips architecture */ +#define _SRAV 0x00000007 /* Mips architecture */ +#define _SRL 0x00000002 /* Mips architecture */ +#define _SRLV 0x00000006 /* Mips architecture */ +#define _SUB 0x00000022 /* Mips architecture */ +#define _SUBU 0x00000023 /* Mips architecture */ +#define _SW 0xAC000000 /* Mips architecture */ +#define _SWAP 0x9C000000 /* Mips architecture */ +#define _SYSCALL 0x0000000C /* Mips architecture */ +#define _XOR 0x00000026 /* Mips architecture */ +#define _XORI 0x38000000 /* Mips architecture */ + +#define _NOP 0x00000001 /* Mips macro */ +#define _LOADI 0x00000002 /* Mips macro */ + +#define _BADVADDR 8 +#define _STATUS 12 +#define _CAUSE 13 +#define _EPC 14 diff --git a/alliance/src/mips_asm/src/mips_globals.c b/alliance/src/mips_asm/src/mips_globals.c new file mode 100644 index 00000000..d806f62c --- /dev/null +++ b/alliance/src/mips_asm/src/mips_globals.c @@ -0,0 +1,32 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* ###--------------------------------------------------------------### */ +/* file : mips_globals.c */ +/* date : Dec 9 1999 */ +/* version : v0.3 */ +/* author : Pirouz BAZARGAN SABET */ +/* description : MIPS assembler - global and static variables */ +/* ###--------------------------------------------------------------### */ + +int MPS_LINNUM = 1; diff --git a/alliance/src/mips_asm/src/mips_l.l b/alliance/src/mips_asm/src/mips_l.l new file mode 100644 index 00000000..c6ad1764 --- /dev/null +++ b/alliance/src/mips_asm/src/mips_l.l @@ -0,0 +1,571 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* ###--------------------------------------------------------------### */ +/* file : mips_mips.lex */ +/* date : Dec 6 1999 */ +/* version : v0.3 */ +/* author : Pirouz BAZARGAN SABET */ +/* description : MIPS assembler - lex rules */ +/* ###--------------------------------------------------------------### */ + +%{ +#include +#include "mut.h" +#include "mips_type.h" +#include "mips_y.h" +#include "mips_defs.h" +#include "mips_lex.h" +%} + +register \$([0-9]|[12][0-9]|3[01]) +digit [0-9] +hexadecimal_valu 0x[0-9a-fA-F]+ +octal_valu 0o[0-7]+ +binary_valu 0b[0-1]+ +decimal_valu {digit}+ +letter [a-zA-Z] +letter_or_digit {letter}|{digit} +ident (\.|_|{letter})(\.|_|{letter_or_digit})* + +%% +\n { +/*printf ("CarriageReturn : %d\n", MPS_LINNUM);*/ + MPS_LINNUM++; + return (CarriageReturn); + } +\: { +/*printf ("Colon\n");*/ + return (Colon); + } +[ \t] { +/*printf ("space\n");*/ + } +# { +/*printf ("Sharp\n");*/ + return (Sharp); + } +\& { +/*printf ("Ampersand\n");*/ + return (Ampersand); + } +\| { +/*printf ("Bar\n");*/ + return (Bar); + } +\~ { +/*printf ("Tilda\n");*/ + return (Tilda); + } +\^ { +/*printf ("Circomflex\n");*/ + return (Circomflex); + } +\+ { +/*printf ("Plus\n");*/ + return (Plus); + } +\/ { +/*printf ("Slash\n");*/ + return (Slash); + } +\* { +/*printf ("Star\n");*/ + return (Star); + } +\<\< { +/*printf ("DoubleLess\n");*/ + return (DoubleLess); + } +\>\> { +/*printf ("DoubleGreat\n");*/ + return (DoubleGreat); + } +\- { +/*printf ("Minus\n");*/ + return (Minus); + } +\( { +/*printf ("LeftParen\n");*/ + return (LeftParen); + } +\) { +/*printf ("RightParen\n");*/ + return (RightParen); + } +\, { +/*printf ("Comma\n");*/ + return (Comma); + } +{register} { +/*printf ("Register : %s\n", yytext);*/ + sscanf (&yytext[1], "%lu", &yylval.valu); + return (Register); + } +{hexadecimal_valu} { +/*printf ("Literal (X) : %s\n", yytext);*/ + yylval.valu = hextoint (yytext); + return (Litteral); + } +{octal_valu} { +/*printf ("Literal (O) : %s\n", yytext);*/ + yylval.valu = octtoint (yytext); + return (Litteral); + } +{binary_valu} { +/*printf ("Literal (B) : %s\n", yytext);*/ + yylval.valu = bintoint (yytext); + return (Litteral); + } +{decimal_valu} { +/*printf ("Literal (D) : %s\n", yytext);*/ + if (sscanf (yytext, "%ld", &yylval.valu) == 0) + yylval.valu = 0; + return (Litteral); + } + +\".*\" { + extern char *mips_allocstr (); + +/*printf ("String : %s\n", yytext);*/ + yylval.text = mips_allocstr (yytext); + return (String); + } +{ident} { + int type ; + extern char *mips_allocstr (); + + yylval.text = mips_allocstr (yytext); + + type = searchtype (yylval.text); + if (type == -1) + { +/*printf ("Identifier : %s\n", yytext);*/ + return (Identifier); + } + else + { +/*printf ("Key Word : %s\n", yytext);*/ + yylval.valu = searchvalu (yylval.text); + return (type); + } + } +\;.*$ { +/*printf ("Comment : %s\n", yytext);*/ + } +%% + +static int searchtype (str) + +char *str; + { + extern char *mips_allocstr () ; + static ht *type_hashpt = NULL; + + if (type_hashpt == NULL) + { + type_hashpt = addht (128); + + addhtitem (type_hashpt, mips_allocstr ("zero" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("at" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("v0" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("v1" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("a0" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("a1" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("a2" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("a3" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t0" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t1" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t2" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t3" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t4" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t5" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t6" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t7" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s0" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s1" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s2" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s3" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s4" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s5" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s6" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s7" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t8" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("t9" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("k0" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("k1" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("gp" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("sp" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("s8" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("ra" ), IntegerRegister ); + + addhtitem (type_hashpt, mips_allocstr ("r0" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r1" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r2" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r3" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r4" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r5" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r6" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r7" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r8" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r9" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r10" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r11" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r12" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r13" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r14" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r15" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r16" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r17" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r18" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r19" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r20" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r21" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r22" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r23" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r24" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r25" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r26" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r27" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r28" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r29" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r30" ), IntegerRegister ); + addhtitem (type_hashpt, mips_allocstr ("r31" ), IntegerRegister ); + + addhtitem (type_hashpt, mips_allocstr ("badvaddr"), CP0Register ); + addhtitem (type_hashpt, mips_allocstr ("status" ), CP0Register ); + addhtitem (type_hashpt, mips_allocstr ("cause" ), CP0Register ); + addhtitem (type_hashpt, mips_allocstr ("epc" ), CP0Register ); + + addhtitem (type_hashpt, mips_allocstr (".align" ), _ALIGN ); + addhtitem (type_hashpt, mips_allocstr (".ascii" ), _ASCII ); + addhtitem (type_hashpt, mips_allocstr (".asciiz" ), _ASCIIZ ); + addhtitem (type_hashpt, mips_allocstr (".byte" ), _BYTE ); + addhtitem (type_hashpt, mips_allocstr (".bytez" ), _BYTEZ ); + addhtitem (type_hashpt, mips_allocstr (".data" ), _DATA ); + addhtitem (type_hashpt, mips_allocstr (".end" ), _END ); + addhtitem (type_hashpt, mips_allocstr (".equ" ), _EQU ); + addhtitem (type_hashpt, mips_allocstr (".global" ), _GLOBAL ); + addhtitem (type_hashpt, mips_allocstr (".org" ), _ORG ); + addhtitem (type_hashpt, mips_allocstr (".skip" ), _SKIP ); + addhtitem (type_hashpt, mips_allocstr (".space" ), _SPACE ); + addhtitem (type_hashpt, mips_allocstr (".start" ), _START ); + addhtitem (type_hashpt, mips_allocstr (".text" ), _TEXT ); + addhtitem (type_hashpt, mips_allocstr (".word" ), _WORD ); + + addhtitem (type_hashpt, mips_allocstr ("nop" ), Macro_n ); + addhtitem (type_hashpt, mips_allocstr ("loadi" ), Macro_rd_longi ); + addhtitem (type_hashpt, mips_allocstr ("la" ), Macro_rd_longi ); + addhtitem (type_hashpt, mips_allocstr ("li" ), Macro_rd_longi ); + + addhtitem (type_hashpt, mips_allocstr ("add" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("addi" ), Codop_rd_rs_imd ); + addhtitem (type_hashpt, mips_allocstr ("addu" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("addiu" ), Codop_rd_rs_imd ); + addhtitem (type_hashpt, mips_allocstr ("and" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("andi" ), Codop_rd_rs_imd ); + addhtitem (type_hashpt, mips_allocstr ("beq" ), Codop_rs_rt_labl); + addhtitem (type_hashpt, mips_allocstr ("bgez" ), Codop_rs_labl ); + addhtitem (type_hashpt, mips_allocstr ("bgezal" ), Codop_rs_labl ); + addhtitem (type_hashpt, mips_allocstr ("bgtz" ), Codop_rs_labl ); + addhtitem (type_hashpt, mips_allocstr ("blez" ), Codop_rs_labl ); + addhtitem (type_hashpt, mips_allocstr ("bltz" ), Codop_rs_labl ); + addhtitem (type_hashpt, mips_allocstr ("bltzal" ), Codop_rs_labl ); + addhtitem (type_hashpt, mips_allocstr ("bne" ), Codop_rs_rt_labl); + addhtitem (type_hashpt, mips_allocstr ("break" ), Codop_imd ); + addhtitem (type_hashpt, mips_allocstr ("j" ), Codop_labl ); + addhtitem (type_hashpt, mips_allocstr ("jal" ), Codop_labl ); + addhtitem (type_hashpt, mips_allocstr ("jalr" ), Codop_od_rs ); + addhtitem (type_hashpt, mips_allocstr ("jr" ), Codop_rs ); + addhtitem (type_hashpt, mips_allocstr ("lb" ), Codop_rd_mem ); + addhtitem (type_hashpt, mips_allocstr ("lbu" ), Codop_rd_mem ); + addhtitem (type_hashpt, mips_allocstr ("lh" ), Codop_rd_mem ); + addhtitem (type_hashpt, mips_allocstr ("lhu" ), Codop_rd_mem ); + addhtitem (type_hashpt, mips_allocstr ("lui" ), Codop_rd_imd ); + addhtitem (type_hashpt, mips_allocstr ("lw" ), Codop_rd_mem ); + + addhtitem (type_hashpt, mips_allocstr ("mfc0" ), Codop_rt_cp0rd ); + addhtitem (type_hashpt, mips_allocstr ("mfhi" ), Codop_rd ); + addhtitem (type_hashpt, mips_allocstr ("mflo" ), Codop_rd ); + addhtitem (type_hashpt, mips_allocstr ("mtc0" ), Codop_rt_cp0rd ); + addhtitem (type_hashpt, mips_allocstr ("mthi" ), Codop_rs ); + addhtitem (type_hashpt, mips_allocstr ("mtlo" ), Codop_rs ); + + addhtitem (type_hashpt, mips_allocstr ("nor" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("or" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("ori" ), Codop_rd_rs_imd ); + addhtitem (type_hashpt, mips_allocstr ("rfe" ), Codop_n ); + addhtitem (type_hashpt, mips_allocstr ("sb" ), Codop_rt_mem ); + addhtitem (type_hashpt, mips_allocstr ("sh" ), Codop_rt_mem ); + addhtitem (type_hashpt, mips_allocstr ("sleep" ), Codop_n ); + addhtitem (type_hashpt, mips_allocstr ("sll" ), Codop_rd_rt_sham); + addhtitem (type_hashpt, mips_allocstr ("sllv" ), Codop_rd_rt_rs ); + addhtitem (type_hashpt, mips_allocstr ("slt" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("slti" ), Codop_rd_rs_imd ); + addhtitem (type_hashpt, mips_allocstr ("sltiu" ), Codop_rd_rs_imd ); + addhtitem (type_hashpt, mips_allocstr ("sltu" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("sra" ), Codop_rd_rt_sham); + addhtitem (type_hashpt, mips_allocstr ("srav" ), Codop_rd_rt_rs ); + addhtitem (type_hashpt, mips_allocstr ("srl" ), Codop_rd_rt_sham); + addhtitem (type_hashpt, mips_allocstr ("srlv" ), Codop_rd_rt_rs ); + addhtitem (type_hashpt, mips_allocstr ("sub" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("subu" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("sw" ), Codop_rt_mem ); + addhtitem (type_hashpt, mips_allocstr ("swap" ), Codop_rt_mem ); + addhtitem (type_hashpt, mips_allocstr ("syscall" ), Codop_n ); + addhtitem (type_hashpt, mips_allocstr ("xor" ), Codop_rd_rs_rt ); + addhtitem (type_hashpt, mips_allocstr ("xori" ), Codop_rd_rs_imd ); + + } + return (gethtitem (type_hashpt, str)); + } + +static int searchvalu (str) + +char *str; + { + extern char *mips_allocstr () ; + static ht *valu_hashpt = NULL; + + if (valu_hashpt == NULL) + { + valu_hashpt = addht (128); + + addhtitem (valu_hashpt, mips_allocstr ("zero" ), 0 ); + addhtitem (valu_hashpt, mips_allocstr ("at" ), 1 ); + addhtitem (valu_hashpt, mips_allocstr ("v0" ), 2 ); + addhtitem (valu_hashpt, mips_allocstr ("v1" ), 3 ); + addhtitem (valu_hashpt, mips_allocstr ("a0" ), 4 ); + addhtitem (valu_hashpt, mips_allocstr ("a1" ), 5 ); + addhtitem (valu_hashpt, mips_allocstr ("a2" ), 6 ); + addhtitem (valu_hashpt, mips_allocstr ("a3" ), 7 ); + addhtitem (valu_hashpt, mips_allocstr ("t0" ), 8 ); + addhtitem (valu_hashpt, mips_allocstr ("t1" ), 9 ); + addhtitem (valu_hashpt, mips_allocstr ("t2" ), 10 ); + addhtitem (valu_hashpt, mips_allocstr ("t3" ), 11 ); + addhtitem (valu_hashpt, mips_allocstr ("t4" ), 12 ); + addhtitem (valu_hashpt, mips_allocstr ("t5" ), 13 ); + addhtitem (valu_hashpt, mips_allocstr ("t6" ), 14 ); + addhtitem (valu_hashpt, mips_allocstr ("t7" ), 15 ); + addhtitem (valu_hashpt, mips_allocstr ("s0" ), 16 ); + addhtitem (valu_hashpt, mips_allocstr ("s1" ), 17 ); + addhtitem (valu_hashpt, mips_allocstr ("s2" ), 18 ); + addhtitem (valu_hashpt, mips_allocstr ("s3" ), 19 ); + addhtitem (valu_hashpt, mips_allocstr ("s4" ), 20 ); + addhtitem (valu_hashpt, mips_allocstr ("s5" ), 21 ); + addhtitem (valu_hashpt, mips_allocstr ("s6" ), 22 ); + addhtitem (valu_hashpt, mips_allocstr ("s7" ), 23 ); + addhtitem (valu_hashpt, mips_allocstr ("t8" ), 24 ); + addhtitem (valu_hashpt, mips_allocstr ("t9" ), 25 ); + addhtitem (valu_hashpt, mips_allocstr ("k0" ), 26 ); + addhtitem (valu_hashpt, mips_allocstr ("k1" ), 27 ); + addhtitem (valu_hashpt, mips_allocstr ("gp" ), 28 ); + addhtitem (valu_hashpt, mips_allocstr ("sp" ), 29 ); + addhtitem (valu_hashpt, mips_allocstr ("s8" ), 30 ); + addhtitem (valu_hashpt, mips_allocstr ("ra" ), 31 ); + + addhtitem (valu_hashpt, mips_allocstr ("r0" ), 0 ); + addhtitem (valu_hashpt, mips_allocstr ("r1" ), 1 ); + addhtitem (valu_hashpt, mips_allocstr ("r2" ), 2 ); + addhtitem (valu_hashpt, mips_allocstr ("r3" ), 3 ); + addhtitem (valu_hashpt, mips_allocstr ("r4" ), 4 ); + addhtitem (valu_hashpt, mips_allocstr ("r5" ), 5 ); + addhtitem (valu_hashpt, mips_allocstr ("r6" ), 6 ); + addhtitem (valu_hashpt, mips_allocstr ("r7" ), 7 ); + addhtitem (valu_hashpt, mips_allocstr ("r8" ), 8 ); + addhtitem (valu_hashpt, mips_allocstr ("r9" ), 9 ); + addhtitem (valu_hashpt, mips_allocstr ("r10" ), 10 ); + addhtitem (valu_hashpt, mips_allocstr ("r11" ), 11 ); + addhtitem (valu_hashpt, mips_allocstr ("r12" ), 12 ); + addhtitem (valu_hashpt, mips_allocstr ("r13" ), 13 ); + addhtitem (valu_hashpt, mips_allocstr ("r14" ), 14 ); + addhtitem (valu_hashpt, mips_allocstr ("r15" ), 15 ); + addhtitem (valu_hashpt, mips_allocstr ("r16" ), 16 ); + addhtitem (valu_hashpt, mips_allocstr ("r17" ), 17 ); + addhtitem (valu_hashpt, mips_allocstr ("r18" ), 18 ); + addhtitem (valu_hashpt, mips_allocstr ("r19" ), 19 ); + addhtitem (valu_hashpt, mips_allocstr ("r20" ), 20 ); + addhtitem (valu_hashpt, mips_allocstr ("r21" ), 21 ); + addhtitem (valu_hashpt, mips_allocstr ("r22" ), 22 ); + addhtitem (valu_hashpt, mips_allocstr ("r23" ), 23 ); + addhtitem (valu_hashpt, mips_allocstr ("r24" ), 24 ); + addhtitem (valu_hashpt, mips_allocstr ("r25" ), 25 ); + addhtitem (valu_hashpt, mips_allocstr ("r26" ), 26 ); + addhtitem (valu_hashpt, mips_allocstr ("r27" ), 27 ); + addhtitem (valu_hashpt, mips_allocstr ("r28" ), 28 ); + addhtitem (valu_hashpt, mips_allocstr ("r29" ), 29 ); + addhtitem (valu_hashpt, mips_allocstr ("r30" ), 30 ); + addhtitem (valu_hashpt, mips_allocstr ("r31" ), 31 ); + + addhtitem (valu_hashpt, mips_allocstr ("badvaddr"), _BADVADDR); + addhtitem (valu_hashpt, mips_allocstr ("status" ), _STATUS ); + addhtitem (valu_hashpt, mips_allocstr ("cause" ), _CAUSE ); + addhtitem (valu_hashpt, mips_allocstr ("epc" ), _EPC ); + + addhtitem (valu_hashpt, mips_allocstr (".align" ), _ALIGN ); + addhtitem (valu_hashpt, mips_allocstr (".ascii" ), _ASCII ); + addhtitem (valu_hashpt, mips_allocstr (".asciiz" ), _ASCIIZ ); + addhtitem (valu_hashpt, mips_allocstr (".byte" ), _BYTE ); + addhtitem (valu_hashpt, mips_allocstr (".bytez" ), _BYTEZ ); + addhtitem (valu_hashpt, mips_allocstr (".data" ), _DATA ); + addhtitem (valu_hashpt, mips_allocstr (".end" ), _END ); + addhtitem (valu_hashpt, mips_allocstr (".equ" ), _EQU ); + addhtitem (valu_hashpt, mips_allocstr (".global" ), _GLOBAL ); + addhtitem (valu_hashpt, mips_allocstr (".org" ), _ORG ); + addhtitem (valu_hashpt, mips_allocstr (".skip" ), _SKIP ); + addhtitem (valu_hashpt, mips_allocstr (".space" ), _SPACE ); + addhtitem (valu_hashpt, mips_allocstr (".start" ), _START ); + addhtitem (valu_hashpt, mips_allocstr (".text" ), _TEXT ); + addhtitem (valu_hashpt, mips_allocstr (".word" ), _WORD ); + + addhtitem (valu_hashpt, mips_allocstr ("nop" ), _NOP ); + addhtitem (valu_hashpt, mips_allocstr ("loadi" ), _LOADI ); + addhtitem (valu_hashpt, mips_allocstr ("la" ), _LOADI ); + addhtitem (valu_hashpt, mips_allocstr ("li" ), _LOADI ); + + addhtitem (valu_hashpt, mips_allocstr ("add" ), _ADD ); + addhtitem (valu_hashpt, mips_allocstr ("addi" ), _ADDI ); + addhtitem (valu_hashpt, mips_allocstr ("addu" ), _ADDU ); + addhtitem (valu_hashpt, mips_allocstr ("addiu" ), _ADDIU ); + addhtitem (valu_hashpt, mips_allocstr ("and" ), _AND ); + addhtitem (valu_hashpt, mips_allocstr ("andi" ), _ANDI ); + addhtitem (valu_hashpt, mips_allocstr ("beq" ), _BEQ ); + addhtitem (valu_hashpt, mips_allocstr ("bgez" ), _BGEZ ); + addhtitem (valu_hashpt, mips_allocstr ("bgezal" ), _BGEZAL ); + addhtitem (valu_hashpt, mips_allocstr ("bgtz" ), _BGTZ ); + addhtitem (valu_hashpt, mips_allocstr ("blez" ), _BLEZ ); + addhtitem (valu_hashpt, mips_allocstr ("bltz" ), _BLTZ ); + addhtitem (valu_hashpt, mips_allocstr ("bltzal" ), _BLTZAL ); + addhtitem (valu_hashpt, mips_allocstr ("bne" ), _BNE ); + addhtitem (valu_hashpt, mips_allocstr ("break" ), _BREAK ); + addhtitem (valu_hashpt, mips_allocstr ("j" ), _J ); + addhtitem (valu_hashpt, mips_allocstr ("jal" ), _JAL ); + addhtitem (valu_hashpt, mips_allocstr ("jalr" ), _JALR ); + addhtitem (valu_hashpt, mips_allocstr ("jr" ), _JR ); + addhtitem (valu_hashpt, mips_allocstr ("lb" ), _LB ); + addhtitem (valu_hashpt, mips_allocstr ("lbu" ), _LBU ); + addhtitem (valu_hashpt, mips_allocstr ("lh" ), _LH ); + addhtitem (valu_hashpt, mips_allocstr ("lhu" ), _LHU ); + addhtitem (valu_hashpt, mips_allocstr ("lui" ), _LUI ); + addhtitem (valu_hashpt, mips_allocstr ("lw" ), _LW ); + addhtitem (valu_hashpt, mips_allocstr ("mfc0" ), _MFC0 ); + addhtitem (valu_hashpt, mips_allocstr ("mfhi" ), _MFHI ); + addhtitem (valu_hashpt, mips_allocstr ("mflo" ), _MFLO ); + addhtitem (valu_hashpt, mips_allocstr ("mtc0" ), _MTC0 ); + addhtitem (valu_hashpt, mips_allocstr ("mthi" ), _MTHI ); + addhtitem (valu_hashpt, mips_allocstr ("mtlo" ), _MTLO ); + addhtitem (valu_hashpt, mips_allocstr ("nor" ), _NOR ); + addhtitem (valu_hashpt, mips_allocstr ("or" ), _OR ); + addhtitem (valu_hashpt, mips_allocstr ("ori" ), _ORI ); + addhtitem (valu_hashpt, mips_allocstr ("rfe" ), _RSTFE ); + addhtitem (valu_hashpt, mips_allocstr ("sb" ), _SB ); + addhtitem (valu_hashpt, mips_allocstr ("sh" ), _SH ); + addhtitem (valu_hashpt, mips_allocstr ("sleep" ), _SLEEP ); + addhtitem (valu_hashpt, mips_allocstr ("sll" ), _SLL ); + addhtitem (valu_hashpt, mips_allocstr ("sllv" ), _SLLV ); + addhtitem (valu_hashpt, mips_allocstr ("slt" ), _SLT ); + addhtitem (valu_hashpt, mips_allocstr ("slti" ), _SLTI ); + addhtitem (valu_hashpt, mips_allocstr ("sltiu" ), _SLTIU ); + addhtitem (valu_hashpt, mips_allocstr ("sltu" ), _SLTU ); + addhtitem (valu_hashpt, mips_allocstr ("sra" ), _SRA ); + addhtitem (valu_hashpt, mips_allocstr ("srav" ), _SRAV ); + addhtitem (valu_hashpt, mips_allocstr ("srl" ), _SRL ); + addhtitem (valu_hashpt, mips_allocstr ("srlv" ), _SRLV ); + addhtitem (valu_hashpt, mips_allocstr ("sub" ), _SUB ); + addhtitem (valu_hashpt, mips_allocstr ("subu" ), _SUBU ); + addhtitem (valu_hashpt, mips_allocstr ("sw" ), _SW ); + addhtitem (valu_hashpt, mips_allocstr ("swap" ), _SWAP ); + addhtitem (valu_hashpt, mips_allocstr ("syscall" ), _SYSCALL ); + addhtitem (valu_hashpt, mips_allocstr ("xor" ), _XOR ); + addhtitem (valu_hashpt, mips_allocstr ("xori" ), _XORI ); + + } + return (gethtitem (valu_hashpt, str)); + } + +static unsigned long hextoint (str) + +char *str; + + { + unsigned long valu = 0; + char c = 0; + + while ((c = *str) != '\0') + { + if ((c >= '0') && (c <= '9')) + valu = (valu << 4) + c - '0'; + else + if ((c >= 'a') && (c <= 'f')) + valu = (valu << 4) + c - 'a' + 10; + else + if ((c >= 'A') && (c <= 'F')) + valu = (valu << 4) + c - 'A' + 10; + str++; + } + + return (valu); + } + +static unsigned long octtoint (str) + +char *str; + + { + unsigned long valu = 0; + char c = 0; + + while ((c = *str) != '\0') + { + if ((c >= '0') && (c <= '7')) + valu = (valu << 3) + c - '0'; + + str++; + } + + return (valu); + } + +static unsigned long bintoint (str) + +char *str; + + { + unsigned long valu = 0; + char c = 0; + + while ((c = *str) != '\0') + { + if ((c == '0') || (c == '1')) + valu = (valu << 1) + c - '0'; + + str++; + } + + return (valu); + } + +int yywrap () + { + return (1); + } diff --git a/alliance/src/mips_asm/src/mips_lex.h b/alliance/src/mips_asm/src/mips_lex.h new file mode 100644 index 00000000..ca515c49 --- /dev/null +++ b/alliance/src/mips_asm/src/mips_lex.h @@ -0,0 +1,41 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* ###--------------------------------------------------------------### */ +/* file : mips_lex.h */ +/* date : Apr 20 1995 */ +/* version : v0.0 */ +/* author : Pirouz BAZARGAN SABET */ +/* description : MIPS assembler - external and static variables and */ +/* functions */ +/* ###--------------------------------------------------------------### */ + +extern int MPS_LINNUM ; + +static unsigned long hextoint (); +static unsigned long octtoint (); +static unsigned long bintoint (); + +static int searchtype (); +static int searchvalu (); +extern int yywrap (); diff --git a/alliance/src/mips_asm/src/mips_type.h b/alliance/src/mips_asm/src/mips_type.h new file mode 100644 index 00000000..64945d5a --- /dev/null +++ b/alliance/src/mips_asm/src/mips_type.h @@ -0,0 +1,37 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* ###--------------------------------------------------------------### */ +/* file : mips_type.h */ +/* date : Apr 20 1995 */ +/* version : v0.0 */ +/* author : Pirouz BAZARGAN SABET */ +/* content : types used by the assmbler */ +/* ###--------------------------------------------------------------### */ + +struct immd + { + unsigned long valu; + char flag; + }; diff --git a/alliance/src/mips_asm/src/mips_util.c b/alliance/src/mips_asm/src/mips_util.c new file mode 100644 index 00000000..f5fa55fa --- /dev/null +++ b/alliance/src/mips_asm/src/mips_util.c @@ -0,0 +1,124 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* ###--------------------------------------------------------------### */ +/* file : mips_util.c */ +/* date : Sep 2 1994 */ +/* version : v0.0 */ +/* author : Pirouz BAZARGAN SABET & Julien DUNOYER */ +/* ###--------------------------------------------------------------### */ + +#include +#include "mut.h" +#include "log.h" +#include "beh.h" + +/* ###--------------------------------------------------------------### */ +/* function : mips_allocstr */ +/* description : make a memory allocation for a string. This function */ +/* insures that for a given string there will be a */ +/* unique memory allocation */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +char *mips_allocstr (src_str) + +char *src_str; /* source string */ + + { + static struct beden **lcl_dic = NULL; + char *res_str = NULL; + unsigned int cod1 = 0 ; + unsigned int cod2 = 0 ; + unsigned int size = 0 ; + struct chain *chn_pnt = NULL; + struct chain *str_lst = NULL; + + /* ###------------------------------------------------------### */ + /* initialize the local static dictionary */ + /* ###------------------------------------------------------### */ + + if (lcl_dic == NULL) + lcl_dic = beh_initab (); + + if (src_str != NULL) + { + /* ###------------------------------------------------------### */ + /* hash the source string. Two codes are produced to decrease*/ + /* conflict probability. */ + /* ###------------------------------------------------------### */ + + while (src_str [size] != '\0') + { + cod1 = (cod1 << 1) ^ (cod2 + (src_str [size] << (size % 8))); + cod2 = (cod1 << 16) + (cod2 << 1) + src_str [size] ; + size++; + } + size++; + + /* ###------------------------------------------------------### */ + /* extract from the dictionary the strings that have the */ + /* same first and second code and the same size */ + /* ###------------------------------------------------------### */ + + chn_pnt = (struct chain *) beh_chktab (lcl_dic, cod1, cod2, 7); + str_lst = chn_pnt; + + /* ###------------------------------------------------------### */ + /* scan the list comparing the strings found in the list */ + /* with the source string. */ + /* ###------------------------------------------------------### */ + + while (chn_pnt != NULL) + { + if (!strcmp (chn_pnt->DATA, src_str)) + break; + chn_pnt = chn_pnt->NEXT; + } + + /* ###------------------------------------------------------### */ + /* if no string has been found, create a new string and add */ + /* it into the dictionary. */ + /* ###------------------------------------------------------### */ + + if (chn_pnt == NULL) + { + res_str = (char *) mbkalloc (size * sizeof (char)); + strcpy (res_str, src_str); + chn_pnt = addchain (NULL, res_str); + + if (str_lst != NULL) + { + chn_pnt->NEXT = str_lst->NEXT; + str_lst->NEXT = chn_pnt ; + } + else + beh_addtab (lcl_dic, cod1, cod2, 7, chn_pnt); + } + else + res_str = (char *) chn_pnt->DATA; + } + + return (res_str); + } diff --git a/alliance/src/mips_asm/src/mips_y.y b/alliance/src/mips_asm/src/mips_y.y new file mode 100644 index 00000000..fb8c9c64 --- /dev/null +++ b/alliance/src/mips_asm/src/mips_y.y @@ -0,0 +1,1847 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* ###--------------------------------------------------------------### */ +/* file : mips_mips.yac */ +/* date : Dec 6 1999 */ +/* version : v0.3 */ +/* author : Pirouz BAZARGAN SABET */ +/* description : MIPS assembler - yacc rules */ +/* ###--------------------------------------------------------------### */ + +%{ +#include +#include "mut.h" +#include "log.h" +#include "beh.h" +#include "mips_type.h" +#include "mips_defs.h" +#include "mips_yacc.h" + +main (argc, argv) + +int argc ; +char *argv []; + + { + extern FILE *yyin ; + extern FILE *MPS_WRTFIL ; + extern FILE *MPS_TXTFIL ; + extern FILE *MPS_DATFIL ; + extern FILE *MPS_SYMFIL ; + FILE *fp_read ; + char arg_flg [ 32] ; + unsigned int txt_siz = 256; + unsigned int dat_siz = 64; + int exit_val = 1; + int asm_fil = 0; + int txt_fil = 0; + int dat_fil = 0; + int i ; + char *symbol_fil ; + char arg_err = 0; + static int call_nbr = 0; + + /* ###------------------------------------------------------### */ + /* initializations */ + /* ###------------------------------------------------------### */ + + mbkenv (); + + alliancebanner_with_authors( "asm", "v0.3", + "MIPS Assembler", "1992", + ALLIANCE_VERSION, + "Pirouz Bazargan Sabet" ); + + for (i=1 ; i0 ; i--) + { + if (arg_flg [i] == 1) + break; + } + + asm_fil = i + 1; + arg_flg [i+1] = 1 ; + txt_fil = i + 2; + arg_flg [i+2] = 1 ; + + if ((i+3) < argc) + { + dat_fil = i + 3; + arg_flg [i+3] = 1 ; + } + + + /* ###------------------------------------------------------### */ + /* cases of errors on the command line: */ + /* - a unrecognized argument */ + /* - not enough arguments */ + /* - too many arguments */ + /* ###------------------------------------------------------### */ + + if ((argc > 11) || (argc < 3)) + arg_err = 1; + + for (i=0 ; i> 2) - 1; + while (txt_siz != 0) + { + txt_siz = txt_siz >> 1; + MPS_TXTSIZ ++; + } + + /* ###------------------------------------------------------### */ + /* compute the length (number of bits) of the data address */ + /* ###------------------------------------------------------### */ + + dat_siz -= 1; + while (dat_siz != 0) + { + dat_siz = dat_siz >> 1; + MPS_DATSIZ ++; + } + + /* ###------------------------------------------------------### */ + /* call the assembly file parser (two passes): */ + /* - set the address space (by default) to text */ + /* - in the first pass identify labels */ + /* - if no error has been found print the result files' */ + /* header */ + /* - translate insstructions in the second pass */ + /* - print the result files' foot */ + /* ###------------------------------------------------------### */ + + MPS_ADRSPC = 'T' ; + MPS_ADDRES = MPS_TXTADR; + MPS_WRTFIL = MPS_TXTFIL; + MPS_ADRSIZ = MPS_TXTSIZ; + MPS_WRDSIZ = 4 ; + + MPS_PASNBR = 1 ; + + if (call_nbr != 0) + yyrestart (yyin); + + yyin = fp_read; + yyparse (); + + call_nbr++; + + if (MPS_ERRFLG == 0) + { + fclose (fp_read); + fp_read = fopen (argv [asm_fil], "r"); + yyin = fp_read; + + MPS_ADRSPC = 'T'; + MPS_ADDRES = MPS_TXTADR; + MPS_WRTFIL = MPS_TXTFIL; + MPS_ADRSIZ = MPS_TXTSIZ; + MPS_WRDSIZ = 4; + + MPS_PASNBR = 2 ; + MPS_LINNUM = 1 ; + + if (MPS_DUMP != 'y') + { + mips_head (MPS_TXTFIL, argv [txt_fil], MPS_TXTSIZ, 4); + if (MPS_DATFIL != NULL) + mips_head (MPS_DATFIL, argv [dat_fil], MPS_DATSIZ, 1); + } + + yyrestart (yyin); + yyparse (); + + if (MPS_DUMP != 'y') + { + mips_foot (MPS_TXTFIL, 4); + if (MPS_DATFIL != NULL) + mips_foot (MPS_DATFIL, 1); + } + + exit_val = 0; + + } + + /* ###------------------------------------------------------### */ + /* close source and result files */ + /* ###------------------------------------------------------### */ + + fclose (fp_read); + fclose (MPS_TXTFIL); + + if (MPS_DATFIL != NULL) + fclose (MPS_DATFIL); + + if (MPS_SYMBOL == 'y') + fclose (MPS_SYMFIL); + + exit (exit_val); + } + +%} + +%union + { + unsigned long valu; + struct immd immd; + char *text; + } + +%token _ALIGN +%token _ASCII +%token _ASCIIZ +%token _BYTE +%token _BYTEZ +%token _DATA +%token _END +%token _EQU +%token _GLOBAL +%token _ORG +%token _SPACE +%token _SKIP +%token _START +%token _TEXT +%token _WORD +%token Ampersand +%token Bar +%token CarriageReturn +%token Circomflex +%token Codop_rd +%token Codop_rd_rs_rt +%token Codop_rd_rt_sham +%token Codop_rd_rt_rs +%token Codop_rd_rs_imd +%token Codop_rs_rt_labl +%token Codop_od_rs +%token Codop_rs +%token Codop_rd_mem +%token Codop_rt_mem +%token Codop_rt_cp0rd +%token Codop_rs_labl +%token Codop_rd_imd +%token Codop_labl +%token Codop_imd +%token Codop_n +%token Colon +%token Comma +%token CP0Register +%token DoubleGreat +%token DoubleLess +%token Identifier +%token IntegerRegister +%token LeftParen +%token Litteral +%token Macro_n +%token Macro_rd_longi +%token Minus +%token Plus +%token Register +%token RightParen +%token Sharp +%token Slash +%token Star +%token String +%token Tilda + +%type effective_instruction + +%type mips_instruction +%type format_n +%type format_labl +%type format_imd +%type format_rd_imd +%type format_rs_labl +%type format_rs_rt_labl +%type format_rd_mem +%type format_rt_mem +%type format_rd_rs_imd +%type format_rd_rt_sham +%type format_rd +%type format_od_rs +%type format_rs +%type format_rd_rs_rt +%type format_rd_rt_rs +%type format_rt_cp0rd + +%type macro_instruction +%type macro_ri +%type macro_n + +%type cp0_reg +%type destination_register +%type source_register +%type integer_register + +%type adding_operator +%type logical_operator +%type mul_div_operator +%type shift_operator + +%type term +%type expression +%type expr..addop__expr.. +%type expr__mulop__expr..mulop__expr.. +%type expr__logop__expr..logop__expr.. +%type expr__shfop__expr +%type .immediate. +%type immediate +%type label +%type offset +%type byte_alloc +%type bytez_alloc +%type word_alloc +%type ascii_alloc +%type asciiz_alloc +%type mem_alloc_directive + +%start mips_assembly_prog + +%% +mips_assembly_prog + : assembly_instructions + .end_pseudo_inst. + ; + +assembly_instructions + : ..an_assembly_instruction.. + ; + +..an_assembly_instruction.. + : /*empty*/ + | ..an_assembly_instruction.. + an_assembly_instruction + ; + +an_assembly_instruction + : .a_label. + .unlabeled_assembly_instruction. + CarriageReturn_ERR + | unlabeled_pseudo_instruction + CarriageReturn_ERR + | error + CarriageReturn_ERR + ; + +.a_label. + : /*empty*/ + | label + Colon + { + /* ###----------------------------------------------### */ + /* in the first pass, check that the label is unique. */ + /* Save its address in the dictionary and flag it as a */ + /* label. */ + /* ###----------------------------------------------### */ + + if (MPS_PASNBR == 1) + { + if (beh_chktab (MPS_HSHTAB, $1, NULL, 0) == 0) + { + beh_addtab (MPS_HSHTAB, $1, NULL, 0, 'l' ); + beh_addtab (MPS_HSHTAB, $1, NULL, 7, MPS_ADDRES); + if (MPS_SYMBOL == 'y') + mips_symbol ($1); + } + else + mips_error (3, NULL); + } + } + ; + +.unlabeled_assembly_instruction. + : /*empty*/ + | mem_alloc_directive + { + if ((MPS_PASNBR == 2) && ($1.flag == 0)) + mips_error (4, NULL); + + if (MPS_PASNBR == 2) + mips_print ($1.valu); + + MPS_ADDRES += $1.valu; + } + | effective_instruction + { + if ((MPS_PASNBR == 2) && ($1.flag == 0)) + mips_error (4, NULL); + + if (MPS_PASNBR == 2) + mips_print ($1.valu); + + MPS_ADDRES += $1.valu; + } + ; + +mem_alloc_directive + : word_alloc + { $$ = $1; } + | byte_alloc + { $$ = $1; } + | bytez_alloc + { $$ = $1; } + | ascii_alloc + { $$ = $1; } + | asciiz_alloc + { $$ = $1; } + | skip_pseudo_inst + { + $$.valu = 0 ; + $$.flag = 'n'; + } + | space_pseudo_inst + { + $$.valu = 0 ; + $$.flag = 'n'; + } + ; + +word_alloc + : _WORD + immediate + { + MPS_BYTTAB [3] = $2.valu >> 24; + MPS_BYTTAB [2] = $2.valu >> 16; + MPS_BYTTAB [1] = $2.valu >> 8; + MPS_BYTTAB [0] = $2.valu ; + + $$.valu = 4; + $$.flag = $2.flag; + } + ; + +byte_alloc + : _BYTE + immediate + { + /* ###----------------------------------------------### */ + /* initialize a byte address with a value */ + /* ###----------------------------------------------### */ + + MPS_BYTTAB [0] = $2.valu; + + $$.valu = 1 ; + $$.flag = $2.flag; + } + ; + +bytez_alloc + : _BYTEZ + immediate + { + /* ###----------------------------------------------### */ + /* initialize a byte table with zeros */ + /* ###----------------------------------------------### */ + + unsigned int i; + + for (i=0; i<$2.valu ; i++) + MPS_BYTTAB [i] = 0x00; + + $$.valu = $2.valu; + $$.flag = $2.flag; + } + ; + +ascii_alloc + : _ASCII + String + { + /* ###----------------------------------------------### */ + /* initialize a set of addresses with a string */ + /* ###----------------------------------------------### */ + + $$.valu = mips_strtobin ($2, MPS_BYTTAB); + $$.flag = 'n'; + } + ; + +asciiz_alloc + : _ASCIIZ + String + { + /* ###----------------------------------------------### */ + /* initialize a set of addresses with a string */ + /* followed by a null character */ + /* ###----------------------------------------------### */ + + unsigned int size; + + size = mips_strtobin ($2, MPS_BYTTAB); + MPS_BYTTAB [size] = '\0'; + + $$.valu = size + 1; + $$.flag = 'n'; + } + ; + +unlabeled_pseudo_instruction + : align_pseudo_inst + | data_pseudo_inst + | equ_pseudo_inst + | global_pseudo_inst + | org_pseudo_inst + | start_pseudo_inst + | text_pseudo_inst + ; + +data_pseudo_inst + : _DATA + .immediate. + { + /* ###----------------------------------------------### */ + /* if the current region is the 'text region', switch */ + /* to the 'data region'. */ + /* if an address is defined, set the current data */ + /* address. */ + /* ###----------------------------------------------### */ + + if (MPS_ADRSPC == 'T') + { + MPS_TXTADR = MPS_ADDRES; + + MPS_ADDRES = MPS_DATADR; + MPS_WRTFIL = MPS_DATFIL; + MPS_ADRSIZ = MPS_DATSIZ; + MPS_WRDSIZ = 1 ; + MPS_ADRSPC = 'D'; + } + + if ($2.flag == 'i') + MPS_ADDRES = $2.valu; + else + { + if ($2.flag != 'n') + mips_error (4, NULL); + } + } + ; + +text_pseudo_inst + : _TEXT + .immediate. + { + /* ###----------------------------------------------### */ + /* if the current region is the 'data region', switch */ + /* to the 'text region'. */ + /* if an address is defined, set the current data */ + /* address. */ + /* ###----------------------------------------------### */ + + if (MPS_ADRSPC == 'D') + { + MPS_DATADR = MPS_ADDRES; + + MPS_ADDRES = MPS_TXTADR; + MPS_WRTFIL = MPS_TXTFIL; + MPS_ADRSIZ = MPS_TXTSIZ; + MPS_WRDSIZ = 4; + MPS_ADRSPC = 'T'; + } + + if ($2.flag == 'i') + MPS_ADDRES = $2.valu; + else + { + if ($2.flag != 'n') + mips_error (4, NULL); + } + } + ; + +global_pseudo_inst + : _GLOBAL + label + ; + +align_pseudo_inst + : _ALIGN + Litteral + { + /* ###----------------------------------------------### */ + /* align the current address */ + /* ###----------------------------------------------### */ + + switch ($2) + { + case 1: + break; + case 2: + MPS_ADDRES = (MPS_ADDRES + 1) & 0xfffffffe; + break; + case 4: + MPS_ADDRES = (MPS_ADDRES + 3) & 0xfffffffc; + break; + case 8: + MPS_ADDRES = (MPS_ADDRES + 7) & 0xfffffff8; + break; + default: + mips_error (4, NULL); + } + } + ; + +.end_pseudo_inst. + : /*empty*/ + | end_pseudo_inst + ; + +end_pseudo_inst + : _END + ..CR.. + ; + +start_pseudo_inst + : _START + label + ; + +space_pseudo_inst + : _SPACE + Litteral + { + MPS_ADDRES += $2; + } + ; + +skip_pseudo_inst + : _SKIP + Litteral + { + MPS_ADDRES += $2; + } + ; + +org_pseudo_inst + : _ORG + immediate + { + /* ###----------------------------------------------### */ + /* define the first address (must be an immediate) */ + /* ###----------------------------------------------### */ + + if ($2.flag == 'i') + MPS_ADDRES = $2.valu; + else + mips_error (4, NULL); + } + ; + +equ_pseudo_inst + : Identifier + _EQU + immediate + { + /* ###----------------------------------------------### */ + /* in the first pass, check that the identifier has */ + /* not been defined ealier. */ + /* Save its value in the dictionary and flag it as */ + /* an immediate. */ + /* ###----------------------------------------------### */ + + if (MPS_PASNBR == 1) + { + if ($3.flag == 'i') + { + if (beh_chktab (MPS_HSHTAB, $1, NULL, 0) == 0) + { + beh_addtab (MPS_HSHTAB, $1, NULL, 0, 'i' ); + beh_addtab (MPS_HSHTAB, $1, NULL, 7, $3.valu); + } + else + mips_error (3, NULL); + } + else + mips_error (4, NULL); + } + } + ; + +effective_instruction + : mips_instruction + { $$ = $1; } + | macro_instruction + { $$ = $1; } + ; + +mips_instruction + : format_n + { $$ = $1; } + | format_labl + { $$ = $1; } + | format_imd + { $$ = $1; } + | format_rd_imd + { $$ = $1; } + | format_rs_labl + { $$ = $1; } + | format_rs_rt_labl + { $$ = $1; } + | format_rd_mem + { $$ = $1; } + | format_rt_mem + { $$ = $1; } + | format_rd_rs_imd + { $$ = $1; } + | format_rd_rt_sham + { $$ = $1; } + | format_rd + { $$ = $1; } + | format_od_rs + { $$ = $1; } + | format_rs + { $$ = $1; } + | format_rd_rs_rt + { $$ = $1; } + | format_rd_rt_rs + { $$ = $1; } + | format_rt_cp0rd + { $$ = $1; } + ; + +format_rd_rs_rt + : Codop_rd_rs_rt + destination_register + Comma + source_register + Comma + source_register + { + unsigned long inst = 0; + + inst = $1 | ($4 << 21) | ($6 << 16) | ($2 << 11); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = 'n'; + } + ; + +format_rd_rt_rs + : Codop_rd_rt_rs + destination_register + Comma + source_register + Comma + source_register + { + unsigned long inst = 0; + + inst = $1 | ($6 << 21) | ($4 << 16) | ($2 << 11); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4 ; + $$.flag = 'n'; + } + ; + +format_rt_cp0rd + : Codop_rt_cp0rd + integer_register + Comma + cp0_reg + { + unsigned long inst = 0; + + inst = $1 | ($2 << 16) | ($4 << 11); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4 ; + $$.flag = 'n'; + } + ; + +format_rd + : Codop_rd + destination_register + { + unsigned long inst = 0; + + inst = $1 | ($2 << 11); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = 'n'; + } + ; + +format_od_rs + : Codop_od_rs + source_register + { + unsigned long inst = 0x0000f800; + + inst |= $1 | ($2 << 21); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = 'n'; + } + | Codop_od_rs + destination_register + Comma + source_register + { + unsigned long inst = 0; + + inst = $1 | ($4 << 21) | ($2 << 11); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = 'n'; + } + ; + +format_rs + : Codop_rs + source_register + { + unsigned long inst = 0; + + inst = $1 | ($2 << 21); + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = 'n'; + } + ; + +format_rd_rs_imd + : Codop_rd_rs_imd + destination_register + Comma + source_register + Comma + .sharp. + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = 0x0000ffff & $7.valu; + inst = $1 | ($4 << 21) | ($2 << 16) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $7.flag; + } + ; + +format_rd_rt_sham + : Codop_rd_rt_sham + destination_register + Comma + source_register + Comma + .sharp. + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = 0x0000001f & $7.valu; + inst = $1 | ($4 << 16) | ($2 << 11) | (imd << 6); + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $7.flag; + } + ; + +format_rd_mem + : Codop_rd_mem + destination_register + Comma + offset + LeftParen + source_register + RightParen + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = 0x0000ffff & $4.valu; + inst = $1 | ($6 << 21) | ($2 << 16) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $4.flag; + } + ; + +format_rt_mem + : Codop_rt_mem + source_register + Comma + offset + LeftParen + source_register + RightParen + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = 0x0000ffff & $4.valu; + inst = $1 | ($6 << 21) | ($2 << 16) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $4.flag; + } + ; + +format_rs_rt_labl + : Codop_rs_rt_labl + source_register + Comma + source_register + Comma + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + if ($6.flag == 'l') + imd = $6.valu - MPS_ADDRES - 4; + else + { + if (MPS_PASNBR == 2) + mips_error (4, NULL); + } + + imd = 0x0000ffff & (imd >> 2); + inst = $1 | ($2 << 21) | ($4 << 16) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4 ; + $$.flag = $6.flag; + } + ; + +format_rs_labl + : Codop_rs_labl + source_register + Comma + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + if ($4.flag == 'l') + imd = $4.valu - MPS_ADDRES - 4; + else + { + if (MPS_PASNBR == 2) + mips_error (4, NULL); + } + + imd = 0x0000ffff & (imd >> 2); + inst = $1 | ($2 << 21) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $4.flag; + } + ; + +format_rd_imd + : Codop_rd_imd + destination_register + Comma + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = 0x0000ffff & $4.valu; + inst = $1 | ($2 << 16) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $4.flag; + } + ; + +format_imd + : Codop_imd + .sharp. + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = 0x0000ffff & $3.valu; + inst = $1 | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $3.flag; + } + ; + +format_labl + : Codop_labl + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + imd = $2.valu; +/*-------- + if ($2.flag == 'l') + imd = $2.valu - MPS_ADDRES - 4; + else + imd = $2.valu; +----------*/ + + imd = 0x03ffffff & (imd >> 2); + inst = $1 | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = $2.flag; + } + ; + +format_n + : Codop_n + { + unsigned long inst = 0; + + inst = $1; + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + $$.valu = 4; + $$.flag = 'n'; + } + ; + +.sharp. + : /*empty*/ + | Sharp + ; + +macro_instruction + : macro_ri + { $$ = $1; } + | macro_n + { $$ = $1; } + ; + +macro_ri + : Macro_rd_longi + destination_register + Comma + immediate + { + unsigned long imd = 0; + unsigned long inst = 0; + + switch ($1) + { + case _LOADI : + imd = 0x0000ffff & ($4.valu >> 16); + inst = _LUI | ($2 << 16) | imd; + + MPS_BYTTAB [3] = inst >> 24; + MPS_BYTTAB [2] = inst >> 16; + MPS_BYTTAB [1] = inst >> 8; + MPS_BYTTAB [0] = inst ; + + imd = 0x0000ffff & $4.valu; + inst = _ORI | ($2 << 21) | ($2 << 16) | imd; + + MPS_BYTTAB [7] = inst >> 24; + MPS_BYTTAB [6] = inst >> 16; + MPS_BYTTAB [5] = inst >> 8; + MPS_BYTTAB [4] = inst ; + + $$.valu = 8; + $$.flag = $4.flag; + break; + + default: + mips_error (5, NULL); + } + } + ; + +macro_n + : Macro_n + { + switch ($1) + { + case _NOP : + MPS_BYTTAB [3] = 0x00; + MPS_BYTTAB [2] = 0x00; + MPS_BYTTAB [1] = 0x00; + MPS_BYTTAB [0] = 0x21; + + $$.valu = 4; + $$.flag = 'n'; + break; + + default: + mips_error (5, NULL); + } + } + ; + +offset + : immediate + { $$ = $1; } + ; + +.immediate. + : /*empty*/ + { + $$.valu = 0 ; + $$.flag = 'n'; + } + | immediate + { $$ = $1; } + ; + +immediate + : expr..addop__expr.. + { $$ = $1; } + | expr__mulop__expr..mulop__expr.. + { $$ = $1; } + | expr__logop__expr..logop__expr.. + { $$ = $1; } + | expr__shfop__expr + { $$ = $1; } + ; + +expr..addop__expr.. + : expression + { $$ = $1; } + | expr..addop__expr.. + adding_operator + expression + { + if ($2 == MPS_PLSDFN) + $$.valu = $1.valu + $3.valu; + else + $$.valu = $1.valu - $3.valu; + + if (($1.flag == 0) || ($3.flag == 0)) + $$.flag = 0; + else + { + if (($1.flag == 'l') || ($3.flag == 'l')) + $$.flag = 'l'; + else + $$.flag = 'i'; + } + } + ; + +expr__mulop__expr..mulop__expr.. + : expression + mul_div_operator + expression + { + if ($2 == MPS_MULDFN) + $$.valu = $1.valu * $3.valu; + else + $$.valu = $1.valu / $3.valu; + + if (($1.flag == 0) || ($3.flag == 0)) + $$.flag = 0; + else + { + if (($1.flag == 'l') || ($3.flag == 'l')) + $$.flag = 'l'; + else + $$.flag = 'i'; + } + } + | expr__mulop__expr..mulop__expr.. + Star + expression + { + $$.valu = $1.valu * $3.valu; + + if (($1.flag == 0) || ($3.flag == 0)) + $$.flag = 0; + else + { + if (($1.flag == 'l') || ($3.flag == 'l')) + $$.flag = 'l'; + else + $$.flag = 'i'; + } + } + ; + +expr__logop__expr..logop__expr.. + : expression + logical_operator + expression + { + if ($2 == MPS_ORDFN) + $$.valu = $1.valu | $3.valu; + + if ($2 == MPS_ANDDFN) + $$.valu = $1.valu & $3.valu; + + if ($2 == MPS_XORDFN) + $$.valu = $1.valu ^ $3.valu; + + if (($1.flag == 0) || ($3.flag == 0)) + $$.flag = 0; + else + { + if (($1.flag == 'l') || ($3.flag == 'l')) + $$.flag = 'l'; + else + $$.flag = 'i'; + } + } + | expr__logop__expr..logop__expr.. + logical_operator + expression + { + if ($2 == MPS_ORDFN) + $$.valu = $1.valu | $3.valu; + + if ($2 == MPS_ANDDFN) + $$.valu = $1.valu & $3.valu; + + if ($2 == MPS_XORDFN) + $$.valu = $1.valu ^ $3.valu; + + if (($1.flag == 0) || ($3.flag == 0)) + $$.flag = 0; + else + { + if (($1.flag == 'l') || ($3.flag == 'l')) + $$.flag = 'l'; + else + $$.flag = 'i'; + } + } + ; + +expr__shfop__expr + : expression + shift_operator + expression + { + if ($2 == MPS_SHLDFN) + $$.valu = $1.valu << $3.valu; + else + $$.valu = $1.valu >> $3.valu; + + if (($1.flag == 0) || ($3.flag == 0)) + $$.flag = 0; + else + { + if (($1.flag == 'l') || ($3.flag == 'l')) + $$.flag = 'l'; + else + $$.flag = 'i'; + } + } + ; + +shift_operator + : DoubleLess + { $$ = MPS_SHLDFN; } + | DoubleGreat + { $$ = MPS_SHRDFN; } + ; + +mul_div_operator + : Star + { $$ = MPS_MULDFN; } + | Slash + { $$ = MPS_DIVDFN; } + ; + +expression + : LeftParen + immediate + RightParen + { + $$ = $2; + } + | Tilda + LeftParen + immediate + RightParen + { + $$.valu = ~ ($3.valu); + $$.flag = $3.flag; + } + | Minus + LeftParen + immediate + RightParen + { + $$.valu = - $3.valu; + $$.flag = $3.flag; + } + | term + { $$ = $1; } + ; + +logical_operator + : Bar + { $$ = MPS_ORDFN; } + | Ampersand + { $$ = MPS_ANDDFN; } + | Circomflex + { $$ = MPS_XORDFN; } + ; + +adding_operator + : Plus + { $$ = MPS_PLSDFN; } + | Minus + { $$ = MPS_MNSDFN; } + ; + +term + : Litteral + { + $$.valu = $1; + $$.flag = 'i'; + } + | Minus + Litteral + { + $$.valu = - $2; + $$.flag = 'i'; + } + | Tilda + Litteral + { + $$.valu = ~ $2; + $$.flag = 'i'; + } + | Identifier + { + unsigned long imd; + + imd = beh_chktab (MPS_HSHTAB, $1, NULL, 7); + $$.valu = imd; + $$.flag = beh_chktab (MPS_HSHTAB, $1, NULL, 0); + } + | Minus + Identifier + { + unsigned long imd; + + imd = beh_chktab (MPS_HSHTAB, $2, NULL, 7); + $$.valu = -imd; + $$.flag = beh_chktab (MPS_HSHTAB, $2, NULL, 0); + } + | Tilda + Identifier + { + unsigned long imd; + + imd = beh_chktab (MPS_HSHTAB, $2, NULL, 7); + $$.valu = ~imd; + $$.flag = beh_chktab (MPS_HSHTAB, $2, NULL, 0); + } + ; + +destination_register + : IntegerRegister + { $$ = $1; } + | Register + { $$ = $1; } + ; + +source_register + : IntegerRegister + { $$ = $1; } + | Register + { $$ = $1; } + ; + +integer_register + : IntegerRegister + { $$ = $1; } + | Register + { $$ = $1; } + ; + +cp0_reg + : CP0Register + { $$ = $1; } + | Register + { $$ = $1; } + ; + +label + : Identifier + { $$ = $1; } + ; + +..CR.. + : /*empty*/ + | ..CR.. + CarriageReturn_ERR + ; + +CarriageReturn_ERR + : CarriageReturn + { yyerrok; } + ; +%% + +/* ###--------------------------------------------------------------### */ +/* function : mips_error */ +/* description : print an error message */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +static void mips_error (code, str) + +int code; +char *str; + + { + MPS_ERRFLG = 1; + if (code <100) + fprintf (stderr,"Error %d near line %d : ",code, MPS_LINNUM); + + switch (code) + { + case 2: + fprintf (stderr, "missing label\n"); + break; + case 3: + fprintf (stderr, "redefinition of label\n"); + break; + case 4: + fprintf (stderr, "undifined string\n"); + break; + case 5: + fprintf (stderr, "parse error\n"); + break; + case 6: + fprintf (stderr, "no output file has been specified\n"); + break; + case 100: + fprintf (stderr, "cannot open file `%s`\n",str); + break; + case 101: + fprintf (stderr, "usage: mips_asm [] \n"); + break; + } + } + +/* ###--------------------------------------------------------------### */ +/* function : yyerror */ +/* description : print yacc error messages */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +yyerror (str) + +char *str; + + { + MPS_ERRFLG = 1; + fprintf (stderr, "line %d : %s\n",MPS_LINNUM, str); + } + +/* ###--------------------------------------------------------------### */ +/* function : mips_foot */ +/* description : print the head lines of the behavioural description */ +/* of a ROM. The 'address size' defines the number of */ +/* bits of the address, the 'word size' defines the size */ +/* of the rom line in bytes and the 'name' specifies the */ +/* name of the Entity. */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +static void mips_head (fp, name, adr_siz, wrd_siz) + +FILE *fp; +char *name; +unsigned int adr_siz; +unsigned int wrd_siz; + + { + adr_siz --; + wrd_siz = (wrd_siz * 8) - 1; + + fprintf (fp, "entity %s is\n port (\n", name); + fprintf (fp, " address : in bit_vector (%u downto 0);\n", adr_siz); + fprintf (fp, " e_n : in bit;\n"); + fprintf (fp, " data : out mux_vector (%u downto 0) bus;\n", wrd_siz); + fprintf (fp, " vdd : in bit;\n"); + fprintf (fp, " vss : in bit);\nend %s;\n\n",name); + fprintf (fp, "architecture VBE of %s is\n\n", name); + fprintf (fp, " signal rom_out : bit_vector (%u downto 0);\n\n", wrd_siz); + fprintf (fp, "begin\n\n"); + fprintf (fp, " write_out : block (e_n = '0')\n begin\n"); + fprintf (fp, " data <= guarded rom_out;\n end block;\n\n"); + fprintf (fp, " with address (%u downto 0) select\n rom_out <=\n", adr_siz); + } + +/* ###--------------------------------------------------------------### */ +/* function : mips_foot */ +/* description : print the foot lines of the behavioural description */ +/* of a ROM. The 'word size' defines the size of the */ +/* rom line in bytes. */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +static void mips_foot (fp, wrd_siz) + +FILE *fp ; +unsigned int wrd_siz; + + { + unsigned int i; + + fprintf (fp, " X\""); + + for (i=0 ; i> 2; + else + adr = MPS_ADDRES; + + for (i=0 ; i> 1; + } + binadr [j] = '\0'; + + fprintf (MPS_WRTFIL, "\" when B\"%s\",\n", binadr); + adr++; + } + } + } + } + } + +/* ###--------------------------------------------------------------### */ +/* function : mips_symbol */ +/* description : print out the location (in text or data region) of a */ +/* symbol */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +static void mips_symbol (str) + +char *str; + { + char *seg; + + if (MPS_ADRSPC == 'T') + seg = "text"; + else + seg = "data"; + + fprintf (MPS_SYMFIL, "%s\t: location %x in %s segment\n", str, + MPS_ADDRES, seg); + } + +/* ###--------------------------------------------------------------### */ +/* function : mips_strtobin */ +/* description : make a binary ? from a string */ +/* called func. : none */ +/* ###--------------------------------------------------------------### */ + +static int mips_strtobin (str, tab) + +char *str; +char *tab; + + { + int i = 1; + int j = 0; + + while (str [i] != '\0') + { + tab [j] = str [i]; + i++; + if (str[i-1] == '\\') + { + if ((str [i] <= '7') && (str [i] >= '0')) + { + tab [j] = str [i] - '0'; + i++; + if ((str [i] <= '7') && (str [i] >= '0')) + { + tab [j] = (tab [j] * 8) + (str [i] - '0'); + i++; + if ((str [i] <= '7') && (str [i] >= '0')) + tab [j] = (tab [j] * 8) + (str [i] - '0'); + } + } + else + { + if (str [i] == '"') + { + tab [j] = str [i]; + i++; + } + } + } + + j++; + } + + return (j-1); + } diff --git a/alliance/src/mips_asm/src/mips_yacc.h b/alliance/src/mips_asm/src/mips_yacc.h new file mode 100644 index 00000000..b2d7ba25 --- /dev/null +++ b/alliance/src/mips_asm/src/mips_yacc.h @@ -0,0 +1,67 @@ +/* + * This file is part of the Alliance CAD System + * Copyright (C) Laboratoire LIP6 - Département ASIM + * Universite Pierre et Marie Curie + * + * Home page : http://www-asim.lip6.fr/alliance/ + * E-mail : mailto:alliance-users@asim.lip6.fr + * + * This progam 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 2 of the License, or (at your + * option) any later version. + * + * Alliance VLSI CAD System 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 the GNU C Library; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* ###--------------------------------------------------------------### */ +/* file : mips_yacc.h */ +/* date : Dec 9 1999 */ +/* version : v0.3 */ +/* author : Pirouz BAZARGAN SABET */ +/* description : MIPS assembler - external and static variables and */ +/* functions */ +/* ###--------------------------------------------------------------### */ + +extern int MPS_LINNUM ; + +static int MPS_PASNBR ; +static int MPS_ERRFLG ; + +static FILE *MPS_TXTFIL = NULL; +static unsigned long MPS_TXTADR = 0 ; +static int MPS_TXTSIZ = 0 ; + +static FILE *MPS_DATFIL = NULL; +static unsigned long MPS_DATADR = 0 ; +static int MPS_DATSIZ = 0 ; + +static char *MPS_LABEL = NULL; + +static FILE *MPS_WRTFIL = NULL; +static FILE *MPS_SYMFIL = NULL; + +static unsigned long MPS_ADDRES ; +static int MPS_ADRSIZ = 0 ; +static int MPS_WRDSIZ = 0 ; +static char MPS_ADRSPC = 'T' ; +static char MPS_SYMBOL = 'n' ; +static char MPS_DUMP = 'n' ; + +static unsigned char MPS_BYTTAB [1024]; + +static struct beden **MPS_HSHTAB = NULL; + +static void mips_error (); +static void mips_head (); +static void mips_foot (); +static void mips_print (); +static void mips_symbol (); +static int mips_strtobin ();