ack.git
7 years agoUse ha16/lo16 to load or store 1, 2, 8 bytes from labels. zzz-old-reloppc
George Koehler [Tue, 7 Feb 2017 19:55:51 +0000 (14:55 -0500)]
Use ha16/lo16 to load or store 1, 2, 8 bytes from labels.

Add the tokens IND_RL_B, IND_RL_H, IND_RL_H_S, IND_RL_D, along with
the rules to use them.  These rules emit shorter code.  For example,
loading a byte becomes lis, lbz instead of lis, addi, lbz.

While making this, I wrongly set IND_RL_D to size 4.  Then ncg made
infinite recursion in codegen() and stackupto(), until it crashed by
stack overflow.  I correctly set IND_RL_D to size 8, preventing the
crash.

7 years agoTrimming mach/powerpc/ncg/table
George Koehler [Tue, 7 Feb 2017 15:53:04 +0000 (10:53 -0500)]
Trimming mach/powerpc/ncg/table

Remove coercion from LABEL to REG.  The coercion never happens because
I have stopped putting LABEL on the stack.  Also remove LABEL from set
ANY_BHW.  Retain the move from LABEL to REG because pat gto uses it.

Remove li32 instruction, unused after the switch to the hi16, ha16,
lo16 syntax.

Remove COMMENT(...) lines from most moves.  In my opinion, they took
too much space, both in the table and in the assembly output.  The
stacking rules and coercions keep their COMMENT(...)  lines.

In test GPR, don't write to RSCRATCH.

Fold several coercions into a single coercion from ANY_BHW uses REG.

Use REG instead of GPR in stack patterns.  REG and GPR act the same,
because every GPR on the stack is a REG, but I want to be clear that I
expect a REG, not r0.

In code rules, sort SUM_RC before SORT_RR, so I can add SUM_RL later.

Remove rules to optimize loc loc cii loc loc cii.  If $2==$4, the
peephole optimizer can optimize it.  If $2!=$4, then the EM program is
missing a conversion from size $2 to size $4.

Remove rules to store a SEX_B with sti 1 or a SEX_H with sti 2.  These
rules would never get used, unless the EM program is missing a
conversion from size 4 to size 1 or 2.

7 years agoIn PowerPC ncg, allocate register for ha16[label].
George Koehler [Mon, 6 Feb 2017 19:57:25 +0000 (14:57 -0500)]
In PowerPC ncg, allocate register for ha16[label].

Use it to generate code like

    lis r12,ha16[__II0]
    lis r11,ha16[_f]
    lfs f1,lo16[_f](r11)
    lfs f2,lo16[__II0](r12)
    fadds f13,f2,f1
    stfs f13,lo16[_f](r11)

Here ncg has allocated r11 for ha16[_f].  We use r11 in lfs and again
in stfs.  Before this change, we needed an extra lis before stfs,
because ncg did not remember that ha16[_f] was in a register.

This example has a gap between ha16[__II0] and lo16[__II0], because
the lo16 is not in the next instruction.  This requires my previous
commits to allow such a gap.  There is a gap because ncg emits the lis
as soon as I allocate it.  The "lfs f2,lo16[__II0](r12)" happens in a
coercion from IND_RL_W to FSREG.  The coercion allocates one FSREG but
may not allocate any other registers.  So I must allocate r12 earlier.
I allocate r12 in pat lae, but this causes a gap.

7 years agoChange RELOPPC to allow gap between ha16 and lo16.
George Koehler [Mon, 6 Feb 2017 19:17:28 +0000 (14:17 -0500)]
Change RELOPPC to allow gap between ha16 and lo16.

This change breaks old .o files.  The linker will probably (but
perhaps not always) say, "Don't know how to read from PowerPC fixup",
when it encounters a RELOPPC in the old format.

The new format divides the 32-bit value into two parts.  The lower 26
bits encode a signed 26-bit offset from the symbol.  The higher 6 bits
encode the distance (in 1 to 63 instructions) from the hi16 or ha16 to
the lo16.  The old format had a 32-bit offset, but the lo16 needed to
be in the next instruction after the hi16 or ha16.

The assembler fails if an offset is too big for signed 26-bit.  Before
this change, we restricted branch instructions to a signed 26-bit
offset, but now I also restrict hi16 and ha16 instructions.

7 years agoFix two problems with previous commit.
George Koehler [Mon, 6 Feb 2017 18:19:01 +0000 (13:19 -0500)]
Fix two problems with previous commit.

First, I can't use relonami to compare symbols, because relonami
doesn't have different values for different symbols until pass 3.  I
was wrongly pairing a hi16 or ha16 with a different symbol's lo16.
Fix by comparing item pointers.  Hack mach/proto/as/comm7.c to pass
each item pointer to mach/proto/as/mach5.c

Second, I broke hi16[...] and ha16[...] for absolute values.  Fix by
checking hr_head with DOTVAL and DOTTYP.

Having fixed the second problem, I can now switch li32 to use
eval_hl() and emit_hl(), without breaking programs that li32 an
absolute value.

