2018-01-31 04:11:46 +00:00
|
|
|
/*
|
2020-03-30 05:02:49 +00:00
|
|
|
* Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
|
2018-01-31 04:11:46 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
2020-03-30 05:02:49 +00:00
|
|
|
#include "defs.h"
|
|
|
|
|
2020-12-06 09:04:22 +00:00
|
|
|
ALIAS(swapcontext, libucontext_swapcontext)
|
2021-01-08 09:30:50 +00:00
|
|
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
2020-03-30 05:02:49 +00:00
|
|
|
|
2020-12-06 09:04:22 +00:00
|
|
|
FUNC(libucontext_swapcontext)
|
2022-03-04 18:35:25 +00:00
|
|
|
#ifndef FORCE_SOFT_FLOAT
|
|
|
|
#ifndef FORCE_HARD_FLOAT
|
|
|
|
/* test for vfp magic number, copy to other ucontext */
|
|
|
|
ldr r3, [r1, #VFP_MAGIC_OFFSET]
|
|
|
|
ldr r4, =#0x56465001
|
|
|
|
str r3, [r0, #VFP_MAGIC_OFFSET]
|
|
|
|
cmp r3, r4
|
|
|
|
bne 1f
|
|
|
|
#endif
|
|
|
|
/* if vfp in use, save and restore d8-d15 */
|
|
|
|
.fpu vfp
|
|
|
|
add r2, r0, #VFP_D8_OFFSET
|
|
|
|
vstmia r2, {d8-d15}
|
|
|
|
|
|
|
|
add r14, r1, #VFP_D8_OFFSET
|
|
|
|
vldmia r14, {d8-d15}
|
|
|
|
.fpu softvfp
|
|
|
|
1:
|
|
|
|
#endif
|
|
|
|
|
2023-08-30 20:31:58 +00:00
|
|
|
/* copy all of the current registers into the ucontext structure */
|
|
|
|
str r13, [r0,#REG_OFFSET(13)]
|
|
|
|
str r14, [r0,#REG_OFFSET(15)]
|
|
|
|
add r2, r0, #REG_OFFSET(0)
|
|
|
|
/* copy r0 with value 0 to indicate success (return value 0) */
|
|
|
|
mov r0, #0
|
|
|
|
stmia r2, {r0-r12}
|
|
|
|
|
2018-01-31 04:11:46 +00:00
|
|
|
/* load new registers from the second ucontext structure */
|
2020-03-30 05:02:49 +00:00
|
|
|
add r14, r1, #REG_OFFSET(0)
|
2018-01-31 04:11:46 +00:00
|
|
|
ldmia r14, {r0-r12}
|
|
|
|
ldr r13, [r14, #52]
|
|
|
|
add r14, r14, #56
|
|
|
|
ldmia r14, {r14, pc}
|
2020-12-06 09:04:22 +00:00
|
|
|
END(libucontext_swapcontext)
|