41d481b065
- an asmconv based tool for conversion from GNU ia32 assembly to ACK assembly - in contrast to asmconv it is a one way tool only - as the GNU assembly in Minix does not prefix global C symbols with _ gas2ack detects such symbols and prefixes them to be compliant with the ACK convention - gas2ack preserves comments and unexpanded macros - bunch of fixes to the asmconv GNU->ACK direction - support of more instructions that ACK does not know but are in use in Minix - it is meant as a temporary solution as long as ACK will be a supported compiler for the core system
87 lines
1.7 KiB
C
87 lines
1.7 KiB
C
/* asm86.c - 80X86 assembly intermediate Author: Kees J. Bot
|
|
* 24 Dec 1993
|
|
*/
|
|
#define nil 0
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include "asm86.h"
|
|
#include "asmconv.h"
|
|
#include "token.h"
|
|
|
|
expression_t *new_expr(void)
|
|
/* Make a new cell to build an expression. */
|
|
{
|
|
expression_t *e;
|
|
|
|
e= allocate(nil, sizeof(*e));
|
|
e->operator= -1;
|
|
e->left= e->middle= e->right= nil;
|
|
e->name= nil;
|
|
e->magic= 31624;
|
|
return e;
|
|
}
|
|
|
|
void del_expr(expression_t *e)
|
|
/* Delete an expression tree. */
|
|
{
|
|
if (e != nil) {
|
|
assert(e->magic == 31624);
|
|
e->magic= 0;
|
|
deallocate(e->name);
|
|
del_expr(e->left);
|
|
del_expr(e->middle);
|
|
del_expr(e->right);
|
|
deallocate(e);
|
|
}
|
|
}
|
|
|
|
asm86_t *new_asm86(void)
|
|
/* Make a new cell to hold an 80X86 instruction. */
|
|
{
|
|
asm86_t *a;
|
|
|
|
a= allocate(nil, sizeof(*a));
|
|
a->opcode= -1;
|
|
get_file(&a->file, &a->line);
|
|
a->optype= NONE;
|
|
a->oaz= 0;
|
|
a->rep= ONCE;
|
|
a->seg= DEFSEG;
|
|
a->args= nil;
|
|
a->magic= 37937;
|
|
a->raw_string = NULL;
|
|
return a;
|
|
}
|
|
|
|
void del_asm86(asm86_t *a)
|
|
/* Delete an 80X86 instruction. */
|
|
{
|
|
assert(a != nil);
|
|
assert(a->magic == 37937);
|
|
a->magic= 0;
|
|
del_expr(a->args);
|
|
deallocate(a->raw_string);
|
|
a->raw_string = NULL;
|
|
deallocate(a);
|
|
}
|
|
|
|
int isregister(const char *name)
|
|
/* True if the string is a register name. Return its size. */
|
|
{
|
|
static char *regs[] = {
|
|
"al", "bl", "cl", "dl", "ah", "bh", "ch", "dh",
|
|
"ax", "bx", "cx", "dx", "si", "di", "bp", "sp",
|
|
"eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp",
|
|
"cs", "ds", "es", "fs", "gs", "ss",
|
|
"cr0", "cr1", "cr2", "cr3", "cr4",
|
|
"st",
|
|
};
|
|
int reg;
|
|
|
|
for (reg= 0; reg < arraysize(regs); reg++) {
|
|
if (strcmp(name, regs[reg]) == 0)
|
|
return reg+1;
|
|
}
|
|
return 0;
|
|
}
|