4 ms·
So does this run DOS on Windows? Or DOS on Linux? Or Linux on DOS? Or DOS on Linux on Windows? Would be nice if there were an explanation in the README.
by phendrenad2 6y ago
So does this run DOS on Windows? Or DOS on Linux? Or Linux on DOS? Or DOS on Linux on Windows? Would be nice if there were an explanation in the README.
- benjojo12 6y agoThis runs Linux "inside" of DOS, allowing you to exec Linux i686 binaries "inside" of a DOS terminal I put inside in quotes because how this actually works is quite amusing (and apparently is actually how Windows 95 also works)
- kentonv 6y agoIs this explained somewhere? I'd love to read how it works (without trying to understand the source code).
- haileys 6y agoAuthor here. I am planning to do an in depth write up of how this works, but it seems Hacker News found it sooner :) When DSL is first invoked at the command line it boots up the Linux kernel which takes over control of the computer from DOS. Now here’s the trick: DSL makes use of a processor feature called VM8086 which allows for a 32 bit operating system to run legacy 16 bit code mostly natively. This feature is how early Windows, DOS extenders, etc worked. The Linux kernel also supports VM86, although it is largely undocumented and not really used these days. I think dosemu is the only major user of VM86 on Linux. DSL then returns to DOS, which has essentially been flipped inside out and is now unknowingly running inside a VM8086 task. Helpfully Linux does not appear to clobber DOS’s memory during its own boot process. DSL does just enough emulation of hardware like the keyboard to make things work, allowing DOS raw hardware access for everything else. This situation of running two operating systems at the same time on the same hardware is extremely fragile and unsafe of course, but it does seem to work surprisingly well anyway!
- kentonv 6y ago> Helpfully Linux does not appear to clobber DOS’s memory during its own boot process. Is that just a coincidence or intentional somehow? I guess DOS can only access the first 1MB (err... plus 65520 HMA bytes?), so if Linux just avoids using that space then DOS can keep running happily... I was curious if there's actually a mechanism to tell Linux to avoid that space. DOS memory management fascinates me in its absurdity.
- oso2k 6y agoWith HIMEM.SYS + EMM386.EXE [0][1], you could include or exclude certain memory segments. But, DOS Subsystem for Linux uses non-standard little documented Unreal Mode [2][3] instead of traditional DOS Memory Management. [0] http://www.mdgx.com/mem6.htm#6 http://www.mdgx.com/mem6.htm#6 [1] http://manmrk.net/tutorials/DOS/msdos7/emm386.htm http://manmrk.net/tutorials/DOS/msdos7/emm386.htm [2] https://en.m.wikipedia.org/wiki/Unreal_mode https://en.m.wikipedia.org/wiki/Unreal_mode [3] https://github.com/charliesome/doslinux/blob/master/doslinux.asm#L239-L247 https://github.com/charliesome/doslinux/blob/master/doslinux...
- NelsonMinar 6y agoThat's hilarious. Nice hack!
- kentonv 6y agoWow you weren't kidding about "largely undocumented". https://man7.org/linux/man-pages/man2/vm86.2.html https://man7.org/linux/man-pages/man2/vm86.2.html Would be really cool if someone contributed a proper man page, I bet it would be a fascinating read.
- temac 6y agoVery cool! Can it use multiple processors under Linux or is it limited to 1 CPU because of some tricks for the DOS compatibility?
- devit 6y agoHave you tried the approach of booting Linux and then creating a normal fullscreen qemu/KVM-based VM initialized with the memory state of the DOS OS, with a configuration so that the transition works correctly? That would make the whole system fully robust and safe, and also support running XMS/EMS managers, DOS extenders, Windows and other bootloaders from the DOS VM. I'm not sure however whether you would need to modify qemu to make it work and how hard that would be (also I guess that would have less hacky fun factor).
- q3k 6y agoFrom a quick skim through the code: - it first, if not yet present, starts Linux, via normal Linux kernel load. It passes over some pointers from DOS into /init arguments so that /init can know about DOS' context when Linux was first loaded - Linux's /init then uses VM86 [1] to call back into DOS, back to the function that was run in DOS before Linux was loaded (vm86_return). This is a bit of a 'draw the rest of the fucking owl' deal, as it has to actually emulate a lot of DOS/PC behaviour (emulate INB/OUTB, etc). It's basically a small VM, like with KVM, but for 16-bit DOS. - when DOS wants to run a Linux command, it now uses a special new interrupt (DOSLINUX_INT) to call into the kernel. This in turn triggers a VM86 exit, jumps into the VM86 monitor in /init, executes the command, and pokes the result back into DOS, resuming VM86 emulation. [1] - https://en.wikipedia.org/wiki/Virtual_8086_mode https://en.wikipedia.org/wiki/Virtual_8086_mode
- TheRealPomax 6y agoThe GIF's prety much crystal clear: it runs QEMU on Linux. And QEMU runs whatever you want, because it's a machine emulator/virtualiser, in this case it's running as x86 with MS DOS on top.
- plus 6y agoNo.... QEMU is being used to run DOS, since a) who runs DOS on metal these days, and b) how would you record the screen if you were running DOS on metal (I suppose you could use a capture card). Linux is running in a WSL-like environment on the DOS host.
- smegger001 6y ago>who runs DOS on metal these days freedos developers? people updating HP bios from bootable media people using intels ssd firmware update tool
- hnlmorg 6y agoNo, qemu is only there to boot DOS. DOS then runs Linux commands via `dsl` (DOS Subsystem for Linux). You could perhaps argue "inception" since it's Linux running a DOS VM running Linux commands. But the charitable explanation is the author just wanted a convenient environment to do DOS development rather than bare metal (think of it like a Vagrant box).
- lights0123 6y agoNo, the interesting part is what's happening in DOS. QEMU was probably just used for screenshots and not going through the pain of installing DOS on a new machine.
- JdeBP 6y agoThis entire discussion is strong evidence that the GIF is not crystal clear at all. (-: