flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Question about int 13h

Author
Thread Post new topic Reply to topic
Giedrius



Joined: 13 Feb 2005
Posts: 40
Location: Lithuania
Giedrius 11 Mar 2006, 07:33
I have this code for my boot loader:
Code:
org 0x7C00

use16

xor ax,ax
mov dx,ax
mov es,ax
mov ss,ax
mov sp,0x7C00

mov ah,2
mov al,1

mov bx,ax

mov cl,1
mov ch,0
mov dh,0
mov dl,0

int 0x13

jmp 0000:0000

times 510-($-$$) db 0x00
dw 0xAA55

org 0x0000

kernel_start:

xor ax,ax
mov dx,ax

mov si,string
call write_str

cli
hlt

write_str:
  mov ah,0x0E
  mov bh,0x00
  mov bl,0x17
  .nextchar:
    lodsb

    or al,al
    jz .return
    int 0x10
    jmp .nextchar
    .return:
    ret

string db 'Hello',13,10,0

times 512-($-kernel_start) db 0x00    
What I want to do is to make the boot loader very simple, it should load 1 sector (or more) after the MBR and execute it. I don't want to have any file system yet. My code isn't working on bochs, it seems that it gets stuck. And I don't know how to dump the memory of it, so I could check if the second sector is written to the memory. I think that there must be something wrong with the int 13h or with the jump. The code after the jump should work normally, I tested it seperately.

_________________
Better to rule in hell, than to be a slave in heaven...
Post 11 Mar 2006, 07:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 11 Mar 2006, 10:52
At first sight: you put the code at address 0, where the real mode IDT usually resides. The interrupts won't work then, and any interrupt will cause the system to crash. You can put the CLI at the very beginning of loader to avoid it, but you cannot use the INT 10h then in your code (since you have sucessfully destroyed the interrupt table by writing this code there). So there are two options: either forget the interrupts at all, put the CLI at the beginning of loader and replace calls to INT 10h with writes to 0B800h segment; OR choose some memory area for your code that is not used by interrupt table or BIOS already.
Post 11 Mar 2006, 10:52
View user's profile Send private message Visit poster's website Reply with quote
Giedrius



Joined: 13 Feb 2005
Posts: 40
Location: Lithuania
Giedrius 11 Mar 2006, 10:58
Thanks for your reply. Could you advice me at which location to put the code? What memory locations are used by the system?
Post 11 Mar 2006, 10:58
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 11 Mar 2006, 11:09
You can look at the MEMORY.LST file from Ralph Brown's Interrupt List (it's in inter61c.zip) to find out what memory areas are usually used for what purposes. As you can find there out, DOS usually used the 0060h:0000h or 0070h:0000h addresses for loading its code at startup - so you may try those.
Post 11 Mar 2006, 11:09
View user's profile Send private message Visit poster's website Reply with quote
Giedrius



Joined: 13 Feb 2005
Posts: 40
Location: Lithuania
Giedrius 11 Mar 2006, 13:37
Could you edit my code, so it reads the code to 0060h:0000h and jumps to it? I'm having a problem with understanding the memory managment...
Post 11 Mar 2006, 13:37
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 11 Mar 2006, 13:46
well, use a jmp 0060:0000 instead of jmp 0000:0000 Wink
and I suggest you put your kernel in another file, and put something like ORG 0000h, and load some the required segment registers with 0060.

Though, you need to read the sectors off the floppy in that 0060 area before you jump. (try int 0x10 with ah=02h function. see Ralph Brown's list)

About you being not experienced in memory management: i strongly suggest you learn a bit more. Designing an OS requires a solid knowledge of memory management, believe me. Wink
Post 11 Mar 2006, 13:46
View user's profile Send private message Reply with quote
doubletoker



Joined: 15 Mar 2005
Posts: 4
doubletoker 15 Mar 2006, 16:00
the problem I see is that you overwrite some of the IVT, the way int 13 works is it transfers data from the chs to es:bx and right before you called it, you ran this code

Code:
mov ah,2
mov al,1

mov bx,ax    


which would write the sector to 0x00000201h in memory, a good thing is you didn't over write int 13 or 10 so you could still use it, anyway after you load it at that address you jump to address 0 which you didn't load it at 0 like you thought, like said before the first memory address 600h segment 60h is the first place application ram starts at, which is a good loading point bx = 0 and es = 60h

-pz
Post 15 Mar 2006, 16:00
View user's profile Send private message Reply with quote
Giedrius



Joined: 13 Feb 2005
Posts: 40
Location: Lithuania
Giedrius 16 Mar 2006, 12:01
Can somebody alter my code, so it works? I can't get it to work :/ I probably need some working code examples. The FAT12 loader from the site is a bit too complex for me.
Post 16 Mar 2006, 12:01
View user's profile Send private message Reply with quote
log(21



Joined: 09 Jun 2006
Posts: 6
log(21 09 Jun 2006, 23:05
Try this code. (I have written a loader, I'm not at the computer with it currently, but this code should work):



org 0x7C00

push cs
pop ds

mov ah, 02h ;Set for reading
mov al, 1 ;Number of sectors to load
mov cl,1 ;Starting sector
mov ch,0 ;Cylinder number
mov dh,0 ;Head number
mov dl,0 ;Drive number

;Set data segment for reading
mov bx, 0600h
mov es, bx
mov bx, 0

int 0x13 ;Read the sector(s)

jmp 0600:0000 ;Kernal is loaded at 0600h:0000h
Post 09 Jun 2006, 23:05
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 10 Jun 2006, 00:14
Code:
org 0x7C00

use16 

xor ax, ax
cli
mov ss, ax
mov sp, $7C00
sti
mov ds, ax

mov ah,2
mov al,1
mov bx, 0600h
mov cl,2  ; LOAD THE NEXT SECTOR!!!
mov ch,0 
mov dh,0 
mov dl,80h

int 0x13 

jmp $0060:kernel_start

times 510-($-$$) db 0x00
dw 0xAA55

org 0x0000

kernel_start:
push cs
push cs
push ss
pop  es
pop  ds
cli
pop ss
xor sp, sp
sti

xor ax,ax 
mov dx,ax 

mov si,string 
call write_str 

cli 
hlt 

write_str: 
  mov ah,0x0E 
  mov bh,0x00 
  mov bl,0x17 
  .nextchar: 
    lodsb 

    or al,al 
    jz .return 
    int 0x10 
    jmp .nextchar 
    .return: 
    ret 

string db 'Hello',13,10,0 

times 512-($-kernel_start) db 0x00    

Works in QEMU

Regards
Post 10 Jun 2006, 00:14
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.