Commit graph

289 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto ae22dab753 [NTVDM]
- BIOS32: As a demonstration, load a BIOS expansion ROM (the one I've tested is the "OS in PCI expansion ROM" from: https://sites.google.com/site/pinczakko/building-a-kernel-in-pci-expansion-rom ; we don't support PCI thingies at all, but the bootstrap code works correctly).
- Initialize the BIOS32 stack for the callbacks.
- In the common BIOS functions, if we try to load the Windows NTVDM (SoftPC) BIOS (file: bios4.rom), we immediately hit a BOP 0x00 followed by INT 0x19 (bootstrap to run an OS). The BOP 0x00 is the function used by the BIOS to ask NTVDM to initialize the hardware, the IVT with data and so on. Also we finish to load the low part of the NTVDM BIOS in it (file: bios1.rom).
It's work-in-progress, nothing is done, there are lots of debugging code...

Have fun!

(to load a custom bios you need to put its filename as the first parameter of the BiosInitialize call, in the main() function in ntvdm.c).

svn path=/branches/ntvdm/; revision=62333
2014-02-26 01:16:56 +00:00
Hermès Bélusca-Maïto e03a6d7ebb [NTVDM]
- Add utility functions for loading ROM images from files, and running them.
- Add a missing PVOID in the MEM_ALIGN_DOWN macro.

svn path=/branches/ntvdm/; revision=62332
2014-02-26 01:07:09 +00:00
Hermès Bélusca-Maïto 4179d7890c [NTVDM]
- Reduce the size of the trampoline needed to perform 32 ---> 16 bit callbacks.
- Fix some comments, improve DPRINTs.

svn path=/branches/ntvdm/; revision=62331
2014-02-26 01:03:14 +00:00
Aleksandar Andrejevic 5036028dd4 [BASESRV]
Implement BaseSrvExitVDM.


svn path=/branches/ntvdm/; revision=62315
2014-02-24 03:51:49 +00:00
Hermès Bélusca-Maïto 9542b86934 [NTVDM]
- Move an "enable interrupts" command to where it belongs (i.e. in the BIOS32 initialization code; we do it at the very end). Otherwise some problems appears when trying to load 16-bit bios images.
- Use the new macro REAL_TO_PHYS to convert "real-mode" pointers (valid inside the VM only) into "physical" ones (valid in ROS/Windows/whatever).
- Add BIG HACKs (thanks Aleksander ;) ) in EmulatorRead/WriteMemory for wrapping up high memory addresses to low ones, so that we can load bios images (when you start running code at F000:FFF0).

To test 16-bit bios images: in ntvdm.c, put a valid bios file name in the BiosInitialize(...) call, and disable all DOS calls that happen before EmulatorSimulate().

