lkml.org 
[lkml]   [2021]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v2 06/14] x86/asm: Fix register order
Date
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)
\
 
 \ /
  Last update: 2021-10-22 21:28    [W:0.202 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site