[PATCH 0/5] Build openbios on powerpc64 host

This series of patches allows to build openbios on a powerpc64 host. It has been tested with following targets: ppc, sparc32, sparc64. A preliminary patch is needed for fcode-utils, as "toke" is broken on big endan architecture: diff -ru fcode-utils/toke/scanner.c fcode-utils-new/toke/scanner.c --- fcode-utils/toke/scanner.c 2006-10-30 09:48:28.000000000 +0100 +++ fcode-utils-new/toke/scanner.c 2015-10-19 00:21:43.417373690 +0200 @@ -1625,7 +1625,7 @@ void user_message( tic_param_t pfield ) { - char delim = (char)pfield.deflt_elem ; + char delim = (char)pfield.fw_token ; handle_user_message( delim, TRUE); } @@ -5295,7 +5295,7 @@ void process_remark( tic_param_t pfield ) { - char until_char = (char)pfield.deflt_elem ; + char until_char = (char)pfield.fw_token ; unsigned int start_lineno = lineno; #ifdef DEBUG_SCANNER Laurent Vivier (5): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. On ppc64, asm/sigcontext.h includes asm/elf.h On ppc64 host, elf_vrreg_t is defined as __vector128 switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32 config/scripts/switch-arch | 85 ++++++++++++++++++++++++-------------------- include/arch/ppc/elf.h | 4 +++ include/arch/ppc/types.h | 5 +++ include/arch/sparc32/elf.h | 4 +++ include/arch/sparc32/types.h | 13 +++++++ include/arch/sparc64/elf.h | 4 +++ include/arch/sparc64/types.h | 13 +++++++ 7 files changed, 90 insertions(+), 38 deletions(-) -- 2.4.3

Put in two functions code that computes if given architecture is big endian or not, and the size of long (32bit or 64bit). Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- config/scripts/switch-arch | 64 ++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch index 7b8b457..5adaa59 100755 --- a/config/scripts/switch-arch +++ b/config/scripts/switch-arch @@ -17,48 +17,44 @@ if [ x"$1" = x -o "$1" = "-help" ]; then exit 0 fi -crosscflags() +is_bigendian() { - host=$1 - target=$2 - - if test "$host" = "powerpc" -o "$host" = "ppc" \ - -o "$host" = "mips" -o "$host" = "s390" \ - -o "$host" = "sparc32" -o "$host" = "sparc64" \ - -o "$host" = "m68k" -o "$host" = "armv4b"; then - hostbigendian="yes" + cpu=$1 + + if test "$cpu" = "powerpc" -o "$cpu" = "ppc" \ + -o "$cpu" = "powerpc64" -o "$cpu" = "ppc64" \ + -o "$cpu" = "mips" -o "$cpu" = "s390" \ + -o "$cpu" = "sparc32" -o "$cpu" = "sparc64" \ + -o "$cpu" = "m68k" -o "$cpu" = "armv4b"; then + echo yes else - hostbigendian="no" + echo no fi +} -# host long bits test - if test "$host" = "sparc64" -o "$host" = "ia64" \ - -o "$host" = "amd64" -o "$host" = "x86_64" \ - -o "$host" = "alpha"; then - hostlongbits="64" +longbits() +{ + cpu=$1 + if test "$cpu" = "sparc64" -o "$cpu" = "ia64" \ + -o "$cpu" = "amd64" -o "$cpu" = "x86_64" \ + -o "$cpu" = "powerpc64" -o "$cpu" = "ppc64" \ + -o "$cpu" = "alpha"; then + echo 64 else - hostlongbits="32" + echo 32 fi +} - if test "$target" = "powerpc" -o "$target" = "ppc" \ - -o "$target" = "powerpc64" -o "$target" = "ppc64" \ - -o "$target" = "mips" -o "$target" = "s390" \ - -o "$target" = "sparc32" -o "$target" = "sparc64" \ - -o "$target" = "m68k" -o "$target" = "armv4b"; then - targetbigendian="yes" - else - targetbigendian="no" - fi +crosscflags() +{ + host=$1 + target=$2 -# target long bits test - if test "$target" = "sparc64" -o "$target" = "ia64" \ - -o "$target" = "amd64" -o "$target" = "x86_64" \ - -o "$target" = "powerpc64" -o "$target" = "ppc64" \ - -o "$target" = "alpha"; then - targetlongbits="64" - else - targetlongbits="32" - fi + hostbigendian=$(is_bigendian $host) + hostlongbits=$(longbits $host) + + targetbigendian=$(is_bigendian $target) + targetlongbits=$(longbits $target) if test "$targetbigendian" = "$hostbigendian"; then cflags="-USWAP_ENDIANNESS" -- 2.4.3

Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- config/scripts/switch-arch | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch index 5adaa59..2e9d601 100755 --- a/config/scripts/switch-arch +++ b/config/scripts/switch-arch @@ -45,6 +45,19 @@ longbits() fi } +basearch() +{ + arch=$1 + case $arch in + powerpc|ppc64|powerpc64) + echo ppc + ;; + *) + echo $arch + ;; + esac +} + crosscflags() { host=$1 @@ -95,6 +108,7 @@ archname() select_prefix() { + BASEARCH=$(basearch $ARCH) for target_arch ; do TARGETS="${target_arch}-unknown-linux-gnu- ${target_arch}-linux-gnu- ${target_arch}-linux- ${target_arch}-elf- ${target_arch}-eabi-" @@ -109,7 +123,8 @@ select_prefix() return fi done - if [ "$ARCH" = "$HOSTARCH" ]; then + if [ "$BASEARCH" = "$(basearch $HOSTARCH)" ]; then + TARGET="" return fi done @@ -240,7 +255,6 @@ for ARCH in $arch_list; do esac done - BASEARCH=$ARCH case $ARCH in amd64) select_prefix x86_64 @@ -263,7 +277,6 @@ for ARCH in $arch_list; do select_prefix powerpc64 CFLAGS="-Wa,-a64 -m64 -msoft-float -fno-builtin" AS_FLAGS="-Wa,-a64" - BASEARCH=ppc ;; sparc32) -- 2.4.3

asm/sigcontext.h: #ifdef __powerpc64__ #include <asm/elf.h> #endif to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- include/arch/ppc/elf.h | 4 ++++ include/arch/sparc32/elf.h | 4 ++++ include/arch/sparc64/elf.h | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/include/arch/ppc/elf.h b/include/arch/ppc/elf.h index fd2a3f9..5836ae9 100644 --- a/include/arch/ppc/elf.h +++ b/include/arch/ppc/elf.h @@ -1,5 +1,9 @@ +#if defined(__powerpc64__) && defined(BOOTSTRAP) +#include "/usr/include/asm/elf.h" +#else #define ARCH_ELF_CLASS ELFCLASS32 #define ARCH_ELF_DATA ELFDATA2MSB #define ARCH_ELF_MACHINE_OK(x) ((x)==EM_PPC) typedef Elf32_Ehdr Elf_ehdr; typedef Elf32_Phdr Elf_phdr; +#endif diff --git a/include/arch/sparc32/elf.h b/include/arch/sparc32/elf.h index 8d429d7..dd4baf7 100644 --- a/include/arch/sparc32/elf.h +++ b/include/arch/sparc32/elf.h @@ -1,5 +1,9 @@ +#if defined(__powerpc64__) && defined(BOOTSTRAP) +#include "/usr/include/asm/elf.h" +#else #define ARCH_ELF_CLASS ELFCLASS32 #define ARCH_ELF_DATA ELFDATA2MSB #define ARCH_ELF_MACHINE_OK(x) ((x)==EM_SPARC || (x)==EM_SPARC32PLUS) typedef Elf32_Ehdr Elf_ehdr; typedef Elf32_Phdr Elf_phdr; +#endif diff --git a/include/arch/sparc64/elf.h b/include/arch/sparc64/elf.h index 8acad1a..e9da5f9 100644 --- a/include/arch/sparc64/elf.h +++ b/include/arch/sparc64/elf.h @@ -1,5 +1,9 @@ +#if defined(__powerpc64__) && defined(BOOTSTRAP) +#include "/usr/include/asm/elf.h" +#else #define ARCH_ELF_CLASS ELFCLASS64 #define ARCH_ELF_DATA ELFDATA2MSB #define ARCH_ELF_MACHINE_OK(x) ((x)==EM_SPARCV9) typedef Elf64_Ehdr Elf_ehdr; typedef Elf64_Phdr Elf_phdr; +#endif -- 2.4.3

