#include <sys/errno.h>
#include <sys/syscall.h>
#include <machine/param.h>
#include <machine/asm.h>
#include <machine/cpu.h>
#include <mips64/mips_cpu.h>
#include <machine/regnum.h>
#include <machine/cpustate.h>
#include <octeon/dev/cn30xxcorereg.h>
#include "assym.h"
#include "octboot.h"
#define RNG_CONTROL_ADDR 0x9001180040000000
#define RNG_CONTROL_ENABLE 0x3
#define RNG_ENTROPY_ADDR 0x9001400000000000
.set noreorder # Noreorder is default style!
.set mips64r2
.globl locore_start
.ent locore_start, 0
locore_start:
dla t0, 0xffffffff80000000
mtc0 t0, COP_0_EBASE
dli t0, COP_0_CVMCTL_FUSE_START_BIT|COP_0_CVMCTL_NOFDA_CP2|\
COP_0_CVMCTL_IPPCI|COP_0_CVMCTL_IPTI
dmtc0 t0, COP_0_CVMCTL
#if 0
dli t0, 0x1846104 # If you want to skip write buffer, use this
#else
dli t0, 0x46104
#endif
dmtc0 t0, COP_0_CVMMEMCTL
mfc0 v0, COP_0_STATUS_REG
li v1, ~(SR_INT_ENAB | SR_ERL | SR_EXL)
and v0, v1
mtc0 v0, COP_0_STATUS_REG # disable all interrupts
mtc0 zero, COP_0_CAUSE_REG # Clear soft interrupts
bne a2, zero, 2f
nop
#if defined(MULTIPROCESSOR)
rdhwr t2, $0
LA t1, cpu_spinup_mask
1: ll t0, 0(t1)
bne t2, t0, 1b
nop
move t0, zero
sc t0, 0(t1)
beqz t0, 1b
nop
j hw_cpu_spinup_trampoline
nop
#elif NOCTBOOT > 0
LA t0, octeon_boot_ready
1: lw t1, (t0)
beq t1, zero, 1b
nop
LA t0, octeon_boot_entry
ld t0, (t0) # get entry point
cache 1, 0(zero) # flush and invalidate dcache
jr t0
cache 0, 0(zero) # invalidate icache
#else
1: wait
j 1b
nop
#endif
2:
dli t0, RNG_CONTROL_ADDR
ld t1, (t0)
ori t1, RNG_CONTROL_ENABLE
sd t1, (t0)
LA t0, __kernel_randomdata
LA t1, __kernel_randomdata_end
dli t2, RNG_ENTROPY_ADDR
1:
li v0, 0x1000
2:
bne v0, zero, 2b
subu v0, v0, 1
ld v0, (t0) # load from randomdata
ld v1, (t2) # load entropy
xor v0, v0, v1 # mix entropy
daddu t0, t0, 8 # advance ptr
blt t0, t1, 1b
sd v0, -8(t0) # store to randomdata
LA t0, edata
LA t1, end
1:
daddu t0, t0, 8
blt t0, t1, 1b
sd zero, -8(t0)
LA t0, initstack_end - FRAMESZ(CF_SZ)
PTR_S ra, CF_RA_OFFS(t0) # save uboot return address
PTR_S sp, 0(t0) # and stack
move sp, t0
jal mips_init # mips_init(argc, argv, envp,
nop # callvec, esym)
beqz v0, 1f # upon failure, return to uboot
nop
PTR_S zero, CF_RA_OFFS(sp) # Zero out old ra for debugger
move sp, v0 # switch to new stack
jal main # main(regs)
move a0, zero
PANIC("Startup failed!")
1: PTR_L ra, CF_RA_OFFS(sp)
PTR_L sp, 0(sp)
jr ra
nop
.end locore_start
LEAF(octeon_sync_tc, 0)
li t0, 5 # set number of iterations
di t3 # disable all interrupts
MTC0_SR_IE_HAZARD
1:
ld t1, (a0) # load data clock counter
dmultu t1, a1 # multiply with mul
mflo t1 # fetch result
beqz a2, 2f # skip if frac == 2^64
subu t0, 1
dmultu t1, a2 # multiply with frac
mfhi t1 # fetch result divided by 2^64
2:
mtc0 t1, COP_0_COUNT # set core clock counter
MTC0_HAZARD
bnez t0, 1b
nop
mtc0 t3, COP_0_STATUS_REG # restore status register
MTC0_SR_IE_HAZARD
jr ra
nop
END(octeon_sync_tc)
#if defined(MULTIPROCESSOR)
LEAF(hw_cpu_spinup_trampoline, 0)
LA t0, cpu_spinup_a0
ld a0, 0(t0)
LA t0, cpu_spinup_sp
ld sp, 0(t0)
jal hw_cpu_hatch
nop
END(hw_cpu_spinup_trampoline)
#endif
.bss
.align 3
initstack:
.space 4096
initstack_end: