mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-25 16:16:50 +03:00
8f992ed021
git-svn-id: svn://kolibrios.org@1635 a494cfbc-eb01-0410-851d-a64ba20cac60
2094 lines
61 KiB
PHP
2094 lines
61 KiB
PHP
; Copyright (c) 2009, <Lrz>
|
|
; All rights reserved.
|
|
;
|
|
; Redistribution and use in source and binary forms, with or without
|
|
; modification, are permitted provided that the following conditions are met:
|
|
; * Redistributions of source code must retain the above copyright
|
|
; notice, this list of conditions and the following disclaimer.
|
|
; * Redistributions in binary form must reproduce the above copyright
|
|
; notice, this list of conditions and the following disclaimer in the
|
|
; documentation and/or other materials provided with the distribution.
|
|
; * Neither the name of the <organization> nor the
|
|
; names of its contributors may be used to endorse or promote products
|
|
; derived from this software without specific prior written permission.
|
|
;
|
|
; THIS SOFTWARE IS PROVIDED BY Alexey Teplov nickname <Lrz> ''AS IS'' AND ANY
|
|
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
|
|
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
;*****************************************************************************
|
|
|
|
; â ýòîé ñåêöèè èäåò ðàçáîð ïàðàìåòðîâ óêàçàòåëü íà ñåêöèþ õðàíèòüñÿ â point_default
|
|
;òèïû îøèáîê ïðè îáðàáîòêå ìàêðîñà
|
|
;Ìàêðîñ RamdiskFS
|
|
;/îïðåäåëåíèå ôëàãîâ â çàïèñè êîðíåâîé äèðåêòîðèè
|
|
ATTR_READ_ONLY equ 0x01
|
|
ATTR_HIDDEN equ 0x02
|
|
ATTR_SYSTEM equ 0x04
|
|
ATTR_VOLUME_ID equ 0x08
|
|
ATTR_DIRECTORY equ 0x10
|
|
ATTR_ARCHIVE equ 0x20
|
|
|
|
|
|
|
|
show_error_1 equ 0x1 ;êîí÷èëèñü äàííûå - íå çàïëàíèðîâàííûé êîíåö ñåêöèè
|
|
show_error_2 equ 0x2 ;íåò çàâåðøàþùåãî ñèìâîëà â ðàçìåðå ðàì äèñêà.
|
|
show_error_3 equ 0x4 ; ðàì äèñê áóäåò èìåòü ðàçìåð =64 êá.
|
|
show_error_4 equ 0x8 ;
|
|
|
|
macro use_parse_def_sect
|
|
{
|
|
mov di,point_default
|
|
push ini_data_
|
|
pop es
|
|
mov si,point_to_point_def
|
|
sub si,2
|
|
mov cx,[si] ;çàãðóçèì óêàçàòåëü íàñëåäóþùèþ ñåêöèþ
|
|
|
|
xor ax,ax ;îáíóëèì àx äëÿ î÷èñòêè ôëàãîâ
|
|
|
|
sub cx,di ;âîò òåïåðü èìååì èñòèíûé ðàçìåð
|
|
mov save_cx_d,cx ;ñîõðàíèì çíà÷åíèå cx ñâîåé ïåðåìåííîé
|
|
;îáíóëèì ïåðåìåííóþ ôëàãîâ, ýòî íåîáõîäèìî, äëÿ òîãî, ÷òî áû èçáåæàòü îáðàáîòêó ïîâòîðÿþùèõñÿ çíà÷åíèé
|
|
|
|
mov status_flag,ax
|
|
;;;;
|
|
;ÂÕîä â îáðàáîòêó ïàðñèíãà çíà÷åíèé ñåêöèé. es:di - óêàçàòåëü íà íà÷àëî ñåêöèè cx ðàçìåð ñåêöèè äîñòóïíîé äëÿ ïàðñèíãà
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;ñîãëàøåíèå íå ðàçðóøàåì bp, es, cs, sp
|
|
;use_Loader_Image ;çàãðóçèòü îáðàç âûøå 1 ìá
|
|
use_RamdiskFS
|
|
;ïðîâåðÿåòñÿ ñàìûé ïîñëåäíèé.
|
|
use_LoaderModule ;îñîáåííîñòü - ïåðåäàåò óïðàâëåíèå íà çàãðóæåííûé ìîäóëü.
|
|
}
|
|
|
|
macro use_LoaderModule
|
|
;êàê âàðèàíò ñåé÷àñ èñïîëüçóåòñÿ ìîäåëü, ïðè çàãðóçêå ìîäóëÿ íà íåãî ïåðåäàåòñÿ óïðàâëåíèå, ðåøåíèå âðåìåíîå
|
|
;óïðàâëåíèå áóäåò ïåðåäàâàòüñÿ òîëüêî ïîñëå îáðàáîòêè âñåé ñåêöèè
|
|
{
|
|
local .found_end_str
|
|
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
;îáðàáîòêà êîíñòðóêöèè òèïà LoaderModule=kord/kolibri.ldm
|
|
.start_p_LM:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz ._afterLoaderModule ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
cmp al,'L'
|
|
jnz .start_p_LM
|
|
;ïðîâåðêà íà çíà÷åíèå LoaderModule
|
|
; parse_LoaderModule
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_LoaderModule
|
|
mov cx,parse_LoaderModule_e - parse_LoaderModule
|
|
repe cmpsb
|
|
jnz .rest_value_loop_LM ;is not compare
|
|
|
|
sub bx,parse_LoaderModule_e - parse_LoaderModule ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
|
|
test status_flag,flag_found_LM ;îöåíêà ôëàãîâ
|
|
jz .correct_is_not_set_LM
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
.correct_is_not_set_LM:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
jcxz .rest_value_loop_LM ;not found param timeout
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .rest_value_loop_LM
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
;di óêàçûâàåò íà íà÷àëî áëîêà èíôîðìàöèè, â cx äëèííà äî êîíöà ñåêöèè.
|
|
;ïîñëå çàãðóçêè çàíîñèòüñÿ çíà÷åíèå çàíÿòîé ïàìÿòè.
|
|
;äëÿ òîãî ÷òî áû çàãðóçèòü ìîäóëü, âîñïîëüçóåìñÿ callback ñåðâèñîì
|
|
;îðèãèíàëüíîå ðåøåíèå - ðàçìåñòèì dd ïåðåä ñòðî÷êîé è ïîñëå ñòðî÷êè ðàçìåñòèì byte =0
|
|
;ýòî âûãëÿäèò òàê: â ini ôàéëå ñóùåñòâóåò ñòðî÷êà LoaderModule = kord/kernel.loader
|
|
;ìû åå ìîäèôèöèðóåì äî òàêîãî ñîñòîÿíèÿ dw,dw,db'kord/kernel.loader',0 êîíå÷íî ñîõðàíèâ òå çíà÷åíèÿ êîòîðûå ìû çàìåíÿåì
|
|
;ñîõðàíèëè ïåâûå 2 word
|
|
push dword [es:di-6]
|
|
lea si,[di-6]
|
|
|
|
push word [es:di-2]
|
|
xor ax,ax
|
|
mov word [es:di-6],ax ;âíîñèì íóæíûå çíà÷åíèÿ
|
|
;info_real_mode_size ðàçìåð è óêàçàòåëü íà îáëàñòü â êîòîðóþ ìîæíî çàãðóçèòüñÿ
|
|
mov ax,info_real_mode_size ;0x3000 ;ñëåäóþùèé ñåãìåíò çà äàííûìè
|
|
|
|
|
|
mov word [es:di-4],ax
|
|
mov word [es:di-2],16 ;êîë-âî áëîêîâ ïî 4 êá =64 êá ò.å. áîëüøå íå ñ÷èòàåì
|
|
;;;;;; ïîèñê êîíöà ñòðî÷êè
|
|
@@: mov al,byte [es:di]
|
|
cmp al,' '
|
|
jz .found_end_str
|
|
cmp al,0xa
|
|
jz .found_end_str
|
|
cmp al,0xd
|
|
jz .found_end_str
|
|
inc di
|
|
dec cx
|
|
jnz @b
|
|
;;;not found äîïóñòèì,÷òî ýòî êîíåö ôàéëà è îí íå èìååò ïðèâû÷íîãî çàâåðåøíèÿ ñòðîêè
|
|
.found_end_str:
|
|
|
|
push word [es:di]
|
|
xor ax,ax
|
|
mov word [es:di],ax
|
|
; xor ax,ax ; function 1 - read file
|
|
mov di,si ;file_data
|
|
inc ax
|
|
push si
|
|
push es
|
|
|
|
push es
|
|
pop ds
|
|
push cs
|
|
pop es
|
|
|
|
call far dword [es:loader_callback]
|
|
|
|
push cs
|
|
pop ds
|
|
|
|
pop es
|
|
pop si
|
|
|
|
test bx,bx
|
|
jnz .error_LM
|
|
|
|
|
|
jmp far dword [es:si]
|
|
|
|
|
|
.error_LM:
|
|
call error.LoaderModule
|
|
.rest_value_loop_LM:
|
|
mov di,ax
|
|
mov cx,bx
|
|
jmp .start_p_LM
|
|
|
|
._afterLoaderModule:
|
|
}
|
|
|
|
macro use_RamdiskFS
|
|
; ôîðìèðîâàíèå ðàì äèñêà, + îáðàáîòêà âñåãî ñâÿçàííîãî.
|
|
{
|
|
if DEBUG
|
|
local ._not_memory_in_sys
|
|
;//////// clear window
|
|
mov ax,3
|
|
int 0x10
|
|
;\\\\\\\\\ clear window is end
|
|
mov si,ramdiskFS_st
|
|
call printplain
|
|
end if
|
|
; îáíóëèì ðåãèñòð ñîñòîÿíèÿ îøèáîê
|
|
xor ax,ax
|
|
mov show_errors_sect,ax
|
|
use_free_memory ; óçíàåì êàêîãî îáúåìà ó íàñ äîñòóïíà ïàìÿòü. çíà÷åíèå âîçàðàùàåòñÿ â ax
|
|
;óçíàåì ñêîëüêî ó íàñ åñòü ïàìÿòè è ñìîæåì ëè ìû ñôîðìèðîâàòü íóæíîãî ðàçìåðà ðàì äèñê.
|
|
use_RamdiskSize ;çíà÷åíèå âîçâðàùàåòñÿ â bx
|
|
cmp free_ad_memory,bx ; ðàçìåðíîñòü â êá.
|
|
jbe ._not_memory_in_sys
|
|
movzx eax,bx
|
|
shl eax,10 ;*1024 = get size in byte
|
|
mov save_ramdisksize,eax ; ñîðõàíèì ðàçìåð â byte
|
|
|
|
get_type_FS ;ïîëó÷èì òèï ôàéëîâîé ñèñòåìû + ñîçäàäèì åå
|
|
|
|
|
|
._not_memory_in_sys:
|
|
|
|
if DEBUG
|
|
;pause
|
|
xor ax,ax
|
|
int 0x16
|
|
end if
|
|
}
|
|
macro use_RamdiskSize
|
|
{
|
|
local .start_p_RS
|
|
local .correct_is_not_set_RS
|
|
local .CS
|
|
local .correct_val_RS
|
|
local .correct_size_RS
|
|
local .rest_value_loop_RS
|
|
local .end_get_RS_ERROR_1
|
|
local .end_get_RS_ERROR_2
|
|
local ._end_parse_RS
|
|
;îáðàáàòûâàåòñÿ ðàçìåð ôîðìèðóåìîãî ðàì äèñêà
|
|
;çàãðóçèì íà÷àëî ñåêöèè, ò.ê. áóäåì ïðîñìàòðèâàòü ñ íà÷àëà è âñþ ñåêöèþ
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
.start_p_RS:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz ._end_parse_RS ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
cmp al,'R'
|
|
jnz .start_p_RS
|
|
;ïðîâåðêà íà çíà÷åíèÿ RamdiskSize
|
|
; parse_RamdiskSize
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_RamdiskSize
|
|
mov cx,parse_RamdiskSize_e - parse_RamdiskSize
|
|
repe cmpsb
|
|
jnz .rest_value_loop_RS ;is not compare
|
|
|
|
sub bx,parse_RamdiskSize_e - parse_RamdiskSize ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
|
|
test status_flag,flag_found_RS ;îöåíêà ôëàãîâ
|
|
jz .correct_is_not_set_RS
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
.correct_is_not_set_RS:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
jcxz .end_get_RS_ERROR_1 ;not found param
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .start_p_RS ; ïåðåéäåì íà íà÷àëî è ïîïðîáóåì íàéòè åùå ñåêöèþ
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;Òóò íóæíî ïðåîáðàçîâûâàòü ñòðî÷êó â öèôðîâîå çíà÷åíèå.
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
xor bx,bx
|
|
mov cx,5
|
|
@@: mov al,byte [es:di]
|
|
cmp al,'0'
|
|
jb .CS
|
|
cmp al,'9'
|
|
jbe .correct_val_RS
|
|
.CS:
|
|
cmp al,'K'
|
|
jz .correct_size_RS
|
|
jmp .end_get_RS_ERROR_2
|
|
.correct_val_RS:
|
|
imul bx,10
|
|
xor al,0x30
|
|
add bl,al
|
|
inc di
|
|
loop @b
|
|
|
|
.correct_size_RS:
|
|
;âîçìîæåí 1 âàðèàíò, êîãäà ðàçìåð çàäàí â K êèëëîáàéòàõ
|
|
;âíóòðåííûé ôîðìàò äàííûõ ýòî êîë-âî çàïðîùåíîé ïàìÿòè â êá.
|
|
test bx,bx
|
|
jnz @f ;åñëè çíà÷åíèå îòëè÷íî îò 0
|
|
;;;;;ñîîáùåíèå îá îøèáêå, ðàçìåð "íàéäåíîãî" áëîêà =0 ìèíèìàëüíî ìû äîëæíû
|
|
;óñòàíîâèòü 64 êá ðàçìåð ðàì äèñêà.
|
|
or show_errors_sect,show_error_3
|
|
mov bx,64
|
|
@@:
|
|
jmp ._end_parse_RS
|
|
|
|
|
|
.rest_value_loop_RS:
|
|
mov di,ax
|
|
mov cx,bx
|
|
jmp .start_p_RS
|
|
|
|
|
|
|
|
.end_get_RS_ERROR_1:
|
|
;ñîîáùåíèå îá îøèáêå - äàííûé ó÷àñòîê êîäà íå áûë êîððåêòíî îáðàáîòàí :(
|
|
or show_errors_sect,show_error_1
|
|
jmp ._end_parse_RS
|
|
.end_get_RS_ERROR_2:
|
|
or show_errors_sect,show_error_2
|
|
|
|
._end_parse_RS:
|
|
if DEBUG
|
|
pusha
|
|
movzx eax,bx
|
|
mov cx,0x0a
|
|
mov di,RamdiskSize_msg
|
|
mov dword[ds:di],' '
|
|
mov word [ds:di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,RamdiskSize_msg
|
|
call printplain
|
|
|
|
popa
|
|
end if
|
|
|
|
}
|
|
|
|
macro use_free_memory
|
|
{
|
|
local _support_function_use_free_memory
|
|
;ìàêðîñ äëÿ ïîëó÷åíèÿ îáùåãî ÷èñëà äîñòóïíîé ïàìÿòè â êá, äëÿ ôîðìèðîâàíèÿ ðàì äèñêà çà ïðåäåëàìè 1 ìá.
|
|
;èñïîëüçóåòñÿ 0õ88 ôóíêöèÿ 0õ15 ïðåðûâàíèÿ
|
|
; åñëè ïîääåðæèâàåòñÿ ôóíêöèÿ, òî â ax çíà÷åíèå â êá, åñëè íåò, òî â ax=0
|
|
mov ah,0x88 ;ah,0x88
|
|
int 0x15
|
|
jnc ._support_function_use_free_memory
|
|
xor ax,ax
|
|
;âîçâðàùàåò â ax ÷èñëî â êá
|
|
._support_function_use_free_memory:
|
|
mov free_ad_memory,ax ; åñëè íå ïîääåðæèâàåòñÿ áèîñîì, òî â ax=0
|
|
if DEBUG
|
|
pushad
|
|
movzx eax,ax
|
|
mov cx,0x0a
|
|
mov di,free_memory_msg
|
|
mov dword[ds:di],' '
|
|
mov word [ds:di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,free_memory_msg
|
|
call printplain
|
|
|
|
popad
|
|
end if
|
|
|
|
|
|
|
|
|
|
}
|
|
macro show_ERRORS
|
|
{
|
|
|
|
}
|
|
|
|
macro get_type_FS ;ïîëó÷èòü è ñîçäàòü îáðàç äëÿ çàäàííîé RFS.
|
|
{
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
.start_g_tpe_RFS:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz ._end_parse_FRS ;._end_get_type_RFS ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
cmp al,'R'
|
|
jnz .start_g_tpe_RFS
|
|
;ïðîâåðêà íà çíà÷åíèÿ RamdiskSize
|
|
; parse_RamdiskSize
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_RamdiskFS
|
|
mov cx,parse_RamdiskFS_e - parse_RamdiskFS
|
|
repe cmpsb
|
|
jnz .start_g_tpe_RFS_rest_v ;is not compare
|
|
|
|
sub bx,parse_RamdiskFS_e - parse_RamdiskFS ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
|
|
test status_flag,flag_found_GTRFMS ;îöåíêà ôëàãîâ
|
|
jz .correct_is_not_set_FRS
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
.correct_is_not_set_FRS:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
test cx,cx
|
|
jz .end_get_FRS_ERROR_1 ;not found param
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .start_g_tpe_RFS ; ïåðåéäåì íà íà÷àëî è ïîïðîáóåì íàéòè åùå ñåêöèþ
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;Òóò íóæíî ïðåîáðàçîâûâàòü ñòðî÷êó â öèôðîâîå çíà÷åíèå.
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_RFS_FAT
|
|
mov cx,parse_RFS_FAT_e - parse_RFS_FAT
|
|
repe cmpsb
|
|
jnz .krfs_cmp ;is not compare
|
|
|
|
make_FAT_RamFS ;ñäåëàòü
|
|
|
|
if DEBUG
|
|
pusha
|
|
mov si,make_fat12_RFS_msg
|
|
call printplain
|
|
popa
|
|
end if
|
|
jmp ._end_parse_FRS
|
|
|
|
.krfs_cmp:
|
|
mov cx,bx
|
|
mov di,ax
|
|
|
|
mov si,parse_RFS_KRFS
|
|
mov cx,parse_RFS_KRFS_e - parse_RFS_KRFS
|
|
repe cmpsb
|
|
; jnz @f ;is not compare
|
|
|
|
jmp ._end_parse_FRS
|
|
|
|
|
|
.start_g_tpe_RFS_rest_v:
|
|
mov cx,bx
|
|
mov di,ax
|
|
jmp .start_g_tpe_RFS
|
|
|
|
|
|
|
|
.end_get_FRS_ERROR_1:
|
|
;ñîîáùåíèå îá îøèáêå - äàííûé ó÷àñòîê êîäà íå áûë êîððåêòíî îáðàáîòàí :(
|
|
or show_errors_sect,show_error_1
|
|
jmp ._end_parse_FRS
|
|
.end_get_FRS_ERROR_2:
|
|
or show_errors_sect,show_error_2
|
|
|
|
._end_parse_FRS:
|
|
if DEBUG
|
|
pusha
|
|
mov si,get_type_FS_msg
|
|
call printplain
|
|
popa
|
|
end if
|
|
|
|
|
|
|
|
}
|
|
macro make_FAT_RamFS
|
|
{
|
|
local .RS1
|
|
local .fat12
|
|
local .fat16
|
|
; ìû äîëæíû ñôîðìèðîâàòü â íà÷àëüíûé îáðàç Ram FS, à ïîòîì çàïèñàòü åãî çà îáëàñòü âûøå 1 ìá..
|
|
;äëÿ ñëó÷àÿ ñ FAT12
|
|
; mov di,fat12_buffer ;ds äîëæåí áûòü = cs
|
|
;es:di - óêàçûâàþò íà íà÷àëî áëîêà äëÿ ôîðìèðîâàíèÿ ðàì ôñ.
|
|
use_RamdiskSector ;âîçðàùàåìîå çíà÷åíèå â ax ðàçìåð ñåêòîðà â áàéòàõ
|
|
cmp ax,4096 ;ïî ñïåöèôèêàöèè çíà÷åíèå äîëæíî áûòü â ïðåäåëàõ îò 1 äî 4096
|
|
ja .RS1
|
|
test ax,ax
|
|
jnz @f ;îøèáêà åñëè ñþäà ïðûãíóëè âñå òàêè ...
|
|
|
|
.RS1: mov word [fat12_buffer.BPB_BytsPerSec],512
|
|
;;;;;;;;;;ñêàæåì ÷òî ïî äåôîëòó áóäåì þçàòü çíà÷åíèå...
|
|
@@: mov word [fat12_buffer.BPB_BytsPerSec],ax ;òóò âñå îê
|
|
|
|
;BPB_SecPerClus êîë-âî ñåêòîðîâ â êëàñòåðå
|
|
use_RamdiskCluster ;âîçðàùàåìîå çíà÷åíèå â al
|
|
cmp al,128
|
|
ja @f
|
|
; test al,0x1 ;ïðîâåðêà íà êðàòíîñòü )
|
|
; jnz @f
|
|
|
|
mov byte [fat12_buffer.BPB_SecPerClus],al
|
|
|
|
;incorrect value will be set dafault
|
|
|
|
;íèæå íåêîððåêòíîå çíà÷åíèå â ò.ê. ðàçìåð êðàòåí 2 è â äèàïàçîíå îò 1 äî 128 âêëþ÷èòåëüíî
|
|
; ìû äîëæíû ðóãíóòüñÿ íà ýòî
|
|
;@@: ;mov byte [fat12_buffer.BPB_SecPerClus],1
|
|
|
|
;;;;; îïðåäåëåèì êàêàÿ ó íàñ áóäåò èñïîëüçîâàòüñÿ FAT
|
|
;ïî óñëîâèþ, fat12<4085<=fat16<65525<=fat32
|
|
; fat12_buffer.BPB_BytsPerSec*fat12_buffer.BPB_SecPerClus = êîë-âî ñåêòîðîâ
|
|
movzx eax,word [fat12_buffer.BPB_BytsPerSec]
|
|
movzx ebx,byte [fat12_buffer.BPB_SecPerClus]
|
|
|
|
imul ebx,eax ;òóò ðàçìåðíîñòü ñåêòîðà
|
|
mov eax,save_ramdisksize ;ðàçìåð çàïðîøåííîãî ðàì äèñêà â áàéòàõ
|
|
cdq
|
|
idiv ebx
|
|
;;;;;;;; ñåé÷àñ ÷àñòíîå â eax, à îñòàòîê â edx
|
|
;ïîëó÷èì êîë-âî ñåêòîðîâ, è ìîæåì óæå îïðåäåëèòü òèï FAT êîòîðóþ íóæíî äåëàòü.
|
|
cmp eax,4085
|
|
jb .fat12
|
|
cmp eax,65525
|
|
jb .fat16
|
|
;;;;;;;;;;;;;;;;;;;;;;;; òóò fat32
|
|
mov set_ramfs,32 ;óñòàíîâèì òèï ôàéëîâîé ñèñòåìû
|
|
mov word [fat12_buffer.BPB_RsvdSecCnt],32
|
|
xor eax,eax
|
|
mov word [fat12_buffer.BPB_RootEntCnt],ax
|
|
mov word [fat12_buffer.BPB_TotSec16],ax
|
|
mov dword [fat12_buffer.BPB_TotSec32],eax
|
|
|
|
|
|
.fat16: ;fat16
|
|
;Äëÿ FAT12 è FAT16 äèñêîâ ýòî ïîëå ñîäåðæèò êîëè÷åñòâî ñåêòîðîâ, à BPB_TotSec32 ðàâíî 0, åñëè çíà÷åíèå <óìåùàåòñÿ> (ìåíüøå 0x10000).
|
|
jmp $
|
|
mov set_ramfs,16 ;óñòàíîâèì òèï ôàéëîâîé ñèñòåìû
|
|
movzx ebx,byte [fat12_buffer.BPB_SecPerClus]
|
|
imul eax,ebx
|
|
|
|
cmp eax,0x10000
|
|
jae @f
|
|
mov word [fat12_buffer.BPB_TotSec16],ax
|
|
mov dword [fat12_buffer.BPB_TotSec32],0
|
|
@@:
|
|
;êîëè÷åñòâî ñåêòîðîâ çàíèìàåìîå îäíîé êîïèåé ôàò
|
|
; mov word [fat12_buffer.BPB_FATSz16],0x9 ;Äëÿ FAT12/FAT16 ýòî êîëè÷åñòâî ñåêòîðîâ îäíîé FAT. ??
|
|
;;;; çàïîëíèì BPB_RootEntCnt Äëÿ FAT12 è FAT16 äèñêîâ, ýòî ïîëå ñîäåðæèò ÷èñëî
|
|
;32-áàéòíûõ ýëåìåíòîâ êîðíåâîé äèðåêòîðèè. Äëÿ FAT32 äèñêîâ, ýòî ïîëå äîëæíî
|
|
;áûòü 0. Ïîêà êîíñòàíòà, íóæíî áóäåò ïîçæå äîäåëàòü.
|
|
mov eax,root_dir_entry_count
|
|
mov word [fat12_buffer.BPB_RootEntCnt],ax ; count of 32-byte dir. entries (224*32 = 14 sectors= 7 kb)
|
|
;ïî äîêóìåíòàöèè ðåêîìåíäóþò îòðåçàòü 16 êá äëÿ ðóò äèð íî ýòî î÷ ìíîãî, äàæå äëÿ êîîñ. èìõî äëÿ íà÷àëà õâàòèò è 7 êá
|
|
;;;;;;;
|
|
;Äëÿ FAT16 ýòî êîëè÷åñòâî ñåêòîðîâ îäíîé FAT. Äëÿ FAT32 ýòî çíà÷åíèå
|
|
;ðàâíî 0, à êîëè÷åñòâî ñåêòîðîâ îäíîé FAT ñîäåðæèòñÿ â BPB_FATSz32.
|
|
;RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec - 1)) / BPB_BytsPerSec;
|
|
|
|
;TmpVal1 = DskSize - (BPB_ResvdSecCnt + RootDirSectors);
|
|
;TmpVal2 = (256 * BPB_SecPerClus) + BPB_NumFATs;
|
|
;If(FATType == FAT32)
|
|
; TmpVal2 = TmpVal2 / 2;
|
|
;FATSz = (TMPVal1 + (TmpVal2 - 1)) / TmpVal2;
|
|
;If(FATType == FAT32) {
|
|
; BPB_FATSz16 = 0;
|
|
; BPB_FATSz32 = FATSz;
|
|
;} else {
|
|
; BPB_FATSz16 = LOWORD(FATSz);
|
|
; /* there is no BPB_FATSz32 in a FAT16 BPB */
|
|
;}
|
|
;=====================================
|
|
;RootDirSectors
|
|
movzx ebx, word [fat12_buffer.BPB_BytsPerSec]
|
|
imul eax,32
|
|
add eax,ebx
|
|
dec eax
|
|
|
|
cdq
|
|
idiv ebx
|
|
;;;;;;;; ñåé÷àñ ÷àñòíîå â eax, à îñòàòîê â edx äëÿ äèñêåòû 1.44 ó íàñ äîëæíî áûòü çíà÷åíèå =14
|
|
;BPB_ResvdSecCnt + RootDirSectors
|
|
movzx ebx, word [fat12_buffer.BPB_RsvdSecCnt]
|
|
add ebx,eax
|
|
|
|
;DskSize ó íàñ ýòî çíà÷åíèå óæå ïîëó÷åíî è äîñòóïíî
|
|
movzx eax,word [fat12_buffer.BPB_TotSec16] ;äîëæåí áûòü â ñåêòîðàõ
|
|
sub eax,ebx
|
|
|
|
|
|
;TmpVal1=eax
|
|
shl edi,8 ;=edi*256
|
|
movzx ecx,byte [fat12_buffer.BPB_NumFATs]
|
|
add edi,ecx
|
|
;TmpVal2=edi
|
|
add eax,edi
|
|
dec eax
|
|
cdq
|
|
idiv edi
|
|
;FATSz = ñåé÷àñ ÷àñòíîå â eax, à îñòàòîê â edx
|
|
mov word [fat12_buffer.BPB_FATSz16],ax
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.fat12: ;fat12
|
|
if DEBUG
|
|
; âûâåäåì â îòëàäêå, ÷òî ñîáèðàåìñÿ äåëàòü îáðàç äèñêà c FS=fat12
|
|
pushad
|
|
mov si,start_making_FAT12_msg
|
|
call printplain
|
|
popad
|
|
end if
|
|
|
|
|
|
|
|
;Äëÿ FAT12 è FAT16 äèñêîâ ýòî ïîëå ñîäåðæèò êîëè÷åñòâî ñåêòîðîâ, à BPB_TotSec32 ðàâíî 0, åñëè çíà÷åíèå <óìåùàåòñÿ> (ìåíüøå 0x10000).
|
|
mov set_ramfs,12 ;óñòàíîâèì òèï ôàéëîâîé ñèñòåìû
|
|
movzx ebx,byte [fat12_buffer.BPB_SecPerClus]
|
|
imul eax,ebx
|
|
|
|
cmp eax,0x10000
|
|
jae @f
|
|
mov word [fat12_buffer.BPB_TotSec16],ax
|
|
mov dword [fat12_buffer.BPB_TotSec32],0
|
|
@@:
|
|
;êîëè÷åñòâî ñåêòîðîâ çàíèìàåìîå îäíîé êîïèåé ôàò
|
|
; mov word [fat12_buffer.BPB_FATSz16],0x9 ;Äëÿ FAT12/FAT16 ýòî êîëè÷åñòâî ñåêòîðîâ îäíîé FAT. ??
|
|
;;;; çàïîëíèì BPB_RootEntCnt Äëÿ FAT12 è FAT16 äèñêîâ, ýòî ïîëå ñîäåðæèò ÷èñëî
|
|
;32-áàéòíûõ ýëåìåíòîâ êîðíåâîé äèðåêòîðèè. Äëÿ FAT32 äèñêîâ, ýòî ïîëå äîëæíî
|
|
;áûòü 0. Ïîêà êîíñòàíòà, íóæíî áóäåò ïîçæå äîäåëàòü.
|
|
mov eax,root_dir_entry_count
|
|
mov word [fat12_buffer.BPB_RootEntCnt],ax ; count of 32-byte dir. entries (224*32 = 14 sectors= 7 kb)
|
|
;ïî äîêóìåíòàöèè ðåêîìåíäóþò îòðåçàòü 16 êá äëÿ ðóò äèð íî ýòî î÷ ìíîãî, äàæå äëÿ êîîñ. èìõî äëÿ íà÷àëà õâàòèò è 7 êá
|
|
;;;;;;;
|
|
;DskSize(â ñåêòîðàõ)*12 (ðàçìåðíîñòü ôàéëîâîé ñèñòåìû, ò.å ïðåäïîëîæèì ñêîëüêî áèòîâ ïîòðåáóåòñÿ äëÿ àäðåñàöèè ýòîãî îáúåìà) /8 (÷òî ïîëó÷èòü ðàçìåð â áàéòàõ)
|
|
;ïîëó÷åííîå ÷èñëî îêðóãëÿåì â áîëüøóþ ñòîðîíó êðàòíîå ñåêòîðó ò.å. 512 áàéò Òàêîé ïîäõîä íå óíèâåðñàëåí, íî ïîêà ïîéäåò
|
|
;âîîáùå ó ìåëêîñîôò ýòî âñå ñ÷èòàåòñÿ ðó÷êàìè, íî ìû áóäåì þçàòü òîëüêî ïîä êîîñ ðàì äèñê ñ ôàò12
|
|
movzx eax, word [fat12_buffer.BPB_TotSec16]
|
|
imul eax,12
|
|
shr eax,3 ;äåëèì íà 8 íî ò.å. íàì íóæíî äåëèòü åùå è íà 512 èëè áîëåå â çàâèñèìîñòè îò ðàçìåðîâ êëàñòåðà
|
|
movzx ebx,word [fat12_buffer.BPB_BytsPerSec] ;ðàçìåð ñåêòîðà
|
|
cdq
|
|
idiv ebx ;ðàçäåëèì íà ðàçìåð êëàñòåðà
|
|
;ñåé÷àñ ó íàñ â eax çíà÷åíèå åãî íóæíî îêðóãëèòü â áîëüøóþ ñòîðîíó êðàòíîìó 512 áàéòàì
|
|
;ïðèìåíèì ñëåäóþùåå î÷èñòèì and è äîáàâèì 512 áàéò. òàêèì îáðàçîì âûðàâíèì íà 512 áàéò
|
|
;íî ò.ê. âñå ðàâíî äåëèòü íèæíèé êîä íàì íå íóæåí
|
|
; and eax,0xfff200
|
|
; add eax,0x200 ;äîáàâèì 512 áàéò äëÿ 1.44 äèñêåòû èäåàëüíî ïîäõîäèò ))
|
|
|
|
inc ax
|
|
;ïî èäåå äîëæíî íà êàæäóþ ôàò òàáëèöó
|
|
;ðåçåðâèðîâàòüñÿ 9 ñåêòîðîâ ò.å. ïîëó÷àåòñÿ 2*9=18+1 =19 ñåêòîðîâ ò.å. ðóò äèð íàõîäèòüñÿ íà ñ 20 ñåòîðà ò.å. ñ àäðåñà 0õ2600
|
|
;ñåé÷àñ íóæíî âû÷èñëèòü ñêîëüêî áóäåò ñåêòîðîâ çàíèìàòü ôàò ) íóæíî ðàçäåëèòü íà 512
|
|
;FATSz = ñåé÷àñ ÷àñòíîå â eax
|
|
mov word [fat12_buffer.BPB_FATSz16],ax
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
get_firstDataSector ;ïîëó÷èòü ñìåùåíèå äî äàííûõ
|
|
;ñîçäàäèì ïåâóþ çàïèñü â ôàò ïî îïðåäåëåííîìó àäðåñó.
|
|
first_create_fat_table
|
|
;çàêèíèì BPB ôàéëîâîé ñèñòåìû çà 1 ìá.
|
|
use_BPB_RAM
|
|
;
|
|
;êîïèðîâàíèå ôàéëà.
|
|
use_RamdiskFile
|
|
|
|
;;;; âû÷èñëÿåì óêàçàòåëü íà êîðíåâóþ äèð FirstRootDirSecNum = BPB_ResvdSecCnt + (BPB_NumFATs * BPB_FATSz16);
|
|
; movzx ebx, [fat12_buffer.BPB_NumFATs]
|
|
; movzx eax,ax
|
|
; imul eax,ebx
|
|
;eax=(BPB_NumFATs * BPB_FATSz16)
|
|
; inc eax
|
|
; BPB_ResvdSecCnt çíà÷åíèå òîëüêî 1 äëÿ fat12/16
|
|
;â eax óêàçàòåëü íà root dir. äëÿ äèñêåòû fat12 äîëæíî ïîëó÷èòüñÿ ïðè êîë-âî êîïèé fat 1 = 1+ (1*1) =2 èëè 3
|
|
|
|
if DEBUG
|
|
pusha
|
|
; mov ax,point_default
|
|
; mov ax,cx
|
|
mov cx,0x0a
|
|
mov di,show_db1
|
|
; mov dword[ds:di],' '
|
|
; mov word [ds:di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,show_db1
|
|
call printplain
|
|
;
|
|
; xor ax,ax
|
|
; int 0x16
|
|
popa
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
macro use_RamdiskSector
|
|
{
|
|
;äëÿ íåêîòîðûõ FS áóäåò èãíîðèðîâàòüñÿ
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
|
|
.start_RamdiskSector:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz .end_RamdiskSector ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
|
|
cmp al,'R'
|
|
jnz .start_RamdiskSector
|
|
;ïðîâåðêà íà çíà÷åíèÿ RamdiskSize
|
|
; parse_RamdiskSize
|
|
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_RamdiskSector
|
|
mov cx,parse_RamdiskSector_e - parse_RamdiskSector
|
|
repe cmpsb
|
|
jnz .RamdiskSector_rest_val ;is not compare
|
|
|
|
sub bx,parse_RamdiskSector_e - parse_RamdiskSector ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
|
|
test status_flag,flag_found_RamdiskSector ;îöåíêà ôëàãîâ
|
|
jz .correct_is_not_set_RamdiskSector
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
.correct_is_not_set_RamdiskSector:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
jcxz .end_get_RamS_ERROR_1 ;not found param
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .start_RamdiskSector ; ïåðåéäåì íà íà÷àëî è ïîïðîáóåì íàéòè åùå ñåêöèþ
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
xor bx,bx
|
|
mov cx,4
|
|
@@: movzx ax,byte [es:di]
|
|
cmp al,'0'
|
|
jb .end_RamdiskSector
|
|
cmp al,'9'
|
|
ja .end_RamdiskSector
|
|
;;;;;;;;;;;;;;;;;;;
|
|
|
|
imul bx,10
|
|
xor al,0x30
|
|
add bx,ax
|
|
|
|
inc di
|
|
|
|
loop @b
|
|
jmp .end_RamdiskSector
|
|
|
|
|
|
.RamdiskSector_rest_val:
|
|
mov cx,bx
|
|
mov di,ax
|
|
jmp .start_RamdiskSector
|
|
.end_get_RamS_ERROR_1:
|
|
|
|
.end_RamdiskSector:
|
|
mov ax,bx
|
|
|
|
if DEBUG
|
|
pusha
|
|
movzx eax,bx;save_cx_d;point_default
|
|
mov cx,0x0a
|
|
mov di,RamdiskSector_msg
|
|
mov dword[ds:di],' '
|
|
mov dword [ds:di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,RamdiskSector_msg
|
|
call printplain
|
|
|
|
popa
|
|
end if
|
|
|
|
; pop di
|
|
; pop es
|
|
}
|
|
|
|
macro use_RamdiskCluster
|
|
{
|
|
;äëÿ íåêîòîðûõ FS áóäåò èãíîðèðîâàòüñÿ
|
|
; push es
|
|
; push di
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
; push ini_data_
|
|
; pop es
|
|
.start_RamdiskCluster:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz .end_RamdiskCluster ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
cmp al,'R'
|
|
jnz .start_RamdiskCluster
|
|
;ïðîâåðêà íà çíà÷åíèÿ RamdiskSize
|
|
; parse_RamdiskSize
|
|
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_RamdiskCluster
|
|
mov cx,parse_RamdiskCluster_e - parse_RamdiskCluster
|
|
repe cmpsb
|
|
jnz .RamdiskCluster_rest_val ;is not compare
|
|
|
|
sub bx,parse_RamdiskCluster_e - parse_RamdiskCluster ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
|
|
test status_flag,flag_found_RamdiskCluster ;îöåíêà ôëàãîâ
|
|
jz .correct_is_not_set_RamdiskCluster
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
.correct_is_not_set_RamdiskCluster:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
jcxz .end_get_RamSC_ERROR_1 ;not found param
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .start_RamdiskCluster ; ïåðåéäåì íà íà÷àëî è ïîïðîáóåì íàéòè åùå ñåêöèþ
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
@@: movzx ax,byte [es:di]
|
|
cmp al,'0'
|
|
jb .end_RamdiskCluster
|
|
cmp al,'9'
|
|
ja .end_RamdiskCluster
|
|
;;;;;;;;;;;;;;;;;;;
|
|
xor al,0x30
|
|
|
|
jmp .end_RamdiskCluster
|
|
|
|
|
|
.RamdiskCluster_rest_val:
|
|
mov cx,bx
|
|
mov di,ax
|
|
jmp .start_RamdiskCluster
|
|
.end_get_RamSC_ERROR_1:
|
|
|
|
.end_RamdiskCluster:
|
|
if DEBUG
|
|
pusha
|
|
mov cx,0x0a
|
|
mov di,RamdiskCluster_msg
|
|
; mov word[ds:di],' '
|
|
call decode
|
|
;Show size
|
|
mov si,RamdiskCluster_msg
|
|
call printplain
|
|
|
|
popa
|
|
end if
|
|
|
|
}
|
|
|
|
macro use_Loader_Image
|
|
;ïðåäíàçíà÷åí äëÿ çàãðóçêè îáðàçîâ âûøå 1 Ìá.
|
|
;ïåðâîíà÷àëüíàÿ âåðñèÿ çàãðóæàåò îáðàç äèñêåòû 1.44 ìá
|
|
{
|
|
local .start_p_LI
|
|
local .exit
|
|
local .error_LI
|
|
local .rest_value_loop
|
|
local .found_end_str
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
;îáðàáîòêà êîíñòðóêöèè òèïà LoaderModule=kord/kolibri.ldm
|
|
.start_p_LI:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz .exit ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
cmp al,'L'
|
|
jnz .start_p_LI
|
|
;ïðîâåðêà íà çíà÷åíèå LoaderModule
|
|
; parse_LoaderModule
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_LoaderImage
|
|
mov cx,parse_LoaderImage_e - parse_LoaderImage
|
|
repe cmpsb
|
|
jnz .rest_value_loop ;is not compare
|
|
|
|
sub bx,parse_LoaderImage_e - parse_LoaderImage ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
|
|
; test status_flag,flag_found_LM ;îöåíêà ôëàãîâ
|
|
; jz .correct_is_not_set_LI
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
;.correct_is_not_set_LI:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
jcxz .rest_value_loop_LI ;not found param timeout
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .rest_value_loop_LI
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
;di óêàçûâàåò íà íà÷àëî áëîêà èíôîðìàöèè, â cx äëèííà äî êîíöà ñåêöèè.
|
|
;ïîñëå çàãðóçêè çàíîñèòüñÿ çíà÷åíèå çàíÿòîé ïàìÿòè.
|
|
;äëÿ òîãî ÷òî áû çàãðóçèòü ìîäóëü, âîñïîëüçóåìñÿ callback ñåðâèñîì
|
|
;îðèãèíàëüíîå ðåøåíèå - ðàçìåñòèì dd ïåðåä ñòðî÷êîé è ïîñëå ñòðî÷êè ðàçìåñòèì byte =0
|
|
;ýòî âûãëÿäèò òàê: â ini ôàéëå ñóùåñòâóåò ñòðî÷êà LoaderModule = kord/kernel.loader
|
|
;ìû åå ìîäèôèöèðóåì äî òàêîãî ñîñòîÿíèÿ dw,dw,db'kord/kernel.loader',0 êîíå÷íî ñîõðàíèâ òå çíà÷åíèÿ êîòîðûå ìû çàìåíÿåì
|
|
;ñîõðàíèëè ïåâûå 2 word
|
|
push dword [es:di-6]
|
|
lea si,[di-6]
|
|
|
|
push word [es:di-2]
|
|
xor ax,ax
|
|
mov word [es:di-6],ax ;âíîñèì íóæíûå çíà÷åíèÿ
|
|
;info_real_mode_size ðàçìåð è óêàçàòåëü íà îáëàñòü â êîòîðóþ ìîæíî çàãðóçèòüñÿ
|
|
mov ax,info_real_mode_size ;0x3000 ;ñëåäóþùèé ñåãìåíò çà äàííûìè
|
|
|
|
|
|
mov word [es:di-4],ax
|
|
mov word [es:di-2],16 ;êîë-âî áëîêîâ ïî 4 êá =64 êá ò.å. áîëüøå íå ñ÷èòàåì
|
|
;;;;;; ïîèñê êîíöà ñòðî÷êè
|
|
@@: mov al,byte [es:di]
|
|
cmp al,' '
|
|
jz .found_end_str
|
|
cmp al,0xa
|
|
jz .found_end_str
|
|
cmp al,0xd
|
|
jz .found_end_str
|
|
inc di
|
|
dec cx
|
|
jnz @b
|
|
;;;not found äîïóñòèì,÷òî ýòî êîíåö ôàéëà è îí íå èìååò ïðèâû÷íîãî çàâåðåøíèÿ ñòðîêè
|
|
.found_end_str:
|
|
; ÷òåíèå áëîêà ïî 64 êá â ñåãìåíò è çàáðàñûâàíèå åãî âûøå 1 ìá.
|
|
push word [es:di]
|
|
xor ax,ax
|
|
mov word [es:di],ax
|
|
; xor ax,ax ; function 1 - read file
|
|
mov di,si ;file_data
|
|
inc ax
|
|
push si
|
|
push es
|
|
call far dword [loader_callback]
|
|
push cs
|
|
pop ds
|
|
|
|
pop es
|
|
pop si
|
|
|
|
test bx,bx
|
|
jnz .error_LM
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; çàáðàñûâàíèå áëîêà â 64 êá âûøå 1 ìá.
|
|
mov si,table_15_87
|
|
push es
|
|
push ds
|
|
pop es
|
|
mov cx, 256*18
|
|
mov ah, 0x87
|
|
int 0x15
|
|
pop es
|
|
pop dx cx
|
|
test ah, ah
|
|
|
|
|
|
|
|
jmp far dword [es:si]
|
|
|
|
|
|
|
|
|
|
.rest_value_loop:
|
|
mov di,ax
|
|
mov cx,bx
|
|
jmp .start_p_LI
|
|
|
|
.exit:
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
macro name_in_root_fat
|
|
;ìàêðîñ, êîòîðûé çàïèñûâàåò èíôîðìàöèþ î çàãðóæåííîì ôàéëå â êîðíåâóþ ôàò òàáëèöó
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
macro use_RamdiskFile
|
|
{
|
|
;çàãðóçêà ôàéëîâ ñ èñïîëüçîâàíèå callback ñåðâèñà ïåðâè÷íîãî çàãðóç÷èêà
|
|
;èñïîëüçóåòñÿ òîëüêî äëÿ çàãðóçêè íåîáõîäèìûõ è íåáîëüøèõ ôàéëîâ, ò.ê. äîñòàòî÷íî ìåäëåííî ðàáîòàåò
|
|
;äëÿ çàãðóçêè èñïîëüçóåò 0õ87 ôóíêöèþ int 0x15 ïðåðûâàíèÿ - çàãðóçêà áëîêîâ äàííûõ äî 64 êá âûøå 1 ìá
|
|
local .start_loop
|
|
local ._end
|
|
local .rest_value_loop
|
|
local .error
|
|
mov di,point_default ;restore value
|
|
mov cx,save_cx_d
|
|
mov data_offset,0 ;clean offset
|
|
;îáðàáîòêà êîíñòðóêöèè òèïà LoaderModule=kord/kolibri.ldm
|
|
.start_loop:
|
|
call get_firs_sym ;get first symbol on new line
|
|
test cx,cx
|
|
jz ._end ;íåòó? íó ëàäíî - ñëåäóþùåå çíà÷åíèå òîãäà )
|
|
cmp al,'R'
|
|
jnz .start_loop
|
|
;ïðîâåðêà íà çíà÷åíèå RamdiskFile
|
|
mov bx,cx
|
|
mov ax,di
|
|
|
|
mov si,parse_RamdiskFile
|
|
mov cx,parse_RamdiskFile_e - parse_RamdiskFile
|
|
repe cmpsb
|
|
jnz .rest_value_loop ;is not compare
|
|
|
|
sub bx,parse_RamdiskFile_e - parse_RamdiskFile ;correct cx
|
|
add bx,cx
|
|
mov cx,bx
|
|
; test status_flag,flag_found_LM ;îöåíêà ôëàãîâ
|
|
; jz .correct_is_not_set_LM
|
|
|
|
; mov si,found_equal_timeout ;ìû íàøëè ÷òî ôëàã óæå óñòàíîâëåí, èíôîðìèðóåì
|
|
; call printplain
|
|
; jmp .get_next_str
|
|
|
|
;.correct_is_not_set_LM:
|
|
mov ax,0x3d20 ;cut al=' ' ah='='
|
|
repe scasb
|
|
test ecx,ecx
|
|
jz .rest_value_loop ;not found param timeout
|
|
|
|
cmp ah,byte [es:di-1] ;find '='
|
|
jnz .rest_value_loop
|
|
|
|
repe scasb ;cut ' '
|
|
inc cx
|
|
dec di
|
|
|
|
mov save_di_RAMDISK,di
|
|
mov save_cx_RAMDISK,cx
|
|
;di óêàçûâàåò íà íà÷àëî áëîêà èíôîðìàöèè, â cx äëèííà äî êîíöà ñåêöèè.
|
|
;ïîñëå çàãðóçêè çàíîñèòüñÿ çíà÷åíèå çàíÿòîé ïàìÿòè.
|
|
;äëÿ òîãî ÷òî áû çàãðóçèòü ìîäóëü, âîñïîëüçóåìñÿ callback ñåðâèñîì
|
|
;îðèãèíàëüíîå ðåøåíèå - ðàçìåñòèì dd ïåðåä ñòðî÷êîé è ïîñëå ñòðî÷êè ðàçìåñòèì byte =0
|
|
;ýòî âûãëÿäèò òàê: â ini ôàéëå ñóùåñòâóåò ñòðî÷êà RamdiskFile = @menu,@menu
|
|
;ìû åå ìîäèôèöèðóåì äî òàêîãî ñîñòîÿíèÿ dw,dw,db'@menu',0 êîíå÷íî ñîõðàíèâ òå çíà÷åíèÿ êîòîðûå ìû çàìåíÿåì
|
|
;ñîõðàíèëè ïåâûå 2 word
|
|
|
|
;
|
|
@@: mov al,byte [es:di]
|
|
cmp al,',' ; ò.å. èùåì ðàçäåëèòåëü
|
|
jz .found_end_str
|
|
inc di
|
|
dec cx
|
|
jnz @b
|
|
;;;not found äîïóñòèì,÷òî ýòî êîíåö ôàéëà è îí íå èìååò ïðèâû÷íîãî çàâåðøåíèÿ ñòðîêè
|
|
.found_end_str:
|
|
; mov al,byte [es:di]
|
|
; cmp al,' ' ; óáèðàåì ïðîáåëû, åñëè îíè åñòü
|
|
; jnz @f
|
|
; inc di
|
|
; dec cx
|
|
; jnz .found_end_str
|
|
|
|
;@@:
|
|
mov point_to_dest_file_name,di
|
|
inc di
|
|
;ïðîâåðêà èíäèâèäóàëüíîñòè èìåíè ôàéëà
|
|
check_name_file
|
|
;/restore di - point and cx -size section
|
|
mov di,save_di_RAMDISK
|
|
mov cx,save_cx_RAMDISK
|
|
|
|
test al,al
|
|
jnz .start_loop ;åñëè â al çíà÷åíèå íå =0, òî òàêîå èìÿ óæå ñóùåñòâóåò â ñèñòåìå.
|
|
|
|
|
|
|
|
push dword [es:di-6]
|
|
lea si,[di-6]
|
|
|
|
push word [es:di-2]
|
|
push di
|
|
xor ax,ax
|
|
mov word [es:di-6],ax ;âíîñèì íóæíûå çíà÷åíèÿ
|
|
;info_real_mode_size ðàçìåð è óêàçàòåëü íà îáëàñòü â êîòîðóþ ìîæíî çàãðóçèòüñÿ
|
|
mov ax,info_real_mode_size ;0x3000 ;ñëåäóþùèé ñåãìåíò çà äàííûìè
|
|
|
|
|
|
mov word [es:di-4],ax
|
|
mov word [es:di-2],16 ;êîë-âî áëîêîâ ïî 4 êá =64 êá ò.å. áîëüøå íå ÷èòàåì
|
|
|
|
mov di,point_to_dest_file_name
|
|
|
|
if DEBUG
|
|
pushad
|
|
; mov ax,di
|
|
mov cx,0x0a
|
|
mov di,name_of_seg_get_64
|
|
mov dword[ds:di],' '
|
|
mov word[ds:di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,name_of_seg_get_64
|
|
call printplain
|
|
|
|
popad
|
|
end if
|
|
|
|
push word [es:di]
|
|
push cx
|
|
xor ax,ax
|
|
mov word [es:di],ax
|
|
; xor ax,ax ; function 1 - read file
|
|
push di
|
|
mov di,si ;file_data
|
|
inc ax
|
|
push si
|
|
push es
|
|
push bp
|
|
|
|
push es
|
|
pop ds
|
|
push cs
|
|
pop es
|
|
|
|
call far dword [es:loader_callback]
|
|
|
|
|
|
push cs
|
|
pop ds
|
|
|
|
pop bp
|
|
pop es
|
|
pop si
|
|
|
|
cmp bx,2
|
|
ja .error
|
|
; ñåé÷àñ ó íàñ â dx:ax ðàçìåð ôàéëà, êîòîðûé ìû çàãðóçèëè.
|
|
; âîçìîæíà ñèòóàöèÿ, êîãäà â bx=1 ò.å. åñòü åùå äàííûå íà äèñêå
|
|
mov status_flag_loader_f,bx
|
|
|
|
shl edx,16
|
|
mov dx,ax
|
|
; shr edx,10 ;ðàçìåð ôàéëà â êá.
|
|
;;â edx ðàçìåð â áàéòàõ.
|
|
mov save_file_size,edx
|
|
mov eax,edx
|
|
;âîññòàíîâèì ïîëíîñòüþ ôàéë ñöåíàðèÿ
|
|
pop di
|
|
pop cx ;äëèííà îñòàòêà ñ 2-îé ÷àñòüþ èìåíè ò.å. ñ èìåíåì íàçíà÷åíèåì.
|
|
pop word [es:di]
|
|
pop di
|
|
pop word [es:di-2]
|
|
pop dword [es:di-6]
|
|
|
|
|
|
if DEBUG
|
|
pushad
|
|
mov cx,0x0a
|
|
mov di,RamdiskFile_msg
|
|
mov dword[ds:di],' '
|
|
call decode
|
|
;Show size
|
|
mov si,RamdiskFile_msg
|
|
call printplain
|
|
|
|
popad
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; çàãðóçèì ÷åìó ó íàñ ðàâåí êëàñòåð
|
|
; mov ax,word [fat12_buffer.BPB_BytsPerSec] ;êîë-âî áàéòîâ â ñåêòîðå ìîæåò áûòü ëþáîå 512 1024 2048 4096 2 áàéòà
|
|
; movzx bx,byte [fat12_buffer.BPB_SecPerClus] ;êîë-âî ñåêòîðîâ â êëàñòåðå
|
|
; imul ax,bx
|
|
;ñåé÷àñ â eax ðàçìåð êëàñòåðà (512) áàéò
|
|
;â edx äëèíà ôàéëà â áàéòàõ äî 64 êá
|
|
;çàêèíèì ôàéë çà 1 ìá
|
|
;1 íàì íóæíî ñîñòàâèòü ôàò òàáëèöó ò.å. ïðîèçâåñòè ðàçìåòêó ðàìäèñêà, çàòåì ïåðåíåñåì ïî àäðåñó ôàéë
|
|
|
|
;çàïèñàòü èíôîðàìàöèþ î ôàéëå â êîðíåâóþ äèðåêòîðèþ
|
|
register_file_in_fat
|
|
;ïåðåíåñòè çà 1 ìá ñîäåðæèìîå ôàéëà
|
|
move_file_up
|
|
|
|
;ïðîâåðèì, çàãðóæåí ëè äî êîíöà ôàéë? ò.å. åñëè ðàçìåð ôàéëà áîëüøå ÷åì 64 êá, òî áóäåò ïîäãðóæàòü îñòàâøèåñÿ áëîêè
|
|
cmp status_flag_loader_f,0x1
|
|
jnz @f
|
|
;íóæíî äîçàãóçèòü äàííûå ôàéëà è ïåðåíåñòè èõ çà 1-ûé ìá ñîãëàñíî ôàò ñòðóêòóðå
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@:
|
|
;òóò îðãàíèçîâàí öèêë ïî çàãðóçêå ôàéëîâ â êîðíåâóþ äèðåêòîðèþ
|
|
mov di,save_di_RAMDISK
|
|
mov cx,save_cx_RAMDISK
|
|
if DEBUG
|
|
pusha
|
|
xor ax,ax
|
|
int 0x16
|
|
popa
|
|
end if
|
|
|
|
|
|
jmp .start_loop
|
|
|
|
|
|
.error:
|
|
;call error.LoaderModule
|
|
;fixme!
|
|
.rest_value_loop:
|
|
mov di,ax
|
|
mov cx,bx
|
|
jmp .start_loop
|
|
|
|
._end:
|
|
;ïåðåíåñåì çà 1-ûé ìá ôàò è ðóò äèð
|
|
move_up_fat_and_root_d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;çàãðóçêà áëîêà
|
|
; mov ah,0x87
|
|
; mov cx, ;size in byte
|
|
|
|
|
|
;es:si point to descripts
|
|
|
|
|
|
}
|
|
|
|
macro use_BPB_RAM ;çàêèíóòü ñàìûå ïåðâûå 512 áàéò çà 1-é ìá
|
|
;äàííûé ìàêðîñ çàêèäûâàåò BPB ñòðóêòóðó ò.å. ïåðâûå 512 áàéò, ïîêà òîëüêî ôàò12 çà 1 ìá
|
|
{
|
|
mov ax,fat12_buffer
|
|
mov si,table_15_87
|
|
add word [si+8*2+2],ax
|
|
push es
|
|
push ds
|
|
pop es
|
|
mov cx,256 ;áóò ñåêòîð óêëàäûâàåòñÿ â 512 áàéò 512/2=256
|
|
mov ah, 0x87
|
|
int 0x15
|
|
pop es
|
|
;add 512 byte for destination adress
|
|
; add dword [si+8*3+2], 512
|
|
; test ah, ah
|
|
; jz
|
|
if DEBUG
|
|
pusha
|
|
mov ax,word [si+8*2+2]
|
|
mov cx,0x0a
|
|
mov di,BPB_msg
|
|
call decode
|
|
;Show size
|
|
mov si,BPB_msg
|
|
call printplain
|
|
popa
|
|
end if
|
|
}
|
|
macro first_create_fat_table
|
|
;äàííûé ìàêðîñ ñîçäàåò îôîðìëÿåò 3 ïåðâûõ áàéòà fat òàáëèöû, è óñòàíàâëèâàåò óêàçàòåëü íà ñëåäóþùèé áëîê, è âíîñèò 0 çíà÷åíèå
|
|
;äëÿ ñìåùåíèÿ â êîðíåâîé òàáëèöå.
|
|
{
|
|
mov al,byte [fat12_buffer.BPB_Media]
|
|
|
|
|
|
push ds
|
|
|
|
|
|
mov di,info_real_mode_size
|
|
add di,0x1000
|
|
|
|
if DEBUG
|
|
pushad
|
|
|
|
mov ax,info_real_mode_size
|
|
add ax,0x1000
|
|
; mov ax,ds
|
|
mov cx,0xa
|
|
|
|
mov di,first_entry_in_fat
|
|
mov dword [di],' '
|
|
mov word [di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,first_entry_in_fat
|
|
call printplain
|
|
|
|
xor ax,ax
|
|
int 0x16
|
|
|
|
popad
|
|
end if
|
|
|
|
|
|
push di ; push word info_real_mode_size+0x1000 ;cëåäóþùèé ñåãìåíò çà çàãðóæåííûì ó÷àñòêîì
|
|
|
|
xor di,di
|
|
mov point_to_free_root,di ;çíà÷åíèå ñìåùåíèÿ =0 â êîðíåâîé ôàò òàáëèöå îïèñàíèÿ
|
|
|
|
pop ds ; çàãðóæåí ñëåäóþùèé ñåãìåíò ò.å. ïóñòîé ñåãìåíò
|
|
|
|
mov byte [di],al
|
|
or ax,-1
|
|
inc di
|
|
mov word [di],ax
|
|
|
|
pop ds
|
|
mov point_next_fat_str,3
|
|
|
|
if DEBUG
|
|
pushad
|
|
mov ax,point_next_fat_str
|
|
mov cx,0x0a
|
|
mov di,fat_create_msg
|
|
call decode
|
|
;Show size
|
|
mov si,fat_create_msg
|
|
call printplain
|
|
popad
|
|
end if
|
|
|
|
}
|
|
macro register_file_in_fat
|
|
;ìàêðîñ ðåãèñòðàöèè ôàéëà â ôàéëîâîé ñòðóêòóðå Fat
|
|
;ïîêà ïîääåðæèâàåòñÿ òîëüêî ôàò12, ïîêà ))
|
|
;âû÷èñëåíèå ñìåæíûõ êëàñòåðîâ è çàíåñåíèå èíôû â fat/
|
|
{
|
|
local .step2
|
|
local .step3
|
|
local .end
|
|
local .eof_file
|
|
|
|
;di point on root dir íà ôðè ñåêöèþ.
|
|
push es
|
|
|
|
mov ax,info_real_mode_size
|
|
add ax,0x1000
|
|
mov es,ax ; push word info_real_mode_size+0x1000 ;ñåãìåíò ñëåäóþùèé çà çàãðóæåííûì áëîêîì â 64 êá
|
|
|
|
; îïðåäåëÿåì òèï ôàò ïîêà íå îïðåäåëÿåì, ïîêà òîëüêî ôàò 12
|
|
; 12 áèò, äëÿ âû÷åñëåíèÿ ñîñåäíèõ êàëàñòåðîâ.
|
|
mov di,firstDataSect ;â ñåêòîðàõ
|
|
sub di,size_root_dir
|
|
;òåïåðü â ax ðàçìåð â ñåêòîðàõ íà÷àëà ðóò äèð
|
|
shl di,9 ;imul 512
|
|
add di,point_to_free_root ;ñìåùåíèå â óæå çàïèñàííûõ 32-õ ñòðóêòóðàõ.
|
|
;íåîáõîäèìî âíåñòè çíà÷åíèå â ðóò äèð ò.å. 32 áàéòà
|
|
if DEBUG
|
|
pushad
|
|
; mov ax,point_default
|
|
; mov ax,
|
|
mov cx,0x0a
|
|
mov di,show_db2
|
|
mov dword[ds:di],' '
|
|
mov word [ds:di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,show_db2
|
|
call printplain
|
|
;
|
|
; xor ax,ax
|
|
; int 0x16
|
|
popad
|
|
end if
|
|
|
|
|
|
|
|
;gs:di - óêàçàòåëü äëÿ âíåñåíèÿ èíôîðàöèè â ðóò îáëàñòü ôàò òàáëèöû èíîðìàöèè î ôàéëå.
|
|
mov si,shot_name_fat
|
|
mov cx,11
|
|
;çàïèøåì â ñòðóêòóðó èìÿ
|
|
@@: lodsb
|
|
stosb
|
|
loop @b
|
|
|
|
;çàïèøåì àòðèáóòû ôàéëà è DIR_NTRes - çàðåçåâðèðîâàííûé áàéò =0
|
|
xor ax,ax
|
|
mov ah,ATTR_VOLUME_ID
|
|
mov word [es:di],ax
|
|
add di,2
|
|
;DIR_CrtTimeTenth
|
|
mov byte [es:di],100
|
|
inc di
|
|
;DIR_CrtTime
|
|
mov word [es:di],0x032b ;äàòà
|
|
add di,2
|
|
;DIR_CrtDate
|
|
mov word [es:di],0x0 ;âðåìÿ ><
|
|
add di,2
|
|
;DIR_LstAccDate
|
|
mov word [es:di],0x032b ;äàòà ìîåãî
|
|
add di,2
|
|
;DIR_FstClusHI
|
|
mov word [es:di],0x0 ;âðåìÿ äëÿ ôàò12 /16 âñåãäà 0
|
|
add di,2
|
|
;DIR_WrtTime
|
|
mov word [es:di],0x0 ;âðåìÿ ><
|
|
add di,2
|
|
;DIR_WrtDate
|
|
mov word [es:di],0x032b
|
|
add di,2
|
|
|
|
mov ax,point_next_fat_str
|
|
mov word [es:di],ax
|
|
add di,2
|
|
|
|
push di
|
|
;DIR_FstClusLO Ìëàäøåå ñëîâî íîìåðà ïåðâîãî êëàñòåðà.
|
|
; mov ax,point_next_fat_str ;çàãðóçèì óêàçàòåëü íà ýëåìåíò ôàò òàáëèöû ò.å. ýòî íîìåð ôàò çàïèñè
|
|
;FATOffset = N + (N / 2) ò.å. ýòî óæå ó íàñ ñìåùåíèå ìû çíàåì ÷òî -íà÷èíàåòñÿ âñå ñ 3-ãî ýëåìåíòà çàïèñè ôàò
|
|
mov bx,ax
|
|
shr bx,1
|
|
add ax,bx
|
|
;â àõ ñåé÷àñ FATOffset
|
|
;ThisFATEntOffset = BPB_ResvdSecCnt + (FATOffset / BPB_BytsPerSec);
|
|
mov bx, word [fat12_buffer.BPB_BytsPerSec]
|
|
cwd
|
|
idiv bx
|
|
;ax=ThisFATEntOffset= rem (FATOffset / BPB_BytsPerSec) ÷åòíûé èëè íå÷åòíûé óêàçàòåëü.
|
|
mov si,ax
|
|
;íàì íóæíî â öèêëå çàïèñàòü âñå êëàñòåðû êîòîðûå áóäóò èñïîëüçîâàíû äëÿ ðàçìåùåíèÿ ôàéëà.
|
|
;óçíàåì ðàçìåð êëàñòåðà.
|
|
movzx eax,word [fat12_buffer.BPB_BytsPerSec]
|
|
movzx ebx,byte [fat12_buffer.BPB_SecPerClus]
|
|
imul eax,ebx
|
|
;ax - ðàçìåð êëàñòåðà.
|
|
;ñåé÷àñ áóäåì çàïèñûâàòü âî âðåìåííûé áóôåð ôàò òàáëèöó äëÿ âûáðàííîãî ôàéëà. Ïîñêîëüêó ìû åãî çàãðóçèëè âîçìîæíî íå ïîëíîñòüþ
|
|
;ìû îáðàáîòàåì çàïèñü äëÿ ôàò ïîëíîñòüþ, â íå çàâèñèìîñòè îò ïðåäåëà áóôåðà ãäå âîçìîæíà ÷àñòü ôàéëà.
|
|
mov ebx,save_file_size ;ðàçìåð ôàéëà â áàéòàõ
|
|
|
|
@@: sub ebx,eax
|
|
cmp ebx,eax
|
|
jbe .eof_file
|
|
|
|
inc point_next_fat_str
|
|
mov cx,point_next_fat_str ;çàãðóçèì óêàçàòåëü íà ýëåìåíò ôàò òàáëèöû ò.å. ýòî íîìåð ôàò çàïèñè
|
|
;FATOffset = N + (N / 2) ò.å. ýòî óæå ó íàñ ñìåùåíèå ìû çíàåì ÷òî -íà÷èíàåòñÿ âñå ñ 3-ãî ýëåìåíòà çàïèñè ôàò
|
|
mov dx,ax
|
|
shr dx,1
|
|
add cx,dx
|
|
|
|
|
|
|
|
test si,0x1
|
|
jz .step2
|
|
shl cx,4
|
|
mov word[es:si],cx
|
|
inc si
|
|
add cx,ax
|
|
jmp @b
|
|
|
|
.step2: and cx,0x0FFF
|
|
mov word[es:si],cx
|
|
inc si
|
|
add cx,ax
|
|
jmp @b
|
|
|
|
.eof_file:
|
|
mov cx,0x0fff
|
|
test si,0x1
|
|
jz .step3
|
|
shl cx,4
|
|
mov word[es:si],cx
|
|
jmp .end
|
|
|
|
.step3: and cx,0x0FFF
|
|
mov word[es:si],cx
|
|
|
|
.end: inc point_next_fat_str
|
|
|
|
pop di
|
|
;DIR_FileSize 32-áèòíûé DWORD ñîäåðæèò ðàçìåð ôàéëà â áàéòàõ.
|
|
mov eax,save_file_size
|
|
mov dword [es:di],eax
|
|
|
|
if DEBUG
|
|
pushad
|
|
|
|
mov di,firstDataSect ;â ñåêòîðàõ
|
|
sub di,size_root_dir
|
|
;òåïåðü â ax ðàçìåð â ñåêòîðàõ íà÷àëà ðóò äèð
|
|
shl di,9 ;imul 512
|
|
add di,point_to_free_root ;ñìåùåíèå â óæå çàïèñàííûõ 32-õ ñòðóêòóðàõ.
|
|
|
|
push di
|
|
|
|
mov si,dest_name_fat
|
|
mov cx,11
|
|
|
|
;çàïèøåì â ñòðóêòóðó èìÿ
|
|
@@: mov al,byte [es:di]
|
|
inc di
|
|
mov byte [ds:si],al
|
|
inc si
|
|
loop @b
|
|
|
|
mov di,si
|
|
inc di
|
|
pop ax
|
|
mov cx,0xa
|
|
call decode
|
|
|
|
mov si,dest_name_fat
|
|
call printplain
|
|
popad
|
|
|
|
END IF
|
|
|
|
|
|
|
|
|
|
|
|
add point_to_free_root,32 ;óâåëèöèì ñìåùåíèå äî ñëåäóþùåãî çíà÷åíèÿ.
|
|
pop es
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
macro get_firstDataSector
|
|
;ìàêðîñ äëÿ âû÷èñëåíèÿ ïåâîãî ñåêòîðà äàííûõ ò.å. äàííûõ ôàéëîâ â ôàòå
|
|
;âû÷èñëèì FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;
|
|
{
|
|
mov ax,word [fat12_buffer.BPB_FATSz16]
|
|
movzx bx,byte [fat12_buffer.BPB_NumFATs]
|
|
imul ax,bx ;9x1=9
|
|
;ax=BPB_NumFATs * FATSz
|
|
mov bx,word [fat12_buffer.BPB_RootEntCnt] ; count of 32-byte dir. entries (224*32 = 14 sectors= 7 kb)
|
|
shr bx,4 ;imul bx,32 and then div 512 -> in bx size in sectors
|
|
add ax,bx ;9+14=23
|
|
mov size_root_dir,bx
|
|
movzx bx,byte [fat12_buffer.BPB_RsvdSecCnt] ;add 1 for fat 16/12
|
|
add ax,bx
|
|
;ax=firstDataSector - ãäå íà÷èíàåòñÿ ïåðâûé ñåêòîðî îò 0 ñåêòîðà â ñåêòîðàõ. - ôàêòè÷åñêè = 24 ñåêòîð
|
|
mov firstDataSect,ax ;ñîõðàíèì äëÿ âû÷èñëåíèÿ
|
|
; ïîëó÷èìçíà÷åíèå êëàñòåðîâ, ýòî îáúåì â êîòîðûé ìû ìîæåì çàïèñàòü äàííûå
|
|
mov bx,word [fat12_buffer.BPB_TotSec16]
|
|
sub bx,ax
|
|
mov ax,bx
|
|
movzx bx,byte [fat12_buffer.BPB_SecPerClus]
|
|
cwd
|
|
idiv bx
|
|
mov DataClasters,ax
|
|
|
|
if DEBUG
|
|
pushad
|
|
mov ax,firstDataSect ;ïåðâûé ñåêòîð äàííûõ
|
|
mov cx,0x0a
|
|
mov di,firstDataSect_msg
|
|
call decode
|
|
;Show size
|
|
mov si,firstDataSect_msg
|
|
call printplain
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
mov ax,size_root_dir ;ðàçìåð ðóò äèð â ñåòîêòîðàõ
|
|
mov cx,0x0a
|
|
mov di,size_root_dir_msg
|
|
call decode
|
|
;Show size
|
|
mov si,size_root_dir_msg
|
|
call printplain
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
mov ax,DataClasters ;êëàñòåðû
|
|
mov cx,0x0a
|
|
mov di,DataClasters_msg
|
|
call decode
|
|
;Show size
|
|
mov si,DataClasters_msg
|
|
call printplain
|
|
popad
|
|
|
|
end if
|
|
|
|
}
|
|
|
|
macro use_RamdiskPATHS
|
|
;ïàðñèíã ïóòè èñòî÷íèêà ôàéëîâ.
|
|
{
|
|
|
|
}
|
|
|
|
macro use_RamdiskPATHD
|
|
;ïàðñèíã ïóòè íàçíà÷åíèÿ ôàéëîâ.
|
|
{
|
|
|
|
}
|
|
macro check_name_file
|
|
;ìàêðîñ ïðîâåðêè èìåíè íà ïîâòîð, èìÿ äîëæíî áûòü óíèêàëüíûì.
|
|
;âõîäíûå äàííûå: es- ñåãìåíò ãäå ëåæèò ôàéë äëÿ ïàðñèíãà ò.å. startos.ini
|
|
;di - óêàçàòåëü íà èìÿ ôàéëà ò.å. es:di óêàçûâàåò íà èìÿ ôàéëà íàçíà÷åíèÿ
|
|
;âûõîäíûå äàííûå eax =-1 èìÿ ñîâïàëî, eax=0 èìÿ íå ñîâïàëî.
|
|
{
|
|
local .no_equal
|
|
local .exit
|
|
local .loop_size_root_dir
|
|
;âû÷èñëèì äëèííó ñòðî÷êè èìåíè íàçíà÷åíèÿ, êîòîðóþ áóäåì ñðàâíèâàòü ñ óæå çàïèñàííûìè äàííûìè.
|
|
;ïðåîáðàçóåì â àíàëîã ôàò çàïèñè ñòî÷êó ñ èìåíåì íàçíà÷åíèÿ
|
|
convertion_file_name ; ïðåîáðàçîâàëè èìÿ ïî íóæíûì ïðàâèëàì
|
|
test ax,ax
|
|
jnz .exit
|
|
|
|
lea si,[shot_name_fat] ; desination name of file
|
|
|
|
;âû÷èñëèì óêàçàòåëü íà êîðíåâóþ äèðåêòîðèþ
|
|
mov di,firstDataSect
|
|
sub di,size_root_dir
|
|
;òåïåðü â ax ðàçìåð â ñåêòîðàõ íà÷àëà ðóò äèð
|
|
shl di,9 ;imul 512
|
|
;di= Ýòî ñìåùåíèå îò íà÷àëà áóôåðà äî ðóò äèðåêòîðèè. â ïðåäåëàõ 64 êá.
|
|
;çàãðóçèì çíà÷åíèå - ò.å. êîë-âî ýëåìåíòîâ, êîòîðûå ìû ìîæåì ïðîñìàòðèâàòü.
|
|
mov dx,root_dir_entry_count
|
|
|
|
mov ax,info_real_mode_size
|
|
add ax,0x1000
|
|
|
|
|
|
mov gs,ax
|
|
.loop_size_root_dir:
|
|
DEBUG1 equ 0
|
|
if DEBUG1
|
|
pushad
|
|
push di
|
|
mov eax,dword[gs:di]
|
|
lea si,[check_root_fat_+14]
|
|
mov dword [ds:si],'----'
|
|
mov dword [ds:si+4],'----'
|
|
mov dword [ds:si+8],'----'
|
|
mov dword[ds:si],eax
|
|
mov eax,dword[gs:di+4]
|
|
mov dword[ds:si+4],eax
|
|
mov eax,dword[gs:di+8]
|
|
mov dword[ds:si+8],eax
|
|
|
|
;
|
|
xor eax,eax
|
|
mov ax,gs;point_next_fat_str
|
|
mov cx,0x0a
|
|
mov di,check_root_fat_
|
|
mov dword [di],' '
|
|
mov word [di+4],' '
|
|
call decode
|
|
xor eax,eax
|
|
pop ax
|
|
mov di,(check_root_fat_+7)
|
|
mov dword [di],' '
|
|
mov word [di+4],' '
|
|
call decode
|
|
|
|
;Show size
|
|
lea si,[check_root_fat_]
|
|
call printplain
|
|
|
|
lea si,[shot_name_fat]
|
|
call printplain
|
|
|
|
xor ax,ax
|
|
int 0x16
|
|
popad
|
|
end if
|
|
|
|
xor bx,bx
|
|
mov cx,11 ;size of name in struct FAT
|
|
|
|
@@:
|
|
mov al,byte [ds:si+bx] ;ds:si - point to name of convertion variable.
|
|
mov ah,byte [gs:di+bx] ;gs:di - point to name in fat struct
|
|
inc bx
|
|
|
|
if DEBUG
|
|
; pushad
|
|
; lea si,[check_root_fat_+14]
|
|
; mov dword [ds:si],'----'
|
|
; mov word [ds:si],ax
|
|
; call printplain
|
|
|
|
; xor ax,ax
|
|
; int 0x16
|
|
|
|
; popad
|
|
end if
|
|
|
|
|
|
|
|
cmp ah,al
|
|
jnz .no_equal
|
|
|
|
; dec cx
|
|
; jnz @b
|
|
loop @b
|
|
|
|
;.succesfuly:
|
|
;ïå÷àëüíî, òàêîå èìÿ óæå èìååòñÿ :(
|
|
or ax,-1
|
|
jmp .exit
|
|
|
|
|
|
.no_equal:
|
|
add di,32 ;fat struct =32 byte
|
|
dec dx
|
|
jnz .loop_size_root_dir
|
|
|
|
;.exit_check_name:
|
|
and ax,0
|
|
|
|
.exit:
|
|
|
|
if DEBUG
|
|
pushad
|
|
;Show size
|
|
lea si,[check_name_fat_msg_n]
|
|
test ax,ax
|
|
jz @f
|
|
lea si,[check_name_fat_msg_y]
|
|
call printplain
|
|
lea si,[alarm_msg]
|
|
@@: call printplain
|
|
popad
|
|
end if
|
|
|
|
}
|
|
|
|
|
|
macro convertion_file_name
|
|
;ìàêðîñ êîíâåðòàöèè èìåíè, ýòî íóæíî ïîñêîëüêó ôîðìàò ïðåäñòàâëåííûé íå ñîîòâåòñâóåò ôàò è íàïðÿìóþ ðåäêî ìîæíî êîãäà èñïîëüçîâàòü
|
|
;ïðåîáðàçîâàíèå èìåíè òèïà hello.asm â 'HELLO ASM', â ñîîòâåòñòâèè ñ ïðàâèëàìè fat.
|
|
;âõîäíûå ïàðàìåòðû es:di óêàçàòåëü íà èìÿ ôàéëà êîòîðîå íóæíî ïðåîáðàçîâàòü, êîíå÷íûé áóôåð shot_name_fat
|
|
{
|
|
local .next_step
|
|
local .error
|
|
local .st1
|
|
local .st2
|
|
local .st2_l
|
|
local .st3
|
|
local .st4_s
|
|
local .st4
|
|
local .st5
|
|
|
|
;âû÷èñëèì äëèííó ñòðî÷êè èìåíè íàçíà÷åíèÿ, êîòîðóþ áóäåì ñðàâíèâàòü ñ óæå çàïèñàííûìè äàííûìè.
|
|
; mov di,point_to_dest_file_name âõîäíîé ïàðàìåòð
|
|
mov si,shot_name_fat
|
|
or first_input,-1 ;ïðè ïåðâîì âõîäå óñòàíàâëèâàåì ôëàã
|
|
mov cx,11 ;äëèííà èìåíè â ñòóêòóðå ôàò òàáëèöû
|
|
|
|
@@:
|
|
mov al,byte [es:di]
|
|
cmp al,0xa
|
|
jz .st4_s
|
|
cmp al,0xd
|
|
jz .st4_s
|
|
cmp al,0x20
|
|
jz .st4_s
|
|
|
|
cmp al,0x20
|
|
jb .error
|
|
cmp al,0x22
|
|
jz .error
|
|
cmp al,0x2a
|
|
jz .error
|
|
cmp al,0x2b
|
|
jz .error
|
|
cmp al,0x2c
|
|
jz .error
|
|
cmp al,0x2F
|
|
jz .error
|
|
|
|
cmp al,0x3a
|
|
jz .error
|
|
cmp al,0x3b
|
|
jz .error
|
|
cmp al,0x3c
|
|
jz .error
|
|
cmp al,0x3d
|
|
jz .error
|
|
cmp al,0x3E
|
|
jz .error
|
|
cmp al,0x3F
|
|
jz .error
|
|
|
|
cmp al,0x5b
|
|
jz .error
|
|
cmp al,0x5c
|
|
jz .error
|
|
cmp al,0x5d
|
|
jz .error
|
|
|
|
cmp al,0x7c
|
|
jz .error
|
|
|
|
|
|
cmp first_input,-1
|
|
jnz .next_step
|
|
and first_input,0 ;ñáîðîñèì ôëàã.
|
|
cmp al,'.'
|
|
jz .error ;îáðàáîòêà òî÷êè, ôàéë íå ìîæåò íà÷èíàòüñÿ ñ òî÷êè
|
|
|
|
.next_step:
|
|
cmp al,0x2e
|
|
jnz .st2 ;îáðàáîòêà òî÷êè, â ñåðåäèíå ôàéëà
|
|
;òóò ó íàñ óñòàíîâëåí ðàçäåëèòåëü
|
|
;âñå îñòàëüíåî ìåñòî çàéìóò ïðîáåëû
|
|
mov al,' '
|
|
|
|
;!fixme îáðàáîòàíû íå âñå èñêëþ÷åíèÿ :(
|
|
cmp cl,3 ;ôîðìàò ôàéëà òàêîé GIDGIDIIASM ò.å. gidgidii.asm
|
|
jbe .st2
|
|
|
|
|
|
.st3:
|
|
mov byte [si],al
|
|
inc si
|
|
dec cx
|
|
cmp cx,3
|
|
ja .st3
|
|
; inc cx
|
|
inc di
|
|
jmp @b
|
|
|
|
.st2:
|
|
cmp al,0x60
|
|
jbe .st2_l
|
|
|
|
xor al,0x20 ;ñäåëàåì çàãëàâíûå áóêâû
|
|
.st2_l: mov byte [si],al
|
|
inc di
|
|
inc si
|
|
; dec cx
|
|
; jnz @b
|
|
loop @b
|
|
.st5: xor ax,ax
|
|
jmp @f
|
|
|
|
;;;;;;;;ôàéë çàêîí÷èëñÿ, è íóæíî âíåñòè â êîíåö ïðîáåëû
|
|
.st4_s: mov al,' '
|
|
.st4: mov byte [si],al
|
|
inc si
|
|
loop .st4
|
|
jmp .st5
|
|
|
|
.error: or ax,-1
|
|
@@:
|
|
|
|
if DEBUG
|
|
pushad
|
|
|
|
mov si,convertion_file_name_msg_y
|
|
test ax,ax
|
|
jz @f
|
|
mov si,convertion_file_name_msg_n
|
|
@@: call printplain
|
|
|
|
mov si,shot_name_fat
|
|
mov byte [si+12],0
|
|
call printplain
|
|
popad
|
|
|
|
end if
|
|
}
|
|
|
|
macro move_file_up
|
|
;ìàêðîñ êîòîðûé ïåðåìåùàåò çà 1 ìá ñ ïðàâèëàìè ôàò äàííûå ôàéëà.
|
|
{
|
|
local .st1
|
|
local .correct_on_byte
|
|
;ñåé÷àñ èìååò áûòü ñèòóàöèÿ, êîãäà BPB óæå ïåðåìåùåí çà 1 ìá, ôàò, è ðóò äèð áóäóò ïîçæå ïåðåìåùåíû,
|
|
;à íàì íóæíî âû÷èñëèòü ìåñòî, è ïåðåíåñòè òóäà ñîäåðæèìîå ôàéëà
|
|
;ïîëó÷åíîå çíà÷åíèå óêàçûâàåò â áàéòàõ íà íà÷àëî äàííûõ
|
|
|
|
mov ax,info_real_mode_size ; ñåãìåíò ãäå ðàñïîëîæåíû äàííûå
|
|
mov si,table_15_87
|
|
mov word [si+8*2+2],ax
|
|
;ñìåùåíèå äî äàííûõ óæå çà 1-ì ìá
|
|
movzx eax,firstDataSect
|
|
movzx edx,data_offset
|
|
add eax,edx
|
|
|
|
movzx ebx,word [fat12_buffer.BPB_BytsPerSec]
|
|
movzx edx,byte [fat12_buffer.BPB_SecPerClus]
|
|
imul bx,dx ;ïîëó÷èì ðàçìåð êëàñòåðà
|
|
|
|
|
|
|
|
push ebx ;save bx
|
|
|
|
imul eax,ebx
|
|
; shl eax,9 ;óìíîæèì íà 512
|
|
|
|
if DEBUG
|
|
pushad
|
|
xor eax,eax
|
|
mov ax,info_real_mode_size
|
|
mov cx,0x0a
|
|
mov di,seg_where_get_data
|
|
mov dword [di],' '
|
|
mov word [di+4],' '
|
|
call decode
|
|
;Show size
|
|
mov si,seg_where_get_data
|
|
call printplain
|
|
popad
|
|
|
|
end if
|
|
|
|
; mov bx,word [fat12_buffer.BPB_BytsPerSec]
|
|
; movzx dx,byte [fat12_buffer.BPB_SecPerClus]
|
|
; imul bx,dx
|
|
; cwd
|
|
; idiv bx
|
|
|
|
mov dl,0x10
|
|
|
|
@@: cmp eax,0x00010000
|
|
jb @f
|
|
|
|
sub eax,0x00010000
|
|
inc dl
|
|
jmp @b
|
|
|
|
|
|
@@: mov byte [si+8*3+3],dl ;êóäà ïèñàòü
|
|
mov word [si+8*3+2],ax
|
|
|
|
mov ecx,save_file_size ;ðàçìåð ôàéëà â áàéòàõ.
|
|
cmp ecx,0x0000ffff ;ðàçìåð áëîêà ò.å. 64 êá
|
|
jbe .correct_on_byte ;êîððåêòèðîâêà íà áàéò çíà÷åíèÿ
|
|
|
|
|
|
|
|
mov ecx,0x00010000 ;65536
|
|
sub save_file_size,ecx ;îòíèìèì
|
|
; jmp .st1 ;ïîëó÷èì 0õ8000
|
|
|
|
|
|
|
|
|
|
;êîððåêòèðîâêà çíà÷åíèÿ äîëæíà áûòü âûïîëåíåíà íà ðàçìåð êëàñòåðà
|
|
.correct_on_byte:
|
|
;/óçíàåì ðàçìåð êëàñòåðà
|
|
pop eax ;restore size of claster
|
|
push ecx
|
|
@@: inc data_offset
|
|
|
|
cmp eax,ecx
|
|
jae @f
|
|
sub ecx,eax
|
|
jmp @b
|
|
@@: pop ecx
|
|
|
|
|
|
|
|
|
|
test ecx,0x1
|
|
jz .st1
|
|
inc ecx
|
|
.st1: shr ecx,1 ; ïðåîáðàçîâàòü çíà÷åíèå äëÿ 0x87 function
|
|
|
|
;ïåðåíåñåì áëîê çà 1 ìá
|
|
push es
|
|
push ds
|
|
pop es
|
|
|
|
mov ah, 0x87
|
|
int 0x15
|
|
pop es
|
|
|
|
if DEBUG
|
|
pusha
|
|
; mov ax,point_next_fat_str
|
|
mov cx,0x0a
|
|
mov di,return_code_af_move
|
|
call decode
|
|
;Show size
|
|
mov si,return_code_af_move
|
|
call printplain
|
|
popa
|
|
|
|
end if
|
|
|
|
}
|
|
|
|
|
|
macro move_up_fat_and_root_d
|
|
;ìàêðîñ, êîòîðûé ïîçâîëÿåò ïåðåíåñòè âûøå 1 ìá â ñòðóêòóðó îáðàçà ôàò òàáëèöó è ðóò äèðåêòîðèþ
|
|
{
|
|
local .st1
|
|
|
|
mov ax,info_real_mode_size
|
|
add ax,0x1000
|
|
|
|
mov si,table_15_87
|
|
mov word [si+8*2+2],ax
|
|
;ñìåùåíèå äî äàííûõ
|
|
mov ax,512
|
|
mov word [si+8*3+2],ax
|
|
;fixme! òóò íåîáõîäèìî ñäåëàòü ïîäåðæêó ò.å. ôîðìèðîâàòü ñìåùåíèå ôàéëà â óæå çàïèñàííûõ äàííûõ.
|
|
|
|
movzx ecx,word [fat12_buffer.BPB_FATSz16]
|
|
movzx bx,byte [fat12_buffer.BPB_NumFATs]
|
|
imul cx,bx ;9x1=9
|
|
|
|
add cx,size_root_dir ;ðàçìåð êîðíåâîé äèððåêòîðèè
|
|
shl ecx,9 ;imul 512
|
|
|
|
|
|
;êîððåêòèðîâêà çíà÷åíèÿ
|
|
test ecx,0x1
|
|
jz .st1
|
|
inc ecx
|
|
.st1: shr ecx,1
|
|
|
|
push es
|
|
push ds
|
|
pop es
|
|
|
|
mov ah, 0x87
|
|
int 0x15
|
|
pop es
|
|
|
|
if DEBUG
|
|
pusha
|
|
; mov ax,point_next_fat_str
|
|
mov cx,0x0a
|
|
mov di,return_code_af_fat_m
|
|
call decode
|
|
;Show size
|
|
mov si,return_code_af_fat_m
|
|
call printplain
|
|
popa
|
|
|
|
end if
|
|
|
|
} |