flat assembler
Message board for the users of flat assembler.

Index > OS Construction > BIOS-Ints

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
hello,

I wrote an driver to write a file on a disk with my own FS. Now I have two problems. The first is, that the code works only after the second time executing him, I don't know, why! The first time, the sector to write isn't written. The second problem is, that the code writes always only the first sector, and not the others, but the coordinates of the part to write is right!
I use Bochs, to test my code.

here it is:

Code:
write:
mov si,write_text
mov ah,0x01
int 0x21
;take the name of the file with my own int
mov di,file_name
mov ah,0x04
int 0x21
write_write_in_dir:
;start writing it at the end of the file-list
;RESET
push es
push ds
mov ax,0x00
mov dl,0x00
int 13h
;read the filelist
mov ax,0x290
mov es,ax
mov bx,0x00
mov ch,0x00
mov cl,0x07
mov dh,0x01
mov dl,0x00
mov al,0x0D
mov ah,0x02
int 0x13
jc write_write_in_dir
;Ende finden
mov ax,0x290
mov es,ax
mov ds,ax
xor ax,ax
mov si,ax
mov di,ax

write_find_dir_end:
lodsb
cmp al,0xFF
jne write_find_dir_end
dec si
mov di,si
mov cx,0x0D
mov ax,ds
mov es,ax
mov ax,0x50
mov ds,ax
mov si,file_name
mov al,0xFE
stosb
write_name_loop:
lodsb
stosb
loop write_name_loop

dec si
dec di


mov ah,0x03
mov al,0x0D
mov ch,0x00
mov cl,0x07
mov dh,0x01
mov dl,0x00
int 0x13


mov ax,es
mov ds,ax
mov si,di

mov ax,0x50
mov es,ax
mov ds,ax

mov [tes],WORD 0x290
mov [tds],WORD 0x290
mov [tsi],si                   ;save the coordinates of the end of the filelist
mov [tdi],di

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

mov ax,0x50
mov ds,ax
mov es,ax                     
mov si,write_inhalt
mov ah,0x01
int 0x21

mov ax,0x530           ;ES:BX = 530
mov es,ax
mov ds,ax
xor ax,ax                     ;initialise the regs for taking the content
mov di,ax
mov si,ax

write_get_file:

mov ah,0x07             ;wait for a keypressing by an own int 
int 0x21

cmp ah,0x01
jz esc_pressed          ;if esc, jump
cmp ah,0x0E
jz near write_back      ;if back, jump
write_back_back:
cmp ah,0x1C
jz near write_enter          ;if enter, jumo
stosb                   
write_enter_back:
mov ah,0x03             ;print the inputed char by an own int
int 0x21
jmp write_get_file
esc_pressed:
mov al,0x00
stosb                   ;an 0 to the end of the content

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

mov ax,0x8F40      ;start reading the table, where is written, if some sectors are empty
mov es,ax
mov ds,ax
mov ax,0x0206      ;set params
xor bx,bx          ;   *
mov cx,0001        ;   *
mov dx,0x0100      ;   *
int 0x13           ;   *

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

mov ax,0x530
mov es,ax
mov ds,ax                 ;set params, to get the lenght of the content with an own int; lenght is in ax

xor si,si
xor di,di

xor dx,dx
mov ah,0x0A
int 0x21

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


mov bx,0x200
div bx
inc ax

mov cx,ax
xor bx,bx                     ;bx = number of runnings; cx = number of sectors to find
mov [tmpw1],cx
xor si,si
xor di,di
mov [ssi],si
mov [sdi],di

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,

write_sector_find_and_write_loop:

mov [tmpw2],cx

mov cx,[tmpw1]
sub cx,[tmpw2]
mov [tmpw3],cx

mov cx,[tmpw2]

mov ax,0x8F40
mov es,ax
mov ds,ax

mov ax,[ssi]
mov si,ax
mov ax,[sdi]
mov di,ax

lodsb

push ax
mov ax,si
mov [ssi],ax
mov ax,si
mov [sdi],ax
mov bx,ax
pop ax

cmp al,0x00
jz near write_sector_found
write_sector_back:
cmp al,0xFF
jz near write_sector_not_found

loop write_sector_find_and_write_loop

mov ax,0x8F40
mov es,ax
mov ds,ax
xor bx,bx

mov ah,0x03
mov al,0x06
mov ch,0x00           ;save the sectorlist
mov cl,0x01
mov dh,0x01
mov dl,0x00

int 0x13

mov ax,0x50
mov es,ax
mov ds,ax
mov si,[tsi]
mov di,[tdi]

mov ax,0x290
mov es,ax
mov ds,ax

mov al,0xFF
stosb

