-
Notifications
You must be signed in to change notification settings - Fork 74
Description
This issue will track the redesign of the T-CREST platform's startup sequence and application exit.
Motivation
Our three environment (hardware, emulator, simulator) each have their own startup sequence:
- Hardware:
- Starts executing at address 0, where the boorloader resides
- Bootloader loads the application ELF from UART and saves its sections in the correct addresses
_startlabel is read from the ELF and called- The
mainfunction will eventually return to the_startfunction in the standard library, which will executebrnd 0, spinning forever
- Emulator:
- Reads the ELF of the application
- Before execution starts, forces the internal pins entering the program counter to the address of
_startfrom the ELF. This is to avoid the bootloader starting to run - After execution starts, unforces the pins to free the core (this does not work correctly)
- Simulator:
- Reads the ELF of the application
- Start executing at the address of
_startfrom the ELF immediately
We have complexity and maintainability issues because of the different ways execution start in each environment. But, most importantly, the current solution does not work for the emulator because the unforcing of the pins does not happen correctly.
Instead, we want a solution that is flexible and can be supported by all environments
Design
2 new read-only registers are added to the CpuInfo device (see table 3.4 in the handbook):
EnvironmentID: Value describing the environment we are running in. I.e. hardware, emulator, or simulator (or in the future, other potential implementations of Patmos).EntryAddr: Undefined for the hardware and simulator, but specifies the address of “_start” for the emulator
The startup sequence for the bootloader changes to check EnvironmentID first.
If EnvironmentID=1, it know it is running on the emulator and should instead call the address in EntryAddr, skipping the download.
For other values of EnvironmentID, the bootloader continues to download.
When running on the simulator, the bootloader is not present at all, so supporting the new registers would be only to ensure compatibility with the platform.
However, the EnvironmentID also adds the benefit that application code can check what environment it is running in. This could be used for various things, like optimizing for a specific implementation, or logging the environment during benchmarking.
To support application exit detection, the emulator and simulator may treat any writes to EnvironmentID as an explicit application exit. The hardware needs to just ignore such a write.
The standard library _start is then updated to write to EnvironmentID after an application returns from main, then return to the bootloader.
Since the hardware will ignore the write, the bootloader will be returned to.
On the emulator and simulator, the write will trigger exit and the bootloader is ignored.
Open Questions
- Name of
EntryAddr: While the purpose of this register is clear for the emulator, it is currently undefined for other environments. To be forward-looking, we could call this something else that doesn't specify as much meaning. E.g., couldEnvironmentInfocould be generic enough to allow any environment (future ones we haven't thought of yet) to use this to provide any information it wants.
Implementation
The changes needed to implement this new startup sequence require all the environments to switch to the new implementations simultaneously.
Therefore, all repositories should create a new branch called startup2 where the code will live until the switch is done.
Here is a list of distinct tasks that need to be done (feel free to make new issues for each and then link them here):
- Patmos hardware: Update CpuInfo device with to add
EnvironmentID=0 andEntryAddr=0, at the next two addresses (0x38, 0x3c). - Patmos hardware: New top-level device is implemented using BoringUtils to set
EnvironmentID=0 and exposeEntryAddras pins for the emulator to set. (for multicore, all cores get the sameEntryAddr, i.e., no exposed pins for each core) - Patmos handbook: Update section 3.2.1 and table 3.4 with the two registers.
- Patmos emulator: C++ harness is updated to set exposed
EntryAddrpins to the application ELF_startaddress before execution starts. It is never unforced. - Patmos emulator: Updated to continuously check for writes to
EnvironmentIDfor exit - Patmos simulator: CpuInfo device is update with
EnvironmentID=2 andEntryAddr=0 - Patmos simulator: Updated to continuously check for writes to
EnvironmentIDfor exit. Should no longer treatbrnd 0as halt. - All repositories are switched at the same time to use
startup2as HEAD.