2013-12-13 21:37:05 +00:00
|
|
|
#include "mips.h"
|
|
|
|
|
|
|
|
.extern main
|
|
|
|
.global start
|
|
|
|
|
|
|
|
.set mips32r2
|
|
|
|
.set noreorder
|
2014-09-23 11:30:17 +00:00
|
|
|
// .set noat
|
2013-12-13 21:37:05 +00:00
|
|
|
|
|
|
|
.section .init.text,"ax",%progbits
|
|
|
|
|
|
|
|
start:
|
|
|
|
di # disable interrupts
|
2014-01-03 07:45:57 +00:00
|
|
|
bltzal zero, load_addr # ra = PC + 8, branch not taken
|
2013-12-13 21:37:05 +00:00
|
|
|
nop
|
2014-01-03 07:45:57 +00:00
|
|
|
|
|
|
|
load_addr:
|
|
|
|
addiu v0, ra, -12 # calc real load address
|
|
|
|
# account for branch delay slot
|
|
|
|
# and very first 'di' instruction
|
2013-12-13 21:37:05 +00:00
|
|
|
|
|
|
|
# setup caches
|
|
|
|
# 4-way, 256 sets, 16 bytes cacheline I/D
|
|
|
|
la t0, 0x80000000 # an idx op should use an unmappable address
|
|
|
|
ori t1, t0, 0x4000 # 16kB cache
|
|
|
|
mtc0 zero, C0_TAGLO
|
|
|
|
mtc0 zero, C0_TAGHI
|
2014-09-23 11:30:17 +00:00
|
|
|
ehb # execution hazard barrier
|
2013-12-13 21:37:05 +00:00
|
|
|
|
|
|
|
cache_init_loop:
|
2014-09-23 11:30:17 +00:00
|
|
|
cache ICIndexStTag, 0(t0) # index store icache tag
|
|
|
|
cache DCIndexStTag, 0(t0) # index store dcache tag
|
2013-12-13 21:37:05 +00:00
|
|
|
addiu t0, t0, 0x10
|
2014-03-04 10:07:07 +00:00
|
|
|
bne t0, t1, cache_init_loop
|
|
|
|
nop
|
2013-12-13 21:37:05 +00:00
|
|
|
|
2014-09-23 11:30:17 +00:00
|
|
|
li t0, 3 # enable cache for kseg0 accesses
|
|
|
|
mtc0 t0, C0_CONFIG
|
|
|
|
ehb
|
|
|
|
|
|
|
|
relocation:
|
|
|
|
la t0, relocstart
|
|
|
|
la t1, relocend
|
|
|
|
beq t0, v0, entry_point # no relocation needed
|
|
|
|
nop
|
|
|
|
|
|
|
|
reloc_loop:
|
|
|
|
lw s0, 0(v0) # src
|
|
|
|
lw s1, 4(v0)
|
|
|
|
lw s2, 8(v0)
|
|
|
|
lw s3, 12(v0)
|
|
|
|
|
|
|
|
sw s0, 0(t0) # dst
|
|
|
|
sw s1, 4(t0)
|
|
|
|
sw s2, 8(t0)
|
|
|
|
sw s3, 12(t0)
|
|
|
|
|
|
|
|
synci 0(t0) # dcache writeback invalidate
|
|
|
|
# icache invalidate
|
|
|
|
|
|
|
|
addiu t0, t0, 16 # inc dst addr
|
|
|
|
blt t0, t1, reloc_loop
|
|
|
|
addiu v0, v0, 16 # inc src addr
|
|
|
|
|
|
|
|
entry_point_jump:
|
|
|
|
la t0, entry_point
|
|
|
|
jr.hb t0 # jump register with hazard barier
|
|
|
|
nop
|
|
|
|
|
|
|
|
entry_point:
|
2013-12-13 21:37:05 +00:00
|
|
|
# clear bss
|
|
|
|
la t0, bssbegin
|
|
|
|
la t1, bssend
|
2014-09-23 11:30:17 +00:00
|
|
|
beq t0, t1, stack_setup
|
|
|
|
nop
|
|
|
|
|
2013-12-13 21:37:05 +00:00
|
|
|
clear_bss_loop:
|
|
|
|
addiu t0, 4
|
2014-03-04 10:07:07 +00:00
|
|
|
bne t0, t1, clear_bss_loop
|
|
|
|
sw zero, -4(t0)
|
2013-12-13 21:37:05 +00:00
|
|
|
|
2014-09-23 11:30:17 +00:00
|
|
|
stack_setup:
|
2013-12-13 21:37:05 +00:00
|
|
|
# setup stack
|
|
|
|
la sp, stackend
|
|
|
|
la t0, stackbegin
|
|
|
|
li t1, 0xdeadbeef
|
|
|
|
|
|
|
|
stack_munge_loop:
|
|
|
|
addiu t0, 4
|
2014-03-04 10:07:07 +00:00
|
|
|
bne t0, sp, stack_munge_loop
|
|
|
|
sw t1, -4(t0)
|
2013-12-13 21:37:05 +00:00
|
|
|
|
|
|
|
# jump to C code
|
|
|
|
j main
|
|
|
|
nop
|
|
|
|
|
|
|
|
.set at
|
|
|
|
.set reorder
|