Loading...
1#ifndef _SELFTESTS_POWERPC_BASIC_ASM_H
2#define _SELFTESTS_POWERPC_BASIC_ASM_H
3
4#include <ppc-asm.h>
5#include <asm/unistd.h>
6
7#define LOAD_REG_IMMEDIATE(reg, expr) \
8 lis reg, (expr)@highest; \
9 ori reg, reg, (expr)@higher; \
10 rldicr reg, reg, 32, 31; \
11 oris reg, reg, (expr)@high; \
12 ori reg, reg, (expr)@l;
13
14/*
15 * Note: These macros assume that variables being stored on the stack are
16 * doublewords, while this is usually the case it may not always be the
17 * case for each use case.
18 */
19#if defined(_CALL_ELF) && _CALL_ELF == 2
20#define STACK_FRAME_MIN_SIZE 32
21#define STACK_FRAME_TOC_POS 24
22#define __STACK_FRAME_PARAM(_param) (32 + ((_param)*8))
23#define __STACK_FRAME_LOCAL(_num_params, _var_num) \
24 ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8))
25#else
26#define STACK_FRAME_MIN_SIZE 112
27#define STACK_FRAME_TOC_POS 40
28#define __STACK_FRAME_PARAM(i) (48 + ((i)*8))
29
30/*
31 * Caveat: if a function passed more than 8 doublewords, the caller will have
32 * made more space... which would render the 112 incorrect.
33 */
34#define __STACK_FRAME_LOCAL(_num_params, _var_num) \
35 (112 + ((_var_num)*8))
36#endif
37
38/* Parameter x saved to the stack */
39#define STACK_FRAME_PARAM(var) __STACK_FRAME_PARAM(var)
40
41/* Local variable x saved to the stack after x parameters */
42#define STACK_FRAME_LOCAL(num_params, var) \
43 __STACK_FRAME_LOCAL(num_params, var)
44#define STACK_FRAME_LR_POS 16
45#define STACK_FRAME_CR_POS 8
46
47/*
48 * It is very important to note here that _extra is the extra amount of
49 * stack space needed. This space can be accessed using STACK_FRAME_PARAM()
50 * or STACK_FRAME_LOCAL() macros.
51 *
52 * r1 and r2 are not defined in ppc-asm.h (instead they are defined as sp
53 * and toc). Kernel programmers tend to prefer rX even for r1 and r2, hence
54 * %1 and %r2. r0 is defined in ppc-asm.h and therefore %r0 gets
55 * preprocessed incorrectly, hence r0.
56 */
57#define PUSH_BASIC_STACK(_extra) \
58 mflr r0; \
59 std r0, STACK_FRAME_LR_POS(%r1); \
60 stdu %r1, -(_extra + STACK_FRAME_MIN_SIZE)(%r1); \
61 mfcr r0; \
62 stw r0, STACK_FRAME_CR_POS(%r1); \
63 std %r2, STACK_FRAME_TOC_POS(%r1);
64
65#define POP_BASIC_STACK(_extra) \
66 ld %r2, STACK_FRAME_TOC_POS(%r1); \
67 lwz r0, STACK_FRAME_CR_POS(%r1); \
68 mtcr r0; \
69 addi %r1, %r1, (_extra + STACK_FRAME_MIN_SIZE); \
70 ld r0, STACK_FRAME_LR_POS(%r1); \
71 mtlr r0;
72
73#endif /* _SELFTESTS_POWERPC_BASIC_ASM_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _SELFTESTS_POWERPC_BASIC_ASM_H
3#define _SELFTESTS_POWERPC_BASIC_ASM_H
4
5#include <ppc-asm.h>
6#include <asm/unistd.h>
7
8#define LOAD_REG_IMMEDIATE(reg, expr) \
9 lis reg, (expr)@highest; \
10 ori reg, reg, (expr)@higher; \
11 rldicr reg, reg, 32, 31; \
12 oris reg, reg, (expr)@high; \
13 ori reg, reg, (expr)@l;
14
15/*
16 * Note: These macros assume that variables being stored on the stack are
17 * doublewords, while this is usually the case it may not always be the
18 * case for each use case.
19 */
20#if defined(_CALL_ELF) && _CALL_ELF == 2
21#define STACK_FRAME_MIN_SIZE 32
22#define STACK_FRAME_TOC_POS 24
23#define __STACK_FRAME_PARAM(_param) (32 + ((_param)*8))
24#define __STACK_FRAME_LOCAL(_num_params, _var_num) \
25 ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8))
26#else
27#define STACK_FRAME_MIN_SIZE 112
28#define STACK_FRAME_TOC_POS 40
29#define __STACK_FRAME_PARAM(i) (48 + ((i)*8))
30
31/*
32 * Caveat: if a function passed more than 8 doublewords, the caller will have
33 * made more space... which would render the 112 incorrect.
34 */
35#define __STACK_FRAME_LOCAL(_num_params, _var_num) \
36 (112 + ((_var_num)*8))
37#endif
38
39/* Parameter x saved to the stack */
40#define STACK_FRAME_PARAM(var) __STACK_FRAME_PARAM(var)
41
42/* Local variable x saved to the stack after x parameters */
43#define STACK_FRAME_LOCAL(num_params, var) \
44 __STACK_FRAME_LOCAL(num_params, var)
45#define STACK_FRAME_LR_POS 16
46#define STACK_FRAME_CR_POS 8
47
48/*
49 * It is very important to note here that _extra is the extra amount of
50 * stack space needed. This space can be accessed using STACK_FRAME_PARAM()
51 * or STACK_FRAME_LOCAL() macros.
52 *
53 * r1 and r2 are not defined in ppc-asm.h (instead they are defined as sp
54 * and toc). Kernel programmers tend to prefer rX even for r1 and r2, hence
55 * %1 and %r2. r0 is defined in ppc-asm.h and therefore %r0 gets
56 * preprocessed incorrectly, hence r0.
57 */
58#define PUSH_BASIC_STACK(_extra) \
59 mflr r0; \
60 std r0, STACK_FRAME_LR_POS(%r1); \
61 stdu %r1, -(_extra + STACK_FRAME_MIN_SIZE)(%r1); \
62 mfcr r0; \
63 stw r0, STACK_FRAME_CR_POS(%r1); \
64 std %r2, STACK_FRAME_TOC_POS(%r1);
65
66#define POP_BASIC_STACK(_extra) \
67 ld %r2, STACK_FRAME_TOC_POS(%r1); \
68 lwz r0, STACK_FRAME_CR_POS(%r1); \
69 mtcr r0; \
70 addi %r1, %r1, (_extra + STACK_FRAME_MIN_SIZE); \
71 ld r0, STACK_FRAME_LR_POS(%r1); \
72 mtlr r0;
73
74#endif /* _SELFTESTS_POWERPC_BASIC_ASM_H */