Page 1 of 2

DPMI - A bit of a noobish question.

Posted: Wed Jul 01, 2009 8:22 pm
by gravaera
If you're reading this, thanks. Now down to business: I've been reading extensively for a while now, and getting the theory down right. However, I've tried to really understand what DOS is, and the DPMI.

So far, this is what I see it as: DOS is a mini, underlying OS that is installed on motherboards, and provides basic I/O services when you make software interrupt calls to it. It was programmed by Bill Gates (?), and it comes, apparently with any motherboard made in the last decade.

The DPMI is, by extension, an encapsulating term for the DOS interrupt system, seeing as it imposes a measure of abstraction by hiding the memory mapped I/Os, data ranges etc, from the programmer. I make the assumption that if I wanted to, I could go ahead (in real mode at least), and write to the ports myself.

If I at least have a basic understanding from here: then my confusion begins here: I've been reading through tos of source form like...everywhere on the net, and I always see people just declare some 'dpmi.h'. Then, magically, they gain access to a function int86(), to __dpmi_int(), or another one whose name I cannot recall, even though it's not in the dpmi.h header.

Not only that, but they normally do something like this:

Code: Select all

struct regs
{
   ulong32 ax;
   ...
   ushort32 ss;
};

struct regs reg_var;
Then, magically, after that, they end up getting this thing that irritates me:

Code: Select all

r.x.ax = ...;
...
r.x.dx = ...;
//Where the F did he get that r var? It just popped out of nowhere! >:(
So, if not an explanation, which i understand would be tedious seeing as I'm most likely asking something rather basic, then could you please spare me the time to just post up a link to an article?

Main, important questions: (1) Where do those functions (int86(), __dpmi_int()), etc come from? Are they compiler linked into the executable, and the people just kind of do something like an 'extern TYPE __dpmi_int(TYPE, TYPE);'?

(2)How can I get to load registers into a variable like the above examples?

(3)This one may be going too far but canI have a comprehensive memory map of real mode mem?

Re: DPMI - A bit of a noobish question.

Posted: Wed Jul 01, 2009 8:31 pm
by JackScott
DOS is an operating system (made by Bill Gates, yes). Since the advent of Windows XP, it is no longer installed on any PC.

The BIOS however, has been (mostly) the same for the last 28 years. It is installed on the motherboard in a ROM chip, and is the basic input/output system for the machine (in real mode at least). There have been efforts to replace it (EFI), but so far with no great inroads.

Re: DPMI - A bit of a noobish question.

Posted: Wed Jul 01, 2009 8:35 pm
by Firestryke31
DOS is not included on any motherboards, DOS was not made by Bill Gates, and I don't think people are going to be super nice due to such severe misinformation. You might want to do some more research before you make another post, specifically as to what DOS is.

The BIOS is probably what you're thinking of when you say DOS, but the BIOS doesn't have much of a DPMI-style library unless you make it yourself. I'll leave it to others to better inform you...

Edit @JackScott: All Intel-based Macs use EFI, so there is some progress in that direction...

Re: DPMI - A bit of a noobish question.

Posted: Wed Jul 01, 2009 10:03 pm
by NickJohnson
Firestryke31 wrote:DOS was not made by Bill Gates, and I don't think people are going to be super nice due to such severe misinformation. You might want to do some more research before you make another post, specifically as to what DOS is.
Okay, to hopefully stop any arguments over this "fact", here is the story based on Wikipedia (mostly). MS-DOS was originally 86DOS a.k.a. QDOS ("Quick and Dirty Operating System"), written by Seattle Computer Products. Microsoft, then a very small company, bought the rights to it in order to market it for the original IBM PC. It was, at least at first (i.e. for MS-DOS 1.0), modified very little other than rebranding - later development was done by Microsoft, which includes Gates (I know for a fact that he wrote FAT). Bill Gates did not write MS-DOS from scratch, but he was involved with it's development after 1981. No more questions/comments.

Re: DPMI - A bit of a noobish question.

Posted: Wed Jul 01, 2009 10:31 pm
by Troy Martin
NickJohnson wrote:
Firestryke31 wrote:DOS was not made by Bill Gates, and I don't think people are going to be super nice due to such severe misinformation. You might want to do some more research before you make another post, specifically as to what DOS is.
Okay, to hopefully stop any arguments over this "fact", here is the story based on Wikipedia (mostly). MS-DOS was originally 86DOS a.k.a. QDOS ("Quick and Dirty Operating System"), written by Seattle Computer Products. Microsoft, then a very small company, bought the rights to it in order to market it for the original IBM PC. It was, at least at first (i.e. for MS-DOS 1.0), modified very little other than rebranding - later development was done by Microsoft, which includes Gates (I know for a fact that he wrote FAT). Bill Gates did not write MS-DOS from scratch, but he was involved with it's development after 1981. No more questions/comments.
Uh, actually that's partially incorrect. SCP didn't write QDOS, they bought it from Tim Paterson, the man who actually wrote QDOS. They bought it, rebranded it to 86DOS, and then sold it to M$ for, IIRC, $200,000. I believe FAT was also an effort on behalf of Bill Gates and Paul Allen, but I could be wrong.

Re: DPMI - A bit of a noobish question.

Posted: Wed Jul 01, 2009 11:05 pm
by NickJohnson
But the point is what Gates' relationship is with MS-DOS - nobody really cares about SCP's various dealings.

Re: DPMI - A bit of a noobish question.

Posted: Fri Jul 03, 2009 4:56 am
by jal
holypanl wrote:I've been reading extensively for a while now, and getting the theory down right. However, I've tried to really understand what DOS is, and the DPMI.
I don't know what you've been reading, but about everything you are saying is wrong. Are you sure it wasn't something you smoked]/i]???
DOS is a mini, underlying OS that is installed on motherboards

Wrong.

and provides basic I/O services when you make software interrupt calls to it.

Wrong.

It was programmed by Bill Gates (?), and it comes, apparently with any motherboard made in the last decade.

Wrong.

The DPMI is, by extension, an encapsulating term for the DOS interrupt system, seeing as it imposes a measure of abstraction by hiding the memory mapped I/Os, data ranges etc, from the programmer.

Wrong.

I make the assumption that if I wanted to, I could go ahead (in real mode at least), and write to the ports myself.

Well, you've got that one right, at least.

If I at least have a basic understanding from here

You don't. Not even close. You're completely lost.

then my confusion begins here

Oh no, your confusion started way before that.

I've been reading through tons of source form like...everywhere on the net

You should not read source files before you understand the underlying basics.

This one may be going too far but can I have a comprehensive memory map of real mode mem?

It's everywhere. Google. That said, it won't help you much, as DPMI is about protected mode, mainly.


JAL

Re: DPMI - A bit of a noobish question.

