Commit graph

2551 commits

Author SHA1 Message Date
David Given 642956fa2f mcg now uses dataf4 and dataf8 to emit floating point constants, and so doesn't
need flt_arith any more. (And also generates them correctly on little-endian
systems.) as now parses numbers properly, doesn't trash memory all over the
place, and can handle negative numbers.
2018-09-12 23:19:32 +02:00
David Given 8105281534 Make sure li works properly when loading fixed up values which end up as 0. Use
lui rather than li to load high values.
2018-09-12 22:28:40 +02:00
David Given a8df9721d3 Adding new tokens to the assembler isn't quite as easy as I thought: ensure
that NUMBERF is stored properly in the temporary file.
2018-09-12 22:27:39 +02:00
David Given 8379969b6f Fix an unsubtle bug where subtractions were done backwards... 2018-09-11 23:16:50 +02:00
David Given 8230ec42ac Fix a subtle thinko which was causing bits 2-3 of jump targets to be reset. 2018-09-11 23:16:30 +02:00
David Given 0ce368324e Add the bitset helpers. We now have enough helpers for the tests to run (and
massively fail).
2018-09-10 23:37:28 +02:00
David Given 2f8fe3ce6e Do some cleanup; ha16[] and friends can now be used with li. 2018-09-10 23:37:04 +02:00
David Given 3122946a6f Replaced some incorrect hi16s with ha16s. 2018-09-10 23:21:54 +02:00
David Given 008737ed19 Added some more very untested helper functions. 2018-09-10 23:20:52 +02:00
David Given a1747ac916 Add the .dataf4 and .dataf8 directives to the assembler --- manually converting
floats and doubles to bytes is not fun. It might even work!
2018-09-10 22:56:18 +02:00
David Given 53f7de794a Ansify. 2018-09-10 22:55:05 +02:00
David Given 976fa0efca Clang-format before editing. 2018-09-10 22:37:04 +02:00
David Given 6275896a11 Clang-format before editing. 2018-09-10 22:25:14 +02:00
David Given 185e910246 Lots more untested helper functions. 2018-09-10 01:08:25 +02:00
David Given f8f6fa9fc1 Added some more incredibly untested helper functions. 2018-09-10 00:21:16 +02:00
David Given bb15c03339 Remember to preserve input registers if we're going to be reading from them
after writing to the output register.
2018-09-09 18:53:49 +02:00
David Given e88670dad4 Yikes! Turns out that FPU registers are only 32 bits wide, and doubles are
stored in pairs, just like on the PowerPC!
2018-09-09 18:25:00 +02:00
David Given 5dfef6f180 Rework relocations again: add RELO2HI and RELO2HISAD for the high two bytes of
a word.
2018-09-09 14:11:11 +02:00
David Given 95dd6f0141 Fix some niggling issues --- we have our first binary now! 2018-09-09 12:24:22 +02:00
David Given b3b7c684c6 Simplify MIPS relocations. Add RELS2 (for generic high-word relocations). Add
support for MIPS branch-and-jump relocations.
2018-09-09 12:23:59 +02:00
David Given 0d8d98fd0f Warning fix. 2018-09-09 12:22:59 +02:00
David Given d2a1d4dcda Added some very untested csa and csb implementations, based on the PowerPC
ones.
2018-09-08 23:12:57 +02:00
David Given 75308901bc Added hi[] and lo[] functions to the assembler; fix things enough that we now
get to the point of failing to link programs.
2018-09-08 22:42:06 +02:00
David Given 379c1a4a3c Rework floating point conversion. Bash enough of the table into workingness
that the libraries build now.
2018-09-08 22:06:38 +02:00
David Given d2c14ca44f Precisely one stack hreg gets allocated for each vreg/congruence group for
eviction; this prevents us from having to worry about moving values from stack
slot to stack slot, which is hard.
2018-09-08 18:59:55 +02:00
David Given b7a1c96986 MIPS appears to hate converting unsigneds to floats and vice versa. 2018-09-05 23:53:38 +02:00
David Given fc0b0ae178 (Slightly) better errors on phi congruence group mismatches. 2018-09-05 23:53:08 +02:00
David Given 7fbce066f8 We attempt to compile the first library function; we fail. 2018-09-05 00:13:01 +02:00
David Given 26fe3f7530 Added library skeletons. 2018-09-05 00:07:07 +02:00
David Given 26c0228b14 The examples all compile now (probably incorrectly, and the libc doesn't
compile yet).
2018-09-04 23:55:28 +02:00
David Given 9d80756253 Lots of assembler and rule bugfixing. 2018-09-04 23:43:24 +02:00
David Given fe5ca5a85f Added li and la instructions. 2018-09-03 22:47:41 +02:00
David Given 26f9b4ceae Add in floating point support to the code generator. 2018-09-03 22:06:05 +02:00
David Given f8e71d888b Add some painfully untested FPU instructions. 2018-09-02 21:36:09 +02:00
David Given 1d6ecddcf4 The MIPS backend is still full of holes, and cut-and-pasted PowerPC code, but
is beginning to look like an actual code generator.
2018-09-02 18:57:25 +02:00
David Given 4741ed8e14 Add a completely non-tested table-based MIPS assembler. 2018-09-01 19:35:31 +02:00
David Given d623440c77 Add the core of a simple em22 platform. Unfortunately it doesn't work; the old
em libmon vanished decades ago (or never existed), and also ass appears to have
a different idea of what the em opcodes are to everything else and gets
confused.
2018-06-10 20:25:48 +09:00
David Given 911ce7ceb5 Crudely tweak some of the prototypes to please clang, which is pickier about
K&R C than gcc is.
2018-06-02 21:31:18 +02:00
David Given 05ddefad65 Adopt a copy of Minix 2's ed; this allows the ACK's antiquated ed scripts to
run with a minimum of tweaking. Rewriting them for modern ed looks really hard.

