2021-01-12 18:22:11 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
2021-11-01 04:36:05 +00:00
|
|
|
#include "soc.h"
|
2021-10-31 19:25:36 +00:00
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
#define UTRSTAT 0x010
|
|
|
|
#define UTXH 0x020
|
|
|
|
|
|
|
|
.extern _start_c
|
|
|
|
.extern _stack_bot
|
2021-01-16 15:45:10 +00:00
|
|
|
.extern _v_sp0_sync
|
|
|
|
.extern _v_sp0_irq
|
|
|
|
.extern _v_sp0_fiq
|
|
|
|
.extern _v_sp0_serr
|
2021-01-28 07:05:24 +00:00
|
|
|
.extern _reset_stack
|
|
|
|
.extern _cpu_reset_c
|
2021-10-31 19:25:36 +00:00
|
|
|
.extern wdt_reboot
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
.section .init, "ax"
|
|
|
|
|
2021-03-04 12:27:25 +00:00
|
|
|
.align 11
|
2021-01-16 15:45:10 +00:00
|
|
|
.globl _vectors_start
|
|
|
|
_vectors_start:
|
|
|
|
|
|
|
|
mov x9, '0'
|
2021-01-28 07:05:24 +00:00
|
|
|
b cpu_reset
|
2021-01-16 15:45:10 +00:00
|
|
|
.align 7
|
|
|
|
mov x9, '1'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
mov x9, '2'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
mov x9, '3'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
b _v_sp0_sync
|
|
|
|
.align 7
|
|
|
|
b _v_sp0_irq
|
|
|
|
.align 7
|
|
|
|
b _v_sp0_fiq
|
|
|
|
.align 7
|
|
|
|
b _v_sp0_serr
|
|
|
|
.align 7
|
2021-02-24 12:46:33 +00:00
|
|
|
b _v_sp0_sync
|
2021-01-16 15:45:10 +00:00
|
|
|
.align 7
|
2021-02-24 12:46:33 +00:00
|
|
|
b _v_sp0_irq
|
2021-01-16 15:45:10 +00:00
|
|
|
.align 7
|
2021-02-24 12:46:33 +00:00
|
|
|
b _v_sp0_fiq
|
2021-01-16 15:45:10 +00:00
|
|
|
.align 7
|
2021-02-24 12:46:33 +00:00
|
|
|
b _v_sp0_serr
|
2021-01-16 15:45:10 +00:00
|
|
|
.align 7
|
|
|
|
mov x9, 'p'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
mov x9, 'q'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
mov x9, 'r'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
mov x9, 's'
|
|
|
|
b exc_unk
|
|
|
|
.align 7
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
.globl _start
|
|
|
|
.type _start, @function
|
|
|
|
_start:
|
2021-01-17 14:16:58 +00:00
|
|
|
mov x19, x0
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
mov w0, 'm'
|
|
|
|
bl debug_putc
|
2021-01-28 07:05:24 +00:00
|
|
|
|
2021-01-28 14:32:30 +00:00
|
|
|
adrp x1, _stack_bot
|
|
|
|
mov sp, x1
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
mov w0, '1'
|
|
|
|
bl debug_putc
|
|
|
|
|
2021-01-28 14:32:30 +00:00
|
|
|
ldr x2, [sp, #-8]
|
2021-01-28 07:05:24 +00:00
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
mov w0, 'n'
|
|
|
|
bl debug_putc
|
|
|
|
|
|
|
|
adrp x0, _base
|
2021-01-17 14:16:58 +00:00
|
|
|
mov x20, x0
|
2021-01-12 18:22:11 +00:00
|
|
|
adrp x1, _rela_start
|
|
|
|
add x1, x1, :lo12:_rela_start
|
|
|
|
adrp x2, _rela_end
|
|
|
|
add x2, x2, :lo12:_rela_end
|
|
|
|
bl apply_rela
|
|
|
|
|
|
|
|
mov w0, '1'
|
|
|
|
bl debug_putc
|
2021-01-17 14:17:30 +00:00
|
|
|
mov w0, 0xd /* '\r', clang compat */
|
2021-01-12 18:22:11 +00:00
|
|
|
bl debug_putc
|
|
|
|
mov w0, '\n'
|
|
|
|
bl debug_putc
|
2021-01-28 07:05:24 +00:00
|
|
|
|
2021-01-17 14:16:58 +00:00
|
|
|
mov x0, x19
|
|
|
|
mov x1, x20
|
2021-01-12 18:22:11 +00:00
|
|
|
bl _start_c
|
|
|
|
b .
|
|
|
|
|
2021-01-16 15:45:10 +00:00
|
|
|
.globl exc_unk
|
|
|
|
.type exc_unk, @function
|
|
|
|
exc_unk:
|
2021-01-17 14:17:30 +00:00
|
|
|
mov w0, 0xd /* '\r', clang compat */
|
2021-01-16 15:45:10 +00:00
|
|
|
bl debug_putc
|
|
|
|
mov w0, '\n'
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, '!'
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, 'E'
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, 'x'
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, 'C'
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, ':'
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, w9
|
|
|
|
bl debug_putc
|
|
|
|
mov w0, '!'
|
|
|
|
bl debug_putc
|
2021-01-17 14:17:30 +00:00
|
|
|
mov w0, 0xd /* '\r', clang compat */
|
2021-01-16 15:45:10 +00:00
|
|
|
bl debug_putc
|
|
|
|
mov w0, '\n'
|
|
|
|
bl debug_putc
|
|
|
|
b reboot
|
|
|
|
|
2021-01-28 07:05:24 +00:00
|
|
|
.globl cpu_reset
|
|
|
|
.type cpu_reset, @function
|
|
|
|
cpu_reset:
|
|
|
|
mov w0, 'O'
|
|
|
|
bl debug_putc
|
|
|
|
|
|
|
|
adrp x1, _reset_stack
|
2021-01-28 14:47:41 +00:00
|
|
|
add x1, x1, :lo12:_reset_stack
|
2021-01-28 07:05:24 +00:00
|
|
|
ldr x1, [x1]
|
|
|
|
mov sp, x1
|
|
|
|
|
2021-01-28 14:32:30 +00:00
|
|
|
ldr x2, [sp, #-8]
|
|
|
|
|
2021-01-28 07:05:24 +00:00
|
|
|
mov w0, 'K'
|
|
|
|
bl debug_putc
|
|
|
|
|
2021-01-28 14:47:41 +00:00
|
|
|
mov x0, sp
|
2021-01-28 07:05:24 +00:00
|
|
|
bl _cpu_reset_c
|
|
|
|
b .
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
.globl debug_putc
|
|
|
|
.type debug_putc, @function
|
|
|
|
debug_putc:
|
2021-11-01 04:36:05 +00:00
|
|
|
#ifdef EARLY_UART_BASE
|
2021-10-31 19:25:36 +00:00
|
|
|
ldr x1, =EARLY_UART_BASE
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
1:
|
|
|
|
ldr w2, [x1, UTRSTAT]
|
|
|
|
tst w2, #2
|
|
|
|
beq 1b
|
|
|
|
str w0, [x1, UTXH]
|
2021-10-31 19:25:36 +00:00
|
|
|
#endif
|
2021-01-12 18:22:11 +00:00
|
|
|
ret
|
|
|
|
|
2021-01-16 15:45:10 +00:00
|
|
|
.globl reboot
|
|
|
|
.type reboot, @function
|
|
|
|
reboot:
|
2021-05-15 11:42:50 +00:00
|
|
|
mrs x0, CurrentEL
|
|
|
|
cmp x0, #8
|
|
|
|
beq 1f
|
|
|
|
hvc #0
|
|
|
|
1:
|
2021-10-31 19:25:36 +00:00
|
|
|
bl wdt_reboot
|
2021-01-16 15:45:10 +00:00
|
|
|
b .
|
|
|
|
|
|
|
|
.pool
|