Page 1 of 1

Can't load kernel with bochs

Posted: Fri Jun 03, 2005 10:47 am
by ich_will
Hi,

I would like to load my kernel with grub (Version 0.94) and I would be able to compile my kernel as ELF and as flat binary. ELF works fine but flat binary not. If I try to load my kernel with bochs it says that's unsupported file type. I check my kernel with mbchk, the output is:
linux:~/os/kernelv0.2 # mbchk ./kernel
./kernel: The Multiboot header is found at the offset 8.
./kernel: Page alignment is turned off.
./kernel: Memory information is turned on.
./kernel: Address fields is turned on.
./kernel: header_addr is less than load_addr (0x100008 > 0x100047).
my linkerscript looks like this:

Code: Select all

/* Link.ld */

ENTRY(start)
SECTIONS
{
   .text 0x100000 :
   {
      *(.text)
      code = .; _code = .; __code = .;
      . = ALIGN(4096);
   }

   .data :
   {
      *(.data)
      data = .; _data = .; __data = .;
      . = ALIGN(4096);
   }

   .bss :
   {
      *(.bss)
      bss = .; _bss = .; __bss = .;
      . = ALIGN(4096);
   }

   end = .; _end = .; __end = .;
}
my _start.asm like this:

Code: Select all

[BITS 32]
[GLOBAL start]
[EXTERN _code]
[EXTERN _bss]
[EXTERN _end]
[EXTERN _main]

start:
jmp _start

MULTIBOOT_MAGIC         equ 0x1BADB002
MULTIBOOT_MEMORY_INFO   equ 1 << 1
%ifndef _ELF
MULTIBOOT_AOUT_KLUDGE   equ 1 << 16
MULTIBOOT_FLAGS         equ MULTIBOOT_MEMORY_INFO|MULTIBOOT_AOUT_KLUDGE
%else
MULTIBOOT_FLAGS         equ MULTIBOOT_MEMORY_INFO
%endif
MULTIBOOT_CHECKSUM      equ -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS)

align 4
multiboot_header:
        magic           dd MULTIBOOT_MAGIC
        flags           dd MULTIBOOT_FLAGS
        checksum        dd MULTIBOOT_CHECKSUM

%ifndef _ELF
        header_addr     dd multiboot_header
        load_addr       dd _code
        load_end_addr   dd _bss
        bss_end_addr    dd _end
        entry_addr      dd start
%endif

_start:
        call _main                              ; run kernel c code
HALT:
%ifndef _BOCHS   
   cli
   hlt
%endif
   jmp HALT
the kernel is linked with the command:

ld --omagic --oformat binary -T link.ld *.o -o /root/os/kernelv0.2/kernel

Re:Can't load kernel with bochs

Posted: Fri Jun 03, 2005 4:59 pm
by GLneo
i've never had grub be able to load a flat bianary, its grub not bochs, stick with elf ;)

Re:Can't load kernel with bochs

Posted: Fri Jun 03, 2005 5:34 pm
by pini
ich_will wrote:

Code: Select all

start:
jmp _start

; ...

%ifndef _ELF
        header_addr     dd multiboot_header
        load_addr       dd _code
        load_end_addr   dd _bss
        bss_end_addr    dd _end
        entry_addr      dd start
%endif

_start:
;...
Try setting the 'entry_addr' to _start and remove the "start: jmp _start" from your code.

I'm not sure grub handles correctly a load address that is located before the header (which is your case).

Re:Can't load kernel with bochs

Posted: Sat Jun 04, 2005 4:20 am
by ich_will
Thank you for reply.

@GLneo: If I remember correct, I had but I don't know how ;-)

@pini: I don't know, but it the idea you posted doesn't work, too. The same error is print out.

I decide to link the kernel only to ELF for now, it works, won't waste time with things I don't need for know.

Re:Can't load kernel with bochs

Posted: Sat Jun 04, 2005 11:37 am
by ich_will
Now I've another problem, if I try to load the elf kernel:

Code: Select all

    GNU GRUB  version 0.96  (639K lower / 31744K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename. ]

