Commit graph

2679 commits

Author SHA1 Message Date
David Given 92b3dfb42c Apparently Windows doesn't have strndup or index. 2022-07-17 00:47:49 +02:00
David Given 44fc125b1a Remove signals. 2022-07-16 23:52:41 +02:00
David Given 25b6712e63 Rework all the ackbuilder scripts not to use wildcards, because we can't expand
them without luaposix, which isn't available (easily) on OSX or Windows.
2022-07-14 23:57:54 +02:00
David Given 8b0a3ac473 Attempt to make work on OSX, and update the build matrix. 2022-06-20 00:18:16 +02:00
Tee-Kiah Chia ceca019493 mach/i86/libem/csb4.s: fix incorrect i86 code for switch (long)
Fixes https://github.com/davidgiven/ack/issues/240
2022-01-17 19:29:56 +00:00
Tee-Kiah Chia 64a74b4e09 Add .seek asm pseudo-op, advances location counter to fixed offset
The new .seek assembler pseudo-op advances the location
counter to a fixed offset within a section --- or to a fixed
address, if the section is a .base'd section.  It works
somewhat like the GNU assembler's .org pseudo-op, though
with a hopefully less confusing name.

This pseudo-op lets us avoid having to manually compute the
needed boot sector padding in the pc86 start-up code
plat/pc86/boot.s .
2021-03-19 13:36:24 +00:00
George Koehler 7ab4794a05 Reduce clang warnings from ncg
If a .c file included "types.h" before "mach.h", then it missed the
declaration of mach_option().  Fix by adding "xmach.h".

Fix mach/powerpc/ncg/mach.h and mach/vc4/ncg/mach.h to use the correct
type in their printf() format strings.
2019-10-30 18:36:55 -04:00
George Koehler 0576641cae Reduce clang warnings from top
Also add `static` and remove `register` in mach/proto/top/top.c.  A
static function is only in one file, so its function declaration may
go in that file, instead of a header file.
2019-10-30 18:36:55 -04:00
George Koehler 51e34acab1 Add a syntax to declare functions in a top table
Use the new syntax in the mips, pdp, powerpc tables to declare
functions before calling them.  These declarations prevent compiler
warnings about implicitly declaring functions.  They also provide
prototypes of the function parameters.

Also fix a warning in the powerpc table: use `bsearch(...) != NULL` to
avoid converting the pointer from bsearch() to an int.

The syntax for topgen is a block `{...}` among the parameters in the
top table.  It looks like the syntax of LLgen, but topgen doesn't
allow nested blocks, so declarations like `struct whatever {...};`
don't work.  The token OPEN_BRACKET that begins a declaration_block
doesn't conflict with the LETTER that begins a parameter_line or the
'%' that begins a separator.

Because a block writes a #line command to gen.h, a parameter line now
also writes a #line command to gen.h, so it doesn't get a wrong line
number from a previous block.
2019-10-30 18:36:55 -04:00
George Koehler 36f16b0cb8 Cut down some clang warnings
Edit C code to reduce warnings from clang.  Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().

Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c.  Such changes don't silence warnings; I make
such changes while I silence warnings in the same file.  In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.

Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning.  I wrongly added the `const` in d347207.

For warnings about implicit declarations of functions, the fix is to
declare the function before calling it.  For example, my OpenBSD
system needs <sys/wait.h> to declare wait().

