Skip to content

Commit

Permalink
MOAR DEBUG
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk committed Jan 24, 2025
1 parent 8284858 commit cc0e968
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
5 changes: 4 additions & 1 deletion grub-core/loader/multiboot_mbi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,9 +1268,12 @@ grub_multiboot2_perform_slaunch (grub_uint32_t mbi_target,
(unsigned) slparams->slr_table_size);

dlinfo = grub_slr_next_entry_by_tag (slparams->slr_table_mem, NULL, GRUB_SLR_ENTRY_DL_INFO);
grub_dprintf ("slaunch", "slparams = %p\n", slparams);
grub_dprintf ("slaunch", "dlinfo = %p\n", dlinfo);
grub_dprintf ("slaunch", "dlinfo->bl_context.context = %p\n", dlinfo->bl_context.context);
dl_entry ((grub_uint64_t)(grub_addr_t) &dlinfo->bl_context);

grub_dprintf ("slaunch", "BROKEN dl_entry!");
grub_dprintf ("slaunch", "BROKEN dl_entry!\n");

/* If this returns, something failed miserably */
return grub_error (GRUB_ERR_BAD_DEVICE, N_("Failed to start D-RTM"));
Expand Down
24 changes: 19 additions & 5 deletions grub-core/loader/slaunch/dlstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void dl_entry (grub_uint64_t dl_ctx)
struct grub_relocator32_state state = {0};
grub_err_t err;

grub_dprintf ("slaunch", "dl_entry(): enter\n");

state.edi = slparams->platform_type;

/* This is done on both Intel and AMD platforms */
Expand All @@ -52,16 +54,22 @@ void dl_entry (grub_uint64_t dl_ctx)

if (slparams->platform_type == SLP_INTEL_TXT)
{
grub_dprintf ("slaunch", "dl_entry(): Intel, set MTRRs\n");

err = grub_set_mtrrs_for_acmod ((void *)(grub_addr_t)slparams->dce_base);
if (err)
{
grub_dprintf ("slaunch", "dl_entry(): MTRRs FAIL!\n");
grub_error (GRUB_ERR_BAD_DEVICE, N_("setting MTRRs for TXT SINIT failed"));
return;
}

grub_dprintf ("slaunch", "dl_entry(): Intel, prepare CPU\n");

err = grub_txt_prepare_cpu ();
if ( err )
{
grub_dprintf ("slaunch", "dl_entry(): CPU FAIL!\n");
grub_error (GRUB_ERR_BAD_DEVICE, N_("prepare CPU for TXT SENTER failed"));
return;
}
Expand Down Expand Up @@ -99,18 +107,22 @@ void dl_entry (grub_uint64_t dl_ctx)
return;
}

grub_dprintf ("slaunch", "dl_entry(): BSP check!\n");

if (!(grub_rdmsr (GRUB_MSR_X86_APICBASE) & GRUB_MSR_X86_APICBASE_BSP))
{
grub_dprintf ("slaunch", "dl_entry(): BSP fail!\n");

grub_error (GRUB_ERR_BAD_DEVICE, N_("x86 dynamic launch event must be performed on the BSP"));
return;
}

if (slparams->boot_type == GRUB_SL_BOOT_TYPE_LINUX || slparams->boot_type == GRUB_SL_BOOT_TYPE_MB2)
{
grub_dprintf ("slaunch", "Linux/MB2?");
grub_dprintf ("slaunch", "Linux/MB2?\n");
if (slparams->platform_type == SLP_INTEL_TXT)
{
grub_dprintf ("slaunch", "Intel");
grub_dprintf ("slaunch", "Intel\n");
/* Configure relocator GETSEC[SENTER] call. */
state.eax = GRUB_SMX_LEAF_SENTER;
state.ebx = slparams->dce_base;
Expand All @@ -119,21 +131,23 @@ void dl_entry (grub_uint64_t dl_ctx)
}
else if (slparams->platform_type == SLP_AMD_SKINIT)
{
grub_dprintf ("slaunch", "AMD");
grub_dprintf ("slaunch", "AMD\n");
/* Configure relocator GETSEC[SENTER] call. */
state.eax = slparams->dce_base;
}

grub_relocator32_boot (slparams->relocator, state, 0);
grub_dprintf ("slaunch", "relocator has failed?");
grub_dprintf ("slaunch", "relocator has failed?\n");
}
else if (slparams->boot_type == GRUB_SL_BOOT_TYPE_EFI)
{
grub_dprintf ("slaunch", "EFI?");
grub_dprintf ("slaunch", "EFI?\n");
dl_trampoline (slparams->dce_base, slparams->dce_size, slparams->platform_type);
}
else
{
grub_dprintf ("slaunch", "dl_entry(): bad boot type?: %d\n", slparams->boot_type);

grub_error (GRUB_ERR_BUG, N_("unknown dynamic launch boot type: %d"), slparams->boot_type);
}
}
6 changes: 3 additions & 3 deletions grub-core/loader/slaunch/txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ grub_txt_boot_prepare (struct grub_slaunch_params *slparams)
err = init_txt_heap (slparams, sinit_base);

if (err != GRUB_ERR_NONE) {
grub_dprintf ("slaunch", "BROKEN init_txt_heap!");
grub_dprintf ("slaunch", "BROKEN init_txt_heap!\n");
return err;
}

Expand All @@ -1021,7 +1021,7 @@ grub_txt_boot_prepare (struct grub_slaunch_params *slparams)
}
else
{
grub_dprintf ("slaunch", "didn't update MLE header!");
grub_dprintf ("slaunch", "didn't update MLE header!\n");
}

slparams->dce_base = (grub_uint32_t)(grub_addr_t) sinit_base;
Expand All @@ -1038,6 +1038,6 @@ grub_txt_boot_prepare (struct grub_slaunch_params *slparams)

grub_tpm_relinquish_locality (0);

grub_dprintf ("slaunch", "all good in grub_txt_boot_prepare()!");
grub_dprintf ("slaunch", "all good in grub_txt_boot_prepare()!\n");
return GRUB_ERR_NONE;
}

0 comments on commit cc0e968

Please sign in to comment.