VirtualBox

Opened 8 years ago

Closed 8 years ago

#15409 closed defect (worksforme)

MakeAlternativeSource bug

Reported by: gim Owned by:
Component: other Version: VirtualBox 5.0.20
Keywords: MakeAlternativeSource, BIOS, Cc:
Guest type: Linux Host type: all

Description (last modified by Frank Mehnert)

Sometime MakeAlternatioveSource generates bad VBoxBiosAlternative.asm dissassebling:

...
    lea sp, [bp-002h]                         ; 8d 66 fe
    pop bx                                    ; 5b
    pop bp                                    ; 5d
    retn                                      ; c3
    retf                                      ; cb
    xchg di, ax                               ; 97
    xchg di, ax                               ; 97
    cbw                                       ; 98
    fst qword [bx-06808h]                     ; dd 97 f8 97
    xchg di, ax                               ; 97
    cbw                                       ; 98
    and bx, word [bx+si-06769h]               ; 23 98 97 98
    sub byte [bx+si-06794h], bl               ; 28 98 6c 98
    insb                                      ; 6c
    cbw                                       ; 98
    insb                                      ; 6c
    cbw                                       ; 98                      <----- !!!
    cbw                                       ; 67 98                   <----- !!!
    insb                                      ; 6c
    cbw                                       ; 98
    insb                                      ; 6c
    cbw                                       ; 98
    pushaw                                    ; 60
    cbw                                       ; 98
_apm_function:                               ; 0xf97a8 LB 0xf5
    push bp                                   ; 55
    mov bp, sp                                ; 89 e5
    push si                                   ; 56
    and byte [bp+018h], 0feh                  ; 80 66 18 fe
    mov ax, word [bp+012h]                    ; 8b 46 12
    xor ah, ah                                ; 30 e4
    cmp ax, strict word 0000eh                ; 3d 0e 00
    jnbe near 0986ch                          ; 0f 87 b0 00
    mov bx, ax                                ; 89 c3
    add bx, ax                                ; 01 c3
    mov dx, word [bp+018h]                    ; 8b 56 18
...

As you can see here same instructions but different bytes:

cbw ; 98 cbw ; 67 98

Thats because it's not code at all. It's offsets from switch-case table:

BIOS_F:978A CB 97          off_F978A       dw offset loc_F97CB     ; DATA XREF: BIOS_F:97C6r
BIOS_F:978C 97 98                          dw offset loc_F9897
BIOS_F:978E DD 97                          dw offset loc_F97DD
BIOS_F:9790 F8 97                          dw offset loc_F97F8
BIOS_F:9792 97 98                          dw offset loc_F9897
BIOS_F:9794 23 98                          dw offset loc_F9823
BIOS_F:9796 97 98                          dw offset loc_F9897
BIOS_F:9798 28 98                          dw offset loc_F9828
BIOS_F:979A 6C 98                          dw offset loc_F986C
BIOS_F:979C 6C 98                          dw offset loc_F986C
BIOS_F:979E 6C 98                          dw offset loc_F986C
BIOS_F:97A0 67 98                          dw offset loc_F9867
BIOS_F:97A2 6C 98                          dw offset loc_F986C
BIOS_F:97A4 6C 98                          dw offset loc_F986C
BIOS_F:97A6 60 98                          dw offset loc_F9860
BIOS_F:97A8                ; ---------------------------------------------------------------------------
BIOS_F:97A8 55                             push    bp
BIOS_F:97A9 89 E5                          mov     bp, sp
BIOS_F:97AB 56                             push    si
BIOS_F:97AC 80 66 18 FE                    and     byte ptr [bp+18h], 0FEh
BIOS_F:97B0 8B 46 12                       mov     ax, [bp+12h]
BIOS_F:97B3 30 E4                          xor     ah, ah
BIOS_F:97B5 3D 0E 00                       cmp     ax, 0Eh
BIOS_F:97B8 0F 87 B0 00                    ja      loc_F986C
BIOS_F:97BC 89 C3                          mov     bx, ax
BIOS_F:97BE 01 C3                          add     bx, ax
BIOS_F:97C0 8B 56 18                       mov     dx, [bp+18h]
BIOS_F:97C3 80 CA 01                       or      dl, 1
BIOS_F:97C6 2E FF A7 8A 97                 jmp     cs:off_F978A[bx]

