Author: hbelusca
Date: Sun Feb 23 20:40:09 2014
New Revision: 62312
URL:
http://svn.reactos.org/svn/reactos?rev=62312&view=rev
Log:
[NTVDM]
- BIOS location must be aligned on 32bit boundaries (or 16, I have to check). This fixes
BIOS images loading when they miss a (null) byte to make them (e.g.) 8192 bytes long
(example: the BIOS image of windows ntvdm).
- Add useful alignment (and others) macros.
Modified:
branches/ntvdm/subsystems/ntvdm/CMakeLists.txt
branches/ntvdm/subsystems/ntvdm/bios/bios.c
branches/ntvdm/subsystems/ntvdm/callback.c
branches/ntvdm/subsystems/ntvdm/emulator.h
Modified: branches/ntvdm/subsystems/ntvdm/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/CMakeLis…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] Sun Feb 23 20:40:09 2014
@@ -20,9 +20,9 @@
dos/dos32krnl/dos.c
dos/dem.c
bop.c
+ callback.c
clock.c
emulator.c
- callback.c
io.c
registers.c
vddsup.c
Modified: branches/ntvdm/subsystems/ntvdm/bios/bios.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios/bio…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/bios/bios.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/bios/bios.c [iso-8859-1] Sun Feb 23 20:40:09 2014
@@ -30,6 +30,7 @@
BOOL Success;
HANDLE hBiosFile;
DWORD BiosSize;
+ PVOID BiosLocation;
/* Open the BIOS file */
SetLastError(0); // For debugging purposes
@@ -62,30 +63,33 @@
return FALSE;
}
+ /* BIOS location needs to be aligned on 32-bit boundary */
+ /* (PVOID)((ULONG_PTR)BaseAddress + ROM_AREA_END + 1 - BiosSize) */
+ BiosLocation = (PVOID)MEM_ALIGN_DOWN((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) + 1 -
BiosSize, sizeof(ULONG));
+
DisplayMessage(L"First bytes at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
L"3 last bytes at 0x%p: 0x%02x 0x%02x 0x%02x",
- (PVOID)((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) + 1 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 1 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 2 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 3 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 4 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 5 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 6 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 7 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 8 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 9 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 0xa - BiosSize),
+ BiosLocation,
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 0),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 1),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 2),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 3),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 4),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 5),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 6),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 7),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 8),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 9),
- (PVOID)((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) - 2),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 2),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 1),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 0));
+ (PVOID)((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) - 2),
+ *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 2),
+ *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 1),
+ *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 0));
/* Attempt to load the BIOS file into memory */
SetLastError(0); // For debugging purposes
Success = ReadFile(hBiosFile,
- (PVOID)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 1 -
BiosSize),
- /* (PVOID)((ULONG_PTR)BaseAddress + ROM_AREA_END + 1 -
BiosSize) */
+ REAL_TO_PHYS(BiosLocation),
BiosSize,
&BiosSize,
NULL);
@@ -96,22 +100,22 @@
DisplayMessage(L"First bytes at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x
0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
L"3 last bytes at 0x%p: 0x%02x 0x%02x 0x%02x",
- (PVOID)((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) + 1 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 1 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 2 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 3 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 4 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 5 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 6 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 7 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 8 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 9 - BiosSize),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) + 0xa - BiosSize),
+ BiosLocation,
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 0),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 1),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 2),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 3),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 4),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 5),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 6),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 7),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 8),
+ *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 9),
- (PVOID)((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) - 2),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 2),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 1),
- *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 0));
+ (PVOID)((ULONG_PTR)TO_LINEAR(0xF000, 0xFFFF) - 2),
+ *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 2),
+ *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 1),
+ *(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(0xF000, 0xFFFF) - 0));
DisplayMessage(L"POST at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
TO_LINEAR(getCS(), getIP()),
Modified: branches/ntvdm/subsystems/ntvdm/callback.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/callback…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/callback.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/callback.c [iso-8859-1] Sun Feb 23 20:40:09 2014
@@ -31,9 +31,6 @@
/* 32-bit Interrupt dispatcher function code for the Control BOP Handler */
#define BOP_CONTROL_INT32 0xFF
-
-// #define ALIGN(ptr) (((ULONG_PTR)(ptr) + 15) & ~15)
-#define ALIGN(ptr) (ptr)
#define BOP(num) LOBYTE(EMULATOR_BOP), HIBYTE(EMULATOR_BOP), (num)
#define UnSimulate16 MAKELONG(EMULATOR_BOP, BOP_UNSIMULATE) //
BOP(BOP_UNSIMULATE)
Modified: branches/ntvdm/subsystems/ntvdm/emulator.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] Sun Feb 23 20:40:09 2014
@@ -44,6 +44,9 @@
/* Basic Memory Management */
+#define MEM_ALIGN_UP(ptr, align) MEM_ALIGN_DOWN((ULONG_PTR)(ptr) + (align) - 1l,
(align))
+#define MEM_ALIGN_DOWN(ptr, align) ((ULONG_PTR)(ptr) & ~((align) - 1l))
+
#define TO_LINEAR(seg, off) (((seg) << 4) + (off))
#define MAX_SEGMENT 0xFFFF
#define MAX_OFFSET 0xFFFF
@@ -54,6 +57,9 @@
#define SEG_OFF_TO_PTR(seg, off) \
(PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), (off)))
+
+#define REAL_TO_PHYS(ptr) (PVOID)((ULONG_PTR)(ptr) + (ULONG_PTR)BaseAddress)
+#define PHYS_TO_REAL(ptr) (PVOID)((ULONG_PTR)(ptr) - (ULONG_PTR)BaseAddress)
/* BCD-Binary conversion */