Skip to content

Commit fc98af0

Browse files
committed
v.0.8.9 Rework of operands and operand types.
1 parent 9b1507c commit fc98af0

22 files changed

Lines changed: 1192 additions & 921 deletions

File tree

CHANGELOG.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,64 @@
44

55
- nothing to log
66

7+
# v.0.8.9 - 2021-06-22
8+
9+
- VMCU_OP rework
10+
- rename to VMCU_OPTYPE
11+
- added new types to enumeration. Enumeration after rework:
12+
- VMCU_OPTYPE_NONE = -1 (no operand, therefore no type)
13+
- VMCU_OPTYPE_R, (register operand)
14+
- VMCU_OPTYPE_RP, (registerpair operand)
15+
- VMCU_OPTYPE_X, (x pointer operand)
16+
- VMCU_OPTYPE_Y, (y pointer operand)
17+
- VMCU_OPTYPE_Z, (z pointer operand)
18+
- VMCU_OPTYPE_B, (bit number 0-7)
19+
- VMCU_OPTYPE_K4, (4-bit immediate)
20+
- VMCU_OPTYPE_K6, (6-bit immediate)
21+
- VMCU_OPTYPE_K8, (8-bit immediate)
22+
- VMCU_OPTYPE_IO5, (5-bit I/O address)
23+
- VMCU_OPTYPE_IO6, (6-bit I/O address)
24+
- VMCU_OPTYPE_D7, (7-bit data address)
25+
- VMCU_OPTYPE_D16, (16-bit data address)
26+
- VMCU_OPTYPE_P22, (22-bit program address)
27+
- VMCU_OPTYPE_S7, (7-bit signed displacement, program memory)
28+
- VMCU_OPTYPE_S12 (12-bit signed displacement, program memory)
29+
- similar types can be found at https://en.wikipedia.org/wiki/Atmel_AVR_instruction_set
30+
31+
- Added: VMCU_REGISTER - an enumeration of AVR general purpose registers (r0-r31)
32+
33+
- Added: vmcu_registerpair_t structure
34+
- this structure is able to represent a registerpair by holding
35+
- a VMCU_REGISTER low - low byte of pair
36+
- a VMCU_REGISTER high - high byte of pair
37+
38+
- vmcu_operand_t rework
39+
- vmcu_operand_t now consists of a
40+
- VMCU_OPTYPE - an enumeration of different operand types
41+
- value union - a c-union holding different kinds of operand values
42+
43+
- The value union of vmcu_operand_t contains
44+
- uint8_t k for type = K4, K6, K8
45+
- uint8_t b for type = B
46+
- uint8_t io for type = IO5, IO6
47+
- uint16_t d for type = D7, D16
48+
- uint32_t p for type = P22
49+
- int16_t s for type = S7, S12
50+
51+
- disassembled .dw directive (= illegal opcode) does not have its opcode as source operand anymore
52+
- instead, an illegal opcode (.dw xxxx) has following attributes
53+
- instr->src.type = VMCU_OPTYPE_NONE
54+
- instr->dest.type = VMCU_OPTYPE_NONE
55+
- therefore no operand values
56+
- in order to simplify printing these "instructions", I've decided to move the .dw value (xxxx)
57+
to instr->mnem.base. So the base mnemonic is now ".dw xxxx" with no operands.
58+
59+
- endloop driver (driver/endloop/) improvement
60+
- endloop driver is now able to detect unconditional and conditional endless loops
61+
62+
- adjusted driver code
63+
- minor improvements
64+
765
# v.0.8.8 - 2021-06-20
866

