Re: [kvm-unit-tests PATCH v2 3/3] arm/debugtest: test access to the debug registers for guest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 22, 2017 at 07:41:13PM +0100, Alex Bennée wrote:
> 
> Andrew Jones <drjones@xxxxxxxxxx> writes:
> > Any reason not to implement the above functions with
> > loops? E.g.
> >
> >  while (--n >= 0) {
> >    write_debug_wcr(array[n].dbgwcr, n);
> >    write_debug_wvr(array[n].dbgwvr, n);
> >  }
> 
> Well we are using macro pasting here so we need to instantiate all
> possible asm fragments.
>

Oh right.  So how about fighting fire with fire - i.e. creating
more macros

#define dbg_case_readb(nr, array) \
        case (nr): \
        (array)[nr].dbgbcr = read_debug_bcr(nr); \
        (array)[nr].dbgbvr = read_debug_bvr(nr); \
        /* fall through */
#define dbg_case_readw(nr, array) \
        case (nr): \
        (array)[nr].dbgwcr = read_debug_wcr(nr); \
        (array)[nr].dbgwvr = read_debug_wvr(nr); \
        /* fall through */
#define dbg_case_writeb(nr, array) \
        case (nr): \
        write_debug_bcr((array)[nr].dbgbcr, nr); \
        write_debug_bvr((array)[nr].dbgbvr, nr); \
        /* fall through */
#define dbg_case_writew(nr, array) \
        case (nr): \
        write_debug_wcr((array)[nr].dbgwcr, nr); \
        write_debug_wvr((array)[nr].dbgwvr, nr); \
        /* fall through */

#define dbg_func(rw, type) \
static void rw ## _dbg ## type(int n, struct dbgregs *array)    \
{                                                       \
        switch (n - 1) {                                \
        dbg_case_ ## rw ## type(15, array);     \
        dbg_case_ ## rw ## type(14, array);     \
        dbg_case_ ## rw ## type(13, array);     \
        dbg_case_ ## rw ## type(12, array);     \
        dbg_case_ ## rw ## type(11, array);     \
        dbg_case_ ## rw ## type(10, array);     \
        dbg_case_ ## rw ## type(9, array);      \
        dbg_case_ ## rw ## type(8, array);      \
        dbg_case_ ## rw ## type(7, array);      \
        dbg_case_ ## rw ## type(6, array);      \
        dbg_case_ ## rw ## type(5, array);      \
        dbg_case_ ## rw ## type(4, array);      \
        dbg_case_ ## rw ## type(3, array);      \
        dbg_case_ ## rw ## type(2, array);      \
        dbg_case_ ## rw ## type(1, array);      \
        dbg_case_ ## rw ## type(0, array);      \
        }                                       \
}

dbg_func(read, b)
dbg_func(read, w)
dbg_func(write, b)
dbg_func(write, w)

Thanks,
drew 



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux