From: Ben Dooks <ben.dooks@codethink.co.uk>
To: linux-riscv@lists.infradead.org
Cc: palmer@dabbelt.com, ajones@ventanamicro.com, alex@ghiti.fr,
Ben Dooks <ben.dooks@codethink.co.uk>
Subject: [PATCH 1/3] riscv: ptrace: add regs_set_register()
Date: Wed, 13 Nov 2024 09:17:01 +0000 [thread overview]
Message-ID: <20241113091703.3133017-2-ben.dooks@codethink.co.uk> (raw)
In-Reply-To: <20241113091703.3133017-1-ben.dooks@codethink.co.uk>
Since we have regs_get_register() and we could use the set counterpart
for things like fixing up traps, add regs_set_register() to set a pt_regs
value from offset.
Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
arch/riscv/include/asm/ptrace.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h
index b5b0adcc85c1..66fc1795141d 100644
--- a/arch/riscv/include/asm/ptrace.h
+++ b/arch/riscv/include/asm/ptrace.h
@@ -143,6 +143,26 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
return *(unsigned long *)((unsigned long)regs + offset);
}
+/**
+ * regs_set_register() - set register value from its offset
+ * @regs: pt_regs from which register value is gotten
+ * @offset: offset of the register.
+ * @to: value to set register to
+ *
+ * regs_set_register sets the value @to to a register whose offset from @regs.
+ * The @offset is the offset of the register in struct pt_regs.
+ * If @offset is bigger than MAX_REG_OFFSET, this will ignore the write.
+ */
+static inline void regs_set_register(struct pt_regs *regs,
+ unsigned int offset,
+ unsigned long to)
+{
+ if (unlikely(offset > MAX_REG_OFFSET))
+ return;
+
+ *(unsigned long *)((unsigned long)regs + offset) = to;
+}
+
/**
* regs_get_kernel_argument() - get Nth function argument in kernel
* @regs: pt_regs of that context
--
2.37.2.352.g3c44437643
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2024-11-13 9:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 9:17 updates for instruction trapping and ptrace Ben Dooks
2024-11-13 9:17 ` Ben Dooks [this message]
2024-11-13 10:12 ` [PATCH 1/3] riscv: ptrace: add regs_set_register() Andrew Jones
2024-11-13 10:19 ` Ben Dooks
2024-11-13 9:17 ` [PATCH 2/3] riscv: traps: make insn fetch common in unknown instruction Ben Dooks
2024-11-13 9:21 ` Ben Dooks
2024-11-13 9:31 ` Ben Dooks
2024-11-13 9:17 ` [PATCH 3/3] riscv: insn: add RV_EXTRACT_FUNCT3() Ben Dooks
2024-11-13 10:17 ` Andrew Jones
2024-11-13 10:35 ` Ben Dooks
-- strict thread matches above, loose matches on Subject: below --
2024-09-17 13:08 RFC: extern illegal instruction trap and trap RDCYCLE Ben Dooks
2024-09-17 13:08 ` [PATCH 1/3] riscv: ptrace: add regs_set_register() Ben Dooks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241113091703.3133017-2-ben.dooks@codethink.co.uk \
--to=ben.dooks@codethink.co.uk \
--cc=ajones@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox