Making a linker

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Touch
Member
Member
Posts: 56
Joined: Sun Oct 22, 2006 10:33 am
Location: England

Making a linker

Post by Touch »

Grr. Now I'm linking troubles.

I need to make the kernel. Evrything is done except the linking.

I have 4 files, that all need to be made into 1 file called "securekernel.bin".

Could anyone help me?

P.S it's a 16-bit kernel.
"We cannot trust the sword in the hands of a n00b!" - Southpark
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

I would use a linker script. Mine is as follows (the file is link.ld and is adapted from bran's kernel development tutorial on osdever):

Code: Select all

ENTRY(_kernelstart);
OUTPUT_FORMAT(binary);
phys = 0xC0000000;

SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  . = ALIGN(4096);
}
As you can see, this is for a flat binary file which will be loaded at 3GB (0xc0000000). Assuming you are using a DOS-based command prompt and LD (as I have assumed from your previous post), you would then type the following:

ld -T link.ld -o securekernel.bin asm\kernel.o bin\*.o

This ensures that kernel.o (my kernel's entry point) gets linked first, followed by all object files in the bin\ subdirectory. For your files, this may become:

ld -T link.ld -o securekernel.bin file1.o file2.o file3.o file4.o

A word of caution - the file you are creating has more than 8.3 characters. For this reason, you need to know what you are looking for if you are using, for example, a FAT12 floppy disk. The file will most likely be named SECURE~1BIN in the FAT root directory.

HTH,
Adam

[EDIT]Sorry - didn't spot that you wanted a 16 bit kernel. I don't know what else this affects, but you certainly won't want to be setting your entry point at 0xC0000000 :) [/EDIT]
User avatar
Touch
Member
Member
Posts: 56
Joined: Sun Oct 22, 2006 10:33 am
Location: England

Post by Touch »

I can attach the files, maybe you could look and try.
"We cannot trust the sword in the hands of a n00b!" - Southpark
INF1n1t
Member
Member
Posts: 60
Joined: Fri Dec 22, 2006 5:32 pm
Location: Somewhere Down...

Post by INF1n1t »

Hi,
Today, I wrote my first 32-Bit Protected Mode Binary File (abbreviation: 32BPMBF) ;) However...I wrote the following piece of code:

wllcome db 'Wellcome to the INF0x OS!', 0

and 5-7 instructions after that:

Code: Select all

mov esi, wllcome
I've the flat mode set up. And guess what happened? Nothing. It did put something in ESI and it was the offset of the wllcome string, for example 206h. But 206h is not the flat memory address, where wllcome stands: so I set esi to a base value of 0x100000 (1 MB mark) and added the wllcome offset to it. Guess what? It worked!

I'm talking about that, because of your linker problems: When you want to link something correctly, be sure you specify the right address. The Linker can't put the universal addressing code just because you didn't specified where the code would be running. 206h in the previous example is totally wrong, but if the linker knows you're talking about 206h offset from 0x100000....that's another thing

Now, on the question: Linking several files. Let me tell you, how I linked my .asm files (I'm using nASM)...I used '%include ....' and it worked. What happened exactly? nASM put the code of the include file, exactly where the line "%include ..." stays.

Why don't you try to include these files you're talking about, so the linker will have only one file to work on?

Sorry, if I misunderstand somethnig, or if I'm not correct!
I think, I have problems with Bochs. The biggest one: Bochs hates me!
Post Reply