Jump to content

Opcode Emulator (OPEMU) Plug-in Project


Meowthra
69 posts in this topic

Recommended Posts

1 hour ago, PeterHolbrook said:

I was expecting the developer would clarify the capabilities of this kext and the contexts where it would work. Perhaps that's too much to expect.

 

As you can see @Meowthra last visit was on October 2019, some are trying to keep this project alive. If I’m not mistaken this kext should prevent apps requiring presence of AVX from crashing, I have my Pentium as headless and I’m not using apps requiring AVX so I’m not sure if it’s properly utilized and rather hoping for better compatibility of my unsupported processor.

Link to comment
Share on other sites

Yesterday I included OpcodeEmulator.kext in my OpenCore 0.8.7 config.plist. OpenCore itself reached the BootPicker without issues on my old Mac Pro 5,1, but when I selected Monterey as the boot device it only was able to show the Apple logo and then nothing. No progress bar, no error messages, no nothing. I suppose the code is not compatible with Xeon processors.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

this build should work up2 ventura

requires lilu v1.6.4 (if you need an older version just recompile with older version)

 

to build with cmake

- install cmake.app https://cmake.org/install/

- install apple devtools (cmake will ask for it)

- open terminal.app (lol)

- cd to ./build

- delete all files there

- type cmake ..

- type make

 

for hackers - check code similiar to this

 

    // BMI1/2 Instruction set
    ins_size = bmi_instruction(state, vexreg, opcode, modrm, high_reg, high_index, high_base, operand_size, leading_opcode, simd_prefix, bytep, ins_size, modbyte, kernel_trap);

    // F16C Instruction set
    if (ins_size == 0) {
        ins_size = f16c_instruction(state, vexreg, opcode, modrm, high_reg, high_index, high_base, reg_size, leading_opcode, simd_prefix, bytep, ins_size, modbyte, kernel_trap);
    }
    // VAES Instruction set
    if (ins_size == 0) {
        ins_size = vaes_instruction(state, vexreg, opcode, modrm, high_reg, high_index, high_base, reg_size, operand_size, leading_opcode, simd_prefix, bytep, ins_size, modbyte, kernel_trap);
    }
    // AVX / AVX2 Instruction set
    if (ins_size == 0) {
        ins_size = avx_instruction(state, vexreg, opcode, modrm, high_reg, high_index, high_base, reg_size, operand_size, leading_opcode, simd_prefix, bytep, ins_size, modbyte, kernel_trap);
    }