In util/int, add "whatever.h" to declare more functions.  Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
2019-10-30 18:36:38 -04:00
George Koehler a434749fd9 Widen valu_t in the assembler to 64 bits.
Most machines had undefined valu_t and redefined it to a different
type.  Edit mach/*/as/mach0.c to remove such redefinitions, so the
next change to valu_t will affect all machines.

Edit mach/proto/as/comm0.h to change valu_t to int64_t, and add
uvalu_t and uint64_t.

Remove int64_t y_valu8 from the yacc %union, now that valu_t y_valu
can hold 64 bits.  Replace y_valu8 with y_valu.  The .data8 pseudo
becomes less special; it now accepts absolute expressions.

This change simplifies the assembler and seems to have no effect on
the assembled output.  Among the files in share/ack/examples, the only
changes are in hilo_bas.* and startrek_c.linuxppc, but those files
seem to change whenever I rebuild them.
2019-10-04 18:58:56 -04:00
George Koehler 0b0c3d5b60 Add csa 8, csb 8 for i386, m68020.
This allows `long long x; switch (x) {...}` in C.  Add test in C.

This adapts the code for csa 8 and csb 8 from the existing code for
csa 4 and csb 4, for both i386 and m68020.
2019-09-27 12:15:10 -04:00
George Koehler bbaed6bdba Edit i386 rules for 8-byte shift, conversion.
Shifts that drop an EM word don't need to coerce the word to REG.
Some arithmetic right shifts can use _cdq_.

Drop rules for illegal integer conversions.  Sizes below a word are
illegal in EM, except as the source size of _cii_.
2019-09-25 12:29:41 -04:00
George Koehler e867861f6d Add 8-byte long long for linux68k.
Add rules for 8-byte integers to m68020 ncg.  Add 8-byte long long to
ACK C on linux68k.  Enable long-long tests for linux68k.  The tests
pass in our emulator using musahi; I don't have a real 68k processor
and haven't tried other emulators.

Still missing are conversions between 8-byte integers and any size of
floats.  The long-long tests don't cover these conversions, and our
emulator can't do floating-point.

Our build always enables TBL68020 and uses word size 4.  Without
TBL68020, 8-byte multiply and divide are missing.  With word size 2,
some conversions between 2-byte and 8-byte integers are missing.

Fix .cii in libem, which didn't work when converting from 1-byte or
2-byte integers.  Now .cii and .cuu work, but also add some rules to
skip .cii and .cuu when converting 8-byte integers.  The new rule for
loc 4 loc 8 cii `with test_set4` exposes a bug: the table may believe
that the condition codes test a 4-byte register when they only test a
word or byte, and this incorrect test may describe an unsigned word or
byte as negative.  Another rule `with exact test_set1+test_set2` works
around the bug by ignoring the negative flag, because a zero-extended
word or byte is never negative.

The old rules for comparison and logic do work with 8-byte integers
and bitsets, but add some specific 8-byte rules to skip libem calls or
loops.  There were no rules for 8-byte arithmetic, shift, or rotate;
so add some.  There is a register shortage, because the table requires
preserving d3 to d7, leaving only 3 data registers (d0, d1, d2) for
8-byte operations.  Because of the shortage, the code may move data to
an address register, or read a memory location more than once.

The multiplication and division code are translations of the i386
code.  They pass the tests, but might not give the best performance on
a real 68k processor.
2019-09-24 13:32:17 -04:00
George Koehler fd27acb487 Fix assembly of bfffo d1[0:32], d3
The assembler wrongly defined _bfexts_ and _bfffo_ with the same bits
as _bfextu_; this turned all bfexts and bfffo instructions into
bfextu.  Motorola's 68k Programmer's Reference Manual (1992) gives
different bits for bfexts, but still has wrong bits for bfffo.  Change
bfexts and bfffo to match the 68k emulators musahi, aranym, syn68k.

The bitfield width is from 1 to 32, not 0 to 31, so move the warning
from 32 to 0.  This doesn't change the warning message, so it will say
that 0 is "too big", when 0 is really too small.
2019-09-24 10:44:48 -04:00
George Koehler f0a2c84d93 Tweak i386 rules for adi 8, sli 8, sru 8.
Add EXACT to the rule for adi 8, in the same way that the old rules
for and 8, ior 8, xor 8 have EXACT.

Add rules for sli 8 and sru 8 when shifting 32 bits, and add
assertions in llshift_e.c to test these rules.
2019-09-18 14:09:51 -04:00
George Koehler f6a1e08218 Test long long division and remainder; fix i386.
My i386 code from 893df4b gave the wrong sign to some 8-byte
remainders.  Fix by splitting .dvi8 and .rmi8 so each has its own code
to pick the sign.  They and .dvu8 and .rmu8 share a private sub
.divrem8 for unsigned division.

Improve the i386 code by using instructions like _bsr_ and _shrd_.
Change the helpers to yield a quotient in ebx:eax or a remainder in
ecx:edx; this seems more convenient, because _div_ puts its quotient
in eax and remainder in edx.
2019-09-16 20:19:36 -04:00
George Koehler 04427e65dc Add and test rol 8, ror 8 for linux386.
These tests are in core/rotate_e.e with the other rotation tests, and
only run on platforms where _EM_LLSIZE == 8.
2019-09-12 19:47:51 -04:00
George Koehler fb9f5387b5 Add long long comparisons, shifts for linux386.
Add tests for comparisons and shifts.  Also add enough integer
conversions to compile the shift test (llshift_e.c), and disable
some wrong rules for ldc and conversions.
2019-09-07 16:20:33 -04:00
George Koehler 893df4b79b Experiment with 8-byte integers in ncg i386.
This provides adi, sbi, mli, dvi, rmi, ngi, dvu, rmu 8, but is missing
shifts and rotates.  It is also missing conversions between 8-byte
integers and other sizes of integers or floats.  The code might not be
all correct, but works at least some of the time.

I adapted this from how ncg i86 does 4-byte integers, but I use a
different algorithm when dividing by a large value: i86 avoids the div
instruction and uses a shift-and-subtract loop; but I use the div
instruction to estimate a quotient, which is more like how big integer
libraries do division.  My .dvi8 and .dvu8 also set ecx:ebx to the
remainder; this might be a bad idea, because it requires .dvi8 and
.dvu8 to always calculate the remainder, even when the caller only
wants the quotient.

To play with 8-byte integers, I wrote EM procedures like

     mes 2, 4, 4
     exp $ngi
     pro $ngi,0
     ldl 4
     ngi 8
     lol 0
     sti 8
     lol 0
     ret 4
     end
     exp $adi
     pro $adi,0
     ldl 4
     ldl 12
     adi 8
     lol 0
     sti 8
     lol 0
     ret 4
     end

and called them from C like

    typedef struct { int l; int h; } q;
    q ngi(q);
    q adi(q, q);
2019-08-20 13:38:18 -04:00
George Koehler 1faff418ec Teach some ncg machines to use .data8
This turns EM `con 5000000000I8` into assembly `.data8 5000000000` for
machines i386, i80, i86, m68020, powerpc, vc4.  These are the only ncg
machines in our build.

i80 and i86 get con_mult(sz) for sz == 4 and sz == 8.  The other
machines only get sz == 8, because they have 4-byte words, and ncg
only calls con_mult(sz) when sz is greater than the word size.  The
tab "\t" after .data4 or .data8 is like the tabs in the con_*() macros
of mach/*/ncg/mach.h.

