Page 1 of 1

Unexpected output when printing to text video memory

Posted: Sat Apr 06, 2019 9:20 pm
by ledoux
Hello everyone . I develop a kernel in C and I created something that displays a message in the video memory.
But I had two cases: The first is that, when I do not make a link with a C file and the assembly kernel, the characters are displayed normally.
The second case, normally when I make a link with a C file, nothing happens.

In a way, I work on KAli linux. I have a C file, and two asm files. The C file is called screen.c which contains the character display functions. ASM files: a boot.asm for bootsectorwhich load PMODE and kernel.asm file (to use C code functions).

Here are the command lines I used to test my code:

gcc -m32 -c screen.c -o screen.o
nasm -f elf32 -o kernel.o kernel.asm
ld -m elf_i386 -Ttext 1000 kernel.o screen.o -o kernel
nasm -f bin -o boot boot.asm
cat boot kernel.o /dev/zero | dd of=floppyA bs=512 count=2880

Where is the problem ?
Can I give you my codes for more readability?

Re: Unexpected output when printing to text video memory

Posted: Sun Apr 07, 2019 8:55 pm
by MichaelPetch
It is how you are building. 1000 should be 0x1000 . You want to DD kernel, not kernel.o, you will need to have the linker output kernel as a binary file and not an ELF executable. Since you aren't using a cross compiler you'll likely need something like -fno-PIC . Something like this may work:

Code: Select all

gcc -m32 -c screen.c -o screen.o -ffreestanding -fno-PIC
nasm -f elf32 -o kernel.o kernel.asm
ld -m elf_i386 --oformat=binary -Ttext 0x1000 kernel.o screen.o -o kernel
nasm -f bin -o boot boot.asm
cat boot kernel /dev/zero | dd of=floppyA bs=512 count=2880