Skip to content

Commit 90cb7bd

Browse files
author
Linus Torvalds
committed
Let compile-i386 know about more registers.
We don't actually _use_ any of them yet, but this lists them, and adds the information about which register conflicts with which register (eg %al conflicts with %eax, but not with %ah)
1 parent 9fbbb55 commit 90cb7bd

File tree

1 file changed

+54
-56
lines changed

1 file changed

+54
-56
lines changed

compile-i386.c

+54-56
Original file line numberDiff line numberDiff line change
@@ -161,68 +161,66 @@ struct function *current_func = NULL;
161161
struct textbuf *unit_post_text = NULL;
162162
static const char *current_section;
163163

164+
enum registers {
165+
NOREG,
166+
AL, DL, CL, BL, AH, DH, CH, BH, // 8-bit
167+
AX, DX, CX, BX, SI, DI, BP, SP, // 16-bit
168+
EAX, EDX, ECX, EBX, ESI, EDI, EBP, ESP, // 32-bit
169+
EAX_EDX, ECX_EBX, ESI_EDI, // 64-bit
170+
};
171+
172+
#define REGINFO(nr, str, aliases...) [nr] = { .name = str }
173+
164174
static struct reg_info reg_info_table[] = {
165-
{ "%eax" },
166-
{ "%ecx" },
167-
{ "%edx" },
168-
{ "%esp" },
169-
{ "%dl" },
170-
{ "%dx" },
171-
{ "%al" },
172-
{ "%ax" },
175+
REGINFO( AL, "%al", AX, EAX, EAX_EDX),
176+
REGINFO( DL, "%dl", DX, EDX, EAX_EDX),
177+
REGINFO( CL, "%cl", CX, ECX, ECX_EBX),
178+
REGINFO( BL, "%bl", BX, EBX, ECX_EBX),
179+
REGINFO( AH, "%ah", AX, EAX, EAX_EDX),
180+
REGINFO( DH, "%dh", DX, EDX, EAX_EDX),
181+
REGINFO( CH, "%ch", CX, ECX, ECX_EBX),
182+
REGINFO( BH, "%bh", BX, EBX, ECX_EBX),
183+
REGINFO( AX, "%ax", AL, AH, EAX, EAX_EDX),
184+
REGINFO( DX, "%dx", DL, DH, EDX, EAX_EDX),
185+
REGINFO( CX, "%cx", CL, CH, ECX, ECX_EBX),
186+
REGINFO( BX, "%bx", BL, BH, EBX, ECX_EBX),
187+
REGINFO( SI, "%si", ESI, ESI_EDI),
188+
REGINFO( DI, "%di", EDI, ESI_EDI),
189+
REGINFO( BP, "%bp", EBP),
190+
REGINFO( SP, "%sp", ESP),
191+
REGINFO(EAX, "%eax", AL, AH, AX, EAX_EDX),
192+
REGINFO(EDX, "%edx", DL, DH, DX, EAX_EDX),
193+
REGINFO(ECX, "%ecx", CL, CH, CX, ECX_EBX),
194+
REGINFO(EBX, "%ebx", BL, BH, BX, ECX_EBX),
195+
REGINFO(ESI, "%esi", SI, ESI_EDI),
196+
REGINFO(EDI, "%edi", DI, ESI_EDI),
197+
REGINFO(EBP, "%ebp", BP),
198+
REGINFO(ESP, "%esp", SP),
199+
REGINFO(EAX_EDX, "%eax:%edx", AL, AH, AX, EAX, DL, DH, DX, EDX),
200+
REGINFO(ECX_EBX, "%ecx:%ebx", CL, CH, CX, ECX, BL, BH, BX, EBX),
201+
REGINFO(ESI_EDI, "%esi:%edi", SI, ESI, DI, EDI),
173202
};
174203

204+
#define REGSTORAGE(nr) [nr] = { .type = STOR_REG, .reg = reg_info_table + (nr) }
205+
175206
static struct storage hardreg_storage_table[] = {
176-
{ /* eax */
177-
.type = STOR_REG,
178-
.reg = &reg_info_table[0],
179-
},
180-
181-
{ /* ecx */
182-
.type = STOR_REG,
183-
.reg = &reg_info_table[1],
184-
},
185-
186-
{ /* edx */
187-
.type = STOR_REG,
188-
.reg = &reg_info_table[2],
189-
},
190-
191-
{ /* esp */
192-
.type = STOR_REG,
193-
.reg = &reg_info_table[3],
194-
},
195-
196-
{ /* dl */
197-
.type = STOR_REG,
198-
.reg = &reg_info_table[4],
199-
},
200-
201-
{ /* dx */
202-
.type = STOR_REG,
203-
.reg = &reg_info_table[5],
204-
},
205-
206-
{ /* al */
207-
.type = STOR_REG,
208-
.reg = &reg_info_table[6],
209-
},
210-
211-
{ /* ax */
212-
.type = STOR_REG,
213-
.reg = &reg_info_table[7],
214-
},
207+
REGSTORAGE(AL), REGSTORAGE(DL), REGSTORAGE(CL), REGSTORAGE(BL),
208+
REGSTORAGE(AH), REGSTORAGE(DH), REGSTORAGE(CH), REGSTORAGE(BH),
209+
REGSTORAGE(AX), REGSTORAGE(DX), REGSTORAGE(CX), REGSTORAGE(BX),
210+
REGSTORAGE(SI), REGSTORAGE(DI), REGSTORAGE(BP), REGSTORAGE(SP),
211+
REGSTORAGE(EAX), REGSTORAGE(EDX), REGSTORAGE(ECX), REGSTORAGE(EBX),
212+
REGSTORAGE(ESI), REGSTORAGE(EDI), REGSTORAGE(EBP), REGSTORAGE(ESP),
213+
REGSTORAGE(EAX_EDX), REGSTORAGE(ECX_EBX), REGSTORAGE(ESI_EDI),
215214
};
216215

217-
#define REG_EAX (&hardreg_storage_table[0])
218-
#define REG_ECX (&hardreg_storage_table[1])
219-
#define REG_EDX (&hardreg_storage_table[2])
220-
#define REG_ESP (&hardreg_storage_table[3])
221-
#define REG_DL (&hardreg_storage_table[4])
222-
#define REG_DX (&hardreg_storage_table[5])
223-
#define REG_AL (&hardreg_storage_table[6])
224-
#define REG_AX (&hardreg_storage_table[7])
225-
216+
#define REG_EAX (&hardreg_storage_table[EAX])
217+
#define REG_ECX (&hardreg_storage_table[ECX])
218+
#define REG_EDX (&hardreg_storage_table[EDX])
219+
#define REG_ESP (&hardreg_storage_table[ESP])
220+
#define REG_DL (&hardreg_storage_table[DL])
221+
#define REG_DX (&hardreg_storage_table[DX])
222+
#define REG_AL (&hardreg_storage_table[AL])
223+
#define REG_AX (&hardreg_storage_table[AX])
226224

227225
static void emit_move(struct storage *src, struct storage *dest,
228226
struct symbol *ctype, const char *comment);

0 commit comments

Comments
 (0)