MIPSel barebones troubles
Posted: Wed Jun 25, 2014 1:02 pm
Hello all; I'm trying to build a simple OS for my mips64el netbook (Lemote Yeeloong) using the target triplet "mipsel-elf". With a little help from CFE Bare Bones, Dominic Sweetman's See MIPS Run, my CPU datasheet, and my GPU datasheet, I conjured up a mipsel-elf cross-compiler toolchain in /usr/local/cross and these files:
entry.s:main-minimal.c:
ldscript:
build.sh:
I'd like to get it working in qemu-system-mipsel first and then try it on the real thing (only because rebooting is a bit of pain). My real goal here is to use as little asm as possible to get to C, then display something on the screen using VGA text mode (which is implemented by my GPU).
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?
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?