Program freezes after loading OS through GRUB on bochs...

Programming, for all ages and all languages.
Post Reply
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Program freezes after loading OS through GRUB on bochs...

Post by Yargh »

Hello, I have recently been attempting to develop some sort of an "OS". At first I had been manually writing characters to the vram, however I have just converted the example Pascal console library to C and added it. It compiled with no errors. The only problem is:

Whenever I try to boot into the OS from Bochs, it freezes after typing "boot" in grub.

In the console for bochs, it is showing these errors:
00096092378i[FDD ] read() on floppy image returns 0
00096137333i[FDD ] read() on floppy image returns 0
00096182288i[FDD ] read() on floppy image returns 0
00096227243i[FDD ] read() on floppy image returns 0
00096272198i[FDD ] read() on floppy image returns 0
00096317153i[FDD ] read() on floppy image returns 0
00096362108i[FDD ] read() on floppy image returns 0

Usually it works, but for some reason after I added this library it won't load.

Here is the source code:

kernel.c:

Code: Select all

#include "console.h"

/*Kernel Main*/
void kmain(void* mbd, unsigned int magic){
	if(magic != 0x2BADB002){ /*Not launched using the magic number, 0x1BADB002. For some reason,
	 even though the kernel is launched with 0x1BADB002, it shows up in the kernel as 0x2BADB002*/
		sWriteStr((unsigned char*)"Error 0");
		xpos = 0;
		ypos = ypos + 1;
		
		//Error 0, kernel not launched correctly
		return;
    }
	
    char * boot_loader_name =(char*) ((long*)mbd)[16];

    /* Print startup message */
	clrscr();
	
	sWriteStr((unsigned char*)"Welcome to lOS!");
	xpos = 0;
	ypos = ypos + 1;
}
console.c:

Code: Select all

#include "console.h"

unsigned char *vram = (unsigned char *) 0xb8000;

void clrscr(){
	for(int i = 0; i < 3999; i = i + 1){
		vram[i] = 0x00;
	}
}

void sWriteChar(unsigned char val){
	int offset;
	if(ypos > 24){
		ypos = 0;
	}
	if(xpos > 79){
		xpos = 0;
	}
	
	offset = (xpos << 1) + (ypos * 160);
	vram[offset] = val;
	offset = offset + 1;
	vram[offset] = 0x07;
	offset = offset + 1;
	
	xpos = (offset % 160);
	ypos = (offset - xpos) / 160;
	xpos = xpos >> 1;
	
}

void sWriteStr(unsigned char* val){
	int offset, i;
	
	if(ypos > 24){
		ypos = 0;
	}
	if(xpos > 79){
		xpos = 0;
	}
	
	offset = (xpos << 1) + (ypos * 160);
	i = 0;
	while(val[i] != (char)0x00){
		vram[offset] = val[i];
		offset = offset + 1;
		vram[offset] = 0x07;
		offset = offset + 1;
		i = i + 1;
	}
	
}
console.h:

Code: Select all

int xpos;
int ypos;

void clrscr();

void sWriteChar(unsigned char val);
void sWriteStr(unsigned char* val);
If it makes any difference, I am compiling it on a machine running Ubuntu Server 10.04, and running it in Bochs on OSX.

Thanks in advance for any help...
Wait... What?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Program freezes after loading OS through GRUB on bochs..

Post by gerryg400 »

What loader are you using ?

Edit: oops sorry I can see it's grub.
If a trainstation is where trains stop, what is a workstation ?
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: Program freezes after loading OS through GRUB on bochs..

Post by Yargh »

It's the same with Qemu, however it loads far faster. It seems to work if I print out one character at a time, however it crashes when I try to get the character from a char* array. Example:

It crashes with this:

Code: Select all

   char* msg = "Hello!";
	sWriteChar(msg[1]);
But it works with this:

Code: Select all

   sWriteChar('e');
Wait... What?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Program freezes after loading OS through GRUB on bochs..

Post by gerryg400 »

Whenever I try to boot into the OS from Bochs, it freezes after typing "boot" in grub.
Usually it works, but for some reason after I added this library it won't load.
It's the same with Qemu, however it loads far faster
however it crashes when I try to get the character from a char* array.
I'm confused, does it freeze, not load, load slowly or crash ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Program freezes after loading OS through GRUB on bochs..

Post by Combuster »

read() on floppy image returns 0
Your floppy image is broken. Make sure its the correct 1.4MB floppy size or emulators won't read large parts of it.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: Program freezes after loading OS through GRUB on bochs..

Post by Yargh »

By loading, I mean getting to grub and typing "kernel 200+18" and "boot", and by crashing I mean hanging after typing boot and not going through instructions before the "bad" code segment. Sorry for the confusion.
Combuster wrote:
read() on floppy image returns 0
Your floppy image is broken. Make sure its the correct 1.4MB floppy size or emulators won't read large parts of it.
So to make it get one character from an unsigned char *, I need to make sure the floppy is 1.4MB by adding a dummy file? Couldn't I just dd the floppy.img file to the start of a 15mb or so HDD image?
Wait... What?
Post Reply