Kernel loading from cd

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.
Payn3
Posts: 15
Joined: Sun Jan 17, 2010 4:14 am

Re: Kernel loading from cd

Post by Payn3 »

So, can anyone explain to me what i have to do to load my kernel?
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel loading from cd

Post 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)
Last edited by egos on Sun Aug 15, 2010 3:52 am, edited 1 time in total.
If you have seen bad English in my words, tell me what's wrong, please.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Kernel loading from cd

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
Payn3
Posts: 15
Joined: Sun Jan 17, 2010 4:14 am

Re: Kernel loading from cd

Post 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.
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Kernel loading from cd

Post 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, ...).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Kernel loading from cd

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

Re: Kernel loading from cd

Post 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.
Payn3
Posts: 15
Joined: Sun Jan 17, 2010 4:14 am

Re: Kernel loading from cd

Post by Payn3 »

kernel.bin starts with MZ, i think is a PE.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Kernel loading from cd

Post 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.
If a trainstation is where trains stop, what is a workstation ?
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel loading from cd

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel loading from cd

Post 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.
Last edited by egos on Sun Aug 15, 2010 4:50 am, edited 1 time in total.
If you have seen bad English in my words, tell me what's wrong, please.
Payn3
Posts: 15
Joined: Sun Jan 17, 2010 4:14 am

Re: Kernel loading from cd

Post 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'.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel loading from cd

Post by egos »

Remove from script PE directives.
If you have seen bad English in my words, tell me what's wrong, please.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Kernel loading from cd

Post 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.
Last edited by gerryg400 on Sun Aug 15, 2010 5:06 am, edited 1 time in total.
If a trainstation is where trains stop, what is a workstation ?
Payn3
Posts: 15
Joined: Sun Jan 17, 2010 4:14 am

Re: Kernel loading from cd

Post 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 = .;
    }
}
Post Reply