Page 1 of 1
grub load problem
Posted: Tue Mar 30, 2010 1:17 pm
by assainator
I have finally started to use grub as bootloader. I have my kernel compiled, I put it on the floppy.
Then if I start bochs, it load grub. I select my kernel, and it loads it. And then it's freezing, while it should give me a nice "Welcome to LaBOS" greeting.
I get a screen like this and i'm sure my kernels 'kmain' get's called.
any idea what i'm doing wrong?
thanks in advance,
assainator
Re: grub load problem
Posted: Tue Mar 30, 2010 2:11 pm
by KotuxGuy
Well, it would help if you posted your linker script, sources, and Makefile.
Re: grub load problem
Posted: Wed Mar 31, 2010 12:19 am
by assainator
OK,
It is based on bran's kernel development tutorial
start.asm
Code: Select all
; This is the kernel's entry point. We could either call main here,
; or we can use this to setup the stack or other nice stuff, like
; perhaps setting up the GDT and segments. Please note that interrupts
; are disabled at this point: More on interrupts later!
[BITS 32]
global start
start:
mov esp, _sys_stack ; This points the stack to our new stack area
jmp stublet
; This part MUST be 4byte aligned, so we solve that issue using 'ALIGN 4'
ALIGN 4
mboot:
; Multiboot macros to make a few lines later more readable
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
EXTERN code, bss, end
; This is the GRUB Multiboot header. A boot signature
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
; AOUT kludge - must be physical addresses. Make a note of these:
; The linker script fills in the data for these ones!
dd mboot
dd code
dd bss
dd end
dd start
; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
extern _kmain
call _kmain
jmp $
; Shortly we will add code for loading the GDT right here!
; In just a few pages in this tutorial, we will add our Interrupt
; Service Routines (ISRs) right here!
; Here is the definition of our BSS section. Right now, we'll use
; it just to store the stack. Remember that a stack actually grows
; downwards, so we declare the size of the data before declaring
; the identifier '_sys_stack'
SECTION .bss
resb 8192 ; This reserves 8KBytes of memory here
_sys_stack:
kernel.c
Code: Select all
void kmain()
{
//print a character. That way I can see if something is happening.
short *VidMem = (short *)0x0b8000;
VidMem[0] = 'o' | 0x0f;
}
link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
and i'm on windows so i have no makefile, but i do have a batch-file:
build.bat
Code: Select all
@echo off
nasm -f aout -o start.o start.asm
gcc -o kernel.o -c kernel.c -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs -I./include
ld -T link.ld -o kernel.bin start.o kernel.o
Re: grub load problem
Posted: Wed Mar 31, 2010 1:16 am
by xenos
Well, it doesn't print "Welcome to LaBOS" because there is absolutely no code that would do that. The only thing your code does is writing some value at the beginning of video RAM which probably should display the letter "o" - but it won't do that either, because there is some simple mistake in your code. It should be something like this:
Code: Select all
void kmain()
{
//print a character. That way I can see if something is happening.
short *VidMem = (short *)0x0b8000;
VidMem[0] = 'o' | (0x0f << 8);
}
The attribute byte is the
second byte, so you need to shift it by 8 bits. This will display the letter "o" in the top left corner of the screen.
Re: grub load problem
Posted: Wed Mar 31, 2010 1:25 am
by assainator
XenOS wrote:Well, it doesn't print "Welcome to LaBOS" because there is absolutely no code that would do that. The only thing your code does is writing some value at the beginning of video RAM which probably should display the letter "o" - but it won't do that either, because there is some simple mistake in your code. It should be something like this:
Code: Select all
void kmain()
{
//print a character. That way I can see if something is happening.
short *VidMem = (short *)0x0b8000;
VidMem[0] = 'o' | (0x0f << 8);
}
The attribute byte is the
second byte, so you need to shift it by 8 bits. This will display the letter "o" in the top left corner of the screen.
Yes, that's true, after i posted i removed all of the printing code so that i would have less code to cover.
sometimes i feel like such an idiot for making a simple mistake like you pointed out.
Re: grub load problem
Posted: Wed Mar 31, 2010 6:24 am
by xenos
assainator wrote:sometimes i feel like such an idiot for making a simple mistake like you pointed out.
I guess that happens to all of us from time to time