News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Generating an ELF format for Linux

Started by cassio, May 26, 2016, 07:01:26 AM

Previous topic - Next topic

cassio

Hello Everyone!
I'm from Brazil and I will try to ask you my doubt to know if it's possible to do what I need  :biggrin:

I'm working in a bus station in the south of Brazil and we are migrating all windows applications to linux. And we are in 99 % of the project  :eusa_dance:

The last one is a DOS application developed through Assembly and communicating through serial port . And that is the most important app here. ( Yes! the most important app is running in DOS  :lol:  )

So, finally here is my doubt:

Do I wave any way to take the ".asm"  file from that app and generate and ELF executable file to run in Linux ? ( yes! I have the ".asm" file with the source code, and not just the ".exe" file )

Using MASM in windows, I can generate the OMF file without any problem, but when I try to generate ELF file through HJwasm, I have the following error:


Running At CentOS 64 bit or Ubuntu 16 64bit:

Quote
# ./hjwasm -elf -Zg -Zm app.asm
HJWasm v2.14, May 23 2016, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

tra3.asm : Error A2168: General Failure

And when I try to run through Windows:

Quote
hjwasm.exe -elf -Zg -Zm app.asm
HJWasm v2.14, May 23 2016, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.

app.asm: Internal error in elf.c (1234)

Can you help me ?

Congratulations in advance by the forum.

Regards from Brazil  :t
What goes arround comes arround

GoneFishing

Hi cassio,
I'm afraid  you cannot generate a working Linux app from your old DOS  sources without modification.
There're  few members here who have experience in programming for Linux. I have played a bit with *JWASM   on Linux but I'm not a programmer and enjoying my summer vacations at the moment.

Wny not re-write your DOS sources from the scratch in C and compile it with GCC ?
Think of it. Lots of  C programmers out there, better support , lower cost .



mineiro

Put more info about the problem Cassio.
On ms-dos you can use instructions in and out because real mode (serial port), but on protected mode/long mode these instructions need more priviledge.
You can translate ms-dos functions one by one to linux 32 or 64 bits. Like int 20h or int 21h ax=4ch on ms-dos that is the same as ExitProcess on win32 and 64, and exit function (int 80) on linux 32 or a syscall (I forgot the number) to linux 64 as native or just call some C library. A lot of work.

