So I'm working on a 16-bit operating system, and I have loaded the second stage that will act as my kernel. The only issue is that the kernel doesn't print any strings, just blank characters.
The kernel code should print out "███ TEST", but it doesn't just moves the cursor printing blank chars.
I have attached source code of the bootloader, the kernel and the LD script that is used.
BOOTLOADER:
.code16
.global _entry
.section .text.main
.extern _print
.extern _strcmp
#
# Bootld. entry point
# just skips over BBFS
# disk parameters
#
_entry:
jmp _start
nop
#
# BBFS Disk parameters
#
_bbfs_disk_label: .ascii "TEST-TEST " # 10 chars. for the disk label
_bbfs_isbootable: .byte 1 # Is the disk bootable? 1 - yes
# 0 - no
_bbfs_is_sysdisk: .byte 1 # Is this a system disk? 1 - yes
# 0 - no
_bbfs_file_systm: .ascii "BBFS V03" # 8 chars. for the FS id
#
# Main bootld. function
#
_start:
# Save the boot device
mov %dl, _boot_dev
#
# Clear the screen
#
mov $0x03, %ax
int $0x10
# Set pallete reg.
mov $0x10, %ah # Set pallete registers
mov $0x03, %al # toggle intensity/blinking
mov $0x00, %bl # 0 - enable intensity
# 1 - enable blinking
int $0x10
mov $0x11, %ah # Set font
mov $0x11, %al # ROM BIOS 8x14 monochrome character set
int $0x10
#
# Stack setup
#
xor %ax, %ax
cli
mov $0x9000,%ax
mov %ax, %ss
mov $0xF800,%sp
sti
mov $0x13, %ah # write string
mov $0x01, %al # write mode
mov $0x00, %bh # video page number
mov $0x0f, %bl # attribute mode
mov $0x0A, %cx # lenght of str
mov $0x00, %dh # row
mov $0x00, %dl # column
mov $_boot_msg, %bp # pointer to str
int $0x10
#
# Load the kernel file
# --------------------
#
# KERNEL 5.5.0.SYS must be
# located after the bootld if
# not bootloader will return
# an error
#
#
# Check if the file located
# @ the second sector is
# called KERNEL 5.5.0
#
# if not return an error
#
_search:
#
# Read the 2nd sector
#
xor %ax, %ax
mov %ax, %es
mov $0x02, %ah
mov $0x01, %al
mov $0xAA00,%bx
mov $0x00, %ch
mov $0x02, %cl
mov $0x00, %dh
movb (_boot_dev),%dl
int $0x13
xor %ax, %ax
xor %cx, %cx
mov $0xAA03,%si
mov $_file_name,%di
mov $13, %cx
_search_loop:
movsb
loop _search_loop
mov $_file_name, %si
mov $_kernel_file, %di
call _strcmp
jc _kernel_found
mov $_no_krnl_file, %si
call _print
jmp _end
_kernel_found:
mov $_found_kernel, %si
call _print
_disk_read:
xor %ax, %ax
xor %bx, %bx
xor %cx, %cx
xor %dx, %dx
mov $0x02, %ah
mov $0x0C, %al
mov $0x7e00,%bx
mov $0x00, %ch
mov $0x02, %cl
mov $0x00, %dh
movb (_boot_dev),%dl
int $0x10
jc _disk_error
mov $_kernel_read,%si
call _print
jmp 0x7e00
_disk_error:
mov $_read_fail,%si
call _print
_end:
cli
hlt
.section .rodata
_boot_msg: .asciz "\xDB\xDB\xDB TEST\r\n"
_found_kernel: .asciz "BBFS: Kernel file found\r\nBBFS: Loading the kernel\r\n"
_no_krnl_file: .asciz "BBFS: Kernel file not found, booting halted\r\n"
_kernel_read: .asciz "BBFS: Kernel loaded, passing control\r\n"
_read_fail: .asciz "BBFS: Disk read error, booting halted\r\n"
_kernel_file: .asciz "KERNEL 5.5.0"
.section .data16
_num_attempts: .byte 0
_boot_dev: .byte 0
_file_name: .fill 12,1,0
The kernel:
.code16
.global _kentry
.section .text.kernel
_kentry:
jmp _kmain
nop
#
# BBFS File Parameters
# _kentry jumps over this
#
#
_bbfs_file_name: .asciz "KERNEL 5.5.0"
_bbfs_file_ext: .ascii "SYS"
_bbfs_is_file_exec: .byte 0
_bbfs_is_system_file: .byte 1
_bbfs_day_of_month: .ascii "23"
_bbfs_month_of_year: .ascii "12"
_bbfs_year_of_creat: .ascii "2023"
_kmain:
xor %ax, %ax
mov %ax, %es
mov %ax, %ds
mov $_kentry,%sp
cld
mov $0x0e, %ah
mov $'a', %al
int $0x10
mov $_msg_0,%si
call _printk
cli
hlt
.section .rodata.kernel
_msg_0: .asciz "\xDB\xDB\xDB TEST\r\n"
Linker script:
OUTPUT_FORMAT(binary);
ENTRY(_kentry);
SECTIONS
{
. = 0x7e00;
.text : SUBALIGN(0)
{
*(.text.kernel);
*(.text.libk);
*(.text)
}
.rodata : SUBALIGN(0)
{
*(.rodata.kernel);
*(.rodata)
}
.data : SUBALIGN(0)
{
*(.data);
}
/DISCARD/ : {
*(.comment);
*(.note*)
}
}
Print function that I'm using:
.code16
.global _printk
.section .text.libk
_printk:
lodsb
or %al, %al
jz .pk_done
mov $0x0e, %ah
int $0x10
jmp _printk
.pk_done:
ret
I have tried everything, changing the LD, setting up the stack in the kernel file, changing how the bootloader loads the kernel, switching from FAT12 to my own file system (BBFS) thinking that it may have something to do with FAT and nothing has worked! I have searched online but I just haven't been able to find any answers.
The kernel should print out "███ TEST" just like the bootloader, but it doesn't.