gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > DOS on the DS?

#109637 - Joe_Sextus - Sun Nov 19, 2006 11:24 pm

I'm considering writing a native port of DOS. I'm read through a couple of discussion here.

http://forum.gbadev.org/viewtopic.php?t=7652
http://forum.gbadev.org/viewtopic.php?t=6875

Neither one even touch the technical aspects of porting DOS. I have been looking at http://sourceforge.net/projects/rxdos as a possible starting point for this port. RxDOS is a real-time clone of MS-DOS completely written in x86 assembly. I have the book that the author of RxDos wrote so the DOS part of this project shouldn't be too difficult to start. But I have a few DS specific question (Bare in mind that I am new to DS development).

1) From what I've gathered, mainly looking at the NDSTech Wiki, 0x02000000 is the lowest general purpose memory address. Does the DS load program code at this address (like the GBA)?

2) Can devkitARM produce a flat binary image (e.g the first instruction in my program is byte 0 of the binary)?

I'm thinking that this project will be CF/SD only and that it will contain 3 files: loader.nds (maybe), kernel.sys, command.com. loader.nds is the file responsible for loading kernel.sys into the correct memory location at boot. Both loader.nds and kernel.nds would be GBA slot device specific (e.g one set for GBAMPv2, one set for M3, ...). kernel.sys is obviously the kernel and it would load command.com after setting up the IVT and SIP and pass control to command.com which is the command line interpreter. It would pare the config.sys and autoexec.bat, if present.

Any feedback would be appreciated.

-Joe

#109638 - Mighty Max - Sun Nov 19, 2006 11:30 pm

Quote:
. RxDOS is a real-time clone of MS-DOS completely written in x86 assembly


Thats the problem. x86 instructions do not work on a arm microprocessor.

It is not possible to create a DR/PC/MR-DOS clone for the DS without emulating the CPU and the primary peripherivals like pic, pit, fdc etc
_________________
GBAMP Multiboot

#109641 - Joe_Sextus - Sun Nov 19, 2006 11:41 pm

Mighty Max wrote:
Thats the problem. x86 instructions do not work on a arm microprocessor.

That's not a problem. I'm thinking that for the DS C/C++ code will work. I was originally thinking that translating from x86 to ARM would be enough.

Mighty Max wrote:
It is not possible to create a DR/PC/MR-DOS clone for the DS without emulating the CPU and the primary peripherivals like pic, pit, fdc etc

I'm not thinking of a 100% compatible environment, but as close as possible. What peripherals would be needed?

#109642 - Dwedit - Sun Nov 19, 2006 11:43 pm

Address 0 is not in any user-writable area, it's in the BIOS.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#109643 - Joe_Sextus - Sun Nov 19, 2006 11:48 pm

Dwedit wrote:
Address 0 is not in any user-writable area, it's in the BIOS.

I was going to shift everything up by 0x02000000 for that reason.

#109644 - Mighty Max - Sun Nov 19, 2006 11:56 pm

Joe_Sextus wrote:
Mighty Max wrote:
Thats the problem. x86 instructions do not work on a arm microprocessor.

That's not a problem. I'm thinking that for the DS C/C++ code will work. I was originally thinking that translating from x86 to ARM would be enough.


It would run the kernel then, but what's the use of a OS if it cant start any programs? ".com" is complete based on the x86 processor layout and MZ (.exe part) are not much better.

Mighty Max wrote:
It is not possible to create a DR/PC/MR-DOS clone for the DS without emulating the CPU and the primary peripherivals like pic, pit, fdc etc

I'm not thinking of a 100% compatible environment, but as close as possible. What peripherals would be needed?[/quote]

The named one at least + some gfx by either writing a int10 wrapper or an actual m/c/e/p/vga emulation.
_________________
GBAMP Multiboot

#109645 - Joe_Sextus - Mon Nov 20, 2006 12:09 am

Mighty Max wrote:

It would run the kernel then, but what's the use of a OS if it cant start any programs? ".com" is complete based on the x86 processor layout and MZ (.exe part) are not much better.