xor si,si
xor di,di
xor bx,bx

mov ah,0x03
mov al,0x0D
mov ch,0x00               ;save filelist
mov cl,0x07
mov dh,0x01
mov dl,0x00

int 0x13

pop ds
pop es
jmp _main





write_enter:
mov al,0x0E
stosb
mov al,0x0A
jmp write_enter_back

write_back:
inc cx
jmp write_back_back

write_sector_found:

push ax
push bx
push cx
push dx

mov al,0xFF
stosb
mov ax,0x50
mov es,ax
mov ds,ax
xor dx,dx
mov ax,bx
mov cx,0x5A0
div cx
mov [tmpb1],al  ;HEAD
sub bx,ax
xor dx,dx
mov ax,bx
mov cl,0x12
div cl
mov [tmpb2],al  ;TRACK
mov [tmpb3],ah  ;SEKTOR

mov ax,0x50
mov ds,ax
mov es,ax
mov si,[tsi]
mov di,[tdi]
mov es,[tes]
mov ds,[tds]

mov ax,0x50
mov ds,ax
mov es,ax
xor ah,ah
mov al,[tmpb1]
mov es,[tes]
mov ds,[tds]
stosb
mov ax,0x50
mov ds,ax
mov es,ax
xor ah,ah
mov al,[tmpb2]
mov es,[tes]
mov ds,[tds]
stosb
mov ax,0x50
mov ds,ax
mov es,ax
xor ah,ah
mov al,[tmpb3]
mov es,[tes]
mov ds,[tds]
stosb

mov ax,0x50
mov ds,ax
mov es,ax
mov [tsi],si
mov [tdi],di


push cx
;-----------------------------------------------
push bx
mov ax,0x200
mov cx,[tmpw3]
mul cx
mov bx,ax
mov ax,0x50
mov es,ax
mov ds,ax
mov ch,[tmpb2]
mov cl,[tmpb3]              ;this is the part, where the sector is written!
mov dh,[tmpb1]            ;it runs not right!
mov ax,0x530
mov es,ax
mov ds,ax
mov ah,0x03
mov al,0x01
mov dl,0x00

call dump_regs

int 0x13
;-----------------------------------------------------------
pop bx

pop cx

pop dx
pop cx
pop bx
pop ax

inc bx
jmp write_sector_back

write_sector_not_found:
inc bx
jmp write_sector_find_and_write_loop






dump_regs:
pusha
push si
push ds
push bx
push ax

mov al,0x0A
mov ah,0x03
int 0x21

mov ax,0x50
mov ds,ax
mov ah,0x01
mov si,ax_reg
int 0x21
pop ax
mov bx,ax
mov ah,0x02
int 0x21
mov si,bx_reg
mov ah,0x01
int 0x21
mov ah,0x02
pop bx
int 0x21
mov si,cx_reg
mov ah,0x01
int 0x21
mov ah,0x02
mov bx,cx
int 0x21
mov ah,0x01
mov si,dx_reg
int 0x21
mov ah,0x02
mov bx,dx
int 0x21

mov al,0x0A
mov ah,0x03
int 0x21

mov ah,0x01
mov si,es_reg
int 0x21
mov bx,es
mov ah,0x02
int 0x21
mov ah,0x01
mov si,di_reg
int 0x21
mov bx,di
mov ah,0x02
int 0x21
mov ah,0x01
mov si,ds_reg
int 0x21
pop ds
mov bx,ds
mov ah,0x02
int 0x21
mov ax,0x50
mov ds,ax
mov ah,0x01
mov si,si_reg
int 0x21
pop si
mov bx,si
mov ah,0x02
int 0x21
mov al,0x0A
mov ah,0x03
int 0x21
mov ah,0x07
int 0x21

mov al,0x0A
mov ah,0x03
int 0x21

popa
ret        
    


It's very long, but I hope, someone may help me!
Post 06 Nov 2004, 19:04
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
i recently wrote some functions using bios to access hadr disks,
here goes,
its not completed as you seee some functions are under interpretation.
hope it helps if you got problems with bios routines.


Description: Disk handling functions
Download
Filename: diskread.zip
Filesize: 10.18 KB
Downloaded: 290 Time(s)

Post 06 Nov 2004, 19:24
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
no, I think, I set all the parameter of the BIOS-Ints right... But I don't know the differenz beetween the first running of the Code, and the second.
Post 07 Nov 2004, 00:13
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
Here is what i think.
1. write sector needs to be tryed 3 times, so you must try 3 writes.
but you do it only once, if it does not work by the third time read ah, error status.

