Skip to contentSkip to conversation

: Fix sparc64 setjmp implementation.

PATCH In review David Miller 6 participants 17 messages Mar 4, 2009 – Mar 7, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 : Fix sparc64 setjmp implementation.

This corrects the sparc64 setjmp implementation.

We need to store the return address register, the stack pointer, and frame pointer into the jump buf.

And on longjmp we need restore those registers, flush the register window state, and pull in the top-most register window.

2009-03-03 David S. Miller <[email protected]>

* normal/sparc64/setjmp.S: Fix setjmp implementation.
* include/grub/sparc64/setjmp.h: Update grub_jmp_buf[].

---
 include/grub/sparc64/setjmp.h |    3 +--
 normal/sparc64/setjmp.S       |   18 +++++++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)
include/grub/sparc64/setjmp.h +1 -2
index 12d8e01..183a820 100644
@@ -19,8 +19,7 @@
 #ifndef GRUB_SETJMP_CPU_HEADER
 #define GRUB_SETJMP_CPU_HEADER	1
 
-/* FIXME (sparc64).  */
-typedef unsigned long grub_jmp_buf[20];
+typedef unsigned long grub_jmp_buf[3];
 
 int grub_setjmp (grub_jmp_buf env);
 void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
normal/sparc64/setjmp.S +13 -5
index b1a9b6e..02e61b1 100644
@@ -26,13 +26,21 @@
  * int grub_setjmp (grub_jmp_buf env)
  */
 FUNCTION(grub_setjmp)
-        ret
-         nop
+	stx	%o7, [%o0 + 0x00]
+	stx	%sp, [%o0 + 0x08]
+	retl
+	 stx	%fp, [%o0 + 0x10]
 
 /*
  * int grub_longjmp (grub_jmp_buf env, int val)
  */
 FUNCTION(grub_longjmp)
-        ret
-         nop
-
+	ldx	[%o0 + 0x10], %g1
+	movrz	%o1, 1, %o1
+	ta	0x3
+	ldx	[%o0 + 0x00], %o7
+	ldx	[%o0 + 0x08], %fp
+	sub	%fp, 192, %sp
+	stx	%g1, [%sp + 2047 + (14 * 8)]
+        retl
+	 restore %o1, 0, %o0
Signature · 1 line
1.6.1.2.253.ga34a
#1 lore raw

normal/sparc64/setjmp.S line 46

Quoted 3 lines · David Miller
normal/sparc64/setjmp.S +3 -0
+	stx	%g1, [%sp + 2047 + (14 * 8)]
+        retl
+	 restore %o1, 0, %o0

Please check your white spaces. As we can see here those three commands are on different columns (mixed tabs and spaces). This applies to every other patch you sent too...

#2 lore raw

From: Vesa Jääskeläinen <[email protected]>
Date: Wed, 04 Mar 2009 12:59:37 +0200

Quoted 9 lines

normal/sparc64/setjmp.S line 46

Quoted 3 lines · David Miller
normal/sparc64/setjmp.S +3 -0
+	stx	%g1, [%sp + 2047 + (14 * 8)]
+        retl
+	 restore %o1, 0, %o0

Please check your white spaces. As we can see here those three commands are on different columns (mixed tabs and spaces). This applies to every other patch you sent too...

I used plain ASCII text for my patch postings.

I just double checked and they are perfectly fine and applyable in my email client.

Also note that in the delay slot of control transfer instructions, I do intentionally use TAB then one space, as this is common practice for sparc assembler to visually denote the delay slot instruction.

Even GCC outputs assembler using this convention :-)

#3 lore raw
In reply to David Miller
Quoted 22 lines · David Miller

This corrects the sparc64 setjmp implementation.

We need to store the return address register, the stack pointer, and frame pointer into the jump buf.

And on longjmp we need restore those registers, flush the register window state, and pull in the top-most register window.

2009-03-03 David S. Miller <[email protected]>

* normal/sparc64/setjmp.S: Fix setjmp implementation.
* include/grub/sparc64/setjmp.h: Update grub_jmp_buf[].

---
 include/grub/sparc64/setjmp.h |    3 +--
 normal/sparc64/setjmp.S       |   18 +++++++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)
include/grub/sparc64/setjmp.h +0 -0
index 12d8e01..183a820 100644

include/grub/sparc64/setjmp.h line 22

Quoted 6 lines
include/grub/sparc64/setjmp.h +1 -2
@@ -19,8 +19,7 @@
 #ifndef GRUB_SETJMP_CPU_HEADER
 #define GRUB_SETJMP_CPU_HEADER	1
 
-/* FIXME (sparc64).  */
-typedef unsigned long grub_jmp_buf[20];
+typedef unsigned long grub_jmp_buf[3];

I assume unsigned long is 64bit in sparc?

Would it be more practical to use grub_uint64_t?

Are there any other registers that needs to be preserved ?

Other than that I cannot decipher more from that asm :). If you have tested it and it works. It probably ain't bad idea to commit this patch.

#4 lore raw

From: Vesa Jääskeläinen <[email protected]>
Date: Wed, 04 Mar 2009 13:34:46 +0200

Quoted 9 lines
Quoted 8 lines · David Miller
include/grub/sparc64/setjmp.h +0 -0
index 12d8e01..183a820 100644
@@ -19,8 +19,7 @@
 #ifndef GRUB_SETJMP_CPU_HEADER
 #define GRUB_SETJMP_CPU_HEADER	1
 
Quoted 5 lines

include/grub/sparc64/setjmp.h line 22

Quoted 3 lines
include/grub/sparc64/setjmp.h +1 -2
-/* FIXME (sparc64).  */
-typedef unsigned long grub_jmp_buf[20];
+typedef unsigned long grub_jmp_buf[3];

I assume unsigned long is 64bit in sparc?

Yes, for sparc64 long is always 64-bit, no exceptions.

Quoted 1 line

Would it be more practical to use grub_uint64_t?

This is a "sparc64" file, so I don't think so.

Quoted 1 line

Are there any other registers that needs to be preserved ?

Not for GRUB, no.

#5 lore raw
Quoted 18 lines · David Miller

From: Vesa Jääskeläinen <[email protected]>
Date: Wed, 04 Mar 2009 13:34:46 +0200

Quoted 9 lines
Quoted 8 lines · David Miller
include/grub/sparc64/setjmp.h +0 -0
index 12d8e01..183a820 100644
@@ -19,8 +19,7 @@
 #ifndef GRUB_SETJMP_CPU_HEADER
 #define GRUB_SETJMP_CPU_HEADER	1
 
Quoted 5 lines

include/grub/sparc64/setjmp.h line 22

Quoted 3 lines
include/grub/sparc64/setjmp.h +1 -2
-/* FIXME (sparc64).  */
-typedef unsigned long grub_jmp_buf[20];
+typedef unsigned long grub_jmp_buf[3];

I assume unsigned long is 64bit in sparc?

Quoted 5 lines

Yes, for sparc64 long is always 64-bit, no exceptions.

Quoted 1 line

Would it be more practical to use grub_uint64_t?

This is a "sparc64" file, so I don't think so.

