forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswap.S
48 lines (39 loc) · 995 Bytes
/
swap.S
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
/*
* Copyright (c) 2020, 2021 Antony Pavlov <antonynpavlov@gmail.com>
*
* based on arch/riscv/core/swap.S
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/toolchain.h>
#include <offsets_short.h>
#include <zephyr/arch/cpu.h>
#include <mips/regdef.h>
/*
* unsigned int arch_swap(unsigned int key)
*
* Always called with interrupts locked
* key is stored in a0 register
*/
GTEXT(arch_swap)
SECTION_FUNC(exception.other, arch_swap)
/* Make a system call to perform context switch */
syscall
/*
* when thread is rescheduled, unlock irq and return.
* Restored register v0 contains IRQ lock state of thread.
*/
la k0, _kernel
/* Get pointer to _kernel.current */
lw k1, _kernel_offset_to_current(k0)
/* Load return value of arch_swap function in register v0 */
lw v0, _thread_offset_to_swap_return_value(k1)
/*
* Unlock irq, following IRQ lock state in v0 register.
*/
mfc0 k0, CP0_STATUS
or k0, k0, a0
mtc0 k0, CP0_STATUS
ehb
/* Return */
jr ra