duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit c57c31da346cfa62b7e67d5f4541cfea88fad51c
parent f4b8b799484efe1f88a8844f02579b9353c04fbc
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon,  3 Oct 2022 07:37:23 -0400

cc/vm/i386: fix register mixup in vmmul, and vmdiv,

By calling :>reg before we do the DX push, we ensure that DX is not going to be
overwritten by vmop^ :>reg.

Diffstat:
Mfs/cc/vm/i386.fs | 14+++++---------
Mfs/xcomp/pc/inittest.fs | 2+-
2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/fs/cc/vm/i386.fs b/fs/cc/vm/i386.fs @@ -151,22 +151,18 @@ struct+[ VMOp \ operand is hardcoded to EAX and also, EDX gets written by the op, so we need \ to save EDX if in use. : _pre - \ TODO: this DX protect below is likely broke because of the following :>reg - \ which will likely push to dx again. I think it's better to hardcode the - \ whole thing to AX and BX. + vmop :>reg vmop^ :>reg reglvl 4 >= if dx push, then - \ if op1 is not EAX, we need to push EAX, perform the mul, copy EAX to op1's - \ reg, then pop eax back. - vmop :>reg vmop :isAX? not if ax push, ax vmop :compile mov, then vmop^ :>reg ; + vmop :isAX? not if ax push, ax vmop :compile mov, then ; : _post vmop^ :init vmop :isAX? not if vmop :compile ax mov, ax pop, then reglvl 4 >= if dx pop, then ; : vmmul, _pre vmop^ :compile mul, _post ; : vmdiv, _pre dx dx xor, vmop^ :compile div, _post ; -\ Copy the contents of op2 in the memory address pointed out by op1 and deinit -\ op2. In other words, perform a AST_ASSIGN with the right part as op2 -\ and the left part as op1. +\ Copy the contents of vmop^ in the memory address pointed out by vmop and +\ deinit vmop^. In other words, perform a "=" binop with the right part as +\ vmop^ and the left part as vmop. : vmmov, vmop^ loc VM_CONSTARRAY = if \ special case, we have a {1, 2, 3} assign vmop loc VM_STACKFRAME = _assert diff --git a/fs/xcomp/pc/inittest.fs b/fs/xcomp/pc/inittest.fs @@ -5,4 +5,4 @@ f<< lib/diag.fs f<< sys/xhere.fs ' bye to abort f<< tests/all.fs -bye +: init bye ;