I'm not planning on writting an emulator, any DOS programs would have to be ported to the DS as well. The .com and .sys extensions in my example are more for the user to tell what they're for, kernel.sys and command.com could be called kernel.nds and command.nds respectively.

[EDIT]
As far as graphics goes, I was planning on just DOS mode 0 for now using a modified version of Sylfurd's subpixelfont.

#109651 - tepples - Mon Nov 20, 2006 12:55 am

Mighty Max: This project appears to be to DOS as DSLinux is to Linux. If you want a real IBM PC emulator, start with the CPU core from dualSwan.

How much of FreeDOS (GPL clone of MS-DOS) is written in C?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#109654 - Joe_Sextus - Mon Nov 20, 2006 1:00 am

tepples wrote:
How much of FreeDOS (GPL clone of MS-DOS) is written in C?

I think most of freedos is written in C, but I think it will be easier to work from RxDOS even though its in Assembly. FreeDOS is a DOS for modern x86 system and has thing that would have to striped out (such as usb and ntfs). RxDOS is the equivalent of
Code:
format a: /s
There isn't any fluff in it.
[EDIT]
As fas as comparing this to DSLinux. That's a good comparison for what I want.

#109662 - kusma - Mon Nov 20, 2006 2:23 am

Joe_Sextus wrote:
As fas as comparing this to DSLinux. That's a good comparison for what I want.

...except that most linux software comes with the source code, unlike most dos software - more or less rendering the entire idea useless imo.

#109663 - Joe_Sextus - Mon Nov 20, 2006 2:26 am

kusma wrote:
Joe_Sextus wrote:
As fas as comparing this to DSLinux. That's a good comparison for what I want.

...except that most linux software comes with the source code, unlike most dos software - more or less rendering the entire idea useless imo.

My experience with DSLinux isn't much better (I have a GBAMP v2, so no X).

#109664 - kusma - Mon Nov 20, 2006 2:26 am

besides from that, even if you were to get the source code for some usable dos-tools, they'd mostly be written in assembly, or some "neat" watcom c/c++ with boat-loads of inline asm to do system calls. and how would you emulate dos interrupts etc anyway (ie provide an api for the applications)?

#109665 - kusma - Mon Nov 20, 2006 2:27 am

Joe_Sextus wrote:
kusma wrote:
Joe_Sextus wrote:
As fas as comparing this to DSLinux. That's a good comparison for what I want.

...except that most linux software comes with the source code, unlike most dos software - more or less rendering the entire idea useless imo.

My experience with DSLinux isn't much better (I have a GBAMP v2, so no X).

linux is SOOO much more than X. seriously. I'm not saying that I find dslinux to be a very good idea either, i'm just saying i find dos for the ds an even worse idea ;)

#109668 - Joe_Sextus - Mon Nov 20, 2006 3:20 am

kusma wrote:
... how would you emulate dos interrupts etc anyway (ie provide an api for the applications)?

I had thought to just take and place the IVT at 0x02000000 and place the function addresses in there as 32-bit pointer instead of segment:offset. But their would still need to be an "int" instruction/function.

For C/C++ it could be
Code:
uint32 int(uint32 ax, uint32 bx, uint32 cx, uint32 dx, byte intNum)
{
  /*
   keep in mind this is pseudo code and the syntax may not be correct
   IVT is an array of function pointers
  */
  IVT[intNum](ax, bx, cx, dx);
}

but I'm not sure how to handle this for asm, maybe a simple function that is included in the asm code.
kusma wrote:
Joe_Sextus wrote:
kusma wrote:
Joe_Sextus wrote:
As fas as comparing this to DSLinux. That's a good comparison for what I want.

...except that most linux software comes with the source code, unlike most dos software - more or less rendering the entire idea useless imo.

My experience with DSLinux isn't much better (I have a GBAMP v2, so no X).

linux is SOOO much more than X. seriously. I'm not saying that I find dslinux to be a very good idea either, i'm just saying i find dos for the ds an even worse idea ;)

I know, both are bad ideas as far as being of any real use (for now). But its something I just wanted to play around with and see if I could make it work. More of a proof of concept rather than an OS to use day in and day out.

