Hello,
Since you will require a reset to exit the application, and re-enter the bootloader, the allocation of RAM resources for the bootloader should not matter. When the application code is entered, it will simply re-allocate the RAM, including the stack, for its own purpose. Once the application code starts, the bootloader is finished.
What does the address 0x7F7F represent? It cannot be the location of the application's _Startup function since this is not fixed, and it seems inappropriate as a vector location.
As an example, let's assume that the bootloader occupies the flash sectors between 0xF700 and 0xFFFF. For the 9S08DN device, this block should be a multiple of 768 bytes, the flash sector size. (For most other MC9S08' the multiple would be 512 bytes). This would mean that the uppermost address for the application code would be 0xF6FF. It would then be usual for the bootloader, when loading the program, to reposition the application reset vector from 0xFFFE to 0xF6FE.
When using the BDM to directly load the application code, this repositioning needs to be taken into account by the linking process for the application. Within the PRM file, you might invoke VECTOR ADDRESS 0xF6FE _Startup in lieu of the normal invocation VECTOR 0 _Startup
However, should the reset vector already be included within a vector table, this method will not work. What repositioning method are you using for the vectors other than the reset vector?
With the above assumptions, the following assembly code would be required to enter the application's _Startup function.
__asm {
ldhx #0xF6FE // Address of repositioned reset vector
ldhx ,x // Vector contents - address of _Startup
jmp ,x // Jump to startup function
}
The second method that you mention will not work because the contents at address 0xF6FE-0xF6FF should be a vector value, and not an instruction - this is effectively an indirect jump. The following method, which has a subtle difference from your second method, should also work for the repositioned vector.
__asm {
ldhx 0xF6FE // Read contents of repositioned vector
jmp ,x // Jump to startup function
}
Before attempting to jump to the application code, it would be worthwhile to modify the above code to check that the vector value has actually been programmed, and contains a value other than 0xFFFF. If not, the operation should remain within the bootloader.
With regard to SOPT, and other write-once system registers, you may leave them at the POR default settings until the application code is commenced. However, if the default settings are unsuitable for the bootloader operation, you will need to initialise within the bootloader, with settings that also suit the application. This may include features that are not required by the current version of the application code, but might be required for a future version.
Regards,
Mac