Bootloader needs fix. See (JMP ...)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

Bootloader needs fix. See (JMP ...)

Post 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
0x00
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Bootloader needs fix. See (JMP ...)

Post by Techel »

What about jmp 0x7E000? (Note that you load the sectors to 0x7E000 as you specify 0x7E00:0x0000 as destination)
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Bootloader needs fix. See (JMP ...)

Post 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?
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

Re: Bootloader needs fix. See (JMP ...)

Post 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.
0x00
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

Re: Bootloader needs fix. See (JMP ...)

Post 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.
0x00
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bootloader needs fix. See (JMP ...)

Post by gerryg400 »

Write some code that checks whether the load works. After the load, compare the first few bytes with the expected data.
If a trainstation is where trains stop, what is a workstation ?
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Bootloader needs fix. See (JMP ...)

Post 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?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Bootloader needs fix. See (JMP ...)

Post 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.
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

Re: Bootloader needs fix. See (JMP ...)

Post 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
0x00
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

Re: Bootloader needs fix. See (JMP ...)

Post 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
0x00
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bootloader needs fix. See (JMP ...)

Post by gerryg400 »

What address are you loading to ?
If a trainstation is where trains stop, what is a workstation ?
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Bootloader needs fix. See (JMP ...)

Post by Techel »

You are still loading to 0x7E000.
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

Re: Bootloader needs fix. See (JMP ...)

Post 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
0x00
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bootloader needs fix. See (JMP ...)

Post 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 !!!!
If a trainstation is where trains stop, what is a workstation ?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Bootloader needs fix. See (JMP ...)

Post 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.
Post Reply