OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Aug 07, 2020 9:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Boot floppy without BIOS disk services
PostPosted: Sat Dec 07, 2019 3:11 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 667
Location: USA
Over at Stack Overflow, someone asked about loading additional sectors from a floppy without using the BIOS disk services. Well, curiosity got me and I had to try. (Actual code is here)

The trick wasn't to simply read more sectors from the disk, this would have been easy. The trick was to do it without assuming anything about the hardware. Granted, I have to assume the first controller and the first drive on the controller, but other than this, all remaining must be not assumed.

For example:
- I reset the controller
- Receive/Send all four Sense Interrupts
- Send the Specify command
- Seek to Cylinder 0
- Set up the DMA, and finally:
- Read a sector from the disk
All within the first 512 bytes, all without using the BIOS disk services.

I had to try it, and found out that it is actually possible. The current code needs a little work. For example, I currently don't wait 2 seconds for the disk to spin up, but it should already be spinning since the BIOS just loaded the first sector. The code needs to be cleaned up a little and a more accurate delay needs to be found, but it does show that it can be done.

It runs on Bochs and QEMU just fine. (So that you don't have to build it, the 1.44meg image is available on the github link shown above.)

It was a fun little experiment and I thought others here might be interested in seeing it.

Ben
- http://www.fysnet.net/osdesign_book_series.htm


Top
 Profile  
 
 Post subject: Re: Boot floppy without BIOS disk services
PostPosted: Sun Dec 08, 2019 12:20 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2010 4:53 pm
Posts: 1089
Location: Scotland
My OS used to work in a similar way, though without using DMA and with interrupts disabled: I wrote a minimal mPD765A device driver in the boot sector which could load the OS and save it back to disk after modification, and it was used for all loading and saving of files too. It worked fine on 486s but refused to boot on later machines so I nearly got stuck when my last 486 stopped working. Bochs then came to the rescue, letting me change the code to use the BIOS instead so that I could use a USB floppy drive. I've often wondered why my old code worked on 486s but not Pentiums but I've never had time to look into why. I'll grab a copy of your code in the hope that it contains the answer, though I won't have time to study it for a while. That device driver is still sitting in my OS, but relocated and no longer used.

Edit: I forgot to mention that my floppy driver ran in 32-bit mode, so the first move in my boot sector was a switch to protected mode.

_________________
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming


Last edited by DavidCooper on Wed Dec 11, 2019 11:21 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Boot floppy without BIOS disk services
PostPosted: Wed Dec 11, 2019 12:06 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 798
Hi,

You could also take a look at Xv6's boot sector.
- bootasm.S is a small prologue that sets up protected mode and calls bootmain()
- bootmain.c then loads the kernel without using BIOS calls (no DMA, extremely simple code).

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Boot floppy without BIOS disk services
PostPosted: Wed Jan 08, 2020 7:51 am 
Offline
Member
Member

Joined: Sat Feb 27, 2010 8:55 pm
Posts: 137
I believe I found a bug in Ben's code. The .inc file has:

Code:
IRQ_NUM             equ  0x0E   ; Interrupt Vector Table index for the floppy disk


OK, so far so good, the floppy is IRQ 6, interrupt vector 0xe

Code:
.if (IRQ_NUM < 8)
           mov  dx,0x21
           in   al,dx
           or   al,(1<<IRQ_NUM)
           out  dx,al
.else
           mov  dx,0xA1
           in   al,dx
           or   al,(1<<(IRQ_NUM-8))
           out  dx,al
.endif


OK, IRQs < 8 go to 1st PIC, >8 go to 2nd PIC. Makes sense. But IRQ_NUM had been defined as the interrupt vector number, not the IRQ number. That means this code will incorrectly enable the IRQ on the 2nd PIC. The code works because the BIOS already has interrupts enabled, but it's not technically correct.

Anyway, thank you for sharing this Ben! I'm using it to learn how to program the floppy. :)


Top
 Profile  
 
 Post subject: Re: Boot floppy without BIOS disk services
PostPosted: Wed Jan 08, 2020 5:21 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 667
Location: USA
Ya, you are probably correct. I rushed through that part. Either way, it does show that it can be done.

Thanks,
Ben


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group