SOLVED:memory behavior in PMode: VMWare Fusion vs Virtualbox
Posted: Mon Apr 25, 2011 11:33 pm
Hi,
I have a boot code that initializes protected mode without paging and jumps into the protected mode code.
After the switch however I observe weird memory behavior.
When I write to the memory addresses that I get from registers they end up happening near 0x0 address instead of 0x100000.
I have tried hardcoding mov dword [0x100000], reg32 and it does not work.
I've decoded an instruction:
0x83f8: mov %edi,0x100000
EDI at that time was: 0x101001
The instruction bytes are: (gdb) x/6b 0x83f8
0x83f8: 0x89 0x3d 0x00 0x00 0x10 0x00
Unfortunately after it gets executed I get:
(gdb) x/1xw 0
0x0: 0x00101001
(gdb) x/1xw 0x100000
0x100000: 0x00000000
Similar story for mov 0x1337, [0x100000]
(gdb) x/10i $eip-11
0x830a: movl $0x1337,0x100000
0x8314: hlt
(gdb) x/1w 0x100000
0x100000: 0x00000000
(gdb) x/1w 0x00000
0x0: 0x00001337
In VirtualBox it all works fine.
I have populated GDT correctly with standard dummy 4G descriptors with base=0 and limit field with all bits set, for null selector, code, data and stack selectors.
CS is set to code selector, DS, ES, FS, GS are set to data selectors, and SS is set to stack selector.
I have no idea why is VMware Fusion behaving like this.
Here's register dump from gdb:
(gdb) i r
eax 0x100000 1048576
ecx 0xc 12
edx 0x0 0
ebx 0x60 96
esp 0x900 0x900
ebp 0x900 0x900
esi 0xa60 2656
edi 0x9e950000 -1634402304
eip 0x8315 0x8315
eflags 0x200006 2097158
cs 0x8 8
ss 0x18 24
ds 0x10 16
es 0x10 16
fs 0x10 16
gs 0x10 16
I have absolutely no idea what is going on and why is VMware Fusion behaving like this. Any suggestions appreciated.
Here's the the relevant part of the 32-bit code that puts writes to wrong memory locations:
EDIT:
Here are values of GDT in VMware
0xb20: 0x0000000000000000 0x00cf9b000000ffff
0xb30: 0x00cf93000000ffff 0x00cf93000000ffff
I have a boot code that initializes protected mode without paging and jumps into the protected mode code.
After the switch however I observe weird memory behavior.
When I write to the memory addresses that I get from registers they end up happening near 0x0 address instead of 0x100000.
I have tried hardcoding mov dword [0x100000], reg32 and it does not work.
I've decoded an instruction:
0x83f8: mov %edi,0x100000
EDI at that time was: 0x101001
The instruction bytes are: (gdb) x/6b 0x83f8
0x83f8: 0x89 0x3d 0x00 0x00 0x10 0x00
Unfortunately after it gets executed I get:
(gdb) x/1xw 0
0x0: 0x00101001
(gdb) x/1xw 0x100000
0x100000: 0x00000000
Similar story for mov 0x1337, [0x100000]
(gdb) x/10i $eip-11
0x830a: movl $0x1337,0x100000
0x8314: hlt
(gdb) x/1w 0x100000
0x100000: 0x00000000
(gdb) x/1w 0x00000
0x0: 0x00001337
In VirtualBox it all works fine.
I have populated GDT correctly with standard dummy 4G descriptors with base=0 and limit field with all bits set, for null selector, code, data and stack selectors.
CS is set to code selector, DS, ES, FS, GS are set to data selectors, and SS is set to stack selector.
I have no idea why is VMware Fusion behaving like this.
Here's register dump from gdb:
(gdb) i r
eax 0x100000 1048576
ecx 0xc 12
edx 0x0 0
ebx 0x60 96
esp 0x900 0x900
ebp 0x900 0x900
esi 0xa60 2656
edi 0x9e950000 -1634402304
eip 0x8315 0x8315
eflags 0x200006 2097158
cs 0x8 8
ss 0x18 24
ds 0x10 16
es 0x10 16
fs 0x10 16
gs 0x10 16
I have absolutely no idea what is going on and why is VMware Fusion behaving like this. Any suggestions appreciated.
Here's the the relevant part of the 32-bit code that puts writes to wrong memory locations:
Code: Select all
bits 32
.text
align 4
default_isr:
iret
align 4
start32:
;; Reload selectors from GDT.
mov ax, DATA_SELECTOR
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, STACK_SELECTOR
mov ss, ax
;; Save ECX as SMAP entry count variable passed
;; in from real mode, and EBX as largest entry offset
mov dword [MemRegions], ecx
mov eax, DATA_SEG
shl eax, 4
add eax, ebx
mov dword [LargestMemRegionAddr], eax
;; Set up stack in such a way that
;; we reuse a memory region
;; from a real mode stack
mov ebp, STACK_SEG
shl ebp, 4
add ebp, esp
mov esp, ebp
;; Now in protected 32-bit mode without paging.
mov dword [0x100000], 0x1337
hlt
jmp $
Here are values of GDT in VMware
0xb20: 0x0000000000000000 0x00cf9b000000ffff
0xb30: 0x00cf93000000ffff 0x00cf93000000ffff