How am I supposed to create a COM file bigger than 64KB (This is called 'Binary File' in NASM; it actually doesn't have to start at CS:0100!)???
Posted on 2006-09-17 04:30:06 by Firefall
I wouldn't bother trying this in MASM - it would probably require you to assemble to exe format and use an "exe2bin" program... one of the reasons assemblers like nasm and fasm were created in the first place.
Posted on 2006-09-17 08:15:10 by f0dder
I think it's not posible  to be a com file bigger than 0FEFFh ( 0FFFF(Max Offset limit) - 0100h(Constant start address))
The com format have no identical structure that would split data and code, so all "things" must store only one segment. As f0dder said, you had better choice exe
Posted on 2006-09-18 05:26:29 by Dite
A .com file can't, but a "flat binary" (used by people for early os-dev experiments) can. For my toy kernel, I use PE format instead... only took ~5 lines of code more than flat binary to have crude PE support, so it's worth it.
Posted on 2006-09-18 06:22:32 by f0dder
Actually writing my own OS (In fact it's just kinda "standalone game") is what I want to do. How can I make such a flat binary? I don't wanna use PE because I want the stuff raw, not with headers and things ;)
Posted on 2006-09-18 16:21:47 by Firefall
Firefall: use fasm or nasm, then :) (or a specialized linker that does binary output).

Using PE is nice, though... as I said above, it's only a few more lines of code to handle (simple) PE instead of raw files, and you don't have to mock around as much.
Posted on 2006-09-18 17:09:13 by f0dder
Well my reason for not using NASM is simply that I am not familiar with its Syntax (I like the MASM Syntax better, and I see it in a way as more important standard). As I know so far, FASM supports MASM Syntax, so that would probably work. But I guess if I use any Macros with if-clauses (Not runtime-ones, assembly-time ones), FASM will not accept them? Another way would be to assemble & link multiple files with MASM and link the COM's afterwards. But then there's that problem with relative jmps and the problem that one instruction might be splitten, which is not very pleasant indeed. I still don't want to use PE, even if it takes only a few lines to support 'em. The only possibility would be to crate a PE and then in some way cut the header off. But I don't think it's as easy as that, is it?
Posted on 2006-09-19 10:29:37 by Firefall

The only possibility would be to crate a PE and then in some way cut the header off. But I don't think it's as easy as that, is it?

That's actually pretty easy, if you don't care about supporting non-standard PEs, and don't want to support imports or relocations...

I still don't see why you have this aversion about using a standard fileformat for your kernel, but I guess that's your own business :)
Posted on 2006-09-19 16:41:55 by f0dder
Well I don't know too well about the PE structure, but the only advantages I see in EXE files is that they are not required (by MASM, for example...) to be smaller than 64K. Well if it's easy to cut of the header, and if that's everything - how do I do that? I mean how many Bytes to I have tu cut off?
Posted on 2006-09-20 11:24:10 by Firefall
Hmmm It's not so that much easy. Nevertheless, If your code don't contain any ".data" section, just cut first 0x200 bytes.
The Atc. contains a document about PE file format
Attachments:
Posted on 2006-09-20 15:01:07 by Dite
My code uses only .code, i include the data in the .code. Now the questions which remain are:
1. HOW do I tell MASM to make a PE file?
2. How will it treat the offsets?
Posted on 2006-09-21 15:17:28 by Firefall
creating PE in FASM takes 1 line - "format PE". and you can start writing your code. nothing harder than "org 100h".

but you still need imports to effectively code something. with usage of macros it's this:

; example of simplified Win32 programming using complex macro features

include 'win32ax.inc'

.code

  start:
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!","Win32 Assembly",MB_OK
invoke ExitProcess,0

.end start
Posted on 2006-09-24 04:53:29 by vid

1. HOW do I tell MASM to make a PE file?


This is actually a function of the linker that MASM passes information to. At any rate, PE is the default format that MASM produces for Win32 programs. My best guess would be to use the ".model flat" directive.

For example, here is a dummy PE program in MASM that you can use as a skeleton...


;ml.exe /c /coff dummy.asm
;link.exe /ENTRY:start /SUBSYSTEM:NATIVE dummy.obj

.386
.model flat

.data
;insert your data here

.code
_start:
;insert your code here
end _start


I cannot promise you that code will help you much, or even will lead you in the right direction.

What I do know, is that if you are serious about developing non-Windows binaries with MASM, you should probably check out POASM instead. The syntax is very similar, if not exactly the same, but there are no licensing issues/limitations in POASM that you will find with using MASM. In short, MASM was developed by Microsoft with the intention that you use it to develop programs that will run on their own operating system products. An intention they enforce with their EULA.


2. How will it treat the offsets?


IIRC, standard PE applications expect to be loaded at address 0x00400000 (the 4MB Mark). This is achieved in Windows by the use of Paging. I know drivers and other system DLL files have a specified/preferred loading address, but this is something that f0dder will be better able to guide you on.
Posted on 2006-09-24 05:43:22 by SpooK

In short, MASM was developed by Microsoft with the intention that you use it to develop programs that will run on their own operating system products. An intention they enforce with their EULA.

Keep in mind that this depens on where you got MASM from; if it's one of the free downloads like the SDK, you will be pretty limited. If you got MASM with Visual Studio, there aren't any such silly limitations afaik.

Pretty interesting, by the way, that the MASM license from the free downloads is so much stricter than the vc2003 toolkit license... the toolkit can be used for non-windows and commercial development.

Loading address is set by the linker with /BASE:xxxxxx, and you can include relocations by /FIXED:NO.
Posted on 2006-09-24 05:53:06 by f0dder
Yeah, I heard about the VC toolkit license being better (less restrictive), but I didn't know they allowed non-Windows development though.

Good information to pass along for those MASM users :)
Posted on 2006-09-24 06:07:38 by SpooK

Yeah, I heard about the VC toolkit license being better (less restrictive), but I didn't know they allowed non-Windows development though.

Good information to pass along for those MASM users :)

Iirc the toolkit doesn't include masm, though :) - so people wanting to use masm (and who don't need very complicated macros) should definitely check out poasm.
Posted on 2006-09-24 06:14:29 by f0dder
Do you know if a similar unrestricted MASM/license comes with Visual C++ 2005 (Express), off-hand???
Posted on 2006-09-24 06:20:00 by SpooK
masm has its own license and it supercedes all other licenses.

Paul
Posted on 2006-09-24 10:30:28 by PBrennick
There's an answer.

Bottom line, use POASM ;)
Posted on 2006-09-24 15:24:05 by SpooK
f0dder: 1. how do i tell MASM how/where to include relocations data? is it possible?
2. can MASM generate other type of relocations than type 3 (relocated dword)?

thanks
Posted on 2006-09-24 18:16:05 by vid