7 years agoIn PowerPC as, keep a list of hi16 and ha16 relocations.
George Koehler [Sat, 4 Feb 2017 16:22:44 +0000 (11:22 -0500)]
In PowerPC as, keep a list of hi16 and ha16 relocations.

Use it to pair hi16 and ha16 relocations with lo16 relocations even if
there are other instructions between them.  For now, the linker still
requires the lo16 in the next instruction.

Code my own linked lists and a bitset because I don't have convenient
libraries for them.  My bitset is an array of 16-bit values, like the
bitsets in ncgg (util/ncgg/set.h), but I also use realloc() to grow
the bitset.

7 years agoUse ha16/lo16 to emit pairs of lis/stw, lis/lfs, lis/stfs.
George Koehler [Thu, 2 Feb 2017 15:48:25 +0000 (10:48 -0500)]
Use ha16/lo16 to emit pairs of lis/stw, lis/lfs, lis/stfs.

A 4-byte load from a label yields a token IND_RL_W.  This token emits
either lis/lwz or lis/lfs, if we want a general-purpose register or a
floating-point register.

7 years agoIn PowerPC as, allow a lonely lo16 without hi16 or ha16.
George Koehler [Thu, 2 Feb 2017 15:35:34 +0000 (10:35 -0500)]
In PowerPC as, allow a lonely lo16 without hi16 or ha16.

The intent is to assemble code like

    lis r3, ha16[_sym]
    lwz r4, lo16[_sym](r3)
    addi r4, r4, 1
    stw r4, lo16[_sym](r3)

7 years agoTweak some tokens in PowerPC ncg.
George Koehler [Wed, 1 Feb 2017 19:29:40 +0000 (14:29 -0500)]
Tweak some tokens in PowerPC ncg.

Remove the GPRINDIRECT token, and use the IND_RC_* tokens as operands
to instructions.  We no longer need to unpack an IND_RC_* token and
repack it as a GPRINDIRECT to use it in an instruction.

Allow storing IND_ALL_B and IND_ALL_H in register variables.  Create a
set ANY_BHW for anything that we can store in a regvar.

Push register variables on the stack without using GPRE, by changing
stwu to accept LOCAL.  Then ncg will replace the string ">>> BUG IN
LOCAL" with the register name.  (I copied ">>> BUG IN LOCAL" from
mach/arm/ncg/table.)

Fix the rule for "pat lil inreg($1)>0" to yield a IND_RC_W token, not
a register.  We might need to kill the token with "kills MEMORY".

Rename CONST_ALL to CONST_STACK, because it only includes constants on
the stack, and excludes CONST tokens.  Instructions still don't allow
CONST_STACK operands, so we still need to repack each CONST_STACK as a
CONST to use it in an instruction.

Rename LABEL_OFFSET_HI to just LABEL_HI, and same for LABEL_HA and
LABEL_HO.

7 years agoIn PowerPC as, check relocations with hi16/ha16/lo16.
George Koehler [Wed, 1 Feb 2017 15:36:06 +0000 (10:36 -0500)]
In PowerPC as, check relocations with hi16/ha16/lo16.

Check that each relocation meets the requirements for RELOPPC, which
handles a hi16/lo16 or ha16/lo16 pair.

In the code, one might confuse hi_token with hl_token and hi_expr with
hl_expr, but I didn't think of better names for these variables.

7 years agoIn PowerPC as, refactor the hi16/ha16/lo16 code.
George Koehler [Tue, 31 Jan 2017 16:35:57 +0000 (11:35 -0500)]
In PowerPC as, refactor the hi16/ha16/lo16 code.

This defers the call to newrelo() until we know the instruction.  In
the future, I might be able to check the instruction's opcode against
the opcodes known to our linker led.

7 years agoRemove #include <stdbool.h> from mach/powerpc/as/mach1.c
George Koehler [Mon, 30 Jan 2017 21:39:23 +0000 (16:39 -0500)]
Remove #include <stdbool.h> from mach/powerpc/as/mach1.c

We should not include a system header file here, because
mach/proto/as/comm2.y goes through cpp twice.  The include can cause
problems like https://github.com/davidgiven/ack/issues/1

Remove this include #<stdbool.h> and leave a comment pointing to the
includes in comm0.h.  Change the few instances of bool, false, true,
to int, 0, 1.

7 years agoRemove type quad, use type word_t in PowerPC as.
George Koehler [Mon, 30 Jan 2017 21:15:02 +0000 (16:15 -0500)]
Remove type quad, use type word_t in PowerPC as.

Type word_t is for encoding the machine instructions.  It only needs
32 bits for PowerPC.  It was long (which can have 32 or 64 bits), and
there was a second type quad (which was uint32_t).  Switch word_t to
uint32_t and replace quad with word_t.

Also change valu_t and ADDR_T away from long.

7 years agoSwap RA and RS when assembling "and", "or", and such instructions.
George Koehler [Mon, 30 Jan 2017 20:47:09 +0000 (15:47 -0500)]
Swap RA and RS when assembling "and", "or", and such instructions.