Posted: Fri Jul 03, 2009 7:55 am
by gravaera
Thanks for your prompt replies, and @jal: ...Ouch. :(

Anyway, it seems like I have it all wrong from the inset, so I'll go do a lot more reading. Sorry for wasting your time, people. I'll do better next time...Aiyayai...

-gravaera

Re: DPMI - A bit of a noobish question.

Posted: Fri Jul 03, 2009 8:37 am
by Troy Martin
@jal: you could have pointed out some more positive thoughts like a few corrections instead of just yelling at the poor kid. And I suppose that every time you asked about something you were always right?

@holypanl: DOS isn't part of the motherboard, it's a separate OS entirely. The BIOS, however, functions similarly to what you described, albeit in a limited fashion. The BIOS service interrupts don't work with filesystems or any of that fun crap, just the bare hardware like the screen, keyboard, floppy and hard drives, the timer, RTC, etc.

The DPMI is like an extension, correct, but it allows 32-bit DOS programs to execute under the real mode 16-bit DOS platform. The DPMI takes the loaded program, jumps to pmode, executes an instruction, then jumps back to real mode. I think.

Re: DPMI - A bit of a noobish question.

Posted: Fri Jul 03, 2009 9:42 am
by ru2aqare
DPMI was used by protected mode programs (not "32-bit DOS programs", there is no such a thing) to use various DOS services. The first version of DPMI didn't even support 32-bit applications. Most (if not all) implementations don't function like a v86 monitor. When a DOS service is needed (for example, open file, read file, allocate DOS memory, etc), it temporary switches back to real mode, completes the operation, and resumes execution of the guest program (DPMI is the "host"). DPMI was an alternative to homebrew "DOS extenders" (Go32, etc.) as it had a standardised interface. Some early versions of Windows provided DPMI functionality as well (I think).

Re: DPMI - A bit of a noobish question.

Posted: Sat Jul 04, 2009 6:14 am
by jal
ru2aqare wrote:DPMI was an alternative to homebrew "DOS extenders" (Go32, etc.) as it had a standardised interface. Some early versions of Windows provided DPMI functionality as well (I think).
Wrong.

Come on people, just read wikipedia on DPMI, VCPI and DOS extenders. But to humour Troy, I'll explain a bit.

MS-DOS is a real mode, 16-bit operating system. At least until MS-DOS 5.0 (I'm not entirely sure about the 6.x series), it can even run on an XT. It's API is mainly accessed via int 21h (though a few other interrupts are used as well). It needs an IBM compatible BIOS to run, as it does not access most of the hardware itself (thus, it uses the BIOS services as drivers).

With the advent of the 386, the need to run programs in protected mode to take advantage of the 386 special features grew. Note that for the 286, this need was far less, as most machines still had only 1MB (yes, that is Mega, not Giga, byte) of RAM, as it was nigh impossible to access more than 1MB on a 286 (due to it's inability of switching back from protected to real mode in a 'normal' way, that is, without a processor reset, although iirc XMS did already exist (int 15h)). It was possible to run in protected mode directly, like we all do (that is, program the hardware yourself etc.), but not very practical. Thus, the DOS extender was born.

A DOS extender is, in its bare essence an API layer(or converter) that allows a program to run in protected mode (16 or 32 bit), but still call DOS as if in real mode. DOS extenders did this by converting protected mode pointers to real mode ones (and if needed copying buffers from > 1MB to 1MB), switching back to realmode (or sometimes using v86) and calling real DOS. DOS extenders usually also provide some memory management for the > 1MB memory.

When the 386 came, and people had more memory (it was becoming cheaper, and you could easily extend it by putting a DIMM in a slot, instead of plugging a handful of chips on your mobo), virtual EMS became available. I say virtual, because EMS was around even before XMS, even on the XT, in the shape of extender boards with RAM that plugged into an ISA slot. On the 386, EMS was emulated by switching to protected mode with paging, and running DOS and all DOS programs in a v86 mode task. This was a very nice (and quick, compared to XMS, that relied on copying chunks of memory) way of doing things, but caused a problem for programs aspiring to use protected mode: the processor already was in protected mode, so it was not possible to switch.

The solution was to extend the EMS drivers with an API that allowed a program that wants to go to protected mode to 'leave' the v86 task and run in full protected mode. Of course the EMS driver must still be allowed to operate, so there were certain restrictions, but the program ran in ring 0, and had full machine control. The first such extension standard was called VCPI, virtual control program interface, devised by Phar Lap and Quarterdeck (both popular DOS extender / extended DOS environment providing companies). The downside was that when VCPI was launched, so was Windows 3, which had both a 286 and 386 mode, both incompatible with VCPI.

As a solution, Microsoft specified a new API, DPMI, that allowed a program to run in protected mode under Windows, but only in ring 3. Both 16 bit and 32 bit protected mode was possible (even running in Windows 3 native 16-bit, you could run a 32-bit protected mode program using DPMI).

DOS extenders had to cope with all these specifications. The typical DOS extender (e.g. the very popular PMODE by Tran, or DOS/4GW) first tried whether it could run in plain protected mode (using an XMS driver if needed). If not possible, it tried VCPI. If not possible, it tried DPMI.

For the programmer, DOS extenders were quite a gift, as it removed the burden of dealing with all the peculiarities of XMS, EMS, VCPI, DPMI and the like, and ensured your main() just started in protected mode, and a malloc() used upper memory if needed.

Ok, that's enough talking for one day. As it may be clear, all of this is totally irrelavant to the current day, as programs are written directly for an OS. But it never hurts to know a bit of history.

Disclaimer: all this comes from my memory, though I did a bit of fact checking here and there. Feel free to correct me, but please provide sources :).


JAL

Re: DPMI - A bit of a noobish question.

Posted: Sat Jul 04, 2009 12:07 pm
by Malevol3nt
The funny (or sad, depending how you look at it) part is that most people around here who've used PCs for some time still believe the first thing their PC's boot is DOS. Usually when they hear the word BIOS they think about the BIOS Setup menu that you can load with one of the function keys. But I can't blame them, whenever they mention DOS I know they really meant to say BIOS. It's still funny tho. :D

Re: DPMI - A bit of a noobish question.

Posted: Sat Jul 04, 2009 6:16 pm
by gravaera
Here's a great opportunity to clear off the biggest cloud in my head: Okay: BIOS is loaded first, yea, everyone knew that, and then: here's where if you correct me, I'll be much obliged:

After BIOS, then, as far as I know control is passed onto the code in the Master Boot Record. I had, with this apparent misconception, assumed that DOS is a small underlying OS that is installe don Motherboards' and is resident in memory somewhere (sounds off, I know), and that when you make interrupt calls to it, it magically picks them up. (I know...)

So where is the distinction between DOS and the BIOS, and exactly when is DOS loaded into memory? I DOS not stored internally on the motherboard?

I honestly DID read up on it. I read a lot. It may not seem like it now, but I even convert articles to HTML and store them on my phone, and read them in the taxi and whatnot. I'm ALWAYS reading. Please, if you can, clarify that for me [-o<

Re: DPMI - A bit of a noobish question.

Posted: Sat Jul 04, 2009 6:20 pm
by JohnnyTheDon
On a modern computer running Window, Linux, Mac OS, or a hobby OS for that matter, DOS is never loaded. Ever. DOS is not stored anywhere, unless you actually put DOS on your computer. And in that case, DOS loads, and then thats it. It is not an intermediary step. It goes from BIOS -> Bootloader -> OS. And before you ask, DOS is not the bootloader.

Re: DPMI - A bit of a noobish question.

Posted: Sat Jul 04, 2009 6:31 pm
by Troy Martin
To clarify:

DOS is like the OSes you write. It's made up of files on a floppy or hard drive (or CD or whatever.) On boot, the BIOS sets up its interrupts and routines, then starts scanning the drives, generally with the floppy first then looking through the (E)IDE/(S)ATA/SCSI/whatever drives. If nothing is bootable, it prints an error message and halts/asks for any key to reboot.

DOS isn't part of the mobo. If it were to be in ROM, you'd be able to detach every drive from your box and boot into DOS. Try it.

I am not to be held responsible in the event that your computer craps itself because there are no drives plugged in. Try at your own risk.