1 | /** @file
|
---|
2 | RISC-V specific functionality for DxeLoad.
|
---|
3 |
|
---|
4 | Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
|
---|
5 | Copyright (c) 2023, Rivos Inc
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 | #include <PiPei.h>
|
---|
11 | #include <Library/BaseLib.h>
|
---|
12 | #include <Library/DebugLib.h>
|
---|
13 | #include <Library/BaseMemoryLib.h>
|
---|
14 | #include <Library/MemoryAllocationLib.h>
|
---|
15 | #include <Library/PcdLib.h>
|
---|
16 | #include <Library/HobLib.h>
|
---|
17 | #include "UefiPayloadEntry.h"
|
---|
18 |
|
---|
19 | #define STACK_SIZE 0x20000
|
---|
20 |
|
---|
21 | /**
|
---|
22 | Transfers control to DxeCore.
|
---|
23 |
|
---|
24 | This function performs a CPU architecture specific operations to execute
|
---|
25 | the entry point of DxeCore with the parameters of HobList.
|
---|
26 | It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.
|
---|
27 |
|
---|
28 | @param DxeCoreEntryPoint The entry point of DxeCore.
|
---|
29 | @param HobList The start of HobList passed to DxeCore.
|
---|
30 |
|
---|
31 | **/
|
---|
32 | VOID
|
---|
33 | HandOffToDxeCore (
|
---|
34 | IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
|
---|
35 | IN EFI_PEI_HOB_POINTERS HobList
|
---|
36 | )
|
---|
37 | {
|
---|
38 | VOID *BaseOfStack;
|
---|
39 | VOID *TopOfStack;
|
---|
40 |
|
---|
41 | //
|
---|
42 | //
|
---|
43 | // Allocate 128KB for the Stack
|
---|
44 | //
|
---|
45 | BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
|
---|
46 | if (BaseOfStack == NULL) {
|
---|
47 | DEBUG ((DEBUG_ERROR, "%a: Can't allocate memory for stack.", __func__));
|
---|
48 | ASSERT (FALSE);
|
---|
49 | }
|
---|
50 |
|
---|
51 | //
|
---|
52 | // Compute the top of the stack we were allocated. Pre-allocate a UINTN
|
---|
53 | // for safety.
|
---|
54 | //
|
---|
55 | TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
|
---|
56 | TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
---|
57 |
|
---|
58 | //
|
---|
59 | // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
|
---|
60 | //
|
---|
61 | UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
|
---|
62 |
|
---|
63 | DEBUG ((DEBUG_INFO, "DXE Core new stack at %x, stack pointer at %x\n", BaseOfStack, TopOfStack));
|
---|
64 |
|
---|
65 | //
|
---|
66 | // Transfer the control to the entry point of DxeCore.
|
---|
67 | //
|
---|
68 | SwitchStack (
|
---|
69 | (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
|
---|
70 | HobList.Raw,
|
---|
71 | NULL,
|
---|
72 | TopOfStack
|
---|
73 | );
|
---|
74 | }
|
---|