Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 6:52 pm



Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
 loading sector and jmp 
Author Message

Joined: Sat Sep 26, 2009 4:29 am
Posts: 15
Location: Philippines
Post loading sector and jmp
guys... i've already written a bootloader program.. loading sectors to the memory was fine..but nothing happens when i jmp to the address where i loaded sector....

here's the code(this is the mbr):
;-------------------------------------------------------------------------------------------
[bits 16]
[org 0x7c00]

start:
cli

call cls
mov [drv],dl

resetdisk:
mov ah,0
mov dl,[drv]
int 0x13
jc resetdisk

loadsector:
mov bx,0x7e00; 7c00 + 200
mov ax,0
mov es,ax ; 0000:7e00
mov ah,02
mov al,3 ;sector count
mov cl,2 ;sector start
mov ch,1;track1
mov dh,1 ;head
mov dl,[drv]
int 0x13
jc loadsector

jmp 0:0x7e00

cls:
; i already coded this part..
; this should move the cursor to 0,0 and set the video mode to 80x25,color
;and fill the screen with 0x20 character with fg:black bg:green attributes
ret


drv db 0
times 510-($-$$) db 0
dw 0xaa55
next:
;-----------------------------------------------------------------------------------------

this is the second sector:
;-----------------------------------------------------------------------------------------
[bits 16]
[org 0x7e00]
start:
lea si,msg1
call print
jmp $

print:
; i already coded this part..
; argument: si,string offset
;terminator is 0
ret

msg1 db 'Hello!',0

;------------------------------------------------------------------------------------------


supposedly this would display a 'Hello!' but all i see is the green screen!!!
could someone help me????
I also tried the PIO in loading the sector but its the same thing


Last edited by prinzrainer on Thu Oct 22, 2009 2:32 am, edited 2 times in total.



Wed Oct 21, 2009 3:35 am
Profile

Joined: Sat Jul 25, 2009 9:15 am
Posts: 257
Post Re: loading sector and jmp
off the top of my head maybe you are not reading the right sectors??
sector number starts at 1
but track and head start at 0

ball park calculations you are reading sector 55 if [drv] were a floppy


Wed Oct 21, 2009 8:20 am
Profile

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post Re: loading sector and jmp
This may be a newb reply, but are you jumping to the right location?

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Wed Oct 21, 2009 10:20 am
Profile

Joined: Sat Sep 26, 2009 4:29 am
Posts: 15
Location: Philippines
Post Re: loading sector and jmp
so it should be
-----------------------------------
mov bx,0x7e00; 7c00 + 200
mov ax,0
mov es,ax; 0000:7e00
mov ah,02
mov al,3 ;sector count
mov cl,2 ;sector start
mov ch,0;track1
mov dh,0 ;head
mov dl,[drv]
int 0x13
-----------------------------------
???
I guess i am jmping to a correct location, isn't it?


Last edited by prinzrainer on Thu Oct 22, 2009 12:55 am, edited 1 time in total.



Wed Oct 21, 2009 11:33 pm
Profile

Joined: Sat Sep 26, 2009 4:29 am
Posts: 15
Location: Philippines
Post Re: loading sector and jmp
ALSO bochs issued an error.... like RIP > CS.limit...........what does it mean?


Thu Oct 22, 2009 12:46 am
Profile

Joined: Sat Jul 25, 2009 11:26 am
Posts: 81
Post Re: loading sector and jmp
No offense, but I suggest you use somebody else's code :)

First of all, use CODE tags if you don't want your post to look all messy as it does. Now let's analyze your code. I made comments everywhere just to point out you need reasons to actually write stuff. You'll see as your OS grows bigger that you can't afford to write sloppy code. It'll be buggy, big and slow.

Code:
[bits 16] ; THIS IS DEFAULT IN NASM
[org 0x7c00] ; ALSO WHY DO YOU KEEP USING BRACKETS?

start: ; WHY DID YOU DEFINE THIS LABEL?
cli ; WHY DO YOU DISABLE INTERRUPTS HERE?
mov [drv],dl ; WHY DO YOU NEED TO DO THIS?

resetdisk: ; YOU KNOW WHY YOU'RE RECALIBRATING?
mov ah,0
mov dl,[drv] ; DL ALREADY HAS THAT VALUE
int 0x13
jc resetdisk ; YOU LIKE INFINITE LOOPS INSTEAD OF ERROR MESSAGES?

