0

Today I am investigating more into linker files. I've been prototyping BIOS programs for many months now and I've mainly managed to run my models for debugging by ld commands For the longest time I had learned to use a template for ld in my Makefile configurations and I shuffled settings until it stuck. So often times manually testing each new setting meant I lacked the relevant resources for reference.

To illustrate this I once had a program running a LBA (Linear Block Address) method that I simply could not get any other address fitted. The Makefile template basically looks like this

FILES =boot.o
FILES2 =stage3.o 

PROCURE = rm -rf

all:    boot.bin stage1.bin stage2.bin stage3.bin
    dd if=boot.bin of=os.img bs=512 count=60 conv=notrunc
    dd if=stage1.bin of=os.img bs=512 seek=1 conv=notrunc
    dd if=stage2.bin of=os.img bs=512 seek=18 conv=notrunc
    dd if=stage3.bin of=os.img bs=512 seek=10 conv=notrunc

boot.o: boot.asm
    nasm -f elf -g -o boot.o boot.asm

stage1.o: stage1.asm
    nasm -f elf -g stage1.asm -o stage1.o

stage2.o: stage2.asm
    nasm -f elf -g stage2.asm -o stage2.o

stage3.o: stage3.asm
    nasm -f elf -g stage3.asm -o stage3.o


boot.bin: $(FILES)
    ld -T link.ld $(FILES) -o boot.bin

stage1.bin: stage1.o
    ld -g -m elf_i386 -Ttext 0x7e00 stage1.o -o stage1.bin --oformat binary

stage2.bin: stage2.o
    ld -g -m elf_i386 -T link4.ld stage2.o -o stage2.bin --oformat binary

stage3.bin: stage3.o
    ld -g -m elf_i386 -Ttext 0x9000 stage3.o -o stage3.bin --oformat binary


clean:
    $(PROCURE) *\.o
    $(PROCURE) *\.bin
    $(PROCURE) os.img

In fact this would shift the platform jump address by whatever file I tried to link telling me that the count and seek commands in dd were not consistant or atleast not configured. However these were actually the same settings I use now where the difference being that I use the regular BIOS instructions (instead of ports for LBA) being apparently more compatible in a way.

Now my main concern is the problem of design being when you don't have the essential parts that omissions happen more often (Disclaimer). Here is the original linker template that had been granted to me from before.

link.ld

OUTPUT_FORMAT(binary)
OUTPUT_ARCH(i386)
ENTRY(_prep_module)

SECTIONS
{


    . = 0x7c00;
    _premier = .;
    _prep_module =.;

    .text 0x7C00 : {*(.text)}
    .rodata : {*(.rodata)}
    .data : {*(.data)}
    
    
    . = _premier + 512*1-2;
    .dummy : {BYTE(0x55); BYTE(0xaa);}

    _bss_premier =.;
        .bss : {*(.bss)}
        _bss_stub = .;
        _heap = .;
        /DISCARD/ : {*(.comment)*(.eh_frame)*(.note.GNU.stack)}




}

As a result I have chosen to practice my models in a more compact range so I can practice in the BIOS instruction set.Now I know how to link into the first segment of standard settings (0FFFF=64kb) but that hardly scrapes a fraction from the allotted amount of 1MB. Here the remainder of the article is on how to use these ld files to configure the other segments. My hope is the answer lets me move on from amateur level to a more usable form. I've looked through several related articles however most just kinda improvise on the question. I did manage to get a pretty good resource from the Texas Instruments webpage however they do more general linking for other things like gcc so I'll be looking into that as of right now. Here's the link to that page.

https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/index.html

Meanwhile if anyone else would like to know how the program is going you can have a look at a source code build from the NASM forum page from the link here https://forum.nasm.us/index.php?topic=3866.0

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

0 Answers0