The Place to Start for Operating System Developers
http://forum.osdev.org/
Code: Select all
asm(".long 0xe85250d6 "); // Magic Number.
asm(".long 0x00000000 "); // Architecture = 32-bit Intel PMode.
asm(".long 0x00000010 "); // Header Length
asm(".long -(0x10+0xe85250d6) "); // ChecksumCode: Select all
...
/* The magic field should contain this. */
#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
...
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
/* Feature flags. */
multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
...
};
I don't know how to get it from Grub. I feel the best way is to define a variable in your linker script that marks the end of the loadable image. I think this will probably work.mostafazizo wrote:thanks, i got the file and included it in my kernel.
right now, is there any way to know the size of the kernel from GRUB or the boot loader?? i need the kernel to know the size of itself every time it boots in order to mark its memory space as used in an implemented memory map. this will help allocating free memory space in an accurate way. do u have any idea, plz???
Regards,
Code: Select all
SECTIONS
{
.text 0x100000 :
ALIGN (0x1000)
{ *(.text) }
.data :
ALIGN (0x1000)
{ *(.data) }
.bss :
ALIGN (0x1000)
{ *(.bss) }
.unused_section :
ALIGN (0x1000)
{ kernel_end = . ; }
}
Code: Select all
extern uint32_t kernel_end;
/* Get the physical address of the end of the image */
pfree = (uint32_t)&kernel_end;
Code: Select all
ENTRY (init)
SECTIONS {
. = 0x100000;
ld_kernel_start = . ;
.text : { *(.text ) }
.bss : { *(.bss ) }
.data : { *(.data ) }
.rodata : { *(.rodata) }
ld_kernel_end = . ;
}
You can get the bios drive number and the partition numbers from the multiboot_info struct.mostafazizo wrote:I wonder if i could know the boot device path (PCI bus/dev/func and so on) from GRUB2. do u have any idea? any help is appreciated...
sorry for the large quantity of questions, but this is only because i stayed months developing my kernel neglecting this part of it, cause it is full of obstacles.
Regards,
I know well :D but the BIOS Drive Number is not enough for a kernel that supports ATA/SATA HDDs, CD-ROMs, USB Mass Storage Devices and USB CD-ROMs to know which of those devices is the boot device...gerryg400 wrote:You can get the bios drive number and the partition numbers from the multiboot_info struct.mostafazizo wrote:I wonder if i could know the boot device path (PCI bus/dev/func and so on) from GRUB2. do u have any idea? any help is appreciated...
sorry for the large quantity of questions, but this is only because i stayed months developing my kernel neglecting this part of it, cause it is full of obstacles.
Regards,
I don't think there is one easy way. This thread may help.mostafazizo wrote:I know well :D but the BIOS Drive Number is not enough for a kernel that supports ATA/SATA HDDs, CD-ROMs, USB Mass Storage Devices and USB CD-ROMs to know which of those devices is the boot device...
The problem with that document is that it doesn't match the current version of Grub (1.98). The version of multiboot2.h in the Grub distro and the version in the multiboot documentation are quite different. Oddly the magic numbers are the same. I'm not sure what the Grub guys are doing.Love4Boobies wrote:Multiboot 2. You're welcome! :)
You don't actually want to refer to a value in the first 32 bit of the kernel, so I prefer to declare it as what it really is:gerryg400 wrote:extern uint32_t kernel_end;
Code: Select all
extern const void kernel_end;