My only real problem with DSLinux (its on my GBAMP) as an embedded distribution is the font size.

Windows CE would probably be the best choice to run on the DS (if it was Open Source).

#109684 - Cthulhu - Mon Nov 20, 2006 8:00 am

Joe_Sextus wrote:
Windows CE would probably be the best choice to run on the DS (if it was Open Source).


It is.

#109685 - OOPMan - Mon Nov 20, 2006 8:14 am

While we're on the subject of OS "porting", has anyone looked into porting one of the various Realtime RISC OSes about, like eCos?
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#109699 - Lazy1 - Mon Nov 20, 2006 2:08 pm

Your better off writing an x86 interpreter, then emulating some x86 hardware such as a CGA display.
That way we can play some really old dos games on our ds without dos.

I doub't you'll have a problem emulating a 4.77mhz 8086, you might even be able to do that on the arm7.

Problem is you'd need to know some 8086 assembly in order to troubleshoot problems that will arise.

#109700 - Joe_Sextus - Mon Nov 20, 2006 2:15 pm

Lazy1 wrote:
Your better off writing an x86 interpreter, then emulating some x86 hardware such as a CGA display.
That way we can play some really old dos games on our ds without dos.

I doub't you'll have a problem emulating a 4.77mhz 8086, you might even be able to do that on the arm7.

Problem is you'd need to know some 8086 assembly in order to troubleshoot problems that will arise.

The more I look into and think about this project, the I think that an emulator would be a better way to go.

#109701 - OOPMan - Mon Nov 20, 2006 2:30 pm

You could just try porting Bochs or DosBox...

I don't think the first has been tried, while the second has without much success...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#109702 - Joe_Sextus - Mon Nov 20, 2006 2:53 pm

OOPMan wrote:
You could just try porting Bochs or DosBox...

I don't think the first has been tried, while the second has without much success...


The problem with that is that I wanted a native DOS environment, not emulated.

#109704 - Izhido - Mon Nov 20, 2006 3:41 pm

I concur with most people here. If you want to be able to write DOS programs that run unchanged on the DS, emulation is the only way to go. x86 & ARM are fundamentally different architectures. Assembly language for both platforms is not even similar. Now, if compatibility is being thought to be kept at C++ level, well, that's another thing...

#109705 - OOPMan - Mon Nov 20, 2006 4:02 pm

Yeah, I don't see much in the way of virtualisation happening here. The ARM is a pretty funky little chip, as detailed here...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#109718 - josath - Mon Nov 20, 2006 6:31 pm

Like others said:

If you make a 'native' ARM version of DOS, you will not be able to run any existing dos programs. If you just want to make this as a fun excercise, then go ahead, but building one based on an emulator would be much more useful IMHO.

Most likely, you will have to write the emulator from scratch, dosbox takes too much memory. Don't even bother with bochs, that thing is a beast even on my 2ghz PC.

I would get in contact with LiraNuna, I think he has made a 8086 CPU core, for some other emulator he was working on which uses a similar CPU. Then all you really need to emulate is: BIOS, a CGA display, Keyboard, and Disk access. Then we could run some old dos apps. If you keep it limited to 640KB of RAM (or even less. dos and lots of apps can run with less), I think it will be doable, to emulate say a 2MHz PC.

This will require you to understand x86 ASM, and be able to research the internals of a PC (the above mentioned devices which need emulating). If this is your first emulator, it may be a bit much, so don't expect it to work on your first try -- I know, I tried making an 8086 emulator. I got it far enough that it can emulate HELOWRLD.COM, but it's not designed real well, and I'd need to start again from scratch if I want to take it further.

#109732 - Joe_Sextus - Mon Nov 20, 2006 9:43 pm

After thinking about this project in more detail, I think I am not going to write it.
Quote:
you will not be able to run any existing dos programs

This is one of the reasons, every way I've looked at this (as a native port) would require the programs to be rewritten and have addresses changed.

I may make a DOS-like environment/shell instead.

#109733 - Dan2552 - Mon Nov 20, 2006 10:00 pm

