Skip to content

Commit

Permalink
smm: Suppress gcc array-bounds warnings
Browse files Browse the repository at this point in the history
Add a hack to suppress spurious gcc array-bounds warning (on at least
gcc v11).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
  • Loading branch information
KevinOConnor committed Jan 21, 2022
1 parent 6a62e0c commit e4f02c1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/fw/smm.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ struct smm_layout {
struct smm_state cpu;
};

// Hack to supress some gcc array-bounds warnings
static void
memcpy_nowarn(void *d, const void *s, size_t len)
{
asm("" : "+r"(d), "+r"(s));
memcpy(d, s, len);
}

void VISIBLE32FLAT
handle_smi(u16 cs)
{
Expand All @@ -85,8 +93,8 @@ handle_smi(u16 cs)
if (CONFIG_CALL32_SMM) {
// Backup current cpu state for SMM trampolining
struct smm_layout *newsmm = (void*)BUILD_SMM_ADDR;
memcpy(&newsmm->backup1, &smm->cpu, sizeof(newsmm->backup1));
memcpy(&newsmm->backup2, &smm->cpu, sizeof(newsmm->backup2));
memcpy_nowarn(&newsmm->backup1, &smm->cpu, sizeof(newsmm->backup1));
memcpy_nowarn(&newsmm->backup2, &smm->cpu, sizeof(newsmm->backup2));
HaveSmmCall32 = 1;
}

Expand Down Expand Up @@ -145,8 +153,8 @@ smm_save_and_copy(void)
// save original memory content
struct smm_layout *initsmm = (void*)BUILD_SMM_INIT_ADDR;
struct smm_layout *smm = (void*)BUILD_SMM_ADDR;
memcpy(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu));
memcpy(&smm->codeentry, &initsmm->codeentry, sizeof(smm->codeentry));
memcpy_nowarn(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu));
memcpy_nowarn(&smm->codeentry, &initsmm->codeentry, sizeof(smm->codeentry));

// Setup code entry point.
initsmm->codeentry = SMI_INSN;
Expand All @@ -168,8 +176,9 @@ smm_relocate_and_restore(void)
/* restore original memory content */
struct smm_layout *initsmm = (void*)BUILD_SMM_INIT_ADDR;
struct smm_layout *smm = (void*)BUILD_SMM_ADDR;
memcpy(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu));
memcpy(&initsmm->codeentry, &smm->codeentry, sizeof(initsmm->codeentry));
memcpy_nowarn(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu));
memcpy_nowarn(&initsmm->codeentry, &smm->codeentry
, sizeof(initsmm->codeentry));

// Setup code entry point.
smm->codeentry = SMI_INSN;
Expand Down

0 comments on commit e4f02c1

Please sign in to comment.