coreboot/src/commonlib
Patrick Rudolph f0d50aa404 commonlib/include/commonlib: Add volatile qualifier
With the introduction of the stack canary breakpoint QEMU uncovered
a different bug within coreboot. Currently the compiler optimizes
over aggressively inline functions and memory stores.

That also affects write_at_ble8(), which is supposed to store a
single byte at time. The compiler however optimizes multiple byte
stores into a single wider (and possibly unaligned) store operation.

This can be seen in the emited assembly code of write_le16(), as used
to install the EBDA:
 401348a:       66 c7 04 25 13 04 00    movw   $0x400,0x413
 4013491:       00 00 04

Make sure that the compiler does not optimize multiple calls to
write_at_ble8() by adding the volatile qualifier.

The emitted assembly code of the same function changes to:
 401394c:       c6 04 25 13 04 00 00    movb   $0x0,0x413
 4013953:       00
 4013954:       c6 04 25 14 04 00 00    movb   $0x4,0x414
 401395b:       04

Fixes a strange bug in QEMU where it triggers the DEBUG breakpoint
handler on unaligned 16-bit stores in the first 4KiB of memory.
Aligned stores and store outside of the first 4KiB do not dispatch
the DEBUG breakpoint handler.

Change-Id: Ibbc661235a38c7f7540b656a67f067c3e51105d1
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/85855
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2025-07-22 16:30:38 +00:00
..
bsd treewide: Work around GCC 15 Werror=unterminated-string-initialization 2025-06-09 07:19:09 +00:00
include/commonlib commonlib/include/commonlib: Add volatile qualifier 2025-07-22 16:30:38 +00:00
storage commonlib/storage: Avoid build error when CONFIG_PCI is disabled 2025-04-03 03:11:05 +00:00
device_tree.c commonlib/device_tree.c: Add a function that reads FDT ints 2025-06-07 15:04:34 +00:00
fsp_relocate.c commonlib/fsp_relocate: Add PE32+ support 2024-06-21 15:49:38 +00:00
iobuf.c src/commonlib: Clean up includes 2022-10-26 16:27:10 +00:00
list.c treewide: Move list.h to commonlib 2024-02-24 11:49:46 +00:00
Makefile.mk mb/emulation/qemu-riscv: Add support for 512 harts 2025-02-28 18:27:39 +00:00
mem_pool.c commonlib/mem_pool: Allow configuring the alignment 2021-11-04 10:33:52 +00:00
rational.c commonlib: Add support for rational number approximation 2022-08-03 03:26:13 +00:00
region.c region: Turn region_end() into an inclusive region_last() 2024-08-23 01:08:16 +00:00
sort.c treewide: Remove "this file is part of" lines 2020-05-11 17:11:40 +00:00