Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35140 )
Change subject: [WIP] arch/x86: Refactor CAR_GLOBAL quirk for FSP1.0 ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35140/2/src/cpu/x86/car.c File src/cpu/x86/car.c:
https://review.coreboot.org/c/coreboot/+/35140/2/src/cpu/x86/car.c@97 PS2, Line 97: uintptr_t *mig_var = car_get_var_ptr(var); Could you add some comments here?
We're getting the migrated pointer and subtracting the value at this new slot?
I'm commenting my thought process here as it's not immediately obvious to me.
struct foo { void *bar; } baz;
&baz == &baz.bar prior to relocation, say it's address A.
baz.bar points to something else, address is B but let's say just after baz, A + sizeof(struct foo); i.e. B = A + sizeof(struct foo).
Things get moved. A -> A' = A - 0x1000 (arbitrary offset for explanation).
bar.baz should have a value of B' = B - 0x1000 == A' + sizeof(struct foo).
So this code: mig_var = car_get_var_ptr(&bar.baz) /* A' */ if (*mig_var) /* *mig_var = B */ return A' - B;
A - 0x1000 - B = A - 0x1000 - (A + sizeof(struct foo) = -0x1000 - sizeof(struct foo)
That math doesn't work in my mind. Can you explain further?