Commit graph

6843 commits

Author SHA1 Message Date
David Given 9b6a5e3ae7 Merge from default. 2016-10-30 15:53:26 +01:00
David Given a5990289a9 Don't allow parallel builds in the top-level makefile. 2016-10-30 15:49:39 +01:00
David Given 613821d771 Old versions of make don't support -r. 2016-10-30 14:28:08 +01:00
David Given 34c4cfee8f Merge pull request #6 from kernigh/pr-linuxppc
PowerPC fixes
2016-10-19 20:39:10 +02:00
George Koehler 99dee0ad24 Remove f14 to f31 from FREG and FSREG.
This would have happened later, if f14 to f31 became regvar (like r13
to r31 are now).  I am doing it now because ncg is too slow for rules
"with FREG FREG uses FREG".  We use such rules for adf 8 and other EM
instructions that operate on 2 floats.  Like my last commit cfbc537,
this commit speeds ncg by removing choices for register allocation.
2016-10-18 21:16:47 -04:00
George Koehler cfbc537959 In powerpc ncg, add a speed hack for sti 8.
ncg is too slow with this many registers.  A stack pattern "with GPR
GPR GPR" or "with REG REG REG" takes too long to pick registers,
causing ncg 8 to take about 2 seconds on each sti 8.  I introduce
REG_PAIR and there are only 4 such pairs.

For programs that use sti 8 (including C programs that copy 8-byte
structs), this speed hack improves the ncg run from several seconds to
almost instantaneous.

Also add a few COMMENT(...) lines in stacking rules.
2016-10-17 20:31:59 -04:00
George Koehler c7b68033ef Add costs to powerpc instructions.
Also show how andi., andis., or., set condition codes.
2016-10-17 14:57:21 -04:00
George Koehler f33b30ed3c Rewrite .fif8 to avoid powerpc64 fctid
This fixes the SIGILL (illegal instruction) in startrek when firing
phasers.  The 32-bit processors in my PowerPC Mac and in QEMU don't
have fctid, a 64-bit instruction.

I got the idea from mach/proto/fp/fif8.c to extract the exponent,
clear some bits to get an integer, then subtract the integer from
the original value to get the fraction.
2016-10-17 00:39:59 -04:00
George Koehler e2ccc8f942 Add "kills MEMORY" to powerpc sti rules.
Adjust some of the loi rules (and associated moves) so we can identify
the tokens that must be in MEMORY.

With this commit, I can navigate the Enterprise even if I comment out
my work-around from e22c888.
2016-10-16 18:13:39 -04:00
George Koehler 19f0eb86a4 Remove IND_LABEL_W and IND_LABEL_D
Because li32 always loads a label into a GPR, it is sufficient to
coerce LABEL to REG, then use IND_RC_W or IND_RC_D for indirection
through the label.
2016-10-16 16:33:24 -04:00
George Koehler 5b5f774a64 Simplify moves to and from IND_RC_*
Now that SUM_RC always has a signed 16-bit constant, it happens that
the various IND_RC_* tokens also have a signed 16-bit constant, so
we no longer need to touch the scratch register.
2016-10-16 16:02:25 -04:00
David Given 486cf9562f Don't need Lua any more. 2016-10-16 20:10:24 +02:00
David Given 1f56bab521 Remember to create the build directory when bootstrapping. 2016-10-16 20:09:52 +02:00
David Given 479a4efa4f Use a self-hosted Lua instead of the system one. 2016-10-16 20:07:54 +02:00
George Koehler 7c64dab491 Refactor how powerpc ncg pushes constants.
When loc (load constant) pushes a constant, it now checks the value of
the constant and pushes any of 7 tokens.  These tokens allow stack
patterns to recognize 16-bit signed integers (CONST2), 16-bit unsigned
integers (UCONST2), multiples of 0x10000 (CONST_HZ), and other
interesting forms of constants.

Use the new constant tokens in the rules for adi, sbi, and, ior, xor.
Adjust a few other rules to understand the new tokens.

