OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Aug 23, 2019 9:11 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Printing text with a C kernel doesn't work properly
PostPosted: Sun Feb 03, 2019 12:04 pm 
Offline

Joined: Sun Feb 03, 2019 9:47 am
Posts: 9
MichaelPetch wrote:
I'd clean it up and do it this way:
Code:
#!/bin/bash

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
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.


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


Top
 Profile  
 
 Post subject: Re: Printing text with a C kernel doesn't work properly
PostPosted: Sun Feb 03, 2019 12:12 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 466
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.


Top
 Profile  
 
 Post subject: Re: Printing text with a C kernel doesn't work properly
PostPosted: Sun Feb 03, 2019 12:24 pm 
Offline

Joined: Sun Feb 03, 2019 9:47 am
Posts: 9
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


Top
 Profile  
 
 Post subject: Re: Printing text with a C kernel doesn't work properly
PostPosted: Sun Feb 03, 2019 12:26 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 466
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
gcc -m32 -c -ffreestanding -fno-PIC video.c -o video.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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group