lkml.org 
[lkml]   [2017]   [Nov]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v10 02/13] x86/insn-eval: Compute linear address in several utility functions

* Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:

> On Thu, Nov 02, 2017 at 09:51:08AM +0100, Ingo Molnar wrote:
> >
> > * Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:
> >
> > > + /*
> > > + * -EDOM means that we must ignore the address_offset. In such a case,
> > > + * in 64-bit mode the effective address relative to the RIP of the
> > > + * following instruction.
> > > + */
> > > + if (*regoff == -EDOM) {
> > > + if (user_64bit_mode(regs))
> > > + tmp = (long)regs->ip + insn->length;
> > > + else
> > > + tmp = 0;
> > > + } else if (*regoff < 0) {
> > > + return -EINVAL;
> > > + } else {
> > > + tmp = (long)regs_get_register(regs, *regoff);
> > > + }
> >
> > > + else
> > > + indx = (long)regs_get_register(regs, indx_offset);
> >
> > This and subsequent patches include a disgustly insane amount of type casts - why?
> >
> > For example here 'tmp' is 'long', while regs_get_register() returns
> > 'unsigned long', but no type cast is necessary for that.
> >
> > > + ret = get_eff_addr_modrm(insn, regs, &addr_offset,
> > > + &eff_addr);
>
> One of the goals of this series is to have the ability to compute 16-bit, 32-bit
> and 64-bit addresses. I put lost of casts, between signed and unsigned types,
> between 64-bit and 32-bit and 16-bit casts. After seeing your comment I have gone
> through the code and I have removed most of the casts. Instead I will use masks.
> I will also inspect the resulting assembly code to make sure the arithmetic is
> performed in the address size pertinent to each case.

Well, casts are probably fine when the goal is to zero out high bits - but the
ones I quoted converted types of the same with.

For register values it would also probably be cleaner to use the u8, u16, u32 and
u64 types instead of char/short/int/long - this goes hand in hand with how the
instructions are documented in the SDMs.

Thanks,

Ingo

\
 
 \ /
  Last update: 2017-11-03 11:18    [W:0.080 / U:0.392 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site