On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it.
That only works for native builds on powerpc64-linux. Is that all that is wanted here? Segher

On 24/10/2015 14:53, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. That only works for native builds on powerpc64-linux. Is that all that is wanted here? Yes, it is.
On a powerpc64 host, when we compile the bootstrap, it includes asm/sigcontext.h, that wants to include asm/elf.h from /usr/include, but instead it includes asm/elf.h from obj-XXX/target/include/. So, I try to include the good one from there. I've modified elf.h for target ppc, sparc32 and sparc64 because I have tried to cross-compile them on a powrpc64 host.
Segher Laurent

On Sat, Oct 24, 2015 at 03:54:13PM +0200, Laurent Vivier wrote:
On 24/10/2015 14:53, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. That only works for native builds on powerpc64-linux. Is that all that is wanted here? Yes, it is.
On a powerpc64 host, when we compile the bootstrap, it includes asm/sigcontext.h, that wants to include asm/elf.h from /usr/include, but
[ The system includes can be elsewhere instead, but you probably do not need to worry about that ].
instead it includes asm/elf.h from obj-XXX/target/include/. So, I try to include the good one from there.
I've modified elf.h for target ppc, sparc32 and sparc64 because I have tried to cross-compile them on a powrpc64 host.
Ah I see, host, not target. Thanks. Segher

On 24/10/2015 16:17, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 03:54:13PM +0200, Laurent Vivier wrote:
On 24/10/2015 14:53, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. That only works for native builds on powerpc64-linux. Is that all that is wanted here? Yes, it is.
On a powerpc64 host, when we compile the bootstrap, it includes asm/sigcontext.h, that wants to include asm/elf.h from /usr/include, but [ The system includes can be elsewhere instead, but you probably do not need to worry about that ].
Yes. The idea here is: if it builds, it's ok.
instead it includes asm/elf.h from obj-XXX/target/include/. So, I try to include the good one from there.
I've modified elf.h for target ppc, sparc32 and sparc64 because I have tried to cross-compile them on a powrpc64 host. Ah I see, host, not target. Thanks.
Segher Thank you for your comments, Laurent

On 24/10/15 13:53, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it.
That only works for native builds on powerpc64-linux. Is that all that is wanted here?
Hmmm that does seem a bit unusual. Is there a better solution for this? Perhaps changing the layout of the OpenBIOS headers to avoid include confusion? ATB, Mark.

On 25/10/2015 12:36, Mark Cave-Ayland wrote:
On 24/10/15 13:53, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. That only works for native builds on powerpc64-linux. Is that all that is wanted here? Hmmm that does seem a bit unusual. Is there a better solution for this? Perhaps changing the layout of the OpenBIOS headers to avoid include confusion? Yes, I agree with you.
There are two solutions here: 1- normally, "#include <...>" searches firstly in system headers, then in "-I" headers, I can seek why it is not the case in the bootstrap case, 2- otherwise, we can change the layout, it was what I tried to do first, but this implies a lot of changes. I'm going to try to find a solution using the first one, feel free to include the other patches from the series if they are ok for you. Laurent

On 25/10/2015 14:14, Laurent Vivier wrote:
On 25/10/2015 12:36, Mark Cave-Ayland wrote:
On 24/10/15 13:53, Segher Boessenkool wrote:
On Sat, Oct 24, 2015 at 11:16:59AM +0200, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. That only works for native builds on powerpc64-linux. Is that all that is wanted here? Hmmm that does seem a bit unusual. Is there a better solution for this? Perhaps changing the layout of the OpenBIOS headers to avoid include confusion? Yes, I agree with you.
There are two solutions here: 1- normally, "#include <...>" searches firstly in system headers, then in "-I" headers, I can seek why it is not the case in the bootstrap case, 2- otherwise, we can change the layout, it was what I tried to do first, but this implies a lot of changes.
I'm going to try to find a solution using the first one, feel free to include the other patches from the series if they are ok for you.
OK, I've a cleaner solution that can replace patches 3/5 and 4/5. I'll resend the series once I'll have tested it on an x86_64 host. Laurent

