-
Notifications
You must be signed in to change notification settings - Fork 1
/
yfasm.h
76 lines (59 loc) · 1.87 KB
/
yfasm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <vector>
#include <string>
using namespace std;
/* yacc forward declerations */
int yyerror(const char* err);
int yylex();
extern int yylineno;
extern char* yytext;
/* this struct holds our cpu system description */
typedef struct {
unsigned long imem;
unsigned long imem_width;
unsigned long regfile;
unsigned long opcode_bits;
unsigned long reg_addr_bits;
unsigned long base;
} yf_sysinfo;
/* symbol type enumerations */
typedef enum {
ST_UNKNOWN = 0,
ST_LABEL,
ST_STRING,
ST_INT,
ST_REGISTER
} yf_symboltype;
/* symbol table entry */
typedef struct {
string name;
yf_symboltype type;
long lvalue;
} yf_symbol;
/* decleration of symbol table and string table */
typedef vector< yf_symbol > yf_symbols;
typedef vector< string > yf_strings;
/* declaration of global variables */
extern yf_sysinfo sys;
extern yf_symbols symbol_table;
extern yf_strings string_table;
/* our assembler instruction memory */
extern unsigned long* lpimem;
void alloc_imem( unsigned long newsize );
/* holds the highest code address */
extern unsigned long codesize;
/* symbol table functions */
int yf_getsymbol(string name);
yf_symbol yf_getsymbol(int i);
int yf_addsymbol(string name, yf_symboltype type, long lvalue);
int yf_addsymbol(string name, yf_symboltype type, string lvalue);
yf_symbol* yf_setsymbol(int i, yf_symboltype type, long value);
yf_symbol* yf_setsymbol(int i, yf_symboltype type, string value);
/* string table functions */
int yf_addstring( string s );
/* outputs the assembled instruction memory in various formats */
void out_fmt_hex();
void out_fmt_hex_waddr(int ipl); // ipl = instructions per line
// macro encodes ra, rb, rd into a single operand value
#define ENCR(ra, rb, rd) ( ((ra) << (sys.reg_addr_bits*2)) | ((rb) << sys.reg_addr_bits) | (rd) )
/* generates assembler instruction given opcode and operand */
int gen( unsigned long opcode, unsigned long operand );