They must use OP_RA_RS_RB_C instead of OP_RS_RA_RB_C.  The code
generator often sets RS and RA to the same register, so swapping them
causes no change in many programs.

I also rename OP_RS_RA_UI_CC to OP_RA_RS_UI_CC, and OP_RS_RA_C to
OP_RA_RS_C, because they already swap RA and RS.

7 years agoTurn off comments again. I turned them on by accident in c416889.
George Koehler [Mon, 30 Jan 2017 20:45:46 +0000 (15:45 -0500)]
Turn off comments again.  I turned them on by accident in c416889.

7 years agoMerge pull request #49 from kernigh/kernigh-pr-xm
David Given [Thu, 26 Jan 2017 20:21:47 +0000 (21:21 +0100)]
Merge pull request #49 from kernigh/kernigh-pr-xm

PowerPC extended mnemonics

7 years agoIn PowerPC ncg, switch the scratch register from r11 to r0.
George Koehler [Thu, 26 Jan 2017 18:10:08 +0000 (13:10 -0500)]
In PowerPC ncg, switch the scratch register from r11 to r0.

r0 is a special case and can't be used when adding a register to a
constant.  The few remaining users of the scratch register don't do
that.  I removed other usages of the scratch register in 7c64dab,
5b5f77419f0eb8f64b7d8.

7 years agoIn PowerPC top, don't delete addi r0, r0, 0
George Koehler [Thu, 26 Jan 2017 17:44:32 +0000 (12:44 -0500)]
In PowerPC top, don't delete addi r0, r0, 0

Also don't delete addis r0, r0, 0.  These instructions are special
cases that set r0 to zero.  If we delete them, then r0 keeps its old
value.