On Sun, Oct 25, 2015 at 02:14:40PM +0100, Laurent Vivier wrote:
asm/sigcontext.h:
#ifdef __powerpc64__ #include <asm/elf.h> #endif
to avoid to include here target/include/asm/elf.h, hardcode the path to /usr/include/asm/elf.h in it. That only works for native builds on powerpc64-linux. Is that all that is wanted here? Hmmm that does seem a bit unusual. Is there a better solution for this? Perhaps changing the layout of the OpenBIOS headers to avoid include confusion? Yes, I agree with you.
There are two solutions here: 1- normally, "#include <...>" searches firstly in system headers, then in "-I" headers, I can seek why it is not the case in the bootstrap case, 2- otherwise, we can change the layout, it was what I tried to do first, but this implies a lot of changes.
<> searches in the -I path. "" searches in ., the -iquote path, and then the -I path. Maybe OpenBIOS uses -I where it should use -iquote? Segher

so we define __vector128 in arch/*/types.h as we can't include the system asm/types.h Also define __<type> (__u8, __u16, ...), when they are missing. Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- include/arch/ppc/types.h | 5 +++++ include/arch/sparc32/types.h | 13 +++++++++++++ include/arch/sparc64/types.h | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/arch/ppc/types.h b/include/arch/ppc/types.h index 69b3db4..55a979f 100644 --- a/include/arch/ppc/types.h +++ b/include/arch/ppc/types.h @@ -101,4 +101,9 @@ typedef int __s32; typedef long long s64; typedef long long __s64; +#ifdef __powerpc64__ +typedef struct { + __u32 u[4]; +} __attribute__((aligned(16))) __vector128; +#endif #endif diff --git a/include/arch/sparc32/types.h b/include/arch/sparc32/types.h index 3f37d4e..68cee94 100644 --- a/include/arch/sparc32/types.h +++ b/include/arch/sparc32/types.h @@ -81,13 +81,26 @@ typedef uint32_t prom_uarg_t; /* size named types */ typedef unsigned char u8; +typedef unsigned char __u8; typedef unsigned short u16; +typedef unsigned short __u16; typedef unsigned int u32; +typedef unsigned int __u32; typedef unsigned long long u64; +typedef unsigned long long __u64; typedef signed char s8; +typedef signed char __s8; typedef short s16; +typedef short __s16; typedef int s32; +typedef int __s32; typedef long long s64; +typedef long long __s64; +#ifdef __powerpc64__ +typedef struct { + __u32 u[4]; +} __attribute__((aligned(16))) __vector128; +#endif #endif diff --git a/include/arch/sparc64/types.h b/include/arch/sparc64/types.h index a26fccb..86c8fd4 100644 --- a/include/arch/sparc64/types.h +++ b/include/arch/sparc64/types.h @@ -90,13 +90,26 @@ typedef __uint128_t ducell; /* size named types */ typedef unsigned char u8; +typedef unsigned char __u8; typedef unsigned short u16; +typedef unsigned short __u16; typedef unsigned int u32; +typedef unsigned int __u32; typedef unsigned long long u64; +typedef unsigned long long __u64; typedef signed char s8; +typedef signed char __s8; typedef short s16; +typedef short __s16; typedef int s32; +typedef int __s32; typedef long long s64; +typedef long long __s64; +#ifdef __powerpc64__ +typedef struct { + __u32 u[4]; +} __attribute__((aligned(16))) __vector128; +#endif #endif -- 2.4.3

As for powerpc64, only sparc64 compiler is available in the distro (Fedora 22), so use it if is available. The change is the same one as introduced for powerpc64. Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- config/scripts/switch-arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch index 2e9d601..38d263d 100755 --- a/config/scripts/switch-arch +++ b/config/scripts/switch-arch @@ -280,7 +280,7 @@ for ARCH in $arch_list; do ;; sparc32) - select_prefix sparc + select_prefix sparc sparc64 CFLAGS="-Wa,-xarch=v8 -Wa,-32 -m32 -mcpu=supersparc -fno-builtin" AS_FLAGS="-Wa,-xarch=v8 -Wa,-32" ;; -- 2.4.3

