What is wrong with this bootloader?

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.
Locked
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

What is wrong with this bootloader?

Post by Mikemk »

I am trying to load and execute the second sector on the disk.

Code: Select all

bits 16
org 0x7c00

jmp asm_main
packet:
	db 0x10
	db 0
	dw 1
	dd 0x5000
	dq 2
asm_main:
	mov ah, 0x41
	mov bx, 0x55AA
	int 0x13
	jc normal_operation
	
	mov bx, packet
	mov [ds:si], bx
	int 0x13
	mov ah, 0xe
	mov al, "A"
	int 0x10
	jmp 0x500:0
normal_operation:
	mov ah, 0xe
	mov al, "N"
	int 0x10
	mov ah, 2
	mov al, 1
	mov ch, 0
	mov cl, 1
	mov dh, 0
	mov bx, 0x500
	mov [es:bx], bx
	jmp 0x500:0

times 510-($-$$) db 0
db 0x55
db 0xaa
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
Combuster
Member
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: What is wrong with this bootloader?

Post by Combuster »

The amount of instances where you're relying on uninitialized data and registers is actually not funny at all: DS, ES, SS, SP, SI. It's as if you just randomly smashed together the code as a demonstration of effort and then come here to get more.

You are aware of the Required Knowledge rule? Your debugging skills need a lot of improvement.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: What is wrong with this bootloader?

Post by Mikemk »

I know the problem is something to do with the jmp commands
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
Combuster
Member
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: What is wrong with this bootloader?

Post by Combuster »

Actually, turns out your problem is reading :shock:

Did you even try to understand what I said? Since I now need to debug a problem between keyboard and chair, tell me, what did I mean?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: What is wrong with this bootloader?

Post by Mikemk »

You said that the segment and stack point registers are uninitialized . . .which I guess kindof makes sense.

I'm guessing that your telling me that the segment registers are in the stack, so I need to set the stack in order to use them?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: What is wrong with this bootloader?

Post by AJ »

Hi,

Locked before the flaming starts. Some hints:
m12 wrote:I'm guessing that your telling me that the segment registers are in the stack, so I need to set the stack in order to use them?
You are in a freestanding environment. There is no (sane) stack until you have initialised it and the segment registers do not contain (sane) values until you have initialised them. The values you load will depend on how you plan to do your real mode addressing.

I'm not going to spoonfeed you segment register values - a hint for suitable search terms would be along the lines of "segment:offset addressing", "real mode addressing" etc.

Theres also (IIRC) a decent tutorial on Bona Fide OS Development on the state of the PC after the BIOS hands your bootloader control.

Cheers,
Adam
Locked