Page 1 of 4
Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 6:01 am
by 0b00000000
Code: Select all
[BITS 16]
[ORG 0x7c00]
start:
MOV AL, 65
CALL print_character
CALL reset
CALL load
JMP ...
load:
MOV AL, 68
CALL print_character
MOV AX, 0x7E00
MOV ES, AX
XOR BX, BX
MOV AH, 0x02
MOV AL, 1
MOV CH, 1
MOV CL, 2
MOV DH, 0
MOV DL, 0
INT 0x13
JC load
RET
print_character:
MOV AH, 0x0E
MOV BH, 0x00
MOV BL, 0x07
INT 0x10
RET
reset:
MOV AL, 66
CALL print_character
MOV AH, 0
MOV DL, 0
INT 0x13
JC reset
MOV AL, 67
call print_character
RET
TIMES 510 - ($ - $$) db 0
DW 0xAA55
MOV AL, 69
CALL print_character
JMP $
TIMES 1024 - ($ - $$) db 0
Can anyone get this to run to completion?
Explanation of code. At each stage success is indicated by printing the next letter in the alphabet. I can get ABCD no problem. Problem is to print out E which would indicate that not only has second sector been successfully loaded (D) but transfer of control to loaded code is successful (E). See MOV AL, 69 after boot signature DW 0xAA55
Assuming that I've got the CHS right the problem seems to be getting the JMP right so that execution proceeds at the right place in memory.
0x00
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 6:27 am
by Techel
What about jmp 0x7E000? (Note that you load the sectors to 0x7E000 as you specify 0x7E00:0x0000 as destination)
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 6:47 am
by iansjack
Roflo wrote:What about jmp 0x7E000? (Note that you load the sectors to 0x7E000 as you specify 0x7E00:0x0000 as destination)
That's not going to work, is it?
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 6:56 am
by 0b00000000
Tried that. Didn't work. Tried using labels. That didn't work either. Tried playing with the CHS in case that was wrong. No luck there either. I'm starting to wonder if this is an emulator issue. Can anyone get the code to run correctly on their setup.
BTW, I'm running this as an emulated floppy with aqemu frontend for KVM.
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:08 am
by 0b00000000
Interesting.
I tried a JMP label version and a JMP 0x7E00 version. Dissassembly gives JMP WORD 0x7E00 for both versions. I've found two different versions online with conflicting CHS values. I've found one that claims CHS should be 1 0 2 and I've found another that claims CHS should be 0 0 2. I've tried both. Neither seem to work.
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:13 am
by gerryg400
Write some code that checks whether the load works. After the load, compare the first few bytes with the expected data.
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:18 am
by Techel
Also keep in mind some bios set cs to 0x7E0 and ip to 0 and that other thing I mentioned. Are you furthermore sure the bootdrive has an id of 0?
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:23 am
by iansjack
0b00000000 wrote:Tried playing with the CHS in case that was wrong. No luck there either. I'm starting to wonder if this is an emulator issue.
It is absolutely not an emulator issue. There is little point in "playing" with values. If you understand what you are doing then you will know whether they are correct or not.
More reading about the BIOS functions is required. And jumping to 0x7E00 when you have loaded the code at 0x7E000 (if your load was successful) is definitely not going to work.
This is pretty basic stuff and, as I said in your previous thread, there are hundreds of tutorials about it on the Internet.
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:26 am
by 0b00000000
Code: Select all
[BITS 16]
[ORG 0x7c00]
start:
CALL reset
CALL load
JMP 0x7C00
load:
MOV AL, 67
CALL print_character
MOV AX, 0x7E00
MOV ES, AX
XOR BX, BX
MOV AH, 0x02
MOV AL, 1
MOV CH, 0
MOV CL, 2
MOV DH, 0
MOV DL, 0
INT 0x13
JC load
MOV AL, 68
CALL print_character
RET
print_character:
MOV AH, 0x0E
MOV BH, 0x00
MOV BL, 0x07
INT 0x10
RET
reset:
MOV AL, 65
CALL print_character
MOV AH, 0
MOV DL, 0
INT 0x13
JC reset
MOV AL, 66
call print_character
RET
TIMES 510 - ($ - $$) db 0
DW 0xAA55
loaded:
MOV AL, 69
CALL print_character
JMP $
TIMES 1024 - ($ - $$) db 0
OK, I think I'm getting a little closer to identifying the problem. The above version loops and I get ABCDABCDABCD repeatedly printed out. So now I know the JMP 0x7C00 works and so a JMP 0x7E00 should also work if the load worked right and put the right instructions in memory at 0x7E00.
0x00
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:30 am
by 0b00000000
iansjack wrote:0b00000000 wrote:Tried playing with the CHS in case that was wrong. No luck there either. I'm starting to wonder if this is an emulator issue.
It is absolutely not an emulator issue. There is little point in "playing" with values. If you understand what you are doing then you will know whether they are correct or not.
More reading about the BIOS functions is required. And jumping to 0x7E00 when you have loaded the code at 0x7E000 (if your load was successful) is definitely not going to work.
This is pretty basic stuff and, as I said in your previous thread, there are hundreds of tutorials about it on the Internet.
Why wouldn't a JMP do it? How else would the IP get to be in the right place? I've seen references to far JMP but I'm not sure that's necessary or even desirable. Surely we haven't hit the boundaries of the present segment yet.
0x00
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:31 am
by gerryg400
What address are you loading to ?
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:31 am
by Techel
You are still loading to 0x7E000.
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:32 am
by 0b00000000
Roflo wrote:Also keep in mind some bios set cs to 0x7E0 and ip to 0 and that other thing I mentioned. Are you furthermore sure the bootdrive has an id of 0?
I have no idea what a floppy image boot drive should be set to. Nor can I find any documentation on this.
0x00
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:33 am
by gerryg400
Roflo wrote:You are still loading to 0x7E000.
Roflo, your posts must be invisible to him so I'll say to for you.
Hey OP, read the replies from Roflo !!!!
Re: Bootloader needs fix. See (JMP ...)
Posted: Mon Dec 21, 2015 7:37 am
by iansjack
0b00000000 wrote:iansjack wrote:0b00000000 wrote:Tried playing with the CHS in case that was wrong. No luck there either. I'm starting to wonder if this is an emulator issue.
It is absolutely not an emulator issue. There is little point in "playing" with values. If you understand what you are doing then you will know whether they are correct or not.
More reading about the BIOS functions is required. And jumping to 0x7E00 when you have loaded the code at 0x7E000 (if your load was successful) is definitely not going to work.
This is pretty basic stuff and, as I said in your previous thread, there are hundreds of tutorials about it on the Internet.
Why wouldn't a JMP do it? How else would the IP get to be in the right place? I've seen references to far JMP but I'm not sure that's necessary or even desirable. Surely we haven't hit the boundaries of the present segment yet.
0x00
Simply because you are not jumping to the location that you loaded the code to. The location that you jump to could contain anything - one thing that you can be certain of is that it's not your code.