* Eric W. Biederman <[email protected]> [051113 09:43]:
> I actually a little surprised you don't remember as I think you were
> the one who brought it to the list.  Someone was using the old
> definition which was uint64_t in a 64bit environment and they couldn't
> read the table.
 
Seems I was oblivious yesterday. You are right. Therefore I have
attached a patch to clean up lb_uint64 handling and comment it.

Looks Ok?

Stefan


Index: src/include/boot/linuxbios_tables.h
===================================================================
--- src/include/boot/linuxbios_tables.h (revision 2085)
+++ src/include/boot/linuxbios_tables.h (working copy)
@@ -31,7 +31,41 @@
  * table entries and be backwards compatible, but it is not required.
  */
 
+/* Since LinuxBIOS is usually compiled 32bit, gcc will align 64bit 
+ * types to 32bit boundaries. If the LinuxBIOS table is dumped on a 
+ * 64bit system, a uint64_t would be aligned to 64bit boundaries, 
+ * breaking the table format.
+ *
+ * lb_uint64 will keep 64bit LinuxBIOS table values aligned to 32bit
+ * to ensure compatibility. They can be accessed with the two functions
+ * below: unpack_lb64() and pack_lb64()
+ *
+ * See also: util/lbtdump/lbtdump.c
+ */
 
+struct lb_uint64 {
+       uint32_t lo;
+       uint32_t hi;
+};
+
+static inline uint64_t unpack_lb64(struct lb_uint64 value)
+{
+        uint64_t result;
+        result = value.hi;
+        result = (result << 32) + value.lo;
+        return result;
+}
+
+static inline struct lb_uint64 pack_lb64(uint64_t value)
+{
+        struct lb_uint64 result;
+        result.lo = (value >> 0) & 0xffffffff;
+        result.hi = (value >> 32) & 0xffffffff;
+        return result;
+}
+
+
+
 struct lb_header
 {
        uint8_t  signature[4]; /* LBIO */
@@ -57,10 +91,6 @@
 
 #define LB_TAG_MEMORY  0x0001
 
-struct lb_uint64 {
-       uint32_t lo;
-       uint32_t hi;
-};
 struct lb_memory_range {
        struct lb_uint64 start;
        struct lb_uint64 size;
Index: src/arch/ppc/boot/linuxbios_table.c
===================================================================
--- src/arch/ppc/boot/linuxbios_table.c (revision 2085)
+++ src/arch/ppc/boot/linuxbios_table.c (working copy)
@@ -7,22 +7,6 @@
 #include <device/device.h>
 #include <stdlib.h>
 
-static inline uint64_t unpack_lb64(struct lb_uint64 value) 
-{
-       uint64_t result;
-       result = value.hi;
-       result = (result << 32) + value.lo;
-       return result;
-}
-
-static inline struct lb_uint64 pack_lb64(uint64_t value)
-{
-       struct lb_uint64 result;
-       result.lo = (value >> 0) & 0xffffffff;
-       result.hi = (value >> 32) & 0xffffffff;
-       return result;
-}
-
 struct lb_header *lb_table_init(unsigned long addr)
 {
        struct lb_header *header;
Index: src/arch/i386/boot/linuxbios_table.c
===================================================================
--- src/arch/i386/boot/linuxbios_table.c        (revision 2085)
+++ src/arch/i386/boot/linuxbios_table.c        (working copy)
@@ -7,22 +7,6 @@
 #include <device/device.h>
 #include <stdlib.h>
 
-static inline uint64_t unpack_lb64(struct lb_uint64 value) 
-{
-       uint64_t result;
-       result = value.hi;
-       result = (result << 32) + value.lo;
-       return result;
-}
-
-static inline struct lb_uint64 pack_lb64(uint64_t value)
-{
-       struct lb_uint64 result;
-       result.lo = (value >> 0) & 0xffffffff;
-       result.hi = (value >> 32) & 0xffffffff;
-       return result;
-}
-
 struct lb_header *lb_table_init(unsigned long addr)
 {
        struct lb_header *header;
Index: util/lbtdump/lbtdump.c
===================================================================
--- util/lbtdump/lbtdump.c      (revision 2085)
+++ util/lbtdump/lbtdump.c      (working copy)
@@ -9,14 +9,6 @@
 #include <sys/mman.h>
 #include "../../src/include/boot/linuxbios_tables.h"
 
-static inline uint64_t unpack_lb64(struct lb_uint64 value)
-{
-       uint64_t result;
-       result = value.hi;
-       result = (result << 32) + value.lo;
-       return result;
-}
-
 void print_lb_records(struct lb_record *rec, struct lb_record *last, unsigned 
long addr);
 
 unsigned long compute_checksum(void *addr, unsigned long length)
-- 
LinuxBIOS mailing list
[email protected]
http://www.openbios.org/mailman/listinfo/linuxbios

Reply via email to