Page 1 of 1

Help on Sectors and Copying to a floppy using partcopy

Posted: Thu Mar 31, 2005 3:25 pm
by TheUnbeliever
If anyone can help I'd be very happy. Smile Razz

I'm using partcopy to write data to specific sectors on a floppy in order to create a bootable floppy using my boot loader and put other instructions where I need them on the floppy so that they can be called by the boot loader/kernel etc.

I wrote my boot loader, compiled it using NASM and using partcopy, copied it to the first sector of the floppy so that the BIOS picks it up and uses it to boot. In case you're wondering I used:

I then wrote my kernel (which is called from the boot loader) which is meant to go into the second sector of the floppy. So I compile and attempt to copy it to the second sector of the floppy. The file is 264 bytes in size - as you can see by the byte range to copy being 0 - 108 (it uses hex not decimal).

Unfortunately, when I do that, the floppy shows up as not formatted in windows (indicating, I'm guessing, that I over wrote the DOS boot record). When I boot from it (I've tested this on a virtual machine - Bochs - and on a real computer), I get my boot loader message (the boot loader just prints the name then loads the kernel into memory and jumps to it), but the message in my kernel doesn't print (the kernel prints a welcome message then loops infinitely). Bochs doesn't throw an error, and everything seems normal (including the number of times that the floppy is read from) except that the message in the kernel doesn't display.

I added a bit after where the boot loader jumps to the kernel, to see if it was actually jumping. If it didn't jump, I'd get a message about it (because it kept executing code in the boot loader and not jump to the kernel), but I didn't get the message - so it does actually jump to the kernel. The problem seems to be with the kernel - either in the code, compiling or the copying to the disk.

Can anyone help?

http://www.angusenterprises.co.uk/boot.asm
http://www.angusenterprises.co.uk/kernel.asm

makeboot.bat
-------------
nasm boot.asm -f bin -o output/bootsec.bin
partcopy output/bootsec.bin 0 200 -f0
nasm kernel.asm -f bin -o output/kernel.bin
partcopy output/kernel.bin 0 108 -f0 201


Sorry if this is something of a newbie-esque question. Also, sorry, this free hosting seems to try to add it's wee thing to everything possible. At some point I must buy myself free hosting, or sort out the PHP on my shell account.

EDIT: Finished merging together various posts I've made which had variations and inconsistencies, particularly with the code)

Re:Help on Sectors and Copying to a floppy using partcopy

Posted: Thu Mar 31, 2005 8:01 pm
by Argh
I believe you'll find the error in your sector loading code. You aren't loading what you think you're loading. Check it.

Re:Help on Sectors and Copying to a floppy using partcopy

Posted: Fri Apr 01, 2005 4:28 am
by TheUnbeliever
Thanks, that gave me a step forward. I got it to load the 1st sector (as evidenced by it looping the first message infinitely), but it doesn't seem to want to load the second sector.

At least I seem to know where the error is, so I can try to fix it. Thanks.

EDIT: I've played around a little bit, trying to load 2 sectors starting at sector one etc, and something I've found is that it seems to load the first sector, to 0x1000 (I changed the position from 0x2000 to be more logical), and I can jump to that, and get it to loop the bootloader infinitely. When I try to jump to 0x1201 which should be the position of the kernel, I get a 'prefetch: RIP > CS.limit' error. I've seen that error before, I got it when I was trying to jump to an area where there was nothing loaded (eg: loading the sector to 0x1000 and jumping to 0x2000), and it disappeared when I changed it to wherever I had loaded something.

What confuses me, is that if I load the second sector to 0x1000 and jump to there, I don't get any error - but in theory I should.

When I print what is at sector 2 (by loading it to 0x1000, then using code:

   mov ax,0000h      ;Setting the offset for the data segment reference.
   mov ds,ax      ;DS:Offset = location of data
   mov si,bx      ;Put string where it needs to be for WStr
   call WStr

I get an uppercase S followed by a space printed to the screen.