view lwdisasm/lwdisasm.h @ 416:1d69ed28f175

Fixed offset problem with emission of incomplete references at start of insn
author lost@l-w.ca
date Tue, 10 Aug 2010 22:00:21 -0600
parents cba03436c720
children
line wrap: on
line source

/*
lwdisasm.h

Copyright © 2010 William Astle

This file is part of LWTOOLS.

LWTOOLS is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ____lwdisasm_h_seen____
#define ____lwdisasm_h_seen____

#include <stdint.h>

enum
{
	INPUT_RAW = 0,
	INPUT_DECB,
	INPUT_OBJ,
	INPUT_OS9
};

enum
{
	TARGET_6809 = 0,
	TARGET_6309
};

enum
{
	ADDR_DIR = 0,
	ADDR_EXT,
	ADDR_IND,
	ADDR_IMM8,
	ADDR_IMM16,
	ADDR_IMM32,
	ADDR_INH,
	ADDR_RTOR,
	ADDR_PSHPULS,
	ADDR_PSHPULU,
	ADDR_IMM8DIR,
	ADDR_IMM8IND,
	ADDR_IMM8EXT,
	ADDR_BITBIT,
	ADDR_REL8,
	ADDR_REL16,
	ADDR_PAGE1,
	ADDR_PAGE2,
	ADDR_TFMPP,
	ADDR_TFMMM,
	ADDR_TFMPC,
	ADDR_TFMCP
};


typedef struct rangedata_s rangedata_t;
struct rangedata_s
{
	int min;
	int max;
	int type;
	rangedata_t *next;
	rangedata_t *prev;
};

typedef struct symbol_s symbol_t;
struct symbol_s
{
	int address;
	int section;
	char *symbol;
	symbol_t *next;
};

typedef struct linedata_s linedata_t;
struct linedata_s
{
	int address;
	int sectionref;
	int length;
	int type;
	int target;
	char *disasm;
	uint8_t *bytes;
	int isref;
	symbol_t *symbol;
	linedata_t *next;
	linedata_t *prev;
};
typedef struct instab_s
{
	char *op;			// mneumonic
	int addrmode;		// addressing mode
} instab_t;

typedef struct disasmstate_s
{
	int input_type;
	int debug_level;
	char *output_file;
	char *input_file;
	int target;
	uint8_t *filedata;	// the file data
	long filelen;		// length of the file data
	int base;			// base address (raw)
	int entry;			// entry address
	int dpval;			// DP value
	linedata_t *lhead;	// start of lines table
	linedata_t *ltail;	// end of lines table
	rangedata_t *rhead;	// start of range table
	rangedata_t *rtail;	// end of range table

	instab_t *page0;	// instruction table 0
	instab_t *page1;	// instruction table 1
	instab_t *page2;	// instruction table 2
	
	int curoff;			// current disassembly point
	rangedata_t *crange; // current range
	
	symbol_t *symbols;	// symbol tables
} disasmstate_t;



extern instab_t page0_6809[];
extern instab_t page1_6809[];
extern instab_t page2_6809[];

extern instab_t page0_6309[];
extern instab_t page1_6309[];
extern instab_t page2_6309[];

enum
{
	type_code = 0,
	type_data = 1
};

extern void register_range(disasmstate_t *as, int min, int max, int type);
extern rangedata_t *lookup_range(disasmstate_t *as, int addr);
extern int fetch_byte(disasmstate_t *as);
extern linedata_t *disasm_insn(disasmstate_t *as);
extern symbol_t *register_symbol(disasmstate_t *as, int addr, int section, char *symbol);
extern void attach_symbols(disasmstate_t *as);
extern void redisasm_insn(disasmstate_t *as, linedata_t *l);
extern symbol_t *find_symbol(disasmstate_t *as, int addr, int section);
#endif // ____lwdisasm_h_seen____