I caught this bug because osxppc protects the .text segment against
writing.  (linuxppc doesn't protect it.)  A program tried to set r0 to
the NULL pointer, but top deleted the instruction, so r0 kept an old
return address pointing into .text.  Later the program checked that r0
wasn't NULL, tried to write to address r0, and crashed.

7 years agoIn PowerPC libem, remove tge.s and powerpc.h
George Koehler [Thu, 26 Jan 2017 17:39:16 +0000 (12:39 -0500)]
In PowerPC libem, remove tge.s and powerpc.h

Nothing uses the tables in tge.s, after I changed the ncg table.
There are no *.e files in libem, so don't try to build them.

7 years agoRewrite how PowerPC ncg does conditional branches and tests.
George Koehler [Thu, 26 Jan 2017 00:08:55 +0000 (19:08 -0500)]
Rewrite how PowerPC ncg does conditional branches and tests.

The rewritten code rules bring 3 new features:

  1.  The new rules compare a small constant with a register by
      reversing the comparison and using `cmpwi` or `cmplwi`.  The old
      rules put the constant in a register.

  2.  The new rules emit shorter code to yield the test results,
      without referencing the tables in mach/powerpc/ncg/tge.s.

  3.  The new rules use the extended `beq` and relatives, not the
      basic `bc`, in the assembly output.

I delete the old tristate tokens and the old moves, because they
confused me.  Some of the old moves weren't really moves.  For
example, `move R3, C0` and then `move C0, R0` did not move r3 to r0.

I rename C0 to CR0.

7 years agoAdd missing size declarations for 8-byte registers.
George Koehler [Wed, 25 Jan 2017 16:24:23 +0000 (11:24 -0500)]
Add missing size declarations for 8-byte registers.

This fixes the coercion from IND_ALL_D to FREG.  The coercion had
never happened, because IND_ALL_D had 8 bytes but FREG had 4 bytes.
Instead, ncg always stacked the IND_ALL_D and unstacked a FREG.  The
stacking rule uses f0, so the code did load f0 with the indirect
value, push f0 to stack, load f1 to stack, move stack pointer.  Now
that FREG has 8 bytes, ncg does the coercion, and the code just loads
f1 with the indirect value.

7 years agoAdd constraints for pat lab, as done in the m68020 table.
George Koehler [Tue, 24 Jan 2017 16:26:35 +0000 (11:26 -0500)]
Add constraints for pat lab, as done in the m68020 table.

Always use 'kills ALL' when reaching a label, because our registers
and tokens have the wrong values if the program jumps to this label
from somewhere else.

When falling through a label, if the top element is in r3, then
require that the rest of the stack is in the real STACK, not in
registers or tokens.

I'm doing this to be certain that the missing constraints are not
causing bugs.  I did not find any such bug, perhaps because the labels
are usually near other instructions (like conditional branches and
function calls) that stack or kill tokens.

7 years agoUse "kills ALL" instead of a list of killed registers.
George Koehler [Mon, 23 Jan 2017 22:31:29 +0000 (17:31 -0500)]
Use "kills ALL" instead of a list of killed registers.

This is for fef 8 and fif 8.  I changed .fef8 so it no longer kills
r7, but I don't want to update the list.  We already use "kills ALL"
for most other calls to libem.

7 years agoIn PowerPC libem, use the new features of our assembler.
George Koehler [Mon, 23 Jan 2017 22:16:39 +0000 (17:16 -0500)]
In PowerPC libem, use the new features of our assembler.

The new features are the hi16/lo16 and ha16/lo16 syntax for
relocations, and the extended mnemonics like "blr".

Use ha16/lo16 to load some double floats with 2 instructions (lis/lfd)
instead of 3 (lis/ori/lfd).

Use the extended names for branches, comparisons, and bit rotations,
so I can more easily read the code.  The new names often encode the
same machine instructions as the old names, except in a few places
where I changed the instructions.

Stop using andi. when we don't need to set cr0.  In inn.s, I change
andi. to extrwi to extract the same bits.  In los.s and sts.s, I
change "andi. r3, r3, ~3" to "clrrwi r3, r3, 2".  This avoids setting
cr0 and also stops clearing the high 16 bits of r3.

In csa.s, los.s, sts.s, I change some comparisons and right shifts
from signed to unsigned (cmplw, cmplwi, srwi), because the sizes are
unsigned.  In inn.s, the right shift can be signed (sraw) or unsigned
(srw), but I use srw because we don't need the carry bit.

In fef8.s, I save an instruction by using rlwinm instead of addis/andc
to rlwinm to clear a field.  The code no longer kills r7.  In both
fef8.s and fif8.s, I remove the list of killed registers.

Also remove some whitespace from ends of lines.

7 years agoAllow more PowerPC instructions in relocations.
George Koehler [Mon, 23 Jan 2017 21:19:38 +0000 (16:19 -0500)]
Allow more PowerPC instructions in relocations.

I need this for relocations in lis/lfd pairs.  I add lfd along with
addi, lfs, lha, stfs, stfd to the list.

7 years agoFix parameters of signal handlers for linuxppc.
George Koehler [Sun, 22 Jan 2017 05:52:32 +0000 (00:52 -0500)]
Fix parameters of signal handlers for linuxppc.

Linux passes the arguments in registers, but our compiler expects
arguments on the stack.  Signal handlers got garbage instead of the
signal number.  Some handlers, like the one in lang/m2/libm2/sigtrp.c,
need the correct signal number.

I write a "bridge" in PowerPC assembly that moves the arguments to the
stack.  I put the bridge in sigaction(), so I provide a signal() that
calls sigaction().  I remove the *.c glob or wildcard from build.lua,
so linuxppc only compiles its own signal.c, not the other signal.c for
linux386 and linux68k.

My bridge uses sigprocmask(), so I also add sigprocmask().  Because
linux386 and linux68k use globs, they also get sigprocmask().  I sync
the header files so all three Linux platforms declare execve(),
sigprocmask(), and unlink(), but not remove(), because we have
remove() in <stdio.h>.

I am using sigaction.s to test some features that we recently added to
our PowerPC assembler.  These are the "hi16[...]" and "lo16[...]"
syntax, and also the extended names like "beq", "cmpwi", "li", "subi".

7 years agoTeach the assembler about PowerPC extended mnemonics.
George Koehler [Sun, 22 Jan 2017 04:49:29 +0000 (23:49 -0500)]
Teach the assembler about PowerPC extended mnemonics.

Also make a few changes to basic mnemonics.  Fix typo in name of the
basic "creqv".  Add the basic "addc" and relatives, because it would
be odd to have the extended "subc" without "addc".  Fix the basic
"rldicl", "rldicr", "rldic", "rldimi" to correctly encode the 6-bit MB
field.  Fix "slw" and relatives to correctly swap their RA and RS
operands.

Add many, but not all, of the extended mnemonics from IBM's Power ISA
Version 2.06 Book I Appendix E.  (I used 2.06, published 2009, just
because I already had the PDF of it.)  This commit includes mnemonics
for branching, subtraction, traps, bit rotation, and a few others,
like "mflr" and "nop".  The assembler now understands branches like
`beq cr7, label` and bit shifts like `slwi r7, r7, 2`.  These encode
the same machine instructions as the basic "bc" and "rlwinm".

Some operands to basic names become optional.  The assembler no longer
requires the level in "sc" or the branch hint in "bcctr" and "bclr";
they default to zero.  Some extended names take an optional branch
hint or condition register.

Some extended names are still missing.  I don't provide names with
static branch prediction, like "beq+" or "bge-", because the assembler
parses '+' and '-' as operators, not as part of an instruction name.
I also don't provide some names that 2.06 has for moving to or from
the condition register or some special purpose registers, names like
"mtcr" or "mfuamr".

This commit also deletes some unused tokens and one unused yacc rule.

7 years agoMerge pull request #46 from kernigh/kernigh-pr-man
David Given [Thu, 19 Jan 2017 23:06:09 +0000 (00:06 +0100)]
Merge pull request #46 from kernigh/kernigh-pr-man

Tune the installed manual pages.

7 years agoTune the installed manual pages.
George Koehler [Thu, 19 Jan 2017 04:02:30 +0000 (23:02 -0500)]
Tune the installed manual pages.

This commit slightly improves the formatting of the manuals.  My
OpenBSD machine uses mandoc(1) to format manuals.  I check the manuals
with `mandoc -T lint` and fix most of the warnings.  I also make
other changes where mandoc didn't warn me.

roff(7) says, "Each sentence should terminate at the end of an input
line," but we often forgot this rule.  I insert some newlines after
sentences that had ended mid-line.

roff(7) also says that blank lines "are only permitted within literal
contexts."  I delete blank lines.  This removes some extra blank lines
from mandoc's output.  If I do want a blank line in the output, I call
".sp 1" to make it in man(7).  If I want a blank line in the source,
but not the output, I put a plain dot "." so roff ignores it.

Hyphens used for command-line options, like \-a, should be escaped by
a backslash.  I insert a few missing backslashes.

mandoc warns if the date in .TH doesn't look like a date.  Our manuals
had a missing date or the RCS keyword "$Revision$".  Git doesn't
expand RCS keywords.  I put in today's date, 2017-01-18.

Some manuals used tab characters in filled mode.  That doesn't work.
I use .nf to turn off filled mode, or I use .IP in man(7) to make the
indentation without a tab character.

ack(1) defined a macro .SB but never used it, so I delete the
definition.  I also remove a call to the missing macro .RF.

mandoc warns about empty paragraphs.  I deleted them.  mandoc also
warned about these macro pairs in anm(1):

    .SM
    .B text

The .SM did nothing because the .B text is on a different line.  I
changed each pair to .SB for small bold text.

I make a few other small changes.

7 years agoMerge pull request #44 from kernigh/kernigh-pr-as
David Given [Wed, 18 Jan 2017 22:33:40 +0000 (23:33 +0100)]
Merge pull request #44 from kernigh/kernigh-pr-as

mach/proto/as: allow more tokens

7 years agoMerge pull request #45 from davidgiven/dtrg-fixups
David Given [Wed, 18 Jan 2017 19:18:04 +0000 (20:18 +0100)]
Merge pull request #45 from davidgiven/dtrg-fixups

Add hi16[], ha16[], lo16[] support to the PowerPC assembler

7 years agoAdd a man page for the PowerPC assembler (not used anywhere yet).
David Given [Wed, 18 Jan 2017 19:10:16 +0000 (20:10 +0100)]
Add a man page for the PowerPC assembler (not used anywhere yet).

7 years agoClean up the led includes.
David Given [Wed, 18 Jan 2017 18:55:56 +0000 (19:55 +0100)]
Clean up the led includes.

7 years agoAllow more tokens in the assembler.
George Koehler [Wed, 18 Jan 2017 03:41:11 +0000 (22:41 -0500)]
Allow more tokens in the assembler.

I need this so I can add more %token lines to mach/powerpc/as/mach2.c

The assembler's tempfile encoded each token in a byte.  This only
worked with tokens 0 to 127 and 256 and 383.  If a token 384 or higher
existed, the assembler stopped working.  I need tokens 384 and higher.

I change the token encoding to a 2-byte little-endian integer.  I also
change a byte in the string encoding.

7 years agoApply kernigh@'s fix to broken symbol tables in aelflod (via mailing list patch):
David Given [Tue, 17 Jan 2017 23:06:14 +0000 (00:06 +0100)]
Apply kernigh@'s fix to broken symbol tables in aelflod (via mailing list patch):

---snip---
The ELF spec at http://www.sco.com/developers/gabi/ says, "In each
symbol table, all symbols with STB_LOCAL binding precede the weak and
global symbols," and that sh_info is the index of the first non-local
symbol.

I was mixing local and global symbols and setting sh_info to zero. I
also forgot to set the type of the .shstrtab section.
---snip---

7 years agoMerge from default.
David Given [Tue, 17 Jan 2017 23:02:32 +0000 (00:02 +0100)]
Merge from default.

7 years agoUse prototypes in mach/proto/as/comm5.c
George Koehler [Tue, 17 Jan 2017 21:41:29 +0000 (16:41 -0500)]
Use prototypes in mach/proto/as/comm5.c

Order the function prototypes in comm1.h to match the order of the
function definitions in *.c files.

7 years agoAdd a bunch more set operations to the PowerPC backends, and the Pascal test dtrg-pas
David Given [Tue, 17 Jan 2017 21:31:38 +0000 (22:31 +0100)]
Add a bunch more set operations to the PowerPC backends, and the Pascal test
for the same.

7 years agoDelay inclusion of <stdint.h> when compiling comm2.y
George Koehler [Tue, 17 Jan 2017 03:39:44 +0000 (22:39 -0500)]
Delay inclusion of <stdint.h> when compiling comm2.y

See issue #1 (https://github.com/davidgiven/ack/issues/1).  The file
mach/proto/as/comm2.y goes through cpp twice.  The _include macro,
defined in comm2.y and used in comm0.h, delays the inclusion of system
header files.  The inclusion of <stdint.h> wasn't delayed.  This
caused multiple inclusions of <sys/_types.h> in FreeBSD and
<machine/_types.h> in OpenBSD.

Use _include to delay <stdint.h>.  Also use _include for "arch.h" and
"out.h", because h/out.h includes <stdint.h> and h/arch.h might
include it in the future.

Sort the system includes in comm0.h by moving them up to be with
<stdint.h>.  Must include <stdint.h> before "mach0.c", because
mach/powerpc/as/mach0.c needs it.  Must include "mach0.c" before
checking ASLD.

7 years agoRemove some obsolete code that causes a gcc warning.
George Koehler [Mon, 16 Jan 2017 23:09:55 +0000 (18:09 -0500)]
Remove some obsolete code that causes a gcc warning.

In my OpenBSD/amd64 system, the code becomes

    if (0)
        outname.on_valu &= ~(((0xFFFFFFFF)<<32)<<32);

The 0xFFFFFFFF is a 32-bit int, so the left shift by 32 is out of
range and causes the gcc warning.

The intent might be to clear any sign-extended bits, if the assignment
outname.on_valu = valu did sign extension.  Old C had no unsigned
long, so .on_valu would have been long.  The code is obsolete because
h/out.h now declares .on_valu as uint32_t.

7 years agoEnsure that memory is zero-initialised.
David Given [Mon, 16 Jan 2017 21:45:03 +0000 (22:45 +0100)]
Ensure that memory is zero-initialised.

7 years agoFix a buffer overrun that was manifesting on OpenBSD; also fix a bounds check and...
David Given [Mon, 16 Jan 2017 21:44:37 +0000 (22:44 +0100)]
Fix a buffer overrun that was manifesting on OpenBSD; also fix a bounds check and some uninitialised variable problems.

7 years agoRun through clang-format.
David Given [Mon, 16 Jan 2017 20:16:33 +0000 (21:16 +0100)]
Run through clang-format.

7 years agoFix cosmetic warning when compiling B.
David Given [Sun, 15 Jan 2017 22:00:17 +0000 (23:00 +0100)]
Fix cosmetic warning when compiling B.

7 years agoMerge pull request #40 from davidgiven/dtrg-pas
David Given [Sun, 15 Jan 2017 21:56:06 +0000 (22:56 +0100)]
Merge pull request #40 from davidgiven/dtrg-pas

Make Pascal sets work on PowerPC (both ncg and mcg); make Pascal know about 8-bit bytes.

7 years agoAllow the full 8-bit byte range when reading program source.
David Given [Sun, 15 Jan 2017 21:41:11 +0000 (22:41 +0100)]
Allow the full 8-bit byte range when reading program source.

7 years agoRename the test to something more sensible.
David Given [Sun, 15 Jan 2017 21:33:41 +0000 (22:33 +0100)]
Rename the test to something more sensible.

7 years agoIncrease the number of items in a char set from 128 to 256, to cover all
David Given [Sun, 15 Jan 2017 21:30:25 +0000 (22:30 +0100)]
Increase the number of items in a char set from 128 to 256, to cover all
possible bytes (7-bit bytes are so 70s).

7 years agoAdd a test (currently failing) to check that Pascal char sets can store all 256
David Given [Sun, 15 Jan 2017 21:28:14 +0000 (22:28 +0100)]
Add a test (currently failing) to check that Pascal char sets can store all 256
possible values. Add the PowerPC ncg and mcg backend support to let the test
actually run, including modifying a bunch of PowrePC libem functions so that
they can be called from both ncg and mcg.

7 years agoActually tell the user which tests failed.
David Given [Sun, 15 Jan 2017 21:26:09 +0000 (22:26 +0100)]
Actually tell the user which tests failed.

7 years agoAdd missing header.
David Given [Sun, 15 Jan 2017 11:04:47 +0000 (12:04 +0100)]
Add missing header.

7 years agoTurns out Apple's hi16/ha16 exactly match my ha16/has16, so renamed
David Given [Sun, 15 Jan 2017 10:59:33 +0000 (11:59 +0100)]
Turns out Apple's hi16/ha16 exactly match my ha16/has16, so renamed
accordingly. (Memo to self: read the docs *before* doing the work.)

7 years agoSigned vs unsigned lower halves of powerpc fixups are now handled by having two
David Given [Sun, 15 Jan 2017 10:51:37 +0000 (11:51 +0100)]
Signed vs unsigned lower halves of powerpc fixups are now handled by having two
assembler directives, ha16() and has16(), for the upper half; has16() applies
the sign adjustment. .powerpcfixup is now gone, as we generate the relocation
in ha*() instead. Add special logic to the linker for undoing and redoing the
sign adjustment when reading/writing fixups. Tests still pass.

7 years agoRevert change; addis/ori requires different handling to addis/lwz due to ori's
David Given [Sun, 15 Jan 2017 09:31:20 +0000 (10:31 +0100)]
Revert change; addis/ori requires different handling to addis/lwz due to ori's
payload being unsigned while lwz's payload is signed.

7 years agoUpdate the hi/lo syntax to be a bit more standard.
David Given [Sun, 15 Jan 2017 09:21:02 +0000 (10:21 +0100)]
Update the hi/lo syntax to be a bit more standard.

7 years agoAdd assembler support for fixing up arbitrary oris/addi pairs of instructions;
David Given [Sat, 14 Jan 2017 23:15:01 +0000 (00:15 +0100)]
Add assembler support for fixing up arbitrary oris/addi pairs of instructions;
this should allow oris/lwz constant value loads, which will save an opcode.

7 years agoFix typo.
David Given [Sun, 8 Jan 2017 17:53:59 +0000 (18:53 +0100)]
Fix typo.

7 years agoImprove confusing error message when calling function procedures from a
David Given [Sun, 8 Jan 2017 10:25:57 +0000 (11:25 +0100)]
Improve confusing error message when calling function procedures from a
top-level statement.

Fixes: #30

7 years agoRun through clang-format.
David Given [Sun, 8 Jan 2017 10:23:56 +0000 (11:23 +0100)]
Run through clang-format.

7 years agoDon't print source file names during compilation (gcc stopped doing it years
David Given [Sat, 7 Jan 2017 23:16:35 +0000 (00:16 +0100)]
Don't print source file names during compilation (gcc stopped doing it years
ago).

