captainys / TOWNSEMU

FM Towns Emulator "Tsugaru"
BSD 3-Clause "New" or "Revised" License
247 stars 18 forks source link

CMPXCHG not emulated #127

Open jckarter opened 3 months ago

jckarter commented 3 months ago

For fun, I tried building a recent Linux 6.9 kernel using Osamu Kurati's FM TOWNS patchset (http://www.nurs.or.jp/~kurati/towns/#kernel) When trying to boot it in Tsugaru, the VM halts on an unhandled instruction:

VM Aborted!
Device:486DX
Reason:Clocks-Passed is not set.  Opcode=0FB1H
Debugger Enabled.
Towns TIME (Nano-Seconds): 59267737955
CS:EIP=0060:C1422CB3  LINEAR:C1422CB3  EFLAGS=00000046  CPL=00
EAX=00000000  EBX=C16A8DB0  ECX=FFFFFFFB  EDX=C15C27C0
ESI=00000000  EDI=00000001  EBP=C15B7F5C  ESP=C15B7F58
CS=0060(LIN:00000000)  DS=007B(LIN:00000000)  ES=007B(LIN:00000000)  
FS=0000(LIN:00000000)  GS=0000(LIN:00000000)  SS=0068(LIN:00000000)  
CR0=80050033  CR1=00000000  CR2=00000000  CR3=0175B000
CF0  PF1  AF0  ZF1  SF0  TF0  IF0  DF0  OF0  IOPL00  NT0  RF0  VM0  AC0
Default Operand Size=32  Default Address Size=32  Stack Address Size=32
SS+00000000:A0 43 5D C1 70 7F 5B C1 B4 91 72 C1 A0 43 5D C1 
SS+00000010:00 00 00 00 63 32 54 C1 84 7F 5B C1 7D 93 72 C1 
0060:C1422CB3 0FB1                      

0FB1 is the encoding for CMPXCHG according to https://www.felixcloutier.com/x86/cmpxchg .

captainys commented 3 months ago

Interesting! Thank you for testing! I've added support for CMPXCHG in the latest source. But, I cannot test in my environment if it is correct. Let me know if it makes your Linux kernel run!

jckarter commented 3 months ago

Nice, thanks! I'll give it a try when the next binary gets tagged.