loadsector:
mov bx,0x7e00; 7c00 + 200
mov ax,0 ; NO ONE DOES THIS. "XOR AX, AX" SAVES YOU ONE BYTE
mov es,ax; 0000:7e00
mov ah,02 ; WHY DON'T YOU SET AX INSTEAD OF WASTING MEMORY AND CYCLES FOR BOTH AH AND AL?
mov al,3 ;sector count
mov cl,2 ;sector start
mov ch,0;track1
mov dh,0 ;head
mov dl,[drv] ; AGAIN, YOU HAVEN'T CHANGED DL. KEEP TRACK OF REGISTERS!
int 0x13
jc loadsector ; SAME COMMENT AS ABOVE

jmp 0:0x7e00 ; WHY THE *FAR* JUMP?

cls:
; i already coded this part..
; this should move the cursor to 0,0 and set the video mode to 80x25,color
;and fill the screen with 0x20 character with fg:black bg:green attributes
ret
; - YES, WHATEVER. YOU DON'T EVEN CALL IT.

drv db 0
times 510-($-$$) db 0
dw 0xaa55
next: ; NEXT?


Code:
[bits 16]
[org 0x7e00]
start:
lea si,msg1 ; WEIRD USE OF LEA
call print
jmp $ ; YOUR FLOPPY MOTOR IS STILL ON FROM SINCE MASKING THE IRQs, BTW

print:
; i already coded this part..
; argument: si,string offset
;terminator is 0
ret

msg1 db 'Hello!',0


You want us to debug it and you don't show us the code? My guess is that you don't take into account the fact that in VGA A/N modes you get 2 bytes per character. One for attribute, one for the actual character. Also, you have BIOS functions that will already print stuff (either just one character or an entire string).

Bochs is showing you that cause you're executing random crap :twisted:

Cheers,
Bogdan


Thu Oct 22, 2009 1:32 am
Profile

Joined: Sat Sep 26, 2009 4:29 am
Posts: 15
Location: Philippines
Post Re: loading sector and jmp
Love4Boobies wrote:
No offense, but I suggest you use somebody else's code :)

First of all, use CODE tags if you don't want your post to look all messy as it does. Now let's analyze your code. I made comments everywhere just to point out you need reasons to actually write stuff. You'll see as your OS grows bigger that you can't afford to write sloppy code. It'll be buggy, big and slow.

Code:
[bits 16] ; THIS IS DEFAULT IN NASM
[org 0x7c00] ; ALSO WHY DO YOU KEEP USING BRACKETS?

start: ; WHY DID YOU DEFINE THIS LABEL?
cli ; WHY DO YOU DISABLE INTERRUPTS HERE?
mov [drv],dl ; WHY DO YOU NEED TO DO THIS?

resetdisk: ; YOU KNOW WHY YOU'RE RECALIBRATING?
mov ah,0
mov dl,[drv] ; DL ALREADY HAS THAT VALUE
int 0x13
jc resetdisk ; YOU LIKE INFINITE LOOPS INSTEAD OF ERROR MESSAGES?

loadsector:
mov bx,0x7e00; 7c00 + 200
mov ax,0 ; NO ONE DOES THIS. "XOR AX, AX" SAVES YOU ONE BYTE
mov es,ax; 0000:7e00
mov ah,02 ; WHY DON'T YOU SET AX INSTEAD OF WASTING MEMORY AND CYCLES FOR BOTH AH AND AL?
mov al,3 ;sector count
mov cl,2 ;sector start
mov ch,0;track1
mov dh,0 ;head
mov dl,[drv] ; AGAIN, YOU HAVEN'T CHANGED DL. KEEP TRACK OF REGISTERS!
int 0x13
jc loadsector ; SAME COMMENT AS ABOVE

jmp 0:0x7e00 ; WHY THE *FAR* JUMP?

cls:
; i already coded this part..
; this should move the cursor to 0,0 and set the video mode to 80x25,color
;and fill the screen with 0x20 character with fg:black bg:green attributes
ret
; - YES, WHATEVER. YOU DON'T EVEN CALL IT.

drv db 0
times 510-($-$$) db 0
dw 0xaa55
next: ; NEXT?


Code:
[bits 16]
[org 0x7e00]
start:
lea si,msg1 ; WEIRD USE OF LEA
call print
jmp $ ; YOUR FLOPPY MOTOR IS STILL ON FROM SINCE MASKING THE IRQs, BTW

