Skip to content

Wasm core doesn't pass opctests. #3

@Ismael-VC

Description

@Ismael-VC
Image

the expected output is:

Ok1
Ok2
Ok3
Ok4
Ok5
Ok6
Ok7
Opcodes passed!
Stack-wrap passed!
RAM-wrap passed!
PC-wrap passed!
PC2-wrap passed!
Zeropage-wrap passed!
Devices-wrap passed!
Result: passed!

got:

-- Unused: rel-distance
Assembled in 3432 bytes.
Ok1
Ok2
Ok3
Ok4
Ok5
Ok6
Ok7
Opcodes passed!
Stack-wrap passed!
RAM-wrap passed!

fails at: https://git.sr.ht/~rabbits/uxn-utils/tree/main/item/cli/opctest/src/opctest.tal#L108

#8055 #ffff STA2 #6c #01 STZ #ffff JSR2 #55 EQU

If i put a debug after the call I can see it never returns:

#8055 #ffff STA2 #6c #01 STZ #ffff JSR2 [ #010e DEO ] #55 EQU

Spotted this in the vanilla js core as well but was fixed, the issue was that there were ram[pc++], that makes this test fail because pc becomes undefined, I am trying to fix it but found #2 hopefully I can send you a PR soon :)

I do see we have several instances of:

(i32.load8_u (i32.and (local.get $pc) (i32.const 0xffff)))

which loads the pc and masks it, but it may alroady be undefined when we do that.

I think it is better to pc = (pc + 1) & 0xffff, as we do in some places, when incrementing, but as far as I understand we are missing a few places:

(local.set $pc (i32.add (local.get $pc) (i32.const 1)))

like:

;;; LIT ( --  a) [0x80]
        ;;;
        ;;; Literal
        ;;;
        ;;; Pushes the next bytes in memory, and moves the PC+2. The LIT opcode
        ;;; always has the keep mode active. Notice how the 0x00 opcode, with
        ;;; the keep bit toggled, is the location of the literal opcodes.
        ;;;
        ;;; Example:
        ;;;   LIT 12          ( 12 )
        ;;;
        (local.set $wstp (i32.and (i32.add (local.get $wstp) (i32.const 255)) (i32.const 0xff)))
        (i32.store8 offset=0x100000 (local.get $wstp) (i32.load8_u (local.get $pc)))
        (local.set $pc (i32.add (local.get $pc) (i32.const 1)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions