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
grub load problem
-
- Member
- Posts: 30
- Joined: Sun Jan 24, 2010 1:12 am
- Location: The Netherlands
grub load problem
Every human has to do something idiot to prevent becoming a complete one
- KotuxGuy
- Member
- Posts: 96
- Joined: Wed Nov 25, 2009 1:28 pm
- Location: Somewhere within 10ft of my favorite chubby penguin!
Re: grub load problem
Well, it would help if you posted your linker script, sources, and Makefile.
Give a man Linux, you feed the nearest optician ( Been staring at the PC too long again? ).
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory )
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory )
-
- Member
- Posts: 30
- Joined: Sun Jan 24, 2010 1:12 am
- Location: The Netherlands
Re: grub load problem
OK,
It is based on bran's kernel development tutorial
start.asm
kernel.c
link.ld
and i'm on windows so i have no makefile, but i do have a batch-file:
build.bat
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:
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 = .;
}
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
Every human has to do something idiot to prevent becoming a complete one
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: grub load problem
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:
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.
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);
}
-
- Member
- Posts: 30
- Joined: Sun Jan 24, 2010 1:12 am
- Location: The Netherlands
Re: grub load problem
Yes, that's true, after i posted i removed all of the printing code so that i would have less code to cover.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:
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.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); }
sometimes i feel like such an idiot for making a simple mistake like you pointed out.
Every human has to do something idiot to prevent becoming a complete one
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: grub load problem
I guess that happens to all of us from time to timeassainator wrote:sometimes i feel like such an idiot for making a simple mistake like you pointed out.