i86 now uses .data4, like i80.  Also, i86 and i386 now use the numeric
string without converting it to an integer and back to a string.
2019-08-13 15:37:05 -04:00
George Koehler 054b9c87e1 Add .data8 for 8-byte literal integers to the assembler.
This takes literal integers, not expressions, because each machine
defines its own valu_t for expressions, but valu_t can be too narrow
for an 8-byte integer, and I don't want to change all the machines to
use a wider valu_t.  Instead, change how the assembler parses literal
integers.  Remove the NUMBER token and add a NUMBER8 token for an
int64_t.  The new .data8 pseudo emits all 8 bytes of the int64_t;
expressions narrow the int64_t to a valu_t.  Don't add any checks for
integer overflow; expressions and .data* pseudos continue to ignore
overflow when a number is too wide.

This commit requires int64_t and uint64_t in the C compiler to build
the assembler.  The ACK's own C compiler doesn't have these.

For the assembler's temporary file, add NUMBER4 to store 4-byte
integers.  NUMBER4 acts like NUMBER[0-3] and only stores a
non-negative integer.  Each negative integer now takes 8 bytes (up
from 4) in the temporary file.

Move the `\fI` and `\fP` in the uni_ass(6) manual, so the square
brackets in `thing [, thing]*` are not italic.  This looks nicer in my
terminal, where italic text is underlined.
2019-08-13 11:47:44 -04:00
David Given 97e6baa052 Fix register corruption when incrementing locals; attempt to solve the
alignment issue.
2019-06-17 23:31:54 +02:00
David Given 94867d24b7 Ensure that procedure labels are word aligned (required by the EM spec). 2019-06-17 22:26:31 +02:00
David Given 3798673afe
Merge pull request #186 from ccodere/carl-ansi-part1
Carl ansi part1
2019-06-15 12:09:41 +02:00
David Given 3feb79ad0c Simplify the .trp API to make it a bit smaller. 2019-06-11 20:02:03 +02:00
carl 9bb69bbb98 Fix several compiler warnings by adding braces 2019-05-14 23:21:19 +08:00
carl de45c1036d ANSI C conversion 2019-05-11 01:11:54 +08:00
carl 708c1ba1b0 ANSI C conversion 2019-05-11 01:11:26 +08:00
carl e6ba8034f0 ANSI C conversion 2019-05-11 01:11:17 +08:00
carl cefebdb5db ANSI C conversion 2019-05-11 01:11:03 +08:00
carl 628dcb3cbf ANSI C conversion 2019-05-11 01:10:47 +08:00
carl 04cb629159 ANSI C conversion 2019-05-11 01:10:12 +08:00
carl 8d6cfa7701 Fix possible buffer writer overflow 2019-03-31 01:14:49 +08:00
carl 4f2c482416 Buffer overflow memory errors. 2019-03-31 00:52:37 +08:00
carl 41fd51eeea Revert change. 2019-03-25 01:41:04 +08:00
carl efecff78b9 Add function prototypes. 2019-03-25 00:14:38 +08:00
carl 9979fb37d2 Add function prototypes. 2019-03-25 00:14:27 +08:00
carl 82cdc096b0 Add function prototypes. 2019-03-25 00:14:08 +08:00
carl f161a5867d Add function prototypes. 2019-03-25 00:13:56 +08:00
carl a6120c220e Fix buffer overflow issue. 2019-03-25 00:13:42 +08:00
carl dcc2be5e8c Add function prototypes. 2019-03-25 00:12:21 +08:00
carl 5295049b16 Add function prototypes. 2019-03-25 00:12:07 +08:00
carl 1636b9b52d Add function prototypes. 2019-03-25 00:11:55 +08:00
carl 180d3388d6 Add function prototypes. 2019-03-25 00:11:43 +08:00
carl 98c5d1f0ee Add function prototypes. 2019-03-25 00:11:31 +08:00
carl ef3a6b3cc4 Add function prototypes. 2019-03-25 00:11:19 +08:00
carl 053c509fc9 Add function prototypes. 2019-03-25 00:10:58 +08:00
carl 2f84fc92cf Add function prototypes. 2019-03-25 00:10:45 +08:00
carl 2dd0d0f81b Add function prototypes. 2019-03-25 00:10:32 +08:00