This series of patches allows to build openbios on a powerpc64 host. It has been tested with the following targets: ppc, sparc32, sparc64. It has also been tested on x86_64 host with the same targets.
v2: remove patches 3/5 and 4/5 of the first series and replace it with patch 4/4. We don't include the system includes using full pathname but use '-iquote' intead of '-I'
A preliminary patch is needed for fcode-utils, as "toke" is broken on big endian 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 (4): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32 bootstrap: don't include files from target/include as system includes.
Makefile.target | 2 +- config/scripts/switch-arch | 85 +++++++++++++++++++++++++--------------------- include/arch/ppc/types.h | 8 ----- 3 files changed, 48 insertions(+), 47 deletions(-)
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"
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)
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" ;;
Replace "-I" by "-iquote" to only take files from this directory when '#include "..."' is used ('#include <...>' works as usual)
We need this because on powerpc64 asm/sigcontext.h includes <asm/elf.h> and tries to include target/include/asm/elf.h instead of /usr/include/asm/elf.h
We also remove from include/arch/ppc/types/h some useless and conflicting type definitions.
Signed-off-by: Laurent Vivier laurent@vivier.eu --- Makefile.target | 2 +- include/arch/ppc/types.h | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-)
diff --git a/Makefile.target b/Makefile.target index a7363e6..4c54105 100644 --- a/Makefile.target +++ b/Makefile.target @@ -15,7 +15,7 @@ HOSTCFLAGS+= -Wstrict-aliasing -Wwrite-strings -Wmissing-prototypes -Wnested-ext HOSTCFLAGS+= -W # Flags for dependency generation HOSTCFLAGS+= -MMD -MP -MT $@ -MF '$(*D)/$(*F).d' -HOSTINCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel -I$(SRCDIR)/kernel/include -I$(ODIR)/target/include +HOSTINCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel -I$(SRCDIR)/kernel/include -iquote $(ODIR)/target/include
CC := $(TARGET)gcc AS := $(TARGET)as diff --git a/include/arch/ppc/types.h b/include/arch/ppc/types.h index 69b3db4..b2246d0 100644 --- a/include/arch/ppc/types.h +++ b/include/arch/ppc/types.h @@ -84,21 +84,13 @@ 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;
#endif
On Sun, Oct 25, 2015 at 04:48:53PM +0100, Laurent Vivier wrote:
Replace "-I" by "-iquote" to only take files from this directory when '#include "..."' is used ('#include <...>' works as usual)
Yes :-)
HOSTCFLAGS+= -MMD -MP -MT $@ -MF '$(*D)/$(*F).d' -HOSTINCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel -I$(SRCDIR)/kernel/include -I$(ODIR)/target/include +HOSTINCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel -I$(SRCDIR)/kernel/include -iquote $(ODIR)/target/include
Shouldn't you give these other dirs the same treatment?
Line is long btw, split it (with +=)?
Segher
On 25/10/2015 17:16, Segher Boessenkool wrote:
On Sun, Oct 25, 2015 at 04:48:53PM +0100, Laurent Vivier wrote:
Replace "-I" by "-iquote" to only take files from this directory when '#include "..."' is used ('#include <...>' works as usual)
Yes :-)
HOSTCFLAGS+= -MMD -MP -MT $@ -MF '$(*D)/$(*F).d' -HOSTINCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel -I$(SRCDIR)/kernel/include -I$(ODIR)/target/include +HOSTINCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel -I$(SRCDIR)/kernel/include -iquote $(ODIR)/target/include
Shouldn't you give these other dirs the same treatment?
Perhaps, but I don't want to break anything with useless changes.
Line is long btw, split it (with +=)?
I can do that. If a new version of the series is needed I will.
Thank you for your comments, Laurent
On 25/10/15 15:48, Laurent Vivier wrote:
This series of patches allows to build openbios on a powerpc64 host. It has been tested with the following targets: ppc, sparc32, sparc64. It has also been tested on x86_64 host with the same targets.
v2: remove patches 3/5 and 4/5 of the first series and replace it with patch 4/4. We don't include the system includes using full pathname but use '-iquote' intead of '-I'
A preliminary patch is needed for fcode-utils, as "toke" is broken on big endian 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 (4): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32 bootstrap: don't include files from target/include as system includes.
Makefile.target | 2 +- config/scripts/switch-arch | 85 +++++++++++++++++++++++++--------------------- include/arch/ppc/types.h | 8 ----- 3 files changed, 48 insertions(+), 47 deletions(-)
Hi Laurent,
I've done some tests here on both x86 and PPC hardware and the basic patchset works well here. The only issue I found is that git-am complains about whitespace errors during application - if you could resubmit the series with this fixed, that would be great.
As for the toke fix, I don't know this code particularly well but I can at least confirm that when applied it still produces valid binaries. Could you send a separate patch in "git style" explaining what bug this patch fixes, and if it looks good then I'll apply it too.
Many thanks,
Mark.
Le 01/11/2015 23:46, Mark Cave-Ayland a écrit :
On 25/10/15 15:48, Laurent Vivier wrote:
This series of patches allows to build openbios on a powerpc64 host. It has been tested with the following targets: ppc, sparc32, sparc64. It has also been tested on x86_64 host with the same targets.
v2: remove patches 3/5 and 4/5 of the first series and replace it with patch 4/4. We don't include the system includes using full pathname but use '-iquote' intead of '-I'
A preliminary patch is needed for fcode-utils, as "toke" is broken on big endian 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 (4): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32 bootstrap: don't include files from target/include as system includes.
Makefile.target | 2 +- config/scripts/switch-arch | 85 +++++++++++++++++++++++++--------------------- include/arch/ppc/types.h | 8 ----- 3 files changed, 48 insertions(+), 47 deletions(-)
Hi Laurent,
Hi Mark,
I've done some tests here on both x86 and PPC hardware and the basic patchset works well here. The only issue I found is that git-am complains about whitespace errors during application - if you could resubmit the series with this fixed, that would be great.
Can I have more details, I've tried to "git-am" the patches I have generated and I had no troubles (do you have some git hooks ?)
As for the toke fix, I don't know this code particularly well but I can at least confirm that when applied it still produces valid binaries. Could you send a separate patch in "git style" explaining what bug this patch fixes, and if it looks good then I'll apply it too.
Done
Many thanks,
Mark.
Thanks, Laurent
On 01/11/15 23:19, Laurent Vivier wrote:
Le 01/11/2015 23:46, Mark Cave-Ayland a écrit :
On 25/10/15 15:48, Laurent Vivier wrote:
This series of patches allows to build openbios on a powerpc64 host. It has been tested with the following targets: ppc, sparc32, sparc64. It has also been tested on x86_64 host with the same targets.
v2: remove patches 3/5 and 4/5 of the first series and replace it with patch 4/4. We don't include the system includes using full pathname but use '-iquote' intead of '-I'
A preliminary patch is needed for fcode-utils, as "toke" is broken on big endian 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 (4): switch-arch: factorize code to compute architecture properties. switch-arch: compute base arch and allow native compiler for 32bit and 64bit. switch-arch: as for powerpc64, select sparc64 compiler to compile sparc32 bootstrap: don't include files from target/include as system includes.
Makefile.target | 2 +- config/scripts/switch-arch | 85 +++++++++++++++++++++++++--------------------- include/arch/ppc/types.h | 8 ----- 3 files changed, 48 insertions(+), 47 deletions(-)
Hi Laurent,
Hi Mark,
I've done some tests here on both x86 and PPC hardware and the basic patchset works well here. The only issue I found is that git-am complains about whitespace errors during application - if you could resubmit the series with this fixed, that would be great.
Can I have more details, I've tried to "git-am" the patches I have generated and I had no troubles (do you have some git hooks ?)
As for the toke fix, I don't know this code particularly well but I can at least confirm that when applied it still produces valid binaries. Could you send a separate patch in "git style" explaining what bug this patch fixes, and if it looks good then I'll apply it too.
Done
Hi Laurent,
Thanks a lot for this patchset. After re-applying on a fresh branch, the whitespace errors were gone and everything still passed my local tests so I've pushed the changes to SVN trunk.
This will definitely make testing OpenBIOS on PPC/KVM so much easier in future :)
Many thanks,
Mark.