From f708c95659873bdb4c25baaa4ec28fac2aa92355 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Mon, 30 Mar 2020 05:02:49 +0000 Subject: [PATCH] arm: modernize --- arch/arm/defs.h | 10 ++++++++++ arch/arm/getcontext.S | 20 ++++++++++---------- arch/arm/makecontext.c | 12 ++++-------- arch/arm/setcontext.S | 16 ++++++++-------- arch/arm/swapcontext.S | 22 +++++++++++----------- arch/common/common-defs.h | 6 +++++- 6 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 arch/arm/defs.h diff --git a/arch/arm/defs.h b/arch/arm/defs.h new file mode 100644 index 0000000..27a94a7 --- /dev/null +++ b/arch/arm/defs.h @@ -0,0 +1,10 @@ +#ifndef __ARCH_ARM_DEFS_H + +#define REG_SZ (4) +#define MCONTEXT_GREGS (32) + +#define TYPE(__proc) + +#include "common-defs.h" + +#endif diff --git a/arch/arm/getcontext.S b/arch/arm/getcontext.S index aa4954f..9872724 100644 --- a/arch/arm/getcontext.S +++ b/arch/arm/getcontext.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Ariadne Conill + * Copyright (c) 2018, 2020 Ariadne Conill * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -10,18 +10,18 @@ * from the use of this software. */ -.globl __getcontext; -__getcontext: +#include "defs.h" + +ALIAS(getcontext, __getcontext) + +FUNC(__getcontext) /* copy all of the current registers into the ucontext structure */ - add r1, r0, #48 + add r1, r0, #REG_OFFSET(4) stmia r1, {r4-r12} - str r13, [r0,#84] - str r14, [r0,#92] + str r13, [r0, #REG_OFFSET(13)] + str r14, [r0, #REG_OFFSET(15)] /* return 0 */ mov r0, #0 mov pc, lr - - -.weak getcontext; -getcontext = __getcontext; +END(__getcontext) diff --git a/arch/arm/makecontext.c b/arch/arm/makecontext.c index 2d1dad4..aed94f0 100644 --- a/arch/arm/makecontext.c +++ b/arch/arm/makecontext.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Ariadne Conill + * Copyright (c) 2018, 2020 Ariadne Conill * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,6 +19,9 @@ #include +#include "defs.h" + + extern void __start_context(void); @@ -52,13 +55,6 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) *sp++ = va_arg (va, unsigned long); va_end(va); - -/* - printf("R4 offset = %d\n", offsetof(ucontext_t, uc_mcontext.arm_r4)); - printf("SP offset = %d\n", offsetof(ucontext_t, uc_mcontext.arm_sp)); - printf("LR offset = %d\n", offsetof(ucontext_t, uc_mcontext.arm_lr)); - printf("PC offset = %d\n", offsetof(ucontext_t, uc_mcontext.arm_pc)); - */ } diff --git a/arch/arm/setcontext.S b/arch/arm/setcontext.S index e6d1e93..2d5420f 100644 --- a/arch/arm/setcontext.S +++ b/arch/arm/setcontext.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Ariadne Conill + * Copyright (c) 2018, 2020 Ariadne Conill * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -10,17 +10,17 @@ * from the use of this software. */ -.globl __setcontext; -__setcontext: +#include "defs.h" + +ALIAS(setcontext, __setcontext) + +FUNC(__setcontext) /* copy all of the current registers into the ucontext structure */ - add r14, r0, #32 + add r14, r0, #REG_OFFSET(0) ldmia r14, {r0-r12} ldr r13, [r14, #52] add r14, r14, #56 /* load link register and jump to new context */ ldmia r14, {r14, pc} - - -.weak setcontext; -setcontext = __setcontext; +END(__setcontext) diff --git a/arch/arm/swapcontext.S b/arch/arm/swapcontext.S index 79ca020..cd28445 100644 --- a/arch/arm/swapcontext.S +++ b/arch/arm/swapcontext.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Ariadne Conill + * Copyright (c) 2018, 2020 Ariadne Conill * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -10,21 +10,21 @@ * from the use of this software. */ -.globl __swapcontext; -__swapcontext: +#include "defs.h" + +ALIAS(swapcontext, __swapcontext) + +FUNC(__swapcontext) /* copy all of the current registers into the ucontext structure */ - add r2, r0, #32 + add r2, r0, #REG_OFFSET(0) stmia r2, {r0-r12} - str r13, [r0,#84] - str r14, [r0,#92] + str r13, [r0,#REG_OFFSET(13)] + str r14, [r0,#REG_OFFSET(15)] /* load new registers from the second ucontext structure */ - add r14, r1, #32 + add r14, r1, #REG_OFFSET(0) ldmia r14, {r0-r12} ldr r13, [r14, #52] add r14, r14, #56 ldmia r14, {r14, pc} - - -.weak swapcontext; -swapcontext = __swapcontext; +END(__swapcontext) diff --git a/arch/common/common-defs.h b/arch/common/common-defs.h index 3e27ca0..bf2fb8c 100644 --- a/arch/common/common-defs.h +++ b/arch/common/common-defs.h @@ -17,10 +17,14 @@ # define ENT(__proc) #endif +#ifndef TYPE +# define TYPE(__proc) .type __proc, @function; +#endif + #define FUNC(__proc) \ .global __proc; \ .align 2; \ - .type __proc, @function; \ + TYPE(__proc) \ ENT(__proc) \ __proc: \ SETUP_FRAME(__proc)