Require that SUM_RC has a signed 16-bit constant, and OR_RC and XOR_RC
each have an unsigned 16-bit constant.  The moves from SUM_RC, OR_RC,
XOR_RC to GPR no longer touch the scratch register, because the
constant is not too big.
2016-10-16 13:58:54 -04:00
David Given 714d8985c8 Experiments with declarative apt and OSX. 2016-10-16 18:16:30 +02:00
George Koehler baa152217e Remove unused parts of mach/powerpc/ncg/table
Remove unused tokens GPRINDIRECTLO, HILABEL, LOLABEL, LABELI.  Also
remove an #if 0 ... #endif group of patterns.
2016-10-15 20:00:48 -04:00
George Koehler 29cb008faa In powerpc table, fix macros los() and his().
Change the operator in his() from a - minus to a + plus.  When los(n)
becomes negative, then his(n) needs to add 0x10000, not subtract it.

Also change los(n) to do the sign extension, because smalls(los(n))
should be true, not false.

Also change hi(n) and lo(n) to wrap n in parentheses, as (n), because
these are macros and n might still contain operators.
2016-10-14 23:59:26 -04:00
George Koehler 65c2a8a0ae Remove stackadjust and stackoffset() from ncg.
This feature has never been used since its introduction, more than 3
years ago, in David Given's commit c93cb69 of May 8, 2013.  The commit
was for "PowerPC and M68K work".  I am not undoing the entire commit.
I am only removing the stackadjust and stackoffset() feature.

This commit removes the feature from my branch kernigh-linuxppc.  This
removal includes the mach/proto/ncg parts.  The default branch already
removed most of the feature, but kept the mach/proto/ncg parts.  That
removal happened in commit 81778b6 of May 13, 2013 (which was a merge;
git diff af0dede 81778b6).  The branch dtrg-experimental-powerpc
merged the default branch but without the removal.  That merge was
commit 4703db0f of Sep 15, 2016 (git diff 8c94b13 4703db0).  My branch
kernigh-linuxppc is off branch dtrg-experimental-powerpc, so I can no
longer get the removal by merging default.

David Given described the stackadjust feature in
  https://sourceforge.net/p/tack/mailman/message/30814691/

The instruction stackadjust would add a value to the offset, and the
function stackoffset() would return this offset.  One would use this
to track sp - fp, then omit the frame pointer by not keeping fp in a
register.
2016-10-07 20:52:13 -04:00
George Koehler 409ba7fb1b Remove most of GPRE from mach/powerpc/ncg/table
We only need GPRE in a few places where we write {GPRE, regvar(...)}
because ncgg can't parse plain regvar(...).  In all other places, a
plain GPR works.

Also remove gpr_gpr_gpr and a few other unused and fake instructions
from the list of instructions.
2016-10-06 22:59:27 -04:00
George Koehler 7cccd88b71 Rename SCRATCH to RSCRATCH. Never stack RSCRATCH nor FSCRATCH.
Rename the scratch gpr (currently r11) from SCRATCH to RSCRATCH so I
can search for RSCRATCH without finding FSCRATCH.  I also want to
avoid confusion with the SCRATCH keyword of the old code generator (cg
which came before ncg).

Change the stacking rules to prevent stacking of RSCRATCH or FSCRATCH
or any other GPR or FPR that isn't an allocatable REG or FREG.  Then
ncgg rejects any rule that tries to stack a GPR or FPR, so change such
rules to stack a REG or FREG.
2016-10-06 20:47:42 -04:00
George Koehler 9017ba9dea Merge branch 'default' into kernigh-linuxppc 2016-09-30 13:55:06 -04:00
George Koehler ce5faba919 Remove .linenumber and .filename; use hol0 and hol0+4.
We need this because some .e files in lang/ are using 'loe 0' and 'lae
4' to load the line number from hol0 and filename from hol0+4.
2016-09-30 13:40:36 -04:00
George Koehler b427d33f9f Define the begdata, begrom, begbss symbols for linuxppc.
I copied the definitions from linux386 and linux68k.

This change also moves _errno and the other common symbols in boot.s
from .text to .bss.  Common symbols belong in .bss, but the assembler
seems dumb enough to put them in any section.
2016-09-30 13:21:42 -04:00
George Koehler e22c8881e7 Add a rule for sdl ldl $1==$2 to work around a bug.
In our powerpc table, sdl fails to kill the old value of the local.
This is a bug, because a later ldl can load the old value instead of
the newly stored value.  By rewriting "sdl 0" "ldl 0" as "dup 8" "sdl
0", the newly added rule works around the bug, but only when the ldl
is immediately after the sdl.