Next month, or maybe next year, someone will need to fix some bug on sparc64 code without being sparc64-savvy, maybe because (like it's already happened) there are no sparc people available. That day people like Bean, Felix, Marco or Robert (to name just a few of the big gurus here) may have to decide between editing a sparc64 file or give up on maintaining the platform. That day it would be really good for them to visually know that "unsigned long" is 64-bit in sparc, instead of having to go see the docs. This is the real utility of typedefs (and the [u]intNN_t types from C99): if you statically _know_ that some variable is going to be 64 bits long because the _platform_ requires it, why not make it explicit? It will be easier for readers and maintainers.

As an example of what this entails, the failure to think with the future in mind has extraordinarily hampered the 32->64 bit transition: many Windows apps (among them the Vorbis codecs!) had be nearly rewritten because they used "unsigned long" interchangeably with pointer types. I still wonder if it would have been so difficult to use "void*", and the proper types for pointer arithmetic.

Signature · 1 line
-- Lazy, Oblivious, Rational Disaster -- Habbit
#6 lore raw

From: Javier Martín <[email protected]>
Date: Wed, 04 Mar 2009 16:58:22 +0100

Quoted 6 lines

As an example of what this entails, the failure to think with the future in mind has extraordinarily hampered the 32->64 bit transition: many Windows apps (among them the Vorbis codecs!) had be nearly rewritten because they used "unsigned long" interchangeably with pointer types. I still wonder if it would have been so difficult to use "void*", and the proper types for pointer arithmetic.

Actually the problem is that they used "int" interchangably with pointer types.

"unsigned long" is always safe because it is going to be the largest natural word size on the machine, at least as large as a pointer will be.

We've been using "unsigned long" for storing virtual addresses in the Linux kernel for 10+ years and it works just fine. :-)

Really, nobody is going to touch the grub_jmp_buf[] implementation other than sparc expert. So saying this case will cause problems for grub non-sparc folks is something of a scarecrow.

#7 lore raw
Quoted 3 lines · David Miller

"unsigned long" is always safe because it is going to be the largest natural word size on the machine, at least as large as a pointer will be.

er... C standard doesn't guarantee this, and I think that Windows in fact has 32-bit longs on machines with 64-bit pointers

Quoted 2 lines

We've been using "unsigned long" for storing virtual addresses in the Linux kernel for 10+ years and it works just fine. :-)

and Linux kernel uses GCC compiler in precise ways

I believe that ptrdiff_t is the proper standardized type for an integer the size of a pointer. except... it's always signed :-)

Can you just use pointer types and pointer arithmetic?

also, standards aside, a common way to get such a type, is "configure" script testing various possibilities like "unsigned long" and "unsigned long long" and seeing which one is the right size for the target architecture. (not sure if that works when cross-compiling though)

-Isaac

#8 lore raw

From: Isaac Dupree <[email protected]>
Date: Thu, 5 Mar 2009 08:04:07 -0500

Quoted 7 lines
Quoted 3 lines · David Miller

"unsigned long" is always safe because it is going to be the largest natural word size on the machine, at least as large as a pointer will be.

er... C standard doesn't guarantee this, and I think that Windows in fact has 32-bit longs on machines with 64-bit pointers

I look forward to that MSVC compile of sparc64 GRUB.

Anyways I'm using grub_uint64_t in the current spin of my patches.

You type lawyers win, so let's just drop this.

#9 lore raw
In reply to Isaac Dupree
Quoted 8 lines · Isaac Dupree
Quoted 2 lines

We've been using "unsigned long" for storing virtual addresses in the Linux kernel for 10+ years and it works just fine. :-)

and Linux kernel uses GCC compiler in precise ways

I believe that ptrdiff_t is the proper standardized type for an integer the size of a pointer. except... it's always signed :-)

Quoted 6 lines

Can you just use pointer types and pointer arithmetic?

also, standards aside, a common way to get such a type, is "configure" script testing various possibilities like "unsigned long" and "unsigned long long" and seeing which one is the right size for the target architecture. (not sure if that works when cross-compiling though)

I think we're already using longs this way in quite a few places. It's not such a big deal IMHO.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#10 lore raw
Quoted 11 lines · Robert Millan
Quoted 10 lines · Isaac Dupree
Quoted 2 lines

We've been using "unsigned long" for storing virtual addresses in the Linux kernel for 10+ years and it works just fine. :-)

and Linux kernel uses GCC compiler in precise ways

I believe that ptrdiff_t is the proper standardized type for an integer the size of a pointer. except... it's always signed :-)

Can you just use pointer types and pointer arithmetic?

Quoted 7 lines
Quoted 4 lines

also, standards aside, a common way to get such a type, is "configure" script testing various possibilities like "unsigned long" and "unsigned long long" and seeing which one is the right size for the target architecture. (not sure if that works when cross-compiling though)

I think we're already using longs this way in quite a few places. It's not such a big deal IMHO.

I was considering making grub_size_t long and grub_ssize_t unsigned long. I remember that it required many changes in string formats, so I didn't feel it would be justified. But we could try it again.

Signature · 2 lines
Regards,
Pavel Roskin
#11 lore raw

From: Pavel Roskin <[email protected]>
Date: Fri, 06 Mar 2009 14:03:57 -0500

Quoted 17 lines · Robert Millan
Quoted 16 lines · Isaac Dupree
Quoted 14 lines
Quoted 2 lines

We've been using "unsigned long" for storing virtual addresses in the Linux kernel for 10+ years and it works just fine. :-)

and Linux kernel uses GCC compiler in precise ways

I believe that ptrdiff_t is the proper standardized type for an integer the size of a pointer. except... it's always signed :-)

Can you just use pointer types and pointer arithmetic?

also, standards aside, a common way to get such a type, is "configure" script testing various possibilities like "unsigned long" and "unsigned long long" and seeing which one is the right size for the target architecture. (not sure if that works when cross-compiling though)

Quoted 6 lines
Quoted 2 lines

I think we're already using longs this way in quite a few places. It's not such a big deal IMHO.

I was considering making grub_size_t long and grub_ssize_t unsigned long. I remember that it required many changes in string formats, so I didn't feel it would be justified. But we could try it again.

You should use whatever is the appropriate size_t/ssize_t type on the given platform+ABI, and that way GRUB could use "%Zd" and/or "%zd" throughout. Was that the plan?

#12 lore raw

Quoting David Miller <[email protected]>:

Quoted 7 lines
Quoted 3 lines

I was considering making grub_size_t long and grub_ssize_t unsigned long. I remember that it required many changes in string formats, so I didn't feel it would be justified. But we could try it again.

You should use whatever is the appropriate size_t/ssize_t type on the given platform+ABI, and that way GRUB could use "%Zd" and/or "%zd" throughout. Was that the plan?

No, the plan was to use long. We don't support architectures where long and size_t have different sizes. I'm not aware of such architectures. I don't care about win64, as it would need some very special handling (perhaps redefinition of long).

I was trying to fix an inconsistency of the userspace, where size_t can be unsigned int or unsigned long. Perhaps the plan was too ambitious.

Signature · 2 lines
Regards,
Pavel Roskin
#13 lore raw
Quoted 6 lines · Pavel Roskin

Quoting David Miller <[email protected]>:

Quoted 4 lines
Quoted 3 lines

I was considering making grub_size_t long and grub_ssize_t unsigned long. I remember that it required many changes in string formats, so I didn't feel it would be justified. But we could try it again.

Quoted 8 lines
Quoted 3 lines

You should use whatever is the appropriate size_t/ssize_t type on the given platform+ABI, and that way GRUB could use "%Zd" and/or "%zd" throughout. Was that the plan?

No, the plan was to use long. We don't support architectures where long and size_t have different sizes. I'm not aware of such architectures. I don't care about win64, as it would need some very special handling (perhaps redefinition of long).

Maybe Christian can shred some light on this ;-)

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#14 lore raw

