MZ EXE Skeleton Made By hand

Programming, for all ages and all languages.
Post Reply
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

MZ EXE Skeleton Made By hand

Post by ~ »

I have the sample of an EXE file with code, data and a stack. I built it fully by hand and set up its stack in the program's code, also by hand.

They all (data and stack variables) are referenced relative to the position after the paragraphs of the MZ header.

I have included the file SAVEMEG.DAT to show the exact position and layout in memory of the EXE when loaded into memory. We just need to find the string "This is a command line to find the start and the end of" to find the sample command line of this program and its PSP as a result.

We can see that the EXE loader just interprets the EXE header, removes it from the image to load (normally 32 bytes long). After removing it, it generates a 256-byte PSP at the start of a segment and then loads the rest of the EXE as indicated by the size of the EXE in the MZ header as if it was a COM file but that can be more than 64K in size.

Obviously each compiler will have its own techniques to be able to use code and data among several segments, with a structure and techniques very similar to those used for being able to call and reference BIOS code and data.

But since this EXE is made fully by hand (without compilers or linkers involved), we will have to develop and maintain our own techniques to achieve the same.

We could have also created a COM file loader, then just have loaded a COM file greater than 64K. With that, we would have loaded a big COM file that supplies the vast majority of needs of a regular EXE file.

With this skeleton we can now start to learn bit by bit more practical things, like loading and executing VxD drivers all by ourselves.

However, I need to investigate and document how to implement and use relocations, which will surely be aboundantly used in VxDs.

Also, it will help to better understand LE (used by VxDs) and NE EXEs (used by Win16).

With that, along with the information about building and implementing GUIs, we could start making simple 16-bit programs that contain WinAPI functions implemented by us and now treat the WinAPI as yet another library ported natively to DOS and then to our own OSes.


Main source code:
http://archive.org/download/tmp_tests/M ... avemeg.asm

Full source code:
http://archive.org/download/tmp_tests/M ... AVEMEG.zip

Sample memory disposition of the EXE in memory (it starts with the 256-byte PSP at physical offset 0x1920):
http://archive.org/download/tmp_tests/M ... AVEMEG.DAT
Last edited by ~ on Tue Aug 30, 2016 3:00 pm, edited 4 times in total.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: MZ EXE Skeleton Made By hand

Post by BrightLight »

I have added you to my "foes" list. :roll:
I really think the mods should do something about your posts. I'd like a decent explanation for their quietness until now. This is not a DOS programming forum. If you know so much on MZ, then maybe write something on the MZ Wiki entry, but not here. :roll:
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: MZ EXE Skeleton Made By hand

Post by ~ »

I know relatively little.

But I need to study and publish this information in a much clearer way, by examples.

After fully developing this basic level, I will try to advance a simple step towards using VxD drivers in my own OS and GUI.

This is not a DOS-exclusive forum but that is a valid OS which can be ported to 32 and 64 bits, and also invoke those modes and return from them, for example, to start and finish loading a custom OS.

It's temporary code, it is better referenced on the spot.

I guess that if I was to implement a full DOS system, it would receive criticism all the same by several people, but I really need to work at that level because it matches perfectly what I know and what I need to explain in the way I better can.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: MZ EXE Skeleton Made By hand

Post by BrightLight »

The only OS which supports MZ executables is DOS. Windows and Linux support them through emulation, and even 64-bit Windows doesn't support them due to the absence of virtual 8086 mode.
~ wrote:This is not a DOS-exclusive forum but that is a valid OS which can be ported to 32 and 64 bits
What does this even mean? An MZ executable is not an OS, and cannot be ported to 32-bit or 64-bits. PE32 and PE64 files have an MZ header, but that doesn't make them MZ executables. The MZ program just prints "This program cannot be run in DOS mode." or a similar message.
Oh, and about LE and NE executables, both are just as deprecated as DOS is. Maybe you could document on PE instead; that would be more useful for this forum/wiki.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: MZ EXE Skeleton Made By hand

Post by alexfru »

omarrx024 wrote:
~ wrote:This is not a DOS-exclusive forum but that is a valid OS which can be ported to 32 and 64 bits
What does this even mean?
Probably, DOS-excluding was meant.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: MZ EXE Skeleton Made By hand

Post by alexfru »

I must say, this (creation of various DOS/Windows/Linux/whatever executables manually) has been done before and examples can be found online. It may be a good exercise for you, but I seriously doubt that the rest of the forum users are interested in this code of yours or in making DOS MZ EXEs by hand. Or in trying to resurrect and reuse bits of Windows 9x.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: MZ EXE Skeleton Made By hand

