Page 1 of 1

Bochs invalidates SS when restored

Posted: Fri Mar 11, 2011 9:30 am
by stranger
Hi, It seems that bochs invalidates SS (sregs[2]->cache.valid=0) and any other register with selector->value & 0xfffc) == 0 in bx_cpu_c::param_restore_handler, thus simulation states before and after restore doesn't match.

Example:
before

Code: Select all

es:0xf000, dh=0x0000930f, dl=0x0000ffff, valid=1
        Data segment, base=0x000f0000, limit=0x0000ffff, Read/Write, Accessed
cs:0x9000, dh=0x00009309, dl=0x0000ffff, valid=1
        Data segment, base=0x00090000, limit=0x0000ffff, Read/Write, Accessed
ss:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
        Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
ds:0x0000, dh=0x00009300, dl=0x0000ffff, valid=1
        Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
fs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
        Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
gs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
        Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
ldtr:0x0000, dh=0x00008200, dl=0x0000ffff, valid=1
tr:0x0000, dh=0x00008b00, dl=0x0000ffff, valid=1
gdtr:base=0x00000000, limit=0xffff
idtr:base=0x00000000, limit=0xffff
after

Code: Select all

es:0xf000, dh=0x0000930f, dl=0x0000ffff, valid=1
        Data segment, base=0x000f0000, limit=0x0000ffff, Read/Write, Accessed
cs:0x9000, dh=0x00009309, dl=0x0000ffff, valid=1
        Data segment, base=0x00090000, limit=0x0000ffff, Read/Write, Accessed
ss:0x0000, dh=0x00009300, dl=0x0000ffff, valid=0
ds:0x0000, dh=0x00009300, dl=0x0000ffff, valid=0
fs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=0
gs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=0
ldtr:0x0000, dh=0x00008200, dl=0x0000ffff, valid=0
tr:0x0000, dh=0x00008b00, dl=0x0000ffff, valid=0
gdtr:base=0x00000000, limit=0xffff
idtr:base=0x00000000, limit=0xffff
I would like to know why. Thanks

Re: Bochs invalidates SS when restored

Posted: Fri Mar 11, 2011 10:26 am
by bewing
Because it's a bug. :wink:
Congrats, you found one. Stanislav will be along soon, and see this thread, and fix it.

Re: Bochs invalidates SS when restored

Posted: Fri Mar 11, 2011 1:52 pm
by stlw
stranger, you are running real mode, right ?

Bochs doesn't save the valid bit and tries to guess it when restoring the selector.
When simulating protected mode the currect behavior is correct, but in real or v8086 mode looks like it is not ...

Stanislav

Re: Bochs invalidates SS when restored

Posted: Mon Mar 14, 2011 9:47 am
by Gigasoft
It's necessary to save the entire descriptor cache including the valid bit. SS may have been 0 when entering protected mode. Then, when saving and restoring it would become invalid.