OK, starting to create an OS using ASM (ofcourse), C and C++. The first thing I want to do is to display the famous text "Hello world!" on to the screen.
I am using DJGPP to compile a simple C file to an object file and NASM to compile the assembler part. When I compile the assembler part and the C part it all goes well.
When I link it goes wrong, it says:
ks.o(.text+0x1): undefined reference to `_k_main'
kernel.o(.eh_frame+0x11):kernel.c: undefined reference to `___gxx_personality_v0
Thus checking the assembler file (ks.o is from this one) but i did have an extern to this one, and in the C file it's named k_main (without the leading _ ). In the kernel.c file I can't find any ___gxx..._v0, so I think I'm doing something wrong with the compiler options.
The way I'm doing it now:
nasmw -f aout kernel_start.asm -o ks.o
gpp -c kernel.c -o kernel.o
ld -T link.ld -o kernel.bin ks.o kernel.o
here it goes wrong.
Please inform me if I'm doing something wrong, and what I'm doing wrong.
The files I use:
kernel_start.asm:
%include "grub.inc" ; needed for the multiboot header
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file
start:
call _k_main
cli ; stop interrupts
hlt ; halt the CPU
EXTERN code, bss, end
ALIGN 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
grub.inc
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
kernel.c:
#define WHITE_TXT 0x07 // white on black text
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
void k_main( void ) // like main in a normal C program
{
k_clear_screen();
k_printf("Hi!\nHow's this for a starter OS?", 0);
}
void k_clear_screen() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*25*2))
{
vidmem=' ';
i++;
vidmem=WHITE_TXT;
i++;
}
}
unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0)
{
if(*message=='\n') // check for a new line
{
line++;
i=(line*80*2);
*message++;
} else {
vidmem=*message;
*message++;
i++;
vidmem=WHITE_TXT;
i++;
}
}
return 1;
}
link.ld
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Hello OS!
Re:Hello OS!
What is gpp? Is it the same as gxx?, which is the C++ compiler. I think you should try2100-OS wrote: undefined reference to `___gxx_personality_v0
gpp -c kernel.c -o kernel.o
Code: Select all
gcc -c kernel.c -o kernel.o
EDIT:- I just compiled your code, and I get the same error when using gpp, but it works fine with gcc.
Re:Hello OS!
That just solved the problem, Indeed I was mistaking gpp with gcc, which is only the C++ compiler, now I understand that second error too.
thanks for clearing this up
thanks for clearing this up