adholioshake
Programmer
- Feb 9, 2003
- 136
Hi people.
I have been working on a boot loader program for a while, and it is almost working fully. I've just hit one problem that occurs after loading a program (off sector 2) in memory. Take a look at the code:
I have indicated the problem with 'WHY DOESN'T THIS WORK??'.
I want the code segment (CS) to be where the program is in memory, but when I try to change it (the code commented out below 'WHY DOESN'T...'), it screws up and just reboots. Why does it do this? Does anyone know what I should do?
Adonai.
I have been working on a boot loader program for a while, and it is almost working fully. I've just hit one problem that occurs after loading a program (off sector 2) in memory. Take a look at the code:
Code:
assume cs:code
code segment
org 100h
program:
jmp start
msg1 db 'Boot Program Started.',0
err1 db 'Error reading disk! Push a key to restart.',0
start:
; Setup segment registers
mov ax,07b0h
dw 08ec8h
mov ax,cs
mov ds,ax
mov es,ax
; Clear screen
mov ax,0003h
int 10h
; Remove cursor
mov ah,02h
mov bh,00h
mov dx,2000h
int 10h
; talk to user :)
sub di,di
add di,0148h
lea si,msg1
call message
reset: ; Reset the floppy drive
mov ax,00h
mov dl,00h
int 13h
jc reset
read:
mov ax,3000h
mov es,ax
mov bx,00h
mov ah,02h
mov al,01h
mov ch,00h
mov cl,02h
mov dh,00h
mov dl,00h
int 13h
jc disk_error
mov ax,3000h
mov ds,ax
mov ax,0b800h
mov es,ax
mov si,00h
; wait for key press
mov ax,00h
int 16h
sub di,di
mov cx,0400h
output_loop:
mov al,[si]
call putchar
inc si
loop output_loop
; wait for key press
mov ax,00h
int 16h
; WHY DOES THIS NOT WORK ???
; change cs to 3000
; mov ax,3000h
; dw 08ec8h
; jmp to 3000:0000, where we loaded program
db 0eah
dd 030000000h
disk_error:
sub di,di
add di,0148h
lea si,err1
call message
; wait for key
mov ax,00h
int 16h
; reboot system
mov ax,0040h
mov es,ax
mov es:0072h,1234h
db 0eah
dd 0ffff0000h
; Dump ds:si msg to screen
message:
push ax
push es
mov ax,0b800h
mov es,ax
messageloop:
lodsb
or al,al
jz messagedone
call putchar
jmp messageloop
messagedone:
pop es
pop ax
ret
; put character (in vid. mem)
putchar:
mov es:[di],al
inc di
inc di
ret
; boot sig.
org 510
dw 0aa55h
code ends
end program
I want the code segment (CS) to be where the program is in memory, but when I try to change it (the code commented out below 'WHY DOESN'T...'), it screws up and just reboots. Why does it do this? Does anyone know what I should do?
Adonai.