Unexpected output when printing to text video memory

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
ledoux
Posts: 4
Joined: Sun Mar 10, 2019 11:55 pm
Libera.chat IRC: ledoux_k

Unexpected output when printing to text video memory

Post 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?
Attachments
kernel.asm
(318 Bytes) Downloaded 24 times
screen.c
COntain screen function
(1.46 KiB) Downloaded 22 times
bootsect.asm
File for bootsector and load PMODE
(1.94 KiB) Downloaded 20 times
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Unexpected output when printing to text video memory

Post 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
Post Reply