Multiple Source File Troubles

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
OzDev

Multiple Source File Troubles

Post by OzDev »

I need some help... My OS does not seem to like accessing the functions from a different module. I have tried compiling using both JLOC and LD but to no success  Below is my source code, and the LD/JLOC linking scripts. I have been compiling using 'gcc -ffreestanding -c *.c'. I know both functions work because i moved the clear_screen code into the main block and the OS still loaded, but
separate them again and the CPU resets.

The computer I am testing this on is a Celeron 266MHz.

If anyone is wondering, I got the JLOC script from Johns JLOC/BOOTF/ETC site (the bootf02.zip download)

Any Ideas?

Thanks, Scott

--------------------------------------------------
kernel.c:

Code:
#include "video.h"

char message[]="Welcome to ExOS!";

void init()
{

char *source = message;
char *destination = (char *)0xB8000;

clear_screen();

while (*source) {
*destination++ = *source++;
*destination++ = 0xCE;
}

};
--------------------------------------------------
video.h:

Code:
// Header file for text
// does display functions
// text.h

#ifndef video_h
#define video_h

void clear_screen();

#endif


--------------------------------------------------

video.c:

Code:
#include "video.h"

void clear_screen() // clear the entire text screen
{
    char *vidmem = (char *)0xB8000;
    const long size = 80*25;
    long loop;
    for (loop=0; loop<size; loop++)
    {
        *vidmem = ' ';
        vidmem++;
        *vidmem = 0x07;
        vidmem++;
    }
}


--------------------------------------------------

LD Linking Script:

Code:
OUTPUT_FORMAT("binary")
ENTRY(_init)
SECTIONS
{
  .text  0xFF800000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  {                
    *(.bss)
  }
}


--------------------------------------------------

JLOC Linking Script:
Code:

ALL:
   kernel.o
   video.o

START: 0,0FF800000
   ,,code,,kernel.o
CODE: 0
   ,,code
DATA: 0,#10
   ,,data
BSS: 0,#10
   ,,bss
Dangamoose

RE:Multiple Source File Troubles

Post by Dangamoose »

I dont know C, so im probably wrong but...

To make functions available, dont you have to write in the header for each function something to make the function available, and then in the caller's header file, something to allow you to call the available function.
I dont know what it is for C.

In asm it would be
[global clear_screen]
[extern clear_screen]

This makes if available to the appropriate functions, when placed inside the appropriate headers.

Dangamoose.
ltos

RE:Multiple Source File Troubles

Post by ltos »

I think you forgot to add an 'extern' decl for your 'clear_screen' fn to your main source file.  And, in the loop, the statment '*destination++=*source++' may not behave correctly, because it is dependent on the (implementation-defined) order of side-effect evaluation for the increment operators.
Post Reply