flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help with int 13h

Author
Thread Post new topic Reply to topic
xleelz



Joined: 12 Mar 2011
Posts: 86
Location: In Google Code Server... waiting for someone to download me
xleelz 06 Jun 2011, 17:03
I'm trying to make a simple boot loader, the only job is to load the kernel and nothing else. It doesn't really work...

The code for it:
Code:
use16
org 0

jmp boot
nop

boot:
 mov ax,cs
   mov ds,ax
   mov es,ax
   
    mov [bootdev],dl
    mov eax,0
   
readkern:
   mov ax,1000h
        mov es,ax
   mov bx,0
    
    mov ah,2
    mov al,1
    mov ch,0
    mov cl,2
    mov dh,0
    mov dl,[bootdev]
    
    int 13h
     jnc done
    call reset
  jnc readkern
        mov si,error_msg
    call print
  jmp reboot

done:
 jmp 1000h:0000

;------------------------------------------;
bootdev db 0
error_msg db 0dh,0ah,"Kernel Loading Error... Press <enter> to reboot",0
;------------------------------------------;




reboot:
   mov ah,00h
  int 16h
     cmp al,0dh
  je rbz
      jmp reboot
rbz:
      jmp 0xFFFF:0000

print:
       lodsb
       cmp al,0
    jne phelp
   ret
phelp:
   mov ah,0eh
  jmp print

reset:
 push ax
     push dx
     mov ax,0
    mov dl, byte[bootdev]
       stc
 int 13h
     pop dx
      pop ax
      ret

times 510-($-$$) db 0
dw 0AA55h    


I'm still a noob at this, is there something I'm missing?

_________________
The person you don't know is the person that could help you the most... or rape you, whichever they prefer.
Post 06 Jun 2011, 17:03
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 06 Jun 2011, 17:23
Try this:
Code:
boot:
  mov ax,7C0h
  cli
  mov ss,ax
  mov sp,8400h
  sti
  cld
  mov ds,ax
  mov [bootdev],dl
  ...
phelp:
  mov bx,7
  mov ah,0eh
  int 10h
  jmp print 
  ...
    
Post 06 Jun 2011, 17:23
View user's profile Send private message Reply with quote
xleelz



Joined: 12 Mar 2011
Posts: 86
Location: In Google Code Server... waiting for someone to download me
xleelz 06 Jun 2011, 17:51
egos wrote:
Try this:
Code:
boot:
  mov ax,7C0h
  cli
  mov ss,ax
  mov sp,8400h
  sti
  cld
  mov ds,ax
  mov [bootdev],dl
  ...
phelp:
  mov bx,7
  mov ah,0eh
  int 10h
  jmp print 
  ...
    


Thanks, I tried it but it still doesn't work. It always goes into reboot: when I run it in qemu and it never prints anything to the screen.

_________________
The person you don't know is the person that could help you the most... or rape you, whichever they prefer.
Post 06 Jun 2011, 17:51
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 07 Jun 2011, 07:22
xleelz wrote:
I'm trying to make a simple boot loader, the only job is to load the kernel and nothing else. It doesn't really work...

The code for it:
Code:
use16
org 0

jmp boot
nop

boot:
  mov ax,cs
   mov ds,ax
   mov es,ax
   
    mov [bootdev],dl
    mov eax,0
   
readkern:
   mov ax,1000h
        mov es,ax
   mov bx,0
    
    mov ah,2
    mov al,1
    mov ch,0
    mov cl,2
    mov dh,0
    mov dl,[bootdev]
    
    int 13h
     jnc done
    call reset
  jnc readkern
        mov si,error_msg
    call print
  jmp reboot

done:
 jmp 1000h:0000

;------------------------------------------;
bootdev db 0
error_msg db 0dh,0ah,"Kernel Loading Error... Press <enter> to reboot",0
;------------------------------------------;




reboot:
   mov ah,00h
  int 16h
     cmp al,0dh
  je rbz
      jmp reboot
rbz:
      jmp 0xFFFF:0000

print:
       lodsb
       cmp al,0
    jne phelp
   ret
phelp:
   mov ah,0eh
  jmp print

reset:
 push ax
     push dx
     mov ax,0
    mov dl, byte[bootdev]
       stc
 int 13h
     pop dx
      pop ax
      ret

times 510-($-$$) db 0
dw 0AA55h    


I'm still a noob at this, is there something I'm missing?