It happens because dissasebler just ignore prefix opcode (0x67) for instruction cbw and not fails.

As a result when we build new BIOS by 'kmk update-pcbios-source' VBoxCmp fail with:

VBoxCmp out/linux.amd64/release/obj/VBoxPcBios/VBoxPcBios.rom out/linux.amd64/release/obj/VBoxPcBios/VBoxBiosAlternative.bin
VBoxCmp: 0x0000097a0: 0x67 (103) != 0x98 (152)
VBoxCmp: 0x0000097a1: 0x98 (152) != 0x6c (108)
VBoxCmp: 0x0000097a2: 0x6c (108) != 0x98 (152)
VBoxCmp: 0x0000097a3: 0x98 (152) != 0x6c (108)
VBoxCmp: 0x0000097a4: 0x6c (108) != 0x98 (152)

...

Attachments (1)

workround.patch (925 bytes ) - added by gim 8 years ago.
Workaround patch for switch table

Download all attachments as: .zip

Change History (6)

comment:1 by Frank Mehnert, 8 years ago

Description: modified (diff)

Right, but this is nothing which can be easily fixed.

comment:2 by gim, 8 years ago

Why you generate this disassemble file VBoxBiosAlternative.asm?

Why not just keep binary file VBoxPcBios.rom. And who want to recompile BIOS, must just install OpenWatcom.

comment:3 by Frank Mehnert, 8 years ago

The alternative asm files are a convenience to some Linux folks, for example Debian, who don't agree that the Watcom tools are free. With the alternative .asm files there is at least a theoretical chance to modify+compile the source code without the Watcom tools (I know, not very convenient).

by gim, 8 years ago

Attachment: workround.patch added

Workaround patch for switch table

comment:4 by gim, 8 years ago

Added more workaround to MakeAlternativeSource

Here results:

apm_out_str_:                                ; 0xf976f LB 0x39
    push bp                                   ; 55
    mov bp, sp                                ; 89 e5
    push bx                                   ; 53
    mov bx, ax                                ; 89 c3
    cmp byte [bx], 000h                       ; 80 3f 00
    je short 09784h                           ; 74 0a
    mov al, byte [bx]                         ; 8a 07
    out DX, AL                                ; ee
    inc bx                                    ; 43
    mov al, byte [bx]                         ; 8a 07
    db  00ah, 0c0h
    ; or al, al                                 ; 0a c0
    jne short 0977ch                          ; 75 f8
    lea sp, [bp-002h]                         ; 8d 66 fe
    pop bx                                    ; 5b
    pop bp                                    ; 5d
    retn                                      ; c3
    retf                                      ; cb
    db  097h, 097h, 098h, 0ddh, 097h, 0f8h, 097h, 097h, 098h, 023h, 098h, 097h, 098h, 028h, 098h, 06ch
    db  098h, 06ch, 098h, 06ch, 098h, 067h, 098h, 06ch, 098h, 06ch, 098h, 060h, 098h
_apm_function:                               ; 0xf97a8 LB 0xf5
    push bp                                   ; 55
    mov bp, sp                                ; 89 e5
    push si                                   ; 56
    and byte [bp+018h], 0feh                  ; 80 66 18 fe
    mov ax, word [bp+012h]                    ; 8b 46 12
    xor ah, ah                                ; 30 e4
    cmp ax, strict word 0000eh                ; 3d 0e 00
    jnbe near 0986ch                          ; 0f 87 b0 00
    mov bx, ax                                ; 89 c3
    add bx, ax                                ; 01 c3
    mov dx, word [bp+018h]                    ; 8b 56 18
    or dl, 001h                               ; 80 ca 01
    jmp word [cs:bx-06876h]                   ; 2e ff a7 8a 97

Patch added

comment:5 by Frank Mehnert, 8 years ago

Resolution: worksforme
Status: newclosed

We will apply such patches if necessary. With the current released versions no patch is required.

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use