How to compile for boot flow at EL2 (BL33)?

Hi,

The LLVM compiler - bare metal version, contains morello specific initialisation code for EL3 (sets up some registers and the mmu for DRAM0 etc). This allows you to easily compile c code to run at EL3. From here you can switch states and exception levels, but have to manage stacks and memory allocations and the c library functions are compiled into EL3 secure memory.

If I wish to compile a program directly for the normal world, at EL2 say (BL33) (so it can access its own c functions) and supply it as a binary directly into the FVP boot flow. I cannot use the LLVM bare metal version of the compiler with the initialisation code since it sets up EL3 registers which are not accessible at EL2. If I by-pass the initialisation code by making the image entry point directly to main, the stack is no longer set up. So EL2 requires it's own initialisation code.

My question is what is the best approach to take to be able to compile stand-a-lone code for EL2 (or any other execption level- EL1S/EL1N etc) so that it can be inserted as part of the boot flow (instead as part of one program for baremetal). Do I need to write my own EL2 initialisation code?, is there another version of the compiler? /setting for normal world code? or do I need to follow some other method?

I would like to be able to have the trusted firmware loaded via the boot flow process, and then be able to interact with it from either normal world code or trusted world code.

many thanks