Joe_Sextus wrote:

I may make a DOS-like environment/shell instead.


Make it manage everything an OS is meant to do (memory management, filesystem management, etc), then think about writing a GUI for it :) Then everyone's happy

#109737 - Joe_Sextus - Mon Nov 20, 2006 10:24 pm

Dan2552 wrote:
Joe_Sextus wrote:

I may make a DOS-like environment/shell instead.


Make it manage everything an OS is meant to do (memory management, filesystem management, etc), then think about writing a GUI for it :) Then everyone's happy

I can see it now, DS-DOS with Windows DS. (BSOD included for free!)

#109746 - Lazy1 - Mon Nov 20, 2006 11:23 pm

I'd say just go for it and write it anyway, so many people would have a use for this.
I think SimCity would work on a CGA display...

#109750 - Joe_Sextus - Mon Nov 20, 2006 11:58 pm

If I write it the way I'm thinking about doing it, I'm going to load DOS high (like 4MB - sizeof(DOS) high). This gives programs the first 3+ MB of Memory.

#109751 - Izhido - Tue Nov 21, 2006 12:05 am

Just out of curiosity, are you going to implement DPMI? That sure would help a lot when porting DOS apps...

Just imagine... the DS breaking the 640kb barrier into a whole new world of... of...

D'oh!

Nevermind. :D :D :D

PS: Just a joke, man! Now, seriously, will you implement DPMI???

- Izhido

#109754 - Dan2552 - Tue Nov 21, 2006 12:15 am

Joe_Sextus wrote:
Dan2552 wrote:
Joe_Sextus wrote:

I may make a DOS-like environment/shell instead.


Make it manage everything an OS is meant to do (memory management, filesystem management, etc), then think about writing a GUI for it :) Then everyone's happy

I can see it now, DS-DOS with Windows DS. (BSOD included for free!)


Exactly! I'm glad someone's catching my drift.

This is how windows started, if we start something like this for DS - then it has the potential windows did back then!

#109758 - Joe_Sextus - Tue Nov 21, 2006 12:42 am

Izhido wrote:
Just out of curiosity, are you going to implement DPMI? That sure would help a lot when porting DOS apps...

Just imagine... the DS breaking the 640kb barrier into a whole new world of... of...

D'oh!

Nevermind. :D :D :D

PS: Just a joke, man! Now, seriously, will you implement DPMI???

- Izhido


I'm not sure, I just want basic dos (equivalent of io.sys, msdos.sys, and command.com) for now.

#109789 - HyperHacker - Tue Nov 21, 2006 7:29 am

Windows DS? No no... WinDS. :p
_________________
I'm a PSP hacker now, but I still <3 DS.

#109851 - josath - Tue Nov 21, 2006 7:11 pm

HyperHacker wrote:
Windows DS? No no... WinDS. :p


We already have a WinDS:
http://s3.invisionfree.com/GBAWinS/index.php?act=site

#109926 - Ant6n - Thu Nov 23, 2006 4:47 am

does anybody know where one can find very specific information about the 8086 though? i.e. all the opcodes and all possible instruction format's etc. Also, what else would one need to 'emulate' besides the cpu to be able to run dos programs?

#109927 - Lazy1 - Thu Nov 23, 2006 5:15 am

I'd say grab dosbox and an 8086 assembly tutorial/book, there is no point in sitting down with just an opcode table and trying to write a cpu core.

Basically what you need:
------------------------------
808x cpu core
CGA Graphics emulation
implement bios/dos system calls

You'd probably be looking at an interpreter rather than a full blown emulator that can run dos.
Then you can make small test programs and run them as you build your emulator and keep adding whatever is missing.

#109928 - Joe_Sextus - Thu Nov 23, 2006 5:19 am

Ant6n wrote:
does anybody know where one can find very specific information about the 8086 though? i.e. all the opcodes and all possible instruction format's etc. Also, what else would one need to 'emulate' besides the cpu to be able to run dos programs?

I have a book from my Computer Architecture class that has all the instruction through the pentium. It called "IBM PC Assembly Language and Programming (Fifth Edition)" by Peter Abel. That might have what your looking for.

