Page 1 of 1

main.c:(.text+0x1c): undefined reference to `init_paging'

Posted: Tue Feb 01, 2011 5:08 pm
by Jacic
Ive been working through JamesM's kernel dev tutorials, and am now on step 6. The goal at the end of this chapter is to force a page fault to test if the handler works. I am, however, receiving the error specified in the subject of this post. Here it is again:

Code: Select all

main.c:(.text+0x1c): undefined reference to `init_paging'
main.c:

Code: Select all

//main.c - C code kernel entry point

#include "monitor.h"
#include "descriptor_tables.h"
#include "timer.h"
#include "paging.h"

int main(struct multiboot *mboot_ptr)
{
  //init calls go here
  init_descriptor_tables();
  monitor_clear();
  init_paging();
  monitor_write("Hello World!\n");
  uint32 *ptr = (uint32*)0xA0000000;
  uint32 do_page_fault = *ptr;
  //asm volatile ("int $0x3");
  //asm volatile ("int $0x4");
  //asm volatile ("sti");
  //init_timer(50);
  return 0;
}
paging.h (where init_paging() is defined):

Code: Select all

#ifndef PAGING_H
#define PAGING_H

#include "common.h"
#include "isr.h"

typedef struct page
{
  uint32 present: 1;  //page present in memory
  uint32 rw: 1;       //read only if clear, read/write if set
  uint32 user: 1;     //supervisor level only if clear
  uint32 accessed: 1; //has the page been accessed since last refresh
  uint32 dirty: 1;    //has the page been written to since last refresh
  uint32 unused: 7;   //amalgation of unused and reserved bits
  uint32 frame: 20;   //frame address (shifted right 12 bits)
} page_t;

typedef struct page_table
{
  page_t pages[1024];
} page_table_t;

typedef struct page_directory
{
  page_table_t *tables[1024];
  uint32 tablesPhysical[1024];
  uint32 physicalAddr;
} page_directory_t;

//sets up environment and enables paging
void init_paging();

//causes the specified page directory to be loaded into the CR3 register
void switch_page_directory(page_directory_t *new);

//retrieves a pointer to the page required
page_t *get_page(uint32 address, int make, page_directory_t *dir);

//handler for page faults
void page_fault(registers_t regs);

#endif
Could someone please help me understand and fix this error? Thanks in advance.

Re: main.c:(.text+0x1c): undefined reference to `init_paging

Posted: Tue Feb 01, 2011 5:18 pm
by gerryg400
Jacic wrote: paging.h (where init_paging() is defined):

Code: Select all

...

//sets up environment and enables paging
void init_paging();

...
Could someone please help me understand and fix this error? Thanks in advance.
That's just a declaration of init_paging. It must be defined elsewhere. Usually in a .c file that's also included in your build. Do you have that ?

Re: main.c:(.text+0x1c): undefined reference to `init_paging

Posted: Tue Feb 01, 2011 5:30 pm
by Jacic
Yes, its in paging.c:

Code: Select all

void init_paging()
{
  uint32 mem_end_page = 0x1000000;
  nframes = mem_end_page / 0x1000;
  frames = (uint32*)kmalloc(INDEX_FROM_BIT(nframes));
  memset(frames, 0, INDEX_FROM_BIT(nframes));
  
  //make a page directory
  kernel_directory = (page_directory_t*)kmalloc_a(sizeof(page_directory_t));
  memset(kernel_directory, 0, sizeof(page_directory_t));
  current_directory = kernel_directory;
  int i = 0;
  while(i < placement_address)
  {
    alloc_frame(get_page(i, 1, kernel_directory), 0, 0);
    i += 0x1000;
  }
  register_interrupt_handler(14, page_fault);
  switch_page_directory(kernel_directory);
}
It should find it though, because they both include paging.h

Re: main.c:(.text+0x1c): undefined reference to `init_paging

Posted: Tue Feb 01, 2011 5:46 pm
by gerryg400
And you updated your makefile to contain

Code: Select all

SOURCES=boot.o main.o paging.o
etc. ?

And there are no error messages or warnings when paging.c compiles ?

Re: main.c:(.text+0x1c): undefined reference to `init_paging

Posted: Tue Feb 01, 2011 6:00 pm
by Jacic
*facepalm*
Sorry for bothering you with such a stupid question. Adding paging.o to my Makefile is exactly what I didnt do. Thanks for the quick reply though.
At least I know i wont make this mistake again! :D

Re: main.c:(.text+0x1c): undefined reference to `init_paging

Posted: Wed Feb 02, 2011 5:29 am
by Solar
The Makefile tutorial shows a Makefile setup that finds all source files by itself. This also has drawbacks (any 'test.c' gets dragged in), but on the whole I found this to be more convenient.

Re: main.c:(.text+0x1c): undefined reference to `init_paging

Posted: Wed Feb 02, 2011 4:00 pm
by Jacic
Thanks Solar, I think I'll try that.