Jump to content

Int 13h ah=02h

- - - - -

  • Please log in to reply
6 replies to this topic

#1
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
Hey everyone,

I started asm programming a while back and i' m trying to drop the OS routines and go closer to te basic routine.
Now i' m trying make a bootloader, it was going quite good until i tried leaving the bootsector by loading the rest of the floppy to the memory.
I'm trying to load the second to the eight sector from the floppy to 0x7E00.
I'm using the following code:

   mov ax,07e0h
         mov es,ax
         mov dx,0000h
    
             mov ah, 0x02 
             mov al, 6h
             
             mov ch, 0h              
             mov cl, 2h
             mov dl,0h  
             int 0x13  
After witch i just call my normal print routine that worked before but the code seems to get stuck at the int 13h
I treid everything i could think about.

i' m running from a IMA floppy image in virtual box, usinf NASM on x86 real mode.

Tanx,

Joran

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Your problem is probably setting DL to 0. When your program boots, the first thing you should do is save DL in memory somewhere; the BIOS sets this to the drive you're booting from, which is not necessarily 0. Right before you load from the disk, reload DL from that spot you saved it in.

Also, you need to reset the disk controller before you do anything, again using the saved value of DL.

Let me know if you need an example.
sudo rm -rf /

#3
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
hi,

Tanx,

It helped.
I also found out that it crasht when i tried to set DS a few instructions earlier.
Dont know why, but i took it out and now it works and int 13h doesn' t even set the carry flag.
I looked at the mike OS bootloader for a example and every thing looks fine now.
The only thing is i tried to load at 07C0h:0200h (just after the bootloader) but when i try to jump to 0x7e00 or a label at the end of my code it doesn't seem to do anything.
A quick overiew:
[BITS 16]	
[ORG 0x7C00]	
	jmp short start
	nop	
... disk info ....
start:
cli
	
     ; create stack
          mov     ax, 0x0000
          mov     ss, ax
          mov     sp, 0xFFFF
    sti
	
	mov byte [bootdev], dl
	mov ax, 2
	call l2hts
				
	mov bx, 07C0h
	mov es, bx
	mov bx, 200h
	
	mov ah, 2			
	mov al, 1			
        pusha				


read_root_dir:
	popa				
	pusha


	stc			
	int 13h				


	jnc soi ; end of code
	call rfloppy		
	jnc read_root_dir


; shutdown to be sure no data is entered as code
MOV     AX,5301h
XOR     BX,BX
INT     15h


MOV     AX,530Eh
XOR     BX,BX
MOV     CX,0102h
INT     15h


MOV     AX,5307h
MOV     BX,0001h
MOV     CX,0003h
INT     15h	


rfloppy:
... reset floppy routine ...
	
l2hts:	 ;;mikeOS function that sets the registers for the now working INT 13h
	push bx
	push ax


	mov bx, ax			; Save logical sector


	mov dx, 0			; First the sector
	div word [SectorsPerTrack]
	add dl, 01h			; Physical sectors start at 1
	mov cl, dl			; Sectors belong in CL for int 13h
	mov ax, bx


	mov dx, 0			; Now calculate the head
	div word [SectorsPerTrack]
	mov dx, 0
	div word [NumHeads]
	mov dh, dl			; Head/side
	mov ch, al			; Track


	pop ax
	pop bx


	mov dl, byte [bootdev]		; Set correct device


	ret
		  
TIMES 510 - ($ - $$) db 0	
DW 0xAA55		


soi:
;Some nice code that worked before.


#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
This is in NASM format, but you'll get the idea

%define LOAD_SEGMENT    7e00h
%define LOAD_OFFSET     0000h


; ...loading code here...
; and then your last line of code is:


jmp     [load_addr]


; Now you put your data declarations here...
; as well as this:
load_addr:  dw  LOAD_OFFSET, LOAD_SEGMENT

For the %define you'll use the EQU, and the jump uses the segment and offset so I guess you'd have to put the long directive?
(And yes, the offset comes before the segment in memory. Don't forget that.)
sudo rm -rf /

#5
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
Tanx for all your help, i got it working now :-)

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Glad to hear that. Lemme know if you have other questions. Do you already enable A20?
sudo rm -rf /

#7
jorants

jorants

    Newbie

  • Members
  • Pip
  • 8 posts
No, not yet.
I first want to get the hang of some basic bios interupts by writing a few applications and a little kernel.
I just started assembly programming and i still have to get use to the main structure.
In time i will try to expand everything and than i will surley do so, but for now i'm quite happy in my 1MB world :-)
Tanx




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users