Discussion:
[ORLinux] [PATCH 2/2] openrisc: Add thread-local storage (TLS) support
Christian Svensson
2014-01-25 16:01:55 UTC
Permalink
Historically OpenRISC GCC has reserved r10 which we now use to hold
the thread pointer for thread-local storage (TLS).

Signed-off-by: Christian Svensson <blue at cmd.nu>
---
arch/openrisc/kernel/process.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c
index 386af25..86b9978 100644
--- a/arch/openrisc/kernel/process.c
+++ b/arch/openrisc/kernel/process.c
@@ -173,6 +173,19 @@ copy_thread(unsigned long clone_flags, unsigned long
usp,

if (usp)
userregs->sp = usp;
+
+ /*
+ * For CLONE_SETTLS set "tp" (r10) to the TLS pointer passed to sys_clone.
+ *
+ * The kernel entry is:
+ * int clone (long flags, void *child_stack, int *parent_tid,
+ * int *child_tid, struct void *tls)
+ *
+ * This makes the source r7 in the kernel registers.
+ */
+ if (clone_flags & CLONE_SETTLS)
+ userregs->gpr[10] = kregs->gpr[7];
+
userregs->gpr[11] = 0; /* Result from fork() */

kregs->gpr[20] = 0; /* Userspace thread */
--
1.7.10.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openrisc.net/pipermail/linux/attachments/20140125/52b3316f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-openrisc-Add-thread-local-storage-TLS-support.patch
Type: application/octet-stream
Size: 1259 bytes
Desc: not available
URL: <http://lists.openrisc.net/pipermail/linux/attachments/20140125/52b3316f/attachment.obj>
Christian Svensson
2014-03-09 00:49:23 UTC
Permalink
Ping!
Post by Christian Svensson
Historically OpenRISC GCC has reserved r10 which we now use to hold
the thread pointer for thread-local storage (TLS).
Signed-off-by: Christian Svensson <blue at cmd.nu>
---
arch/openrisc/kernel/process.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c
index 386af25..86b9978 100644
--- a/arch/openrisc/kernel/process.c
+++ b/arch/openrisc/kernel/process.c
@@ -173,6 +173,19 @@ copy_thread(unsigned long clone_flags, unsigned long
usp,
if (usp)
userregs->sp = usp;
+
+ /*
+ * For CLONE_SETTLS set "tp" (r10) to the TLS pointer passed to sys_clone.
+ *
+ * int clone (long flags, void *child_stack, int *parent_tid,
+ * int *child_tid, struct void *tls)
+ *
+ * This makes the source r7 in the kernel registers.
+ */
+ if (clone_flags & CLONE_SETTLS)
+ userregs->gpr[10] = kregs->gpr[7];
+
userregs->gpr[11] = 0; /* Result from fork() */
kregs->gpr[20] = 0; /* Userspace thread */
--
1.7.10.4
Stefan Kristiansson
2014-04-24 05:10:46 UTC
Permalink
Post by Christian Svensson
Historically OpenRISC GCC has reserved r10 which we now use to hold
the thread pointer for thread-local storage (TLS).
Signed-off-by: Christian Svensson <blue at cmd.nu>
---
arch/openrisc/kernel/process.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c
index 386af25..86b9978 100644
--- a/arch/openrisc/kernel/process.c
+++ b/arch/openrisc/kernel/process.c
@@ -173,6 +173,19 @@ copy_thread(unsigned long clone_flags, unsigned long
usp,
if (usp)
userregs->sp = usp;
+
+ /*
+ * For CLONE_SETTLS set "tp" (r10) to the TLS pointer passed to sys_clone.
+ *
+ * int clone (long flags, void *child_stack, int *parent_tid,
+ * int *child_tid, struct void *tls)
+ *
+ * This makes the source r7 in the kernel registers.
+ */
+ if (clone_flags & CLONE_SETTLS)
+ userregs->gpr[10] = kregs->gpr[7];
To keep it on record so we don't forget it, this should be:

userregs->gpr[10] = userregs->gpr[7];
Post by Christian Svensson
+
userregs->gpr[11] = 0; /* Result from fork() */
kregs->gpr[20] = 0; /* Userspace thread */
--
1.7.10.4
_______________________________________________
Linux mailing list
Linux at lists.openrisc.net
http://lists.openrisc.net/listinfo/linux
Christian Svensson
2014-07-12 13:34:55 UTC
Permalink
Updated patch.
Since I'm sending this via gmail I do not expect the patch to be
copy-paste:able so I attached it. The patch is also viewable at:
https://github.com/bluecmd/or1k-linux/commit/5407ab8ce13f2c3f85e733c5d6b5cca5fb35f728.patch
Loading...