* [PATCH] Stash reent marker in upper bits of s1 on AMD GCN
@ 2019-11-07 22:46 Kwok Cheung Yeung
2019-11-08 9:35 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Kwok Cheung Yeung @ 2019-11-07 22:46 UTC (permalink / raw)
To: newlib; +Cc: Kwok Cheung Yeung
s[0:3] contain a descriptor used to set up the initial value of the
stack, but only the lower 48 bits of s[0:1] are currently used.
The reent marker is currently set in s3, but by stashing it in the
upper 16 bits of s[0:1] instead, s3 can be freed up for other purposes.
---
newlib/libc/machine/amdgcn/getreent.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/newlib/libc/machine/amdgcn/getreent.c b/newlib/libc/machine/amdgcn/getreent.c
index bc50ca0..be7d2ed 100644
--- a/newlib/libc/machine/amdgcn/getreent.c
+++ b/newlib/libc/machine/amdgcn/getreent.c
@@ -34,7 +34,7 @@ __getreent (void)
s11 contains the offset to the base of the stack.
s[4:5] contains the dispatch pointer.
- WARNING: this code will break if s[0:3] is ever used for anything! */
+ WARNING: this code will break if s[0:1] is ever used for anything! */
const register unsigned long buffer_descriptor asm("s0");
unsigned long private_segment = buffer_descriptor & 0x0000ffffffffffff;
const register unsigned int stack_offset asm("s11");
@@ -54,20 +54,20 @@ __getreent (void)
if (sp >= addr)
goto stackoverflow;
- /* Place a marker in s3 to indicate that the reent data is initialized.
- The register is known to hold part of an unused buffer descriptor
- when the kernel is launched. This may not be unused forever, but
- we already used s0 and s1 above, so this doesn't do extra harm. */
- register int s3 asm("s3");
- if (s3 != 123456)
+ /* Stash a marker in the unused upper 16 bits of s[0:1] to indicate that
+ the reent data is initialized. */
+ const register unsigned int s1 asm("s1");
+ unsigned int marker = s1 >> 16;
+ if (marker != 12345)
{
- asm("s_mov_b32 s3, 123456");
- data->marker = 123456;
+ asm("s_and_b32\ts1, s1, 0xffff");
+ asm("s_or_b32\ts1, s1, (12345 << 16)");
+ data->marker = 12345;
__builtin_memset (&data->reent, 0, sizeof(struct _reent));
_REENT_INIT_PTR_ZEROED (&data->reent);
}
- else if (data->marker != 123456)
+ else if (data->marker != 12345)
goto stackoverflow;
--
2.8.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Stash reent marker in upper bits of s1 on AMD GCN
2019-11-07 22:46 [PATCH] Stash reent marker in upper bits of s1 on AMD GCN Kwok Cheung Yeung
@ 2019-11-08 9:35 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2019-11-08 9:35 UTC (permalink / raw)
To: Kwok Cheung Yeung; +Cc: newlib
[-- Attachment #1: Type: text/plain, Size: 2448 bytes --]
On Nov 7 14:46, Kwok Cheung Yeung wrote:
> s[0:3] contain a descriptor used to set up the initial value of the
> stack, but only the lower 48 bits of s[0:1] are currently used.
> The reent marker is currently set in s3, but by stashing it in the
> upper 16 bits of s[0:1] instead, s3 can be freed up for other purposes.
> ---
> newlib/libc/machine/amdgcn/getreent.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/newlib/libc/machine/amdgcn/getreent.c b/newlib/libc/machine/amdgcn/getreent.c
> index bc50ca0..be7d2ed 100644
> --- a/newlib/libc/machine/amdgcn/getreent.c
> +++ b/newlib/libc/machine/amdgcn/getreent.c
> @@ -34,7 +34,7 @@ __getreent (void)
> s11 contains the offset to the base of the stack.
> s[4:5] contains the dispatch pointer.
>
> - WARNING: this code will break if s[0:3] is ever used for anything! */
> + WARNING: this code will break if s[0:1] is ever used for anything! */
> const register unsigned long buffer_descriptor asm("s0");
> unsigned long private_segment = buffer_descriptor & 0x0000ffffffffffff;
> const register unsigned int stack_offset asm("s11");
> @@ -54,20 +54,20 @@ __getreent (void)
> if (sp >= addr)
> goto stackoverflow;
>
> - /* Place a marker in s3 to indicate that the reent data is initialized.
> - The register is known to hold part of an unused buffer descriptor
> - when the kernel is launched. This may not be unused forever, but
> - we already used s0 and s1 above, so this doesn't do extra harm. */
> - register int s3 asm("s3");
> - if (s3 != 123456)
> + /* Stash a marker in the unused upper 16 bits of s[0:1] to indicate that
> + the reent data is initialized. */
> + const register unsigned int s1 asm("s1");
> + unsigned int marker = s1 >> 16;
> + if (marker != 12345)
> {
> - asm("s_mov_b32 s3, 123456");
> - data->marker = 123456;
> + asm("s_and_b32\ts1, s1, 0xffff");
> + asm("s_or_b32\ts1, s1, (12345 << 16)");
> + data->marker = 12345;
>
> __builtin_memset (&data->reent, 0, sizeof(struct _reent));
> _REENT_INIT_PTR_ZEROED (&data->reent);
> }
> - else if (data->marker != 123456)
> + else if (data->marker != 12345)
> goto stackoverflow;
>
>
> --
> 2.8.1
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-08 9:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 22:46 [PATCH] Stash reent marker in upper bits of s1 on AMD GCN Kwok Cheung Yeung
2019-11-08 9:35 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).