So I added something like that at the end of my bootsector:
Code:
; MBR partition table https://wiki.osdev.org/Partition_Table
times 48 db 0 ; empty entries
db 0x80 ; bootable partition
db 0x0 ; starting head
db 0x1 ; Starting sector (Bits 6-7 are the upper two bits for the Starting Cylinder field.) (Sectors are ennumerated from 1)
db 0x0 ; Starting Cylinder
db 0x4D ; System ID ('M' for MatOS in this case) not important
; For drives bigger than 8GB, generally the CHS fields are set to Cylinder = 1023, Head = 254 or 255, Sector = 63 -- which is considered an invalid setting.
db 0xFF ; Ending Head
db 0xFF ; Ending Sector (Bits 6-7 are the upper two bits for the ending cylinder field)
db 0xFF ; Ending Cylinder
dd 0x00 ; Relative Sector (to start of partition -- also equals the partition's starting LBA value)
dd 16515072; Total Sectors in partition (- 1 ????)
; bootsector signature
dw 0xAA55
It tested it and now my system boots from the USB HDD emulation on every PC I have at home. I cannot, however, get it to boot as a disc on bochs for some reason. My os image is a 34 816 Byte file called matos.raw so I added such lines in .bxsrc file:
Code:
ata0-master: type=disk, path="matos.raw", mode=flat, model="Boot drive"
...
boot: disk
Unfortuantely, once I run it bochs says there is no bootable device. Is it a problem with my .bxsrc configuration or the MBR? Or maybe I should format matos.raw file in some way?
Another thing is that I'm not sure how should the 6 bits of starting sector value in the partition table entry look like. It says here
https://wiki.osdev.org/Partition_Table that every value should be little endian. However, little endian desn't make sense when the value is only 6 bits wide I think...
If I want to choose sector 1, should I write "db 0x1" or "db (0x1 << 2)" or maybe "db (0x1 << 7)". I'm confused with it.