-
Notifications
You must be signed in to change notification settings - Fork 22
[sw-sysemu] erbium boot protocol support #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AFOliveira
wants to merge
6
commits into
aifoundry-org:master
Choose a base branch
from
AFOliveira:fix/erbium-sysreg-reset-values
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
abe8861
[sw-sysemu] add MRAM boot protocol region checker
AFOliveira 66e4d24
[sw-sysemu] reserve first 256 bytes of MRAM for boot protocol region
AFOliveira 2bb49c6
[sw-sysemu] make load_elf() return the ELF entry point
AFOliveira 7606449
[sw-sysemu] add apply_boot_protocol() platform method
AFOliveira 30c74a2
[sw-sysemu] add --boot_elf/--payload_pc/--payload_sp and wire up boot…
AFOliveira c61500f
[sw-sysemu] add boot protocol tests
AFOliveira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /*------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Ainekko, Co. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| *-------------------------------------------------------------------------*/ | ||
|
|
||
| #include "emu_defines.h" | ||
|
|
||
| #if EMU_ERBIUM | ||
| #include "boot-protocol_er.cpp" | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /*------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Ainekko, Co. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| *-------------------------------------------------------------------------*/ | ||
|
|
||
| #include <cinttypes> | ||
|
|
||
| #include "system.h" | ||
| #include "processor.h" | ||
| #include "emu_gio.h" | ||
|
|
||
| namespace bemu { | ||
|
|
||
| void System::apply_boot_protocol(uint64_t payload_pc, uint64_t payload_sp) | ||
| { | ||
| constexpr uint64_t MRAM_BASE = 0x40000000ULL; | ||
| constexpr uint64_t BOOT_PROT_SIZE = 0x100; | ||
| constexpr uint64_t PC_OFFSET = 0x28; | ||
| constexpr uint64_t SP_OFFSET = 0x20; | ||
|
|
||
| // Write PC and SP to MRAM boot vector addresses | ||
| memory.init(noagent, MRAM_BASE + PC_OFFSET, sizeof(payload_pc), &payload_pc); | ||
| memory.init(noagent, MRAM_BASE + SP_OFFSET, sizeof(payload_sp), &payload_sp); | ||
|
|
||
| uint64_t pc = payload_pc; | ||
| uint64_t sp = payload_sp; | ||
|
|
||
| // Sanity checks | ||
| if (pc >= MRAM_BASE && pc < MRAM_BASE + BOOT_PROT_SIZE) | ||
| LOG_AGENT(WARN, noagent, "Payload PC (0x%" PRIx64 ") points into boot protocol region", pc); | ||
| if (sp >= MRAM_BASE && sp < MRAM_BASE + BOOT_PROT_SIZE) | ||
| LOG_AGENT(WARN, noagent, "Payload SP (0x%" PRIx64 ") points into boot protocol region", sp); | ||
|
|
||
| // Set enabled harts | ||
| for (unsigned h = 0; h < EMU_NUM_THREADS; ++h) { | ||
| if (cpu[h].is_nonexistent() || cpu[h].is_unavailable()) | ||
| continue; | ||
| cpu[h].pc = pc; | ||
| cpu[h].npc = pc; | ||
| cpu[h].xregs[2] = sp; | ||
| } | ||
| } | ||
|
|
||
| } // namespace bemu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /*------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Ainekko, Co. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| *-------------------------------------------------------------------------*/ | ||
|
|
||
| /* | ||
| * Test: --payload_sp sets the initial stack pointer | ||
| * | ||
| * This is a standalone assembly test (no boot.S) that checks SP at the | ||
| * very first instruction. Must be run with: | ||
| * --boot_elf <this_elf> --payload_sp 200c100 | ||
| * | ||
| * The boot protocol sets SP before the hart starts executing, so we | ||
| * check it immediately at entry before anything can overwrite it. | ||
| */ | ||
|
|
||
| .section .text.init, "ax", @progbits | ||
| .globl _boot | ||
| _boot: | ||
| li t0, 0x200c100 | ||
| bne sp, t0, fail | ||
|
|
||
| /* PASS */ | ||
| li a7, 0x1feed000 | ||
| csrw 0x8d0, a7 /* validation0 */ | ||
| j done | ||
|
|
||
| fail: | ||
| /* FAIL */ | ||
| li a7, 0x50bad000 | ||
| csrw 0x8d0, a7 /* validation0 */ | ||
|
|
||
| done: | ||
| wfi | ||
| j done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /*------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Ainekko, Co. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| *-------------------------------------------------------------------------*/ | ||
|
|
||
| /* | ||
| * Test: Store to MRAM boot protocol region succeeds with warning | ||
| * | ||
| * The first 256 bytes of MRAM (0x40000000-0x400000FF) are reserved for | ||
| * the boot protocol. Stores are allowed (no fault) but the emulator | ||
| * logs a warning. Verify the store actually lands in memory. | ||
| */ | ||
|
|
||
| #include "test.h" | ||
| #include <stdint.h> | ||
|
|
||
| #define MRAM_BOOT_REGION 0x40000020ull /* Payload SP offset */ | ||
| #define TEST_PATTERN 0xDEADBEEFCAFEFEEDull | ||
|
|
||
| int main() { | ||
| volatile uint64_t *boot_region = (volatile uint64_t *)MRAM_BOOT_REGION; | ||
|
|
||
| *boot_region = TEST_PATTERN; | ||
|
|
||
| if (*boot_region == TEST_PATTERN) { | ||
| TEST_PASS; | ||
| } | ||
|
|
||
| TEST_FAIL; | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.