967
- Added: vmcu_mnemonic_t structure to vmcu_instr_t

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ int main(const int argc, const char **argv) {
102102
vmcu_operand_t *src = &instr.src; // source operand
103103
vmcu_operand_t *dest = &instr.dest; // destination operand
104104

105-
VMCU_OP src_type = src->type; // VMCU_OP_IMM8
106-
VMCU_OP dest_type = dest->type; // VMCU_OP_REGISTER
107-
108-
const uint8_t src_val = src->value; // 0x08
109-
const uint8_t dest_val = dest->value; // (R)29
105+
VMCU_OPTYPE src_type = src->type; // VMCU_OPTYPE_K8
106+
VMCU_OPTYPE dest_type = dest->type; // VMCU_OPTYPE_R
107+
108+
const uint8_t src_val = src->k; // 0x08
109+
VMCU_REGISTER dest_val = dest->r; // VMCU_REGISTER_R29
110110

111111
vmcu_mnemonic_t *mnem = &instr.mnem; // instruction mnemonic
112112

@@ -126,18 +126,17 @@ int main(const int argc, const char **argv) {
126126
```c
127127
/* this snippet can be used to assemble and print an instruction */
128128
129-
void print_instruction(vmcu_instr_t *instr) {
129+
void print_instruction(const vmcu_instr_t *instr) {
130130
131-
vmcu_mnemonic_t *mnem = &instr->mnem;
131+
printf("%s", instr->mnem.base);
132132
133-
printf("%s ", mnem->base);
134-
printf("%s", mnem->dest);
133+
if(instr->dest.type != VMCU_OPTYPE_NONE)
134+
printf(" %s,", instr->mnem.dest);
135135
136-
if(instr->dest.type != VMCU_OP_NONE)
137-
printf(", ");
136+
if(instr->src.type != VMCU_OPTYPE_NONE)
137+
printf(" %s", instr->mnem.src);
138138
139-
printf("%s ", mnem->src);
140-
printf("%s\n", mnem->comment);
139+
printf(" %s\n", instr->mnem.comment);
141140
}
142141
```
143142

driver/details/details.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/* Forward Declaration of static Functions */
1414

1515
static void print_instr(vmcu_instr_t *instr, const uint32_t opcode);
16-
static void print_mnemonic(vmcu_instr_t *instr);
16+
static void print_mnemonic(const vmcu_instr_t *instr);
1717
static int htoi(const char *input);
1818

1919
/* --- Extern --- */
@@ -72,18 +72,17 @@ static void print_instr(vmcu_instr_t *instr, const uint32_t opcode) {
7272
printf("16-bit\n");
7373
}
7474

75-
static void print_mnemonic(vmcu_instr_t *instr) {
75+
static void print_mnemonic(const vmcu_instr_t *instr) {
7676

77-
vmcu_mnemonic_t *mnem = &instr->mnem;
77+
printf("%s", instr->mnem.base);
7878

79-
printf("%s ", mnem->base);
80-
printf("%s", mnem->dest);
79+
if(instr->dest.type != VMCU_OPTYPE_NONE)
80+
printf(" %s,", instr->mnem.dest);
8181

82-
if(instr->dest.type != VMCU_OP_NONE)
83-
printf(", ");
82+
if(instr->src.type != VMCU_OPTYPE_NONE)
83+
printf(" %s", instr->mnem.src);
8484

85-
printf("%s ", mnem->src);
86-
printf("%s\n", mnem->comment);
85+
printf(" %s\n", instr->mnem.comment);
8786
}
8887

8988
int htoi(const char *input) {

driver/disasm/disasm.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ vmcu_model_t *m328p = NULL;
5555
static void print_instruction(vmcu_instr_t *instr);
5656
static void print_instruction_details(vmcu_instr_t *instr);
5757
static void print_colored_base(const char *basestr, VMCU_GROUP group);
58-
static void print_colored_operands(const char *opstr, VMCU_OP optype);
58+
static void print_colored_operands(const char *opstr, VMCU_OPTYPE optype);
5959
static void add_padding(const size_t length, const size_t max);
6060
static void cleanup(void);
6161

@@ -96,13 +96,13 @@ static void print_instruction(vmcu_instr_t *instr) {
9696

9797
size_t sz = 0;
9898

99-
if(instr->dest.type != VMCU_OP_NONE) {
99+
if(instr->dest.type != VMCU_OPTYPE_NONE) {
100100

101101
print_colored_operands(mnem->dest, instr->dest.type);
102102
sz += printf(", ");
103103
}
104104

105-
if(instr->src.type != VMCU_OP_NONE) {
105+
if(instr->src.type != VMCU_OPTYPE_NONE) {
106106

107107
print_colored_operands(mnem->src, instr->src.type);
108108
sz += printf(" ");
@@ -147,25 +147,31 @@ static void print_colored_base(const char *basestr, VMCU_GROUP group) {
147147
printf("%s%s ", basestr, COLOR_RESET);
148148
}
149149

150-
static void print_colored_operands(const char *opstr, VMCU_OP optype) {
150+
static void print_colored_operands(const char *opstr, VMCU_OPTYPE optype) {
151151

152152
switch(optype) {
153153

154-
case VMCU_OP_IMM:
155-
case VMCU_OP_IMM8:
156-
case VMCU_OP_UIMM8:
157-
case VMCU_OP_UIMM16:
158-
case VMCU_OP_IODIRECT:
154+
case VMCU_OPTYPE_B:
155+
case VMCU_OPTYPE_K4:
156+
case VMCU_OPTYPE_K6:
157+
case VMCU_OPTYPE_K8:
158+
case VMCU_OPTYPE_IO5:
159+
case VMCU_OPTYPE_IO6:
160+
case VMCU_OPTYPE_D7:
161+
case VMCU_OPTYPE_D16:
162+
case VMCU_OPTYPE_P22:
163+
case VMCU_OPTYPE_S7:
164+
case VMCU_OPTYPE_S12:
159165

160166
printf("%s", COLOR_BLUE);
161167

162168
break;
163169

164-
case VMCU_OP_REGISTER:
165-
case VMCU_OP_REGISTERPAIR:
166-
case VMCU_OP_XPTR:
167-
case VMCU_OP_YPTR:
168-
case VMCU_OP_ZPTR:
170+
case VMCU_OPTYPE_R:
171+
case VMCU_OPTYPE_RP:
172+
case VMCU_OPTYPE_X:
173+
case VMCU_OPTYPE_Y:
174+
case VMCU_OPTYPE_Z:
169175

170176
printf("%s", COLOR_CYAN);
171177

driver/endloop/endloop.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static bool is_valid_flow_change(vmcu_instr_t *instr);
3434
static bool is_absolute_flow_change(vmcu_instr_t *instr);
3535
static bool is_conditional(vmcu_instr_t *instr);
3636

37-
static void print_instruction(vmcu_instr_t *instr);
37+
static void print_instruction(const vmcu_instr_t *instr);
3838

3939
/* --- Extern --- */
4040

@@ -87,10 +87,15 @@ static bool is_endloop(vmcu_instr_t *instr) {
8787
if(is_valid_flow_change(instr) == false)
8888
return false;
8989

90-
if(!is_absolute_flow_change(instr) && instr->src.value == -1)
91-
return true;
90+
if(is_absolute_flow_change(instr) == true) {
91+
92+
if(instr->src.p == instr->addr)
93+
return true;
94+
95+
return false;
96+
}
9297

93-
if(instr->src.value == instr->addr)
98+
if(instr->src.s == -1)
9499
return true;
95100

96101
return false;
@@ -158,16 +163,15 @@ static bool is_conditional(vmcu_instr_t *instr) {
158163
return false;
159164
}
160165

161-
static void print_instruction(vmcu_instr_t *instr) {
166+
void print_instruction(const vmcu_instr_t *instr) {
162167

163-
vmcu_mnemonic_t *mnem = &instr->mnem;
168+
printf("%s", instr->mnem.base);
164169

165-
printf("%s ", mnem->base);
166-
printf("%s", mnem->dest);
170+
if(instr->dest.type != VMCU_OPTYPE_NONE)
171+
printf(" %s,", instr->mnem.dest);
167172

168-
if(instr->dest.type != VMCU_OP_NONE)
169-
printf(", ");
173+
if(instr->src.type != VMCU_OPTYPE_NONE)
174+
printf(" %s", instr->mnem.src);
170175

171-
printf("%s ", mnem->src);
172-
printf("%s\n", mnem->comment);
176+
printf(" %s\n", instr->mnem.comment);
173177
}

driver/findgroup/findgroup.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ vmcu_report_t *report = NULL;
3333
/* Forward Declaration of static Functions */
3434

3535
static VMCU_GROUP get_filter(const char *arg);
36-
static void print_instruction(vmcu_instr_t *instr);
36+
static void print_instruction(const vmcu_instr_t *instr);
3737
static void cleanup(void);
3838

3939
/* --- Extern --- */
@@ -92,18 +92,17 @@ static VMCU_GROUP get_filter(const char *arg) {
9292
return VMCU_GROUP_NONE;
9393
}
9494

95-
static void print_instruction(vmcu_instr_t *instr) {
95+
void print_instruction(const vmcu_instr_t *instr) {
9696

97-
vmcu_mnemonic_t *mnem = &instr->mnem;
97+
printf("%s", instr->mnem.base);
9898

99-
printf("%s ", mnem->base);
100-
printf("%s", mnem->dest);
99+
if(instr->dest.type != VMCU_OPTYPE_NONE)
100+
printf(" %s,", instr->mnem.dest);
101101

102-
if(instr->dest.type != VMCU_OP_NONE)
103-
printf(", ");
102+
if(instr->src.type != VMCU_OPTYPE_NONE)
103+
printf(" %s", instr->mnem.src);
104104

105-
printf("%s ", mnem->src);
106-
printf("%s\n", mnem->comment);
105+
printf(" %s\n", instr->mnem.comment);
107106
}
108107

109108
static void cleanup(void) {

driver/findisr/findisr.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ vmcu_label_t* find_label(int address, vmcu_report_t* report) {
3232
void analyze_isr(vmcu_instr_t* instr, vmcu_report_t* report) {
3333

3434
vmcu_operand_t* op = &instr->src;
35-
36-
int absolute_address = op->value;
35+
int absolute_address = (op->type == VMCU_OPTYPE_S12) ? op->s : op->p;
3736

3837
if(instr->key == VMCU_IKEY_RJMP)
3938
absolute_address += instr->addr + 1;
4039

4140
vmcu_label_t* label = find_label(absolute_address, report);
42-
4341
printf("L%d\t0x%04x\n", label->id, absolute_address);
4442
}
4543

driver/labels/labels.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/* Forward Declaration of static Functions */
1212

13-
static void print_instruction(vmcu_instr_t *instr);
13+
static void print_instruction(const vmcu_instr_t *instr);
1414

1515
/* --- Extern --- */
1616

@@ -52,16 +52,15 @@ int main(const int argc, const char **argv) {
5252

5353
/* --- Static --- */
5454

55-
static void print_instruction(vmcu_instr_t *instr) {
55+
void print_instruction(const vmcu_instr_t *instr) {
5656

57-
vmcu_mnemonic_t *mnem = &instr->mnem;
57+
printf("%s", instr->mnem.base);
5858

59-
printf("%s ", mnem->base);
60-
printf("%s", mnem->dest);
59+
if(instr->dest.type != VMCU_OPTYPE_NONE)
60+
printf(" %s,", instr->mnem.dest);
6161

62-
if(instr->dest.type != VMCU_OP_NONE)
63-
printf(", ");
62+
if(instr->src.type != VMCU_OPTYPE_NONE)
63+
printf(" %s", instr->mnem.src);
6464

65-
printf("%s ", mnem->src);
66-
printf("%s\n", mnem->comment);
65+
printf(" %s\n", instr->mnem.comment);
6766
}

driver/sfr/sfr.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/* Forward Declaration of static Functions */
1515

16-
static void print_instruction(vmcu_instr_t *instr);
16+
static void print_instruction(const vmcu_instr_t *instr);
1717

1818
/* --- Extern --- */
1919

@@ -58,16 +58,15 @@ int main(const int argc, const char **argv) {
5858

5959
/* --- Static --- */
6060

61-
static void print_instruction(vmcu_instr_t *instr) {
61+
void print_instruction(const vmcu_instr_t *instr) {
6262

63-
vmcu_mnemonic_t *mnem = &instr->mnem;
63+
printf("%s", instr->mnem.base);
6464

65-
printf("%s ", mnem->base);
66-
printf("%s", mnem->dest);
65+
if(instr->dest.type != VMCU_OPTYPE_NONE)
66+
printf(" %s,", instr->mnem.dest);
6767

68-
if(instr->dest.type != VMCU_OP_NONE)
69-
printf(", ");
68+
if(instr->src.type != VMCU_OPTYPE_NONE)
69+
printf(" %s", instr->mnem.src);
7070

71-
printf("%s ", mnem->src);
72-
printf("%s\n", mnem->comment);
71+
printf(" %s\n", instr->mnem.comment);
7372
}

0 commit comments

Comments
 (0)