entry.s:
Code: Select all
.global start
.extern kernel_main
.set noreorder
.set STACKSIZE, 0x1000
.section .text
start:
la $sp, stack
addiu $sp, STACKSIZE - 32
jal kernel_main
nop
b .
nop
.section .bss
stack:
.space STACKSIZE
Code: Select all
#include <stdint.h>
#include <stddef.h>
void kernel_main()
{
uint16_t* buffer = (uint16_t*) 0xB8000;
for (size_t i = 0; i < 80*25; i++)
buffer[i] = ((uint16_t) '&') | ((uint8_t) 7) << 8;
}
Code: Select all
OUTPUT_FORMAT(elf32-littlemips)
OUTPUT_ARCH(mips:isa32)
ENTRY(start)
SECTIONS
{
.text (0xBFC0) :
{
*(.text)
*(.text.*)
*(.stub)
*(.gnu.linkonce.t.*)
}
.rodata ALIGN(4K) :
{
*(.rodata*)
*(.gnu.linkonce.r.*)
}
.data ALIGN(4K) :
{
*(.data*)
*(.gnu.linkonce.d.*)
}
.bss ALIGN(4K) :
{
*(.common)
*(.bss*)
*(.gnu.linkonce.b.*)
}
/DISCARD/ :
{
*(.gcc_except_table)
*(.eh_frame)
*(.note)
*(.comment)
*(.rel.*)
*(.rela.*)
}
}
Code: Select all
#!/bin/bash
set -e
export PREFIX="/usr/local/cross"
export TARGET=mipsel-elf
export PATH="$PREFIX/bin:$PATH"
mipsel-elf-as -o entry.o entry.s -mfix-loongson2f-nop -mfix-loongson2f-jump
#mipsel-elf-gcc -o main.o -c main.c -std=c99 -Wall -Wextra -Werror -ffreestanding -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -O2 -Wa,-mfix-loongson2f-nop,-mfix-loongson2f-jump
mipsel-elf-gcc -o main.o -c main-minimal.c -std=c99 -Wall -Wextra -Werror -ffreestanding -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -O2 -Wa,-mfix-loongson2f-nop,-mfix-loongson2f-jump
mipsel-elf-ld -T ldscript -o kernel.elf entry.o main.o
#sudo mount /dev/sda1 /mnt/boot
#sudo cp kernel.elf /mnt/boot
#sudo umount /dev/sda1
The problem is that when I run "qemu-system-mipsel -kernel kernel.elf", I just get a VGA blank mode screen (in other words, just blackness) instead of the screen being filled up with the '&' character as expected. If I had to guess where the problem was I would definitely say it's in the ldscript; I know very little about how linking works and it's entirely possible that 0xBFC0 is not what I should be putting there.
Brains of OSDev, do you have any advice for me? Does this code pass a sanity check? What would you reccommend to me for making this work?