Page 1 of 1

Multiple SSource File Troubles

Posted: Wed Jan 07, 2004 11:36 pm
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.
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

#if defined( video_h )
//already include
#else
#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


I will clean up the code once the 'inter-modular' functions start working

Re:Multiple SSource File Troubles

Posted: Thu Jan 08, 2004 2:04 am
by Ytinasni
Hi

The easiest way to fix your problem (aka: the way i do it) is to create a new source file, containing:

void init();

void start()
{
init();
}


when you link your kernel, have this file before the other .o files.

EDIT: and change the 'entry' in your LD script to _start

Re:Multiple SSource File Troubles

Posted: Thu Jan 08, 2004 8:31 am
by Slasher
you need to use more compile options

gcc -c -Wall -fwritable-strings -nostdlib -fno-builtin -ffreestanding *.c

Re:Multiple SSource File Troubles

Posted: Thu Jan 08, 2004 8:52 am
by Tim
Assuming the problem really is that the linker is putting strings where the code should be, Ytinasni's solution is cleaner than using -fwritable-strings. This works, but it's treating the symptom -- it moves strings into the data section -- rather than the cause. Later on you'll want strings put into read-only memory, so that modifying will cause an exception, allowing bugs to be found sooner.

I believe gcc puts strings into the .rodata section by default, so adding *(.rodata) to the linker script after *(.text) should also fix this.

Re:Multiple SSource File Troubles

Posted: Thu Jan 08, 2004 11:48 am
by df
how are you booting up? grub? are your ss/gs/fs/es sane values? got enough stack?

there could be any number of questions/reasons here.....