The best way is read/write a sector at a time, inc sector and loop, check for sector is more than 18, if so make sector 1, also check if head is 0 or 1, if 0 then inc, if 1 dec and add 1 to track.
Read/write sector's can only be done if all sectors are on one track.
As i remember CL = start sector number, AL = number of sectors, up to a max for a track.
So by starting at sector 7 and doing 13 sectors = 20, only 18 sectors on a track.

But i would try it on a real pc, bochs is not too good with emulating these things.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Nov 2004, 04:08
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
And in my opinion, if sector reading on hard disk is not error less the first time, i whould set the bad sector flag Smile
as well as on floppy
of course user should be warned about this, and sector should be read retry times again, to make sure data is lost there.

when you're reading/writing more drives, you must issue the disk reset function each time changing drive, ( if i didn't do this data written from floppy to other floppy was 00 )
as well as first tme accessing the drive, you must issue disk reset command.

i have already used int 13h bios functions to raw read / write my 850 MB harddisk sectors, and it was completely working backup mirror of my drive's data, i could reload it and boot the drive.
Post 07 Nov 2004, 12:08
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
ok,

i put a 10-times-loop around my write-part, and a reset-command before it. there is still the problem! it still works only after the second time executing it. there is no error-code!
Post 07 Nov 2004, 12:48
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
ps: and i don't want to write a sector, which doesn't exist!!!
Post 07 Nov 2004, 12:50
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
why do you wanna get ds back from data segment indexed variable?

Code:
mov ds,[tds]
    


your code is a little unclear to me, but hope someone can help you.

however i saw this code:
Code:
write_name_loop:
lodsb
stosb
loop write_name_loop
    

i know this is not a problem in general, but i'd suggest to use this instead:
Code:
rep movsb
    
Post 07 Nov 2004, 14:00
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
@matrix: you're right, your idea is bether to copy the name. the

mov ds,[tds]

is, to save also the ds-register of the coordinates to write or read into the filelist.
Post 07 Nov 2004, 15:17
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
Have you try a real pc yet, bochs does things that real pc do not, like waiting for a int from commands, that do not need a int on a real pc, i have just written a pmode floppy driver for my OS and lots of people have trouble on bochs, but there code works fine on a real pc, i have not tyred my floppy on bochs, but if it works on bochs, i will after work on it some more Laughing.

If it still does not work on a real pc, try duping some regs etc, to see the difference between the first and second run or is that not what bochs is for.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Nov 2004, 16:16
View user's profile Send private message Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
i'l test it!
Post 07 Nov 2004, 18:25
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
now i have an other problem!!! it doesn't work in real!!! i think, it's because some sectors are broken, because every file-function doesn't work!!! i'll copy it on an other floppy, maybe there it works!
Post 09 Nov 2004, 13:26
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
well, after I implemented an error-output for my OS, now I know the misstake in running on the real PC. it's because he can't read the sector!!! that's absolutely unable! all the parameters are right! might it be, because there could be an broke sector? if I format the floppy, there comes, that 3 sectors are broken. might it be one of that 18 sectors? what do you think? what should I do?
Post 09 Nov 2004, 19:33
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
i don't know Smile
i use CD-R s instead of floppies, then i throw them away when i don't need them anymore.
i hate floppies, especilly when they destroy my important data.
Post 09 Nov 2004, 19:46
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
Try another floppy disk, format it first to see that all sector are OK, then try again,

PS: You many not have a good FS, but look on the bright side, you may have a very good file shredder Laughing.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 09 Nov 2004, 20:37
View user's profile Send private message Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
right, my FS isn't very good! it's constructed very simple, because I don't understand Fat and so on... @Matrix: always writing a new CD is also bad and expensive, and there I need an other bootsector and a driver, right?
Post 11 Nov 2004, 13:22
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
No,
i can make botcd with floppy disk emulation, with nero, or easycd creator,
you just select image file and software writes it on,
well, there are CD-RW disks, that can be formmatted many times, and made a boot floppy again Smile
CD-R s aren't tthat expensive, and if i use it as data storage for ex.:16 MB, then i can write again a few times replacing or adding data.
Post 11 Nov 2004, 14:12
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
that's right! I didn't calculate the replacings... But don't I need an special CD-driver? With CD-RW it's very good, but you talked about CD-Rs, so I did'nt calculate them, too...
Post 11 Nov 2004, 16:12
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
later bioses for example a bios on a Pentium I, supports boot from cd function, and then the CD or CD-RW will emulate an A: drive with 1.44MB, then youcan do whatever on your new A: drive, its fully compatible, loads @7c00h, or you can specify another location to nero for example Smile like 100h
Post 11 Nov 2004, 16:24
View user's profile Send private message Visit poster's website Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu
thank you for the information.
Post 11 Nov 2004, 16:57
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.