kernel hang

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mastergoon

kernel hang

Post by mastergoon »

Hi. I am using mostly code from the OS FAQ. (I will put all my code towards the end of this post.) Grub and all loads successful, but once it "loads" my kernel, it just hangs. I am guessing i am doing something very stupid, and if someone could help me figure this out it would be great. I don't really know asm, and would like to get into an environment where I can start hacking away and having stuff happen in C :)

loader.s

Code: Select all

# loader.s

.global _loader            # making entry point visible to linker

# setting up the Multiboot header - see GRUB docs for details
.set ALIGN,     1<<0                     # align loaded modules on page boundaries
.set MEMINFO,  1<<1                      # provide memory map
.set FLAGS,     ALIGN | MEMINFO  # this is the Multiboot 'flag' field
.set MAGIC,     0x1BADB002         # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum required

.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

# reserve initial kernel stack space
.set STACKSIZE, 0x4000            # that's 16k.
.comm stack, STACKSIZE, 32        # reserve 16k stack on a quadword boundary

_loader:           mov   $(stack + STACKSIZE), %esp # set up the stack
                           push  %eax                                      # Multiboot magic number
                           push  %ebx                                      # Multiboot data structure

                           call  _main                  # call kernel proper
                           hlt                                  # halt machine should kernel return
link.ld

Code: Select all

TARGET (elf32-i386)
ENTRY (_loader)

SECTIONS
{
    . = 0x00100000;

    .text :
    {
        *(.text)
        *(.rodata)
    }

    .data ALIGN (0x1000) :
    {
        *(.data)
    }

    .bss :
    {
        _sbss = .;
        *(COMMON)
        *(.bss)
        _ebss = .;
    }
}
kernel.c

Code: Select all

#include "video.h"

video *Video;

int _main(void* mbd, unsigned int magic)
{
        Video = video_create();
        video_write(Video, "Hello there folks.");

        return 0;
}
video.h

Code: Select all

#ifndef VIDEO_H
#define VIDEO_H

typedef struct {
        unsigned short *mem;
        unsigned int off, pos;
} video;

int video_put(video *Video, char ch);
int video_write(video *Video, char *buf);
video *video_create();

#endif
video.c

Code: Select all

#include "video.h"

video *video_create()
{
        video *new;
        new->mem = (unsigned short*) 0xb8000;
        new->off = 0;
        new->pos = 0;
        return new;
}

int video_write(video *Video, char *buf)
{
        int i;
        for (i=0;i<sizeof(buf);i++) {
                video_put(Video, buf[i]);
        }

        return i;
}

int video_put(video *Video, char ch)
{
        if (Video->pos <= 80) {
                Video->pos = 0;
                Video->off += 80;
        }

        Video->mem[Video->off + Video->pos] = (unsigned char) ch | 0x0700;
        Video->pos++;

        return 1;
}
make commands

Code: Select all

as   -o loader.o loader.s
gcc  -c kernel.c -o kernel.o -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs
gcc  -c video.c -o video.o -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs
ld -T link.ld loader.o kernel.o video.o -o popcorn
mastergoon

Re:kernel hang

Post by mastergoon »

ACK! Disregard this message, i realized it is loading but my video driver has mistakes in it.

Thanks for your time.
proxy

Re:kernel hang

Post by proxy »

Code: Select all

        video *new;
        new->mem = (unsigned short*) 0xb8000;
        new->off = 0;
        new->pos = 0;
        return new;
AHH, i hope this is one of the mistakes you found, this is a biggie. You ha ve a pointer to an effectivly random location and you use it! I would recomend compile with all warnings on to catch these "uninitialized pointer" errors.

proxy
Post Reply