Commit Graph

832 Commits

Author SHA1 Message Date
Bill Currie 59044d3827 Fix a bunch of distcheck issues 2022-02-14 19:28:19 +09:00
Bill Currie 4d491a444d [gamecode] Fix handling of undefined builtins
The setup of the function descriptor for undefined builtins was
incomplete and led to the progs running code at address 0. It didn't end
well.
2022-02-14 14:28:19 +09:00
Bill Currie db8cf68ef3 [gamecode] Pass registered data pointer to builtins
This is the bulk of the work for recording the resource pointer with
with builtin data. I don't know how much of a difference it makes for
most things, but it's probably pretty big for qwaq-curses due to the
very high number of calls to the curses builtins.

Closes #26
2022-02-14 12:28:38 +09:00
Bill Currie 944a9253e9 [gamecode] Support %u format in PR_Sprintf
Not sure why it was missed as it would have been useful even before
unsigned was properly supported by qfcc.
2022-02-12 01:58:38 +09:00
Bill Currie eba614336d [gamecode] Add single-component float bitop instructions
These add legacy support for basic float bitops (& | ^ ~). Avoiding the
instructions would require tot only the source to be converted, but also
the servers (as they do access those fields), and this seemed to be too
much.
2022-02-06 21:20:00 +09:00
Bill Currie e1ecda9221 [gamecode] Add unsigned divide and remainder instructions
I had forgotten that unsigned division was different from signed
division (rather silly of me). However, with some testing and analysis,
unsigned true modulo is not needed as it's not possible to have
negative inputs and thus it's the same as remainder.
2022-02-06 12:20:17 +09:00
Bill Currie 078f36a871 [gamecode] Add "return pointer" mode to with instruction
This loads the current return pointer into the specified register. No
offset is used (should make that an error, but for now any offset is
simply ignored). This is part of the fix for getting obj_msg_sendv to
work with return values.
2022-02-05 18:42:54 +09:00
Bill Currie 208cba85eb [gamecode] Move return buffer to end of progs memory map
With the return buffer in progs_t, it could not be addressed by the
progs on 64-bit machines (this was intentional, actually), but in order
to get obj_msg_sendv working properly, I needed a way to "bounce" the
return address of a calling function to the called function. The
cleanest solution I could think of was to add a mode to the with
instruction allowing the return pointer to be loaded into a register and
then calling the function with a 0 offset for the return value but using
the relevant register (next few commits). Testing promptly segfaulted
due to the 64-bit offset not fitting into a 32-bit value.
2022-02-05 18:37:23 +09:00
Bill Currie 9cf2740cb4 [gamecode] Create a globally accessible hash of type encodings
The plan is to use the types to extract the number of parameters for a
selector when it is necessary to know the count. However, it'll probably
become useful for something else alter (these things seem to always do
so).
2022-02-05 14:07:45 +09:00
Bill Currie 7731c469e2 [gamecode] Count calls to builtins in profile
It's a bit disconcerting seeing a builtin in the top 10 when builtins
are counted by call while progs functions are counted by instruction.

Also, show the total profile after the function top-10 list.
2022-02-04 21:49:59 +09:00
Bill Currie 0211b6ec5b [gamecode] Add 64-bit load/store instructions
Only widths 3 and 4 have been added because widths 1 and 2 can be
implemented by widths 2 and 4 of the 32-bit load/store instructions.
2022-02-02 14:47:36 +09:00
Bill Currie 6514e09e7c [gamecode] Use an explicit size for the null page
It's currently only 4 (or even 3 for v6) words, but this fixes false
positives when checking for null pointers in Ruamoko progs due to
pr_return pointing to the return buffer and thus outside the progs
memory map resulting in an impossible to exceed value.
2022-02-01 16:43:29 +09:00
Bill Currie 5d41e90cc7 [gamecode] Remove pushregs and popregs specs
They have been redundant since the operations were moved into with.
2022-01-31 23:47:47 +09:00
Bill Currie 712d800491 [gamecode] Save return ptr for chained calls
It turns out the return pointer still needs to be saved even when a
builtin sets up a chain call to progs, but rather than the pointer being
simply restored, it needs to be saved in the call stack exactly as if
the function was called directly by progs. This fixes the invalid self
issue quite thoroughly: parameter state seems to be correct across all
calls now.

