how to jump from bin to obj?

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
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

how to jump from bin to obj?

Post by ehenkes »

Target: I want to change to a C-Kernel

Status:
I have four files:
1) bootloader (512 Byte) starting at 7C00h by boot signature, asm ->bin format
2) kernel part I: org 8000h, switching on A20 and to PM, asm -> bin format (filled with HLT to 1024 byte) http://www.henkessoft.de/OS_Dev/OS_Dev1 ... ocId412221
3) kernel part II: asm -> obj-Format, global start, jump to main
4) kernel part III: C -> obj

OK:
a) files 3 + 4 are linked with ld to bin format
b) the three binaries (boot, I, II+III) are merged by copy and sent to floppy disk
c) bootloader jumps to 8000h (I), next jump has to be done directly (e.g. jmp 0x08:0x86e3)
d) II calls III by _main

My problem:
kernel part I (bin) is not allowed to use "extern start " and jump to start, not allowed for binaries; I cannot assemble to object format, not allowed due to org (important).

Work-around: I look up the hex address of start in the binary, and jump direct to this address from 2 to 3. This works, but address changes.

File 1 & 2 are described in my tutorial, and work perfect.

Now I use for file II:

Code: Select all

[BITS 32]
[global start]
[extern _main] ; this is in the c file
hlt
hlt 
hlt
start:
  call _main
  jmp $ 
But I cannot jump to this (global) start by file I.
Hence, I use these three HLT. I find them in the Binary by f4f4f4 and jump directly to this address. :mrgreen:

Please carry me out from this deadlock.
Must-be: Kernel I starts with 'org 0x8000'
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: how to jump from bin to obj?

Post by Combuster »

search "linker script"
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

Re: how to jump from bin to obj?

Post by ehenkes »

Thanks, I performed. The linker sequence also was important.
I simplified to bootloader, asmkernel and ckernel.

linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(RealMode)
SECTIONS
{
  .text  0x8000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  { 					
    *(.bss)
  }
}
makefile:

Code: Select all

all: 
	nasmw -O32 -f bin boot.asm -o boot.bin
	nasmw -O32 -f aout kernel.asm -o kernel.o
	gcc -c ckernel.c -o ckernel.o
	ld -T kernel.ld kernel.o ckernel.o 
	rename a.out ckernel.bin
		
	cmd /c copy /b boot.bin + ckernel.bin MyOS.bin
	partcopy MyOS.bin 0 1400 -f0
http://forum.osdev.org/viewtopic.php?f= ... 1&start=31
Post Reply