From d7d746f44e1df16ea3178a8fa6118f3ba81d1a77 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Mon, 30 Mar 2020 01:12:07 -0500 Subject: [PATCH] s390x: modernize assembly code --- arch/s390x/defs.h | 13 ++++++++++--- arch/s390x/getcontext.S | 15 ++++++--------- arch/s390x/makecontext.c | 2 +- arch/s390x/setcontext.S | 15 ++++++--------- arch/s390x/startcontext.S | 7 +++---- arch/s390x/swapcontext.S | 19 ++++++++----------- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/arch/s390x/defs.h b/arch/s390x/defs.h index 1b2c9e7..cad2184 100644 --- a/arch/s390x/defs.h +++ b/arch/s390x/defs.h @@ -1,8 +1,15 @@ #ifndef __ARCH_S390X_DEFS_H #define __ARCH_S390X_DEFS_H -#define OFFSET_GREGS (56) -#define OFFSET_AREGS (184) -#define OFFSET_FPREGS (248) +#define REG_SZ (8) +#define AREG_SZ (4) + +#define MCONTEXT_GREGS (56) +#define MCONTEXT_AREGS (184) +#define MCONTEXT_FPREGS (248) + +#define AREG_OFFSET(__reg) (MCONTEXT_AREGS + ((__reg) * AREG_SZ)) + +#include "common-defs.h" #endif diff --git a/arch/s390x/getcontext.S b/arch/s390x/getcontext.S index ad4bb4a..d38de97 100644 --- a/arch/s390x/getcontext.S +++ b/arch/s390x/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 @@ -12,17 +12,14 @@ #include "defs.h" +ALIAS(getcontext, __getcontext) -.globl __getcontext; -__getcontext: +FUNC(__getcontext) lgr %r1, %r2 /* use %r1 as our working register */ la %r2, 0 /* we will return 0 */ - stam %a0, %a15, OFFSET_AREGS(%r1) /* store access registers */ - stmg %r0, %r15, OFFSET_GREGS(%r1) /* store general-purpose registers */ + stam %a0, %a15, AREG_OFFSET(0)(%r1) /* store access registers */ + stmg %r0, %r15, REG_OFFSET(0)(%r1) /* store general-purpose registers */ br %r14 /* return to where we came from */ - - -.weak getcontext; -getcontext = __getcontext; +END(__getcontext) diff --git a/arch/s390x/makecontext.c b/arch/s390x/makecontext.c index c226e78..488f768 100644 --- a/arch/s390x/makecontext.c +++ b/arch/s390x/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 diff --git a/arch/s390x/setcontext.S b/arch/s390x/setcontext.S index a363ebc..52618b8 100644 --- a/arch/s390x/setcontext.S +++ b/arch/s390x/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 @@ -12,16 +12,13 @@ #include "defs.h" +ALIAS(setcontext, __setcontext) -.globl __setcontext; -__setcontext: +FUNC(__setcontext) lgr %r1, %r2 /* use %r1 as our working register */ - lam %a2, %a15, OFFSET_AREGS+8(%r1) /* load access registers, but skip %a0 and %a1 which are for TLS */ - lmg %r0, %r15, OFFSET_GREGS(%r1) /* store general-purpose registers */ + lam %a2, %a15, AREG_OFFSET(2)(%r1) /* load access registers, but skip %a0 and %a1 which are for TLS */ + lmg %r0, %r15, REG_OFFSET(0)(%r1) /* store general-purpose registers */ br %r14 /* return to new link register address */ - - -.weak setcontext; -setcontext = __setcontext; +END(__setcontext) diff --git a/arch/s390x/startcontext.S b/arch/s390x/startcontext.S index 434d481..79bd3fe 100644 --- a/arch/s390x/startcontext.S +++ b/arch/s390x/startcontext.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 @@ -12,9 +12,7 @@ #include "defs.h" - -.globl __start_context; -__start_context: +FUNC(__start_context) basr %r14, %r7 /* run function pointer (%r7) and return here */ ltgr %r8, %r8 /* check to see if uc_link (%r8) is null */ @@ -28,3 +26,4 @@ no_linked_context: brasl %r14, exit@plt /* call exit */ j .+2 /* crash if exit returns */ +END(__start_context) diff --git a/arch/s390x/swapcontext.S b/arch/s390x/swapcontext.S index 5fc629c..8c85cf0 100644 --- a/arch/s390x/swapcontext.S +++ b/arch/s390x/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 @@ -12,21 +12,18 @@ #include "defs.h" +ALIAS(swapcontext, __swapcontext) -.globl __swapcontext; -__swapcontext: +FUNC(__swapcontext) lgr %r1, %r2 /* use %r1 to save current context to */ lgr %r0, %r3 /* use %r0 for source context */ - stam %a0, %a15, OFFSET_AREGS(%r1) /* store access registers */ - stmg %r0, %r15, OFFSET_GREGS(%r1) /* store general-purpose registers */ + stam %a0, %a15, AREG_OFFSET(0)(%r1) /* store access registers */ + stmg %r0, %r15, REG_OFFSET(0)(%r1) /* store general-purpose registers */ lgr %r2, %r0 /* swap %r0 to %r2 (XXX: figure out why it hates loading from %r0) */ - lam %a2, %a15, OFFSET_AREGS+8(%r2) /* load access registers, but skip %a0 and %a1 which are for TLS */ - lmg %r0, %r15, OFFSET_GREGS(%r2) /* load general-purpose registers */ + lam %a2, %a15, AREG_OFFSET(2)(%r2) /* load access registers, but skip %a0 and %a1 which are for TLS */ + lmg %r0, %r15, REG_OFFSET(0)(%r2) /* load general-purpose registers */ br %r14 /* return to new link register address */ - - -.weak swapcontext; -swapcontext = __swapcontext; +END(__swapcontext)