svn path=/branches/ntvdm/; revision=62314
2014-02-24 00:33:21 +00:00
Hermès Bélusca-Maïto 679980a06c [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.

svn path=/branches/ntvdm/; revision=62312
2014-02-23 20:40:09 +00:00
Hermès Bélusca-Maïto 6f5166457c [NTVDM]: We can call now directly the interrupts instead of the internal functions BiosPeekCharacter and VidBiosPrintCharacter (so that if some program hooks them, we behave correctly).
svn path=/branches/ntvdm/; revision=62311
2014-02-23 19:43:31 +00:00
Hermès Bélusca-Maïto b33a34bec1 [NTVDM]
- Use callbacks in BIOS/DOS (and disable int32.c)
- Move DOS bops to dem.c

svn path=/branches/ntvdm/; revision=62306
2014-02-23 16:09:35 +00:00
Hermès Bélusca-Maïto 0c3c1170ab [NTVDM]: Limit the number of CPU recursion calls (not more than 32).
svn path=/branches/ntvdm/; revision=62305
2014-02-23 15:54:20 +00:00
Amine Khaldi 121bde3b83 * Sync up to trunk HEAD (r62286).
svn path=/branches/ntvdm/; revision=62287
2014-02-22 10:50:51 +00:00
Hermès Bélusca-Maïto 4489198537 [NTVDM]
** WARNING! WARNING! WORK IN PROGRESS!! **
**    MEGA HUGE IRC SPAM IN SIGHT!!     **

Commit a starting point implementation for 16-bit callbacks from 32-bit code that work together with the EmulatorSimulate / EmulatorUnsimulate functions.
That needs HUUUGE reviewing (go to the END to skip details and going to the current drawbacks of the implementation) <-- [TheFlash], Vampyre, others...

How it is intended to work:

1- Add callback.c to the CMakeLists.txt file, and remove int32.c from it.
2- In some 32-bit module that will get called by 16-bit code sooner or later (e.g. bios32 or dos32), include callback.h instead of int23.h.
3- Add a CALLBACK16 MyContext; // definition
4- In some initialization code for this module, call: InitializeContext(&MyContext, custom_segment, custom_offset);
   This allows you to define a zone of memory custom_segment:custom_offset that will be used as a trampoline zone. FIXME/TODO: we can return from this call the size of this zone (not implemented at the moment), so that we can know the zone that will be reserved for calls (it will be used in the following steps).

5- Now you can register e.g. 32-bit interrupt handlers with calls like:
   MyContext.NextOffset += RegisterInt32(MAKELONG(MyContext.NextOffset,
                                                  MyContext.Segment),
                                         IntNumber, Int32Handler, NULL);
Now comes the tricky part: since we want to be able to give precise memory addresses to where to put interrupt stubs (whose addresses will be stored in the IVT) (it's because it happens that some programs expect some few code interrupts to be placed at given places in memory; or one can argue that it is "for IBM bios compatibility"....), we pass a far pointer instead of the context structure as the first parameter. Then, currently the function returns the size of the written code (and it returns too via its last optional parameter).

6- You can do almost the same with RegisterInt16, where now instead of giving a 32-bit interrupt handler, you give the code of a 16-bit interrupt. What changes here is that in the 32-bit case, the 16-bit interrupt code was generated (to call back the 32-bit handler) whereas here you control it fully. For 16-bit interrupt code you need to use IRETs operands.

7- There is a RegisterCallback16 function, which registers at a given place in memory a chunk of 16-bit code. This code is expected to return with RETs. Its accompanying function RunCallback16 is untested at the moment.

8- Now the magic: Calling this code: an example is given in the following (from DosFastConOut fucntion of Dos32):
<code_snip>
   /* Save AX and BX */
   USHORT AX = getAX();
   USHORT BX = getBX();

   setBL(DOS_CHAR_ATTRIBUTE);
   setBH(Bda->VideoPage);
   setAH(0x0E);
   Int32Call(&DosContext, 0x10);

   /* Restore AX and BX */
   setAX(AX);
   setBX(BX);
</code_snip>

   Here (after saving some registers and setting some parameters for the INT 10h being called), we call interrupt 10h with Int32Call(&DosContext, 0x10); // where DosContext is a CALLBACK16 context.
   The call is done "synchronously", i.e. we restart here CPU simulation. The simulation then stops because the generated trampoline code has a suitable BOP_UNSIMULATE instruction.

CURRENT DRAWBACKS:
==================
1- The module which is going to use those callbacks need to know where in memory the code will be placed. Nothing is done "automatically". Otherwise we would have to:
   * maintain a (gobal, and finite) table of callbacks (in some way or another), and/or
   * be able to place the code in some "shadowed" memory zone of the emulator that gets hidden for all the programs emulated BUT the emulator.
2- Linked to the previous second point comes the problem of trampoline code. It is needed because we need to put a BOP_UNSIMULATE operand after the code to stop the 16-bit code simulation and go back to 32-bit. We need also to call e.g. INT 0x10 from 16-bit to be able to run the interrupt that could be hooked by some program. Some may argue that one can first call EmulatorInterrupt(0x10); but then we would have to find a means of stopping the simulation as soon as the interrupt exits...
3- For calling "regular" 16-bit code (with RunCallback16) we need a suitable callback: "call far_pointer; BOP_UNSIMULATE" .
4- Currently we build the trampolines on-the-fly when calling either RunCallback16 or Int32Call, at the memory location given when initializing CALLBACK16 context. If a given 32-bit module calls some 16-bit code that calls in turn a 32-bit function from the SAME module which calls also a 16-bit callback, then the trampoline will be overwritten. In RunCallback16 (and Int32Call) we save it, push a new one and then call the 16-bit code, and then restore the old one after the call. It seems to work fine currently, but I've found a problem, I think, which is the following:
   * Suppose that a 16-bit program calls some VDD function,
   * this VDD function creates a thread,
   * the two running VDD functions then call back the 16-bit program, or trigger an interrupt from whatever nature which both call 32-bit functions from a given 32-bit module (bios, dos). In this situation many problems arise:
     a. Our current implementation of the emulator doesn't support that since you are going to play concurrently with the unique CONTEXT of the emulated CPU... (i.e. flags / registers corruption in sight)
     b. If the 32-bit functions (called concurrently, and which are from the same 32-bit module) call some 16-bit code / interrupt, then they are going to use the same memory zone for the trampoline stub and there are very high risks of corruption. A solution for that would be to generate the trampolines once and for all for each registered 16-bit interrupt stub / 16-bit generic callback, retrieve their addresses and store them in some place (that also get shared amongst all of the 32-bit modules of the NTVDM emulator), so that each (possible concurrent) call go to the trampoline and just make the CPU point at it...

Voilà !

svn path=/branches/ntvdm/; revision=62283
2014-02-21 20:31:56 +00:00
Hermès Bélusca-Maïto 5a3cc5df3c [NTVDM]
Start to implement EmulatorSimulate / EmulatorUnsimulate (used by VDDSimulate16 and VDDUnsimualte16). This piece of code can be better written, but it works for what I'm going to commit next.

svn path=/branches/ntvdm/; revision=62282
2014-02-21 19:27:27 +00:00
Aleksandar Andrejevic 60dd86e7ac [BASESRV]
Implement BaseSrvGetVDMExitCode.


svn path=/branches/ntvdm/; revision=62237
2014-02-18 02:15:33 +00:00
Hermès Bélusca-Maïto 9b24de4f64 [NTVDM]: Load a BIOS image in case its name is given in BiosInitialize.
svn path=/branches/ntvdm/; revision=62236
2014-02-17 22:50:41 +00:00
Hermès Bélusca-Maïto 574f922049 [NTVDM]
- Remove an unneeded assignment (cmos.c)
- Reorganize BIOS code: put our 32-bit bios in a dedicated directory; start to introduce a way to load other bioses (WIP).

svn path=/branches/ntvdm/; revision=62235
2014-02-17 22:20:03 +00:00
Aleksandar Andrejevic c64a03a80f [BASESRV]
Move the VDM states and binary types to a public header file.
Implement GetNextDosSesId.
Continue implementing BaseSrvCheckVDM.


svn path=/branches/ntvdm/; revision=62200
2014-02-16 00:09:27 +00:00
Aleksandar Andrejevic 5a678ff4e0 [KERNEL32]
Implement GetVDMCurrentDirectories.
[BASESRV]
Fix a bug in BaseSrvGetVDMCurDirs.


svn path=/branches/ntvdm/; revision=62097
2014-02-10 13:56:55 +00:00
Aleksandar Andrejevic 158d2645a5 [BASESRV]
Implement BaseSrvSetVDMCurDirs.


svn path=/branches/ntvdm/; revision=62091
2014-02-10 00:37:06 +00:00
Aleksandar Andrejevic d0176d9ee8 [BASESRV]
Implement BaseSrvGetVDMCurDirs.
The current directory information is stored in the console record,
and it applies to all DOS records within it.


svn path=/branches/ntvdm/; revision=62086
2014-02-09 22:26:13 +00:00
Aleksandar Andrejevic 884d0853f8 [BASESRV]
Add an (incomplete) definition for VDM console records and VDM DOS records.
Implement BaseSrvIsFirstVDM.
Start implementing BaseSrvCheckVDM.


svn path=/branches/ntvdm/; revision=62078
2014-02-09 17:37:35 +00:00
Hermès Bélusca-Maïto ac8e7f981c [NTVDM]: Silent few DPRINTs.
svn path=/branches/ntvdm/; revision=62018
2014-02-06 20:28:33 +00:00
Hermès Bélusca-Maïto 6a287dfdfe [NTVDM]: German translation by Robert Naumann, thanks!
CORE-7250

svn path=/branches/ntvdm/; revision=61920
2014-02-02 14:01:21 +00:00
Hermès Bélusca-Maïto 3c5b236b5a [NTVDM]
- Sorry !!!!!! The previous translation (Polish, revision 61916 ) was by Wojtek Kozlowski aka. wojo664!! Sorry for having mistaken you with Radek Liska!
- Czesh translation by Radek Liska :D, thanks!
CORE-7250

svn path=/branches/ntvdm/; revision=61917
2014-02-02 00:43:52 +00:00
Hermès Bélusca-Maïto 97eee1dd69 [NTVDM]: Polish translation by Radek Liska, thanks!
CORE-7835 #resolve
CORE-7250

svn path=/branches/ntvdm/; revision=61916
2014-02-02 00:34:48 +00:00
Hermès Bélusca-Maïto 8eb145a87c [NTVDM]: Comment out what-appears-to-be a broken test. Fixes some LIFE.COM program. Need to investigate further...
svn path=/branches/ntvdm/; revision=61908
2014-02-01 22:13:31 +00:00
Hermès Bélusca-Maïto 285d283861 [NTVDM]: Okay, let's clear the VGA memory everytime we change modes... (fixes VGA-->EGA transition in Dave).
svn path=/branches/ntvdm/; revision=61907
2014-02-01 20:55:57 +00:00
Hermès Bélusca-Maïto 6e7f995863 [NTVDM]: Italian translation by Ivan di Francesco, thanks!
CORE-7250

svn path=/branches/ntvdm/; revision=61905
2014-02-01 19:42:49 +00:00
Hermès Bélusca-Maïto d028bd7690 [NTVDM]: Spanish translation by Javier Fernandez, thanks!
svn path=/branches/ntvdm/; revision=61903
2014-02-01 17:22:30 +00:00
Hermès Bélusca-Maïto 105aff1c51 [NTVDM]
- Define and export VDDSimulate16 and host_simulate.
- Move the big emulation loop from ntvdm.c to clock.c, and the console input pump thread from ps2.c to ntvdm.c.
  Indeed:
  * Moving the emulation loop out of the main initialization function will be helpful if one wants to modify how emulation is done,
  * The console input pump thread deals also with console UI bits that have nothing to do with keyboard/mouse/ps-2. Instead, the pump thread will dispatch keyboard and mouse events to the ps/2 controller.
- Implement a custom menu in the console's system menu to be able to parametrize ROS VDM (work-in-progress); at the moment only a menu item to show/hide mouse pointer, and another one allowing us to quit properly the VDM are implemented. The menu code was taken from the GUI frontend in winsrv.dll. Only english and french translations available at the moment.

svn path=/branches/ntvdm/; revision=61902
2014-02-01 16:32:20 +00:00
Hermès Bélusca-Maïto d25d9ea618 [NTVDM]
- Enable experimental sound support (only PC speaker for the moment, aka. uses beep.sys).
- Introduce a #define WORKING_TIMER which aim is to disable the currently problematic approximate performance counter value calculation done in order not to call QueryPerformanceCounter each time.
  The problem is that we then compute a number of clock ticks for the PIT, which becomes negative, and therefore everything starts to hang.
  Disabling this code and calling each time QueryPerformanceCounter, fixes everything; we gain in precision but we loose in performance...
  A definitive fix must be found, [TheFlash] !!

This fixes sound (and hangs) in Advanced NetWars, Dangerous Dave, ElitePlus and Rescue Rover (the games that I've tested so far).

svn path=/branches/ntvdm/; revision=61875
2014-01-29 00:25:43 +00:00
Hermès Bélusca-Maïto f2a98176d6 [NTVDM]: Add debug print for timer ticks to try to find why the emulator sometimes hangs...
svn path=/branches/ntvdm/; revision=61867
2014-01-28 20:39:16 +00:00
Hermès Bélusca-Maïto 03d8479401 [NTVDM]
Part 2 of PIT + sound fix.
- Move port 61h management from speaker.c to the emulator.c module;
- Add PIT OUT callbacks support;
- Add (unimplemented) PitSetGate function (will be used later on).
Still WIP.

svn path=/branches/ntvdm/; revision=61866
2014-01-28 20:24:24 +00:00
Hermès Bélusca-Maïto 5dafb169e0 [NTVDM]: Replace my #if 0 by #ifdef IPS_DISPLAY for DPRINTing (or not) the no. of instructions per seconds.
svn path=/branches/ntvdm/; revision=61865
2014-01-28 20:18:52 +00:00
Hermès Bélusca-Maïto 951276a7d8 [NTVDM]: Remove erroneous comments.
svn path=/branches/ntvdm/; revision=61861
2014-01-28 17:26:26 +00:00
Hermès Bélusca-Maïto 0a46ec7a18 [NTVDM]
- Break the DOS source file into the "DOS BIOS" (also known in other places as ibmbio or io or...), which is in fact some kind of hardware abstraction layer, and the "DOS BDOS" kernel (also known in other places as ibmdos.com or msdos.sys or...).
- Add in DEM the possibility of loading the DOS from another files (WIP).

svn path=/branches/ntvdm/; revision=61846
2014-01-26 21:51:27 +00:00
Hermès Bélusca-Maïto c98977184f [NTVDM]
- Start to refactor the DOS sources:
  Introduce the DEM (DOS Emulation) support library that is used by our built-in DOS, and that is used (via BOPs) by windows NT DOS (files: ntio.sys and ntdos.sys).
- Export some of DEM functions; stub most of them and implement the remaining ones (with existing code that we had in dos.c before).

svn path=/branches/ntvdm/; revision=61838
2014-01-26 18:25:59 +00:00
Hermès Bélusca-Maïto 1608c84d72 [NTVDM]: Implement a basic BIOS Wait interrupt INT 15h, AH=86h.
svn path=/branches/ntvdm/; revision=61821
2014-01-25 22:29:54 +00:00
Hermès Bélusca-Maïto 298e47dbaf [NTVDM]
- Shut up some DPRINTs in io.c and ntvdm.c
- I forgot to update the call to PitClock in the previous revision...

svn path=/branches/ntvdm/; revision=61816
2014-01-25 18:57:17 +00:00
Hermès Bélusca-Maïto 4bbed217b6 [NTVDM]: Each PIT channel is decreased by the same amount of "Count".
svn path=/branches/ntvdm/; revision=61815
2014-01-25 18:56:12 +00:00
Hermès Bélusca-Maïto 2bbb94f82b [NTVDM]
Big PIT fix Part 1/X
Currently, sound frequency is fixed (in Advanced NetWars, Rover, Dave)

svn path=/branches/ntvdm/; revision=61810
2014-01-25 17:00:09 +00:00
Hermès Bélusca-Maïto f878b8abae [NTVDM]
Welcome sound in Advanced NetWars!
However it won't work totally due to problems in the PIT or in the sound emulation (and as a result, the emulator will "hang").

svn path=/branches/ntvdm/; revision=61809
2014-01-25 16:23:27 +00:00
Aleksandar Andrejevic a3a28181c2 [NTVDM]
Add two general-purpose variables to the interrupt handler stub stack.
Fix INT 29h so that it works correctly when the INT 10h, AH = 0Eh call is hooked.


svn path=/branches/ntvdm/; revision=61797
2014-01-25 00:53:10 +00:00
Hermès Bélusca-Maïto 6ddfa7d2b8 [NTVDM]
- Move all the hardware initialization to EmulatorInitialize (since emulator.c can be viewed as support functions for emulating a PC motherboard) --> PS2 and VGA go there.
- Break bios.c into bios.c and kbdbios.c (the keyboard bios module) (according to the IBM documentation as well as other emulator sources or SeaBIOS or...).
- Move Exception handling from int32.c to emulator.c, because it's something tight to the emulator, not to the interrupt system by itself (yet it happens that INT 00h to 07h are commonly set to some exception handlers). In the bios.c, initialize those vectors with the default exception handler.
- Handling IRQs is done fully in bios.c now: introduce PicSetIRQMask and EnableHwIRQ helper functions (adapted from their equivalents from SeaBIOS) that allows the bios to set (and activate in the PIC) a given IRQ with its corresponding handler. Also introduce PicIRQComplete that serves as a PIC IRQ completer (i.e. sends the EOI to the right PIC(s)).
- Continuing on that, at the moment I set dumb default PIC IRQ handlers for IRQ 08h - 0Fh and IRQ 70h - 77h).
- By default I disable all the IRQs; there are then set on-demand with EnableHwIRQ.
- Rework the POST (aka. BiosInitialize function):
  * the memory size is now get from the CMOS (as well as the extended memory size via INT 12h, AH=88h),
  * then we initialize the interrupts,
  * then platform hardware (ie. the chips) are initialized,
  * and finally the keyboard and video bioses.
- As said before, move memory sizes into the CMOS.
- Simplify video bios initialization.

svn path=/branches/ntvdm/; revision=61796
2014-01-25 00:21:51 +00:00
Hermès Bélusca-Maïto 3c273ca1a9 [NTVDM]: Register functions are already declared via the inclusion of ddk/vddsvc.h. However still keep their definitions also in registers.h (yet #if 0'ed out) for reference.
svn path=/branches/ntvdm/; revision=61795
2014-01-24 20:37:40 +00:00
Hermès Bélusca-Maïto ba97a8f567 [NTVDM]: Clean ConsoleFramebuffer after leaving graphics mode.
svn path=/branches/ntvdm/; revision=61794
2014-01-24 20:36:17 +00:00
Hermès Bélusca-Maïto 1d9208e0a3 [NTVDM]: Use EmulatorRead/WriteMemory instead of directly use the VgaXXXMemory helpers.
svn path=/branches/ntvdm/; revision=61786
2014-01-24 00:41:26 +00:00
Hermès Bélusca-Maïto b393d6bbc4 [NTVDM]: Improve the icon, and add 16x16 format.
svn path=/branches/ntvdm/; revision=61785
2014-01-23 23:46:10 +00:00
Hermès Bélusca-Maïto f0466501fc [NTVDM]
- Do not export (for the PIC/PIT/Speaker) the port functions but use instead the common port interface.
- In bios.c : IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086 /* | PIC_ICW4_AEOI */); (line 377) : in NXVM they add PIC_ICW4_AEOI; [TheFlash], can you have a look at this and see whether it is required for the master PIC only, otherwise remove this comment.

svn path=/branches/ntvdm/; revision=61590
2014-01-11 21:45:01 +00:00
Hermès Bélusca-Maïto 40f773b96b [DDK:NT_VDD]
Declare some VDM memory services.

[NTVDM]
- Almost all of the XXXInitialize functions just return TRUE always, so VOIDify them instead (since they always succeed).
- Move almost all of the hardware initialization inside EmulatorInitialize.
- Move pure console initialization/mode-saving/cleanup code into ConsoleInit/Cleanup functions in ntvdm.c instead of in bios.c.

svn path=/branches/ntvdm/; revision=61588
2014-01-11 20:59:27 +00:00
Hermès Bélusca-Maïto 25105f6bec [NTVDM]: Break the BIOS into the BIOS and the video BIOS.
svn path=/branches/ntvdm/; revision=61586
2014-01-11 17:05:25 +00:00