Page 1 of 1

copying kernel to floppy

Posted: Fri Aug 10, 2007 5:37 am
by ubergeek
Allright, I've got past the bootloader. I followed the "Xosdev" tutorials on osdever.net, there was some code there to load the kernel. You had to change some variables to indicate how many sectors long the kernel was. (1kb = 2 sectors, etc.) So should I just copy the kernel.bin to the disk or should I burn it with partcopy to the next couple of sectors?

Posted: Fri Aug 10, 2007 11:10 am
by Gizmo
Are you copying raw binaries directly onto sectors 1 and 2, or does your bootloader read fat12 and loads a file?

If you are writing raw binaries without a filesystem you can use this c code to make a disk image where your bootloader is bootldr.bin and your kernel is kernel.bin:

Code: Select all

#include <stdio.h>
#include <string.h>


#define FLOPPYSIZE 1474560
unsigned char DiskImage[FLOPPYSIZE];

	int main(void)
	{
	//clear disk image
		memset(DiskImage,0,FLOPPYSIZE);
	//read bootsector
		FILE *BootFile=fopen("bootldr.bin","rb");
		if(BootFile)
		{
			fread(&DiskImage[0],512,1,BootFile);
			fclose(BootFile);
		}
	//read kernel
		FILE *KernelFile=fopen("kernel.bin","rb");
		if(KernelFile)
		{
			int aa=512,bb=0;
			while(aa<FLOPPYSIZE)
			{
				bb=32000;
				if(FLOPPYSIZE-aa<bb)
				{
					bb=FLOPPYSIZE-aa;
				}
				fread(&DiskImage[aa],bb,1,KernelFile);
				aa+=bb;
			}
			fclose(KernelFile);
		}
	//save disk image
		FILE *ImgFile=fopen("Floppy.img","wb");
		if(ImgFile)
		{
			int aa=0,bb;
			while(aa<FLOPPYSIZE)
			{
				bb=32000;
				if(FLOPPYSIZE-aa<bb)
				{
					bb=FLOPPYSIZE-aa;
				}
				fwrite(&DiskImage[aa],bb,1,ImgFile);
				aa+=bb;
			}
			fflush(ImgFile);
			fclose(ImgFile);
		}
		return 0;
	}


Posted: Fri Aug 10, 2007 6:41 pm
by LaurensR1983
edit: never mind... I read it all wrong