This rule improves code that uses double-precision floating point.
The output of printf("%f", 6.0) in C changes from all zero digits to
"6000000" but still doesn't print the decimal point.  The result of
atof("-123.456") becomes correct.  In startrek, I can now move the
Enterprise, but I still can't fire phasers without crashing the game.

We already have a rule for stl lol $1==$2.  We had two copies of the
rule, so I am deleting the second copy.
2016-09-30 11:50:50 -04:00
George Koehler 6ae415d48b Rewrite fef 8 in powerpc assembly.
In EM, fef splits a float into exponent and fraction.  The old C code,
given an infinite float, got stuck in an infinite loop.  The new
assembly code doesn't loop; it extracts the IEEE exponent.
2016-09-29 15:52:54 -04:00
George Koehler a71eee3914 For "pat ass", move fake stack to real stack before adjusting SP.
This fixes code that tried to "addi SP, SP, 4" to drop a value that
was in a register, not on the real stack.

Add a rule to optimize "asp 4" (which becomes "loc 4" "ass") when
the value being dropped is already in a GPR.
2016-09-28 00:13:35 -04:00
George Koehler 1e3dde915a Remove the "invalid" stacking rule.
When ncg fell back on this rule, it did emit the string "invalid" in
the assembly code and caused a syntax error in the assembler.

Adjust the stacking rules so we can stack LOCAL, CONST, and LABEL
without falling back on the "invalid" rule, and so we can stack them
when we have no free register except the scratch register.
2016-09-27 16:46:11 -04:00
George Koehler 865ef629dd Multiple tweaks to plat/linuxppc/descr
Don't define __POWERPC.  I don't know any other compiler that defines
__POWERPC and don't want to invent a new macro.  Apple's gcc 4.0.1
from Xcode 2.5 defines __ppc__, _ARCH_PPC, __POWERPC__.  Debian's gcc
4.9.2-10 defines _ARCH_PPC, __PPC__, __powerpc__, __PPC, __powerpc,
PPC, powerpc.

Move the base vm address from 0x80000000 down to 0x10000000, as this
is where Debian loads /bin/true.  This is still higher than the base
addresses for linux386 and linux68k.

Sync led's arguments with linux386.
2016-09-21 16:26:30 -04:00
David Given bbac1193ff Merge pull request #5 from kernigh/fix-isatty
Implement isatty() for Linux.
2016-09-21 19:47:00 +02:00
George Koehler f6dc6f6875 Implement isatty() for Linux.
If it understands TIOCGETD, then it is a tty, else it isn't one.  This
seems to help Basic's input statement so I can see the prompt before
I enter my input.
2016-09-20 21:28:37 -04:00
George Koehler 5b69777647 Rename our pseudo-opcode 'la' to 'li32'.
GNU as has "la %r4,8(%r3)" as an alias for "addi %r4,%r3,8", meaning
to load the address of the thing at 8(%r3).  Our 'la', now 'li32',
makes an addis/ori pair to load an immediate 32-bit value.  For
example, "li32 r4,23456789" loads a big number.
2016-09-18 17:03:23 -04:00
George Koehler 9db305b338 Enable the Hall check again, and get powerpc to pass it.
Upon enabling the check, mach/powerpc/ncg/table fails to build as ncgg
gives many errors of "Previous rule impossible on empty stack".  David
Given reported this problem in 2013:
  https://sourceforge.net/p/tack/mailman/message/30814694/

Commit c93cb69 commented out the error in util/ncgg/cgg.y to disable
the Hall check.  This commit enables it again.  In ncgg, the Hall
check is checking that a rule is possible with an empty fake stack.
It would be possible if ncg can coerce the values from the real stack
to the fake stack.  The powerpc table defined coercions from STACK to
{FS, %a} and {FD, %a}, but the Hall check didn't understand the
coercions and rejected each rule "with FS" or "with FD".

