162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#include <linux/linkage.h>
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#define R0 0x00
562306a36Sopenharmony_ci#define R1 0x08
662306a36Sopenharmony_ci#define R2 0x10
762306a36Sopenharmony_ci#define R3 0x18
862306a36Sopenharmony_ci#define R4 0x20
962306a36Sopenharmony_ci#define R5 0x28
1062306a36Sopenharmony_ci#define R6 0x30
1162306a36Sopenharmony_ci#define R7 0x38
1262306a36Sopenharmony_ci#define R8 0x40
1362306a36Sopenharmony_ci#define R9 0x48
1462306a36Sopenharmony_ci#define SL 0x50
1562306a36Sopenharmony_ci#define FP 0x58
1662306a36Sopenharmony_ci#define IP 0x60
1762306a36Sopenharmony_ci#define SP 0x68
1862306a36Sopenharmony_ci#define LR 0x70
1962306a36Sopenharmony_ci#define PC 0x78
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * Implementation of void perf_regs_load(u64 *regs);
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * This functions fills in the 'regs' buffer from the actual registers values,
2562306a36Sopenharmony_ci * in the way the perf built-in unwinding test expects them:
2662306a36Sopenharmony_ci * - the PC at the time at the call to this function. Since this function
2762306a36Sopenharmony_ci *   is called using a bl instruction, the PC value is taken from LR.
2862306a36Sopenharmony_ci * The built-in unwinding test then unwinds the call stack from the dwarf
2962306a36Sopenharmony_ci * information in unwind__get_entries.
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci * Notes:
3262306a36Sopenharmony_ci * - the 8 bytes stride in the registers offsets comes from the fact
3362306a36Sopenharmony_ci * that the registers are stored in an u64 array (u64 *regs),
3462306a36Sopenharmony_ci * - the regs buffer needs to be zeroed before the call to this function,
3562306a36Sopenharmony_ci * in this case using a calloc in dwarf-unwind.c.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci.text
3962306a36Sopenharmony_ci.type perf_regs_load,%function
4062306a36Sopenharmony_ciSYM_FUNC_START(perf_regs_load)
4162306a36Sopenharmony_ci	str r0, [r0, #R0]
4262306a36Sopenharmony_ci	str r1, [r0, #R1]
4362306a36Sopenharmony_ci	str r2, [r0, #R2]
4462306a36Sopenharmony_ci	str r3, [r0, #R3]
4562306a36Sopenharmony_ci	str r4, [r0, #R4]
4662306a36Sopenharmony_ci	str r5, [r0, #R5]
4762306a36Sopenharmony_ci	str r6, [r0, #R6]
4862306a36Sopenharmony_ci	str r7, [r0, #R7]
4962306a36Sopenharmony_ci	str r8, [r0, #R8]
5062306a36Sopenharmony_ci	str r9, [r0, #R9]
5162306a36Sopenharmony_ci	str sl, [r0, #SL]
5262306a36Sopenharmony_ci	str fp, [r0, #FP]
5362306a36Sopenharmony_ci	str ip, [r0, #IP]
5462306a36Sopenharmony_ci	str sp, [r0, #SP]
5562306a36Sopenharmony_ci	str lr, [r0, #LR]
5662306a36Sopenharmony_ci	str lr, [r0, #PC]	// store pc as lr in order to skip the call
5762306a36Sopenharmony_ci	                        //  to this function
5862306a36Sopenharmony_ci	mov pc, lr
5962306a36Sopenharmony_ciSYM_FUNC_END(perf_regs_load)
60