4 * Copyright (C) 1998-2009 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * This Assember Ported by
25 * jhartman at compuserve dot com
26 * noice at noicedebugger dot com
28 * Modified from i51pst.c
30 * w_mckinnon at conknet dot com
37 char *cpu
= "Dallas Semiconductor [User Defined]";
46 * Opcode Cycle Definitions
48 #define OPCY_SDP ((char) (0xFF))
49 #define OPCY_ERR ((char) (0xFE))
51 /* OPCY_NONE ((char) (0x80)) */
52 /* OPCY_MASK ((char) (0x7F)) */
54 #define OPCY_CPU ((char) (0xFD))
55 #define OPCY_AMODE ((char) (0xFC))
56 #define OPCY_BITS ((char) (0xFB))
59 #define UN ((char) (OPCY_NONE | 0x00))
62 * ds8xcxxx Cycle Count
64 * opcycles = ds8pg1[opcode]
66 static char ds8pg1
[256] = {
67 /*--*--* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
68 /*--*--* - - - - - - - - - - - - - - - - */
69 /*00*/ 4,12,16, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
70 /*10*/ 12,12,16, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
71 /*20*/ 12,12,16, 4, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
72 /*30*/ 12,12,16, 4, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
73 /*40*/ 12,12, 8,12, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
74 /*50*/ 12,12, 8,12, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
75 /*60*/ 12,12, 8,12, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
76 /*70*/ 12,12, 8,12, 8,12, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
77 /*80*/ 12,12, 8,12,20,12, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
78 /*90*/ 12,12, 8,12, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
79 /*A0*/ 8,12, 8,12,20,UN
, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
80 /*B0*/ 8,12, 8, 4,16,16,16,16,16,16,16,16,16,16,16,16,
81 /*C0*/ 8,12, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
82 /*D0*/ 8,12, 8, 4, 4,16, 4, 4,12,12,12,12,12,12,12,12,
83 /*E0*/ 8,12, 8, 8, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
84 /*F0*/ 8,12, 8, 8, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
88 * Process machine ops.
91 machine(struct mne
*mp
)
94 char pid
[NINPUT
], id
[NINPUT
];
98 struct expr e
, e1
, e2
;
105 switch (mp
->m_type
) {
111 default: op
= DS8XCXXX
;
112 case DS8XCXXX
: v1
= 2; str
= "DS8XCXXX"; sym
[2].s_addr
= X_DS8XCXXX
; break;
113 case DS80C310
: v1
= 2; str
= "DS80C310"; sym
[2].s_addr
= X_DS80C310
; break;
114 case DS80C320
: v1
= 2; str
= "DS80C320"; sym
[2].s_addr
= X_DS80C320
; break;
115 case DS80C323
: v1
= 2; str
= "DS80C323"; sym
[2].s_addr
= X_DS80C323
; break;
116 case DS80C390
: v1
= 3; str
= "DS80C390"; sym
[2].s_addr
= X_DS80C390
; break;
117 case DS83C520
: v1
= 2; str
= "DS83C520"; sym
[2].s_addr
= X_DS83C520
; break;
118 case DS83C530
: v1
= 2; str
= "DS83C530"; sym
[2].s_addr
= X_DS83C530
; break;
119 case DS83C550
: v1
= 2; str
= "DS83C550"; sym
[2].s_addr
= X_DS83C550
; break;
120 case DS87C520
: v1
= 2; str
= "DS87C520"; sym
[2].s_addr
= X_DS87C520
; break;
121 case DS87C530
: v1
= 2; str
= "DS87C530"; sym
[2].s_addr
= X_DS87C530
; break;
122 case DS87C550
: v1
= 2; str
= "DS87C550"; sym
[2].s_addr
= X_DS87C550
; break;
123 case DS______
: v1
= 2; str
= "DS______"; sym
[2].s_addr
= X_DS______
;
127 while ((c
= get()) != d
) {
129 xerr('q', "Unquoted argument.");
131 if (p
< &pid
[sizeof(pid
)-3]) {
147 /* GCC 10.2.0 error [-Wformat-overflow=] ? */
148 /* sprintf(id, "__%s", str); */
150 memcpy(&id
[2], str
, strlen(str
)+1);
152 if (sp
->s_type
!= S_NEW
&& (sp
->s_flag
& S_ASG
) == 0) {
159 /* GCC 10.2.0 error [-Wformat-overflow=] ? */
160 /* sprintf(buff, "%s %s", DS_CPU, str); */
162 memcpy(buff
, DS_CPU
, t
);
163 memcpy(&buff
[t
], " ", 1);
165 memcpy(&buff
[t
+1], str
, t1
+1);
168 sp
= lookup("__SFR_BITS");
169 if (sp
->s_type
!= S_NEW
&& (sp
->s_flag
& S_ASG
) == 0) {
178 sp
->s_addr
= e
.e_addr
;
185 opcycles
= OPCY_AMODE
;
186 if ((mchtyp
!= 0) && (mchtyp
!= DS80C390
)) {
187 xerr('o', "Not a DS80C390 instruction.");
190 if ((mchtyp
== 0) && ((a_bytes
< 2) || (a_bytes
> 3))) {
191 xerr('o', "Not a 16 or 24 Bit machine.");
196 amode
= (int) e
.e_addr
;
197 if ((amode
< 0) || (amode
> 2)) {
199 xerr('o', "Valid values are 0 -> 2.");
201 if ((c
= getnb()) == ',') {
204 if (e1
.e_addr
!= 0) {
205 /* mov ta,#0aah */ outab(0x075); outab(0x0C7); outab(0x0AA);
206 /* mov ta,#055h */ outab(0x075); outab(0x0C7); outab(0x055);
207 /* mov acon,#amode */ outab(0x075); outab(0x09D); outab(amode
);
218 if (ds8_bytes
== 0) {
219 ds8_bytes
= (int) op
;
220 exprmasks(ds8_bytes
);
222 if (ds8_bytes
!= (int) op
) {
225 opcycles
= OPCY_BITS
;
236 outr3bm(&e
, R_J19
, op
);
238 outrwm(&e
, R_J11
, op
);
255 xerr('a', "Argument must A.");
260 /* A, direct, @R0, @R1, R0 to R7. "INC" also allows DPTR */
270 /* Direct is also legal */
276 outab(op
+ 6 + e
.e_addr
);
280 outab(op
+ 8 + e
.e_addr
);
285 /* only INC (op=0) has DPTR mode */
286 xerr('a', "DPTR allowed only in INC instruction.");
292 xerr('a', "Invalid Addressing Mode.");
297 /* A,#imm; A,direct; A,@R0; A,@R1; A,R0 to A,R7 */
300 xerr('a', "First argument must be A.");
317 outab(op
+ 6 + e1
.e_addr
);
321 outab(op
+ 8 + (e1
.e_addr
));
325 xerr('a', "Invalid Addressing Mode.");
331 * A,#imm; A,direct; A,@R0; A,@R1; A,R0 to A,R7
332 * C,direct; C,/direct
354 xerr('a', "Invalid Addressing Mode.");
372 outab(op
+ 6 + e1
.e_addr
);
376 outab(op
+ 8 + e1
.e_addr
);
380 xerr('a', "Invalid Addressing Mode.");
385 /* XRL has no boolean version. Trap it */
387 xerr('a', "XRL does not support boolean.");
402 xerr('a', "Invalid Addressing Mode.");
407 xerr('a', "Invalid Addressing Mode.");
412 /* A,direct; A,@R0; A,@R1; A,R0 to A,R7 */
415 xerr('a', "First argument must be A.");
427 outab(op
+ 6 + e1
.e_addr
);
431 outab(op
+ 8 + e1
.e_addr
);
435 xerr('a', "Invalid Addressing Mode.");
439 /* MOV instruction, all modes */
460 outab(0xE6 + e1
.e_addr
);
464 outab(0xE8 + e1
.e_addr
);
468 xerr('a', "Invalid Addressing Mode.");
475 outab(0xF8 + e
.e_addr
);
479 outab(0x78 + e
.e_addr
);
485 outab(0xA8 + e
.e_addr
);
490 xerr('a', "Invalid Addressing Mode.");
516 outab(0x86 + e1
.e_addr
);
521 outab(0x88 + e1
.e_addr
);
531 xerr('a', "Invalid Addressing Mode.");
538 outab(0x76 + e
.e_addr
);
544 outab(0xA6 + e
.e_addr
);
549 outab(0xF6 + e
.e_addr
);
553 xerr('a', "Invalid Addressing Mode.");
558 if ((t1
!= S_DIR
) && (t1
!= S_EXT
))
559 xerr('a', "Second argument must be an address.");
566 xerr('a', "#__ is required second argument.");
575 xerr('a', "Invalid Addressing Mode.");
579 case S_BITBR
: /* JB, JBC, JNB bit,rel */
580 /* Branch on bit set/clear */
582 if ((t
!= S_DIR
) && (t
!= S_EXT
))
583 xerr('a', "Argument must be an address.");
584 /* sdcc svn rev #4994: fixed bug 1865114 */
592 v1
= (int) (e1
.e_addr
- dot
.s_addr
- 1);
593 /* sdcc svn rev #602: Fix some path problems */
594 if (pass
== 2 && ((v1
< -128) || (v1
> 127)))
595 xerr('a', "Branching Range Exceeded.");
600 if (e1
.e_mode
!= S_USER
)
604 case S_BR
: /* JC, JNC, JZ, JNZ */
605 /* Relative branch */
606 /* sdcc svn rev #4994: fixed bug 1865114 */
611 v1
= (int) (e1
.e_addr
- dot
.s_addr
- 1);
612 /* sdcc svn rev #602: Fix some path problems */
613 if (pass
== 2 && ((v1
< -128) || (v1
> 127)))
614 xerr('a', "Branching Range Exceeded.");
619 if (e1
.e_mode
!= S_USER
)
624 /* A,#; A,dir; @R0,#; @R1,#; Rn,# */
639 else if ((t1
== S_DIR
) || (t1
== S_EXT
)) {
644 xerr('a', "Invalid Addressing Mode.");
648 outab(op
+ 6 + e
.e_addr
);
650 xerr('a', "#__ is required second argument.");
655 outab(op
+ 8 + e
.e_addr
);
657 xerr('a', "#__ is required second argument.");
662 xerr('a', "Invalid Addressing Mode.");
666 /* branch destination */
668 v1
= (int) (e2
.e_addr
- dot
.s_addr
- 1);
669 /* sdcc svn rev #602: Fix some path problems */
670 if (pass
== 2 && ((v1
< -128) || (v1
> 127)))
671 xerr('a', "Branching Range Exceeded.");
676 if (e2
.e_mode
!= S_USER
)
681 /* Dir,dest; Reg,dest */
683 /* sdcc svn rev #4994: fixed bug 1865114 */
695 outab(op
+ 8 + e
.e_addr
);
699 xerr('a', "Invalid Addressing Mode.");
702 /* branch destination */
703 /* sdcc svn rev #4994: fixed bug 1865114 */
705 v1
= (int) (e1
.e_addr
- dot
.s_addr
- 1);
706 /* sdcc svn rev #602: Fix some path problems */
707 if (pass
== 2 && ((v1
< -128) || (v1
> 127)))
708 xerr('a', "Branching Range Exceeded.");
713 if (e1
.e_mode
!= S_USER
)
721 xerr('a', "JMP @A+DPTR is the only allowed mode.");
726 /* A,@A+DPTR A,@A+PC */
729 xerr('a', "First argument must be A.");
734 else if (t1
== S_AT_APC
)
737 xerr('a', "MOVC A,@A+DPTR; A,@A+PC are the allowed modes.");
741 /* A,@DPTR A,@R0 A,@R1 @DPTR,A @R0,A @R1,A */
754 outab(0xE2 + e1
.e_addr
);
758 xerr('a', "Second argument must be @DPTR or @Rn.");
766 xerr('a', "Second argument must A.");
771 outab(0xF2 + e
.e_addr
);
773 xerr('a', "Second argument must A.");
777 xerr('a', "Invalid Addressing Mode.");
785 xerr('a', "A,B is the only valid argument.");
789 /* CLR or CPL: A, C, or bit */
811 xerr('a', "Invalid Addressing Mode.");
830 xerr('a', "Invalid Addressing Mode.");
841 if ((t
!= S_DIR
) && (t
!= S_EXT
)) {
842 xerr('a', "Argument must be an address.");
853 xerr('a', "First argument must A.");
858 outab(op
+ e1
.e_addr
);
862 xerr('a', "Invalid Addressing Mode.");
868 xerr('o', "Internal Opcode Error.");
871 if (opcycles
== OPCY_NONE
) {
872 opcycles
= ds8pg1
[cb
[0] & 0xFF];
877 * Branch/Jump PCR Mode Check
880 mchpcr(struct expr
*esp
)
882 if (esp
->e_base
.e_ap
== dot
.s_area
) {
885 if (esp
->e_flag
==0 && esp
->e_base
.e_ap
==NULL
) {
887 * Absolute Destination
889 * Use the global symbol '.__.ABS.'
890 * of value zero and force the assembler
891 * to use this absolute constant as the
892 * base value for the relocation.
895 esp
->e_base
.e_sp
= &sym
[1];
901 * Machine specific initialization
921 * add the pre-defined symbols to the table
927 sym
[2].s_addr
= X_DS8XCXXX
;
932 for (i
=0; i
<2; i
++) {
934 * i == 0, Create Upper Case Symbols
935 * i == 1, Create Lower Case Symbols
940 *p
= ccase
[*p
& 0x007F];
945 if (sp
->s_type
== S_NEW
) {
946 sp
->s_addr
= pd
->value
;
948 sp
->s_flag
= S_LCL
| S_ASG
;