Are you assembling using (h)jwasm and linking with ld? How are setup the path token? (on ms-dos and windows this is by default "\" but on linux this is "/", better you adjust the environment and remove these delimiters to portability from source code).

I'm supposing here, remove parts of program or just comment lines that have in and out instructions and try to compile. If works, you should create like a driver (module) to linux with these parts or find a function that access this port on user mode.

I'm from the same country irmão.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

cassio

Hi GoneFishing!
I hope you enjoy your vacations  :biggrin:

I was thinking about your suggestion and It is very good, but we have a hardware problem ( few computers with DOS support, and they are not reliable ) and I was thinking about anything to earn some time ultil we create a new application!

If the application stops, the bus station will stop to sell tickets, and that means the hell to us  :icon_eek:

Quote
I'm from the same country irmão.

Hi Brother !
I Will try your suggestion about the driver.
I did not understand that part you talked about the path
I am Using (h)Jwasm but I was not able to compile the code to link until now. Do you have a suggestion about the Linker I can use ?

Thanks to ou both for the suggestions!
What goes arround comes arround

avcaballero

Maybe it's a bit obvious but, have you tested on dosbox running on linux? or in a virtual machine. But dosbox usually goes very well.

GoneFishing

Quote from: avcaballero on May 26, 2016, 11:58:09 PM
Maybe it's a bit obvious but, have you tested on dosbox running on linux? or in a virtual machine. But dosbox usually goes very well.

I thought about it . AFAIK DOS virtual machine always loaded  100% of my CPU .

cassio:
Maybe for the timebeing it's better do not make any changes into your hard- and software configuration until you'll have  PROPERLY WORKING AND WELL TESTED  replacement for it.
I think your wish is not to have more problem with your project ? so I repeat my advice :
Think about the future : re-write it in C, compile with GCC, link with LD

Quote from: cassio on May 26, 2016, 11:28:30 PM
...
I hope you enjoy your vacations  :biggrin:
...

I could do it better if I had more money/power and was a little bit younger (-20 years would be enough I suppose).

cassio

Quote from: avcaballero on May 26, 2016, 11:58:09 PM
Maybe it's a bit obvious but, have you tested on dosbox running on linux? or in a virtual machine. But dosbox usually goes very well.

Yes, avcabalerro, it works! But like GoneFishing was mentioned, the cpu stays 100% loaded all the time, and we have some crashs on emulator with 1 -  2  days testing.


Quote from: GoneFishing on May 27, 2016, 12:07:11 AM

cassio:
Maybe for the timebeing it's better do not make any changes into your hard- and software configuration until you'll have  PROPERLY WORKING AND WELL TESTED  replacement for it.
I think your wish is not to have more problem with your project ? so I repeat my advice :
Think about the future : re-write it in C, compile with GCC, link with LD


I think you are Right, My friend !
I Tried this topic because I thought that HJwasm was capable to generate the ELF file to execute in Linux. But if that is not simple like I thought, the better way is to re-write it.
Good Vacations for you, if it's not to enjoy the way you wanted it. At least to have some good rest.  :t
What goes arround comes arround

GoneFishing

Quote
I think you are Right, My friend !
I Tried this topic because I thought that HJwasm was capable to generate the ELF file to execute in Linux. But if that is not simple like I thought, the better way is to re-write it.
Good Vacations for you, if it's not to enjoy the way you wanted it. At least to have some good rest.  :t
I'm glad that my advise was helpful. Thank you good wishes . Good luck with your project.
Keep us informed when you solve the problem .
:t

mineiro

about path Cassio;
on ms-dos, we generally do something like:
c:\somepath\
on linux this is
/somepath/
This way, jwasm does not undestand, if you see 'include \somepath\somefile" that will not work on linux. Put only "include somefile" and adjust linux environment, or an easy way, move files to same path.
You can try other assembler to generate object file and link with ld, solasm from bogdan ontanu appears to be compatible with tasm (90% compatible with masm 16) and works on linux 64, I have changed only 1 byte from generated elf file, I posted on their forum my experiment.
You're dealing with I/O to serial port and this need priviledged code, think about this. Linux have been done to 386. That's why many ms-dos programs does not work under Vmware/qemu/... but works under microsoft virtual pc (not only int 2e).

I was thinking and you can generate elf files under windows, copy if ok to linux and 'chmod' that file to be an executable. What's nice on ms-dos assembly is that the files generally does not need library's. But, 'new line' on ms-dos/windows is 0d,0ah, on linux is only 0ah.

Well, better find a c way as said before.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

cassio

Quote from: mineiro on May 27, 2016, 04:57:22 AM
you can try other assembler to generate object file and link with ld, solasm from bogdan ontanu appears to be compatible with tasm (90% compatible with masm 16) and works on linux 64, I have changed only 1 byte from generated elf file, I posted on their forum my experiment.

I already tried with TASM, NASM, YASM.. and others through Linux.
Now I tried Sol Asm like you said, It don't recognize the syntax.

Only MASM ( 100%, in OMF format ) and Jwasm (with errors)  can understand that OLD MS-DOS Syntax using the "-Zm" and "-Zg" parameters as you can see in my post. Even in windows.

Thanks for help. But if there is no simple way to do that, We will re-write it like GoneFishing said before.

Quote from: GoneFishing on May 27, 2016, 02:32:11 AM

I'm glad that my advise was helpful. Thank you good wishes . Good luck with your project.
Keep us informed when you solve the problem .
:t
Thanks  :biggrin:
Ok, We will start the work and I'll tell you the result.
What goes arround comes arround

mineiro

#10
Have you tried a simple command line, well, you put only elf on your example, and I'm supposing no libraries need:
./jwasm -elf64 -Fo=file.o file.asm
./ld -o file file.o

If libraries are used you can try, but I know, you don't reached here because is not generating object file:
ld -o file file.o /lib/somepath/ld-2.15.so /lib/somepath/libc.so.6

Not sure but just an idea, on linux you can do an "echo $?" to echo a supposed code error and more info (like errorlevels on .bat files on windows or ms-dos), and you can find a better person to help you, maybe hjwasm developer.

Ok sir Cassio, good luck brother and welcome to forum.

On linux you have binutils package that is very usefull to assembly programmers. Debug under linux is not good, more than 1000 pages of read just to debug a program. Well man, the best choice can be a c way, on ms-dos you can acess things using interruptions (cry if this is your source code), direct access memory and port I/O (a bit of hope here). Some programs just terminate itself by doing a 'ret' instruction (windows and ms-dos tiny program), but on linux you should use a native call to exit or an exit function from c library, if not you receive a segmentation fault.
You say that it's an .exe file, so segments have been used, file is bigger than 64k.
Sorry, I really like to help you, but without source or more info I cannot.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything