arm: modernize

pull/17/head
Ariadne Conill 2020-03-30 05:02:49 +00:00
parent fb27ad693b
commit f708c95659
6 changed files with 48 additions and 38 deletions

10
arch/arm/defs.h Normal file
View File

@ -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

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org> * Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -10,18 +10,18 @@
* from the use of this software. * from the use of this software.
*/ */
.globl __getcontext; #include "defs.h"
__getcontext:
ALIAS(getcontext, __getcontext)
FUNC(__getcontext)
/* copy all of the current registers into the ucontext structure */ /* copy all of the current registers into the ucontext structure */
add r1, r0, #48 add r1, r0, #REG_OFFSET(4)
stmia r1, {r4-r12} stmia r1, {r4-r12}
str r13, [r0,#84] str r13, [r0, #REG_OFFSET(13)]
str r14, [r0,#92] str r14, [r0, #REG_OFFSET(15)]
/* return 0 */ /* return 0 */
mov r0, #0 mov r0, #0
mov pc, lr mov pc, lr
END(__getcontext)
.weak getcontext;
getcontext = __getcontext;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org> * Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -19,6 +19,9 @@
#include <stdio.h> #include <stdio.h>
#include "defs.h"
extern void __start_context(void); extern void __start_context(void);
@ -52,13 +55,6 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
*sp++ = va_arg (va, unsigned long); *sp++ = va_arg (va, unsigned long);
va_end(va); 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));
*/
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org> * Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -10,17 +10,17 @@
* from the use of this software. * from the use of this software.
*/ */
.globl __setcontext; #include "defs.h"
__setcontext:
ALIAS(setcontext, __setcontext)
FUNC(__setcontext)
/* copy all of the current registers into the ucontext structure */ /* copy all of the current registers into the ucontext structure */
add r14, r0, #32 add r14, r0, #REG_OFFSET(0)
ldmia r14, {r0-r12} ldmia r14, {r0-r12}
ldr r13, [r14, #52] ldr r13, [r14, #52]
add r14, r14, #56 add r14, r14, #56
/* load link register and jump to new context */ /* load link register and jump to new context */
ldmia r14, {r14, pc} ldmia r14, {r14, pc}
END(__setcontext)
.weak setcontext;
setcontext = __setcontext;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org> * Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -10,21 +10,21 @@
* from the use of this software. * from the use of this software.
*/ */
.globl __swapcontext; #include "defs.h"
__swapcontext:
ALIAS(swapcontext, __swapcontext)
FUNC(__swapcontext)
/* copy all of the current registers into the ucontext structure */ /* copy all of the current registers into the ucontext structure */
add r2, r0, #32 add r2, r0, #REG_OFFSET(0)
stmia r2, {r0-r12} stmia r2, {r0-r12}
str r13, [r0,#84] str r13, [r0,#REG_OFFSET(13)]
str r14, [r0,#92] str r14, [r0,#REG_OFFSET(15)]
/* load new registers from the second ucontext structure */ /* load new registers from the second ucontext structure */
add r14, r1, #32 add r14, r1, #REG_OFFSET(0)
ldmia r14, {r0-r12} ldmia r14, {r0-r12}
ldr r13, [r14, #52] ldr r13, [r14, #52]
add r14, r14, #56 add r14, r14, #56
ldmia r14, {r14, pc} ldmia r14, {r14, pc}
END(__swapcontext)
.weak swapcontext;
swapcontext = __swapcontext;

View File

@ -17,10 +17,14 @@
# define ENT(__proc) # define ENT(__proc)
#endif #endif
#ifndef TYPE
# define TYPE(__proc) .type __proc, @function;
#endif
#define FUNC(__proc) \ #define FUNC(__proc) \
.global __proc; \ .global __proc; \
.align 2; \ .align 2; \
.type __proc, @function; \ TYPE(__proc) \
ENT(__proc) \ ENT(__proc) \
__proc: \ __proc: \
SETUP_FRAME(__proc) SETUP_FRAME(__proc)