Alternative loading technique
-
- Member
- Posts: 50
- Joined: Sun Dec 20, 2015 4:00 pm
- Libera.chat IRC: 0b00000000
Alternative loading technique
Hi,
so it seems that most boot loading techniques out there are using INT 13 variants to load code beyond the first sector (assumed to be automatically loaded by the BIOS is certain conventions have been adhered to).
But what if we aren't happy with the assumption that the BIOS can perform those INT 13 variants for us? Or simply would just rather not rely on the BIOS to do this for us and want complete independence from the BIOS immediately?
Is there any way to load sectors into memory without using INT 13 but using direct methods that do not rely on any of the BIOS functions?
so it seems that most boot loading techniques out there are using INT 13 variants to load code beyond the first sector (assumed to be automatically loaded by the BIOS is certain conventions have been adhered to).
But what if we aren't happy with the assumption that the BIOS can perform those INT 13 variants for us? Or simply would just rather not rely on the BIOS to do this for us and want complete independence from the BIOS immediately?
Is there any way to load sectors into memory without using INT 13 but using direct methods that do not rely on any of the BIOS functions?
0x00
-
- Member
- Posts: 5588
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Alternative loading technique
Yes.0b00000000 wrote:Is there any way to load sectors into memory without using INT 13 but using direct methods that do not rely on any of the BIOS functions?
However, all of those methods take up way more space than using int 0x13, and you need separate code for each type of device. Good luck fitting that in under 512 bytes.
Re: Alternative loading technique
Or one could build their own hardware, not PC-compatible, w/o the traditional BIOS and maybe with a simplified chipset...Octocontrabass wrote:Yes.0b00000000 wrote:Is there any way to load sectors into memory without using INT 13 but using direct methods that do not rely on any of the BIOS functions?
However, all of those methods take up way more space than using int 0x13, and you need separate code for each type of device. Good luck fitting that in under 512 bytes.
-
- Member
- Posts: 50
- Joined: Sun Dec 20, 2015 4:00 pm
- Libera.chat IRC: 0b00000000
Re: Alternative loading technique
Would it be feasible to fit the code for a single known device into the 512 bytes?Octocontrabass wrote:Yes.0b00000000 wrote:Is there any way to load sectors into memory without using INT 13 but using direct methods that do not rely on any of the BIOS functions?
However, all of those methods take up way more space than using int 0x13, and you need separate code for each type of device. Good luck fitting that in under 512 bytes.
0x00
Re: Alternative loading technique
That is one problem but I think it is not the main reason for this being a bad idea. Please note that the INT 13h services are not necessarily "what they look like", i.e. there might be an intermediate layer that provides that abstraction. It is (or should be) a de facto standard that boot loaders use those services for accessing their boot storage media.Octocontrabass wrote:However, all of those methods take up way more space than using int 0x13, and you need separate code for each type of device. Good luck fitting that in under 512 bytes.
- Combuster
- 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: Alternative loading technique
In your case, no.0b00000000 wrote:Would it be feasible to fit the code for a single known device into the 512 bytes?
-
- Member
- Posts: 50
- Joined: Sun Dec 20, 2015 4:00 pm
- Libera.chat IRC: 0b00000000
Re: Alternative loading technique
In your case yes?Combuster wrote:In your case, no.0b00000000 wrote:Would it be feasible to fit the code for a single known device into the 512 bytes?
0x00
Re: Alternative loading technique
It might be possible in really simple cases, but when adding support for a filesystem (fat e.g. requires it's parameter block in the first sector, the available bytes for the boot code shrink to ~440 bytes minus the code for finding the kernel file) int 13h is the only thing to use.
-
- Member
- Posts: 50
- Joined: Sun Dec 20, 2015 4:00 pm
- Libera.chat IRC: 0b00000000
Re: Alternative loading technique
So, in the scenario with no file system just reading raw binary from the media could this be done?Roflo wrote:It might be possible in really simple cases, but when adding support for a filesystem (fat e.g. requires it's parameter block in the first sector, the available bytes for the boot code shrink to ~440 bytes minus the code for finding the kernel file) int 13h is the only thing to use.
0x00
Re: Alternative loading technique
Think about what your code needs to do to read a sector from a SATA drive, and then decide if you think it can be done in 446 bytes:
- Initialize PCI controllers and, if not already done by BIOS, assign BARs.
- Assigning BARs requires knowing the system memory map. You'll need to use INT15H to get that.
- If you don't want to use INT15H either, you'll need a chipset driver to query the memory controller for DRAM configuration and an ACPI driver to parse the DSDT and build a memory map from that.
- Search for AHCI HBAs and initialize them.
- Initialize active ports and query the attached devices.
- Select one of the devices and send it a read.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Alternative loading technique
You could probably write a floppy disk driver in under 512 bytes, which would allow you to read arbitrary sectors from a floppy disk. Forget about filesystem parsing though; you'll have to just blindly load specific sectors as there probably won't be enough space in the boot sector for a floppy disk driver *and* a filesystem parser. Of course, once you can read sectors, you can load a filesystem parser for whatever filesystem you want from elsewhere on the disk, but that's only *after* you've already blindly loaded the filesystem parser. It might be better to use one floppy disk of known layout to store the rest of the bootloader (which includes the filesystem parser and/or drivers for other storage devices), load that, then prompt the user to insert another disk containing the actual operating system, which can then be parsed and loaded with the filesystem parser and executable loader which were read by the bootsector from the first disk.
In short, yes you can probably write a bootloader to load *one* format of kernel from *one* kind of device without using any BIOS interrupts. If that's what you call a bootloader, then fine. From an experimental point of view it's an interesting exercise, but in reality it's clumsy and doesn't offer any real advantage.
P.S. I gather from some of your posts around here that you have a fear of low-level espionage against your computer? You seem to be intent on avoiding the BIOS as much as possible, and the virtual machines thread was kind of creepy...
In short, yes you can probably write a bootloader to load *one* format of kernel from *one* kind of device without using any BIOS interrupts. If that's what you call a bootloader, then fine. From an experimental point of view it's an interesting exercise, but in reality it's clumsy and doesn't offer any real advantage.
P.S. I gather from some of your posts around here that you have a fear of low-level espionage against your computer? You seem to be intent on avoiding the BIOS as much as possible, and the virtual machines thread was kind of creepy...
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Alternative loading technique
I seem to recall estimating that PIO reading legacy harddrives could be done in about 150 bytes.