kernel hang
Posted: Sat Aug 14, 2004 1:38 pm
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
link.ld
kernel.c
video.h
video.c
make commands

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
Code: Select all
TARGET (elf32-i386)
ENTRY (_loader)
SECTIONS
{
. = 0x00100000;
.text :
{
*(.text)
*(.rodata)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
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;
}
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
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;
}
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