OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 10:48 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [SOLVED] Use ld to output flat binary for real mode
PostPosted: Sun Jul 22, 2018 12:28 am 
Offline

Joined: Sun Jul 22, 2018 12:07 am
Posts: 3
I basically want to use ld to output as a flat binary that I can use in real mode. I mostly want to do this so that I can use C for my second stage bootloader. Here is my linker script heavily based off of(mostly copied) it's page on the OsDev Wiki:

Code:
ENTRY(start)
STARTUP(bootldr_s2.s.o)
OUTPUT_FORMAT("binary_i386?") /* Biggest isue here */
SECTIONS
{
  .text.start (_KERNEL_BASE_) : { /* I change this to 0x0000, right? */
    bootldr_s2.s.o( .text )
  }

  .text : ALIGN(0x1000) {
_TEXT_START_ = .;
    *(.text)
_TEXT_END_ = .;
  }

  .data : ALIGN(0x1000) {
_DATA_START_ = .;
    *(.data)
_DATA_END_ = .;
  }

  .bss : ALIGN(0x1000) {
_BSS_START_ = .;
    *(.bss)
_BSS_END_ = .;
  }


}


My biggest issue here is that I don't know what I should put as the output format. If i use "binary", it gives me this:
Code:
ld: skipping incompatible bootldr_s2.s.o when searching for bootldr_s2.s.o
ld: cannot find bootldr_s2.s.o

Note that bootldr_s2.s was compiled with
Code:
nasm -f elf -o bootldr_s2.s.o

and that it's currently
Code:
    BITS 16
    start:
        mov eax, 0xBCAF ;If this is in eax, then the code loaded
        jmp $


I'm not really sure where to go from here, and would really appreciate some help.


Last edited by person4268 on Sun Jul 22, 2018 7:46 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Use ld to output flat binary for real mode
PostPosted: Sun Jul 22, 2018 1:10 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
Check out Smaller C.


Top
 Profile  
 
 Post subject: Re: Use ld to output flat binary for real mode
PostPosted: Sun Jul 22, 2018 4:34 am 
Offline

Joined: Sun Apr 02, 2017 11:43 am
Posts: 12
ENTRY(start)
STARTUP(bootldr_s2.s.o) // set startup file (bootldr_s2.s.o)
OUTPUT_ARCH(i386) // set arch = i386 (32 bit ) / or i386:x86-64 (64 bit) / ia64 (for ia 64 arch)
OUTPUT_FORMAT("binary") // set output type (elf32-i386 / elf32-x86-64 / elf64-x86-64 / pe-i386 / pe-x86-64 / binary )


Top
 Profile  
 
 Post subject: Re: Use ld to output flat binary for real mode
PostPosted: Sun Jul 22, 2018 6:18 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
If you have a single input file, and want bin format output, why are you using elf files and the linker? Nasm can output a bin file directly.


Top
 Profile  
 
 Post subject: Re: Use ld to output flat binary for real mode
PostPosted: Sun Jul 22, 2018 7:37 am 
Offline

Joined: Sun Jul 22, 2018 12:07 am
Posts: 3
I know that nasm can output a flat binary file, but I'm linking so that I can use C once I get this working.


Top
 Profile  
 
 Post subject: Re: Use ld to output flat binary for real mode
PostPosted: Sun Jul 22, 2018 7:46 am 
Offline

Joined: Sun Jul 22, 2018 12:07 am
Posts: 3
I should also mention that GeGuNa's answer worked. Thanks for all the help!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 112 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