print:
; i already coded this part..
; argument: si,string offset
;terminator is 0
ret

msg1 db 'Hello!',0


You want us to debug it and you don't show us the code? My guess is that you don't take into account the fact that in VGA A/N modes you get 2 bytes per character. One for attribute, one for the actual character. Also, you have BIOS functions that will already print stuff (either just one character or an entire string).

Bochs is showing you that cause you're executing random crap :twisted:

Cheers,
Bogdan


shuddup!!! Ur not even answering my questions... Okay I coded it in an internet cafe (there's no time in optimizing the code ) but I already have the optimized code in my PC the thing is we lose our internet connection, maybe next day it will be back... I'll show it to you next time...


Thu Oct 22, 2009 2:31 am
Profile

Joined: Sat Jul 25, 2009 9:41 am
Posts: 58
Post Re: loading sector and jmp
Now now, he was helping you by going through your code ...


Thu Oct 22, 2009 10:40 am
Profile

Joined: Sat Jul 25, 2009 11:26 am
Posts: 81
Post Re: loading sector and jmp
Arrowofdarkness wrote:
Now now, he was helping you by going through your code ...


It's okay, I don't think he was really pissed :)

The thing is, if you don't show us what's inside those procedure calls we can't tell if they actually return (nor why print doesn't actually print text on the screen).


Thu Oct 22, 2009 11:12 am
Profile

Joined: Sat Sep 26, 2009 4:29 am
Posts: 15
Location: Philippines
Post Re: loading sector and jmp
I already solved the problem..... DudeOfX is right..cylinder and head starts from 0..

here's my code:
(put this one in the first sector)

Code:

[BITS 16]
[org 0x7c00]   ;I want the square brackets =p

cli      ; Disable IRQ

mov ax,0x7c0   ; Setup stack
mov ss,ax           ; ss=0x7c0[0]
mov sp,stack   ; 0x7c0:stack

mov [drv],dl   ; Save the drive number which it has booted from

call cls   ;note dx is used in this function

push byte 0   ;push byte for temporary_variable
mov bp,sp   ;point to temporary_variable

loadsector:
cmp byte[ss:bp],3;is it the 3rd attempt to load sector?
je loadfail   ;if IT IS jmp loadfail
inc byte[ss:bp]   ;++temporary_variable

xor ax,ax   ;
mov es,ax   ;
mov ax,0x0201   ;load 1 sector from
mov cx,0x0002   ;cylinder:0 sector:2
mov dh,0   ;head:0
mov dl,[drv]
mov bx,0x7e00   ;to 0:0x7e00 (directly above where the mbr is loaded)
int 0x13
jc loadsector
inc sp      ;discard temporary_variable

lea si,[msgok]
call print

jmp next

loadfail:
lea si,[msgerr]
call print
jmp $

cls:
mov ax,0x0003   ;set video mode to color 25x80
int 0x10   ;
mov ah,0x02   ;move cursor
mov bh,0   ;page=0
xor dx,dx   ;row=0 col=0
int 0x10   ;
mov ax,0x0920   ;display char, 0x20 - space
mov bx,0x0020   ;page=0,attrib=20,bg: green fg:black
mov cx,2000   ;fill up the whole screen
int 0x10
ret

print:
mov ah,0x0e   ;display char and advance cursor
printx:
cmp byte[si],0   ;is byte[si] == 0?
je printx_exit   ;if TRUE terminate loop
mov al,[si]   ;display byte[si]
int 0x10   ;
inc si      ;move to next character
jmp printx   ;loop
printx_exit:   ;
ret


resb 0x20   ;reserve 32 bytes for stack
stack:

msgerr    db 'Error in loading sectors!!',0
msgok    db 'Sectors loaded!!',0
drv   db 0

times 510-($-$$) db 0   ;Fill the rest with 0
dw 0xAA55      ;boot signature
next:         ;0:0x7e00


( and this at the second sector )

Code:

[BITS 16]
[org 0x7e00]   ;I want the square brackets =p

lea si,[msg1]
call print
jmp $


print:
mov ah,0x0e   ;display char and advance cursor
printx:
cmp byte[si],0   ;is byte[si] == 0?
je printx_exit   ;if TRUE terminate loop
mov al,[si]   ;display byte[si]
int 0x10   ;
inc si      ;move to next character
jmp printx   ;loop
printx_exit:   ;
ret

msg1 db 'Hello World!!',0



Thu Oct 22, 2009 8:54 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.