Calculate size of the kernel based on symbols defined in the linker script
Neat trick!
This commit is contained in:
parent
4daee62439
commit
ddb4c30c62
2 changed files with 12 additions and 0 deletions
|
@ -22,6 +22,9 @@
|
|||
#error "This file should be compiled with an ix86-elf compiler!"
|
||||
#endif
|
||||
|
||||
extern u32 kernelStart;
|
||||
extern u32 kernelEnd;
|
||||
|
||||
|
||||
/** The beginning of the world... */
|
||||
extern "C"
|
||||
|
@ -37,6 +40,12 @@ kmain(multiboot::Information *information,
|
|||
|
||||
auto& console = kernel.console();
|
||||
|
||||
auto start = u32(&kernelStart);
|
||||
auto end = u32(&kernelEnd);
|
||||
console.printFormat("Kernel start: 0x%08lX\n", start);
|
||||
console.printFormat("Kernel end: 0x%08lX\n", end);
|
||||
console.printFormat("Kernel size: %ld bytes\n", end - start);
|
||||
|
||||
console.printFormat("Command line: \"%s\"\n", info->commandLine());
|
||||
|
||||
console.printFormat("Memory map:\n");
|
||||
|
|
|
@ -7,6 +7,8 @@ SECTIONS
|
|||
/* Begin putting sections at 1 MiB, a conventional place for kernels to be loaded at by the bootloader. */
|
||||
. = 1M;
|
||||
|
||||
kernelStart = .;
|
||||
|
||||
/* First put the multiboot header, as it is required to be put very early in the image or the bootloader won't recognize the file format. Next we'll put the .text section. */
|
||||
.text BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
|
@ -39,4 +41,5 @@ SECTIONS
|
|||
}
|
||||
|
||||
/* The compiler may produce other sections, by default it will put them in a segment with the same name. Simply add stuff here as needed. */
|
||||
kernelEnd = ALIGN(4K);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue