Init local memory in each core

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Init local memory in each core

632 Views
曾经怀念
Contributor II

I want to initialize DMEM in each core and enable CACHE function, based on MPC5746R.

I think there is something wrong with the startup code because MEMU reports a failure

  _RAM_START_ADDR = 0x40000000;
  __CORE1_LOCAL_IMEM_BASE_ADDR = 0x51000000;
  __CORE1_LOCAL_IMEM_SIZE = 0x000004000;
  __CORE1_LOCAL_DMEM_BASE_ADDR = 0x51800000;
  __CORE1_LOCAL_DMEM_SIZE = 0x000008000;
  __CORE0_LOCAL_IMEM_BASE_ADDR = 0x51000000;
  __CORE0_LOCAL_IMEM_SIZE = 0x000004000;
  __CORE0_LOCAL_DMEM_BASE_ADDR = 0x50800000;
  __CORE0_LOCAL_DMEM_SIZE = 0x000008000;

___asm(_start_c0:)
___asm(__start_c0:)
__as1(e_lis  r11, _RAM_START_ADDR@h;     
  __as2(e_ori  r11,r11, _RAM_START_ADDR@l;
__as1(e_lis  r16,0x0000  ;/* init pattern */)
__as1(e_lis  r17,0x0000  ;/* init pattern */)
__as1(e_lis  r18,0x0000  ;/* init pattern */)
__as1(e_lis  r19,0x0000  ;/* init pattern */)
__as1(e_lis  r20,0x0000  ;/* init pattern */)
__as1(e_lis  r21,0x0000  ;/* init pattern */)
__as1(e_lis  r22,0x0000  ;/* init pattern */)
__as1(e_lis  r23,0x0000  ;/* init pattern */)
__as1(e_lis  r24,0x0000  ;/* init pattern */)
__as1(e_lis  r25,0x0000  ;/* init pattern */)
__as1(e_lis  r26,0x0000  ;/* init pattern */)
__as1(e_lis  r27,0x0000  ;/* init pattern */)
__as1(e_lis  r28,0x0000  ;/* init pattern */)
__as1(e_lis  r29,0x0000  ;/* init pattern */)
__as1(e_lis  r30,0x0000  ;/* init pattern */)
__as1(e_lis  r31,0x0000  ;/* init pattern */)
___asm(;/* skip RAM init for slave cores */)
__as1(mfspr     r3, PIR         ;/* read out CPU ID PIR                 */)
__as1(se_cmpi   r3, BRS_CPU_STARTUP_ID     ;/* if current CPU is NOT startup core?   */)
___asm(se_bne   _InitCore0Ram       ;/* proceed with section F              */

___asm(_init_l2ram:)
__as1(e_li r12,BRSHW_CPU_MAX_RAM)
__as2(e_slwi r12,r12,4;/* *r12 = *r12<<4 (Standard Singlecore implementation)*/)
___asm(;/*__as2(e_slwi r12,r12,3) -> Dualcore bugfix! */)

___asm(mtctr r12 ;/* set IP to r12*/)

___asm(_init_l2ram_loop:)
__as1(e_stmw    r16,0(r11))
__as2(e_addi    r11,r11,64)
___asm(;/* if you get a reset here try to use the "Dualcore bugfix" instead of the "Standard Singlecore implementation" above */)
___asm(e_bdnz    _init_l2ram_loop)

___asm(;/*****************************************************************************/)
___asm(;/* (D) Initialise Core 1 Local Data SRAM ECC                                 */)
___asm(;/*****************************************************************************/)
__as1(e_lis  r5, __CORE1_LOCAL_DMEM_SIZE@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE1_LOCAL_DMEM_SIZE@l;      /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE1_LOCAL_DMEM_SIZE@l;          /* lowbytes  - r11 holds start address of the RAM */)
#endif

__as2(e_srwi  r5,r5, 0x7;                         /* # Divide SRAM size by 128 */ )
___asm(se_mtctr r5;                               /* # Move to counter for use with "bdnz" */  )

__as1(e_lis  r5, __CORE1_LOCAL_DMEM_BASE_ADDR@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE1_LOCAL_DMEM_BASE_ADDR@l;    /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE1_LOCAL_DMEM_BASE_ADDR@l; /* lowbytes  - r11 holds start address of the RAM */)
#endif

___asm(core1_ldmem_loop:)
__as1(e_stmw      r0,0(r5);             /* # Write all 32 registers to SRAM */)
__as2(e_addi      r5,r5,128;            /* # Increment the RAM pointer to next 128bytes */)
___asm(e_bdnz      core1_ldmem_loop;          /* # Loop for all of SRAM */)

___asm(;/*****************************************************************************/)
___asm(;/* (D) Initialise Core 1 Local Instruction SRAM ECC                          */)
___asm(;/*****************************************************************************/)
__as1(e_lis  r5, __CORE1_LOCAL_IMEM_SIZE@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE1_LOCAL_IMEM_SIZE@l;    /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE1_LOCAL_IMEM_SIZE@l; /* lowbytes  - r11 holds start address of the RAM */)
#endif
__as2(e_srwi  r5,r5, 0x7/* # Divide SRAM size by 128 */ )
___asm(se_mtctr r5;  /* # Move to counter for use with "bdnz" */  )

__as1(e_lis  r5, __CORE1_LOCAL_IMEM_BASE_ADDR@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE1_LOCAL_IMEM_BASE_ADDR@l;    /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE1_LOCAL_IMEM_BASE_ADDR@l; /* lowbytes  - r11 holds start address of the RAM */)
#endif
___asm(core1_limem_loop:)
__as1(e_stmw      r0,0(r5);             /* # Write all 32 registers to SRAM */)
__as2(e_addi      r5,r5,128;            /* # Increment the RAM pointer to next 128bytes */)
___asm(e_bdnz      core1_limem_loop;          /* # Loop for all of SRAM */)
#if defined(BRSASR_ENABLE_OS_MULTICORESUPPORT)
___asm(;/* skip RAM init for slave cores */)
__as1(mfspr     r3, PIR         ;/* read out CPU ID PIR                 */)
__as1(se_cmpi   r3, BRS_CPU_STARTUP_ID     ;/* if current CPU is NOT startup core?   */)
___asm(se_beq   _startupF       ;/* proceed with section F              */)     //cjh
#endif

___asm(;/*****************************************************************************/)
___asm(;/* (F) INIT Core0 RAM                                                        */)
___asm(;/*****************************************************************************/)
#if defined(BRSASR_ENABLE_OS_MULTICORESUPPORT)
___asm(_InitCore0Ram:)
#endif

___asm(;/*****************************************************************************/)
___asm(;/* (D) Initialise Core 0 Local Data SRAM ECC                                 */)
___asm(;/*****************************************************************************/)
__as1(e_lis  r5, __CORE0_LOCAL_DMEM_SIZE@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE0_LOCAL_DMEM_SIZE@l;      /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE0_LOCAL_DMEM_SIZE@l;          /* lowbytes  - r11 holds start address of the RAM */)
#endif

__as2(e_srwi  r5,r5, 0x7;                         /* # Divide SRAM size by 128 */ )
___asm(se_mtctr r5;                               /* # Move to counter for use with "bdnz" */  )

__as1(e_lis  r5, __CORE0_LOCAL_DMEM_BASE_ADDR@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE0_LOCAL_DMEM_BASE_ADDR@l;    /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE0_LOCAL_DMEM_BASE_ADDR@l; /* lowbytes  - r11 holds start address of the RAM */)
#endif

___asm(core0_ldmem_loop:)
__as1(e_stmw      r0,0(r5);             /* # Write all 32 registers to SRAM */)
__as2(e_addi      r5,r5,128;            /* # Increment the RAM pointer to next 128bytes */)
___asm(e_bdnz      core0_ldmem_loop;          /* # Loop for all of SRAM */)

___asm(;/*****************************************************************************/)
___asm(;/* (D) Initialise Core 0 Local Instruction SRAM ECC                          */)
___asm(;/*****************************************************************************/)
__as1(e_lis  r5, __CORE0_LOCAL_IMEM_SIZE@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE0_LOCAL_IMEM_SIZE@l;    /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE0_LOCAL_IMEM_SIZE@l; /* lowbytes  - r11 holds start address of the RAM */)
#endif
__as2(e_srwi  r5,r5, 0x7/* # Divide SRAM size by 128 */ )
___asm(se_mtctr r5;  /* # Move to counter for use with "bdnz" */  )

__as1(e_lis  r5, __CORE0_LOCAL_IMEM_BASE_ADDR@h;       /* highbytes - r11 holds start address of the RAM */)
#if defined (BRSHW_INSTRUCTION_SET_VLE)
__as1(e_or2i  r5, __CORE0_LOCAL_IMEM_BASE_ADDR@l;    /* lowbytes  - r11 holds start address of the RAM */)
#else
__as2(e_ori  r5,r5, __CORE0_LOCAL_IMEM_BASE_ADDR@l; /* lowbytes  - r11 holds start address of the RAM */)
#endif

___asm(core0_limem_loop:)
__as1(e_stmw      r0,0(r5);             /* # Write all 32 registers to SRAM */)
__as2(e_addi      r5,r5,128;            /* # Increment the RAM pointer to next 128bytes */)
___asm(e_bdnz      core0_limem_loop;          /* # Loop for all of SRAM */)


___asm(;/*****************************************************************************/)
___asm(;/* (F) INIT INTERRUPT VECTOR BASE REGISTER                                   */)
___asm(;/*****************************************************************************/)
#if defined(BRSASR_ENABLE_OS_MULTICORESUPPORT)
___asm(_startupF:)
#endif

#define D_CACHE_ENABLE
___asm(;/*****************************************************************************/)
___asm(;/* D_Cache enable                               */)
___asm(;/*****************************************************************************/)
#ifdef D_CACHE_ENABLE
    ___asm(DCACHE_CFG:;)
        __as1(e_li r50x2:smileywink:
        __as1(mtspr l1csr0,r5;)
        __as1(e_li r70x4:smileywink:
        __as1(e_li r80x2:smileywink:
        __as1(e_lis   r110xFFFF:smileywink:
        __as1(e_or2i  r110xFFFB:smileywink:
    ___asm(DCACHE_INV:;)
        __as1(mfspr r9, l1csr0;)
        __as2(and.  r10, r7, r9;)
        ___asm(e_beq   DCACHE_NO_ABORT;)
        __as2(and.  r10, r11, r9;)
        __as1(mtspr l1csr0, r10;)
    ___asm(e_b  DCACHE_CFG;)
        ___asm(DCACHE_NO_ABORT:;)
        __as2(and.  r10, r8, r9;)
        ___asm(e_bne DCACHE_INV;)
        __as1(mfspr r5, l1csr0;)
        __as2(e_ori   r5, r5, 0x0001:smileywink:
        ___asm(se_isync;)
        ___asm(msync;)
        __as1(mtspr l1csr0, r5;)
#endif 

  __as1(e_li     r00        ;/* Clear r0 */)
#if !defined (BRS_DERIVATIVE_PC582101)
  __as1(e_lis    r0,_VECTORTABLE_START_ADDR@h    ;/* r11 holds base address of the L2SRAM 64-bit word aligned*/)
# if defined (BRSHW_INSTRUCTION_SET_VLE)
  __as1(e_or2i    r0,_VECTORTABLE_START_ADDR@l 
# else
  __as2(e_ori    r0,r0,_VECTORTABLE_START_ADDR@l;)
# endif
#endif
  __as1(mtspr    63, r0       ;/* set IVPR */)

.......

 

pastedImage_17.png

Best regards

Tags (2)
0 Kudos
1 Reply

537 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

as a first step - what can you see when you check the memory content via debugger? You can step the init code and watch the memory if it is initialized accordingly...

Regards,

Lukas

0 Kudos