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:
- Starts executing at address 0, where the boorloader resides
- Bootloader loads the application ELF from UART and saves its sections in the correct addresses
_start label is read from the ELF and called
- The
main function will eventually return to the _start function in the standard library, which will execute brnd 0, spinning forever
- Reads the ELF of the application
- Before execution starts, forces the internal pins entering the program counter to the address of
_start from 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)
- Reads the ELF of the application
- Start executing at the address of
_start from 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
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):
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:
_startlabel is read from the ELF and calledmainfunction will eventually return to the_startfunction in the standard library, which will executebrnd 0, spinning forever_startfrom the ELF. This is to avoid the bootloader starting to run_startfrom the ELF immediatelyWe 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 emulatorThe startup sequence for the bootloader changes to check
EnvironmentIDfirst.If
EnvironmentID=1, it know it is running on the emulator and should instead call the address inEntryAddr, 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
EnvironmentIDalso 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
EnvironmentIDas an explicit application exit. The hardware needs to just ignore such a write.The standard library
_startis then updated to write toEnvironmentIDafter an application returns frommain, 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
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
startup2where 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):
EnvironmentID=0 andEntryAddr=0, at the next two addresses (0x38, 0x3c).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)EntryAddrpins to the application ELF_startaddress before execution starts. It is never unforced.EnvironmentIDfor exitEnvironmentID=2 andEntryAddr=0EnvironmentIDfor exit. Should no longer treatbrnd 0as halt.startup2as HEAD.