Commit Graph

85 Commits

Author SHA1 Message Date
Bill Currie c9f1d770e0 Merge master into csqc-improvements
That was a mess
2021-03-25 22:01:31 +09:00
Bill Currie 66fda1fddb Rewrite edict access.
The server edict arrays are now stored outside of progs memory, only the
entity data itself (ie data accessible to progs via ent.fld) is stored in
progs memory. Many of the changes were due to code accessing edicts and
entity fields directly rather than through the provided macros.
2021-03-25 18:13:48 +09:00
Bill Currie 4f8a06ddd3 [build] Fix a pile of gcc 10 issues
gcc got stricter about array accesses, complicating progs macros, and
much better at detecting buffer overflows.
2020-12-28 18:58:51 +09:00
Bill Currie f90613bc3a [gamecode] Rename fields in pr_stack_t
s and f are a little too succinct.
2020-04-02 15:00:01 +09:00
Bill Currie e9733416f4 [gamecode] Hide trace messages when debugger is attached 2020-04-01 00:09:34 +09:00
Bill Currie 2d5df34234 [gamecode] Add VM enter/exit events
And rename prd_exit to prd_terminate (the idea is the host will
terminate the VM). This makes it possible for the debugger to pause the
VM before any code, even a builtin function, is executed. Breaks the
debugger source window, but only because it's not updating on file
change (I think).
2020-03-26 12:30:32 +09:00
Bill Currie 1bd8e2ee85 [gamecode] Add a param pointer to debug_handler
I decided I want events for VM enter/exit but enter needs to somehow
pass the function which will be executed (even if a builtin). A generic
void * param seemed the best idea, which meant the error string could be
passed via the param instead of a "global" string in the progs struct.
2020-03-26 11:44:02 +09:00
Bill Currie c945c42989 [gamecode] Fix some silly errors
I forgot to compile-test :(
2020-03-24 23:16:25 +09:00
Bill Currie d867a1a9f1 [gamecode] Allow watch-point to be updated
With the watch-point address cached in a local var, it was not possible
to update the watch-point while the progs were executing.
2020-03-24 19:45:39 +09:00
Bill Currie 713150b41a [gamecode] Add debug hooks to the VM engine
While there was a breakpoint hook, it was for only breakpoints and more
was needed. Now there's a generic hook that is called for tracing,
breakpoints, watch points, runtime errors and VM errors, with the
"event" type passed as the first parameter and a data pointer in the
second.
2020-03-24 19:45:10 +09:00
Bill Currie 1d6843d7f0 [gamecode] Improve watchpoint handling a little
Mostly just update the old value if the condition didn't trigger.
2020-03-24 13:26:35 +09:00
Bill Currie 753d183d82 [gamecode] Be more informative with function calls
PR_EnterFunction and PR_LeaveFunction now print the
entered/left/returned function when tracing. Makes debugging obj code
much easier.
2020-03-24 13:24:55 +09:00
Bill Currie a0d85e33c2 [gamecode] Rework implementation of memset*
The memset instructions now match the move* instructions other than the
first operand (always int). Probably breaks much, but fixed in next few
commits.
2020-03-13 17:50:57 +09:00
Bill Currie 6ca85d770d [gamecode] Add memset instructions 2020-03-11 22:48:55 +09:00
Bill Currie 023a920a51 [gamecode] Replace lost parameter auto-reset
rcallN messes with the progs parameter pointers and not resetting them
can cause incorrect data to be copied into the called function.
2020-03-11 19:38:50 +09:00
Bill Currie 6c56e93fc8 [gamecode] Be more careful with temp strings
If a temp string is found in the return slot, PR_FreeTempStrings won't
delete the string. However, PR_PopFrame was blindly stomping on the
possibly surviving temp string with the push strings, which would cause
a leak.
2020-03-10 03:24:31 +09:00
Bill Currie f290b115a5 [gamecode] Add function PR_PushTempString
This "pushes" a temp string onto the callee's stack frame after removing
it from the caller's stack frame. This is so builtins can pass
auto-freed memory to called progs code. No checking is done, but mayhem
is likely to ensue if a string is pushed that was allocated in an
earlier frame.
2020-03-09 23:36:09 +09:00
Bill Currie aa02069dd1 Add a breakpoint flag to opcodes
The progs execution code will call a breakpoint handler just before
executing an instruction with the flag set. This means there's no need
for the breakpoint handler to mess with execution state or even the
instruction in order to continue past the breakpoint.

The flag being set in a progs file is invalid.
2020-02-26 13:40:26 +09:00
Bill Currie a55b9544ac Improve handling of pr_argc
It is now set to 0 when progs are loaded and every time
PR_ExecuteProgram() returns. This takes care of the default case, but
when setting parameters, pr_argc needs to be set correctly in case a
vararg function is called.
2020-02-25 17:36:29 +09:00
Bill Currie 61d7f4f9c4 Dump locals stack when dumping main stack
Any shutdown functions in progs will need locals too.
2020-02-25 15:18:15 +09:00
Bill Currie 9bb68f2d8c Allow nested use of PR_SaveParams()
PR_SaveParams() is required for implementing the +initialize diversion
used by Objective-QuakeC because builtins do not have local def spaces
(of course, a normal stack calling convention would help). However, it
is entirely possible for a call to +initialize to trigger another call
to +initialize, thus the need for stacking parameter stashes. As a
bonus, this implementation cleans up some fields in progs_t.
2020-02-25 14:30:26 +09:00
Bill Currie ed283a9e7f Copy only the necessary number of vararg parameters 2020-02-16 18:00:29 +09:00
Bill Currie 12d2a0ff75 Copy the correct number of words for rcall 2020-02-16 17:58:36 +09:00
Bill Currie f5741a979e Implement parameter alignment in the engine
The engine now requires non-v6 progs to store the log2 alignment for the
param struct in .param_alignment.

PR_EnterFunction is clearer and possibly more efficient.
2020-02-16 17:13:45 +09:00
Bill Currie 32c21ec559 Make gcc accept the bitwise-boolean magic
Forgot to compile check...
2020-02-16 12:08:08 +09:00
Bill Currie b4fd804e4e Implement true modulo in the engine 2020-02-16 11:53:56 +09:00
Bill Currie 4269c8cb07 Rename the mod instruction to rem
Because % really implements remainder rather than true modulo, and I
plan on adding %% to implement true modulo.
2020-02-16 11:04:30 +09:00
Bill Currie df7c08a010 Add support for doubles to Ruamoko
Only as scalars, I still need to think about what to do for vectors and
quaternions due to param size issues. Also, doubles are not yet
guaranteed to be correctly aligned.
2020-02-15 23:49:12 +09:00
Bill Currie 13b608f40c Don't truncat float % float
This allows full usage, eg, x % pi, but otherwise maintains
compatibility with integer %
2020-02-15 23:49:12 +09:00
Bill Currie 6252faa069 Fix a size error in OP_LOAD_Q.
C&P from OP_LOAD_V :/
2018-10-11 13:25:32 +09:00
Bill Currie 364c2d2c2b Add a stack and push and pop instructions.
The stack is for data, not return addresses.
2018-10-11 13:24:03 +09:00
Bill Currie 546e333a3c Allow Sys_Error to be hooked.
This makes debugging builtins that wrap normal functions a little easier by
giving a progs dump when such an error occurs.
2016-01-03 23:04:00 +09:00
Bill Currie 7b350b2a1b Indicate calls to builtins when tracing.
This makes following progs traces a little easier.
2016-01-03 16:13:59 +09:00
Bill Currie 99a8e8f228 Fix the jump instruction.
The offset to compensate for st++ was missing.

Obviously, the code has never been tested.  Found while looking at the
jump code and thinking about using 32-bit addresses for the jump tables.
2013-06-26 09:59:19 +09:00
Bill Currie 3c67e8f020 Fix the vector/quaternion scaling instructions.
It was pointed out by Blub\w (gmqcc) that OP_MUL_FV and friends were buggy
when the operands overlapped (eg, x = x.x * x) as the result would become
'x.x*x.x x.y*x.x*x.x x.z*x.x*x.x' (note the x.x squared for y and z). On
testing, sure enough the bug was present (and is a nice demonstration that
QF's VM does NOT have strict-aliasing bugs). As a very nice benefit: the
code produced by the fixes is actually faster than the broken version :).

The ruamoko code used for testing:
void (string fmt, ...) printf = #0;

vector foo (vector x)
{
    x = x * x.x;
    return x;
}

vector bar (vector x)
{
    x = x.x * x;
    return x;
}

int main ()
{
    vector x = '2 3 4';
    vector y = foo (x);
    vector z = bar (x);
    printf ("x=%v y=%v z=%v 2*x=%v\n", x, y, z, 2*x);
    return 0;
}
2013-01-17 10:23:02 +09:00
Bill Currie e0e69ac71a Fix some signed/unsigned comparison warnings.
It seems mingw's gcc treats pointer subtraction differently to how linux's
gcc does.
2013-01-05 17:52:48 +09:00
Bill Currie 3b63c31b5d Use pr_return for the null pointer check.
The params come after the return slot :P. Getting a null pointer exception
for movep from .return wasn't very funny.
2012-12-26 11:47:53 +09:00
Bill Currie 1fdc32bb39 Check for null VM pointer accesses.
Currently only four words of "null pointer protection" are available, but
it's a start.
2012-12-22 14:24:11 +09:00
Bill Currie 6eb6b6c0ba Change pointer_t to unsigned and clean up the mess.
It doesn't make sense to have negative pointers. The size of the commit is
from enabling gcc's -Wtype-limits warning and cleaning up that mess too.
2012-12-21 21:53:13 +09:00
Bill Currie 11b991cf9d Print the error message before the state dump.
Normally, the order doesn't matter, but when tracing code, it becomes very
difficult to tell where the trace ends and the dump begins. Printing the
message first puts the message between the trace and the dump: much easier
:)
2012-12-16 12:27:15 +09:00
Bill Currie 49ad301d3d Add improved memory checking to progs.
With pr_boundscheck >= 2, pointer access will be checked against allocated
blocks (qfvalgrind?:). Currently extremely basic, but it seems to work.
2012-11-19 20:03:21 +09:00
Bill Currie 23a38738fc Massive whitespace cleanup.
Lots of trailing whitespace and otherwise blank lines.
2012-05-22 08:23:22 +09:00
Bill Currie 1a0ccf6a92 Add vec = quat * vec to the progs engine. 2012-04-26 11:58:20 +09:00
Bill Currie bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie b5019c8e33 Nuke the engine dicrectory from gamecode.
Not the contents, of course :) Anyway, finally, that totally useless
directory is gone.
2012-02-06 23:44:52 +09:00
Adam Olsen 9ea52e8239 Move the gamecode engine into a subdir. 2001-08-21 21:05:26 +00:00
Bill Currie 07a09e0812 statement printing now infers the type of a def from the instruction where
possible, thus allowing anonymous defs to print their contents.
2001-08-13 23:49:04 +00:00
Bill Currie 283b0e1a21 change the types of the statement operands to unsigned short to clean up
most of the uses
2001-08-13 21:09:00 +00:00
Bill Currie 45fd3e084d rhamph's deadbeaf locals patch as-is :) 2001-08-13 20:29:33 +00:00
Adam Olsen 6414897dae got a few new operators for qc :)
<< >> % which all act like their C counterparts
+= -= *= /= &= ^= |= <<= >>= %= which just expand into the obvious,
also like the C versions.
2001-08-10 16:17:00 +00:00