From: Robert Millan <[email protected]>
Date: Sat, 7 Mar 2009 11:38:38 +0100

Quoted 11 lines · Pavel Roskin
Quoted 10 lines

Quoting David Miller <[email protected]>:

Quoted 7 lines
Quoted 3 lines

I was considering making grub_size_t long and grub_ssize_t unsigned long. I remember that it required many changes in string formats, so I didn't feel it would be justified. But we could try it again.

You should use whatever is the appropriate size_t/ssize_t type on the given platform+ABI, and that way GRUB could use "%Zd" and/or "%zd" throughout. Was that the plan?

Quoted 6 lines
Quoted 4 lines

No, the plan was to use long. We don't support architectures where long and size_t have different sizes. I'm not aware of such architectures. I don't care about win64, as it would need some very special handling (perhaps redefinition of long).

Maybe Christian can shred some light on this ;-)

I've checked a lot of cases (other than win64) and this assumption that sizeof(long)==sizeof(size_t) seems to hold.

#15 lore raw
In reply to Robert Millan

From: Robert Millan <[email protected]>
Date: Fri, 6 Mar 2009 19:55:53 +0100

Quoted 11 lines · Isaac Dupree
Quoted 10 lines
Quoted 2 lines

We've been using "unsigned long" for storing virtual addresses in the Linux kernel for 10+ years and it works just fine. :-)

and Linux kernel uses GCC compiler in precise ways

I believe that ptrdiff_t is the proper standardized type for an integer the size of a pointer. except... it's always signed :-)

Can you just use pointer types and pointer arithmetic?

Quoted 7 lines
Quoted 4 lines

also, standards aside, a common way to get such a type, is "configure" script testing various possibilities like "unsigned long" and "unsigned long long" and seeing which one is the right size for the target architecture. (not sure if that works when cross-compiling though)

I think we're already using longs this way in quite a few places. It's not such a big deal IMHO.

And ironically enough, using "unsigned long" would allow us to share this header with any future 32-bit sparc GRUB support.

#16 lore raw
Quoted 6 lines · David Miller
Quoted 3 lines

I think we're already using longs this way in quite a few places. It's not such a big deal IMHO.

And ironically enough, using "unsigned long" would allow us to share this header with any future 32-bit sparc GRUB support.

Are there any GNU/Linux distributions still supporting 32-bit sparc?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."