#define __ASSEMBLY__
#include "include/revision.h"
#include "ppsi/include/hw-specific/wrh.h"
#include "arch/risc-v/crt0.h"
#include "include/generated/autoconf.h"

.section .boot, "ax", @progbits

.global _start
_start:
    j      _entry

.org 0x8

.extern trap_entry
_exception_entry:
    j      trap_entry

.org WRPC_MARK
/* Used by the dumping tool to identify byte ordering */	
.ascii     "WRPC----"
.int       0x01234567
.short     0x89ab, 0xcdef
/* Pointer to structures, for the dumping tool */
.org WRC_STATIC_PADDR
    .word  wrc_global
#ifdef CONFIG_WRPC_PPSI
.org PPG_STATIC_PADDR
    .word  ppg_static
#endif
.org STATS_PADDR
    .word  stats

.org UPTIME_SEC_ADDR
.global uptime_sec
uptime_sec:
    .word  0

.org VERSION_WRPC_ADDR
.global version_wrpc
version_wrpc:
    .byte  WRPC_SHMEM_VERSION

.org VERSION_PPSI_ADDR
.global version_ppsi
version_ppsi:
    .byte  WRS_PPSI_SHMEM_VERSION


/* Pointer to a structure used by testbenches, use only when
 * CONFIG_WR_NODE_SIM is set */
.org HDL_TESTBENCH_PADDR
.global hdl_testbench_p
hdl_testbench_p:
#ifdef CONFIG_WR_NODE_SIM
    .word  hdl_testbench
#else
    .word  0
#endif

.org 0x100

_entry:

    la     gp, _gp                 # Initialize global pointer
    la     sp, _fstack

    la     t0, _fexception_stack
    csrrw  t0, mscratch, t0

# clear the bss segment
    la     t0, _fbss
    la     t1, _end
1:
#ifdef __riscv64
    sd     zero,0(t0)
    addi   t0, t0, 8
#else
    sw     zero,0(t0)
    addi   t0, t0, 4
#endif
    bltu   t0, t1, 1b

    call   main
