From ea620f2a4a4968af60e8f5f5acc3b89ed23b347c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 29 Nov 2020 21:15:37 -0700 Subject: [PATCH] Chez Scheme: add PPC Mac OS --- racket/src/ChezScheme/c/Mf-ppc32osx | 32 +++++++++++++++++++ racket/src/ChezScheme/c/Mf-tppc32osx | 5 +++ racket/src/ChezScheme/c/ppc32.c | 5 +++ racket/src/ChezScheme/c/version.h | 14 +++++++-- racket/src/ChezScheme/configure | 10 +++++- racket/src/ChezScheme/mats/Mf-ppc32osx | 14 +++++++++ racket/src/ChezScheme/mats/Mf-tppc32osx | 5 +++ racket/src/ChezScheme/s/Mf-ppc32osx | 6 ++++ racket/src/ChezScheme/s/Mf-ti3osx | 3 +- racket/src/ChezScheme/s/Mf-tppc32osx | 5 +++ racket/src/ChezScheme/s/cmacros.ss | 1 + racket/src/ChezScheme/s/mkheader.ss | 41 +++++++++++++------------ racket/src/ChezScheme/s/ppc32osx.def | 6 ++++ racket/src/ChezScheme/s/tppc32osx.def | 6 ++++ racket/src/ChezScheme/workarea | 4 ++- racket/src/cs/rumble/system.ss | 9 ++++-- 16 files changed, 138 insertions(+), 28 deletions(-) create mode 100644 racket/src/ChezScheme/c/Mf-ppc32osx create mode 100644 racket/src/ChezScheme/c/Mf-tppc32osx create mode 100644 racket/src/ChezScheme/mats/Mf-ppc32osx create mode 100644 racket/src/ChezScheme/mats/Mf-tppc32osx create mode 100644 racket/src/ChezScheme/s/Mf-ppc32osx create mode 100644 racket/src/ChezScheme/s/Mf-tppc32osx create mode 100644 racket/src/ChezScheme/s/ppc32osx.def create mode 100644 racket/src/ChezScheme/s/tppc32osx.def diff --git a/racket/src/ChezScheme/c/Mf-ppc32osx b/racket/src/ChezScheme/c/Mf-ppc32osx new file mode 100644 index 0000000000..e6efbb1a54 --- /dev/null +++ b/racket/src/ChezScheme/c/Mf-ppc32osx @@ -0,0 +1,32 @@ +# Mf-ppc32osx + +m ?= ppc32osx +Cpu ?= PPC32 + +mdinclude = -I/opt/X11/include/ +o = o +mdsrc ?= ppc32.c +mdobj ?= ppc32.o + +.SUFFIXES: +.SUFFIXES: .c .o + +.c.o: + $C -c -D${Cpu} -I${Include} ${zlibInc} ${LZ4Inc} ${mdinclude} $*.c + +include Mf-base + +${KernelO}: ${kernelobj} ${zlibDep} ${LZ4Dep} + ${LD} -r -o ${KernelO} ${kernelobj} ${zlibLib} ${LZ4Lib} + +${KernelLib}: ${kernelobj} + ${AR} ${ARFLAGS} ${KernelLib} ${kernelobj} + +${Scheme}: ${Kernel} ${KernelLinkDeps} ${Main} + $C -o ${Scheme} ${Main} ${Kernel} ${KernelLinkLibs} ${LDFLAGS} ${LIBS} + +../zlib/configure.log: + (cd ../zlib; ${SetConfigEnv} CFLAGS="${CFLAGS}" ./configure) + +../lz4/lib/liblz4.a: ${LZ4Sources} + (cd ../lz4/lib; ${SetConfigEnv} CFLAGS="${CFLAGS}" ${MAKE} liblz4.a) diff --git a/racket/src/ChezScheme/c/Mf-tppc32osx b/racket/src/ChezScheme/c/Mf-tppc32osx new file mode 100644 index 0000000000..2a1a6584ed --- /dev/null +++ b/racket/src/ChezScheme/c/Mf-tppc32osx @@ -0,0 +1,5 @@ +# Mf-tppc32osx + +m ?= tppc32osx + +include Mf-ppc32osx diff --git a/racket/src/ChezScheme/c/ppc32.c b/racket/src/ChezScheme/c/ppc32.c index 6607771e84..1932d3051f 100644 --- a/racket/src/ChezScheme/c/ppc32.c +++ b/racket/src/ChezScheme/c/ppc32.c @@ -54,11 +54,16 @@ void S_doflush(uptr start, uptr end) { } void S_machine_init() { +#if defined(__linux__) if ((l1_dcache_line_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)) <= 0) { l1_dcache_line_size = DEFAULT_L1_MAX_CACHE_LINE_SIZE; } if ((l1_icache_line_size = sysconf(_SC_LEVEL1_ICACHE_LINESIZE)) <= 0) { l1_icache_line_size = DEFAULT_L1_MAX_CACHE_LINE_SIZE; } +#else + l1_dcache_line_size = DEFAULT_L1_MAX_CACHE_LINE_SIZE; + l1_icache_line_size = DEFAULT_L1_MAX_CACHE_LINE_SIZE; +#endif l1_max_cache_line_size = l1_dcache_line_size > l1_icache_line_size ? l1_dcache_line_size : l1_icache_line_size; } diff --git a/racket/src/ChezScheme/c/version.h b/racket/src/ChezScheme/c/version.h index 9285967e8d..c8ed8582c4 100644 --- a/racket/src/ChezScheme/c/version.h +++ b/racket/src/ChezScheme/c/version.h @@ -87,8 +87,16 @@ # define S_ENABLE_CODE_WRITE(on) pthread_jit_write_protect_np(!(on)) #endif +#if (machine_type == machine_type_ppc32osx || machine_type == machine_type_tppc32osx) +# define OS_ANY_MACOSX +# if (machine_type == machine_type_tppc32osx) +# define PTHREADS +# endif +# define FLUSHCACHE +#endif + #if (machine_type == machine_type_pb) -# if defined(__powerpc__) && !defined(__powerpc64__) +# if (defined(__powerpc__) || defined(__POWERPC__)) && !defined(__powerpc64__) # define PORTABLE_BYTECODE_BIGENDIAN # endif # if defined(__linux__) @@ -314,7 +322,9 @@ typedef int tputsputcchar; #define USE_MMAP #define MMAP_HEAP #define IEEE_DOUBLE -#define LITTLE_ENDIAN_IEEE_DOUBLE +#if !defined(__POWERPC__) +# define LITTLE_ENDIAN_IEEE_DOUBLE +#endif #define LDEXP #define ARCHYPERBOLIC #define GETPAGESIZE() getpagesize() diff --git a/racket/src/ChezScheme/configure b/racket/src/ChezScheme/configure index 1ff39ad7d6..abf49efcc4 100755 --- a/racket/src/ChezScheme/configure +++ b/racket/src/ChezScheme/configure @@ -59,6 +59,7 @@ disablex11=no disablecurses=no addflags=yes addwarningflags=no +default_warning_flags="-Wpointer-arith -Wall -Wextra -Werror -Wno-implicit-fallthrough" : ${CC:="gcc"} : ${CPPFLAGS:=""} : ${CFLAGS:=""} @@ -159,6 +160,10 @@ case "${CONFIG_UNAME}" in elif uname -a | egrep 'arm|aarch' > /dev/null 2>&1 ; then m64=arm64osx tm64=tarm6osx + elif uname -a | egrep 'Power' > /dev/null 2>&1 ; then + m64=ppc32osx + tm64=tppc32osx + default_warning_flags="" fi installprefix=/usr/local installmansuffix=share/man @@ -475,7 +480,7 @@ fi optFlags=-O2 if [ "$cflagsset" = "no" -o "$addwarningflags" = "yes" ] ; then - warningFlags="-Wpointer-arith -Wall -Wextra -Werror -Wno-implicit-fallthrough" + warningFlags="$default_warning_flags" else warningFlags="" fi @@ -545,6 +550,9 @@ if [ "$cflagsset" = "no" ] ; then ppc32le|tppc32le) CFLAGS="-m32 ${optFlags}" ;; + ppc32osx|tppc32osx) + CFLAGS="${optFlags}" + ;; esac fi diff --git a/racket/src/ChezScheme/mats/Mf-ppc32osx b/racket/src/ChezScheme/mats/Mf-ppc32osx new file mode 100644 index 0000000000..1ed6c0928c --- /dev/null +++ b/racket/src/ChezScheme/mats/Mf-ppc32osx @@ -0,0 +1,14 @@ +# Mf-ppc32osx + +m ?= ppc32osx + +fsrc = foreign1.c foreign2.c foreign3.c foreign4.c +fobj = foreign1.so + +include Mf-base + +foreign1.so: ${fsrc} ../boot/$m/scheme.h + cc --dynamiclib -undefined dynamic_lookup -I${Include} -o foreign1.so ${fsrc} + +cat_flush: cat_flush.c + cc -o cat_flush cat_flush.c diff --git a/racket/src/ChezScheme/mats/Mf-tppc32osx b/racket/src/ChezScheme/mats/Mf-tppc32osx new file mode 100644 index 0000000000..2a1a6584ed --- /dev/null +++ b/racket/src/ChezScheme/mats/Mf-tppc32osx @@ -0,0 +1,5 @@ +# Mf-tppc32osx + +m ?= tppc32osx + +include Mf-ppc32osx diff --git a/racket/src/ChezScheme/s/Mf-ppc32osx b/racket/src/ChezScheme/s/Mf-ppc32osx new file mode 100644 index 0000000000..90e504a865 --- /dev/null +++ b/racket/src/ChezScheme/s/Mf-ppc32osx @@ -0,0 +1,6 @@ +# Mf-ppc32osx + +m ?= ppc32osx +archincludes = ppc32.ss + +include Mf-base diff --git a/racket/src/ChezScheme/s/Mf-ti3osx b/racket/src/ChezScheme/s/Mf-ti3osx index 20da12fdfe..a83bd3feb0 100644 --- a/racket/src/ChezScheme/s/Mf-ti3osx +++ b/racket/src/ChezScheme/s/Mf-ti3osx @@ -14,6 +14,5 @@ # limitations under the License. m = ti3osx -archincludes = x86.ss -include Mf-base +include Mf-i3osx diff --git a/racket/src/ChezScheme/s/Mf-tppc32osx b/racket/src/ChezScheme/s/Mf-tppc32osx new file mode 100644 index 0000000000..56b001c5d7 --- /dev/null +++ b/racket/src/ChezScheme/s/Mf-tppc32osx @@ -0,0 +1,5 @@ +# Mf-tppc32osx + +m = tppc32osx + +include Mf-ppc32osx diff --git a/racket/src/ChezScheme/s/cmacros.ss b/racket/src/ChezScheme/s/cmacros.ss index b29fe30585..d8eb39ce8a 100644 --- a/racket/src/ChezScheme/s/cmacros.ss +++ b/racket/src/ChezScheme/s/cmacros.ss @@ -395,6 +395,7 @@ ppc32le tppc32le arm64le tarm64le arm64osx tarm64osx + ppc32osx tppc32osx ) (include "machine.def") diff --git a/racket/src/ChezScheme/s/mkheader.ss b/racket/src/ChezScheme/s/mkheader.ss index e1e31417e0..8f78513d22 100644 --- a/racket/src/ChezScheme/s/mkheader.ss +++ b/racket/src/ChezScheme/s/mkheader.ss @@ -652,9 +652,12 @@ (pr " : \"r\" (addr) \\~%") (pr " : \"flags\", \"memory\")~%")))] [(ppc32) + (let ([reg (constant-case machine-type-name + [(ppc32osx tppc32osx) ""] + [else "%%"])]) (pr "#define INITLOCK(addr) \\~%") - (pr " __asm__ __volatile__ (\"li %%r0, 0\\n\\t\"\\~%") - (pr " \"stw %%r0, 0(%0)\\n\\t\"\\~%") + (pr " __asm__ __volatile__ (\"li ~ar0, 0\\n\\t\"\\~%" reg) + (pr " \"stw ~ar0, 0(%0)\\n\\t\"\\~%" reg) (pr " : \\~%") (pr " : \"b\" (addr)\\~%") (pr " :\"memory\", \"r0\")~%") @@ -662,16 +665,16 @@ (nl) (pr "#define SPINLOCK(addr) \\~%") (pr " __asm__ __volatile__ (\"0:\\n\\t\"\\~%") ; top: - (pr " \"lwarx %%r0, 0, %0\\n\\t\"\\~%") ; start lock acquisition - (pr " \"cmpwi %%r0, 0\\n\\t\"\\~%") ; see if someone already owns the lock + (pr " \"lwarx ~ar0, 0, %0\\n\\t\"\\~%" reg) ; start lock acquisition + (pr " \"cmpwi ~ar0, 0\\n\\t\"\\~%" reg) ; see if someone already owns the lock (pr " \"bne 1f\\n\\t\"\\~%") ; if so, go to our try_again loop - (pr " \"li %%r0, 1\\n\\t\"\\~%") ; attempt to store the value 1 - (pr " \"stwcx. %%r0, 0, %0\\n\\t\"\\~%") ; + (pr " \"li ~ar0, 1\\n\\t\"\\~%" reg) ; attempt to store the value 1 + (pr " \"stwcx. ~ar0, 0, %0\\n\\t\"\\~%" reg); (pr " \"beq 2f\\n\\t\"\\~%") ; if we succeed, we own the lock (pr " \"1:\\n\\t\"\\~%") ; again: (pr " \"isync\\n\\t\"\\~%") ; sync things to pause the processor - (pr " \"lwz %%r0, 0(%0)\\n\\t\"\\~%") ; try a non-reserved load to see if we are likely to succeed - (pr " \"cmpwi %%r0, 0\\n\\t\"\\~%") ; if it is = 0, try to acquire at start + (pr " \"lwz ~ar0, 0(%0)\\n\\t\"\\~%" reg) ; try a non-reserved load to see if we are likely to succeed + (pr " \"cmpwi ~ar0, 0\\n\\t\"\\~%" reg) ; if it is = 0, try to acquire at start (pr " \"beq 0b\\n\\t\"\\~%") ; (pr " \"b 1b\\n\\t\"\\~%") ; othwerise loop through the try again (pr " \"2:\\n\\t\"\\~%") ; done: @@ -681,8 +684,8 @@ (nl) (pr "#define UNLOCK(addr) \\~%") - (pr " __asm__ __volatile__ (\"li %%r0, 0\\n\\t\"\\~%") - (pr " \"stw %%r0, 0(%0)\\n\\t\"\\~%") + (pr " __asm__ __volatile__ (\"li ~ar0, 0\\n\\t\"\\~%" reg) + (pr " \"stw ~ar0, 0(%0)\\n\\t\"\\~%" reg) (pr " : \\~%") (pr " : \"b\" (addr)\\~%") (pr " :\"memory\", \"r0\")~%") @@ -691,11 +694,11 @@ (pr "#define LOCKED_INCR(addr, ret) \\~%") (pr " __asm__ __volatile__ (\"li %0, 0\\n\\t\"\\~%") (pr " \"0:\\n\\t\"\\~%") - (pr " \"lwarx %%r12, 0, %1\\n\\t\"\\~%") - (pr " \"addi %%r12, %%r12, 1\\n\\t\"\\~%") - (pr " \"stwcx. %%r12, 0, %1\\n\\t\"\\~%") + (pr " \"lwarx ~ar12, 0, %1\\n\\t\"\\~%" reg) + (pr " \"addi ~ar12, ~ar12, 1\\n\\t\"\\~%" reg reg) + (pr " \"stwcx. ~ar12, 0, %1\\n\\t\"\\~%" reg) (pr " \"bne 0b\\n\\t\"\\~%") - (pr " \"cmpwi %%r12, 0\\n\\t\"\\~%") + (pr " \"cmpwi ~ar12, 0\\n\\t\"\\~%" reg) (pr " \"bne 1f\\n\\t\"\\~%") (pr " \"li %0, 1\\n\\t\"\\~%") (pr " \"1:\\n\\t\"\\~%") @@ -707,17 +710,17 @@ (pr "#define LOCKED_DECR(addr, ret) \\~%") (pr " __asm__ __volatile__ (\"li %0, 0\\n\\t\"\\~%") (pr " \"0:\\n\\t\"\\~%") - (pr " \"lwarx %%r12, 0, %1\\n\\t\"\\~%") - (pr " \"addi %%r12, %%r12, -1\\n\\t\"\\~%") - (pr " \"stwcx. %%r12, 0, %1\\n\\t\"\\~%") + (pr " \"lwarx ~ar12, 0, %1\\n\\t\"\\~%" reg) + (pr " \"addi ~ar12, ~ar12, -1\\n\\t\"\\~%" reg reg) + (pr " \"stwcx. ~ar12, 0, %1\\n\\t\"\\~%" reg) (pr " \"bne 0b\\n\\t\"\\~%") - (pr " \"cmpwi %%r12, 0\\n\\t\"\\~%") + (pr " \"cmpwi ~ar12, 0\\n\\t\"\\~%" reg) (pr " \"bne 1f\\n\\t\"\\~%") (pr " \"li %0, 1\\n\\t\"\\~%") (pr " \"1:\\n\\t\"\\~%") (pr " : \"=&r\" (ret)\\~%") (pr " : \"r\" (addr)\\~%") - (pr " : \"cc\", \"memory\", \"r12\")~%")] + (pr " : \"cc\", \"memory\", \"r12\")~%"))] [(arm32) (pr "#define INITLOCK(addr) \\~%") (pr " __asm__ __volatile__ (\"mov r12, #0\\n\\t\"\\~%") diff --git a/racket/src/ChezScheme/s/ppc32osx.def b/racket/src/ChezScheme/s/ppc32osx.def new file mode 100644 index 0000000000..e8a3815b5a --- /dev/null +++ b/racket/src/ChezScheme/s/ppc32osx.def @@ -0,0 +1,6 @@ +;;; ppc32osx.def + +(define-constant machine-type (constant machine-type-ppc32osx)) +(features iconv expeditor) +(include "ppc32.def") +(include "default.def") diff --git a/racket/src/ChezScheme/s/tppc32osx.def b/racket/src/ChezScheme/s/tppc32osx.def new file mode 100644 index 0000000000..56123ee3f6 --- /dev/null +++ b/racket/src/ChezScheme/s/tppc32osx.def @@ -0,0 +1,6 @@ +;;; tppc32le.def + +(define-constant machine-type (constant machine-type-tppc32osx)) +(features iconv expeditor pthreads) +(include "ppc32.def") +(include "default.def") diff --git a/racket/src/ChezScheme/workarea b/racket/src/ChezScheme/workarea index 86c5c3e9c1..5e2fadceed 100755 --- a/racket/src/ChezScheme/workarea +++ b/racket/src/ChezScheme/workarea @@ -65,6 +65,7 @@ case "$Mhost" in i3qnx) ;; i3s2) ;; ppc32le) ;; + ppc32osx) ;; ta6fb) Muni=a6fb ;; ta6le) Muni=a6le ;; ta6nb) Muni=a6nb ;; @@ -84,6 +85,7 @@ case "$Mhost" in ti3qnx) Muni=i3qnx ;; ti3s2) Muni=i3s2 ;; tppc32le) Muni=ppc32le ;; + tppc32osx) Muni=ppc32osx ;; *) echo "Unrecognized machine name $Mhost"; exit 1 ;; esac @@ -113,7 +115,7 @@ case "$Muniarch" in i3qnx) March=i3 ;; i3s2) March=i3 ;; ppc32le) March=ppc32 ;; - pb) March=pb ;; + ppc32osx) March=ppc32 ;; *) March="" ;; esac diff --git a/racket/src/cs/rumble/system.ss b/racket/src/cs/rumble/system.ss index 6987ec6b72..091771814d 100644 --- a/racket/src/cs/rumble/system.ss +++ b/racket/src/cs/rumble/system.ss @@ -19,7 +19,7 @@ (define os-symbol (case (machine-type) - [(a6osx ta6osx i3osx ti3osx arm64osx tarm64osx) + [(a6osx ta6osx i3osx ti3osx arm64osx tarm64osx ppc32osx tppc32osx) (if unix-style-macos? 'unix 'macosx)] [(a6nt ta6nt i3nt ti3nt) 'windows] [else 'unix])) @@ -28,7 +28,8 @@ (case (machine-type) [(a6osx ta6osx i3osx ti3osx - arm64osx tarm64osx) + arm64osx tarm64osx + ppc32osx tppc32osx) (if unix-style-macos? 'darwin 'macosx)] @@ -63,7 +64,9 @@ 'i386] [(arm32le tarm32le) 'arm] [(arm64le tarm64le arm64osx tarm64osx) 'aarch64] - [(ppc32le tppc32le) 'ppc] + [(ppc32le tppc32le + ppc32osx tppc32osx) + 'ppc] [else (error 'system-type "internal error: unknown architecture")])) (define link-symbol