Page 2 of 3

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 3:14 am
by Payn3
So, can anyone explain to me what i have to do to load my kernel?

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 3:48 am
by egos
Owen wrote:on a CD you have a little extra space for the initial bootsrap, but you can't reliably use more than 2048 bytes.

Read: Yet again BIOSes are buggy sacks of crap
I saw this but though reliability is high. Although I use 2K boot block for CDs 8)

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 3:49 am
by gerryg400
So, can anyone explain to me what i have to do to load my kernel?
I'm not sure what you want to know. There is a wiki with lots of information and if you have a specific question, I'm sure someone can/will help. If you just want an instant solution to loading your kernel you can use Grub.

What about starting by giving us some useful information. Did you get your kernel to compile yet ? Also, I'll ask once again, How are you building the kernel ? What tools, command line etc ?

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 3:56 am
by Payn3
I compile the kernel using mingw.

Code: Select all

gcc -o kernel.o -c kernel.cpp -nostdlib -nostartfiles -nodefaultlibs

Code: Select all

ld -T linker.ld -o kernel.bin kernel.o
What i have to do to load the kernel from my bootloader?

I know that there are a lot of tutorials, but most of them use GRUB as bootloader and i don't want that.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 3:59 am
by Creature
If you are using C++, kernel_main must use C linkage (well must is not really correct, but it makes things a lot easier) if you are planning to call it from Assembly (not sure if LD would complain about that though when you're only using one C++ source file).

If that doesn't fix it, "Cannot find entry point" issue is usually fixed by placing [SECTION .text] at the top of the multiboot header, but seeing as your kernel is only one C++ source file, that's going to be a bit harder (maybe GCC's __attribute__ may work).

Other common mistakes are forgetting to add some arguments to the command line. I see your source file is C++, if you're completely new, it may be better to get C working first and then build upon that. C++ brings a couple of other things that you need to consider (e.g. calling constructors/destructors, exception handling, ...).

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:01 am
by gerryg400
What executable format is your kernel.bin ? Is it actually a flat binary ? Or a format like ELF or PE exe that needs to be parsed ?

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:06 am
by nikito
You have enough space in the 2k bootspace on an CD. Use the ATAPI driver shown in the wiki and this certainly will work for you.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:10 am
by Payn3
kernel.bin starts with MZ, i think is a PE.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:14 am
by gerryg400
Okay, so that's a problem. If you just want to load the file and jmp into it, it will need to be a flat binary. I've not used mingw but I imagine there is a linker option for that.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:21 am
by egos
Payn3 wrote:So, can anyone explain to me what i have to do to load my kernel?
I prefer to use own boot loader with no emulation but it is not most easy way. Maybe grub will better for you.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:43 am
by egos
Payn3 wrote:kernel.bin starts with MZ, i think is a PE.
Well, but we may think about this. You must know. It could be PE, original MZ or actually NE or LE.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:48 am
by Payn3
If I put OUTPUT_FORMAT("binary") in the linker.ld i get
ld: cannot perform PE operations on non PE output file 'kernel.bin'.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:53 am
by egos
Remove from script PE directives.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 4:57 am
by gerryg400
Remove the ENTRY directive. You won't need it. Your entry address will be at a known offset in the binary file that you choose.

Re: Kernel loading from cd

Posted: Sun Aug 15, 2010 5:05 am
by Payn3
I removed the entry directive, but the output file still starts with the MZ. And if i put the again the OUTPUT_FORMAT directive, but without ENTRY i get the same error.

ld: cannot perform PE operations on non PE output file 'kernel.bin'.

Code: Select all

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

Code: Select all

OUTPUT_FORMAT("binary")
SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}