Something wrong with my bootstrap

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.
Post Reply
User avatar
negcit.K
Member
Member
Posts: 34
Joined: Fri Dec 07, 2007 9:57 am

Something wrong with my bootstrap

Post by negcit.K »

l have written a bootstrap boot.asm. It just print the string " load setup ...." which is not my want. i looked at it for a long time;nothing wrong found. Can some of you give me some tips?
The code is here:

Code: Select all

;-----------------------------------------------------------------------;
;		boot.asm
;
	
[ORG 0x7c00]
	jmp start

BOOTSEG	equ 0x07c0
SYSSEG 	equ 0x1000
LOADSEG	equ 0x07e0

;some print strings and val
msg1_load	db	"loading setup... "
msg2_ok		db	"loaded ok "
msg3_faile	db	"loaded faile "

sectors		db	18



;----------------------------------;
;	boot starts here	   ;
;----------------------------------;
start:
	mov ax, [BOOTSEG]
	mov es, ax
	mov ds, ax
	mov ss, ax
			
;set textmode
	mov ax, 0x0003
	int 0x10


	mov ax, [BOOTSEG]
	mov es, ax





;print "Loadint setup... "
	mov dx, 0x0100
	mov cx, 17
	mov bx, 0x0007
	mov bp, msg1_load
	mov ax, 0x1301		; write string, move cursor
	int 0x10

			

load_setup:
	mov ax, [LOADSEG]
	mov es, ax
	
	xor bx, bx		; bx is starting address within segment
	mov dx, 0x0000		; driver 0, head 0
	mov cx, 0x0002		; start sector 2, track 0
	mov al, 02		; nr of sectors
	mov ah, 02		; service
	int 0x13
	jnc next
	jmp load_failed

;; print "load Ok"
next:
	mov ax, [BOOTSEG]
	mov es, ax
	

	
	mov dx, 0x0200
	mov cx, 10
	mov bx, 0x0007
	mov bp, msg2_ok
	mov ax, 0x1301		; write string, move cursor
	int 0x10

	
	jmp 0x07e0:0x0000			



load_failed:
	mov ax, [BOOTSEG]
	mov es, ax
	
	mov dx, 0x0300
	mov cx, 13
	mov bx, 0x0007
	mov bp, msg3_faile
	mov ax, 0x1301		; write string, move cursor
	int 0x10

die:	jmp die



times 510-($-$$) db 0           ; Fill up the file with zeros

boot_sign:
        dw 0AA55h                ; Boot sector identifyer
and here is want my want:
load the second and third sector of floopy where my setup.s is at 0x07c00.
Then jump into setup.s.

but it does nothing but prints the first message.

Thanks all the tips.
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Post by gzaloprgm »

Hi!
load the second and third sector of floopy where my setup.s is at 0x07c00.
You won't be able to do that, why? Simply, because 1º stage (1st sector of floppy) is loaded at 0x7c00, so if you write there you'll get to the point in which you'll overwrite the actually running code and it won't continue (it will, but it will execute garbage)

So select another place in memory, lets say 0x7c00 (0x7c00:0x0200)

By the way, you can read http://www.brokenthorn.com/Resources/OSDevIndex.html to make a better bootloader which loads files from a fat12 formatted floppy (my bootloader is a 1stage pmode version I made adding things to it)

Cheers,
Gonzalo
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Code: Select all

mov ax, [BOOTSEG] 
This statement is wrong everywhere it appears in the code. You want it to say: mov ax, BOOTSEG

The [] operators are like the * operator in C. Your code is pulling values out of memory location 0x7c0 all the time. The [LOADSEG] statement has the same problem, of course.

Your code for loading the second and third sectors looks like it might work, since you seem to by trying to load two sectors starting at 0x7e00. I haven't checked your CHS values to make sure they are right.
Post Reply