Post by onlyonemac »

Stop using archive.org as a file sharing platform.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: MZ EXE Skeleton Made By hand

Post by Brendan »

Hi,
~ wrote:This is not a DOS-exclusive forum but that is a valid OS which can be ported to 32 and 64 bits, and also invoke those modes and return from them, for example, to start and finish loading a custom OS.
The "OS Development" sub-forum (and the entire OSdev forums in general) are specifically for people creating new operating systems. It is not for people creating applications for any existing OS (Windows, Linux, FreeDOS, MS-DOS, etc).

Also note that what people consider an OS has changed in the last several decades; and MS-DOS no longer really qualifies as an OS (if it ever did). If you compare MS-DOS to UEFI you'll find that UEFI is more like an OS than MS-DOS ever was, but nobody thinks UEFI firmware is an OS. In today's world, you'd have to downgrade DOS to "about 10% of an OS".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: MZ EXE Skeleton Made By hand

Post by glauxosdever »

Hi,

omarrx024 wrote:I really think the mods should do something about your posts. I'd like a decent explanation for their quietness until now.
I second that.
omarrx024 wrote:If you know so much on MZ, then maybe write something on the MZ Wiki entry, but not here. :roll:
Please, don't encourage him to use the wiki. He will spam it with, well, spam.


Regards,
glauxosdever
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: MZ EXE Skeleton Made By hand

Post by Kazinsal »

omarrx024 wrote:I really think the mods should do something about your posts. I'd like a decent explanation for their quietness until now.
Of the list of 16 moderators on this forum, only three of them actively visit. One other one is in the IRC frequently. The rest haven't been around in years, or show up once in a blue moon to post and then disappear again.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: MZ EXE Skeleton Made By hand

Post by iansjack »

glauxosdever wrote:Hi,

omarrx024 wrote:I really think the mods should do something about your posts. I'd like a decent explanation for their quietness until now.
I second that.
omarrx024 wrote:If you know so much on MZ, then maybe write something on the MZ Wiki entry, but not here. :roll:
Please, don't encourage him to use the wiki. He will spam it with, well, spam.


Regards,
glauxosdever
The simple answer is to put the guy on your Foes list and stop replying to his posts, rather than feeding him. That way you need never know that they exist.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: MZ EXE Skeleton Made By hand

Post by Roman »

I think it's not a complete answer. I did that, but I still see him in "View unread posts". I can also see his posts in the forum index and the forums themselves. Why can't Brendan or Combuster just ban him? Aren't we all sure he is not appropriate for this forum and only spreads unrelated garbage?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: MZ EXE Skeleton Made By hand

Post by Octacone »

onlyonemac wrote:
Stop using archive.org as a file sharing platform.
Why are you guys so mad about him using that website???
When I type archive.org and press enter I go to a site called "way back machine"? What is going on?
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: MZ EXE Skeleton Made By hand

Post by onlyonemac »

octacone wrote:Why are you guys so mad about him using that website???
When I type archive.org and press enter I go to a site called "way back machine"? What is going on?
archive.org is a project aimed at preserving digital artefacts for historical reasons, much like a traditional archive or museum preserves physical artefacts. The Wayback Machine part of the site archives (read: preserves) old versions of websites. They also archive other forms of historically-significant (or likely to be historically-significant in the future) digital media, such as e-books/digital texts, music/internet radio/podcasts and software. ~ is using the site as a cloud storage and file-sharing site, specifically to store his code in a place that he can find it easily and to link to it from this forum.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: MZ EXE Skeleton Made By hand

Post by Ycep »

onlyonemac wrote:
octacone wrote:Why are you guys so mad about him using that website???
When I type archive.org and press enter I go to a site called "way back machine"? What is going on?
archive.org is a project aimed at preserving digital artefacts for historical reasons, much like a traditional archive or museum preserves physical artefacts. The Wayback Machine part of the site archives (read: preserves) old versions of websites. They also archive other forms of historically-significant (or likely to be historically-significant in the future) digital media, such as e-books/digital texts, music/internet radio/podcasts and software. ~ is using the site as a cloud storage and file-sharing site, specifically to store his code in a place that he can find it easily and to link to it from this forum.
+1. ~ shall not be given premission to upload that or I'm going to report him in archive.org, if he adds any other random DOS executable posted on this forum.
Post Reply