This commit removes the FS and FD tokens and adds a new group of FSREG
registers for single-precision floats, while keeping FREG registers
for double precision.  The registers overlap, with each FSREG
containing one FREG, because it is the same register in PowerPC
hardware.  FS tokens become FSREG registers and FD tokens become FREG
registers.  The Hall check understands the coercions from STACK to
FSREG and FREG.  The idea to define separate but overlapping registers
comes from the PDP-11 table (mach/pdp/ncg/table).

This commit also removes F0 from the FREG group.  This is my attempt
to keep F0 off the fake stack, because one of the stacking rules uses
F0 as a scratch register (FSCRATCH).
2016-09-18 15:08:55 -04:00
George Koehler 9ec2918e14 In ncgg, increase MAXREGS from 80 to 200.
I need this to add more registers to powerpc.
2016-09-18 14:37:42 -04:00
George Koehler e4ce7da0a2 Fix hilo.p for big-endian platforms.
Unless it is packed, a Pascal char is a C int.  Using C types, hilo.p
passed an int *buf to uread(), which expected a char *buf.  Then
uread() wrote the char on the end of the int.  This worked on
little-endian platforms.  This failed on big-endian platforms, as
writing the value to the big end of an int multiplied it by 16777216.

The fix is to use a packed array [0..0] of char in Pascal.  I also
change 'string' to a packed array, though this is not a necessary part
of the fix.
2016-09-18 00:07:30 -04:00
George Koehler 03b067e1d5 Add the missing .lar4 and .sar4 for powerpc.
Inspired by the sparc code (mach/sparc/libem/lar.s).  My powerpc code
might still have bugs, but it's enough for examples/hilo.mod to work.

May need to 'make clean' or touch a build.lua file, so ackbuilder can
notice the new lar4.s and sar4.s files and build them.
2016-09-17 23:55:55 -04:00
George Koehler ff4a7e3d2a Merge branch 'default' into kernigh-linuxppc 2016-09-17 18:15:54 -04:00
David Given 80cb6ba927 Eliminate the RELOH2 relocation, as it never worked --- the address would be
calculated incorrectly because of overflow errors.

Replace it with an extended RELOPPC relocation which understands addis/ori
pairs; add an la pseudoop to the assembler which generates these and the
appropriate relocation. Make good.

--HG--
branch : dtrg-experimental-powerpc-branch
2016-09-17 12:43:15 +02:00
David Given 45a950571d Mostly add support for the experimental and largely broken linuxppc platform.
(Doesn't quite build.)

--HG--
branch : dtrg-experimental-powerpc-branch
2016-09-15 23:12:03 +02:00
David Given 4703db0fff Merge from default.
--HG--
branch : dtrg-experimental-powerpc-branch
2016-09-15 22:59:01 +02:00
David Given 52ad82f8b9 Merge pull request #3 from kernigh/ego-fix
Fix bugs with memory allocation in ego.
2016-09-10 11:25:21 +02:00
George Koehler b1d1b5e1f8 Fix bugs with memory allocation in ego.
cf/cf_loop.c and share/put.c tried to read the next pointer in an
element of a linked list after freeing the element.  ud/ud_copy.c
tried to read beyond the end of the _defs_ array: it only has
_nrexpldefs_ elements, not _nrdefs_ elements.

These bugs caused core dumps on OpenBSD.  Its malloc() put _defs_ near
the end of a page, so reading beyond the end crossed into an unmapped
page.  Its free() wrote junk bytes and changed the next pointer to
0xdfdfdfdfdfdfdfdf.
2016-09-09 23:37:43 -04:00
David Given 8c94b1316c Add unlink system call. 2016-09-04 19:23:02 +02:00
David Given 56e13e24e0 Cleanup some stray files. 2016-09-03 19:22:38 +02:00
David Given 1b8df04e58 Add modeline, fix formatting. 2016-09-03 19:17:09 +02:00
David Given 95ad06849b Updated. 2016-09-03 19:07:12 +02:00
David Given de2f99dc1a More documentation. 2016-09-03 19:01:47 +02:00
David Given ea4142daee First half of the ackbuilder documentation. 2016-09-03 01:04:16 +02:00
David Given ff9bf5b08a Makefiles are now slightly less inaccurate. Does actually seem to do sensible
incremental builds now. I loathe make.
2016-09-03 00:20:11 +02:00
David Given de7023dd61 Add an install target. 2016-09-02 23:03:57 +02:00