you can disable some instructions you dont need (in theory they shouldn't be called)

doing so allows for specific cpu ops testing

care for apps that use CPUID checks as the emulator can't bypass that

 

check https://dortania.github.io/OpenCore-Legacy-Patcher/ lots of patches for older/unsupported macs also help hackintosh

 

check in terminal your cpu with:

sysctl machdep.cpu

 

the avx2 shows up in machdep.cpu.leaf7_features

i forgot to enable a kernel patch in my ryzen cpu and .leaf7_features were disabled (check the amd thread if need those patches https://www.insanelymac.com/forum/494-general-discussion/

 

the emulator won't bypass this checks - all it does is emulate missing instructions

if an app uses cpuid to check for avx2 the workaround is patch that check in app and use the emulator for the missing instructions

 

OpcodeEmulator.zip

Edited by jalavoui
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Does anyone know if this is at all a good solution for the Jasperlake line of Pentiums??? I've got an Acer laptop with an n6000 silver in it. Think it would make a nice MacOS machine!

Link to comment
Share on other sites

On 12/21/2022 at 8:42 AM, PeterHolbrook said:

Yesterday I included OpcodeEmulator.kext in my OpenCore 0.8.7 config.plist. OpenCore itself reached the BootPicker without issues on my old Mac Pro 5,1, but when I selected Monterey as the boot device it only was able to show the Apple logo and then nothing. No progress bar, no error messages, no nothing. I suppose the code is not compatible with Xeon processors.

Nope, it ain't. 

Link to comment
Share on other sites

  • 3 weeks later...

@jalavoui, I built OpcodeEmulator.kext with cmake(installed via homebrew), changed CMAKE_OSX_DEPLOYMENT_TARGET to 10.12(not sure how it affects), otherwise it won’t build/load in older OSX.  Unfortunately, after running sysctl machdep.cpu, avx2 doesn’t show up in machdep.cpu.leaf7_features.

Edited by hardcorehenry
Link to comment
Share on other sites

On 4/18/2023 at 12:16 PM, hardcorehenry said:

@jalavoui, I built OpcodeEmulator.kext with cmake(installed via homebrew), changed CMAKE_OSX_DEPLOYMENT_TARGET to 10.12(not sure how it affects), otherwise it won’t build/load in older OSX.  Unfortunately, after running sysctl machdep.cpu, avx2 doesn’t show up in machdep.cpu.leaf7_features.

sysctl machdep.cpu will show you CPU capabilities calculated from CPUID response. It will not show emulated instructions.

The correct check will be an application that compiled with tested instructions like AVX2. The application will crash without AVX2 support.

Is there anybody have such a test?

 

Many years ago I had a CPU without SSE3 instructions and I had a kernel (MacOSX 10.4 Tiger) with an emulator for such instruction so I really saw how it works.

Now I see no any test for this emulator.

  • Like 1
Link to comment
Share on other sites

 

On 4/22/2023 at 6:11 AM, Slice said:

sysctl machdep.cpu will show you CPU capabilities calculated from CPUID response. It will not show emulated instructions.

The correct check will be an application that compiled with tested instructions like AVX2. The application will crash without AVX2 support.

Is there anybody have such a test?

 

Many years ago I had a CPU without SSE3 instructions and I had a kernel (MacOSX 10.4 Tiger) with an emulator for such instruction so I really saw how it works.

Now I see no any test for this emulator.

 

Gigapixel AI (installed for test only) requires presence of AVX2 and theoretically should crash, but it doesn’t, would that mean OpcodeEmulator.kext works? I guess indeed better to wait till someone suggests a proper/better test.

 

Spoiler

2086547675_ScreenShot2023-04-22at2_22_44PM.thumb.png.e0b770bc486b90350a4a59768640bc4c.png

 

Edited by hardcorehenry
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

this was done long ago

i'n uploading meo files b4 they get lost

 

if the app doesn't crash with the emulator then all good

but if an app as this kind of check

https://gist.github.com/hi2p-perim/7855506

then it will fail - in this case you need to patch the code so the emulator can work

this is the opencore legacy approach btw

this is bad on old macs without avx2 on ventura cause patch the app not enough - ventura as embedded avx2 checks in some libraries

 

the amd kernel patch unlocks machdep.cpu.leaf7_features - but if your cpu doesn't support avx2 i doubt you will get this

machdep.cpu.leaf7_feature_bits: 547094953 0
machdep.cpu.leaf7_features: RDWRFSGS BMI1 AVX2 SMEP BMI2 RDSEED ADX SMAP CLFSOPT SHA

not an issue if the app you're trying to run doesn't do this check.

Arquivo.zip

Edited by jalavoui
  • Like 4
Link to comment
Share on other sites

This looks like a very promising project.  Just wanted to report that I tried OpcodeEmulator.kext to see if it would allow my HackBookPro6,2 to install RSR 13.3.1a.  My understanding is that pre-Haswell Macs/hacks cannot install RSRs, because installation of RSRs requires one or more AVX2 opcodes.  The OpcodeEmulator.kext built easily by following the instructions in the Readme and it loaded without any issues (injected via OC 0.9.2).  

 

Unfortunately, after injecting OpcodeEmulator.kext, I was unable to install RSR 13.3.1a, so OpcodeEmulator.kext did not work for me in this case.

 

I just wanted to report my findings in case this is helpful to devs of this project.  I think that what this kext attempts to accomplish is an excellent idea.

Edited by deeveedee
  • Like 1
  • Sad 1
Link to comment
Share on other sites

  • 4 months later...

the code as this 2 "emulators"

 

/** Runs the VEX emulator. returns the number of bytes consumed. **/
int vex_ins(uint8_t *instruction, x86_saved_state_t *state, int kernel_trap)

 

/** Runs the REX emulator. returns the number of bytes consumed. **/
int rex_ins(uint8_t *instruction, x86_saved_state_t *state, int kernel_trap)

 

i dont really understand how this works but yep it depends on cpu

Link to comment
Share on other sites

When some user try to install Ventura on IvyBridge CPU having AMD RX5700 he fails because of drivers contains AVX2.0 instructions. He just see black screen.

May be we can prepare NullEmulator which will not do full emulation of AVX2.0, it is complex task, but prevent crash. Such kext will just return from interrupt. There will be artefacts but framebuffer will work. Yes?

Link to comment
Share on other sites

5 hours ago, jalavoui said:

this is for testing.

- avx emulation is enabled others are off

- dump unkown opcodes is enabled so we can check what instructions need tobe emulated

 

 

OpcodeEmulator.zip 5.73 MB · 3 downloads

I tested but I see no effects. Where is the dump? In system.log? No.

I still see Invalid instruction launching the utility.

Link to comment
Share on other sites

in system.log should be visible invalid opcodes unless theres a bug in

 

vex_ins()

or
rex_ins()

 

maybe a bug in this first call

 

        //Enable REX Opcode Emulation
        bytes_skip = rex_ins(code_buffer, state, 0);
        
        //Enable VEX Opcode Emulation
        if (bytes_skip == 0) {
            bytes_skip = vex_ins(code_buffer, state, 0);
        }

Edited by jalavoui
Link to comment
Share on other sites

×
×
  • Create New...