I should set up an automated test now that I know and understand the
situation.
2022-01-31 23:35:56 +09:00
Bill Currie cabb53e693 [gamecode] Skip return ptr restore if depth changed
When calling a builtin, normally the return pointer needs to be
restored, but if the builtin changes the call depth (usually by
effecting "return foo()" as in support for objects, but possibly
setjmp/longjmp when they are implemented), then the return pointer must
not be restored. This gets vkgen past object allocation, but it dies
when trying to send messages to super. This appears to be a compiler
bug.
2022-01-31 16:51:46 +09:00
Bill Currie 8dc4a0ea80 [qfcc] Change v6p's jumpb opname to jump
More ease of searching, since the operand types help greatly.
2022-01-30 22:39:21 +09:00
Bill Currie 7971bcd91c [gamecode] Sort out shr's opname for easier searching
Since the operand types sort out the difference between asr and shr, no
need to give them different opnames. Means qfcc doesn't need to worry
about which one it's searching for.
2022-01-30 22:37:03 +09:00
Bill Currie 766bf758ab [gamecode] Redesign jump's B addressing
Yet another redundant addressing mode (since ptr + 0 can be used), so
replace it with a variable-indexed array (same as in v6p). Was forced
into noticing the problem when trying to compile Machine.r.
2022-01-30 22:34:40 +09:00
Bill Currie 4871717fae [gamecode] Rename v6 vector-scalar multiply to scale
Makes it easier to get Ruamoko scaling implemented if they both use the
same opname.
2022-01-30 14:47:26 +09:00
Bill Currie 46ce37160b [gamecode] Correct vecops widths
I had forgotten to update the widths when I moved cross product's
position.
2022-01-30 14:11:41 +09:00
Bill Currie 728c42e921 [gamecode] Use pr_type_names for debug views
I abandoned the reason for doing it (adding a pile of vector types), but
I liked the cleanup. All the implementations are hand-written still, but
at least the boilerplate stuff is automated.
2022-01-30 10:49:33 +09:00
Bill Currie 49395b3ba1 [gamecode] Correct state's types for double time
It takes int for the frame rather than float.
2022-01-29 18:48:05 +09:00
Bill Currie 7e9cf76cfe [qfcc] Change ne to cmp for v6 string inequality check
Since it's really strcmp in disguise (makes the instruction consistent
across all targets).
2022-01-29 18:18:33 +09:00
Bill Currie 10843fe340 [gamecode] Correct memset opname and types 2022-01-29 17:05:10 +09:00
Bill Currie 5c22253095 [gamecode] Use the stack frame to find local defs
Of course, only in Ruamoko progs, but it works quite nicely.
global_string is now passed the absolute address of the referenced
operand. With a little groveling through the progs stack, it should be
possible to resolve pointers to locals in functions further up the
stack.
2022-01-27 14:20:09 +09:00
Bill Currie de974fdd3f [gamecode] Add format for addressing modes and use in return
This fixes Ruamoko's return format string. It looks like it's producing
the correct address (but doesn't show all the information it should),
but the rest of the debug code needs work locals.
2022-01-27 13:29:38 +09:00
Bill Currie 42db8514ae [gamecode] Use version instead of locals count
It turned out I need locals count and params_start for debugging, so use
the progs version instead to bail early from PR_EnterFunction and
PR_LeaveFunction (which I had forgotten anyway, oops).
2022-01-27 11:24:00 +09:00
Bill Currie a0d9cf8d8e [gamecode] Improve verbose statement prints for Ruamoko
They now include base register index and effective address of the
operands (though it may be wrong for instructions that don't use a base
register for that operand).
2022-01-27 10:57:31 +09:00
Bill Currie 59ee723201 [gamecode] Rename parm to param
That misspelling bothered me from the very beginning, I'd always have
trouble getting the name right when trying to access one of those fields.
2022-01-27 10:55:06 +09:00
Bill Currie e9dff4ff9c [gamecode] Correct types and widths for bitnot
bitnot is the only unary operator in the bitops group and thus needs
special handling.
2022-01-27 10:21:48 +09:00
Bill Currie faa98d8198 [gamecode] Use a struct for offset/count pairs
This cleans up dprograms_t, making it easier to read and see what chunks
are in it (I was surprised to see only 6, the explicit pairs made it
seem to have more).
2022-01-26 19:30:25 +09:00
Bill Currie a2f4522e76 [gamecode] Align Ruamoko progs to 32 bytes.
Intel hardware requires 32-byte alignment for lvec4 and dvec4.
Unfortunately, it turns out that my attempts to align progs data in qfcc
went awry do to the order block sizes are calculated when writing the
progs.
2022-01-26 16:55:14 +09:00
Bill Currie ee4eecc741 [gamecode] Correct types and opname for memset and move 2022-01-26 12:26:12 +09:00
Bill Currie 6bc6db471d [gamecode] Make return use same addressing as other ops
This makes return consistent with load, store, etc, though its
addressing mode is encoded in bits 5 and 6 of c rather than the opcode.
It turns out I had no tests for any of return's addressing modes other
than basic def references, so no tests needed changing.
2022-01-26 09:51:11 +09:00
Bill Currie 37f08f9d4f [qfcc] Build the Ruamoko function parameters
The parameter defs are allocated from the parameter space using a
minimum alignment of 4, and varargs functions get a va_list struct in
place of the ...

An "args" expression is unconditionally injected into the call arguments
list at the place where ... is in the list, with arguments passed
through ... coming after the ...

Arguments get through to functions now, but there's problems with taking
the address of local variables: currently done using constant pointer
defs, which can't work for the base register addressing used in Ruamoko
progs.

With the update to test-bi's printf (and a hack to qfcc for lea),
triangle.r actually works, printing the expected results (but -1 instead
of 1 for equality, though that too is actually expected). qfcc will take
a bit longer because it seems there are some design issues in address
expressions (ambiguity, and a few other things) that have pretty much
always been there.
2022-01-24 23:44:48 +09:00
Bill Currie b663fecd4e [gamecode] Use PR_SetupParameters for rua called builtins
It's a bit heavy-handed as it sets all the param pointers, but simple
(no varargs) functions are working nicely in Ruamoko.
2022-01-24 16:46:49 +09:00
Bill Currie 00b7bced7f [gamecode] Rework PR_RESET_PARAMS to use PR_SetupParams
PR_SetupParams is new and sets up the parameter pointers so older code
that expects only up to 8 parameter will work with both v6p and Ruamoko
progs without having to check what progs are running. PR_SetupParams is
useful even when Ruamoko progs are expected as it reserves the required
space (respecting alignment) on the stack and returns a pointer to the
top (bottom? confusing) of the stack. PR_PushFrame and PR_PopFrame
need to be used around PR_SetupParams, regardless of using temp strings,
to avoid a stack leak (need to do an audit).
2022-01-24 12:50:15 +09:00
Bill Currie 9c51c3d2e1 [gamecode] Add a data pointer passed to builtin functions
This is part of the work for #26 (Record resource pointer with builtin
function data). Currently, the data pointer gets as far as the
per-instance VM function table (I don't feel like tackling the job of
converting all the builtin functions tonight). All the builtin modules
that register a resources data block pass that block on to
PR_RegisterBuiltins.
2022-01-24 00:20:05 +09:00
Bill Currie a818fa4b8e [gamecode] Rearrange bfunction_t in preparation for param offsets
The builtin and progs function data is overlaid so the extra data
doesn't cause too much memory to be used (it's actually 8 bytes smaller
now).  The plan is to pre-compute the offsets based on the parameter
size and alignment data.
2022-01-24 00:19:13 +09:00
Bill Currie e746e39738 [gamecode] Create macros for progs sizeof and alignof
I wound up needing the idioms in too many places.
2022-01-23 14:29:33 +09:00
Bill Currie 3c86660d4a [gamecode] Rename MAX_PARMS to PR_MAXPARAMS 2022-01-23 14:17:25 +09:00
Bill Currie 861e98725c [gamecode] Return early if the entered function has no locals
As even the simplest v6p functions that take parameters but have no
local or temporary variables still have locals for the local copy of the
parameters, this is a both a good check for for the Ruamoko ISA as its
functions never have locals (everything's on the progs data stack), and
an optimization for v6p functions that have no params or locals (simple
getters (very rare?), most .ctor, etc).
2022-01-22 21:41:35 +09:00
Bill Currie 06b1ea6837 [gamecode] Tweak some docs and macro names
And fix an incorrect definition for RETURN_QUAT.

Prefixed MAX_STACK_DEPTH and LOCALSTACK_SIZE (and LOCALSTACK_SIZE got an
extra _).

The rest is just edits to documentation comments.
2022-01-22 11:38:14 +09:00
Bill Currie 7a5ee6a55a [gamecode] Initialize .stack if it's available
And implement bounds checks for adjstk.
2022-01-21 20:33:15 +09:00
Bill Currie 9199a0ee54 [gamecode] Don't check v6p progs for Ruamoko progs
It doesn't end well. For now, the Ruamoko check is just a stub, but I do
plan on doing similar checks.
2022-01-21 20:31:49 +09:00
Bill Currie 3df46d197f [gamecode] Add instructions for stack adjust, nop, and ldconst
ldconst isn't implemented yet but the plan is to load various constants
(eg, 0, 1, 2, pi, e, ...).

Stack adjust is useful for adding an offset to the stack pointer without
having to worry about finding it (and it checks for alignment).

nop is just that :)
2022-01-21 20:00:38 +09:00
Bill Currie c53127707b [qfcc] Set the return of Ruamoko calls
Of course, I had the width of opc wrong :P. But with this, it seems that
unoptimized calls should work once I get the stack frame working.
2022-01-21 13:50:21 +09:00
Bill Currie 16a203c643 [gamecode] Partially implement conversion code debug
The code is simply printed in octal for now, but it's better than
breaking the rest of the format string.
2022-01-21 10:12:50 +09:00
Bill Currie 578314c5a3 [gamecode] Use a buffer for discarded return values
Due to how OP_RETURN works, a destination is required for any function
returning data, but the caller may not have allocated any space for the
value. Thus the VM maintains a buffer into which the data can be put and
ignored. It also makes a good place for return values when the engine
calls Ruamoko code as trusting progs code with return sizes seems like a
recipe for disaster, especially if the return location is on the C
stack.
2022-01-21 10:09:02 +09:00
Bill Currie 4b87d24737 [gamecode] Correct call's operator types 2022-01-21 10:07:35 +09:00