Page 1 of 1
bootloader error
Posted: Thu Oct 13, 2016 7:09 am
by Raymond
Code: Select all
; haribote-ipl
; TAB=4
CYLS EQU 4
ORG 0x7c00
JMP entry
DB 0x90
DB "HARIBOTE"
DW 512
DB 1
DW 1
DB 2
DW 224
DW 2880
DB 0xf0
DW 9
DW 18
DW 2
DD 0
DD 2880
DB 0,0,0x29
DD 0xffffffff
DB "HARIBOTEOS "
DB "FAT12 "
RESB 18
entry:
MOV AX,0
MOV SS,AX
MOV SP,0x7c00
MOV DS,AX
;read disk
MOV AX,0x0820
MOV ES,AX
MOV CH,0 ; cylinder 0
MOV DH,0 ; head0
MOV CL,2 ; sect 2
readloop:
MOV SI,0
retry:
MOV AH,0x02
MOV AL,1
MOV BX,0
MOV DL,0x80
INT 0x13
JNC next
ADD SI,1
CMP SI,5
JAE error
MOV AH,0x00
MOV DL,0x80 ; C disk
INT 0x13
JMP retry
next:
MOV AX,ES ;add 0x200
ADD AX,0x0020
MOV ES,AX
ADD CL,1
CMP CL,63
JBE readloop ; CL <= 17 go to readloop
MOV CL,1
ADD DH,1
CMP DH,16
JB readloop
MOV DH,0
ADD CH,1
CMP CH,CYLS
JB readloop
; jump to sys files
MOV [0x0ff0],CH
JMP 0xc200
error:
MOV SI,msg
putloop:
MOV AL,[SI]
ADD SI,1
CMP AL,0
JE fin
MOV AH,0x0e
MOV BX,15
INT 0x10
JMP putloop
fin:
HLT
JMP fin
msg:
DB 0x0a, 0x0a
DB "load error"
DB 0x0a
DB 0
RESB 0x7dfe-$
DB 0x55, 0xaa
This is my bootloader file,before it can load from hard disk ,but after I lost my primitive boot file , i rebuild it ,but it
has an error at 'int 0x13' for hard disk,below is my bochs config for hard disk.
Code: Select all
ata0-master: type=disk, mode=flat, path=woods.img, cylinders=1024, heads=16, spt=63
Who can help me to find some bugs for me ,i will thank you very much.
ray
Re: bootloader error
Posted: Thu Oct 13, 2016 10:35 am
by BenLunt
For one thing, maybe not related, you have a BPB for a 1.44meg floppy disk.
The read service may or may not preserve the registers. Therefore, when you loop back for another sector/head/cylinder, the registers may not be correctly preserved.
The retry count of 5, which by the way is usually only used for floppy disks, is probably redundant. A hard drive read won't fail on the first try, then be successful on a second try. If it is, you have got more problems than just trying to read from the drive.
Did Bochs Panic with a "read out of bounds" message?
Your code assumes 16 heads per cylinder, which is correct via the ATA: line you specify. However, I would get the disk parameters from the BIOS first.
Better yet, check to see if the Extended Read service is available and use LBA addressing instead of CHS addressing.
BTW, you can read more than one sector at a time, using CHS or LBA addressing.
A few more (unrelated) hints, since it looks like you might not be familiar with x86 assembly. The CL and CH registers can be accessed via the combined CX register. For example,
can be changed to
instead.
Give us a little more information and we will see what we can do to help.
Ben
http://www.fysnet.net/osdesign_book_series.htm
Re: bootloader error
Posted: Thu Oct 13, 2016 1:31 pm
by Schol-R-LEA
Raymond wrote:This is my bootloader file,before it can load from hard disk ,but after I lost my primitive boot file , i rebuild it
I hope you now understand the value of an
offsite VCS repo, after that. Were this me, the first thing I would do after realizing I had lost such a crucial piece of code would be to make an account on
GitHub,
GitLab,
BitBucket,
Cloudforge, or
somewhere like that, and religiously check in
any code changes once I was sure they were working.
If you aren't convinced yet, this
2014 essay on the subject should change your mind.
Re: bootloader error
Posted: Thu Oct 13, 2016 5:23 pm
by Raymond
Code: Select all
01558479749i[BIOS ] int13_harddisk: function 02, parameters out of range 0001/0003/0013!
01562308473i[BIOS ] IDE time out
This is my bochs output file.
And can you give some references about programming of Extended Read service that uses lba mode?
Re: bootloader error
Posted: Thu Oct 13, 2016 8:34 pm
by BenLunt
See, there you go. Parameters out of range: Cyl/Head/Sector. (Those numbers are hex by the way)
So, your code tries to access the 19th sector of the disk, which is not present. This tells me you are actually using a floppy disk image instead of a HDD image.
However, the "int13_harddisk:" part of the error tells me you are using the hard drive image. How many bytes (sectors) is your "woods.img" file? Could it be that it isn't actually the 100 cylinders you tell Bochs it is? By chance is your "woods.img" file around 622,080 bytes in length?
As for the Extended services, you use service 0x4100 and put 0x55AA in BX. Then on return, if carry is not set *and* BX now is 0xAA55, you can use the extended read and write services for that disk.
However, please note that most BIOSes will return FALSE for any floppy disk even though it supports it for the hard drives. Therefore, you (almost) always have to use CHS for floppy access. (Almost, because I once came across a BIOS that supported it for the floppy disk)
Check your "woods.img" file for length. I bet that it is short and Bochs is trying to read from the end of the file. Either that or you are some how telling the BIOS that your hard disk now only has 18 sectors per track...
Ben
Re: bootloader error
Posted: Fri Oct 14, 2016 2:13 am
by Raymond
OK,I finally find the issue that is my config of my bochs.
In bochs the max chs is 1024/17/63,since my chs is rightly at bound,so i change the config:
Code: Select all
ata0-master: type=disk, mode=flat, path=wood.img, cylinders=940, heads=6, spt=17
And it works,thanks,
ray
Re: bootloader error
Posted: Fri Oct 14, 2016 10:53 am
by BenLunt
Max CHS values for Bochs, and most other emulators as well as BIOSes, is 1024 cyls, 16 heads, and 63 sectors. Cyls using 10 bits, heads using only 4 of the allotted 8, and sectors using 6 bits.
In the olden' days, there were BIOS wrappers that would use all 8 bits of the head field to allow larger disks to be used. Wasn't that fun? You had to install a BIOS hook, usually just past the MBR, to hook INT 13h to read a 8gig drive. On top of that, due to a bug in DOS, you could only use 255 heads. Then on top of that, there were a few other limits. With today's drives in the Terabyte range, it's a good thing we don't use CHS anymore.
I know that it might not be too important to you at the moment, but I would find out why your code didn't work for the most common setting of 1024/16/63. A setting of 6 heads and 17 sectors per track is quite uncommon for a hard drive, especially when emulated.
Anyway, something to do for another time, right?
Re: bootloader error
Posted: Fri Oct 14, 2016 12:17 pm
by Octocontrabass
BenLunt wrote:Max CHS values for Bochs, and most other emulators as well as BIOSes, is 1024 cyls, 16 heads, and 63 sectors.
Bochs emulates an ATA device, and the C/H/S parameters you give it are the ATA geometry. The limits are 65536 cylinders, 16 heads, and 255 sectors. These limits apply to real ATA devices as well, when using CHS.
BenLunt wrote:In the olden' days, there were BIOS wrappers that would use all 8 bits of the head field to allow larger disks to be used.
And in the slightly-less olden days, the BIOS had this functionality built-in. You could even choose how the translation would be performed, although it's usually not obvious which option controls it.
BenLunt wrote:A setting of 6 heads and 17 sectors per track is quite uncommon for a hard drive, especially when emulated.
Not if Bochs is being clever about how it translates the drive geometry.
Re: bootloader error
Posted: Fri Oct 14, 2016 3:40 pm
by BenLunt
Octocontrabass wrote:BenLunt wrote:Max CHS values for Bochs, and most other emulators as well as BIOSes, is 1024 cyls, 16 heads, and 63 sectors.
Bochs emulates an ATA device, and the C/H/S parameters you give it are the ATA geometry. The limits are 65536 cylinders, 16 heads, and 255 sectors. These limits apply to real ATA devices as well, when using CHS.
How are you fitting 65536 (0xFFFF zero based) into 10 bits? CHS uses a max of 1024 cylinders. Period...
Octocontrabass wrote:BenLunt wrote:A setting of 6 heads and 17 sectors per track is quite uncommon for a hard drive, especially when emulated.
Not if Bochs is being clever about how it translates the drive geometry.
Still, uncommon.
Ben
Re: bootloader error
Posted: Fri Oct 14, 2016 8:23 pm
by BenLunt
BenLunt wrote:Octocontrabass wrote:BenLunt wrote:Max CHS values for Bochs, and most other emulators as well as BIOSes, is 1024 cyls, 16 heads, and 63 sectors.
Bochs emulates an ATA device, and the C/H/S parameters you give it are the ATA geometry. The limits are 65536 cylinders, 16 heads, and 255 sectors. These limits apply to real ATA devices as well, when using CHS.
How are you fitting 65536 (0xFFFF zero based) into 10 bits? CHS uses a max of 1024 cylinders. Period...
Octocontrabass wrote:BenLunt wrote:A setting of 6 heads and 17 sectors per track is quite uncommon for a hard drive, especially when emulated.
Not if Bochs is being clever about how it translates the drive geometry.
Still, uncommon.
Ben
I take that back, and humbly apologize. The ATA-5 specs say:
"A CHS address is made up of three fields: the sector number, the head number, and the cylinder number. Sectors are numbered from 1 to the maximum value allowed by the current CHS translation but shall not exceed 255. Heads are numbered from 0 to the maximum value allowed by the current CHS translation but shall not exceed 15. Cylinders are numbered from 0 to the maximum value allowed by the current CHS translation but shall not exceed 65,535."
"Not to exceed 65536".
Sorry,
Ben
Re: bootloader error
Posted: Sun Oct 16, 2016 9:31 am
by Schol-R-LEA
Just to follow up: did you take my earlier advice about
Code Management yet? I cannot stress enough the importance of this, and I want to make sure you have take steps to prevent this sort of thing from happening again.