OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 5:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Weird elf program that could be ran in both MS-DOS and unix?
PostPosted: Fri Mar 26, 2021 7:30 am 
Offline
Member
Member

Joined: Tue Jul 14, 2020 4:01 am
Posts: 70
So I found this weird program in grub4dos, which is called "bootlace.com", that can be ran in both MS-DOS and unix, and google didn't help. I would like an explanation on how did it do that.


Top
 Profile  
 
 Post subject: Re: Weird elf program that could be ran in both MS-DOS and u
PostPosted: Fri Mar 26, 2021 8:04 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
clementttttttttt wrote:
So I found this weird program in grub4dos, which is called "bootlace.com", that can be ran in both MS-DOS and unix, and google didn't help.
Have you tried github? bootlace source.
clementttttttttt wrote:
I would like an explanation on how did it do that.
Use the source Luke...! :-D

The DOS .com executable has no header, it just starts executing the code in real mode from the first byte. ELF needs a header, which starts with 4 magic bytes. Those magic bytes interpreted as real mode code gives:
Code:
   # ELF64 header backup here upto the end of file. Its length is 0x40.

   .byte   0x7F, 0x45, 0x4C, 0x46   # ELF magic number
               // 7F 45 = jg dos_entry_point
               // 4C = decw %sp
               // 46 = incw %si
So assuming CPU flags are set, that "jg" instruction will jump to the "dos_entry_point", while under Linux the ELF header is parsed and the code specified by the ELF e_entry point will be executed instead (_start_linux). If CPU flags aren't set for the conditional jump, then the first 16 bytes of the file will be executed in real-mode, which then would jump to the same dos_entry_point.

Cheers,
bzt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group