Skip to content

Commit 4f77aec

Browse files
authored
Merge pull request #354 from zu2/mc6800
mach/mc6800: Add MC6800 code generator support
2 parents 6074574 + b1b8543 commit 4f77aec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6336
-0
lines changed

mach/mc6800/Action

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name "Motorola 6800 assembler"
2+
dir as
3+
end
4+
name "Motorola 6800 backend"
5+
dir cg
6+
end
7+
#name "Motorola 6800 download program(s)"
8+
#dir dl
9+
#end
10+
name "Motorola 6800 EM library"
11+
dir libem
12+
end
13+
name "Motorola 6800 etext,edata,end library"
14+
dir libend
15+
end
16+
name "Motorola 6800 MON library"
17+
dir libmon
18+
end
19+
name "Motorola 6800 system call library"
20+
dir libsys
21+
end

mach/mc6800/as/mach0.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3+
* See the copyright notice in the ACK home directory, in the file "Copyright".
4+
*/
5+
#define RCSID0 "$Id$"
6+
7+
/*
8+
* Motorola 6800 options
9+
*/
10+
11+
#define BYTES_REVERSED
12+
#define WORDS_REVERSED
13+
#define THREE_PASS
14+
#define LISTING
15+
#define RELOCATION
16+
#define DEBUG 1

mach/mc6800/as/mach1.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3+
* See the copyright notice in the ACK home directory, in the file "Copyright".
4+
*/
5+
#define RCSID1 "$Id$"
6+
7+
/*
8+
* Motorola 6800 C declarations
9+
*/
10+
11+
void branch(int opc, expr_t exp);
12+

mach/mc6800/as/mach2.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3+
* See the copyright notice in the ACK home directory, in the file "Copyright".
4+
*/
5+
#define RCSID2 "$Id$"
6+
7+
/*
8+
* Motorola 6800 tokens
9+
*/
10+
11+
%token <y_word> X
12+
%token <y_word> EXTENSION
13+
%token <y_word> NOARG
14+
%token <y_word> BRANCH
15+
%token <y_word> AOP
16+
%token <y_word> XOP
17+
18+
%type <y_word> memref
19+
20+
%nonassoc EXTENSION