Try "mov dl, 0" in your routine. Also instead of setting up es and ds, try just setting org to 7c00h. Hope I helped Smile
Post 07 Jun 2011, 07:22
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 07 Jun 2011, 07:57
here is some part of mine:
Code:
        USE16
        ORG 7C00h

        START1:

        jmp START

        DATASECT:

        DAP:
        DAP_Size             db 10h         ;1h
        DAP_Res1             db 0           ;2h
        DAP_Bytes2Transfer   db 1h          ;3h
        DAP_Res2             db 0           ;4h
        DAP_Buff_Addr1       dw 0h          ;6h
        DAP_Buff_Addr2       dw 8000h       ;8h
        DAP_LBA              dq 1h          ;9h

        DAT_Disk_Num         db 80h         ;12h          number of device 80h-winchester
        DAT_Num_Of_Sects     dw 03h         ;13h          the number of 512byte sectors, that contain your kernel your kernel

        END_DAP:

        END_DATASECT:

        ERROR:
        nop
        jmp ERROR

        START:

        REG_LOAD:
        mov bp, START1
        mov ax, cs
        mov ds, ax
        mov ss, ax
        mov sp, 7DFFh

        SECOND_STAGE_LOAD:                      ; service for reading data from disk specified DAT_Disk_Num
        mov ah, 42h
        xor al, al
        mov dl, [cs:bp+12h]
        mov si, DAP
        mov cx, [cs:bp+13h]

        READ_LOOP:
        pusha
        int 13h
        jc ERROR
        popa
        add word [ds:si+6h], 20h
        inc byte [ds:si+8h]
        loop READ_LOOP                          ;service ends here

        VIDEO_MODE_CHNG:                        ; serveice for setting up a video mode
        xor ah, ah
        mov al, 3h
        int 10h
        mov cx, 0B800h
        mov es, cx                              ; service ends here

        CLS:                                    ;service for clearing the screen
        mov cx, 2000d
        mov al, ''
        mov ah, 1Fh
        CLS_LOOP:
        mov si, cx
        add si, si
        mov word [es:si], ax
        loop CLS_LOOP                           ;service ends

        PASS_CONTROL:                           ; this shit passes control to second stage bootloader
        jmp 8000h:0000h                         ; bye bye first stage mbr

        FINISH:
        jmp FINISH

        times 410 db 0
        dw 0AA55h
                

it works OK
and IMO its better to use int 13h ah=42h, here some stuff:
http://www.ctyme.com/intr/rb-0708.htm
if you still wanna use ah 0 02h
http://www.ctyme.com/intr/rb-0607.htm

Good luck!

_________________
_______________________________
NSOS
Post 07 Jun 2011, 07:57
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 07 Jun 2011, 10:18
Quote:
Thanks, I tried it but it still doesn't work. It always goes into reboot: when I run it in qemu and it never prints anything to the screen.
It works in Bochs. Maybe code that has taken control is wrong. Or problem in Qemu.
Post 07 Jun 2011, 10:18
View user's profile Send private message Reply with quote
xleelz



Joined: 12 Mar 2011
Posts: 86
Location: In Google Code Server... waiting for someone to download me
xleelz 07 Jun 2011, 18:31
Well, I rewrote it, it's still pretty similar though, and still doesn't work but it's closer because it actually printed something this time Very Happy

New code:
Code:
use16
org 7C00h

boot:
   jmp start
   nop

OemName db "TestBoot"


start:
    push cs
     pop ds
      cli
 push cs
     pop ss
      mov sp,07FFFh
       sti

     mov [bootdev],dl


    
read:
       pusha
       xor ah,ah
   int 13h
     popa
        mov ax,1000h    
    mov es,ax
   xor bx,bx
   xor ax,ax       
    mov ah,02h
  mov al,1
    xor ch,ch
   mov cl,2
    mov dh,0
    mov dl,[bootdev]
    
    int 13h
     jnc done

        jmp reboot

done:
 jmp 0x1000:0000

reboot:
      xor esi,esi
 mov esi,rbmsg
       call print
  xor ah,ah
   int 16h
     cmp al,0dh
  je rbz
      jmp reboot
rbz:
      jmp 0xFFFF:0000



print:
       lodsb
       cmp al,0
    jne phelp
   ret
phelp:
   mov ah,0eh
  int 10h
     jmp print

;----------------------------------------;
bootdev db 0
rbmsg db 0dh,0ah,"ERROR LOADING KERNEL, PRESS <ENTER> TO REBOOT...",0
;----------------------------------------;

times 510-($-$$) db 0
dw 0AA55h    


and the kernel that I made, is just a test so it's extremely simple:
Code:
use16
org 0

main:
 xor ax,ax
   mov al,'>'
     mov ah,0eh
  int 10h

hltr:
    hlt
 jmp hltr
    



times 512-($-$$) db 0    


Starting to get a headache from this Shocked

_________________
The person you don't know is the person that could help you the most... or rape you, whichever they prefer.
Post 07 Jun 2011, 18:31
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 07 Jun 2011, 21:44
xleelz wrote:
Starting to get a headache from this

Hi xleelz,
The code in your first post works fine (simple errors notwithstanding).
The problem must be in building the image.
It's simple with FASM to assemble the entire image as one file:
Code:
org 7C00h
; boot sector code
  times 510-($-$$) db 0 
  dw 0AA55h
  
org 0 
; kernel code
  times 512-($-$$) db 0    

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 07 Jun 2011, 21:44
View user's profile Send private message Visit poster's website Reply with quote
xleelz



Joined: 12 Mar 2011
Posts: 86
Location: In Google Code Server... waiting for someone to download me
xleelz 07 Jun 2011, 22:13
Quote:

...assemble the entire image as one file...


Hah, thanks Mike! It works fine now
Post 07 Jun 2011, 22:13
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.