Menu

Solaris 10 Sparc host: core dumped

Help
2018-08-04
2018-08-25
  • Michele Denber

    Michele Denber - 2018-08-04

    I installed bochs on a Solaris 10 Sparc machine using .conf.sparc. I also put

    ata0-master: type=disk, mode=flat, path="/export/home/denber/bochs-2.6/freedos-img/a.img"

    in .boschrc. Then:

    # ./bochs
    ========================================================================
                            Bochs x86 Emulator 2.6
                Built from SVN snapshot on September 2nd, 2012
                      Compiled on Aug  3 2018 at 17:12:39
    ========================================================================
    00000000000i[     ] reading configuration from .bochsrc
    00000000000e[     ] .bochsrc:504: ataX-master/slave CHS set to 0/0/0 - autodetection enabled
    ------------------------------
    Bochs Configuration: Main Menu
    ------------------------------
    
    This is the Bochs Configuration Interface, where you can describe the
    machine that you want to simulate.  Bochs has already searched for a
    configuration file (typically called bochsrc.txt) and loaded it if it
    could be found.  When you are satisfied with the configuration, go
    ahead and start the simulation.
    
    You can also start bochs with the -q option to skip these menus.
    
    1. Restore factory default configuration
    2. Read options from...
    3. Edit options
    4. Save options to...
    5. Restore the Bochs state from...
    6. Begin simulation
    7. Quit now
    
    Please choose one: [6]
    00000000000i[     ] installing x module as the Bochs GUI
    00000000000i[     ] using log file bochsout.txt
    Bus Error - core dumped
    #
    

    boschsout.txt is:

    # more bochsout.txt
    00000000000i[     ] Bochs x86 Emulator 2.6
    00000000000i[     ]   Built from SVN snapshot on September 2nd, 2012
    00000000000i[     ] Compiled on Aug  3 2018 at 17:12:39
    00000000000i[     ] System configuration
    00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
    00000000000i[     ]   A20 line support: yes
    00000000000i[     ] IPS is set to 4000000
    00000000000i[     ] CPU configuration
    00000000000i[     ]   level: 6
    00000000000i[     ]   SMP support: no
    00000000000i[     ]   APIC support: xapic
    00000000000i[     ]   FPU support: yes
    00000000000i[     ]   MMX support: yes
    00000000000i[     ]   3dnow! support: no
    00000000000i[     ]   SEP support: yes
    00000000000i[     ]   SSE support: sse2
    00000000000i[     ]   XSAVE support: no
    00000000000i[     ]   AES support: no
    00000000000i[     ]   MOVBE support: no
    00000000000i[     ]   ADX support: no
    00000000000i[     ]   x86-64 support: yes
    00000000000i[     ]   1G paging support: no
    00000000000i[     ]   MWAIT support: yes
    00000000000i[     ] Optimization configuration
    00000000000i[     ]   RepeatSpeedups support: yes
    00000000000i[     ]   Fast function calls: yes
    00000000000i[     ]   Handlers Chaining speedups: yes
    00000000000i[     ] Devices configuration
    00000000000i[     ]   NE2000 support: yes
    00000000000i[     ]   PCI support: yes, enabled=yes
    00000000000i[     ]   SB16 support: no
    00000000000i[     ]   USB support: yes
    00000000000i[     ]   VGA extension support: vbe cirrus
    00000000000i[MEM0 ] allocated memory at 1fac8d0. after alignment, vector=1fad000
    00000000000i[MEM0 ] 256.00MB
    00000000000i[MEM0 ] mem block size = 0x00100000, blocks=256
    00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('/export/home/denber/bochs-2.6/bios/BIOS-bochs-latest')
    00000000000i[     ] init_dev of 'pci' plugin device by virtual method
    00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
    00000000000i[     ] init_dev of 'pci2isa' plugin device by virtual method
    00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
    00000000000i[     ] init_dev of 'cmos' plugin device by virtual method
    00000000000i[CMOS ] Using local time for initial clock
    00000000000i[CMOS ] Setting initial clock to: Fri Aug  3 20:11:03 2018 (time0=1533341463)
    00000000000i[     ] init_dev of 'dma' plugin device by virtual method
    00000000000i[DMA  ] channel 4 used by cascade
    00000000000i[     ] init_dev of 'pic' plugin device by virtual method
    00000000000i[     ] init_dev of 'pit' plugin device by virtual method
    00000000000i[     ] init_dev of 'floppy' plugin device by virtual method
    00000000000i[DMA  ] channel 2 used by Floppy Drive
    00000000000i[     ] init_dev of 'vga' plugin device by virtual method
    00000000000i[MEM0 ] Register memory access handlers: 0x00000000000a0000 - 0x00000000000bffff
    00000000000i[VGA  ] interval=200000
    00000000000i[MEM0 ] Register memory access handlers: 0x00000000e0000000 - 0x00000000e0ffffff
    00000000000i[BXVGA] VBE Bochs Display Extension Enabled
    00000000000i[XGUI ] test_alloc_colors: 16 colors available out of 16 colors tried
    00000000000i[XGUI ] font 8 wide x 16 high, display depth = 24
    00000000000i[MEM0 ] rom at 0xc0000/41472 ('/export/home/denber/bochs-2.6/bios/VGABIOS-lgpl-latest')
    00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
    00000000000i[PCI  ] ACPI Controller present at device 1, function 3
    00000000000i[     ] init_dev of 'ioapic' plugin device by virtual method
    00000000000i[IOAP ] initializing I/O APIC
    00000000000i[MEM0 ] Register memory access handlers: 0x00000000fec00000 - 0x00000000fec00fff
    00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
    00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
    00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
    00000000000i[HD   ] HD on ata0-0: '/export/home/denber/bochs-2.6/freedos-img/a.img', 'flat' mode00000000000i[IMG  ] hd_size: 1474560
    00000000000i[HD   ] ata0-0: autodetect geometry: CHS=2/16/63
    00000000000i[HD   ] ata0-0: extra data outside of CHS address range
    00000000000i[HD   ] translation on ata0-0 set to 'none'
    00000000000i[HD   ] Using boot sequence disk, none, none
    00000000000i[HD   ] Floppy boot signature check is enabled
    00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
    00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
    00000000000i[     ] init_dev of 'unmapped' plugin device by virtual method
    00000000000i[     ] init_dev of 'biosdev' plugin device by virtual method
    00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
    00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
    00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
    00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
    00000000000i[     ] init_dev of 'serial' plugin device by virtual method
    00000000000i[SER  ] com1 at 0x03f8 irq 4
    00000000000i[     ] register state of 'pci' plugin device by virtual method
    00000000000i[     ] register state of 'pci2isa' plugin device by virtual method
    00000000000i[     ] register state of 'cmos' plugin device by virtual method
    00000000000i[     ] register state of 'dma' plugin device by virtual method
    00000000000i[     ] register state of 'pic' plugin device by virtual method
    00000000000i[     ] register state of 'pit' plugin device by virtual method
    00000000000i[     ] register state of 'floppy' plugin device by virtual method
    00000000000i[     ] register state of 'vga' plugin device by virtual method
    00000000000i[     ] register state of 'unmapped' plugin device by virtual method
    00000000000i[     ] register state of 'biosdev' plugin device by virtual method
    00000000000i[     ] register state of 'speaker' plugin device by virtual method
    00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
    00000000000i[     ] register state of 'parallel' plugin device by virtual method
    00000000000i[     ] register state of 'serial' plugin device by virtual method
    00000000000i[     ] register state of 'acpi' plugin device by virtual method
    00000000000i[     ] register state of 'ioapic' plugin device by virtual method
    00000000000i[     ] register state of 'keyboard' plugin device by virtual method
    00000000000i[     ] register state of 'harddrv' plugin device by virtual method
    00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
    00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
    00000000000i[CPU0 ] cpu hardware reset
    00000000000i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x00000000fee00000
    00000000000i[CPU0 ] CPUID[0x00000000]: 00000002 756e6547 6c65746e 49656e69
    00000000000i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00002008 1fcbfbff
    00000000000i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
    00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
    00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100000
    00000000000i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
    00000000000i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
    00000000000i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
    00000000000i[CPU0 ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140
    00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
    00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
    00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
    00000000000i[     ] reset of 'pci' plugin device by virtual method
    00000000000i[     ] reset of 'pci2isa' plugin device by virtual method
    00000000000i[     ] reset of 'cmos' plugin device by virtual method
    00000000000i[     ] reset of 'dma' plugin device by virtual method
    00000000000i[     ] reset of 'pic' plugin device by virtual method
    00000000000i[     ] reset of 'pit' plugin device by virtual method
    00000000000i[     ] reset of 'floppy' plugin device by virtual method
    00000000000i[     ] reset of 'vga' plugin device by virtual method
    00000000000i[     ] reset of 'acpi' plugin device by virtual method
    00000000000i[     ] reset of 'ioapic' plugin device by virtual method
    00000000000i[     ] reset of 'keyboard' plugin device by virtual method
    00000000000i[     ] reset of 'harddrv' plugin device by virtual method
    00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
    00000000000i[     ] reset of 'unmapped' plugin device by virtual method
    00000000000i[     ] reset of 'biosdev' plugin device by virtual method
    00000000000i[     ] reset of 'speaker' plugin device by virtual method
    00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
    00000000000i[     ] reset of 'parallel' plugin device by virtual method
    00000000000i[     ] reset of 'serial' plugin device by virtual method
    00000000000i[XGUI ] Mouse capture off
    #
    

    What could this be about?

     
  • Stanislav Shwartsman

    This is 6-years old binary of Bochs. Would you like to try latest one first ?

     
  • Michele Denber

    Michele Denber - 2018-08-04

    Oops. Good catch! Don't know how I picked that up. So I downloaded 2.6.9 and tried again. This is on a Sun Oracle Enterprise M3000 with 2.75 GHz. quad core SPARC64 VII running Solaris 10U11, Opencsw toolchain and gcc 7.3.0.

    ./.config-sparc failed with that "C compiler doesn't work" error so I just ran

    # ./configure --enable-ne2000 \
            --enable-all-optimizations \
                --enable-cpu-level=6 \
                --enable-x86-64 \
                --enable-pci \
             --enable-clgd54xx \
            --enable-usb 
    

    That completed successfully as did gmake. But when I did gmake install I got:

    ...
    cd iodev/network && \
    gmake  libnetwork.a
    gmake[1]: Entering directory '/export/home/denber/bochs-2.6.9/iodev/network'
    g++ -c  -I.. -I../.. -I./.. -I./../.. -I../../instrument/stubs -I./../../instrument/stubs  -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_REENTRANT -pthread    eth_socket.cc -o eth_socket.o
    eth_socket.cc:86:10: fatal error: netpacket/packet.h: No such file or directory
    

    The only match I have on this machine for packet.h is:
    /opt/SUNWrtvc/examples/rtvc_video_conference/packet.h
    so I fed that to eth_socket.cc. I don't know if that's the right file but we continued on. Then,

    ...
    cd iodev/network && \
    gmake  libnetwork.a
    gmake[1]: Entering directory '/export/home/denber/bochs-2.6.9/iodev/network'
    g++ -c  -I.. -I../.. -I./.. -I./../.. -I../../instrument/stubs -I./../../instrument/stubs  -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_REENTRANT -pthread    eth_socket.cc -o eth_socket.o
    eth_socket.cc:89:10: fatal error: net/ethernet.h: No such file or directory
    

    I have that here:
    /usr/include/sys/ethernet.h
    so I fed that to eth_socket.cc. Then,

    ...
    gmake  libnetwork.a
    gmake[1]: Entering directory '/export/home/denber/bochs-2.6.9/iodev/network'
    g++ -c  -I.. -I../.. -I./.. -I./../.. -I../../instrument/stubs -I./../../instrument/stubs  -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_REENTRANT -pthread    eth_socket.cc -o eth_socket.o
    eth_socket.cc:92:10: fatal error: linux/types.h: No such file or directory
    

    Now I'm stuck. I have no linux/types.h anywhere. A net search for this file came up empty. Is this something that can be fixed with config options? Or am I doing something else wrong now?

     
  • Stanislav Shwartsman

    Do you really need the network card ?
    Does it compile without --enable-ne2000 ?

     
  • Michele Denber

    Michele Denber - 2018-08-04

    If network card means that it gives my emulated machine access to the Internet, then yes, that would be extremely useful. So I removed the --enable-ne2000 line and ran ./configure again.

    Then I had to make a few changes:
    gui/x.cc needed a full path for:
    #include </usr/X11/include/X11/extensions/Xrandr.h>

    Then I was getting linker problems with:

    Undefined                       first referenced
     symbol                             in file
    XFree                               gui/libgui.a(x.o)  (symbol belongs to implicit dependency /usr/openwin/lib/libX11.so.4)
    ...and many more
    

    despite my having that library in LD_LIBRARY_PATH. I finally gave up and added: /usr/openwin/lib/libX11.so.4 \
    after line 182 in Makefile (where it's doing "gcc bochs").

    Then gmake finished. I ran

    ./bochs

    and got a pop-up PANIC with:

    Bochs is exiting with the following message:
    [HD    ] ata0-0: could not open hard drive image file '/export/home/denber/bochs-2.6.9/images/fdos-10meg/fdosmini.img'
    

    But

    # pwd
    /export/home/denber/bochs-2.6.9/images/fdos-10meg
    # ls -l
    total 20243
    -rw-r-----   1 1000     tomcat      1074 Aug  4  2013 bochsrc.txt
    -rw-r-----   1 1000     tomcat   10321920 Aug  4  2013 fdosmini.img
    -rw-r-----   1 root     root           0 Aug  4 15:15 fdosmini.img.lock
    -rw-r--r--   1 1000     tomcat       642 Apr  2  2005 README
    

    and .bochsrc contains
    ata0-master: type=disk, mode=flat, path="/export/home/denber/bochs-2.6.9/images/fdos-10meg/fdosmini.img"

    So I tried debian, figuring maybe the first img file was defective:

    ata0-master: type=disk, mode=flat, path="/export/home/denber/bochs-2.6.9/images/debian-3.0r0/debian-3.0r0.img"

    Please choose one: [6]
    00000000000i[      ] installing x module as the Bochs GUI
    00000000000i[      ] using log file bochsout.txt
    Bus Error - core dumped
    #
    

    bochsout.txt attached (it's pretty long). It's odd - this time it didn't complain about the img file not being found, it just croaked. (Edit: But if I restart bochs again, this time I do get the "file not found" error).

    So at least I'm now getting the bochs window appearing, but I must still be doing something wrong.

    Oh, and I figured out why I got 2.6 the first time. If you first visit
    https://sourceforge.net/projects/bochs/files/Disk%20Images/FreeDos/
    it says that 2.6 is the "Latest Version".

     

    Last edit: Michele Denber 2018-08-04
  • Volker Ruppert

    Volker Ruppert - 2018-08-05

    Bochs 2.6.9 creates a file with extension ".lock" to avoid opening the same image twice in read/write mode. If Bochs crashes it might be necessary to manually remove these file that Bochs usually removes on normal exit. In SVN I have added the command line option '-unlock' to simplify this.

     
  • Michele Denber

    Michele Denber - 2018-08-05

    Thanks but that didn't fix it. I removed the lock file and ran ./bochs again. The gui window appeared and after about five seconds it crashed.

    ...
    Please choose one: [6]
    00000000000i[      ] installing x module as the Bochs GUI
    00000000000i[      ] using log file bochsout.txt
    Bus Error - core dumped
    

    The "can't open file" message only pops up if the lock file exists. Otherwise, it just dumps core.

    If it matters, in .bochsrc I have

    ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
    ata0-master: type=disk, mode=flat, path="/export/home/denber/bochs-2.6.9/images/fdos-10meg/fdosmini.img"
    
     
  • Michele Denber

    Michele Denber - 2018-08-05

    Well figuring that "core dumped" isn't a particularly illuminating error message, I recompiled with gdb.

    ./configure --enable-gdb-stub \
            --enable-all-optimizations \
                --enable-cpu-level=6 \
                --enable-x86-64 \
                --enable-pci \
             --enable-clgd54xx \
            --enable-usb 
    

    Does this help any?

    ...
    Please choose one: [6]
    00000000000i[      ] installing x module as the Bochs GUI
    00000000000i[      ] using log file bochsout.txt
    
    Program received signal SIGSEGV, Segmentation fault.
    0x001604c8 in FetchWORD(unsigned char const*) ()
    (gdb) bt
    #0  0x001604c8 in FetchWORD(unsigned char const*) ()
    #1  0x0015d7e0 in decodeImmediate32(unsigned char const*, unsigned int&, bxInstruction_c*, unsigned int, unsigned int) ()
    #2  0x0015f0a0 in decoder32(unsigned char const*, unsigned int&, bxInstruction_c*, unsigned int, unsigned int, BxOpcodeInfo_t const*) ()
    #3  0x0015f628 in fetchDecode32(unsigned char const*, unsigned int, unsigned int, bxInstruction_c*, unsigned int) ()
    #4  0x0015c0d4 in BX_CPU_C::serveICacheMiss(unsigned int, unsigned long long) ()
    #5  0x00159a58 in BX_CPU_C::getICacheEntry() ()
    #6  0x00159744 in BX_CPU_C::cpu_loop() ()
    #7  0x0007773c in bx_begin_simulation(int, char**) ()
    #8  0x00222940 in bx_real_sim_c::begin_simulation(int, char**) ()
    #9  0x0022d770 in bx_text_config_interface(int) ()
    #10 0x0022dc40 in bx_text_config_interface(int) ()
    #11 0x00231a58 in ci_callback(void*, ci_command_t) ()
    #12 0x002228e8 in bx_real_sim_c::configuration_interface(char const*, ci_command_t) ()
    #13 0x00075978 in bxmain() ()
    #14 0x00075a58 in main ()
    (gdb) list
    530     #if !defined(__WXMSW__)
    531     // normal main function, presently in for all cases except for
    532     // wxWidgets under win32.
    533     int CDECL main(int argc, char *argv[])
    534     {
    535       bx_startup_flags.argc = argc;
    536       bx_startup_flags.argv = argv;
    537     #ifdef WIN32
    538       int arg = 1;
    539       bx_bool bx_noconsole = 0;
    (gdb)
    
     

    Last edit: Michele Denber 2018-08-05
  • Stanislav Shwartsman

    This is mine :)

    But unfortunatelly it is hard to debug over e-mail and try to understand what is going on removte host through partial gdb messages ... This regular CPU emulation flow, new instruction is fetched and decoded and segfault is occured during attemp to fetch next byte of the opcode. Should never happen of course and I never saw such failures. Unfortunatelly no line numbers available and no more debug information so I can't help that much.

    Is SPARC big endian host ? We actually never did testing of Bochs on big endian machines.

    Can suggest only to try 2.6.8 official release sources. This code (new decoder) was not present yet in 2.6.8 and you may get lucky and not fail.

    Not sure how can I help better. You probably will have to find a way to debug the case further locally and send more information, if you can.

    Stanislav

     
  • Michele Denber

    Michele Denber - 2018-08-06

    Is SPARC big endian host

    Yes.

    Can suggest only to try 2.6.8 official release sources.

    Unfortunately, 2.6.8 dumps core too. The gui window opens, and then:

    ...
    Please choose one: [6]
    00000000000i[      ] installing x module as the Bochs GUI
    00000000000i[      ] using log file bochsout.txt
    Bus Error - core dumped
    #
    

    At least it didn't complain about compiling with ne2000 configured in. I should add that the gui window comes up empty. In the 2.6 version I first tried, the window included a menu bar up top. So it's dying before that gets drawn.

    Not sure how can I help better.

    You are more than welcome to an account on my machine if you'd like. I doubt I'll be able to figure this out on my own.

     

    Last edit: Michele Denber 2018-08-06
  • Stanislav Shwartsman

    Hi, I cactually have an idea which can screen out a lot of issues.
    In latest SVN I have option to compile decoder stand-alone, without Bochs. When you can use it as stand-alone decoder/disassembler. I wrote simple opcode bytes generator in perl which generates all possible opcodes in Intel x86 opcode space (except VEX and EVEX yet). You can compile and run it on your big endian host and also on some Intel host and compare the output.
    This would tell immediatelly if decoder has a problem on BE hosts.
    I'll send you a test program tomorrow morning.

     
  • Stanislav Shwartsman

    #include <stdio.h>
    #include <assert.h>
    #include <vector>
    
    using namespace std;
    
    #define X 0 /* undefined opcode */
    
    static const unsigned char hasmodrm32[512] = {
      /*       0 1 2 3 4 5 6 7 8 9 a b c d e f          */
      /*       -------------------------------          */
      /* 00 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,X,
      /* 10 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
      /* 20 */ 1,1,1,1,0,0,X,0,1,1,1,1,0,0,X,0,
      /* 30 */ 1,1,1,1,0,0,X,0,1,1,1,1,0,0,X,0,
      /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* 60 */ 0,0,1,1,X,X,X,X,0,1,0,1,0,0,0,0,
      /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* 80 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
      /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* A0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* B0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* C0 */ 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
      /* D0 */ 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,
      /* E0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      /* F0 */ X,0,X,X,0,0,1,1,0,0,0,0,0,0,1,1,
      /*       0 1 2 3 4 5 6 7 8 9 a b c d e f           */
      /*       -------------------------------           */
               1,1,1,1,X,0,0,0,0,0,X,0,X,1,0,1, /* 0F 00 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 10 */
               1,1,1,1,1,X,1,X,1,1,1,1,1,1,1,1, /* 0F 20 */
               0,0,0,0,0,0,X,X,1,X,1,X,X,X,X,X, /* 0F 30 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 40 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 50 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 60 */
               1,1,1,1,1,1,1,0,1,1,X,X,1,1,1,1, /* 0F 70 */
               0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0F 80 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 90 */
               0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1, /* 0F A0 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F B0 */
               1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* 0F C0 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F D0 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F E0 */
               1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,X  /* 0F F0 */
      /*       -------------------------------           */
      /*       0 1 2 3 4 5 6 7 8 9 a b c d e f           */
    };
    
    static unsigned prefixes[] = { 0x66, 0x67, 0xf2, 0xf3, 0x26, 0x2e, 0x36, 0x3e, 0x64, 0x65, 0xf0, 0xffffffff };
    const unsigned numprefixes = sizeof(prefixes)/sizeof(unsigned);
    
    typedef unsigned char byte;
    
    vector<byte> opcode_to_string(unsigned opcode)
    { 
        vector<byte> opcode_string;
    
        if (opcode <= 0xff) {
            opcode_string.push_back(opcode);
        }
        else if (opcode <= 0x1ff) {
            opcode_string.push_back(0x0f);
            opcode_string.push_back(opcode & 0xff);
        }
        else if (opcode <= 0x2ff) {
            opcode_string.push_back(0x0f);
            opcode_string.push_back(0x38);
            opcode_string.push_back(opcode & 0xff);
        }
        else if (opcode <= 0x3ff) {
            opcode_string.push_back(0x0f);
            opcode_string.push_back(0x3a);
            opcode_string.push_back(opcode & 0xff);
        }
        return opcode_string; // empty
    }
    
    bool is_prefix(unsigned op)
    {
        if (op >= 256) return false;
    
        for(unsigned i=0;i<numprefixes;i++)
            if (prefixes[i] == op) return true;
    
        return false;
    }
    
    void test_no_modrm(unsigned op);
    void test_modrm(unsigned op);
    void test_modrm_forms(const vector<byte> &opcode_string);
    
    void dump(const vector<byte> &op)
    {
        unsigned char dummy[16] = { 0x12, 0x34, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00, 0xED, 0xCB, 0xA9, 0x87, 0x54, 0x32, 0xFF };
    
        for (unsigned i=0;i<op.size();i++) {
            printf("0x%02x,", op[i]);
        }
    
        if (op.size() < 16) {
            for (unsigned i=op.size();i<16;i++) {
                printf("0x%02x,", dummy[i]);
            }
        }
        printf("\n");
    }
    
    int main(void)
    {
    //  printf("numprefixes=%d\n", numprefixes);
    
        // for each opcode
        for (unsigned op=0; op<1024; op++) {
            if (is_prefix(op) || op == 0x0f || op == 0x138 || op == 0x13a) continue;
            printf("//==== printing opcode %02x\n", op);
            unsigned char hasmodrm = hasmodrm32[op] || op >= 0x1ff;
            if (hasmodrm) {
                test_modrm(op);
            }
            else {
                test_no_modrm(op);
            }
        }
    }
    
    void test_modrm(unsigned op)
    {
        vector<byte> opcode = opcode_to_string(op);
    
        for (unsigned i=0;i<numprefixes;i++) {
            vector<byte> opcode_string = opcode_to_string(prefixes[i]);
            opcode_string.insert(opcode_string.end(), opcode.begin(), opcode.end());
            test_modrm_forms(opcode_string);
        }
    }
    
    void test_no_modrm(unsigned op)
    {
        vector<byte> opcode = opcode_to_string(op);
    
        for (unsigned i=0;i<numprefixes;i++) {
            vector<byte> opcode_string = opcode_to_string(prefixes[i]);
            opcode_string.insert(opcode_string.end(), opcode.begin(), opcode.end());
            dump(opcode_string);
        }
    }
    
    void test_modrm_forms(const vector<byte> &opcode_string)
    {
        // no mem form
        for(unsigned i=0;i<64;i++) {
            vector<byte> op(opcode_string);
            op.push_back(0xc0 | i);
            dump(op);
        }
    
        // mem form, rm =  4 => sib mode
        // mem form, rm != 4, try mod=00,01,10
        for (unsigned mod = 0; mod < 3; mod++) {
            for (unsigned rm = 0; rm < 8; rm++) {
    //          if (rm == 4) continue;
                for (unsigned nnn = 0; nnn < 8; nnn++) {
                    unsigned modrm = (mod << 6) | (nnn << 3) | rm;
                    vector<byte> op(opcode_string);
                    op.push_back(modrm);
                    dump(op);
                }
            }
        }
    }
    

    Don't judge that code, it was written in 5 minutes :)
    But it does the job - it produces all possible valid x86 opcodes into single text file.

     
  • Stanislav Shwartsman

    Now see version of bx_disasm_new which is disasming all the testset producing by previous script:

    /////////////////////////////////////////////////////////////////////////
    // $Id: bxdisasm_new.cc 13391 2017-12-13 20:27:02Z sshwarts $
    /////////////////////////////////////////////////////////////////////////
    //
    //   Copyright (c) 2014-2017 Stanislav Shwartsman
    //          Written by Stanislav Shwartsman [sshwarts at sourceforge net]
    //
    //  This library is free software; you can redistribute it and/or
    //  modify it under the terms of the GNU Lesser General Public
    //  License as published by the Free Software Foundation; either
    //  version 2 of the License, or (at your option) any later version.
    //
    //  This library is distributed in the hope that it will be useful,
    //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    //  Lesser General Public License for more details.
    //
    //  You should have received a copy of the GNU Lesser General Public
    //  License along with this library; if not, write to the Free Software
    //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
    /////////////////////////////////////////////////////////////////////////
    
    // Compile using:
    // g++ -I. -I./instrument/stubs -DBX_STANDALONE_DECODER bxdisasm_new.cc cpu/decoder/*.cc -o bxdisasm
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    #include "config.h"
    #include "cpu/decoder/instr.h"
    
    unsigned char testset[] = {
    #include "testset.h"
    };
    
    unsigned char char2byte(unsigned char input)
    {
      if(input >= '0' && input <= '9')
        return input - '0';
      if(input >= 'A' && input <= 'F')
        return input - 'A' + 10;
      if(input >= 'a' && input <= 'f')
        return input - 'a' + 10;
    
      return 0; // wrong input, ignore
    }
    
    // This function assumes src to be a zero terminated sanitized string with
    // an even number of [0-9a-f] characters, and target to be sufficiently large
    void hex2bin(Bit8u* target, const char* src, unsigned len)
    {
      while(len >= 2 && src[0] && src[1])
      {
        *(target++) = (unsigned) char2byte(src[0])*16 + (unsigned) char2byte(src[1]);
        src += 2;
        len -= 2;
      }
    }
    
    extern char* disasm(const Bit8u *opcode, bool is_32, bool is_64, char *disbufptr, bxInstruction_c *i, bx_address cs_base = 0, bx_address rip = 0);
    
    int main(int argn, const char **argv)
    {
      char disbuf[256];
      bx_bool is_32 = 1, is_64 = 0, silent=0;
    
      if (argn < 2)
      {
        printf("Usage: bxdisasm [-16|-32|-64]\n");
        exit(1);
      }
    
      for (unsigned i=1;i<argn;i++) {
        if (!strcmp(argv[i], "/16")) {
          is_32 = 0;
          is_64 = 0;
          printf("16 bit mode\n");
          continue;
        }
        if (!strcmp(argv[i], "/32")) {
          is_32 = 1;
          is_64 = 0;
          printf("32 bit mode\n");
          continue;
        }
        if (!strcmp(argv[i], "/64")) {
          is_32 = 1;
          is_64 = 1;
          printf("64 bit mode\n");
          continue;
        }
    
        if (!strcmp(argv[i], "/silent")) {
          silent = 1;
        }
      }
    
      unsigned char *ibuf = &testset[0];
    
      for (unsigned n=0; n<sizeof(testset)/16;n++) {
          if (!silent) {
              printf("instruction bytes:");
              for (unsigned i=0;i<16;i++)
                printf("%02x", ibuf[i]);
          }
    
          bxInstruction_c i;
          disasm(ibuf, is_32, is_64, disbuf, &i, 0, 0);
          if (! silent) {
              printf(" : %s\n", disbuf);
          }
    
          ibuf+=16;
      }
    }
    

    Place into testset.h output of previous script.

     
  • Wes Fisher

    Wes Fisher - 2018-08-25

    I'm having a very similar issue porting 2.6.8 to Irix 6.5 (yes, people still use it. There is an active hobbyist community). It compiles fine, but dumps core after the window opens. I'm not sure how to go about finding out why. The only difference is I had to compile it with SDL as Xsgi doesn't have Xrandr. Ideas?

     

Log in to post a comment.