"how can i Reset all of the registers of the CPU after bootloader is jumping to the Application software, in the Application Software. "
As I understand what you wrote above:
The bootloader has messed with lots of things, we don't know what, so we want to start as if we are starting from a clean reset out of the bootloader when it has jumped to our application.
This is how that is handled:
We look at the BOOTLOADER bit in RCM.
When we see that the bootloader was what got us to main(), we issue a software reset to reset the hardware registers to the data sheet values.
How at this second boot we look at RCM again to see if we got here via either Watchdog or SWS reset.
SWS tells us that we got here because the bootloader started us and this is our reset from that event, and this is the second reset in this boot process.
If nothing special needs done on this second boot then no need to look at SWS and the software can treat it as it would POR or PIN-Reset.
This is what I have in my own vectors.c that is the first code executed out of hardware reset:
/* This overrides the weakly linked funciton in vectors.c so we can found out why we rebooted */
void bootloader_mr_setup( void );
void bootloader_mr_setup( void )
{
/*
* RCM_MR Indicates the boot source, the boot source remains set
* until the next System Reset or software can write logic one to
* clear the corresponding mode bit. While either bit is set the
* NMI input is disabled and the vector table is relocated to the
* ROM base address at 0x1C00_0000. These bits should be cleared by
* writing logic one before executing any code from either Flash or
* SRAM.
*
* A reset is forced to clear out anything that the ROM
* bootloader did, so we are sure we have the data sheet reset
* values.
*
* This method works around the buggy KL43/27/17 bootloaders as
* described in: "Problem Analysis and solutions for booting from
* ROM BOOTLOADER in KL series".
*/
boot_src_u16_n = ( ( ( uint32_t ) RCM_FM << 8U ) | ( ( uint32_t ) RCM_MR ) );
if( 0U != ( RCM_MR & RCM_MR_BOOTROM_MASK ) )
{
RCM_MR = RCM_MR_BOOTROM_MASK; /* Clear the bits that indicated a bootlaoder boot via ROM */
RCM_FM = 0U; /* Boot from Flash not ROM on next reset */
SCB_AIRCR = ( SCB_AIRCR_VECTKEY( 0x05FAU ) | SCB_AIRCR_SYSRESETREQ_MASK ); /* Force a Software Reset */
}
RCM_FM = 0U;
}