Messages in this thread |  | | From | David Laight <> | Subject | RE: [PATCH v2 06/14] x86/asm: Fix register order | Date | Fri, 22 Oct 2021 19:27:06 +0000 |
| |
From: Peter Zijlstra > Sent: 20 October 2021 11:45 > > Ensure the register order is correct; this allows for easy translation > between register number and trampoline and vice-versa.
There is an alternate cpp pattern that can be used to have the same effect. Possibly less error prone. Stealing some text from 2 patches you'd have:
asm/GEN-for-each-reg.h would contain:
#define GEN_FOR_EACH_REG(GEN) \ GEN(rax) \ GEN(rcx) \ GEN(rdx) \ GEN(rbx) \ GEN(rsp) \ GEN(rbp) \ GEN(rsi) \ GEN(rdi) \ GEN(r8) \ GEN(r9) \ GEN(r10)
and the user would contain:
#include <asm/GEN-for-each-reg.h>
#define GEN(reg) \ extern asmlinkage void __x86_indirect_thunk_ ## reg (void); GEN_FOR_EACH_REG(GEN) #undef GEN
#define GEN(reg) \ extern asmlinkage void __x86_indirect_alt_call_ ## reg (void); GEN_FOR_EACH_REG(GEN) #undef GEN
It is probably possible to use ... and _VA_LIST_. Something like:
#define GEN_FOR_EACH_REG(GEN, ...) \ GEN(rax, _VA_LIST_) \ ...
#define GEN_THUNK(reg, thunk) \ extern asmlinkage void thunk ## reg (void);
GEN_FOR_EACH_REG(GEN_THUNK, __x86_indirect_thunk_) GEN_FOR_EACH_REG(GEN_THUNK, __x86_indirect_alt_call_) #undef GEN_THUNK
David
- Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
|  |