grub> kernel /boot/kernel
   [Multiboot-elf, <0xdc:0x1af:0x0>

Error 28: Selected item cannot fit into memory

grub>
what's going on here??? I've only add more functions to my code and reload the gdt in the _start.asm. (The kernel is now 6,8KB big). Why can't grub load it? Bochs megs option is set to 32

my link command looks like:

Code: Select all

ld --omagic  -nostartfiles -nodefaultlibs -nostdlib -T link.ld *.o -o /root/os/kernelv0.3/kernel
my _start.asm see attachment

Re:Can't load kernel with bochs

Posted: Sun Jun 12, 2005 5:58 am
by ich_will
No ideas?? Simple question: Why doesn't anyone reply to this thread?
Is it 'cause my worse english? Is it because noone knows an answer for my problem? Or is it 'cause I should know a solution for this problem?

Re:Can't load kernel with bochs

Posted: Sun Jun 12, 2005 6:40 am
by distantvoices
It occurs to you that we others *might* have a life to deal with, doesn't it?

It's not as if our sole reason of existence is to answer your question. *gg* But on the other hand, what's the question? And don't you dare to take 7,5 million years just to answer "42" then. *gg*

But go on, tell, what you gonna pay for exquisite, 12 hrs p day help line? Say 1000 euros per day?

Your english is ok, I for one can understand it. :-)

about your problem ... What do you set to those end addresses?
Else I canna tell, haven't encountered such problems.

Re:Can't load kernel with bochs

Posted: Sun Jun 12, 2005 6:42 am
by AR
If no one answers then either A) They can't understand you (but will likely say so) or B) No-one knows what exactly is wrong and/or can't be bothered asking for additional details.

I frankly have no idea what you've done, I've never had any problems like this except when Megs was too low.

Re:Can't load kernel with bochs

Posted: Sun Jun 12, 2005 8:36 am
by ich_will
@beyond infinity: do you mean _bss and _end with end addresses?
these are symboles defined in my linkerscript:

Code: Select all

/* Link.ld */

OUTPUT_FORMAT("elf32-i386")

ENTRY(start)
SECTIONS
{
   .text 0x100000 :
   {
      *(.text)
      code = .; _code = .; __code = .;
      . = ALIGN(4096);
   }

   .data :
   {
      *(.data)
      data = .; _data = .; __data = .;
      . = ALIGN(4096);
   }

   .bss :
   {
      *(.bss)
      bss = .; _bss = .; __bss = .;
      . = ALIGN(4096);
   }

   end = .; _end = .; __end = .;
}

Re:Can't load kernel with bochs

Posted: Sun Jun 12, 2005 1:45 pm
by mystran
I think your load address in the aout-kludge-header is wrong. Your code, _code, and __code labels are AFTER the text section, while you probably want load_address to be 0x100000? Now it's 0x100000 + size of text-segment.

Same thing with _bss. The label is after the segment, so you end up loading the _bss section (which probably makes no sense).

So, let's see:

Code: Select all

/* Link.ld */

OUTPUT_FORMAT("elf32-i386")

ENTRY(start)
SECTIONS
{
   .text 0x100000 :
   {
      code = .; _code = .; __code = .;
      *(.text)
      . = ALIGN(4096);
   }

   .data :
   {
      data = .; _data = .; __data = .;
      *(.data)
      . = ALIGN(4096);
   }

   .bss :
   {
      bss = .; _bss = .; __bss = .;
      *(.bss)
      . = ALIGN(4096);
   }

   end = .; _end = .; __end = .;
}
That's probably what you wanted?

Re:Can't load kernel with bochs

Posted: Mon Jun 13, 2005 8:34 am
by ich_will
Thank you, but it works in my old kernel project. And thats not the problem with the elf format.

Re:Can't load kernel with bochs

Posted: Mon Jun 13, 2005 9:11 am
by AR
If you are saying that the linkscript worked in the ELF but not the a.out/binary that is because you didn't use those tags in the linkscript before (ELFs have proper description headers that GRUB reads to know where to put everything, the kludge and therefore those tags are only used when you aren't using an ELF).

Re:Can't load kernel with bochs

Posted: Mon Jun 13, 2005 11:25 am
by ich_will
I know, currently i'm not using these tags though GRUB can't load my kernel, which is linked to ELF.