7 years agoRun through clang-format.
David Given [Sat, 7 Jan 2017 23:15:23 +0000 (00:15 +0100)]
Run through clang-format.

7 years agoDon't sort inludes any more (breaks too many ACK files).
David Given [Sat, 7 Jan 2017 23:15:10 +0000 (00:15 +0100)]
Don't sort inludes any more (breaks too many ACK files).

7 years agoMerge pull request #32 from dram/add-execve
David Given [Sat, 7 Jan 2017 22:23:00 +0000 (23:23 +0100)]
Merge pull request #32 from dram/add-execve

Add execve() system call for Linux

7 years agoNo longer truncate module names at 10 characters when constructing paths;
David Given [Sat, 7 Jan 2017 22:00:52 +0000 (23:00 +0100)]
No longer truncate module names at 10 characters when constructing paths;
rename some library modules to their full names.

7 years agoRun through clang-format.
David Given [Sat, 7 Jan 2017 21:56:00 +0000 (22:56 +0100)]
Run through clang-format.

7 years agoProperly install man pages.
David Given [Sat, 7 Jan 2017 21:38:30 +0000 (22:38 +0100)]
Properly install man pages.

7 years agoAdd a B man page.
David Given [Sat, 7 Jan 2017 21:35:02 +0000 (22:35 +0100)]
Add a B man page.

