JamesM Tutorial Code Compilation Error

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.
Post Reply
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

JamesM Tutorial Code Compilation Error

Post 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
Last edited by JoeTheProgrammer on Fri Jul 10, 2009 12:43 am, edited 1 time in total.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: JamesM Tutorial Code Compilation Error

Post 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?
Every good solution is obvious once you've found it.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Re: JamesM Tutorial Code Compilation Error

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: JamesM Tutorial Code Compilation Error

Post 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...
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Re: JamesM Tutorial Code Compilation Error

Post 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
Post Reply