-------------------------------------------------------------------------------
-- Module      = coldreset.850
-- Version     = E1.0.2g
--               manually created  
--               
-------------------------------------------------------------------------------
--                                  COPYRIGHT
-------------------------------------------------------------------------------
-- Copyright (c) 2018 - 2020 by Renesas Electronics Europe GmbH,
--               a company of the Renesas Electronics Corporation
-------------------------------------------------------------------------------
-- Purpose:      Startup Code
--
-------------------------------------------------------------------------------
--
-- Warranty Disclaimer
--
-- Because the Product(s) is licensed free of charge, there is no warranty
-- of any kind whatsoever and expressly disclaimed and excluded by Renesas,
-- either expressed or implied, including but not limited to those for
-- non-infringement of intellectual property, merchantability and/or
-- fitness for the particular purpose.
-- Renesas shall not have any obligation to maintain, service or provide bug
-- fixes for the supplied Product(s) and/or the Application.
--
-- Each User is solely responsible for determining the appropriateness of
-- using the Product(s) and assumes all risks associated with its exercise
-- of rights under this Agreement, including, but not limited to the risks
-- and costs of program errors, compliance with applicable laws, damage to
-- or loss of data, programs or equipment, and unavailability or
-- interruption of operations.
--
-- Limitation of Liability
--
-- In no event shall Renesas be liable to the User for any incidental,
-- consequential, indirect, or punitive damage (including but not limited
-- to lost profits) regardless of whether such liability is based on breach
-- of contract, tort, strict liability, breach of warranties, failure of
-- essential purpose or otherwise and even if advised of the possibility of
-- such damages. Renesas shall not be liable for any services or products
-- provided by third party vendors, developers or consultants identified or
-- referred to the User by Renesas in connection with the Product(s) and/or
-- the Application.
--
-------------------------------------------------------------------------------
-- Environment:
--              Device:         All RH850 Mutlicore
--              IDE:            GHS Multi V7.1.4 or later
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Revision Control History:
-- E1.0.0g :   23th-Jan-2018    : Initial Version
-- E1.0.1g :   25th-Jun-2019    : Updated Activation of PE for support U2AEVA
--                                Updated PEn startup routine
-- E1.0.2g :   07th-Jan-2020    : Added SYNCI in Common Startup Routine 

-------------------------------------------------------------------------------
#include <cold_irq.h>
#include <Startup.inc>
#define MAX_PE1 //sky add
  .extern   _RESET_PE0
  .extern   _RESET_PEn
  .text
  
-------------------------------------------------------------------------------
-------------  Common Startup Routine
-------------------------------------------------------------------------------
_RESET:
  -- PE0 set Boot Control Register for all PE
  stsr  0,    r1, 2
  andi  0x7,  r1, r1
  cmp   PE0,  r1
  bne   2f
  SYNCI
  1: jr   _BOOTCTRL_SETTING
  2: jr   _PE_RESET

_PE_RESET:
  -- CPU function group program registers initialization
  mov   r0, r2
  mov   r0, r3
  mov   r0, r4
  mov   r0, r5
  mov   r0, r6
  mov   r0, r7
  mov   r0, r8
  mov   r0, r9
  mov   r0, r10
  mov   r0, r11
  mov   r0, r12
  mov   r0, r13
  mov   r0, r14
  mov   r0, r15
  mov   r0, r16
  mov   r0, r17
  mov   r0, r18
  mov   r0, r19
  mov   r0, r20
  mov   r0, r21
  mov   r0, r22
  mov   r0, r23
  mov   r0, r24
  mov   r0, r25
  mov   r0, r26
  mov   r0, r27
  mov   r0, r28
  mov   r0, r29
  mov   r0, r30
  mov   r0, r31
  
  -- CPU function group system registers initialization
  ldsr  r0,         EIPC,  0
  ldsr  r0,         EIPSW, 0
  ldsr  r0,         FEPC,  0
  ldsr  r0,         FEPSW, 0
  mov   0x00000020, r6
  ldsr  r6,         PSW,   0
  ldsr  r0,         EIIC,  0
  ldsr  r0,         FEIC,  0
  ldsr  r0,         CTPC,  0
  ldsr  r0,         CTPSW, 0
  ldsr  r0,         CTBP,  0
  ldsr  r0,         EIWR,  0
  ldsr  r0,         FEWR,  0
  ldsr  r0,         RBASE, 1
  ldsr  r0,         EBASE, 1
  ldsr  r0,         INTBP, 1
  ldsr  r0,         SCCFG, 1
  ldsr  r0,         SCBP,  1
  ldsr  r0,         MEA,   2
  ldsr  r0,         MEI,   2

  -- Don't Initialize registers list
  -- Following registers is't set by this startup routine
  -- SNZCFG, SPID, SPIDLIST, MCTL, PID, SVLOCK,
  -- PEID, BMID, RBCR0, RBCR1, RBNR, RBIP
  
  -- Jump to PEn Startup Routine
  jmpIfPEn  _RESET_PEn, PE3
  jmpIfPEn  _RESET_PEn, PE2
  jmpIfPEn  _RESET_PEn, PE1
  jmpIfPEn  _RESET_PE0, PE0

__unused_isr:
  br __unused_isr
  
 -- PEn activation
_BOOTCTRL_SETTING:
#if defined (MAX_PE3)
  mov   0xFFFB2000, r2
  mov   0x0F, r3
  st.w  r3, 0[r2]
  jr   _PE_RESET
#endif
#if defined (MAX_PE1)
  mov   0xFFFB2000, r2
  mov   0x03, r3
  st.w  r3, 0[r2]
  jr   _PE_RESET
#endif 

-------------------------------------------------------------------------------
-------------  Add section ".intvect_PE0" to your linker command file
-------------  at address 0x0000
-------------------------------------------------------------------------------
.section".intvect_PE0",.text

-------------------------------------------------------------------------------
-------------  Initializing of interrupt vector table
-------------  Please don't modify this section
-------------------------------------------------------------------------------
  .global _RESET_VECTOR
  .offset 0x0000
_RESET_VECTOR:
  #if (RESET_ENABLE > 0x00000000)
    .extern _RESET
    jr _RESET
  #else
    jr __unused_isr
  #endif