Fixes: #84
2018-06-02 18:02:51 +02:00
George Koehler 1df4db99c9 Optimize libfp. Don't lose -O6 in ackcflags.
This drops 124 bytes from the mandelbrot command (from 15015 to 14891
bytes) but has almost no effect on performance; the command takes
about 144 seconds (in YAZE-AG) both before and after optimizing libfp.
2018-04-25 22:48:28 -04:00
George Koehler 93e01eb5d1 Teach i80 ncg to use libfp. Enable ack -mcpm -fp.
Old .o files stop working if they use floating point.  One must
recompile those files.  Old files don't call libfp in the correct way,
and may use symbols that I removed from libem.  I don't keep old
symbols in libem/flp.s, because a program that pulls both libfp and
flp.s would get "multiply defined" errors in the linker.

I teach mach/i80/ncg/table to use libfp by copying or adapting the
patterns from mach/i86/ncg/table.  I did not test all the patterns,
but I did use `ack -mcpm -fp -O4` to compile examples/mandelbrot.c,
then I ran it in the emulator YAZE-AG.  It worked, but it was slow.
2018-04-25 16:09:56 -04:00
George Koehler b9b3428e01 Build (but don't use) libfp for cpm.
This library is for software floating point.  The i80 back end has
never implemented floating point, and might not be ready for libfp.
This commit only builds libfp without using it.

I edit first/build.lua and plat/build.lua to allow `ack -c.s`, then
use FP.script to edit the assembly code.  I edit FP.script so it
writes the edited assembly code to stdout, not to the input file.
2018-04-25 00:34:10 -04:00
David Given aabf0bdd69
Merge pull request #73 from kernigh/kernigh-pr
better code from PowerPC ncg and mcg
2018-03-13 13:57:28 +01:00
George Koehler b1badf1851 Add instructions like "lwarx". Extend manual.
Add more page numbers from PowerPC version 2.01.  Remove "xnop" not in
2.01, add "mtcr" from 2.01.  Add "lwarx" and the other instructions
from Book II.  I did not try all the newly added instructions, but
these seem to work: dcbt, dcbtst, icibi, isync, lwarx, stwcx., mftb,
mftbu

In man/powerpc_as.6 (not installed), add a summary of the registers
and addressing modes (like in i386_as.6), describe short forms, update
description of hi16/ha16, add CAVEATS about instructions that some
processors can't run.
2018-03-07 13:37:31 -05:00
David Given 4b5a7fee14 Made the cgg and the cg code generator work; use this to beat the PDP/11
backend into shape. It now generates binaries --- no idea whether they work or
not.
2018-02-23 22:31:46 +01:00
George Koehler a60738a50d Don't use '-' in option string to getopt().
Using '-' might fail on platforms like FreeBSD.  Commit 50a7031
stopped using '-' in the B compiler and ego.  I now stop using '-' in
mcg, because I can now check that mcg still works.
2018-02-05 14:55:10 -05:00
George Koehler 04ac91889c Only lower "addi sp, sp, X" if X > 0.
If X < 0, then lowering the addi might cause the code to use the stack
space before allocating it.  This is a bug because an asynchronous
signal handler can overwrite the unallocated stack space.
2018-02-01 12:20:31 -05:00
George Koehler 9077b3a5ab Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.

Add or correct some EM instructions in treebuilder.c:
 - "lof", "stf": handle negative offsets in load() and store().
 - "cuu": add using IR_FROMUI.
 - "lim", "sim": keep an entire word in ".ignmask", to be compatible
   with mach/powerpc/libem/trp.s and ncg.  We also keep a word in
   ".ignmask" in ncg for both i386 and m68020.
 - "trp": pass trap number in register.  See comment in
   helper_function_with_arg().
 - "sig": push the old value of .trppc on the stack.
 - "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
   connect to helper functions in libem.
 - "blm", "bls": drop call to memmove() and use new helper ".bls4",
   because tests/plat/structcopy_e.c can't call memmove().
 - "xor s", "cms s": if s is large, fall back on helper function.
 - "rol", "ror": add by decomposing each rotate into 4 IR ops.
 - "rck s", "bls s": make fatal unless s is word size.
 - "loi": push multiple loads in the correct order.
 - "dup s", "exg s": if s is large, fall back on helper.
 - "dus": add using new helper ".dus4".
 - "lxl", "lxa": follow the static chain, not the dynamic chain.
 - "lor 1": materialise the stack before pushing the stack pointer.
 - "lor 2", "str 2": make fatal.
 - "los", "sts": drop calls to memcpy() and use helpers ".los4" and
   and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
 - "gto": correctly read descriptor.

Change mach/powerpc/mcg/table:
 - ANY.L: add for "asp -8".
 - LOAD.L: work around register corruption.
 - COMPAREUL.I: add for "cms 8".
2018-01-31 21:05:40 -05:00
George Koehler 3dae9e49cc Use subfic (val - reg) and mulli (reg * val).
In the instruction list, put /* kills xer */ for sraw, srawi, subfic;
and correct the (now unused) "addi." and "lfdu".

Change MACHOPT_F from -m3 to -m2.  This changes the code for 15 * i
from

    slwi r3,r4,4
    subfic r5,r4,0
    add r3,r3,r5

to

    mulli r3,r4,15

If the sequence "slwi subfic addi" takes 3 cycles and 12 bytes, and
mulli takes 3 cycles and 4 bytes, then mulli is better.
2018-01-27 15:53:05 -05:00
George Koehler 7c9c4f82fd Get ack -mosxppc -g to partly work with gdb.
Copy and adapt code from mach/{i386,m68020}/ncg/mach.c to pass the
debugging stabs from EM to assembly.  The next tools (as, led, cv)
already know how to put the stabs in the Mach-o executable.

Modify the function prolog/prologue so gdb uses fp, not sp, for N_LSYM
and N_PSYM stabs.  Simplify prolog() by reducing differences between
stabs and no stabs, and zero and nonzero framesize.  For files without
stabs, the new prolog has the same number of instructions and memory
accesses as the old prolog, and to run at about the same speed on my
PowerPC Mac.

This is enough to see some info for global and local variables in gdb
for Mac OS X.  I still can't get a backtrace; gdb gets confused
because EM and ncg don't link 0(sp) to the previous stack frame.

I don't expect `ack -mlinuxppc -g` to work with gdb for Linux, because
we prepend underscores to the symbol table, which is correct for
Mach-o but wrong for ELF.
2018-01-26 20:19:38 -05:00