im booting to my bootsector and from there jumping with protected mode to the kernel.
my problem starts then im trying to build my kernel from more then one file (.c), i don't see any errors in the compiling and linking process, but then i run it in bochs, it just ignores the functions in the other files (except main-basic.c).
this is the main-basic.c (bootsector jumps to this):
Code: Select all
#include "video-basic.h"
void main()
{
clrscreen();
out(0x3D5, (unsigned char)(0));
out(0x3D4, 14);
out(0x3D5, (unsigned char)(0 >> 8));
print();
for(;;);
}
Code: Select all
#include "video-basic.h"
unsigned char in(unsigned short _port)
{
// "=a" (result) means: put AL register in variable result when finished
// "d" (_port) means: load EDX with _port
unsigned char result;
__asm__ ("in %%dx, %%al" : "=a" (result) : "d" (_port));
return result;
}
void out(unsigned short _port, unsigned char _data)
{
// "a" (_data) means: load EAX with _data
// "d" (_port) means: load EDX with _port
__asm__ ("out %%al, %%dx" : :"a" (_data), "d" (_port));
}
void clrscreen()
{
unsigned char *vidmem = (unsigned char *)0xB8000;
const long size = 80*25;
long loop;
// Clear visible video memory
for (loop=0; loop<size; loop++) {
*vidmem++ = 0;
*vidmem++ = 0xF;
}
}
void print()
{
unsigned long i;
unsigned char *vidmem = (unsigned char *)0xB8000;
// Continue until we reach null character
i = 0;
while (i < 5) {
*vidmem = 'X';
i++;
vidmem += 2;
}
out(0x3D4, 14);
out(0x3D5, (unsigned char)(0));
out(0x3D4, 15);
out(0x3D5, (unsigned char)(i));
}
Code: Select all
unsigned char in(unsigned short _port);
void out(unsigned short _port, unsigned char _data);
void clrscreen();
void print();
and the compiling code:
Code: Select all
nasm bootsect.asm -f bin -o build\bootsect.bin
gcc -ffreestanding -c main-basic.c -o build\main.o
gcc -c video-basic.c -o build\video.o
cd build
ld -e _main -Ttext 0x1000 -o kernel.o main.o video.o
ld -i -e _main -Ttext 0x1000 -o kernel.o main.o video.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
cd ..
makeboot build\a.img build\bootsect.bin build\kernel.bin