Assembly examples for Red-V Thing Plus (SiFive FE310-G002)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

102 lines
2.9 KiB

#
# main.s
#
# 2021 flabbergast <flabbergast@drak.xyz>
# Unlicense: https://unlicense.org/
#
.option norelax
.equ compressed_isa, 1
# -----------------------------------------------------------------------------
# macros and RAM variables
# -----------------------------------------------------------------------------
.include "macros.s"
.set rampointer, 0x80000000 # start allocating at the beginning of RAM
# end of RAM is +0x4000
ramallot data_stack_begin, 128 # 32 values
ramallot data_stack_end, 0
ramallot return_stack_begin, 512
ramallot return_stack_end, 0
# -----------------------------------------------------------------------------
# Execution begins here
# -----------------------------------------------------------------------------
.text
j Reset
# -----------------------------------------------------------------------------
# Static data
# -----------------------------------------------------------------------------
s_hello: sized_string ":Hello, world! %B %H %W %d %% woof\n"
# -----------------------------------------------------------------------------
# Include any supporting code
# -----------------------------------------------------------------------------
.include "platform_regs.inc"
.include "p_interrupts.s"
.include "p_clock.s"
.include "p_delay.s"
.include "p_uart0irq.s"
.include "write.s"
# -----------------------------------------------------------------------------
Reset: # Execution begins here
# -----------------------------------------------------------------------------
# set up stacks
li sp, return_stack_end
li s11, data_stack_end
# set up interrupt and exception handler (ours needs sp)
csrci mstatus, 8 # disable interrupts
la t0, irq_handler
csrw mtvec, t0
csrsi mstatus, 8 # enable interrupts
# the board (usually) runs on 13.8MHz HFROSC on boot?
jal clock_extcryst # switch to external crystal, 16MHz
jal plic_init # enable PLIC (used for uart)
jal uart_init # initialise UART0 (115200baud)
# if you change clock, you'll need to adjust the
# baud divisor in p_uart0.s
jal write_init # set up default "emit" over uart
jal delay_init # enable the timer interrupt
puts "Welcome!\n"
# chase again
li s1, GPIO_BASE
li s2, 0b111111<<18 # pins 18-23
sw s2, GPIO_OUTPUT_EN(s1) # set as outputs
li a0, 200 # delay in ms
li s2, 0b1<<18 # start with pin 18
li s3, 0b1<<23 # end with pin 23
1:
sw s2, GPIO_OUTPUT_VAL(s1) # make the pin high
li a0, 200
jal delay
slli s2, s2, 1 # move one to the left
# test uart
jal uart_recv
bltz a0, 2f
jal uart_emit
2:
bleu s2, s3, 1b # did we move past last pin?
li s2, 0b1<<18 # back to the first pin
j 1b
end:
j end