Page 1 of 1

JamesM Tutorial Code Compilation Error

Posted: Thu Jul 09, 2009 11:55 pm
by JoeTheProgrammer
Hi,

I am compiling the sample kernel from thes JamesM Tutorial Code. I keep getting the error: kheap.c:11: error: initializer element is not constant

in the line of code below:

Code: Select all

u32int placement_address = (u32int)&end;
Here is the first part of the kheap.c file:

Code: Select all

// kheap.c -- Kernel heap functions, also provides
//            a placement malloc() for use before the heap is 
//            initialised.
//            Written for JamesM's kernel development tutorials.

#include "kheap.h"
#include "paging.h"

// end is defined in the linker script.
extern u32int end;
u32int placement_address = (u32int)&end;
extern page_directory_t *kernel_directory;
heap_t *kheap=0;

u32int kmalloc_int(u32int sz, int align, u32int *phys)
{
    if (kheap != 0)
    {
        void *addr = alloc(sz, (u8int)align, kheap);
        if (phys != 0)
        {
            page_t *page = get_page((u32int)addr, 0, kernel_directory);
            *phys = page->frame*0x1000 + ((u32int)addr&0xFFF);
        }
        return (u32int)addr;
    }
    else
    {
        if (align == 1 && (placement_address & 0xFFFFF000) )
        {
            // Align the placement address;
            placement_address &= 0xFFFFF000;
            placement_address += 0x1000;
        }
        if (phys)
        {
            *phys = placement_address;
        }
        u32int tmp = placement_address;
        placement_address += sz;
        return tmp;
    }
}
I am compiling using gcc, ld, make, and nasm on Ubuntu Linux 9.04. I am not for sure what to do to correct the issue, so any help is appreciated.

Thanks,
Joseph

Re: JamesM Tutorial Code Compilation Error

Posted: Fri Jul 10, 2009 12:38 am
by Solar
JoeTheProgrammer wrote: in the line of code below:

Code: Select all

u32int placement_address = (u32int)&end;
Here is the first part of the kheap.c file:

Code: Select all

u32int placement_address = (u32int)end;
Which one is it, then? With '&' or without?

Re: JamesM Tutorial Code Compilation Error

Posted: Fri Jul 10, 2009 12:41 am
by JoeTheProgrammer
Solar wrote:
JoeTheProgrammer wrote: in the line of code below:

Code: Select all

u32int placement_address = (u32int)&end;
Here is the first part of the kheap.c file:

Code: Select all

u32int placement_address = (u32int)end;
Which one is it, then? With '&' or without?
With '&', my mistake, sorry.

Thanks,
Joseph

Re: JamesM Tutorial Code Compilation Error

Posted: Fri Jul 10, 2009 3:39 am
by JamesM
Are you sure? Because if you had accidentally omitted the '&', the compiler would generate an error very similar to the one you're complaining about...

Re: JamesM Tutorial Code Compilation Error

Posted: Fri Jul 10, 2009 10:34 am
by JoeTheProgrammer
JamesM wrote:Are you sure? Because if you had accidentally omitted the '&', the compiler would generate an error very similar to the one you're complaining about...
No it has the '&' and the compiler is giving me the error, I just double checked it.

Edited To Add: Never mind about my post, I figured out what was wrong and corrected it.

Thanks,
Joseph