creating a looping 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.
Post Reply
poona
Posts: 1
Joined: Mon Apr 05, 2010 4:19 am

creating a looping bootloader

Post by poona »

Hi. I have a question on using int 19h to create a looping/reloading bootloader.

This bootloader prints the string "Testing interrupts!Testing interrupts!" when run

Code: Select all

        BITS 16

start:
        mov ax, 07C0h		; Set up 4K stack space after this bootloader
        add ax, 288		; (4096 + 512) / 16 bytes per paragraph
        mov ss, ax
        mov sp, 4096

        mov ax, 07C0h		; Set data segment to where we're loaded
        mov ds, ax


        mov si, text_string	; Put string position into SI
        call print_string	; Call our string-printing routine

        mov si, text_string	; Put string position into SI
        call print_string	; Call our string-printing routine

        jmp $			; Jump here - infinite loop!

        text_string db 'Testing interrupts!', 0


print_string:			; Routine: output string in SI to screen
        mov ah, 0Eh		; int 10h 'print char' function

.repeat:
        lodsb			; Get character from string
        cmp al, 0
        je .done		; If char is zero, end of string
        int 10h			; Otherwise, print it
        jmp .repeat

.done:
        ret

	times 510-($-$$) db 0	; Pad remainder of boot sector with 0s
	dw 0xAA55		; The standard PC boot signature
Now if I add a

Code: Select all

int 19h
right after I do the first call print_string, should the system go for a reboot and the bootloader be loaded again and the same string "Testing interrupts!" be printed again and the same thing continued recursively, with the bootloader being loaded again and again? This doesn't seem to be happening. What am I missing? I seem to have understood the interrupt wrongly. Shouldn't "int 19h" reread the first sector of the first hard disk and then reexcute the entire bootloader again?

like this

Code: Select all

        BITS 16

start:
        mov ax, 07C0h		; Set up 4K stack space after this bootloader
        add ax, 288		; (4096 + 512) / 16 bytes per paragraph
        mov ss, ax
        mov sp, 4096

        mov ax, 07C0h		; Set data segment to where we're loaded
        mov ds, ax

        mov si, text_string	; Put string position into SI
        call print_string	; Call our string-printing routine

	int 19h ; i have called this interrupt here

        mov si, text_string	; Put string position into SI
        call print_string	; Call our string-printing routine

        jmp $			; Jump here - infinite loop!

        text_string db 'Testing interrupts!', 0

print_string:			; Routine: output string in SI to screen
        mov ah, 0Eh		; int 10h 'print char' function

.repeat:
        lodsb			; Get character from string
        cmp al, 0
        je .done		; If char is zero, end of string
        int 10h			; Otherwise, print it
        jmp .repeat

.done:
        ret

	times 510-($-$$) db 0	; Pad remainder of boot sector with 0s
	dw 0xAA55		; The standard PC boot signature
Thanks a lot
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: creating a looping bootloader

Post by Chandra »

Display the message "Testing Interrupts" again and again? Hmm..............does that make any sense?

I suggest you to do something meaningful. First of all, focus on your bootloader. You may want your bootloader to load the segment registers, perform some real mode functions such as memory detection, graphics initialization etc., load the descriptor tables, and then load the kernel and pass execution to it. This is the main theory of operating system devolpment. This seems to be long and tedious but is fun when you learn it. So try something better.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: creating a looping bootloader

Post by egos »

int 18h - boot from next drive of boot sequence. Usually it's used in fixed drive bootloaders.
int 19h - boot from first drive of boot sequence. Usually it's used in removable media bootloaders.
If you have seen bad English in my words, tell me what's wrong, please.
Post Reply