Skip to content

Implement address size modifier handling in CMPSOp and SCASOp#5062

Merged
Sonicadvance1 merged 4 commits intoFEX-Emu:mainfrom
pmatos:fix/address-size-handle
Nov 20, 2025
Merged

Implement address size modifier handling in CMPSOp and SCASOp#5062
Sonicadvance1 merged 4 commits intoFEX-Emu:mainfrom
pmatos:fix/address-size-handle

Conversation

@pmatos
Copy link
Copy Markdown
Collaborator

@pmatos pmatos commented Nov 17, 2025

A few games were generating "Can't handle adddress size".

I implemented 0x67 prefix handling for CMPSOp and SCASOP and improved the error messages for the remainder.

This modified the address to be 32bits on 64bits and to 16bits on 32bits.

@pmatos pmatos marked this pull request as draft November 17, 2025 15:59
@Sonicadvance1
Copy link
Copy Markdown
Member

As a note here, we can't support 16-bit addressing modes because Linux reserves the lowest 16-bits of VA space. Requires the use of segments to offset everything, which isn't setup at all.

@pmatos pmatos force-pushed the fix/address-size-handle branch 4 times, most recently from 62d6f1f to 89ec103 Compare November 17, 2025 17:08
@bylaws
Copy link
Copy Markdown
Collaborator

bylaws commented Nov 18, 2025

which games out of interest?

@pmatos pmatos force-pushed the fix/address-size-handle branch from 89ec103 to eb95bd7 Compare November 18, 2025 16:11
@pmatos
Copy link
Copy Markdown
Collaborator Author

pmatos commented Nov 18, 2025

which games out of interest?

Good question - need to rerun the last batch to tell you. I will get back to you on this.

@pmatos pmatos force-pushed the fix/address-size-handle branch 2 times, most recently from 7485230 to 6d33794 Compare November 19, 2025 10:08
@Sonicadvance1
Copy link
Copy Markdown
Member

It looks like you've run afoul of out of all the string operating instructions, stos and scas both will fault if attempting to get used with a null-selector for the ES segment register.

This patch to the ASM generation will fix it.

diff --git a/unittests/32Bit_ASM/CMakeLists.txt b/unittests/32Bit_ASM/CMakeLists.txt
index 462b319d4..187a5a675 100644
--- a/unittests/32Bit_ASM/CMakeLists.txt
+++ b/unittests/32Bit_ASM/CMakeLists.txt
@@ -30,7 +30,7 @@ foreach(ASM_SRC ${ASM_SOURCES})
   add_custom_command(OUTPUT ${TMP_FILE}
     DEPENDS "${ASM_SRC}"
     COMMAND "cp" ARGS "${ASM_SRC}" "${TMP_FILE}"
-    COMMAND "sed" ARGS "-i" "-e" "\'1s;^;BITS 32\\norg 10000h\\nmov eax, 0x17\\nmov ds, ax\\n;\'" "-e" "\'\$\$a\\ret\\n\'" "${TMP_FILE}"
+    COMMAND "sed" ARGS "-i" "-e" "\'1s;^;BITS 32\\norg 10000h\\nmov eax, 0x17\\nmov ds, ax\\nmov es, ax\\n;\'" "-e" "\'\$\$a\\ret\\n\'" "${TMP_FILE}"
     )

   set(OUTPUT_NAME "${OUTPUT_ASM_FOLDER}/${ASM_NAME}.bin")

@pmatos pmatos force-pushed the fix/address-size-handle branch 2 times, most recently from 0ab9142 to c7792c6 Compare November 20, 2025 10:27
@pmatos
Copy link
Copy Markdown
Collaborator Author

pmatos commented Nov 20, 2025

It looks like you've run afoul of out of all the string operating instructions, stos and scas both will fault if attempting to get used with a null-selector for the ES segment register.

This patch to the ASM generation will fix it.

diff --git a/unittests/32Bit_ASM/CMakeLists.txt b/unittests/32Bit_ASM/CMakeLists.txt
index 462b319d4..187a5a675 100644
--- a/unittests/32Bit_ASM/CMakeLists.txt
+++ b/unittests/32Bit_ASM/CMakeLists.txt
@@ -30,7 +30,7 @@ foreach(ASM_SRC ${ASM_SOURCES})
   add_custom_command(OUTPUT ${TMP_FILE}
     DEPENDS "${ASM_SRC}"
     COMMAND "cp" ARGS "${ASM_SRC}" "${TMP_FILE}"
-    COMMAND "sed" ARGS "-i" "-e" "\'1s;^;BITS 32\\norg 10000h\\nmov eax, 0x17\\nmov ds, ax\\n;\'" "-e" "\'\$\$a\\ret\\n\'" "${TMP_FILE}"
+    COMMAND "sed" ARGS "-i" "-e" "\'1s;^;BITS 32\\norg 10000h\\nmov eax, 0x17\\nmov ds, ax\\nmov es, ax\\n;\'" "-e" "\'\$\$a\\ret\\n\'" "${TMP_FILE}"
     )

   set(OUTPUT_NAME "${OUTPUT_ASM_FOLDER}/${ASM_NAME}.bin")

Thanks I was adding that to the tests but clearly there it's better. Still there's still a failure I need to investigate:

host/Test_32Bit_FEX_bugs/GOT_calculation.asm

@pmatos
Copy link
Copy Markdown
Collaborator Author

pmatos commented Nov 20, 2025

Thanks I was adding that to the tests but clearly there it's better. Still there's still a failure I need to investigate:

host/Test_32Bit_FEX_bugs/GOT_calculation.asm

oh, i see, the cmakelists patch screwed got_calculation. will fix that now.

@pmatos pmatos force-pushed the fix/address-size-handle branch from c7792c6 to cee9132 Compare November 20, 2025 12:34
A few games were generating "Can't handle adddress size".
I implemented 0x67 prefix handling for CMPSOp and SCASOP and improved
the error messages for the remainder. This will implement the address
modifier on 64bit systems, and keep issuing an error on 32bits.
@pmatos pmatos force-pushed the fix/address-size-handle branch from cee9132 to de10154 Compare November 20, 2025 12:42
@pmatos pmatos marked this pull request as ready for review November 20, 2025 12:42
@pmatos
Copy link
Copy Markdown
Collaborator Author

pmatos commented Nov 20, 2025

which games out of interest?

I have seen this in more but Overcooked 2 has several:

E can't handle address size

errors.

@bylaws
Copy link
Copy Markdown
Collaborator

bylaws commented Nov 20, 2025

That's just the JIT exploring garbage code, it isn't actually used.

Copy link
Copy Markdown
Member

@Sonicadvance1 Sonicadvance1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool. Even though the message only occurred with code exploration, nice that all of this is implemented so if we /do/ hit a game that uses it, it'll work fine.

@Sonicadvance1 Sonicadvance1 merged commit 5205ae4 into FEX-Emu:main Nov 20, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants