copying kernel to floppy

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
ubergeek
Posts: 23
Joined: Thu Aug 09, 2007 5:26 am

copying kernel to floppy

Post 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?
Gizmo
Member
Member
Posts: 41
Joined: Fri Aug 03, 2007 3:41 am

Post 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;
	}

LaurensR1983
Posts: 24
Joined: Wed Jun 27, 2007 10:34 am

Post by LaurensR1983 »

edit: never mind... I read it all wrong
Post Reply