Page 1 of 1

How easy is it to understand the meaning of the register val

Posted: Fri Apr 08, 2022 9:28 am
by mrjbom
Hi.

I would like to be able to easily find out what exactly is hidden behind the current value of the registers.
For example, just copy the current EFLAGS from qemu (using info registers) and immediately decrypt it, or do the same with CRx registers.
Now I have to translate the value from 16 to 2 number system and manually examine the bits by checking the documentation.
Maybe there are some convenient online tools or something?

Re: How easy is it to understand the meaning of the register

Posted: Fri Apr 08, 2022 9:34 am
by iansjack
Pretty trivial to write such tools for yourself, I would have thought.

Re: How easy is it to understand the meaning of the register

Posted: Fri Apr 08, 2022 9:36 am
by mrjbom
iansjack wrote:Pretty trivial to write such tools for yourself, I would have thought.
I was thinking of writing this for myself.
But suddenly someone did it before me, in this case it is more convenient to use something ready-made.

Re: How easy is it to understand the meaning of the register

Posted: Fri Apr 08, 2022 1:22 pm
by nullplan
mrjbom wrote:Now I have to translate the value from 16 to 2 number system and manually examine the bits by checking the documentation.
Well, if you are doing that, you are already doing something wrong (unless I misunderstood you). You see, each hex digit is a shorthand for four bits. This makes it both easy to identify what bits a given hex digit stands for (as it is always the same thing), and to locate the bit in the documentation.

For example, I'm defining the GDT as just an array of 64-bit numbers. So I have the assignment

Code: Select all

    gdt[KCODE_DESC] = 0x00af9a000000ffff;
Cross-reference that with the documentation for a 64-bit GDT entry, and you see, for example, that the first "a" in the number means that the G bit and the L bit are set: "a" is "1010" in binary, and this one is two digits in, so eight bits in. And luckily in the GDT entry, most important things line up with boundaries divisible by four.

Doesn't always work that way, but then you just get as close as possible with hex digits. And so there is never really a reason to translate the number back to binary. One thing I particularly never understood is the insistence of some members of this community to use binary for full thirty-two bit numbers (or even sixty-four bit numbers). How do you even see anything in that long mess?

Re: How easy is it to understand the meaning of the register

Posted: Sat Apr 09, 2022 4:27 am
by mrjbom
nullplan wrote:
mrjbom wrote:Now I have to translate the value from 16 to 2 number system and manually examine the bits by checking the documentation.
Well, if you are doing that, you are already doing something wrong (unless I misunderstood you). You see, each hex digit is a shorthand for four bits. This makes it both easy to identify what bits a given hex digit stands for (as it is always the same thing), and to locate the bit in the documentation.
Wow, I've never noticed this, although even with this it's not particularly convenient to manually check the documentation every time.
nullplan wrote:How do you even see anything in that long mess?
It's hard to see something there, so it was cool for some utility to see it for me

Re: How easy is it to understand the meaning of the register

Posted: Sat Apr 09, 2022 6:37 am
by nullplan
mrjbom wrote:Wow, I've never noticed this, although even with this it's not particularly convenient to manually check the documentation every time.
Unfortunately, I've found that symbolic constants don't help a lot, because the concepts are often too arcane, so you need to read the code with the documentation in hand anyway. And particularly in places where you only need the constants once, like in the GDT and IDT code (which I initialize once and then never touch again), I just use magic numbers and then put the whole issue to bed.