mini assembler - support for toolcalls. uses the Nifty List tool list.

This commit is contained in:
Kelvin Sherlock 2019-04-14 23:28:08 -04:00
parent b561811394
commit 4c55800e23
2 changed files with 94 additions and 4 deletions

View File

@ -62,6 +62,12 @@ enum {
MNEMONIC_LAST
};
enum {
TOOL_CALL = MNEMONIC_LAST,
GSOS_CALL,
MLI_CALL
};
struct mnemonic_entry {
const char *name;
@ -519,6 +525,24 @@ static const char *parse_opcode(const char *cp, struct cookie *cookie) {
/*!re2c
* { return NULL; }
'_' [A-Za-z] {0,16} / (ws|eol) {
extern int lookup_tool_number(const char *name, unsigned vector);
char name[20];
int tool;
memcpy(name, cp, YYCURSOR - cp);
name[YYCURSOR - cp] = 0;
tool = lookup_tool_number(name, 0xe10000);
if (tool <= 0) return NULL;
cookie->mnemonic = TOOL_CALL;
cookie->operand = tool;
return ltrim(YYCURSOR);
}
[A-Za-z]{3} / (ws|eol) {
uint32_t tmp = 0;
@ -670,6 +694,19 @@ static int parse_line(const char *cp, uint32_t *pc) {
if (!cp) return error(offset, "bad opcode");
offset = cp - start;
if (cookie.mnemonic == TOOL_CALL) {
if (*cp) return error(offset, "invalid address mode");
if (g_disasm_psr & 0x30) return error(0, "8-bit m/x");
set_memory_c(addr++, 0xa2, 0);
set_memory_c(addr++, cookie.operand >> 0, 0);
set_memory_c(addr++, cookie.operand >> 8, 0);
set_memory_c(addr++, 0x22, 0);
set_memory_c(addr++, 0x00, 0);
set_memory_c(addr++, 0x00, 0);
set_memory_c(addr++, 0xe1, 0);
goto out;
}
if (*cp) {
cp = parse_operand(cp, &cookie);
@ -703,6 +740,7 @@ static int parse_line(const char *cp, uint32_t *pc) {
}
out:
fputs("\r\x1b[A\x1b[K", stdout);
do_list(cookie.pc, 1);
*pc = addr;

View File

@ -409,6 +409,12 @@ struct tool *tools = NULL;
int tool_count = 0;
int tool_alloc = 0;
struct tool *tool_names = NULL;
int tool_name_count = 0;
static void add_tool(struct tool *t) {
if (tool_count == tool_alloc) {
size_t size = (tool_alloc + 1024) * sizeof(struct tool);
@ -436,11 +442,20 @@ static int tool_compare(const void *a, const void *b) {
const struct tool *bb = b;
int rv = (int)aa->vector - (int)bb->vector;
if (rv == 0)
rv = (int)aa->number - (int)bb->number;
if (rv == 0) rv = (int)aa->number - (int)bb->number;
return rv;
}
static int tool_name_compare(const void *a, const void *b) {
const struct tool *aa = a;
const struct tool *bb = b;
int rv = (int)aa->vector - (int)bb->vector;
if (rv == 0) rv = strcasecmp(aa->name, bb->name);
return rv;
}
/* nifty list */
/*
* format:
@ -564,14 +579,51 @@ prefix:
}
fclose(f);
qsort(tools, tool_count, sizeof(struct tool), tool_compare);
fclose(f);
/* name index for tools and gs/os calls */
int tmp = 0;
int i;
for (i = 0; i < tool_count; ++i) {
unsigned v = tools[i].vector;
if (v == 0xe10000 || v == 0xe100a8 || v == 0xbf00)
++tmp;
}
if (!tmp) return;
tool_name_count = tmp;
tool_names = malloc(sizeof(struct tool) * tmp);
if (!tool_names) return;
tool_name_count = tmp;
tmp = 0;
for(i = 0; i < tool_count; ++i) {
unsigned v = tools[i].vector;
if (v == 0xe10000 || v == 0xe100a8 || v == 0xbf00)
tool_names[tmp++] = tools[i];
}
qsort(tool_names, tool_name_count, sizeof(struct tool), tool_name_compare);
}
const char *debug_tool_name(unsigned number, unsigned vector) {
if (!tool_count) return NULL;
struct tool tmp = { 0, number, vector };
struct tool *t = bsearch(&tmp, tools, tool_count, sizeof(struct tool), tool_compare);
if (t) return t->name;
return NULL;
}
}
int lookup_tool_number(const char *name, unsigned vector) {
if (!tool_name_count) return 0;
struct tool tmp = { (char *)name, 0, vector};
struct tool *t = bsearch(&tmp, tool_names, tool_name_count, sizeof(struct tool), tool_name_compare);
if (!t) return 0;
return t->number;
}