mach/mc6800/as/mach3.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3+
* See the copyright notice in the ACK home directory, in the file "Copyright".
4+
*/
5+
#define RCSID3 "$Id$"
6+
7+
/*
8+
* Motorola 6800 keywords
9+
*/
10+
{0, EXTENSION, 0, ".l"},
11+
{0, EXTENSION, 8, ".h"},
12+
{0, X, 0, "x"},
13+
{0, NOARG, 0x01, "nop"},
14+
{0, NOARG, 0x06, "tap"},
15+
{0, NOARG, 0x07, "tpa"},
16+
{0, NOARG, 0x08, "inx"},
17+
{0, NOARG, 0x09, "dex"},
18+
{0, NOARG, 0x0A, "clv"},
19+
{0, NOARG, 0x0B, "sev"},
20+
{0, NOARG, 0x0C, "clc"},
21+
{0, NOARG, 0x0D, "sec"},
22+
{0, NOARG, 0x0E, "cli"},
23+
{0, NOARG, 0x0F, "sei"},
24+
{0, NOARG, 0x10, "sba"},
25+
{0, NOARG, 0x11, "cba"},
26+
{0, NOARG, 0x16, "tab"},
27+
{0, NOARG, 0x17, "tba"},
28+
{0, NOARG, 0x19, "daa"},
29+
{0, NOARG, 0x1B, "aba"},
30+
{0, BRANCH, 0x20, "bra"},
31+
{0, BRANCH, 0x22, "bhi"},
32+
{0, BRANCH, 0x23, "bls"},
33+
{0, BRANCH, 0x24, "bcc"},
34+
{0, BRANCH, 0x24, "bhs"}, /* bcc */
35+
{0, BRANCH, 0x25, "bcs"},
36+
{0, BRANCH, 0x25, "blo"}, /* bcs */
37+
{0, BRANCH, 0x26, "bne"},
38+
{0, BRANCH, 0x27, "beq"},
39+
{0, BRANCH, 0x28, "bvc"},
40+
{0, BRANCH, 0x29, "bvs"},
41+
{0, BRANCH, 0x2A, "bpl"},
42+
{0, BRANCH, 0x2B, "bmi"},
43+
{0, BRANCH, 0x2C, "bge"},
44+
{0, BRANCH, 0x2D, "blt"},
45+
{0, BRANCH, 0x2E, "bgt"},
46+
{0, BRANCH, 0x2F, "ble"},
47+
{0, NOARG, 0x30, "tsx"},
48+
{0, NOARG, 0x31, "ins"},
49+
{0, NOARG, 0x32, "pula"},
50+
{0, NOARG, 0x33, "pulb"},
51+
{0, NOARG, 0x34, "des"},
52+
{0, NOARG, 0x35, "txs"},
53+
{0, NOARG, 0x36, "psha"},
54+
{0, NOARG, 0x37, "pshb"},
55+
{0, NOARG, 0x39, "rts"},
56+
{0, NOARG, 0x3B, "rti"},
57+
{0, NOARG, 0x3E, "wai"},
58+
{0, NOARG, 0x3F, "swi"},
59+
{0, NOARG, 0x40, "nega"},
60+
{0, NOARG, 0x43, "coma"},
61+
{0, NOARG, 0x44, "lsra"},
62+
{0, NOARG, 0x46, "rora"},
63+
{0, NOARG, 0x47, "asra"},
64+
{0, NOARG, 0x48, "asla"},
65+
{0, NOARG, 0x48, "lsla"},
66+
{0, NOARG, 0x49, "rola"},
67+
{0, NOARG, 0x4A, "deca"},
68+
{0, NOARG, 0x4C, "inca"},
69+
{0, NOARG, 0x4D, "tsta"},
70+
{0, NOARG, 0x4F, "clra"},
71+
{0, NOARG, 0x50, "negb"},
72+
{0, NOARG, 0x53, "comb"},
73+
{0, NOARG, 0x54, "lsrb"},
74+
{0, NOARG, 0x56, "rorb"},
75+
{0, NOARG, 0x57, "asrb"},
76+
{0, NOARG, 0x58, "aslb"},
77+
{0, NOARG, 0x58, "lslb"},
78+
{0, NOARG, 0x59, "rolb"},
79+
{0, NOARG, 0x5A, "decb"},
80+
{0, NOARG, 0x5C, "incb"},
81+
{0, NOARG, 0x5D, "tstb"},
82+
{0, NOARG, 0x5F, "clrb"},
83+
{0, AOP, 0x60, "neg"},
84+
{0, AOP, 0x63, "com"},
85+
{0, AOP, 0x64, "lsr"},
86+
{0, AOP, 0x66, "ror"},
87+
{0, AOP, 0x67, "asr"},
88+
{0, AOP, 0x68, "asl"},
89+
{0, AOP, 0x68, "lsl"},
90+
{0, AOP, 0x69, "rol"},
91+
{0, AOP, 0x6A, "dec"},
92+
{0, AOP, 0x6C, "inc"},
93+
{0, AOP, 0x6D, "tst"},
94+
{0, XOP, 0x6E, "jmp"},
95+
{0, AOP, 0x6F, "clr"},
96+
{0, BRANCH, 0x8D, "bsr"},
97+
{0, XOP, 0xA0, "suba"},
98+
{0, XOP, 0xA1, "cmpa"},
99+
{0, XOP, 0xA2, "sbca"},
100+
{0, XOP, 0xA4, "anda"},
101+
{0, XOP, 0xA5, "bita"},
102+
{0, XOP, 0xA6, "ldaa"},
103+
{0, XOP, 0xA7, "staa"},
104+
{0, XOP, 0xA8, "eora"},
105+
{0, XOP, 0xA9, "adca"},
106+
{0, XOP, 0xAA, "oraa"},
107+
{0, XOP, 0xAB, "adda"},
108+
{0, XOP, 0xAC, "cpx"},
109+
{0, XOP, 0xAD, "jsr"},
110+
{0, XOP, 0xAE, "lds"},
111+
{0, XOP, 0xAF, "sts"},
112+
{0, XOP, 0xE0, "subb"},
113+
{0, XOP, 0xE1, "cmpb"},
114+
{0, XOP, 0xE2, "sbcb"},
115+
{0, XOP, 0xE4, "andb"},
116+
{0, XOP, 0xE5, "bitb"},
117+
{0, XOP, 0xE6, "ldab"},
118+
{0, XOP, 0xE7, "stab"},
119+
{0, XOP, 0xE8, "eorb"},
120+
{0, XOP, 0xE9, "adcb"},
121+
{0, XOP, 0xEA, "orab"},
122+
{0, XOP, 0xEB, "addb"},
123+
{0, XOP, 0xEE, "ldx"},
124+
{0, XOP, 0xEF, "stx"},

