From 0023db327bc1db00068284b70e1db45857aeee35 Mon Sep 17 00:00:00 2001 From: Travis Bradshaw Date: Tue, 31 Jan 2012 14:32:09 -0600 Subject: The Quake sources as originally release under the GPL license on December 21, 1999 --- WinQuake/gas2masm/gas2masm.c | 1056 ++++++++++++++++++++++++++++++++++++++++ WinQuake/gas2masm/gas2masm.dsp | 100 ++++ WinQuake/gas2masm/gas2masm.dsw | 29 ++ WinQuake/gas2masm/gas2masm.mdp | Bin 0 -> 37888 bytes WinQuake/gas2masm/gas2masm.plg | 32 ++ 5 files changed, 1217 insertions(+) create mode 100644 WinQuake/gas2masm/gas2masm.c create mode 100644 WinQuake/gas2masm/gas2masm.dsp create mode 100644 WinQuake/gas2masm/gas2masm.dsw create mode 100644 WinQuake/gas2masm/gas2masm.mdp create mode 100644 WinQuake/gas2masm/gas2masm.plg (limited to 'WinQuake/gas2masm') diff --git a/WinQuake/gas2masm/gas2masm.c b/WinQuake/gas2masm/gas2masm.c new file mode 100644 index 0000000..2e1eb87 --- /dev/null +++ b/WinQuake/gas2masm/gas2masm.c @@ -0,0 +1,1056 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. + +This program 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. + +This program 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 this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +// +// gas to MASM source code converter +// + +#include +#include +#include + +#define MAX_TOKENS 100 +#define MAX_TOKEN_LENGTH 1024 +#define LF 0x0A + +typedef enum {NOT_WHITESPACE, WHITESPACE, TOKEN_AVAILABLE, LINE_DONE, FILE_DONE, PARSED_OKAY} tokenstat; +typedef enum {NOSEG, DATASEG, TEXTSEG} segtype; + +int tokennum; +int inline, outline; + +char *token; +char tokens[MAX_TOKENS][MAX_TOKEN_LENGTH+1]; + +segtype currentseg = NOSEG; + +typedef struct { + char *text; + char *emit; + int numtokens; + void (*parsefunc) (void); +} parsefield; + + +void errorexit (void); + + +//============================================== + +typedef struct { + char *text; + char *emit; + int len; +} regdesc; + +regdesc reglist[] = { + {"%eax", "eax", 4}, + {"%ebx", "ebx", 4}, + {"%ecx", "ecx", 4}, + {"%edx", "edx", 4}, + {"%esi", "esi", 4}, + {"%edi", "edi", 4}, + {"%ebp", "ebp", 4}, + {"%esp", "esp", 4}, + {"%ax", "ax", 3}, + {"%bx", "bx", 3}, + {"%cx", "cx", 3}, + {"%dx", "dx", 3}, + {"%si", "si", 3}, + {"%di", "di", 3}, + {"%bp", "bp", 3}, + {"%sp", "sp", 3}, + {"%al", "al", 3}, + {"%bl", "bl", 3}, + {"%cl", "cl", 3}, + {"%dl", "dl", 3}, + {"%ah", "ah", 3}, + {"%bh", "bh", 3}, + {"%ch", "ch", 3}, + {"%dh", "dh", 3}, + {"%st(0)", "st(0)", 6}, + {"%st(1)", "st(1)", 6}, + {"%st(2)", "st(2)", 6}, + {"%st(3)", "st(3)", 6}, + {"%st(4)", "st(4)", 6}, + {"%st(5)", "st(5)", 6}, + {"%st(6)", "st(6)", 6}, + {"%st(7)", "st(7)", 6}, +}; + +int numregs = sizeof (reglist) / sizeof (reglist[0]); + +//============================================== + + +void emitanoperand (int tnum, char *type, int notdata) +{ + int i, index, something_outside_parens, regfound; + int parencount; + char *pt; + char temp[MAX_TOKEN_LENGTH+1]; + + pt = tokens[tnum]; + + if (pt[0] == '%') + { + // register + for (i=0 ; i '9') || (pt[2] < '0')) + { + i = 2; + printf ("offset "); + + parencount = 1; + + while ((pt[i] != ')') || (parencount > 1)) + { + if (!pt[i]) + { + fprintf (stderr, "mismatched parens"); + errorexit (); + } + + if (pt[i] == ')') + parencount--; + else if (pt[i] == '(') + parencount++; + + printf ("%c", pt[i]); + i++; + } + } + else + { + pt++; + + parencount = 1; + + for (i=1 ; (pt[i] != ')') || (parencount > 1) ; i++) + { + if (!pt[i]) + { + fprintf (stderr, "mismatched parens"); + errorexit (); + } + + if (pt[i] == ')') + parencount--; + else if (pt[i] == '(') + parencount++; + } + + pt[i] = 0; + + if ((pt[1] == '0') && ((pt[2] == 'x') || (pt[2] == 'X'))) + { + printf ("0%sh", &pt[3]); + } + else + { + printf ("%s", &pt[1]); + } + } + } + else if ((pt[1] == '0') && ((pt[2] == 'x') || (pt[2] == 'X'))) + { + printf ("0%sh", &pt[3]); + } + else if ((pt[1] >= '0') && (pt[1] <= '9')) + { + printf ("%s", &pt[1]); + } + else + { + printf ("offset %s", &pt[1]); + } + } + else if (!notdata && ((pt[0] >= '0') && (pt[0] <= '9'))) + { + pt--; + + if ((pt[1] == '0') && ((pt[2] == 'x') || (pt[2] == 'X'))) + { + printf ("0%sh", &pt[3]); + } + else + { + printf ("%s", &pt[1]); + } + } + else + { + // must be a memory location + strcpy (temp, type); + index = strlen (temp); + + if (notdata) + temp[index++] = '['; + + something_outside_parens = 0; + + while (*pt) + { + if (index > (MAX_TOKEN_LENGTH - 10)) + { + fprintf (stderr, "Error: operand too long %s\n", + tokens[tnum]); + errorexit (); + } + + if (*pt != ')') + { + if (*pt == '(') + { + if (something_outside_parens) + temp[index++] = '+'; + } + else if (*pt == '%') + { + regfound = 0; + + for (i=0 ; i= '1') && (*pt <= '8')) + { + temp[index++] = '*'; + temp[index++] = *pt; + } + else if (*pt != ')') + { + if (temp[index-1] != '+') + temp[index++] = '+'; + } + } + else + { + something_outside_parens = 1; + + // handle hexadecimal constants in addresses + if ((*pt == '0') && + ((*(pt+1) == 'x') || (*(pt+1) == 'X'))) + { + pt += 2; + + do + { + temp[index++] = *pt++; + } while (((*pt >= '0') && (*pt <= '9')) || + ((*pt >= 'a') && (*pt <= 'f')) || + ((*pt >= 'A') && (*pt <= 'F'))); + + pt--; + temp[index++] = 'h'; + } + else + { + temp[index++] = *pt; + } + } + } + + pt++; + } + + if (notdata) + temp[index++] = ']'; + + temp[index] = 0; + printf ("%s", temp); + } +} + + +void datasegstart (void) +{ + if (currentseg == DATASEG) + return; + + if (currentseg == TEXTSEG) + printf ("_TEXT ENDS\n"); + + printf ("_DATA SEGMENT"); + + currentseg = DATASEG; +} + + +void textsegstart (void) +{ + if (currentseg == TEXTSEG) + return; + + if (currentseg == DATASEG) + printf ("_DATA ENDS\n"); + + printf ("_TEXT SEGMENT"); + + currentseg = TEXTSEG; +} + + +void emitdata (void) +{ + int i; + + for (i=1 ; i<(tokennum-1) ; i++) + printf (" %s,", tokens[i]); + + printf (" %s", tokens[tokennum-1]); +} + + +void emitonedata (void) +{ + + printf (" %s", tokens[1]); +} + + +void emitonecalldata (void) +{ + int i, isaddr, len; + + if (tokens[1][0] == '*') + { + printf (" dword ptr[%s]", &tokens[1][1]); + } + else + { + isaddr = 0; + len = strlen(tokens[1]); + + for (i=0 ; i 127) || + (c == ',')) + { + return WHITESPACE; + } + + return NOT_WHITESPACE; +} + + +int gettoken (void) +{ + char c; + int count, parencount; + tokenstat stat; + + do + { + if ((c = getchar ()) == EOF) + return FILE_DONE; + + if ((stat = whitespace (c)) == LINE_DONE) + return LINE_DONE; + } while (stat == WHITESPACE); + + token[0] = c; + count = 1; + + if (c == '~') + { + count--; + token[count++] = 'n'; + token[count++] = 'o'; + token[count++] = 't'; + token[count++] = ' '; + } + + if (c == '(') + { + do + { + if ((c = getchar ()) == EOF) + { + fprintf (stderr, "EOF in middle of parentheses\n"); + errorexit (); + } + + token[count++] = c; + + } while (c != ')'); + } + + for ( ;; ) + { + if ((c = getchar ()) == EOF) + { + token[count] = 0; + return TOKEN_AVAILABLE; + } + + if (whitespace (c) == LINE_DONE) + { + if (ungetc (c, stdin) == EOF) + { + fprintf (stderr, "Couldn't unget character\n"); + errorexit (); + } + + token[count] = 0; + return TOKEN_AVAILABLE; + } + + if (whitespace (c) == WHITESPACE) + { + token[count] = 0; + return TOKEN_AVAILABLE; + } + + if (count >= MAX_TOKEN_LENGTH) + { + fprintf (stderr, "Error: token too long\n"); + errorexit (); + } + + token[count++] = c; + + if (c == '~') + { + count--; + token[count++] = 'n'; + token[count++] = 'o'; + token[count++] = 't'; + token[count++] = ' '; + } + else if (c == '(') + { + parencount = 1; + + do + { + if ((c = getchar ()) == EOF) + { + fprintf (stderr, "EOF in middle of parentheses\n"); + errorexit (); + } + + if (c == '(') + parencount++; + else if (c == ')') + parencount--; + + if (c == '~') + { + token[count++] = 'n'; + token[count++] = 'o'; + token[count++] = 't'; + token[count++] = ' '; + } + else + { + token[count++] = c; + } + + } while ((c != ')') || (parencount > 0)); + } + } +} + + +tokenstat parseline (void) +{ + tokenstat stat; + int i, j, firsttoken, labelfound; + int mnemfound; + + firsttoken = 1; + tokennum = 0; + labelfound = 0; + + for ( ;; ) + { + token = tokens[tokennum]; + stat = gettoken (); + + switch (stat) + { + case FILE_DONE: + return FILE_DONE; + + case LINE_DONE: + if (!firsttoken && tokennum) + { + mnemfound = 0; + + for (i=0 ; i 0) && + (parsedata[i].numtokens != tokennum)) || + ((parsedata[i].numtokens < 0) && + (tokennum < -parsedata[i].numtokens))) + { + fprintf (stderr, "mismatched number of tokens\n"); + + for (j=0 ; j= MAX_TOKENS) + { + fprintf (stderr, "Error: too many tokens\n"); + exit (0); + } + + tokennum++; + + break; + + default: + fprintf (stderr, "Error: unknown tokenstat %d\n", stat); + exit (0); + } + } +} + + +void main (int argc, char **argv) +{ + tokenstat stat; + + printf (" .386P\n" + " .model FLAT\n"); + inline = 1; + outline = 3; + + for ( ;; ) + { + stat = parseline (); + inline++; + + switch (stat) + { + case FILE_DONE: + if (currentseg == TEXTSEG) + printf ("_TEXT ENDS\n"); + else if (currentseg == DATASEG) + printf ("_DATA ENDS\n"); + + printf (" END\n"); + exit (0); + + case PARSED_OKAY: + break; + + default: + fprintf (stderr, "Error: unknown tokenstat %d\n", stat); + exit (0); + } + } +} + diff --git a/WinQuake/gas2masm/gas2masm.dsp b/WinQuake/gas2masm/gas2masm.dsp new file mode 100644 index 0000000..de661a4 --- /dev/null +++ b/WinQuake/gas2masm/gas2masm.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="gas2masm" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=gas2masm - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "gas2masm.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "gas2masm.mak" CFG="gas2masm - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "gas2masm - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "gas2masm - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "gas2masm - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir ".\Release" +# PROP BASE Intermediate_Dir ".\Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir ".\Release" +# PROP Intermediate_Dir ".\Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "gas2masm - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir ".\Debug" +# PROP BASE Intermediate_Dir ".\Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir ".\Debug" +# PROP Intermediate_Dir ".\Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /YX /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 + +!ENDIF + +# Begin Target + +# Name "gas2masm - Win32 Release" +# Name "gas2masm - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90" +# Begin Source File + +SOURCE=.\gas2masm.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/WinQuake/gas2masm/gas2masm.dsw b/WinQuake/gas2masm/gas2masm.dsw new file mode 100644 index 0000000..b536254 --- /dev/null +++ b/WinQuake/gas2masm/gas2masm.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "gas2masm"=.\gas2masm.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/WinQuake/gas2masm/gas2masm.mdp b/WinQuake/gas2masm/gas2masm.mdp new file mode 100644 index 0000000..76bfd31 Binary files /dev/null and b/WinQuake/gas2masm/gas2masm.mdp differ diff --git a/WinQuake/gas2masm/gas2masm.plg b/WinQuake/gas2masm/gas2masm.plg new file mode 100644 index 0000000..067e7c7 --- /dev/null +++ b/WinQuake/gas2masm/gas2masm.plg @@ -0,0 +1,32 @@ + + +
+

Build Log

+

+--------------------Configuration: gas2masm - Win32 Debug-------------------- +

+

Command Lines

+Creating temporary file "C:\TEMP\RSP730.tmp" with contents +[ +/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /Fp".\Debug/gas2masm.pch" /YX /Fo".\Debug/" /Fd".\Debug/" /FD /c +"D:\Work\quake source\WinQuake\gas2masm\gas2masm.c" +] +Creating command line "cl.exe @C:\TEMP\RSP730.tmp" +Creating temporary file "C:\TEMP\RSP731.tmp" with contents +[ +kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:".\Debug/gas2masm.pdb" /debug /machine:I386 /out:".\Debug/gas2masm.exe" +".\Debug\gas2masm.obj" +] +Creating command line "link.exe @C:\TEMP\RSP731.tmp" +

Output Window

+Compiling... +gas2masm.c +Linking... + + + +

Results

+gas2masm.exe - 0 error(s), 0 warning(s) +
+ + -- cgit v1.2.3