#109930 - Ant6n - Thu Nov 23, 2006 6:10 am

I have never read on how a cpu is emulated (i mean just the basic core). it probably comes down to something like
- find what the sources are, and load them into r1,r2
- find out what the operation is and
- jump to a place where this operation is executed (i.e. r1+r2->r1).
- jump to some place where
- the flags (parity, sign, overflow, auxiliary) are being set,
- r1 is moved to the destination register
- repeat.

i am interested in how this is done, actually doing it seems like a crazy amount of work. it would probably be easier to do a JVM.

actually, there is quite some amount of information on 80x86, but only few sources on the 8086 alone. I think most dos programs that would run at <8 MHz run on the 8086 alone.

#109936 - OOPMan - Thu Nov 23, 2006 7:22 am

Bochs is an x86 emulator. You might want to take a look at the source code for it if that's what you're keen on doing. At the very least it would be a useful reference...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#110019 - Payk - Fri Nov 24, 2006 9:23 am

Well Bochs takes about 16 minutes to load win95 on gp2x.
But it has alot of more ram, and better display resolution.
I also thought about a dos emu, but thats stupid to emulate/translate asm
since that are to little steps to translate. Smaller steps = more waste of time. Its much better to just make a java platform, dslua or maybe a script os which can read qbasic. The commands of java or qb arent that small steps. so there is less interprating then calculating as well. In Bochs loib its vice versa(i guess).

#110059 - josath - Sat Nov 25, 2006 3:36 am

Ant6n wrote:
I have never read on how a cpu is emulated (i mean just the basic core). it probably comes down to something like
- find what the sources are, and load them into r1,r2
- find out what the operation is and
- jump to a place where this operation is executed (i.e. r1+r2->r1).
- jump to some place where
- the flags (parity, sign, overflow, auxiliary) are being set,
- r1 is moved to the destination register
- repeat.

i am interested in how this is done, actually doing it seems like a crazy amount of work. it would probably be easier to do a JVM.

actually, there is quite some amount of information on 80x86, but only few sources on the 8086 alone. I think most dos programs that would run at <8 MHz run on the 8086 alone.


These should give you most of the info you need:
Code:
Intel Architecture Software Developer's Manual
  Volume 1: Basic Architecture
  Volume 2: Instruction Set Reference Manual
  Volume 3: System Programing Guide

easy to find on google.

In order to run old dos apps, you also need to emulate:
BIOS routines
Text-Mode Display
Disk access
Keyboard input

Optional things:
CGA Video (play some old 4-color games)
EGA Video (more advanced, play 16-color video games)
Joystick input
Mouse input
PC Speaker for some beeps and blips. Soundblaster type stuff is probably too advanced.

Here's an interesting tutorial on writing an emulator:
http://fms.komkon.org/EMUL8/HOWTO.html

#110084 - OOPMan - Sat Nov 25, 2006 8:56 am

Nice link Josath :-)
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#110214 - Joe_Sextus - Sun Nov 26, 2006 10:08 pm

Can anyone point me to some good books or references on how to write an emulator?

#110265 - Ant6n - Mon Nov 27, 2006 9:48 am

ha! I have been searching for a 8086-only reference, since references usually go up til pentium which makes finding the information about the 8086 the biggest hassle.
Instead i now found some nice reference to what appears to be a mobile spin off the 8186. it has seven instructions added to the original design, and its a little faster. so basicly nothin changed. here we go
ftp://download.intel.com/design/intarch/manuals/27095003.pdf
has nice lists with the opcodes and decoding info, together with a normal intel x86 reference (which tells what exactly each instruction does) this could be doable.
a list of only 8086 instructions with what they do and which flags they set is at
http://www.emu8086.com/assembly_language_tutorial_assembler_reference/8086_instruction_set.html
together with the info from josath (esp. the short tutorial), one could have something up in C.
I realize that this might not be very relevant for somebody who doesnt develope for the ds but only gba, as the gba might not only be a little bit slow but also too constraint on memory. so i guess i am out of this game for the moment...