mach/mc6800/as/mach4.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#define RCSID4 "$Id$"
2+
3+
/*
4+
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
5+
* See the copyright notice in the ACK home directory, in the file "Copyright".
6+
*
7+
*/
8+
9+
/*
10+
* Motorola 6800 parsing rules
11+
*/
12+
13+
expr
14+
: expr EXTENSION
15+
{ $$.val = ($1.val >> $2) & 0xFF;
16+
#ifdef RELOCATION
17+
$$.typ = combine($1.typ, S_ABS, '&');
18+
/* This will generate an 'invalid operator' */
19+
/* error if $1.typ is not absolute after pass 1. */
20+
#else
21+
$$.typ = $1.typ; /* Even if $1.typ is relocatable, it should be */
22+
/* absolute by the final pass. */
23+
#endif /* RELOCATION */
24+
}
25+
;
26+
operation
27+
:
28+
NOARG
29+
{ emit1($1);}
30+
|
31+
BRANCH expr
32+
{ branch($1,$2);}
33+
|
34+
XOP '#' expr
35+
{ emit1($1 - 0x20);
36+
switch ($1 & 0x0F) {
37+
case 0x03:
38+
case 0x0C:
39+
case 0x0E:
40+
#ifdef RELOCATION
41+
if (rflag != 0 && PASS_RELO)
42+
newrelo($3.typ, RELO2|RELBR);
43+
#endif
44+
emit2($3.val);
45+
break;
46+
default:
47+
#ifdef RELOCATION
48+
if (rflag != 0 && PASS_RELO)
49+
newrelo($3.typ, RELO1);
50+
#endif
51+
emit1($3.val);
52+
}
53+
}
54+
|
55+
XOP '<' expr
56+
{ emit1($1 - 0x10);
57+
#ifdef RELOCATION
58+
if (rflag != 0 && PASS_RELO)
59+
newrelo($3.typ, RELO1);
60+
#endif
61+
emit1($3.val);
62+
}
63+
|
64+
memref expr
65+
{ emit1($1 + 0x10);
66+
#ifdef RELOCATION
67+
if (rflag != 0 && PASS_RELO)
68+
newrelo($2.typ, RELO2|RELBR);
69+
#endif
70+
emit2($2.val);
71+
}
72+
|
73+
memref expr ',' X
74+
{ emit1($1);
75+
#ifdef RELOCATION
76+
newrelo($2.typ, RELO1);
77+
#endif
78+
emit1($2.val);
79+
}
80+
;
81+
memref :
82+
AOP
83+
|
84+
XOP
85+
;

mach/mc6800/as/mach5.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3+
* See the copyright notice in the ACK home directory, in the file "Copyright".
4+
*/
5+
#define RCSID5 "$Id$"
6+
7+
/*
8+
* Motorola 6800 special routines
9+
*/
10+
11+
void branch(int opc,expr_t exp)
12+
{
13+
int sm, dist;
14+
int saving;
15+
16+
dist = exp.val - (DOTVAL + 2);
17+
if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
18+
dist -= DOTGAIN;
19+
sm = fitb(dist);
20+
if ((exp.typ & ~S_DOT) != DOTTYP)
21+
sm = 0;
22+
if (opc == 0x8D || opc == 0x20)
23+
saving = 1;
24+
else
25+
saving = 3;
26+
if (small(sm,saving)) {
27+
emit1(opc);
28+
emit1(dist);
29+
} else {
30+
if (opc == 0x8D) /* bsr */
31+
emit1(0xBD); /* jsr */
32+
else {
33+
if (opc != 0x20) { /* bra */
34+
35+
/* reverse condition : */
36+
37+
emit1(opc ^ 1);
38+
emit1(3);
39+
}
40+
emit1(0x7E); /* jmp */
41+
}
42+
#ifdef RELOCATION
43+
newrelo(exp.typ, RELO2 | RELBR);
44+
#endif
45+
emit2(exp.val);
46+
}
47+
}

mach/mc6800/cg/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from build.c import clibrary
2+
3+
clibrary(name="cg", hdrs={"mach.h": "./mach.h", "mach.c": "./mach.c"})

0 commit comments

Comments
 (0)