summaryrefslogtreecommitdiff
path: root/libcpu/aarch64/common/up/vector_gcc.S
blob: 0bc509f9bcab2fba6619a623e1ee4cf3c78594f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-03-28     Shell        Move vector handling codes from context_gcc.S
 */

#ifndef __ASSEMBLY__
#define __ASSEMBLY__
#endif

#include "../include/vector_gcc.h"
#include "context_gcc.h"

#include <rtconfig.h>
#include <asm-generic.h>
#include <asm-fpu.h>
#include <armv8.h>

.section .text

    .align  8
    .globl vector_fiq
vector_fiq:
    SAVE_IRQ_CONTEXT
    stp     x0, x1, [sp, #-0x10]!
    bl      rt_hw_trap_fiq
    ldp     x0, x1, [sp], #0x10
    RESTORE_IRQ_CONTEXT

.globl      rt_interrupt_enter
.globl      rt_interrupt_leave
.globl      rt_thread_switch_interrupt_flag
.globl      rt_interrupt_from_thread
.globl      rt_interrupt_to_thread

    .align  8
    .globl vector_irq
vector_irq:
    SAVE_IRQ_CONTEXT
    stp     x0, x1, [sp, #-0x10]!   /* X0 is thread sp */

    bl      rt_interrupt_enter
    bl      rt_hw_trap_irq
    bl      rt_interrupt_leave

    ldp     x0, x1, [sp], #0x10

    /**
     * if rt_thread_switch_interrupt_flag set, jump to
     * rt_hw_context_switch_interrupt_do and don't return
     */
    ldr     x1, =rt_thread_switch_interrupt_flag
    ldr     x2, [x1]
    cmp     x2, #1
    b.ne    vector_irq_exit

    mov     x2,  #0         // clear flag
    str     x2,  [x1]

    ldr     x3,  =rt_interrupt_from_thread
    ldr     x4,  [x3]
    str     x0,  [x4]       // store sp in preempted tasks's tcb

    ldr     x3,  =rt_interrupt_to_thread
    ldr     x4,  [x3]
    ldr     x0,  [x4]       // get new task's stack pointer

    RESTORE_IRQ_CONTEXT

vector_irq_exit:
    RESTORE_IRQ_CONTEXT_WITHOUT_MMU_SWITCH