OSDev.org https://forum.osdev.org/ |
|
Printing text with a C kernel doesn't work properly https://forum.osdev.org/viewtopic.php?f=1&t=33479 |
Page 2 of 2 |
Author: | lucasrdrgs [ Sun Feb 03, 2019 12:04 pm ] |
Post subject: | Re: Printing text with a C kernel doesn't work properly |
MichaelPetch wrote: I'd clean it up and do it this way: Code: #!/bin/bash This should compile each individual file, link them to an executable called kernel.elf and that executable is converted into a binary file call kernel.bin. I also simplify creating a disk image (I chose a nominal floppy disk size of 1.44MiB). Bootloader in first sector and kernel starting in second sector.nasm -f bin boot.asm -o boot.bin gcc -m32 -c -ffreestanding main.c -o main.o gcc -m32 -c -ffreestanding video.c -o video.o # Link files to kernel.elf using GCC rather than LD gcc -m32 -Tlink.ld -fno-PIE -nostartfiles main.o video.o -o kernel.elf objcopy -R .note -R .comment -S -O binary kernel.elf kernel.bin # Make disk image size of 1.44MiB floppy dd if=/dev/zero of=disk.img bs=1024 count=1440 dd if=boot.bin of=disk.img conv=notrunc dd if=kernel.bin of=disk.img seek=1 conv=notrunc It works fine with qemu but the problem with printing is still there. Am I setting up the stack incorrectly? Code: [BITS 16]
[ORG 0x7c00] ;First instruction adress global loader mov ax, 1003h mov bx, 0 int 0x10 mov ax, 0x0003 ; 80x25 16color mode int 0x10 ; video interrupt xor ax, ax ; <---------------------------------------------------------------- ax = 0 mov ss, ax ; <--------------------------------------------------------------- ss = ax = 0 mov sp, 0x7c00 ; <--------------------------------------------------------- stack pointer = 0x7c00 reset_drive: mov ah, 0 int 0x13 or ah, ah jnz reset_drive ; load from disk xor ax, ax mov es, ax mov ch, ah mov dh, ah mov bx, 0x7e00 mov cl, 0x02 mov ah, 0x02 mov al, 0x0A ; 10 (it works with numbers above 5 now) int 0x13 or ah, ah jnz reset_drive more code below but it's irrelevant since this is the only part I changed |
Author: | MichaelPetch [ Sun Feb 03, 2019 12:12 pm ] |
Post subject: | Re: Printing text with a C kernel doesn't work properly |
As I stated in a previous comment the real mode stack code you are asking about looks fine. Can you show us C code with a string that doesn't print properly? Also remember that writing to video memory directly a string of 2000 characters will stop at 2000 and there is no automatic screen scrolling like you'd get with the BIOS. You'd have to code that yourself. |
Author: | lucasrdrgs [ Sun Feb 03, 2019 12:24 pm ] |
Post subject: | Re: Printing text with a C kernel doesn't work properly |
MichaelPetch wrote: As I stated in a previous comment the real mode stack code you are asking about looks fine. Can you show us C code with a string that doesn't print properly? Also remember that writing to video memory directly a string of 2000 characters will stop at 2000 and there is no automatic screen scrolling like you'd get with the BIOS. You'd have to code that yourself. It seems to work now! I didn't change AL back to 0x0A (I set it back to 0x02). Thank you all for the support =D |
Author: | MichaelPetch [ Sun Feb 03, 2019 12:26 pm ] |
Post subject: | Re: Printing text with a C kernel doesn't work properly |
Typing things up quickly I have made an edit to the build process. The lines that compile the C files should have had the -fno-PIC option: Code: gcc -m32 -c -ffreestanding -fno-PIC main.c -o main.o .Of course the issue with PIC code (Position Independent code) can be fixed by using a GCC Cross Compiler where PIC is off by default.
gcc -m32 -c -ffreestanding -fno-PIC video.c -o video.o |
Page 2 of 2 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |