From 046cf3c81e021a801d2710c7cfac169e814486ee Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Wed, 24 Jun 2026 18:45:50 -0500 Subject: [PATCH] Return a zero-filled register with uint8_t Apparently, gcc expects a uint8_t to be zero-padded if it's loaded into a register. A code that fails looks like this: uint8_t addr; uint64_t full_906 = (uint64_t)BUILD_GEN << (32 + 24); full_906 |= ((uint64_t)pfI2cCfgs[2].slaveAddress) << (32 + 16); addr = HW_get_8bit_reg(pfI2cCfgs[2].baseAddress, ADDRESS); full_906 |= ((uint64_t)addr) << (32 + 8); At this point, the value of full_906 is 0xFFFFFF8400000000 and the field of BUILD_GEN is destroyed. Observe, there's no signed int sneaking in through promotion. The sign-extension happens inside the assembly code. Therefore, we fix it. Signed-off-by: Pete Zaitcev --- hal/hw_reg_access.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hal/hw_reg_access.S b/hal/hw_reg_access.S index 41c7bbf..f2e1447 100644 --- a/hal/hw_reg_access.S +++ b/hal/hw_reg_access.S @@ -171,7 +171,7 @@ HW_set_8bit_reg: * @return 8 bits value read from the peripheral register. */ HW_get_8bit_reg: - lb a0, 0(a0) + lbu a0, 0(a0) ret /***************************************************************************//**