7 years agoUpdate the README.
David Given [Sat, 7 Jan 2017 19:11:01 +0000 (20:11 +0100)]
Update the README.

7 years agoMake sure that constant folding doesn't render our tests trivial.
David Given [Sat, 7 Jan 2017 18:53:57 +0000 (19:53 +0100)]
Make sure that constant folding doesn't render our tests trivial.

7 years agoSections are now aligned (required by the EM spec).
David Given [Sat, 7 Jan 2017 17:47:46 +0000 (18:47 +0100)]
Sections are now aligned (required by the EM spec).

7 years agoFix a bunch of issues with pushing and popping mismatched sizes, which the B
David Given [Sat, 7 Jan 2017 17:47:00 +0000 (18:47 +0100)]
Fix a bunch of issues with pushing and popping mismatched sizes, which the B
compiler does a lot; dup 8 for pairs of words is now optimised.

7 years agoPre-and-post-modification operators now work substantially better (i.e.,
David Given [Sat, 7 Jan 2017 17:46:03 +0000 (18:46 +0100)]
Pre-and-post-modification operators now work substantially better (i.e.,
working).

7 years agoMoved the inc/dec operator tests into their own source file; more exhaustive
David Given [Sat, 7 Jan 2017 17:38:43 +0000 (18:38 +0100)]
Moved the inc/dec operator tests into their own source file; more exhaustive
testing.

7 years agoine and ste are now declared to modify memory (preventing cached values being
David Given [Sat, 7 Jan 2017 12:25:09 +0000 (13:25 +0100)]
ine and ste are now declared to modify memory (preventing cached values being
propagated across the modification).

7 years agoIntroduce sequence points before store instructions to prevent loads from the
David Given [Sat, 7 Jan 2017 12:17:39 +0000 (13:17 +0100)]
Introduce sequence points before store instructions to prevent loads from the
same address being delayed until after the store (at which point they'll return
the wrong value).

7 years agoUse a better NOT; and after remembering that PowerPC bit numbers are all
David Given [Sat, 7 Jan 2017 00:03:15 +0000 (01:03 +0100)]
Use a better NOT; and after remembering that PowerPC bit numbers are all
backwards in the documentation, rewrote IFEQ/IFLT/IFLE to actually work.
Probably. Thanks to the B test suite for spotting this.

7 years agoExtern variables can now be written to.
David Given [Fri, 6 Jan 2017 22:24:05 +0000 (23:24 +0100)]
Extern variables can now be written to.

7 years agoEnsure that procedure labels are word-aligned.
David Given [Fri, 6 Jan 2017 21:29:52 +0000 (22:29 +0100)]
Ensure that procedure labels are word-aligned.

7 years agoAdd execve() system call for Linux
Xin Wang [Fri, 6 Jan 2017 10:33:52 +0000 (18:33 +0800)]
Add execve() system call for Linux

7 years agoFix typo in the descr file which was stopping -B from working. Add B
David Given [Wed, 4 Jan 2017 13:28:40 +0000 (13:28 +0000)]
Fix typo in the descr file which was stopping -B from working. Add B
documentation to the ack man page.

7 years agoAdded an abmodules tool which detects B modules and generates an initialiser
David Given [Tue, 3 Jan 2017 18:54:13 +0000 (18:54 +0000)]
Added an abmodules tool which detects B modules and generates an initialiser
function for them (in C, unfortunately).

7 years agoAdd a control flow test.
David Given [Sun, 1 Jan 2017 23:51:48 +0000 (23:51 +0000)]
Add a control flow test.

7 years agoJump tables for switch now go in ROM (required by the EM spec). Forward gotos
David Given [Sun, 1 Jan 2017 23:28:41 +0000 (23:28 +0000)]
Jump tables for switch now go in ROM (required by the EM spec). Forward gotos
now work.

7 years agoAdd proper support for negative constants in external initialisers.
David Given [Sun, 1 Jan 2017 17:56:53 +0000 (17:56 +0000)]
Add proper support for negative constants in external initialisers.

7 years agoRemove the negative-constant code from the compiler; I think it's going to
David Given [Sun, 1 Jan 2017 17:44:55 +0000 (17:44 +0000)]
Remove the negative-constant code from the compiler; I think it's going to
break a=-1 (with no spaces). Backed out changeset dead3363ac7d.

7 years agoAdd tests for more operators.
David Given [Sun, 1 Jan 2017 17:44:03 +0000 (17:44 +0000)]
Add tests for more operators.

7 years agoAdd support for the ~ operator.
David Given [Sun, 1 Jan 2017 17:40:06 +0000 (17:40 +0000)]
Add support for the ~ operator.

7 years agoAdd support for negative constants in external initialisers.
David Given [Sat, 31 Dec 2016 19:43:03 +0000 (19:43 +0000)]
Add support for negative constants in external initialisers.

7 years agoAllow programs to override binit() (so they can register their own modules).
David Given [Sat, 31 Dec 2016 17:39:51 +0000 (17:39 +0000)]
Allow programs to override binit() (so they can register their own modules).

7 years agoAdd support for B tests; add a test for the B operators (finding several
David Given [Sat, 31 Dec 2016 17:38:52 +0000 (17:38 +0000)]
Add support for B tests; add a test for the B operators (finding several
compiler bugs in the process).

7 years agoAdd support for the xor operator.
David Given [Sat, 31 Dec 2016 17:36:12 +0000 (17:36 +0000)]
Add support for the xor operator.

7 years agoB patch table names shouldn't be in the B symbol namespace.
David Given [Sat, 31 Dec 2016 00:14:28 +0000 (00:14 +0000)]
B patch table names shouldn't be in the B symbol namespace.

7 years agoFix issue where !x was actually calculating !!x.
David Given [Sat, 31 Dec 2016 00:14:04 +0000 (00:14 +0000)]
Fix issue where !x was actually calculating !!x.

7 years agoTrying to install openbios-ppc causes Travis to error out now (not sure why).
David Given [Thu, 29 Dec 2016 17:30:47 +0000 (17:30 +0000)]
Trying to install openbios-ppc causes Travis to error out now (not sure why).

7 years agoAdd a B version of the hilo program.
David Given [Thu, 29 Dec 2016 17:20:51 +0000 (17:20 +0000)]
Add a B version of the hilo program.

7 years agoAdd a declaration for the -Bxyz module name flag, used by the B compiler.
David Given [Thu, 29 Dec 2016 17:12:40 +0000 (17:12 +0000)]
Add a declaration for the -Bxyz module name flag, used by the B compiler.
Rename some of the Basic flags to avoid confusion.

7 years agoFix an issue throughout where B couldn't be built by ackprogram due to symbol
David Given [Thu, 29 Dec 2016 17:11:53 +0000 (17:11 +0000)]
Fix an issue throughout where B couldn't be built by ackprogram due to symbol
laziness.

7 years agoBuild the B compiler and standard library (also the Basic one, which was
David Given [Thu, 29 Dec 2016 17:11:07 +0000 (17:11 +0000)]
Build the B compiler and standard library (also the Basic one, which was
missing).

7 years agoFirst draft of the B module code; a module name can now be specified as a
David Given [Thu, 29 Dec 2016 17:10:21 +0000 (17:10 +0000)]
First draft of the B module code; a module name can now be specified as a
compiler flag, which is used to set the name of the patch table. The compiler
now understands C preprocessor line directives. Extend the standard library
somewhat.

7 years agoChange the i80 assembler to be three-pass, which allows forward references;
David Given [Thu, 29 Dec 2016 17:08:53 +0000 (17:08 +0000)]
Change the i80 assembler to be three-pass, which allows forward references;
required for assembling B.