s390x: modernize assembly code

pull/17/head
Ariadne Conill 2020-03-30 01:12:07 -05:00
parent ef42ad682a
commit d7d746f44e
6 changed files with 34 additions and 37 deletions

View File

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

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
* 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)

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
* purpose with or without fee is hereby granted, provided that the above

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
* 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)

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
* 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)

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
* 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)