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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [common/] [crt0.S] - Diff between revs 72 and 73

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

Rev 72 Rev 73
Line 68... Line 68...
// Setup CPU core CSRs (some of them DO NOT have a dedicated
// Setup CPU core CSRs (some of them DO NOT have a dedicated
// reset and need to be explicitly initialized)
// reset and need to be explicitly initialized)
// ************************************************************************************************
// ************************************************************************************************
__crt0_cpu_csr_init:
__crt0_cpu_csr_init:
 
 
  la   x10,   __crt0_dummy_trap_handler // configure early trap handler
  la   x10,   __crt0_dummy_trap_handler // configure early-boot trap handler
  csrw mtvec, x10
  csrw mtvec, x10
  csrw mepc,  x10                       // just to init mepc
  csrw mepc,  x10                       // just to init mepc
 
 
  csrw mstatus, zero                    // disable global IRQ
  csrw mstatus, zero                    // clear all control flags, also disable global IRQ
 
  csrw mie,     zero                    // absolutely no interrupt sources, thanks
  csrw mie, zero                        // absolutely no interrupts sources, thanks
  csrw mip,     zero                    // clear all pending interrupts
 
 
 
  csrw 0x320,      zero                 // stop all counters; use "mcountinhibit" literal address for lagacy toolchain compatibility
  csrw mcounteren, zero                 // no access from less-privileged modes to counter CSRs
  csrw mcounteren, zero                 // no access from less-privileged modes to counter CSRs
 
 
  li   x11,   ~5                        // stop all counters except for [m]cycle[h] and [m]instret[h]
  csrw mcycle,    zero                  // reset cycle counter
  csrw 0x320, x11                       // = mcountinhibit (literal address for lagacy toolchain compatibility)
 
 
 
  csrw mcycle,    zero                  // reset cycle counters
 
  csrw mcycleh,   zero
  csrw mcycleh,   zero
  csrw minstret,  zero                  // reset instruction counters
  csrw minstret,  zero                  // reset instructions-retired counter
  csrw minstreth, zero
  csrw minstreth, zero
 
 
 
 
// ************************************************************************************************
// ************************************************************************************************
// Initialize integer register file (lower half)
// Initialize integer register file (lower half)
Line 105... Line 103...
//addi  x9, x0, 0 // implicitly initialized within crt0
//addi  x9, x0, 0 // implicitly initialized within crt0
//addi x10, x0, 0 // implicitly initialized within crt0
//addi x10, x0, 0 // implicitly initialized within crt0
//addi x11, x0, 0 // implicitly initialized within crt0
//addi x11, x0, 0 // implicitly initialized within crt0
//addi x12, x0, 0 // implicitly initialized within crt0
//addi x12, x0, 0 // implicitly initialized within crt0
//addi x13, x0, 0 // implicitly initialized within crt0
//addi x13, x0, 0 // implicitly initialized within crt0
  addi x14, x0, 0
//addi x14, x0, 0 // implicitly initialized within crt0
  addi x15, x0, 0
//addi x15, x0, 0 // implicitly initialized within crt0
 
 
 
 
// ************************************************************************************************
// ************************************************************************************************
// Initialize integer register file (upper half, if no E extension)
// Initialize integer register file (upper half, if no E extension)
// ************************************************************************************************
// ************************************************************************************************
Line 151... Line 149...
  addi x8,   x8, 4
  addi x8,   x8, 4
  bne  x8,   x9, __crt0_reset_io_loop
  bne  x8,   x9, __crt0_reset_io_loop
 
 
 
 
// ************************************************************************************************
// ************************************************************************************************
// Clear .bss section (byte-wise) using linker script symbols
 
// ************************************************************************************************
 
__crt0_clear_bss:
 
  la   x11,  __crt0_bss_start
 
  la   x12,  __crt0_bss_end
 
 
 
__crt0_clear_bss_loop:
 
  bge  x11,  x12, __crt0_clear_bss_loop_end
 
  sb   zero, 0(x11)
 
  addi x11,  x11, 1
 
  j    __crt0_clear_bss_loop
 
 
 
__crt0_clear_bss_loop_end:
 
 
 
 
 
// ************************************************************************************************
 
// Copy initialized .data section from ROM to RAM (byte-wise)
// Copy initialized .data section from ROM to RAM (byte-wise)
// ************************************************************************************************
// ************************************************************************************************
__crt0_copy_data:
__crt0_copy_data:
  la   x11, __crt0_copy_data_src_begin        // start of data area (copy source)
  la   x11, __crt0_copy_data_src_begin        // start of data area (copy source)
  la   x12, __crt0_copy_data_dst_begin        // start of data area (copy destination)
  la   x12, __crt0_copy_data_dst_begin        // start of data area (copy destination)
Line 186... Line 168...
 
 
__crt0_copy_data_loop_end:
__crt0_copy_data_loop_end:
 
 
 
 
// ************************************************************************************************
// ************************************************************************************************
 
// Clear .bss section (byte-wise)
 
// ************************************************************************************************
 
__crt0_clear_bss:
 
  la   x14,  __crt0_bss_start
 
  la   x15,  __crt0_bss_end
 
 
 
__crt0_clear_bss_loop:
 
  bge  x14,  x15, __crt0_clear_bss_loop_end
 
  sb   zero, 0(x14)
 
  addi x14,  x14, 1
 
  j    __crt0_clear_bss_loop
 
 
 
__crt0_clear_bss_loop_end:
 
 
 
 
 
// ************************************************************************************************
// Setup arguments and call main function
// Setup arguments and call main function
// ************************************************************************************************
// ************************************************************************************************
__crt0_main_entry:
__crt0_main_entry:
  addi a0,  zero, 0                  // a0 = argc = 0
  addi a0,  zero, 0                  // a0 = argc = 0
  addi a1,  zero, 0                  // a1 = argv = 0
  addi a1,  zero, 0                  // a1 = argv = 0
Line 218... Line 216...
// ************************************************************************************************
// ************************************************************************************************
// go to endless sleep mode
// go to endless sleep mode
// ************************************************************************************************
// ************************************************************************************************
__crt0_shutdown:
__crt0_shutdown:
  csrci mstatus, 8                   // disable global IRQs (clear mstatus.mie)
  csrci mstatus, 8                   // disable global IRQs (clear mstatus.mie)
__crt0_shutdown_loop:
 
  wfi                                // go to sleep mode
  wfi                                // go to sleep mode
  j __crt0_shutdown_loop             // endless loop
  j .                                // endless loop
 
 
 
 
// ************************************************************************************************
// ************************************************************************************************
// dummy trap handler (for exceptions & IRQs during very early boot stage)
// dummy trap handler (for exceptions & IRQs during very early boot stage)
// does nothing but trying to move on to the next instruction
// does nothing but trying to move on to the next instruction

powered by: WebSVN 2.1.0

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