blob: 9ed259a6c3fd252c35cb659b1df23de8e7506d2d [file] [log] [blame]
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// A starting functions for simple kelvin programs.
/**
* Entry point.
*/
.section ._init
.balign 4
.global _start
.type _start, @function
_start:
###############################################
# Put all scalar registers into a known state #
###############################################
la sp, __stack_end__
la gp, _global_pointer
mv tp, zero
mv t1, zero
mv t2, zero
mv s0, zero
mv s1, zero
mv a1, zero
mv a2, zero
mv a3, zero
mv a4, zero
mv a5, zero
mv a6, zero
mv a7, zero
mv s2, zero
mv s3, zero
mv s4, zero
mv s5, zero
mv s6, zero
mv s7, zero
mv s8, zero
mv s9, zero
mv s10, zero
mv s11, zero
mv t3, zero
mv t4, zero
mv t5, zero
mv t6, zero
###############################################
# Zero out all kelvin registers #
###############################################
vdup.w.x.m v0, zero
vdup.w.x.m v4, zero
vdup.w.x.m v8, zero
vdup.w.x.m v12, zero
vdup.w.x.m v16, zero
vdup.w.x.m v20, zero
vdup.w.x.m v24, zero
vdup.w.x.m v28, zero
vdup.w.x.m v32, zero
vdup.w.x.m v36, zero
vdup.w.x.m v40, zero
vdup.w.x.m v44, zero
vdup.w.x.m v48, zero
vdup.w.x.m v52, zero
vdup.w.x.m v56, zero
vdup.w.x.m v60, zero
acset.v v48, v0
adwinit.v v48, v0
# Zero out the bss section
la a0, __bss_start__
la a1, __bss_end__
call crt_section_clear
# Initialize the heap ptr after clearing BSS
la s0, __heap_start__
sw s0, _heap_ptr, s1
# Initialize arrays
la s0, __init_array_start__
la s1, __init_array_end__
bgeu s0, s1, init_array_loop_end
init_array_loop:
lw t0, 0(s0)
jalr t0
addi s0, s0, 0x4
bltu s0, s1, init_array_loop
init_array_loop_end:
# Set up sentinel value in _ret
# If we see this after an ebreak,
# the break source is unlikely to
# be a clean return from main.
la t0, _ret
li a0, 0x0badd00d
sw a0, 0(t0)
#############
# Call main #
#############
li a0, 0 # argv
li a1, 0 # argc
la ra, main
jalr ra, ra
# Store the application's return value at _ret
la t0, _ret
sw a0, 0(t0)
flushall
beqz a0, success
failure:
ebreak
j loop
success:
mpause # Kelvin end of program op
loop:
j loop