2009-10-30 16:57:35 +01:00
|
|
|
/* 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",
|
this patch adds access to the debug breakpoints to
the kernel. They are not used atm, but having them in trunk allows them
to be easily used when needed. To set a breakpoint that triggers when
the variable foo is written to (the most common use case), one calls:
breakpoint_set(vir2phys((vir_bytes) &foo), 0,
BREAKPOINT_FLAG_MODE_GLOBAL |
BREAKPOINT_FLAG_RW_WRITE |
BREAKPOINT_FLAG_LEN_4);
It can later be disabled using:
breakpoint_set(vir2phys((vir_bytes) &foo), 0,
BREAKPOINT_FLAG_MODE_OFF);
There are some limitations:
- There are at most four breakpoints (hardware limit); the index of the
breakpoint (0-3) is specified as the second parameter of
breakpoint_set.
- The breakpoint exception in the kernel is not handled and causes a
panic; it would be reasonably easy to change this by inspecing DR6,
printing a message, disabling the breakpoint and continuing. However,
in my experience even just a panic can be very useful.
- Breakpoints can be set only in the part of the address space that is
in every page table. It is useful for the kernel, but to use this for
user processes would require saving and restoring the debug registers
as part of the context switch. Although the CPU provides support for
local breakpoints (I implemened this as BREAKPOINT_FLAG_LOCAL) they
only work if task switching is used.
2010-03-19 20:15:20 +01:00
|
|
|
"dr0", "dr1", "dr2", "dr3", "dr6", "dr7",
|
2009-10-30 16:57:35 +01:00
|
|
|
"st",
|
|
|
|
};
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
for (reg= 0; reg < arraysize(regs); reg++) {
|
|
|
|
if (strcmp(name, regs[reg]) == 0)
|
|
|
|
return reg+1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|