flat assembler
Message board for the users of flat assembler.
Index
> DOS > Support MS COFF OBJ for DOS and proc, endp, struct in DOS |
Author |
|
Kenneth Zheng 07 Oct 2010, 14:07
Notes:
1. I've upgraded the macro package onto the fasm_macro_0.02.zip. Please use it. 2. Added RELOC_ADDR macro for using COFF OBJ file. 3. There are three programs for playing DOS, WIN32 and WIN64 ASM program with proc, endp and struct. examples\dos\doscoff : COFF OBJ for DOS DEMO examples\dos\dos_seg: proc, endp and struct for DOS examples\win\template3: proc, endp and strcut for WIN32 examples\win64\template3: proc, endp and strcut for WIN64 Hi, Guys: I've come back after one year. The reason is that I have to change my work job during that time. Please see the attached files for two new features for DOS development: 1. Support MS COFF OBJ for DOS. We known that FASM doesn't support MS OMF OBJ format for DOS, it only produce COM and EXE MZ format. But I hope that we can find one temp solution to beyound this limition. Please try the alink.exe , it can combine COFF and OMF objs onto one DOS EXE and COM MZ format. Of course, it need some of programs skill to implement it. Please see below code for it: examples\dos\doscoff\doscoff.asm: Code: FORMAT MS COFF ;============================================================================ include 'PRIVATE\DOS.INC' ;============================================================================ section '.text' code USE16 public _Start org 0h _Start: cli cld mov eax, 0 sub eax, 8 mov esp, eax push cs pop ds mov ax, ds mov ds, ax mov es, ax mov gs, ax xor ebx, ebx call near @f @@: pop bx sub ebx,@b ;Calculate the Loaded Address mov ah,9 lea edx, [hello] add edx, ebx ;Get the Runtime Adddress int 21H mov ax,4c00H int 21H section '.data' data shareable hello db 'COFF OBJ Format for DOS Demo Program',0DH,0AH db 'Hello, The FASM World!',0DH,0AH db 'Designer:Kenneth Zheng 2003/07/16','$' build.bat: Code: @echo off \fasm\fasm.exe doscoff.asm doscoff.obj alink -oEXE doscoff.obj alink.exe is one open source and free linker, you can find its source code from below web link: [url] http://alink.sourceforge.net/download.html [/url] 2. Support proc, endp and strcut for DOS 16 bit program. We known that Tomasz has supported proc32.inc and proc64.inc, but he doesn't present proc16.inc. So I've made it and combine proc16.inc, proc32.inc and proc64.inc onto one file proc.inc. It means that you only include one file 'proc.inc' onto your ASM file, you can use proc, endp, structure ionto the 16bit, 32bit and 64bit ASM files. Please see the examples\dos\dos_seg\dos_seg.asm: Code: FORMAT MZ ENTRY main:start ; program entry point STACK 100h ; stack size ;============================================================================ include 'private\dos.inc' ;============================================================================ segment main ; main program segment start: ;call extra:dummy_proc ccall test_proc,1234h mov ax,'F' call extra:write_char_f,cs,ax call extra:write_text,text,hello mov ax,4C00h int 21h proc test_proc c uses eax ebx dx, \ test_para:WORD local test_local:WORD, hello1[10]:BYTE mov ax,[test_para] mov [test_local],ax mov bx,[test_local] mov al,[hello2] ret endp hello2 db 'xxxx' ;============================================================================ segment text hello DB 0Dh,0Ah,09h,'Hello world! --Test HLL procedures on DOS platform' DB 0Dh,0Ah,09h,"Author:Kenneth Zheng Date:March 03th, 2004" DB 0Dh,0Ah,24h ;============================================================================ segment extra ;---------------------------------------------------------------------------- proc_far write_text str_seg,str_offset local local_proc:WORD push ds mov ax,[str_seg] mov ds,ax mov dx,[str_offset] mov ah,9h int 21h mov ax,write_char_n mov [local_proc],ax mov ax,'N' call [local_proc],ax pop ds ret endp ;---------------------------------------------------------------------------- proc write_char_n char push ds pusha mov ax,cs mov ds,ax mov ah,2 mov dx,[char] xor dh,dh int 21h popa pop ds ret endp ;---------------------------------------------------------------------------- proc_far write_char_f char_seg,char push ds pusha mov ax,[char_seg] mov ds,ax mov ah,2 mov dx,[char] xor dh,dh int 21h popa pop ds ret endp proc_far dummy_proc local local_proc:WORD mov ax,[local_proc] ret endp Otherwise, I hope that FASM release package can combine multi packages onto one package. And we maybe use below directory tree for example codes: \fasm\examples\dos ==for Dos DEMO programs \fasm\examples\win == for WIN DEMO programs \fasm\examples\Linux == For Linux DEMO Programs \fasm\examples\Unix == For Unix DEMO programs \fasm\examples\WIN64 == For WIN64 DEMO programs If you have any questions about it, please tell me. Thanks. Kenneth Zheng October 7th ,2010
_________________ Pure Assembly Language Funs Last edited by Kenneth Zheng on 12 Oct 2010, 09:23; edited 2 times in total |
|||||||||||
07 Oct 2010, 14:07 |
|
baldr 07 Oct 2010, 18:41
Kenneth Zheng,
How about 16-bit fixups? Add mov ax, $ anywhere, it won't get IMAGE_REL_I386_DIR16 record. I wish it was so easy. |
|||
07 Oct 2010, 18:41 |
|
Kenneth Zheng 08 Oct 2010, 02:30
Hi, Baldr:
Please see below code for get current code relolcation address: Code: call near @f @@: pop bx sub ebx,@b ;Calculate the Loaded Address For example, if this program is loaded onto 0x100 by DOS, the EBX will equal to 0x100 after executed above code. Code: lea edx, [hello] add edx, ebx ;Get the Runtime Adddress section '.data' data shareable hello db 'COFF OBJ Format for DOS Demo Program',0DH,0AH So used two line codes to get the runtime address. I create one new macro (RELOC_ADDR) to implemnet above codes, it's one easy method to do it. Code: FORMAT MS COFF ;============================================================================ include 'PRIVATE\DOS.INC' ;============================================================================ ;---------------------------------------------------------------------------- ; ; RELOC_ADDR - Reloated runtime Address ; ; Entry: ; FloatAddr : It's need to be reloate address. ; ; Exit: ; EAX : It point to runtime address. ; ; Modified: ; EAX ; ; Processing: ; 1. Calculated the OS loading address of program. ; 2. Added the absolate address onto float address. ; ;---------------------------------------------------------------------------- macro RELOC_ADDR FloatAddr { local NextInst common push ebx xor ebx, ebx call near NextInst NextInst: pop bx sub ebx,NextInst ;Calculate the Loaded Address lea eax, [FloatAddr] add eax, ebx pop ebx } section '.text' code USE16 public _Start org 0h _Start: cli cld mov eax, 0 sub eax, 8 mov esp, eax push cs pop ds mov ax, ds mov ds, ax mov es, ax mov gs, ax RELOC_ADDR hello mov edx, eax mov ah,9 int 21H mov ax,4c00H int 21H section '.data' data shareable hello db 'COFF OBJ Format for DOS Demo Program',0DH,0AH db 'Hello, The FASM World!',0DH,0AH db 'Designer:Kenneth Zheng 2003/07/16','$' Thanks. Kenneth Zheng October 08th, 2010
_________________ Pure Assembly Language Funs |
|||||||||||
08 Oct 2010, 02:30 |
|
Kenneth Zheng 12 Oct 2010, 09:43
Hi, rugxulo:
Thank your reply for this topic. Yes, we known that FASM supported COFF OBJ for WIN and Linux, but it doesn't support OMF OBJ for DOS. But some of bigger project for DOS needs several OBJ and libary, it maybe use C language to implement some of codes. So OMF OBJ format is one important feature for big project. Alink.exe is one open source linker, it can combine COFF OBJ and OMF OBJ and then link it onto one DOS MZ exe. It seems one good temp solution to beyond FASM limition. Otherwise, the finally solution is that we should modifiy FASM source code to support OMF OBJ as FASMARM to do it. I have thinked another method to do it: 1. Using FASM or other tool to create PE32 or PE32+ EXE. 2. Made one PE32 or PE32+ loader for DOS. 3. Run PE32 or PE32+ Loader to load PE32 EXE in the DOS. Kenneth Zheng October 12th, 2010 _________________ Pure Assembly Language Funs |
|||
12 Oct 2010, 09:43 |
|
Tomasz Grysztar 12 Oct 2010, 11:40
Kenneth Zheng wrote: Otherwise, the finally solution is that we should modifiy FASM source code to support OMF OBJ as FASMARM to do it. |
|||
12 Oct 2010, 11:40 |
|
edfed 12 Oct 2010, 12:09
or make it in the source of your program. fasm is just a compiler.
then, it can do anything as you want? if you want to relocate code, the simple way is to use org xxx, then, load it in a segment. and then, it will be relocated. it is a run time trick, not a compile time. then, it should be implemented in the program to run, not in the compiler. |
|||
12 Oct 2010, 12:09 |
|
rugxulo 12 Oct 2010, 22:09
1). Use Agner's ObjConv to convert to/from (DJGPP or incompatible MS) COFF, ELF, OMF, Mach-O
2). Use NASM, JWasm, LZASM (which all support OMF) 3). Use a linker (Alink, WLINK) that supports mixing different formats 4). Use DJGPP (COFF) instead of OpenWatcom (OMF) to recompile, if possible 5). Use HX, which does have a PE loader (and libs and runtime and support from various compilers) 6). (hard) hack up FASM to work |
|||
12 Oct 2010, 22:09 |
|
Kenneth Zheng 13 Oct 2010, 06:32
1). ObjConv can't support convert 32bit COFF onto 16BIT OMF OBJ task. I have tried to use it, it's failure.
2). Nasm, JWasm and LZASM support OMF format, but I hope that we can use FASM to do it. 3). Alink.exe can caclulate correctly relocation address with COFF OBJ, but Wlink.exe can't do it. Please see the disasmler result of DOSCOFF.EXE (DOS DEMO 1), I have used alink.exe and wlink.exe to create one DOS MZ EXE, only Alink.exe is okay and doscoff.exe executed normally. Wlink.exe created one DOSCOFF.exe but it can't run in the DOS. The reason is that wlink.exe will put all of COFF relocation address onto 0. 4). Using LD of DJGPP is one good solution. 5). HX doesn't support PE32+ format. 6). Thomas said that it is one hard work to modify FASM complier. So we have to accept his idea for it. But I think that we maybe design one COFF onto OMF OBJ tool for helpping FASM to do it. Kenneth Zheng October 13th, 2010 _________________ Pure Assembly Language Funs |
|||
13 Oct 2010, 06:32 |
|
DOS386 14 Oct 2010, 03:06
> Please try the alink.exe , it can combine COFF and OMF objs onto one
> DOS EXE and COM MZ format. Of course, it need some of > programs skill to implement it. Funny. So you manipulated MS-COFF-32 to MS-COFF-16 and ALINK is able to brew a 16-bit MZ EXE from it ??? Still, no C compiler will brew a compatible MS-COFF-16 I ASS'ume There is no "COM MZ format" > 5). HX doesn't support PE32+ format. But what's the problem ??? "PE32++" is in fact PE64 - used to host 64-bit long mode code. PS: lack of OMF support is a flaw of FASM, but I personally don't need OMF. |
|||
14 Oct 2010, 03:06 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.