OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [common/] [crt0.S] - Diff between revs 3 and 6

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 3 Rev 6
Line 1... Line 1...
/* ################################################################################################# */
/* ################################################################################################# */
/* # << NEORV32 - crt0.S - Application Start-Up Code >>                                            # */
/* # << NEORV32 - crt0.S - Application Start-Up Code & Minimal Runtime Environment >>              # */
/* # ********************************************************************************************* # */
/* # ********************************************************************************************* # */
/* # The start-up code provides a minimal runtime environment that catches all exceptions/         # */
/* # The start-up code provides a minimal runtime environment that catches all exceptions and      # */
/* # interrupts and delegates them to the handler functions (installed by user via dedicated       # */
/* # interrupts and delegates them to the handler functions (installed by user via dedicated       # */
/* # install function from the neorv32 runtime environment library).                               # */
/* # install function from the neorv32 runtime environment library).                               # */
/* # ********************************************************************************************* # */
/* # ********************************************************************************************* # */
/* # BSD 3-Clause License                                                                          # */
/* # BSD 3-Clause License                                                                          # */
/* #                                                                                               # */
/* #                                                                                               # */
Line 115... Line 115...
 
 
// *********************************************************
// *********************************************************
// Setup stack pointer
// Setup stack pointer
// *********************************************************
// *********************************************************
__crt0_stack_pointer_init:
__crt0_stack_pointer_init:
  csrrw x11, CSR_MDSPACEBASE, zero // data memory space base address
  csrr  x11, CSR_MDSPACEBASE // data memory space base address
  csrrw x12, CSR_MDSPACESIZE, zero // data memory space size
  csrr  x12, CSR_MDSPACESIZE // data memory space size
  add   sp, x11, x12
  add   sp, x11, x12
  addi  sp, sp, -4 // stack pointer = last entry
  addi  sp, sp, -4 // stack pointer = last entry
  addi  fp, sp, 0  // frame pointer = stack pointer
  addi  fp, sp, 0  // frame pointer = stack pointer
 
 
 
 
Line 137... Line 137...
// *********************************************************
// *********************************************************
// Init exception vector table (2x16 4-byte entries) with dummy handlers
// Init exception vector table (2x16 4-byte entries) with dummy handlers
// *********************************************************
// *********************************************************
__crt0_neorv32_rte_init:
__crt0_neorv32_rte_init:
  la    x11, __crt0_neorv32_rte
  la    x11, __crt0_neorv32_rte
  csrrw zero, mtvec, x11 // set address of first-level exception handler
  csrw  mtvec, x11 // set address of first-level exception handler
 
 
  csrrw x11, CSR_MDSPACEBASE, zero // data memory space base address
  csrr  x11, CSR_MDSPACEBASE // data memory space base address
  la    x12, __crt0_neorv32_rte_dummy_hanlder
  la    x12, __crt0_neorv32_rte_dummy_hanlder
  li    x13, 2*16  // number of entries (16xEXC, 16xIRQ)
  li    x13, 2*16  // number of entries (16xEXC, 16xIRQ)
 
 
__crt0_neorv32_rte_init_loop:
__crt0_neorv32_rte_init_loop:
  sw  x12,  0(x11) // set dummy handler
  sw  x12,  0(x11) // set dummy handler
Line 276... Line 276...
 
 
 
 
  // --------------------------------------------
  // --------------------------------------------
  // get cause and prepare jump into vector table
  // get cause and prepare jump into vector table
  // --------------------------------------------
  // --------------------------------------------
  csrrw t0, mcause, zero  // get cause code
  csrr  t0, mcause        // get cause code
 
 
  andi  t1, t0, 0x0f      // isolate cause ID
  andi  t1, t0, 0x0f      // isolate cause ID
  slli  t1, t1, 2         // make address offset
  slli  t1, t1, 2         // make address offset
  csrrw ra, CSR_MDSPACEBASE, zero  // data memory space base address
  csrr  ra, CSR_MDSPACEBASE  // data memory space base address
  add   t1, t1, ra        // get vetor table entry address (EXC vectors)
  add   t1, t1, ra        // get vetor table entry address (EXC vectors)
 
 
  csrrw ra, mepc, zero    // get return address
  csrr  ra, mepc          // get return address
 
 
  blt   t0, zero, __crt0_neorv32_rte_is_irq  // branch if this is an INTERRUPT
  blt   t0, zero, __crt0_neorv32_rte_is_irq  // branch if this is an INTERRUPT
 
 
 
 
  // --------------------------------------------
  // --------------------------------------------
  // compute return address for EXCEPTIONS only
  // compute return address for EXCEPTIONS only
  // --------------------------------------------
  // --------------------------------------------
__crt0_neorv32_rte_is_exc:
__crt0_neorv32_rte_is_exc:
 
 
  // is faulting instruction compressed?
  // is faulting instruction compressed?
  csrrw t0, mtinst, zero
  csrr  t0, mtinst
  andi  t0, t0, 2   // get compression flag (bit #1): 0=compressed, 2=uncompressed
  andi  t0, t0, 2   // get compression flag (bit #1): 0=compressed, 1=uncompressed
 
 
  addi  ra, ra, +2  // only this for compressed instr
  addi  ra, ra, +2  // only this for compressed instructions
  add   ra, ra, t0  // add another 2 (0+4) for uncompressed instr
  add   ra, ra, t0  // add another 2 (making +4) for uncompressed instructions
  j __crt0_neorv32_rte_execute
  j __crt0_neorv32_rte_execute
 
 
 
 
  // --------------------------------------------
  // --------------------------------------------
  // vector table offset for INTERRUPTS only
  // vector table offset for INTERRUPTS only
Line 318... Line 318...
  lw    t0, 0(t1)       // get base address of second-level handler
  lw    t0, 0(t1)       // get base address of second-level handler
 
 
  // push ra
  // push ra
  addi  sp, sp, -4
  addi  sp, sp, -4
  sw    ra, 0(sp)
  sw    ra, 0(sp)
csrrw zero, mscratch, ra
 
 
 
  jalr  ra, t0          // call second-level handler
  jalr  ra, t0          // call second-level handler
 
 
  // pop ra
  // pop ra
  lw    ra, 0(sp)
  lw    ra, 0(sp)
  addi  sp, sp, +4
  addi  sp, sp, +4
 
 
  csrrw zero, mepc, ra
  csrw  mepc, ra
 
 
 
 
  // --------------------------------------------
  // --------------------------------------------
  // full context restore
  // full context restore
  // --------------------------------------------
  // --------------------------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.