Make the big instruction arrays "const"

Make the big instruction arrays "const", so they end up in readonly
storage.  While we're at it, move their prototypes into insns.h.
This commit is contained in:
H. Peter Anvin 2007-09-11 04:16:57 +00:00
parent ea6bfb8107
commit 3360d79369
4 changed files with 17 additions and 17 deletions

View File

@ -90,8 +90,6 @@
#include "regflags.c"
#include "regvals.c"
extern struct itemplate *nasm_instructions[];
typedef struct {
int sib_present; /* is a SIB byte necessary? */
int bytes; /* # of bytes of offset needed */
@ -106,7 +104,7 @@ static ListGen *list;
static int32_t calcsize(int32_t, int32_t, int, insn *, const char *);
static void gencode(int32_t, int32_t, int, insn *, const char *, int32_t);
static int matches(struct itemplate *, insn *, int bits);
static int matches(const struct itemplate *, insn *, int bits);
static int32_t regflag(const operand *);
static int32_t regval(const operand *);
static int rexflags(int, int32_t, int);
@ -215,7 +213,7 @@ int32_t assemble(int32_t segment, int32_t offset, int bits, uint32_t cp,
insn * instruction, struct ofmt *output, efunc error,
ListGen * listgen)
{
struct itemplate *temp;
const struct itemplate *temp;
int j;
int size_prob;
int32_t insn_end;
@ -550,7 +548,7 @@ int32_t assemble(int32_t segment, int32_t offset, int bits, uint32_t cp,
int32_t insn_size(int32_t segment, int32_t offset, int bits, uint32_t cp,
insn * instruction, efunc error)
{
struct itemplate *temp;
const struct itemplate *temp;
errfunc = error; /* to pass to other functions */
cpu = cp;
@ -1516,7 +1514,7 @@ static int rexflags(int val, int32_t flags, int mask)
return rex & mask;
}
static int matches(struct itemplate *itemp, insn * instruction, int bits)
static int matches(const struct itemplate *itemp, insn * instruction, int bits)
{
int i, size[3], asize, oprs, ret;

View File

@ -19,8 +19,6 @@
#include "names.c"
extern struct itemplate **itable[];
/*
* Flags that go into the `segment' field of `insn' structures
* during disassembly.
@ -313,7 +311,7 @@ static uint8_t *do_ea(uint8_t *data, int modrm, int asize,
* Determine whether the instruction template in t corresponds to the data
* stream in data. Return the number of bytes matched if so.
*/
static int matches(struct itemplate *t, uint8_t *data, int asize,
static int matches(const struct itemplate *t, uint8_t *data, int asize,
int osize, int segsize, int rep, insn * ins,
int rex, int *rexout, int lock)
{
@ -582,7 +580,7 @@ static int matches(struct itemplate *t, uint8_t *data, int asize,
int32_t disasm(uint8_t *data, char *output, int outbufsize, int segsize,
int32_t offset, int autosync, uint32_t prefer)
{
struct itemplate **p, **best_p;
const struct itemplate * const *p, * const *best_p;
int length, best_length = 0;
char *segover;
int rep, lock, asize, osize, i, slen, colon, rex, rexout, best_rex;

View File

@ -27,6 +27,10 @@ struct itemplate {
uint32_t flags; /* some flags */
};
/* Tables for the assembler and disassembler, respectively */
extern const struct itemplate * const nasm_instructions[];
extern const struct itemplate * const * const itable[];
/*
* this define is used to signify the end of an itemplate
*/

View File

@ -74,14 +74,14 @@ if ( !defined($output) || $output eq 'a' ) {
print A "\n";
foreach $i (@opcodes, @opcodes_cc) {
print A "static struct itemplate instrux_${i}[] = {\n";
print A "static const struct itemplate instrux_${i}[] = {\n";
$aname = "aa_$i";
foreach $j (@$aname) {
print A " $j\n";
}
print A " ITEMPLATE_END\n};\n\n";
}
print A "struct itemplate *nasm_instructions[] = {\n";
print A "const struct itemplate * const nasm_instructions[] = {\n";
foreach $i (@opcodes, @opcodes_cc) {
print A " instrux_${i},\n";
}
@ -101,7 +101,7 @@ if ( !defined($output) || $output eq 'd' ) {
print D "#include \"insns.h\"\n";
print D "\n";
print D "static struct itemplate instrux[] = {\n";
print D "static const struct itemplate instrux[] = {\n";
foreach $j (@big) {
print D " $j\n";
}
@ -109,7 +109,7 @@ if ( !defined($output) || $output eq 'd' ) {
for ($c=0; $c<256; $c++) {
$h = sprintf "%02X", $c;
print D "static struct itemplate *itable_${h}[] = {\n";
print D "static const struct itemplate * const itable_${h}[] = {\n";
$aname = "dd_$h";
foreach $j (@$aname) {
print D " instrux + $j,\n";
@ -117,7 +117,7 @@ if ( !defined($output) || $output eq 'd' ) {
print D " NULL\n};\n\n";
}
print D "struct itemplate **itable[] = {\n";
print D "const struct itemplate * const * const itable[] = {\n";
for ($c=0; $c<256; $c++) {
printf D " itable_%02X,\n", $c;
}
@ -162,7 +162,7 @@ if ( !defined($output) || $output eq 'n' ) {
" - don't edit it */\n\n";
print N "/* This file in included by names.c */\n\n";
print N "static const char *insn_names[] = {";
print N "static const char * const insn_names[] = {";
$first = 1;
foreach $i (@opcodes) {
print N "," if ( !$first );
@ -186,7 +186,7 @@ if ( !defined($output) || $output eq 'n' ) {
print N "\n};\n\n";
print N "/* and the corresponding opcodes */\n";
print N "static int ico[] = {";
print N "static const int ico[] = {";
$first = 1;
foreach $i (@opcodes_cc) {
print N "," if ( !$first );