Question

I work on a MPC8347 PowerPC. In u-boot-v2014.01, I have this instruction in start.S:

li  r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
         (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32

What is the meaning of & ~31 and & 31? Are there masks on 32 bits? I'd like to verify that the value loaded in R4 is the same as my old u-boot-1.1.3 did.

Was it helpful?

Solution

It's not 32 bits, it's 5 bits.

The number 32 is 0x00000020.

31 is 0x0000001f.

~31 is 0xffffffe0.

So & 31 gives you the lower 5 bits.

& ~31 gives you all bits except with the lower 5 bits turned off.

The code appears to be getting the block number of one 32-byte block larger than the upper address of a RAM chip. I get that from the part where it adds 31 and then divides by 32.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top