On 24/10/15 10:16, Laurent Vivier wrote:
This series of patches allows to build openbios on a powerpc64 host. It has been tested with following targets: ppc, sparc32, sparc64.
A preliminary patch is needed for fcode-utils, as "toke" is broken on big endan architecture:
diff -ru fcode-utils/toke/scanner.c fcode-utils-new/toke/scanner.c --- fcode-utils/toke/scanner.c 2006-10-30 09:48:28.000000000 +0100 +++ fcode-utils-new/toke/scanner.c 2015-10-19 00:21:43.417373690 +0200 @@ -1625,7 +1625,7 @@
void user_message( tic_param_t pfield ) { - char delim = (char)pfield.deflt_elem ; + char delim = (char)pfield.fw_token ; handle_user_message( delim, TRUE); }
@@ -5295,7 +5295,7 @@
void process_remark( tic_param_t pfield ) { - char until_char = (char)pfield.deflt_elem ; + char until_char = (char)pfield.fw_token ; unsigned int start_lineno = lineno;
#ifdef DEBUG_SCANNER
Laurent Vivier (5): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. On ppc64, asm/sigcontext.h includes asm/elf.h On ppc64 host, elf_vrreg_t is defined as __vector128 switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32
config/scripts/switch-arch | 85 ++++++++++++++++++++++++-------------------- include/arch/ppc/elf.h | 4 +++ include/arch/ppc/types.h | 5 +++ include/arch/sparc32/elf.h | 4 +++ include/arch/sparc32/types.h | 13 +++++++ include/arch/sparc64/elf.h | 4 +++ include/arch/sparc64/types.h | 13 +++++++ 7 files changed, 90 insertions(+), 38 deletions(-)
Hi Laurent, Thank you so much for this - we noticed this was broken when testing native PPC during GSoC. I'll take a look further over the next few days. ATB, Mark.

On 25/10/2015 12:34, Mark Cave-Ayland wrote:
On 24/10/15 10:16, Laurent Vivier wrote:
This series of patches allows to build openbios on a powerpc64 host. It has been tested with following targets: ppc, sparc32, sparc64.
A preliminary patch is needed for fcode-utils, as "toke" is broken on big endan architecture:
diff -ru fcode-utils/toke/scanner.c fcode-utils-new/toke/scanner.c --- fcode-utils/toke/scanner.c 2006-10-30 09:48:28.000000000 +0100 +++ fcode-utils-new/toke/scanner.c 2015-10-19 00:21:43.417373690 +0200 @@ -1625,7 +1625,7 @@
void user_message( tic_param_t pfield ) { - char delim = (char)pfield.deflt_elem ; + char delim = (char)pfield.fw_token ; handle_user_message( delim, TRUE); }
@@ -5295,7 +5295,7 @@
void process_remark( tic_param_t pfield ) { - char until_char = (char)pfield.deflt_elem ; + char until_char = (char)pfield.fw_token ; unsigned int start_lineno = lineno;
#ifdef DEBUG_SCANNER
Laurent Vivier (5): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. On ppc64, asm/sigcontext.h includes asm/elf.h On ppc64 host, elf_vrreg_t is defined as __vector128 switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32
config/scripts/switch-arch | 85 ++++++++++++++++++++++++-------------------- include/arch/ppc/elf.h | 4 +++ include/arch/ppc/types.h | 5 +++ include/arch/sparc32/elf.h | 4 +++ include/arch/sparc32/types.h | 13 +++++++ include/arch/sparc64/elf.h | 4 +++ include/arch/sparc64/types.h | 13 +++++++ 7 files changed, 90 insertions(+), 38 deletions(-) Hi Laurent,
Thank you so much for this - we noticed this was broken when testing native PPC during GSoC. I'll take a look further over the next few days. Thank you,
is there way to update source repository ? I can resend the patch inlined, as I did a cut'n'paste in this email. Laurent
participants (3)
-
Laurent Vivier
-
Mark Cave-Ayland
-
Segher Boessenkool