@@ -98,40 +98,15 @@ void resolve_immediate_values(list_t *symbols, area_t *area, list_t *errors) {
98
98
}
99
99
100
100
/* z80 only (and possibly ez80) */
101
- void auto_relocate_area (area_t * area , area_t * runtime ) {
101
+ void auto_relocate_area (area_t * area , area_t * relocation_table ) {
102
102
scas_log (L_DEBUG , "Performing automatic relocation for %s" , area -> name );
103
- uint8_t rst0x8 = 0xCF ;
104
103
int i ;
105
104
for (i = 0 ; i < area -> late_immediates -> length ; ++ i ) {
106
105
late_immediate_t * imm = area -> late_immediates -> items [i ];
107
- if (imm -> type != IMM_TYPE_RELATIVE ) {
108
- if (imm -> base_address != imm -> address ) {
109
- /* Relocate this */
110
- scas_log (L_DEBUG , "Adding relocation instruction for immediate at 0x%08X (inserting at 0x%08X)" , imm -> address , imm -> instruction_address );
111
- insert_in_area (area , & rst0x8 , sizeof (uint8_t ), imm -> instruction_address );
112
- ++ imm -> address ;
113
- /* Move everything that comes after */
114
- int k ;
115
- for (k = 0 ; k < area -> symbols -> length ; ++ k ) {
116
- symbol_t * sym = area -> symbols -> items [k ];
117
- if (sym -> type == SYMBOL_LABEL && sym -> value > imm -> instruction_address ) {
118
- ++ sym -> value ;
119
- }
120
- }
121
- int j ;
122
- for (j = 0 ; j < area -> late_immediates -> length ; ++ j ) {
123
- late_immediate_t * _imm = area -> late_immediates -> items [j ];
124
- if (_imm -> base_address > imm -> base_address ) {
125
- ++ _imm -> base_address ;
126
- ++ _imm -> instruction_address ;
127
- ++ _imm -> address ;
128
- }
129
- }
130
- } else {
131
- /* Relocate this */
132
- uint16_t value = (uint16_t )(imm -> address + area -> final_address );
133
- append_to_area (runtime , (uint8_t * )& value , sizeof (uint16_t ));
134
- }
106
+ if (imm -> type != IMM_TYPE_RELATIVE && imm -> base_address != imm -> address ) {
107
+ /* Relocate this */
108
+ uint16_t value = (uint16_t )(imm -> address + area -> final_address );
109
+ append_to_area (relocation_table , (uint8_t * )& value , sizeof (uint16_t ));
135
110
}
136
111
}
137
112
}
@@ -161,27 +136,25 @@ void link_objects(FILE *output, list_t *objects, linker_settings_t *settings) {
161
136
list_t * symbols = create_list (); // TODO: Use a hash table
162
137
163
138
/* Create a new area for relocatable references */
164
- area_t * runtime ;
139
+ area_t * relocation_table ;
165
140
if (settings -> automatic_relocation ) {
166
- const char * sym_name = "__scas_relocatable_data" ;
167
- runtime = create_area ("__scas_relocatable" );
141
+ relocation_table = create_area ("__scas_relocation_table" );
168
142
symbol_t * sym = malloc (sizeof (symbol_t ));
169
143
sym -> type = SYMBOL_LABEL ;
170
- sym -> name = malloc (strlen (sym_name ) + 1 );
171
- strcpy (sym -> name , sym_name );
144
+ sym -> name = strdup ("__scas_relocation_table" );
172
145
sym -> value = 0 ;
173
146
sym -> defined_address = 0 ;
174
147
sym -> exported = 0 ;
175
- list_add (runtime -> symbols , sym );
148
+ list_add (relocation_table -> symbols , sym );
176
149
object_t * o = create_object ();
177
- list_add (o -> areas , runtime );
150
+ list_add (o -> areas , relocation_table );
178
151
list_add (objects , o );
179
152
}
180
153
181
154
object_t * merged = merge_objects (objects );
182
155
area_t * final = create_area ("FINAL" );
183
156
184
- runtime = get_area_by_name (merged , "__scas_relocatable " );
157
+ relocation_table = get_area_by_name (merged , "__scas_relocation_table " );
185
158
186
159
scas_log (L_INFO , "Assigning final address for all areas" );
187
160
if (scas_runtime .options .remove_unused_functions ) {
@@ -193,11 +166,11 @@ void link_objects(FILE *output, list_t *objects, linker_settings_t *settings) {
193
166
area_t * area = merged -> areas -> items [i ];
194
167
relocate_area (area , address , false);
195
168
if (settings -> automatic_relocation ) {
196
- if (area == runtime ) {
169
+ if (area == relocation_table ) {
197
170
uint16_t null_ptr = 0 ;
198
171
append_to_area (area , (uint8_t * )& null_ptr , sizeof (uint16_t ));
199
172
} else {
200
- auto_relocate_area (area , runtime );
173
+ auto_relocate_area (area , relocation_table );
201
174
}
202
175
}
203
176
address += area -> data_length ;
0 commit comments