* Handle numeric values as radix=10 by default in ollyasm

- Fixes rarc ATT output format for x86
* Fix commandline flags parsing in rarc2
  - Honor intel syntax with ".intel_syntax noprefix" header
    - GAS can now compile att and intel syntax rarc2 output
* Handle .intel_syntax and .att_syntax directives in rasm2
This commit is contained in:
pancake 2010-09-10 13:17:24 +02:00
parent 09f5ca50a6
commit f4ada2309f
4 changed files with 32 additions and 19 deletions

View File

@ -78,7 +78,7 @@ static void emit_syscall_args(int nargs) {
if (attsyntax)
rcc_printf (" mov %d(%%"R_SP"), %%%s\n", k, regs[j+1]);
else
rcc_printf (" mov %s, dword ["R_SP"%c%d]\n", regs[j+1], k>0?'+':' ', k);
rcc_printf (" mov %s, dword ptr ["R_SP"%c%d]\n", regs[j+1], k>0?'+':' ', k);
}
}
@ -169,8 +169,8 @@ static void emit_get_var (int type, char *out, int idx) {
}
} else {
switch (type) {
case 0: sprintf (out, "dword ["R_BP"%c%d]", idx>0?' ':'+', -idx); break; /* variable */
case 1: sprintf(out, "dword ["R_SP"%c%d]", idx>0?'+':' ', idx); break; /* argument */
case 0: sprintf (out, "dword ptr ["R_BP"%c%d]", idx>0?' ':'+', -idx); break; /* variable */
case 1: sprintf(out, "dword ptr ["R_SP"%c%d]", idx>0?'+':' ', idx); break; /* argument */
}
}
}
@ -184,7 +184,7 @@ static void emit_load_ptr(const char *dst) {
eprintf ("HACK HACK HACK\n");
// XXX: 32/64bit care
if (attsyntax) rcc_printf (" leal %d(%%"R_BP"), %%"R_AX"\n", d);
else rcc_printf (" leal "R_AX", dword ["R_BP"+%d]\n", d);
else rcc_printf (" leal "R_AX", dword ptr ["R_BP"+%d]\n", d);
//rcc_printf (" movl %%"R_BP", %%"R_AX"\n");
//rcc_printf (" addl $%d, %%"R_AX"\n", d);
}

View File

@ -723,6 +723,7 @@ static void parseflag(const char *arg) {
break;
case 'm':
showmain = 1;
break;
case 's':
attsyntax = 1;
break;
@ -742,28 +743,34 @@ static void parseflag(const char *arg) {
}
int main(int argc, char **argv) {
int fd = 0;
int once=0, i, fd = 0;
char ch;
rcc_init ();
while (argc-->0) {
if (argc>0) {
if (argv[argc][0]!='-') {
file = argv[argc];
fd = open (file, O_RDONLY);
} else parseflag (argv[argc]+1);
}
for (i=1;i<argc;i++) {
if (argv[i][0]=='-')
parseflag (argv[i]+1);
else break;
}
do {
if (i!=argc)
fd = open ((file=argv[i++]), O_RDONLY);
if (fd == -1) {
eprintf ("Cannot open '%s'.\n", file);
return 1;
}
if (showmain) {
emit->call ("main", 0);
emit->trap ();
if (!once) {
once++;
if (!attsyntax)
rcc_printf (".intel_syntax noprefix\n");
if (showmain) {
emit->call ("main", 0);
emit->trap ();
}
}
for (line=1; read (fd, &ch, 1)==1; )
parsechar (ch);
close (fd);
}
} while (i<argc);
rcc_flush ();
return 0;
}

View File

@ -262,14 +262,16 @@ static void Scanasm(int mode) {
asmerror="Unknown identifier";
scan=SCAN_ERR; return; }
else if (isdigit(*asmcmd)) { // Constant
base=0; maxdigit=0; decimal=hex=0L; floating=0.0;
base=10; maxdigit=0; decimal=hex=0L; floating=0.0;
if (asmcmd[0]=='0' && toupper(asmcmd[1])=='X') {
base=16; asmcmd+=2; }; // Force hexadecimal number
//printf("DIGIT (%s) %d\n", asmcmd, base);
while (1) {
if (isdigit(*asmcmd)) {
decimal=decimal*10+(*asmcmd)-'0';
floating=floating*10.0+(*asmcmd)-'0';
hex=hex*16+(*asmcmd)-'0';
//hex=hex*16+(*asmcmd)-'0';
hex=hex*base+(*asmcmd)-'0';
if (maxdigit==0) maxdigit=9;
asmcmd++; }
else if (isxdigit(*asmcmd)) {

View File

@ -316,7 +316,11 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
continue;
} else if (*ptr_start == '.') { /* pseudo */
ptr = ptr_start;
if (!memcmp (ptr, ".string ", 8))
if (!memcmp (ptr, ".intel_syntax", 13))
a->syntax = R_ASM_SYNTAX_INTEL;
else if (!memcmp (ptr, ".att_syntax", 10))
a->syntax = R_ASM_SYNTAX_ATT;
else if (!memcmp (ptr, ".string ", 8))
ret = r_asm_pseudo_string (&aop, ptr+8);
else if (!memcmp (ptr, ".arch ", 6))
ret = r_asm_pseudo_arch (a, ptr+6);