ack/plat/osxppc
George Koehler 26de4c1ab1 Add test for EM _rck_. Fix traps in PowerPC ncg.
The new test rck_e.e segfaults on PowerPC unless I make some changes.
The inline code for _rck_ was wrong because it didn't allow the trap
handler to return.  _sig_ forgot to push the old trap handler.

Move plat/linuxppc/libsys/trap.s to mach/powerpc/libem/trp.s and
rewrite it with simplified/extended mnemonics.  Remove .trap alias for
.trp procedure.  Add a missing `mtspr lr, r0` so we can return from
the trap handler.  Call write() and _exit() so trp.s works with both
linuxppc and osxppc.  Before, Mac OS X was wrongly using the trap.s
for Linux.

In powerpc/libem, simplify .aar4; teach .csa and .csb to raise the
trap if the default target is zero.

C programs don't need these changes.  You may relink your C programs
with the changed .csa and .csb, but C code doesn't raise the trap.
Modula-2 code can raise traps, so you may want to relink your Modula-2
programs with the changed libem, but you might keep your old .o files
from Modula-2.  You may need to recompile your Pascal programs (delete
old .o files from Pascal) because the Pascal compiler might use _rck_.
2017-12-24 22:37:52 -05:00
..
include Clean up how the language libraries refer to plat headers; they should be using 2016-12-05 21:05:24 +01:00
libsys Add test for EM _rck_. Fix traps in PowerPC ncg. 2017-12-24 22:37:52 -05:00
boot.s Fix my typo to put symbol "begrom" in correct section. 2016-11-19 19:23:42 -05:00
build-pkg.lua Install only 1 copy, not 2 copies, of osx headers. 2016-11-08 17:13:51 -05:00
build-tools.lua Don't share as, ncg, top between Linux and Mac OS X. 2016-12-05 20:13:29 -05:00
descr Fix an issue throughout where B couldn't be built by ackprogram due to symbol 2016-12-29 17:11:53 +00:00
README Write README files for osx386 and osxppc. 2016-12-03 17:17:44 -05:00

The osxppc platform
===================

    ack -mosxppc ...

This platform produces Mach-o executables for PowerPC Mac OS X.  You
can run them from the command line in the Terminal.

You *can't* link to libraries from other compilers.  These static
executables don't use the dynamic linker.  They don't load Apple's
libraries, so they can't call Carbon or Cocoa.

The executables use BSD system calls to interact with your Mac.  Our
libsys provides only a few system calls, enough to run a few demo
programs, but not much else.  Check the header files in ../osx/include
for the available system calls.


Bugs
----

ACK didn't run on Mac OS X when this platform was added.  The only way
to run ack -mosxppc was as a cross compiler from another operating
system.

ACK doesn't have 64-bit integers, but Mac OS X uses 64-bit integers in
its system calls.  Our libsys converts between 32-bit and 64-bit
integers by setting the high bits to zero, or discarding the high
bits.  This affects lseek() and stat().  They report the wrong values
for file sizes and offsets beyond 4 gigabytes.

Our PowerPC code generator is new and probably has bugs.  Its stack
layout and calling conventions are not compatible with other
compilers.  It passes all function arguments on the stack, which is
slower than passing them in registers.


Example
-------
Compile something:

    ack -mosxppc -O6 -o paranoia examples/paranoia.c

The executable has a symbol table.  If you have Apple's Xcode, try

    nm -g paranoia      # to list the global symbols
    otool -hl paranoia  # to check the Mach header and load commands
    gdb paranoia        # to debug it

Within gdb, commands like "gdb main" and "gdb '.ret'" can disassemble
functions.  Backtraces don't work, because our stack layout is not the
same as Apple's.


Other hints
-----------

PowerPC Macs became obsolete after Apple's transition to Intel.  Mac
OS X 10.5 Leopard was the last version to run on PowerPC.  The older
Mac OS X 10.4 Tiger was the last version to include Classic for
running Mac OS 9 programs.  Our ack -mosxppc began to produce
executables in 2016, about 7 years after Apple released Mac OS X 10.6
Snow Leopard for Intel only.

Apple's Xcode included tools like gcc and gdb.  It also had manual
pages for some system calls, like getdirentries(2).  Some system calls
are like FreeBSD, some are unique to OS X.  If you want to learn how
to call write(2) or sigaction(2), then a manual page from another BSD
or Linux might be enough.

Xcode 2.5 was the last version to run on Tiger.  The "Xcode 2.5
Developer Tools" were a 902.9 MB download from Apple.  As of 2016, the
download required an Apple ID and was available at:

    https://developer.apple.com/download/more/

Older versions of Xcode came with Mac OS X.  If your version of OS X
came with your Mac, /Applications/Installers might contain an Xcode
installer.  If you upgraded OS X, your install DVD might have Xcode.

The source code at https://opensource.apple.com/ might reveal more
about system calls.  For 10.4.11.ppc, the kernel is in xnu-792.24.17,
and Libc is in Libc-391.2.10.  These files might help:

    xnu*/bsd/kern/syscalls.master
      master list of BSD system calls
    xnu*/osfmk/kern/syscall_sw.c
      master list of Mach traps
    xnu*/bsd/kern/mach_loader.c
      details about loading Mach-o executables
    xnu*/bsd/dev/ppc/unix_signal.c
      details about sending signals to processes
    xnu*/bsd/sys/*.h
      headers that Xcode installs as /usr/include/sys/*.h
    xnu*/bsd/man/man2/*.2
      manual pages that Xcode installs as /usr/share/man/man2/*.2
    Libc*/ppc/sys/SYS.h
    Libc*/ppc/sys/*.s
      assembly code (in gas syntax) for making system calls

The 10.4.11.ppc sources are wrong for Intel; use 10.4.11.x86 or 10.5
or newer.  10.5 moved SYS.h to xnu*/libsyscall/custom/SYS.h

The kernel maps a common page into every process, and Apple's Libc
uses the common page to speed up system calls like gettimeofday(2).
Our libsys does not use the common page.


George Koehler <xkernigh@netscape.net>
2016-12-03