From 17da7e7f7af8afd40c344b6b5e05da12a1437e4e Mon Sep 17 00:00:00 2001 From: "Evgeny Grechnikov (Diamond)" Date: Fri, 5 May 2006 12:40:02 +0000 Subject: [PATCH] File system: read folders with long names and in new standard System functions: many small corrections git-svn-id: svn://kolibrios.org@75 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/blkdev/flp_drv.inc | 8 +- kernel/trunk/blkdev/rd.inc | 355 ++++++++++++++++---- kernel/trunk/blkdev/rdsave.inc | 6 +- kernel/trunk/core/sys32.inc | 3 + kernel/trunk/core/syscall.inc | 14 +- kernel/trunk/fs/fat12.inc | 404 +++++++++++++++-------- kernel/trunk/fs/fat32.inc | 182 ++++++++++- kernel/trunk/fs/fs_lfn.inc | 558 +++++++++++++++++++++++--------- kernel/trunk/kernel.asm | 473 ++++++++++++++------------- kernel/trunk/video/vesa20.inc | 6 - 10 files changed, 1399 insertions(+), 610 deletions(-) diff --git a/kernel/trunk/blkdev/flp_drv.inc b/kernel/trunk/blkdev/flp_drv.inc index 411cf86b1d..b5e9cdb00b 100644 --- a/kernel/trunk/blkdev/flp_drv.inc +++ b/kernel/trunk/blkdev/flp_drv.inc @@ -42,6 +42,7 @@ MAX_Track equ 79 MAX_Head equ 1 MAX_Sector equ 18 +uglobal ; Счетчик тиков таймера TickCounter dd ? ; Код завершения операции с контроллером НГМД @@ -69,6 +70,7 @@ FDC_N DB ? ReadRepCounter DB ? ; Счетчик повторения операции рекалибровки RecalRepCounter DB ? +endg ; Область памяти для хранения прочитанного сектора ;FDD_DataBuffer: times 512 db 0 ;DB 512 DUP (?) fdd_motor_status db 0 @@ -111,13 +113,13 @@ Init_FDC_DMA: ;*********************************** FDCDataOutput: ; pusha - push ax cx dx + push eax ecx edx mov AH,AL ;запомнить байт в AH ; Сбросить переменную состояния контроллера mov [FDC_Status],FDC_Normal ; Проверить готовность контроллера к приему данных mov DX,3F4h ;(порт состояния FDC) - xor CX,CX ;установить счетчик тайм-аута + mov ecx, 0x10000 ;установить счетчик тайм-аута @@TestRS: in AL,DX ;прочитать регистр RS and AL,0C0h ;выделить разряды 6 и 7 @@ -134,7 +136,7 @@ FDCDataOutput: out DX,AL @@End_5: ; popa - pop dx cx ax + pop edx ecx eax ret ;****************************************** diff --git a/kernel/trunk/blkdev/rd.inc b/kernel/trunk/blkdev/rd.inc index 148af37ea3..139ff0ed09 100644 --- a/kernel/trunk/blkdev/rd.inc +++ b/kernel/trunk/blkdev/rd.inc @@ -553,7 +553,7 @@ uni2ansi_str: add al, 0x70 jmp .doit .rus2: -; 0x440-0x450 -> 0xE0-0xEF +; 0x440-0x44F -> 0xE0-0xEF add al, 0xA0 .ascii: .doit: @@ -563,6 +563,43 @@ uni2ansi_str: mov byte [edi], 0 ret +ansi2uni_char: +; convert ANSI character in al to UNICODE character in ax, using cp866 encoding + mov ah, 0 +; 0x00-0x7F - trivial map + cmp al, 0x80 + jb .ret +; 0x80-0xAF -> 0x410-0x43F + cmp al, 0xB0 + jae @f + add ax, 0x410-0x80 +.ret: + ret +@@: +; 0xE0-0xEF -> 0x440-0x44F + cmp al, 0xE0 + jb .unk + cmp al, 0xF0 + jae @f + add ax, 0x440-0xE0 + ret +; 0xF0 -> 0x401 +; 0xF1 -> 0x451 +@@: + cmp al, 'р' + jz .yo1 + cmp al, 'с' + jz .yo2 +.unk: + mov al, '_' ; ah=0 + ret +.yo1: + mov ax, 0x401 + ret +.yo2: + mov ax, 0x451 + ret + char_toupper: ; convert character to uppercase, using cp866 encoding ; in: al=symbol @@ -606,7 +643,9 @@ fat_get_name: jz .longname push ecx mov ecx, 8 - push edi ebp ecx + push edi ebp ecx + cmp byte [ebp-4], 0 + jnz .unicode_short @@: mov al, [edi] inc edi @@ -641,6 +680,49 @@ fat_get_name: and byte [ebp], 0 ; CF=0 pop ebp edi ecx ret +.unicode_short: +@@: + mov al, [edi] + inc edi + call ansi2uni_char + mov [ebp], ax + inc ebp + inc ebp + loop @b + pop ecx +@@: + cmp word [ebp-2], ' ' + jnz @f + dec ebp + dec ebp + loop @b +@@: + mov word [ebp], '.' + inc ebp + inc ebp + mov ecx, 3 + push ecx +@@: + mov al, [edi] + inc edi + call ansi2uni_char + mov [ebp], ax + inc ebp + inc ebp + loop @b + pop ecx +@@: + cmp word [ebp-2], ' ' + jnz @f + dec ebp + dec ebp + loop @b + dec ebp + dec ebp +@@: + and word [ebp], 0 ; CF=0 + pop ebp edi ecx + ret .longname: ; LFN mov al, byte [edi] @@ -681,12 +763,15 @@ fat_get_name: ret @@: ; if this is first entry: + cmp byte [ebp-4], 0 + jnz .ret ; buffer at ebp contains UNICODE name, convert it to ANSI push esi edi mov esi, ebp mov edi, ebp call uni2ansi_str pop edi esi +.ret: clc ret @@ -725,6 +810,76 @@ fat_compare_name: pop esi ebp ret +fat_time_to_bdfe: +; in: eax=FAT time +; out: eax=BDFE time + push ecx edx + mov ecx, eax + mov edx, eax + shr eax, 11 + shl eax, 16 ; hours + and edx, 0x1F + add edx, edx + mov al, dl ; seconds + shr ecx, 5 + and ecx, 0x3F + mov ah, cl ; minutes + pop edx ecx + ret + +fat_date_to_bdfe: + push ecx edx + mov ecx, eax + mov edx, eax + shr eax, 9 + add ax, 1980 + shl eax, 16 ; year + and edx, 0x1F + mov al, dl ; day + shr ecx, 5 + and ecx, 0xF + mov ah, cl ; month + pop edx ecx + ret + +fat_entry_to_bdfe: +; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi +; destroys eax + movzx eax, byte [edi+11] + mov [esi], eax ; attributes + mov eax, [ebp-4] + mov [esi+4], eax ; ASCII/UNICODE name + movzx eax, word [edi+14] + call fat_time_to_bdfe + mov [esi+8], eax ; creation time + movzx eax, word [edi+16] + call fat_date_to_bdfe + mov [esi+12], eax ; creation date + and dword [esi+16], 0 ; last access time is not supported on FAT + movzx eax, word [edi+18] + call fat_date_to_bdfe + mov [esi+20], eax ; last access date + movzx eax, word [edi+22] + call fat_time_to_bdfe + mov [esi+24], eax ; last write time + movzx eax, word [edi+24] + call fat_date_to_bdfe + mov [esi+28], eax ; last write date + mov eax, [edi+28] + mov [esi+32], eax ; file size (low dword) + xor eax, eax + mov [esi+36], eax ; file size (high dword) + push ecx edi + lea edi, [esi+40] + mov esi, ebp + mov ecx, 259/2 + rep movsd + movsw + stosw + mov esi, edi + pop edi ecx + ret + rd_find_lfn: ; in: esi->name ; out: CF=1 - file not found @@ -732,6 +887,7 @@ rd_find_lfn: push esi ebp edi sub esp, 262*2 ; allocate space for LFN mov ebp, esp ; ebp points to buffer + push 0 ; for fat_get_name: read ASCII name mov edi, 0x100000+512*19 ; to root dir .l1: call fat_get_name @@ -743,7 +899,7 @@ rd_find_lfn: cmp edi, 0x100000+512*33 jb .l1 .notfound: - add esp, 262*2 + add esp, 262*2+4 pop edi ebp esi stc ret @@ -757,7 +913,7 @@ rd_find_lfn: ; folders are not supported cmp byte [esi], 0 jnz .notfound - add esp, 262*2+4 ; CF=0 + add esp, 262*2+4+4 ; CF=0 pop ebp esi ret @@ -776,79 +932,146 @@ rd_find_lfn: ; ;-------------------------------------------------------------- fs_RamdiskRead: - cmp byte [esi], 0 - jnz @f - or ebx, -1 - mov eax, 10 ; access denied - ret + cmp byte [esi], 0 + jnz @f + or ebx, -1 + mov eax, 10 ; access denied + ret @@: - push edi - call rd_find_lfn - jnc .found - pop edi - or ebx, -1 - mov eax, 5 ; file not found - ret + push edi + call rd_find_lfn + jnc .found + pop edi + or ebx, -1 + mov eax, 5 ; file not found + ret .found: - test ebx, ebx - jz .l1 - cmp dword [ebx+4], 0 - jz @f - mov ebx, [edi+28] + test ebx, ebx + jz .l1 + cmp dword [ebx+4], 0 + jz @f + mov ebx, [edi+28] .reteof: - mov eax, 6 ; EOF - pop edi - ret + mov eax, 6 ; EOF + pop edi + ret @@: - mov ebx, [ebx] + mov ebx, [ebx] .l1: - push dword [edi+28] ; file size - push dword [edi+28] - movzx edi, word [edi+26] ; cluster - push ecx edx + push dword [edi+28] ; file size + push dword [edi+28] + movzx edi, word [edi+26] ; cluster + push ecx edx .new: - jecxz .done - test edi, edi - jz .eof - cmp edi, 0xFF8 - jae .eof - lea eax, [edi+31] ; bootsector+2*fat+filenames - shl eax, 9 ; *512 - add eax, 0x100000 ; image base + jecxz .done + test edi, edi + jz .eof + cmp edi, 0xFF8 + jae .eof + lea eax, [edi+31] ; bootsector+2*fat+filenames + shl eax, 9 ; *512 + add eax, 0x100000 ; image base ; now eax points to data of cluster - sub ebx, 512 - jae .skip - lea eax, [eax+ebx+512] - neg ebx - push ecx - cmp ecx, ebx - jbe @f - mov ecx, ebx + sub ebx, 512 + jae .skip + lea eax, [eax+ebx+512] + neg ebx + push ecx + cmp ecx, ebx + jbe @f + mov ecx, ebx @@: - cmp ecx, [esp+12] - jbe @f - mov ecx, [esp+12] + cmp ecx, [esp+12] + jbe @f + mov ecx, [esp+12] @@: - mov ebx, edx - call memmove - add edx, ecx - sub [esp], ecx - sub [esp+12], ecx - pop ecx - xor ebx, ebx - cmp [esp+8], ebx - jnz .skip - jecxz .done - jmp .eof + mov ebx, edx + call memmove + add edx, ecx + sub [esp], ecx + sub [esp+12], ecx + pop ecx + xor ebx, ebx + cmp [esp+8], ebx + jnz .skip + jecxz .done + jmp .eof .skip: - movzx edi, word [edi*2+0x280000] ; find next cluster from FAT - jmp .new + movzx edi, word [edi*2+0x280000] ; find next cluster from FAT + jmp .new .eof: - pop edx ecx ebx ebx - jmp .reteof + pop edx ecx ebx ebx + jmp .reteof .done: - pop edx ecx ebx ebx edi - xor eax, eax - ret + pop edx ecx ebx ebx edi + xor eax, eax + ret + +;---------------------------------------------------------------- +; +; fs_RamdiskReadFolder - LFN variant for reading sys floppy folder +; +; esi points to filename; only root is folder on ramdisk +; ebx pointer to 32-bit number = first wanted block +; ecx number of blocks to read, 0+ +; edx mem location to return data +; +; ret ebx = size or 0xffffffff file not found +; eax = 0 ok read or other = errormsg +; +;-------------------------------------------------------------- +fs_RamdiskReadFolder: + mov ebx, [ebx] + cmp byte [esi], 0 + jz @f +; ramdisk doesn't support folders + mov eax, ERROR_ACCESS_DENIED + or ebx, -1 + ret +@@: + push esi edi ecx +; init header + push ecx + mov edi, edx + mov ecx, 32/4 + xor eax, eax + rep stosd + mov byte [edx], 1 ; version + pop ecx + push ebp + sub esp, 262*2 ; allocate space for LFN + mov ebp, esp + push 1 ; for fat_get_name: read UNICODE name +; read root + mov esi, edi ; esi points to block of data of folder entry (BDFE) + mov edi, 0x100000+512*19 +.l1: + call fat_get_name + jc .l2 + cmp byte [edi+11], 0xF + jnz @f + add edi, 0x20 +@@: + inc dword [edx+8] ; new file found + dec ebx + jns .l2 + dec ecx + js .l2 + inc dword [edx+4] ; new file block copied + call fat_entry_to_bdfe +.l2: + add edi, 0x20 + cmp edi, 0x100000+512*33 + jb .l1 + add esp, 262*2+4 + pop ebp + mov ebx, [edx+8] + xor eax, eax + dec ecx + js @f + mov al, ERROR_END_OF_FILE +@@: + pop ecx edi esi + ret ; \end{diamond} \ No newline at end of file diff --git a/kernel/trunk/blkdev/rdsave.inc b/kernel/trunk/blkdev/rdsave.inc index abfa8963b3..3065971642 100644 --- a/kernel/trunk/blkdev/rdsave.inc +++ b/kernel/trunk/blkdev/rdsave.inc @@ -1,5 +1,4 @@ - cmp eax,6 ; SAVE FLOPPY IMAGE (HD version only) - jnz nosaveimage +sysfn_saveramdisk: ; 18.6 = SAVE FLOPPY IMAGE (HD version only) cmp ebx,1 jnz img_save_hd_1 mov edx,bootpath ; path = '/KOLIBRI ' @@ -21,6 +20,5 @@ mov ebx,1440*1024 ; size 1440 Kb mov ecx,0x100000 ; address of image call file_write + mov [esp+36],eax ret - - nosaveimage: diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index e10e4b68d8..b5ed7e1906 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -465,10 +465,13 @@ irqhandler: add esi,irq00read ; 1 shl edi,12 ; 1 add edi,0x2E0000 + mov ecx,16 mov [check_idle_semaphore],5 irqnewread: + dec ecx + js irqover mov dx,[esi] ; 2+ diff --git a/kernel/trunk/core/syscall.inc b/kernel/trunk/core/syscall.inc index f19d69ba3d..004cf59700 100644 --- a/kernel/trunk/core/syscall.inc +++ b/kernel/trunk/core/syscall.inc @@ -86,7 +86,7 @@ iglobal dd sys_background ; 15-bgr dd sys_cachetodiskette ; 16-FlushFloppyCache dd sys_getbutton ; 17-GetButton - dd syscall_system ; 18-Shutdown,KillApp,WindowActivate + dd sys_system ; 18-System Services dd syscall_startapp ; 19-StartApp dd sys_midi ; 20-ResetMidi and OutputMidi dd sys_setup ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,. @@ -98,11 +98,14 @@ iglobal dd sys_wss ; 27-SetWssMainVol and SetWssCdVol dd sys_sb16II ; 28-SetSb16 dd sys_date ; 29-GetDate - dd syscall_readhd ; 30-ReadHd - dd syscall_starthdapp ; 31-StartHdApp +; dd syscall_readhd ; 30-ReadHd - obsolete + dd undefined_syscall ; 30-reserved +; dd syscall_starthdapp ; 31-StartHdApp - obsolete + dd undefined_syscall ; 31-reserved dd syscall_delramdiskfile ; 32-DelRamdiskFile dd syscall_writeramdiskfile; 33-WriteRamdiskFile - dd read_floppy_file ; 34-ReadFloppyDrive +; dd read_floppy_file ; 34-ReadFloppyDrive - obsolete + dd undefined_syscall ; 34-reserved dd syscall_getpixel ; 35-GetPixel dd syscall_readstring ; 36-ReadString (not yet ready) dd readmousepos ; 37-GetMousePosition_ScreenRelative,. @@ -125,7 +128,8 @@ iglobal dd user_events ; 54-User events dd sound_interface ; 55-Sound interface dd write_to_hd ; 56-Write a file to hd - dd delete_from_hd ; 57-Delete a file from hd +; dd delete_from_hd ; 57-Delete a file from hd - obsolete + dd undefined_syscall ; 57-reserved dd file_system ; 58-Common file system interface dd sys_trace ; 59-System call trace dd new_sys_ipc ; 60-Inter Process Communication diff --git a/kernel/trunk/fs/fat12.inc b/kernel/trunk/fs/fat12.inc index b0b24aa86f..69520ef6af 100644 --- a/kernel/trunk/fs/fat12.inc +++ b/kernel/trunk/fs/fat12.inc @@ -1088,80 +1088,81 @@ fd_find_lfn: ; in: esi->name ; out: CF=1 - file not found ; else CF=0 and edi->direntry - pusha - sub esp, 262*2 ; reserve place for LFN - mov ebp, esp - call read_flp_fat - cmp [FDC_Status], 0 - jnz .error - mov eax, 19 - mov dh, 14 + pusha + sub esp, 262*2 ; reserve place for LFN + mov ebp, esp + push 0 ; for fat_get_name: read ASCII name + call read_flp_fat + cmp [FDC_Status], 0 + jnz .error + mov eax, 19 + mov dh, 14 .main_loop: .20_1: - pusha - call read_chs_sector - popa - cmp [FDC_Status], 0 - jnz .error - mov edi, 0xD000 - inc [FDD_Sector] - push eax + pusha + call read_chs_sector + popa + cmp [FDC_Status], 0 + jnz .error + mov edi, 0xD000 + inc [FDD_Sector] + push eax .21_1: - call fat_get_name - jc @f - call fat_compare_name - jz .found + call fat_get_name + jc @f + call fat_compare_name + jz .found @@: - add edi, 0x20 - cmp edi, 0xD200 - jb .21_1 - pop eax - inc eax - dec dh - js @f - jnz .20_1 + add edi, 0x20 + cmp edi, 0xD200 + jb .21_1 + pop eax + inc eax + dec dh + js @f + jnz .20_1 .error: - add esp, 262*2 - popa - stc - ret + add esp, 262*2+4 + popa + stc + ret @@: ; read next sector from FAT - mov eax, [(eax-31)*2+0x282000] - and eax, 0xFFF - cmp eax, 0xFF8 - jae .error - add eax, 31 - jmp .main_loop + mov eax, [(eax-31-1)*2+0x282000] + and eax, 0xFFF + cmp eax, 0xFF8 + jae .error + add eax, 31 + jmp .main_loop .found: - pop eax + pop eax ; if LFN entry, advance to corresponding short entry - cmp byte [edi+11], 0xF - jnz .entryfound - add edi, 0x20 - cmp edi, 0xD200 - jb .entryfound - dec dh - jz .error - inc eax - call read_chs_sector - cmp [FDC_Status], 0 - jnz .error - mov edi, 0xD000 + cmp byte [edi+11], 0xF + jnz .entryfound + add edi, 0x20 + cmp edi, 0xD200 + jb .entryfound + dec dh + jz .error + inc eax + call read_chs_sector + cmp [FDC_Status], 0 + jnz .error + mov edi, 0xD000 .entryfound: - cmp byte [esi], 0 - jz .done - test byte [edi+11], 10h ; is a directory? - jz .error - movzx eax, word [edi+26] - add eax, 31 - mov dh, 0 - jmp .main_loop + cmp byte [esi], 0 + jz .done + test byte [edi+11], 10h ; is a directory? + jz .error + movzx eax, word [edi+26] + add eax, 31 + mov dh, 0 + jmp .main_loop .done: - add esp, 262*2+4 - push edi - popad - ret + add esp, 262*2+4+4 + push edi + popad + ret ;---------------------------------------------------------------- ; @@ -1178,87 +1179,222 @@ fd_find_lfn: ; ;-------------------------------------------------------------- fs_FloppyRead: - mov [save_flag], 0 - cmp byte [esi], 0 - jnz @f - or ebx, -1 - mov eax, 10 ; access denied - ret + call read_flp_fat + cmp byte [esi], 0 + jnz @f + or ebx, -1 + mov eax, 10 ; access denied + ret @@: - push edi - call fd_find_lfn - jnc .found - pop edi - or ebx, -1 - mov eax, 5 ; file not found - ret + push edi + call fd_find_lfn + jnc .found + pop edi + or ebx, -1 + mov eax, 5 ; file not found + ret .found: - test ebx, ebx - jz .l1 - cmp dword [ebx+4], 0 - jz @f - mov ebx, [edi+28] + test ebx, ebx + jz .l1 + cmp dword [ebx+4], 0 + jz @f + mov ebx, [edi+28] .reteof: - mov eax, 6 ; EOF - pop edi - ret + mov eax, 6 ; EOF + pop edi + ret @@: - mov ebx, [ebx] + mov ebx, [ebx] .l1: - push dword [edi+28] - push dword [edi+28] - movzx edi, word [edi+26] - push ecx edx + push dword [edi+28] + push dword [edi+28] + movzx edi, word [edi+26] + push ecx edx .new: - jecxz .done - test edi, edi - jz .eof - cmp edi, 0xFF8 - jae .eof - mov eax, edi - add eax, 31 - pusha - call read_chs_sector - popa - cmp [FDC_Status], 0 - jnz .err - sub ebx, 512 - jae .skip - lea eax, [eax+ebx+512] - neg ebx - push ecx - cmp ecx, ebx - jbe @f - mov ecx, ebx + jecxz .done + test edi, edi + jz .eof + cmp edi, 0xFF8 + jae .eof + mov eax, edi + add eax, 31 + pusha + call read_chs_sector + popa + cmp [FDC_Status], 0 + jnz .err + sub ebx, 512 + jae .skip + lea eax, [eax+ebx+512] + neg ebx + push ecx + cmp ecx, ebx + jbe @f + mov ecx, ebx @@: - cmp ecx, [esp+12] - jbe @f - mov ecx, [esp+12] + cmp ecx, [esp+12] + jbe @f + mov ecx, [esp+12] @@: - mov ebx, edx - mov eax, 0xD000 - call memmove - add edx, ecx - sub [esp], ecx - sub [esp+12], ecx - pop ecx - xor ebx, ebx - cmp [esp+8], ebx - jnz .skip - jecxz .done - jmp .eof + mov ebx, edx + mov eax, 0xD000 + call memmove + add edx, ecx + sub [esp], ecx + sub [esp+12], ecx + pop ecx + xor ebx, ebx + cmp [esp+8], ebx + jnz .skip + jecxz .done + jmp .eof .skip: - movzx edi, word [edi*2+0x282000] - jmp .new + movzx edi, word [edi*2+0x282000] + jmp .new .done: - pop edx ecx ebx ebx edi - xor eax, eax - ret + pop edx ecx ebx ebx edi + xor eax, eax + ret .eof: - pop edx ecx ebx ebx - jmp .reteof + pop edx ecx ebx ebx + jmp .reteof .err: - mov eax, 5 ; may be other error code? - pop edx ecx ebx ebx edi - ret + mov eax, 5 ; may be other error code? + pop edx ecx ebx ebx edi + ret + +;---------------------------------------------------------------- +; +; fs_FloppyReadFolder - LFN variant for reading floppy folders +; +; esi points to filename +; ebx pointer to 32-bit number = first wanted block, 0+ +; ecx number of blocks to read, 0+ +; edx mem location to return data +; +; ret ebx = size or 0xffffffff folder not found +; eax = 0 ok read or other = errormsg +; +;-------------------------------------------------------------- +fs_FloppyReadFolder: + call read_flp_fat + mov ebx, [ebx] + push edi + cmp byte [esi], 0 + jz .root + call fd_find_lfn + jnc .found + pop edi + or ebx, -1 + mov eax, ERROR_FILE_NOT_FOUND + ret +.found: + test byte [edi+11], 0x10 ; do not allow read files + jnz .found_dir + pop edi + or ebx, -1 + mov eax, ERROR_ACCESS_DENIED + ret +.found_dir: + movzx eax, word [edi+26] + add eax, 31 + push 0 + jmp .doit +.root: + mov eax, 19 + push 14 +.doit: + push ecx ebp + sub esp, 262*2 ; reserve space for LFN + mov ebp, esp + push 1 ; for fat_get_name: read UNICODE names +; init header + push eax ecx + mov edi, edx + mov ecx, 32/4 + xor eax, eax + rep stosd + pop ecx eax + mov byte [edx], 1 ; version + mov esi, edi ; esi points to BDFE +.main_loop: + pusha + call read_chs_sector + popa + cmp [FDC_Status], 0 + jnz .error + mov edi, 0xD000 + push eax +.l1: + call fat_get_name + jc .l2 + cmp byte [edi+11], 0xF + jnz .do_bdfe + add edi, 0x20 + cmp edi, 0xD200 + jb .do_bdfe + pop eax + inc eax + dec byte [esp+262*2+12] + jz .done + jns @f +; read next sector from FAT + mov eax, [(eax-31-1)*2+0x282000] + and eax, 0xFFF + cmp eax, 0xFF8 + jae .done + add eax, 31 + mov byte [esp+262*2+12], 0 +@@: + pusha + call read_chs_sector + popa + cmp [FDC_Status], 0 + jnz .error + mov edi, 0xD000 + push eax +.do_bdfe: + inc dword [edx+8] ; new file found + dec ebx + jns .l2 + dec ecx + js .l2 + inc dword [edx+4] ; new file block copied + call fat_entry_to_bdfe +.l2: + add edi, 0x20 + cmp edi, 0xD200 + jb .l1 + pop eax + inc eax + dec byte [esp+262*2+12] + jz .done + jns @f +; read next sector from FAT + mov eax, [(eax-31-1)*2+0x282000] + and eax, 0xFFF + cmp eax, 0xFF8 + jae .done + add eax, 31 + mov byte [esp+262*2+12], 0 +@@: + jmp .main_loop +.error: + add esp, 262*2+4 + pop ebp ecx edi edi + or ebx, -1 + mov eax, ERROR_FILE_NOT_FOUND + ret +.done: + add esp, 262*2+4 + pop ebp + mov ebx, [edx+8] + xor eax, eax + dec ecx + js @f + mov al, ERROR_END_OF_FILE +@@: + pop ecx edi edi + ret + ; \end{diamond} \ No newline at end of file diff --git a/kernel/trunk/fs/fat32.inc b/kernel/trunk/fs/fat32.inc index 361086560e..0a895c5aa8 100644 --- a/kernel/trunk/fs/fat32.inc +++ b/kernel/trunk/fs/fat32.inc @@ -7,9 +7,10 @@ ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; ;; ;; ;; See file COPYING for details ;; +;; 04.05.2006 LFN read folder - diamond ;; ;; 29.04.2006 Elimination of hangup after the ;; ;; expiration hd_wait_timeout - Mario79 ;; -;; 23.04.2006 LFN read - diamond ;; +;; 23.04.2006 LFN read file - diamond ;; ;; 28.01.2006 find all Fat16/32 partition in all input point ;; ;; to MBR, see file part_set.inc - Mario79 ;; ;; 15.01.2005 get file size/attr/date, file_append - ATV ;; @@ -2933,9 +2934,10 @@ hd_find_lfn: ; in: esi->name ; out: CF=1 - file not found ; else CF=0 and edi->direntry - pusha - sub esp, 262*2 ; allocate space for LFN - mov ebp, esp + pusha + sub esp, 262*2 ; allocate space for LFN + mov ebp, esp + push 0 ; for fat_get_name: read ASCII name mov eax, [ROOT_CLUSTER] ; start from root .mainloop: .new_cluster: @@ -2990,7 +2992,7 @@ hd_find_lfn: cmp eax, [fatRESERVED] jb .new_cluster .notfound: - add esp, 262*2 + add esp, 262*2+4 popa stc ret @@ -3036,7 +3038,7 @@ hd_find_lfn: mov ax, [edi+26] jmp .mainloop .done: - add esp, 262*2+4 ; CF=0 + add esp, 262*2+4+4 ; CF=0 push edi popad ret @@ -3197,4 +3199,172 @@ fs_HdRead: .eof: pop ebx edx ecx ebx jmp .reteof + +;---------------------------------------------------------------- +; +; fs_HdReadFolder - LFN variant for reading hard disk folder +; +; esi points to filename +; ebx pointer to 32-bit number = first wanted block, 0+ +; ecx number of blocks to read, 0+ +; edx mem location to return data +; +; ret ebx = size or 0xffffffff folder not found +; eax = 0 ok read or other = errormsg +; +;-------------------------------------------------------------- +fs_HdReadFolder: + mov ebx, [ebx] + mov eax, [ROOT_CLUSTER] + push edi + cmp byte [esi], 0 + jz .doit + call hd_find_lfn + jnc .found + pop edi + or ebx, -1 + mov eax, ERROR_FILE_NOT_FOUND + ret +.found: + test byte [edi+11], 0x10 ; do not allow read files + jnz .found_dir + pop edi + or ebx, -1 + mov eax, ERROR_ACCESS_DENIED + ret +.found_dir: + mov eax, [edi+20-2] + mov ax, [edi+26] ; eax=cluster +.doit: + push esi ecx + push ebp + sub esp, 262*2 ; reserve space for LFN + mov ebp, esp + push 1 ; for fat_get_name: read UNICODE name +; init header + push eax ecx + mov edi, edx + mov ecx, 32/4 + xor eax, eax + rep stosd + pop ecx eax + mov byte [edx], 1 ; version + mov esi, edi ; esi points to BDFE +.new_cluster: + mov [cluster_tmp], eax + test eax, eax + jnz @f + cmp [fat_type], 32 + jz .notfound + mov eax, [ROOT_START] + push [ROOT_SECTORS] + push ebx + jmp .new_sector +@@: + dec eax + dec eax + imul eax, [SECTORS_PER_CLUSTER] + push [SECTORS_PER_CLUSTER] + add eax, [DATA_START] + push ebx +.new_sector: + mov ebx, buffer + mov edi, ebx + call hd_read + cmp [hd_error], 0 + jnz .notfound2 + add ebx, 512 + push eax +.l1: + call fat_get_name + jc .l2 + cmp byte [edi+11], 0xF + jnz .do_bdfe + add edi, 0x20 + cmp edi, ebx + jb .do_bdfe + pop eax + inc eax + dec dword [esp+4] + jnz @f + mov eax, [cluster_tmp] + test eax, eax + jz .done + call get_FAT + cmp [hd_error], 0 + jnz .notfound2 + cmp eax, 2 + jb .done + cmp eax, [fatRESERVED] + jae .done + push eax + mov eax, [SECTORS_PER_CLUSTER] + mov [esp+8], eax + pop eax + mov [cluster_tmp], eax + dec eax + dec eax + imul eax, [SECTORS_PER_CLUSTER] + add eax, [DATA_START] +@@: + mov ebx, buffer + mov edi, ebx + call hd_read + cmp [hd_error], 0 + jnz .notfound2 + add ebx, 512 + push eax +.do_bdfe: + inc dword [edx+8] ; new file found + dec dword [esp+4] + jns .l2 + dec ecx + js .l2 + inc dword [edx+4] ; new file block copied + call fat_entry_to_bdfe +.l2: + add edi, 0x20 + cmp edi, ebx + jb .l1 + pop eax + inc eax + dec dword [esp+4] + jnz .new_sector + mov eax, [cluster_tmp] + test eax, eax + jz .done + call get_FAT + cmp [hd_error], 0 + jnz .notfound2 + cmp eax, 2 + jb .done + cmp eax, [fatRESERVED] + jae .done + push eax + mov eax, [SECTORS_PER_CLUSTER] + mov [esp+8], eax + pop eax + pop ebx + add esp, 4 + jmp .new_cluster +.notfound2: + add esp, 8 +.notfound: + add esp, 262*2+4 + pop ebp ecx esi edi + mov eax, ERROR_FILE_NOT_FOUND + or ebx, -1 + ret +.done: + add esp, 262*2+4+8 + pop ebp + mov ebx, [edx+8] + xor eax, eax + dec ecx + js @f + mov al, ERROR_END_OF_FILE +@@: + pop ecx esi edi + ret + ; \end{diamond} diff --git a/kernel/trunk/fs/fs_lfn.inc b/kernel/trunk/fs/fs_lfn.inc index 55749de9da..90eba1a534 100644 --- a/kernel/trunk/fs/fs_lfn.inc +++ b/kernel/trunk/fs/fs_lfn.inc @@ -4,203 +4,455 @@ iglobal ; in this table names must be in lowercase rootdirs: - db 2,'rd' - dd fs_OnRamdisk - db 7,'ramdisk' - dd fs_OnRamdisk - db 2,'fd' - dd fs_OnFloppy - db 10,'floppydisk' - dd fs_OnFloppy - db 3,'hd0' - dd fs_OnHd0 - db 3,'hd1' - dd fs_OnHd1 - db 3,'hd2' - dd fs_OnHd2 - db 3,'hd3' - dd fs_OnHd3 - db 0 + db 2,'rd' + dd fs_OnRamdisk + dd fs_NextRamdisk + db 7,'ramdisk' + dd fs_OnRamdisk + dd fs_NextRamdisk + db 2,'fd' + dd fs_OnFloppy + dd fs_NextFloppy + db 10,'floppydisk' + dd fs_OnFloppy + dd fs_NextFloppy + db 3,'hd0' + dd fs_OnHd0 + dd fs_NextHd0 + db 3,'hd1' + dd fs_OnHd1 + dd fs_NextHd1 + db 3,'hd2' + dd fs_OnHd2 + dd fs_NextHd2 + db 3,'hd3' + dd fs_OnHd3 + dd fs_NextHd3 + db 0 + +virtual_root_query: + dd fs_HasRamdisk + du 'rd',0 + dd fs_HasFloppy + du 'fd',0 + dd fs_HasHd0 + du 'hd0',0 + dd fs_HasHd1 + du 'hd1',0 + dd fs_HasHd2 + du 'hd2',0 + dd fs_HasHd3 + du 'hd3',0 + dd 0 endg file_system_lfn: ; in: eax->fileinfo block ; operation codes: ; 0 : read file -; 1 : rewrite file - not implemented yet -; 2 : delete file - not implemented yet +; 1 : read folder +; 2 : rewrite file - not implemented yet ; 3 : write/append to file - not implemented yet -; 4 : create directory - not implemented yet -; 5 : rename file/directory - not implemented yet -; 6 : get file attributes structure - not implemented yet -; 7 : start application - not implemented yet -; 8 : find file with mask - not implemented yet +; 4 : start application - not implemented yet +; 5 : delete file - not implemented yet +; 6 : create directory - not implemented yet +; 7 : rename file/directory - not implemented yet +; 8 : get file attributes structure - not implemented yet + add eax, std_application_base_address ; parse file name - xchg ebx, eax - lea esi, [ebx+20] - lodsb - cmp al, '/' - jz @f + xchg ebx, eax + lea esi, [ebx+20] + lodsb + cmp al, '/' + jz @f .notfound: - mov dword [esp+36], 5 ; file not found - ret + mov dword [esp+36], 5 ; file not found + ret @@: - cmp byte [esi], 0 - jz .rootdir - mov edi, rootdirs-4 - xor ecx, ecx - push esi + cmp byte [esi], 0 + jz .rootdir + mov edi, rootdirs-8 + xor ecx, ecx + push esi .scan1: - pop esi - add edi, ecx - scasd - mov cl, byte [edi] - jecxz .notfound - inc edi - push esi + pop esi + add edi, ecx + scasd + scasd + mov cl, byte [edi] + jecxz .notfound + inc edi + push esi @@: - lodsb - or al, 20h - scasb - loopz @b - jnz .scan1 - pop eax - lodsb - cmp al, '/' - jz .found1 - test al, al - jnz .scan1 + lodsb + or al, 20h + scasb + loopz @b + jnz .scan1 + lodsb + cmp al, '/' + jz .found1 + test al, al + jnz .scan1 + pop eax ; directory /xxx .maindir: + cmp dword [ebx], 1 + jnz .access_denied + xor eax, eax + mov ebp, [ebx+12] + mov edx, [ebx+16] + add edx, std_application_base_address + mov ebx, [ebx+4] + mov esi, [edi+4] +; ebx=first block, ebp=number of blocks, edx=return area, esi='Next' handler + mov edi, edx + mov ecx, 32/4 + rep stosd + mov byte [edx], 1 ; version +.maindir_loop: + call esi + jc .maindir_done + inc dword [edx+8] + dec ebx + jns .maindir_loop + dec ebp + js .maindir_loop + inc dword [edx+4] + mov dword [edi], 0x10 ; attributes: folder + mov dword [edi+4], 1 ; name type: UNICODE + push eax + xor eax, eax + add edi, 8 + mov ecx, 40/4-2 + rep stosd + pop eax + push eax edx +; convert number in eax to decimal UNICODE string + push edi + push -'0' + mov cl, 10 +@@: + xor edx, edx + div ecx + push edx + test eax, eax + jnz @b +@@: + pop eax + add al, '0' + stosw + jnz @b + mov byte [edi-1], 0 + pop edi + add edi, 520 + pop edx eax + jmp .maindir_loop +.maindir_done: + mov ebx, [edx+8] + xor eax, eax + dec ebp + js @f + mov al, ERROR_END_OF_FILE +@@: + mov [esp+36], eax + mov [esp+24], ebx + ret ; directory / .rootdir: - mov dword [esp+36], 10 ; access denied - ret + cmp dword [ebx], 1 ; read folder? + jz .readroot +.access_denied: + mov dword [esp+36], 10 ; access denied + ret + +.readroot: +; virtual root folder - special handler + mov esi, virtual_root_query + mov ebp, [ebx+12] + mov edx, [ebx+16] + add edx, std_application_base_address + mov ebx, [ebx+4] + xor eax, eax +; eax=0, ebx=first block, ebp=number of blocks, edx=return area + mov edi, edx + mov ecx, 32/4 + rep stosd + mov byte [edx], 1 ; version +.readroot_loop: + cmp dword [esi], eax + jz .readroot_done + call dword [esi] + add esi, 4 + test eax, eax + jnz @f +.readroot_next: + or ecx, -1 + xchg esi, edi + repnz scasw + xchg esi, edi + jmp .readroot_loop +@@: + xor eax, eax + inc dword [edx+8] + dec ebx + jns .readroot_next + dec ebp + js .readroot_next + inc dword [edx+4] + mov dword [edi], 0x10 ; attributes: folder + mov dword [edi+4], 1 ; name type: UNICODE + add edi, 8 + mov ecx, 40/4-2 + rep stosd + push edi +@@: + lodsw + stosw + test eax, eax + jnz @b + pop edi + add edi, 520 + jmp .readroot_loop +.readroot_done: + mov ebx, [edx+8] + xor eax, eax + dec ebp + js @f + mov al, ERROR_END_OF_FILE +@@: + mov [esp+36], eax + mov [esp+24], ebx + ret .found1: - cmp byte [esi], 0 - jz .maindir - mov ebp, dword [edi] ; handler for this device + pop eax + cmp byte [esi], 0 + jz .maindir ; read partition number - xor ecx, ecx - xor eax, eax + xor ecx, ecx + xor eax, eax @@: - lodsb - cmp al, '/' - jz .done1 - test al, al - jz .done1 - sub al, '0' - cmp al, 9 - ja .notfound - imul ecx, 10 - add ecx, eax - jmp @b + lodsb + cmp al, '/' + jz .done1 + test al, al + jz .done1 + sub al, '0' + cmp al, 9 + ja .notfound + imul ecx, 10 + add ecx, eax + jmp @b .done1: - test ecx, ecx - jz .notfound - test al, al - jnz @f - dec esi + test ecx, ecx + jz .notfound + test al, al + jnz @f + dec esi @@: -; now ebp contains handler address, ecx - partition number, esi points to ASCIIZ string - rest of name - jmp ebp +; now [edi] contains handler address, ecx - partition number, +; esi points to ASCIIZ string - rest of name + jmp dword [edi] ; handlers for devices +; in: ecx = 0 => query virtual directory /xxx ; in: ecx = partition number ; esi -> relative (for device) name ; ebx -> fileinfo ; out: [esp+36]=image of eax, [esp+24]=image of ebx fs_OnRamdisk: - cmp ecx, 1 - jnz file_system_lfn.notfound - movzx eax, byte [ebx] - test eax, eax - jnz .not_impl - mov ecx, [ebx+12] - mov edx, [ebx+16] - add edx, std_application_base_address - add ebx, 4 - call dword [fs_RamdiskServices + eax*4] - mov [esp+36], eax - mov [esp+24], ebx - ret + cmp ecx, 1 + jnz file_system_lfn.notfound + mov eax, [ebx] + cmp eax, 1 + ja .not_impl + mov ecx, [ebx+12] + mov edx, [ebx+16] + add edx, std_application_base_address + add ebx, 4 + call dword [fs_RamdiskServices + eax*4] + mov [esp+36], eax + mov [esp+24], ebx + ret .not_impl: - mov dword [esp+36], 2 ; not implemented - ret + mov dword [esp+36], 2 ; not implemented + ret fs_RamdiskServices: - dd fs_RamdiskRead + dd fs_RamdiskRead + dd fs_RamdiskReadFolder fs_OnFloppy: - cmp ecx, 2 - ja file_system_lfn.notfound - movzx eax, byte [ebx] - test eax, eax - jnz fs_OnRamdisk.not_impl - call reserve_flp - mov [flp_number], cl - mov ecx, [ebx+12] - mov edx, [ebx+16] - add edx, std_application_base_address - add ebx, 4 - call dword [fs_FloppyServices + eax*4] - and [flp_status], 0 - mov [esp+36], eax - mov [esp+24], ebx - ret + cmp ecx, 2 + ja file_system_lfn.notfound + mov eax, [ebx] + cmp eax, 1 + ja fs_OnRamdisk.not_impl + call reserve_flp + mov [flp_number], cl + mov ecx, [ebx+12] + mov edx, [ebx+16] + add edx, std_application_base_address + add ebx, 4 + call dword [fs_FloppyServices + eax*4] + and [flp_status], 0 + mov [esp+36], eax + mov [esp+24], ebx + ret fs_FloppyServices: - dd fs_FloppyRead + dd fs_FloppyRead + dd fs_FloppyReadFolder fs_OnHd0: - call reserve_hd1 - mov [hdbase], 0x1F0 - mov [hdid], 0 - push 1 - jmp fs_OnHd + call reserve_hd1 + mov [hdbase], 0x1F0 + mov [hdid], 0 + push 1 + jmp fs_OnHd fs_OnHd1: - call reserve_hd1 - mov [hdbase], 0x1F0 - mov [hdid], 0x10 - push 2 - jmp fs_OnHd + call reserve_hd1 + mov [hdbase], 0x1F0 + mov [hdid], 0x10 + push 2 + jmp fs_OnHd fs_OnHd2: - call reserve_hd1 - mov [hdbase], 0x170 - mov [hdid], 0 - push 3 - jmp fs_OnHd + call reserve_hd1 + mov [hdbase], 0x170 + mov [hdid], 0 + push 3 + jmp fs_OnHd fs_OnHd3: - call reserve_hd1 - mov [hdbase], 0x170 - mov [hdid], 0x10 - push 4 + call reserve_hd1 + mov [hdbase], 0x170 + mov [hdid], 0x10 + push 4 fs_OnHd: - pop eax - mov [hdpos], eax - cmp ecx, [0x40001+eax] - jbe @f - and [hd1_status], 0 - mov dword [esp+36], 5 ; not found - ret + pop eax + mov [hdpos], eax + cmp ecx, 0x100 + jae .nf + cmp cl, [0x40001+eax] + jbe @f +.nf: + and [hd1_status], 0 + mov dword [esp+36], 5 ; not found + ret @@: - mov [fat32part], ecx - push ebx esi - call choice_necessity_partition_1 - pop esi ebx - mov ecx, [ebx+12] - mov edx, [ebx+16] - add edx, std_application_base_address - movzx eax, byte [ebx] - add ebx, 4 - call dword [fs_HdServices + eax*4] - and [hd1_status], 0 - mov [esp+36], eax - mov [esp+24], ebx - ret + mov [fat32part], ecx + push ebx esi + call choice_necessity_partition_1 + pop esi ebx + mov ecx, [ebx+12] + mov edx, [ebx+16] + add edx, std_application_base_address + mov eax, [ebx] + cmp eax, 1 + ja .not_impl + add ebx, 4 + call dword [fs_HdServices + eax*4] + and [hd1_status], 0 + mov [esp+36], eax + mov [esp+24], ebx + ret +.not_impl: + and [hd1_status], 0 + mov dword [esp+36], 2 ; not implemented + ret fs_HdServices: - dd fs_HdRead + dd fs_HdRead + dd fs_HdReadFolder + +fs_HasRamdisk: + mov al, 1 ; we always have ramdisk + ret + +fs_HasFloppy: + cmp byte [0x40000], 0 + setnz al + ret + +fs_HasHd0: + mov al, [0x40001] + and al, 11000000b + cmp al, 01000000b + setz al + ret +fs_HasHd1: + mov al, [0x40001] + and al, 00110000b + cmp al, 00010000b + setz al + ret +fs_HasHd2: + mov al, [0x40001] + and al, 00001100b + cmp al, 00000100b + setz al + ret +fs_HasHd3: + mov al, [0x40001] + and al, 00000011b + cmp al, 00000001b + setz al + ret + +; fs_NextXXX functions: +; in: eax = partition number, from which start to scan +; out: CF=1 => no more partitions +; CF=0 => eax=next partition number + +fs_NextRamdisk: +; we always have /rd/1 + test eax, eax + stc + jnz @f + mov al, 1 + clc +@@: + ret + +fs_NextFloppy: +; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0) + test byte [0x40000], 0xF0 + jz .no1 + test eax, eax + jnz .no1 + inc eax + ret ; CF cleared +.no1: + test byte [0x40000], 0x0F + jz .no2 + cmp al, 2 + jae .no2 + mov al, 2 + clc + ret +.no2: + stc + ret + +; on hdx, we have partitions from 1 to [0x40002+x] +fs_NextHd0: + push 0 + jmp fs_NextHd +fs_NextHd1: + push 1 + jmp fs_NextHd +fs_NextHd2: + push 2 + jmp fs_NextHd +fs_NextHd3: + push 3 +fs_NextHd: + pop ecx + movzx ecx, byte [0x40002+ecx] + cmp eax, ecx + jae fs_NextFloppy.no2 + inc eax + clc + ret diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index b9328dfd99..66073c05ee 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -1417,8 +1417,8 @@ display_number: ret cont_displ: - cmp eax,60*0x10000 ; length <= 60 ? - jbe cont_displ2 + cmp eax,61*0x10000 ; length <= 60 ? + jb cont_displ2 ret cont_displ2: @@ -1435,7 +1435,7 @@ display_number: cmp ah,0 ; DECIMAL jne no_display_desnum shr eax,16 - and eax,0x2f + and eax,0x3f push eax ;mov edi,[0x3010] ;mov edi,[edi+0x10] @@ -1461,7 +1461,7 @@ display_number: cmp ah,0x01 ; HEXADECIMAL jne no_display_hexnum shr eax,16 - and eax,0x2f + and eax,0x3f push eax ;mov edi,[0x3010] ;mov edi,[edi+0x10] @@ -1488,7 +1488,7 @@ display_number: cmp ah,0x02 ; BINARY jne no_display_binnum shr eax,16 - and eax,0x2f + and eax,0x3f push eax ;mov edi,[0x3010] ;mov edi,[edi+0x10] @@ -1637,6 +1637,10 @@ midi_base dw 0 nsyse2: cmp eax,3 ; CD jnz nsyse3 + test ebx,ebx + jz nosesl + cmp ebx, 4 + ja nosesl mov [cd_base],bl cmp ebx,1 jnz noprma @@ -1694,6 +1698,10 @@ wss_temp dd 0 cmp eax,7 ; HD BASE jne nsyse7 + test ebx,ebx + jz nosethd + cmp ebx,4 + ja nosethd mov [hd_base],bl cmp ebx,1 jnz noprmahd @@ -1727,6 +1735,7 @@ wss_temp dd 0 call reserve_hd1 call clear_hd_cache mov [hd1_status],0 ; free + nosethd: ret hd_base db 0 @@ -1748,6 +1757,8 @@ hd_base db 0 cmp eax,10 ; SOUND DMA CHANNEL jne no_set_sound_dma + cmp ebx,3 + ja sys_setup_err mov [sound_dma],ebx ret no_set_sound_dma: @@ -1770,6 +1781,7 @@ hd_base db 0 include 'vmodeint.inc' ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +sys_setup_err: mov [esp+36],dword -1 ret @@ -2062,34 +2074,61 @@ sys_end: call delay_hs jmp waitterm -sys_system: +iglobal +sys_system_table: + dd sysfn_shutdown ; 1 = system shutdown + dd sysfn_terminate ; 2 = terminate thread + dd sysfn_activate ; 3 = activate window + dd sysfn_getidletime ; 4 = get idle time + dd sysfn_getcpuclock ; 5 = get cpu clock + dd sysfn_saveramdisk ; 6 = save ramdisk + dd sysfn_getactive ; 7 = get active window + dd sysfn_sound_flag ; 8 = get/set sound_flag + dd sysfn_shutdown_param ; 9 = shutdown with parameter + dd sysfn_minimize ; 10 = minimize window + dd sysfn_getdiskinfo ; 11 = get disk subsystem info + dd sysfn_lastkey ; 12 = get last pressed key + dd sysfn_getversion ; 13 = get kernel version + dd sysfn_waitretrace ; 14 = wait retrace + dd sysfn_centermouse ; 15 = center mouse cursor + dd sysfn_getfreemem ; 16 = get free memory size + dd sysfn_getallmem ; 17 = get total memory size +sysfn_num = ($ - sys_system_table)/4 +endg - cmp eax,1 ; BOOT - jnz nosystemboot +sys_system: + dec eax + cmp eax, sysfn_num + jae @f + jmp dword [sys_system_table + eax*4] +@@: + ret + +sysfn_shutdown: ; 18.1 = BOOT mov [0x2f0000+0x9030],byte 0 for_shutdown_parameter: mov eax,[0x3004] add eax,2 mov [shutdown_processes],eax mov [0xFF00],al - xor eax, eax + and dword [esp+36], 0 ret uglobal shutdown_processes: dd 0x0 endg - nosystemboot: - cmp eax,2 ; TERMINATE - jnz noprocessterminate +sysfn_terminate: ; 18.2 = TERMINATE cmp ebx,2 jb noprocessterminate mov edx,[0x3004] cmp ebx,edx - jg noprocessterminate + ja noprocessterminate mov eax,[0x3004] shl ebx,5 mov edx,[ebx+0x3000+4] add ebx,0x3000+0xa + cmp byte [ebx], 9 + jz noprocessterminate ;call MEM_Heap_Lock ;guarantee that process isn't working with heap mov [ebx],byte 3 ; clear possible i40's @@ -2099,11 +2138,10 @@ sys_system: jne noatsc mov [application_table_status],0 noatsc: - ret noprocessterminate: + ret - cmp eax,3 ; ACTIVATE WINDOW - jnz nowindowactivate +sysfn_activate: ; 18.3 = ACTIVATE WINDOW cmp ebx,2 jb nowindowactivate cmp ebx,[0x3004] @@ -2115,80 +2153,73 @@ sys_system: ;mov esi, [ebx] ; esi = window stack value ;and esi, 0xffff ; word movzx esi, word [0xC000 + ebx*2] - mov edx, [0x3004] ; edx = number of processes - cmp esi, edx + cmp esi, [0x3004] ; number of processes jz nowindowactivate ; continue if window_stack_value != number_of_processes ; i.e. if window is not already active ;* start code - get active process (1) - Mario79 - cli +; cli mov [window_minimize],2 ; mov [active_process],edi - sti +; sti ;* end code - get active process (1) - Mario79 mov [0xff01],edi ; activate - xor eax, eax +nowindowactivate: ret - nowindowactivate: - - cmp eax,4 ; GET IDLETIME - jnz nogetidletime +sysfn_getidletime: ; 18.4 = GET IDLETIME mov eax,[idleusesec] + mov [esp+36], eax ret - nogetidletime: - cmp eax,5 ; GET TSC/SEC - jnz nogettscsec +sysfn_getcpuclock: ; 18.5 = GET TSC/SEC mov eax,[0xf600] + mov [esp+36], eax ret - nogettscsec: ; SAVE ramdisk to /hd/1/menuet.img ;!!!!!!!!!!!!!!!!!!!!!!!! include 'blkdev/rdsave.inc' ;!!!!!!!!!!!!!!!!!!!!!!!! - cmp eax,7 - jnz nogetactiveprocess + +sysfn_getactive: ; 18.7 = get active window mov eax,[active_process] + mov [esp+36],eax ret - nogetactiveprocess: - cmp eax,8 - jnz nosoundflag + +sysfn_sound_flag: ; 18.8 = get/set sound_flag cmp ebx,1 jne nogetsoundflag movzx eax,byte [sound_flag] ; get sound_flag + mov [esp+36],eax ret nogetsoundflag: cmp ebx,2 jnz nosoundflag - inc byte [sound_flag] ; set sound_flag - and byte [sound_flag],1 ; + xor byte [sound_flag], 1 + nosoundflag: ret -nosoundflag: - cmp eax,9 ; system shutdown with param - jnz noshutdownsystem + +sysfn_shutdown_param: ; 18.9 = system shutdown with param cmp ebx,1 - jl exit_for_anyone + jl exit_for_anyone cmp ebx,4 jg exit_for_anyone mov [0x2f0000+0x9030],bl jmp for_shutdown_parameter -noshutdownsystem: - cmp eax,10 ; minimize window - jnz nominimizewindow + +sysfn_minimize: ; 18.10 = minimize window mov [window_minimize],1 exit_for_anyone: ret -nominimizewindow: - cmp eax,11 ; get disk info table - jnz nogetdiskinfo + +sysfn_getdiskinfo: ; 18.11 = get disk info table cmp ebx,1 jnz full_table small_table: call for_all_tables - mov cx,10 + mov ecx,10 cld rep movsb ret @@ -2197,28 +2228,24 @@ nominimizewindow: mov edi,[edi+10h] add edi,ecx mov esi,0x40000 - xor ecx,ecx ret full_table: cmp ebx,2 jnz exit_for_anyone call for_all_tables - mov cx,16384 + mov ecx,16384 cld rep movsd ret -nogetdiskinfo: - cmp eax,12 ; get all key pressed with ALT - jnz nogetkey + +sysfn_lastkey: ; 18.12 = get all key pressed with ALT mov eax,[last_key_press] mov al,[keyboard_mode_sys] mov [esp+36],eax mov [last_key_press],0 - .finish: ret -nogetkey: - cmp eax,13 ; get kernel ID and version - jnz nogetkernel_id + +sysfn_getversion: ; 18.13 = get kernel ID and version mov edi,[3010h] mov edi,[edi+10h] add edi,ebx @@ -2227,9 +2254,8 @@ nogetkey: cld rep movsb ret -nogetkernel_id: - cmp eax,14 ; sys wait retrace - jnz nosys_wait_retrace + +sysfn_waitretrace: ; 18.14 = sys wait retrace ;wait retrace functions sys_wait_retrace: mov edx,0x3da @@ -2239,29 +2265,26 @@ nogetkernel_id: jz WaitRetrace_loop mov [esp+36],dword 0 ret -nosys_wait_retrace: - cmp eax,15 ; mouse centered - jnz no_mouse_centered + +sysfn_centermouse: ; 18.15 = mouse centered call mouse_centered mov [esp+36],dword 0 ret -no_mouse_centered: - cmp eax,16 - jnz no_get_free_space + +sysfn_getfreemem: mov eax,[MEM_FreeSpace] shl eax,2 + mov [esp+36],eax ret -no_get_free_space: - cmp eax,17 - jnz no_get_all_space + +sysfn_getallmem: mov eax,[0xFE8C] shr eax,10 ; mov eax,[MEM_AllSpace] ; shl eax,2 + mov [esp+36],eax ret -no_get_all_space: - ret uglobal ;// mike.dld, 2006-29-01 [ screen_workarea RECT @@ -2694,10 +2717,18 @@ align 4 sys_date: cli - mov al,6 ; day of week - out 0x70,al - in al,0x71 - mov ch,al + + @@: mov al, 10 + out 0x70, al + in al, 0x71 + test al, al + jns @f + mov esi, 1 + call delay_ms + jmp @b + @@: + + mov ch,0 mov al,7 ; date out 0x70,al in al,0x71 @@ -3503,50 +3534,51 @@ memmove: ; memory move in bytes ret -align 4 - -read_floppy_file: - -; as input +; Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead. +;align 4 ; -; eax pointer to file -; ebx file lenght -; ecx start 512 byte block number -; edx number of blocks to read -; esi pointer to return/work area (atleast 20 000 bytes) +;read_floppy_file: ; +;; as input +;; +;; eax pointer to file +;; ebx file lenght +;; ecx start 512 byte block number +;; edx number of blocks to read +;; esi pointer to return/work area (atleast 20 000 bytes) +;; +;; +;; on return +;; +;; eax = 0 command succesful +;; 1 no fd base and/or partition defined +;; 2 yet unsupported FS +;; 3 unknown FS +;; 4 partition not defined at hd +;; 5 file not found +;; ebx = size of file ; -; on return +; mov edi,[0x3010] +; add edi,0x10 +; add esi,[edi] +; add eax,[edi] ; -; eax = 0 command succesful -; 1 no fd base and/or partition defined -; 2 yet unsupported FS -; 3 unknown FS -; 4 partition not defined at hd -; 5 file not found -; ebx = size of file - - mov edi,[0x3010] - add edi,0x10 - add esi,[edi] - add eax,[edi] - - pushad - mov edi,esi - add edi,1024 - mov esi,0x100000+19*512 - sub ecx,1 - shl ecx,9 - add esi,ecx - shl edx,9 - mov ecx,edx - cld - rep movsb - popad - - mov [esp+36],eax - mov [esp+24],ebx - ret +; pushad +; mov edi,esi +; add edi,1024 +; mov esi,0x100000+19*512 +; sub ecx,1 +; shl ecx,9 +; add esi,ecx +; shl edx,9 +; mov ecx,edx +; cld +; rep movsb +; popad +; +; mov [esp+36],eax +; mov [esp+24],ebx +; ret @@ -3558,14 +3590,13 @@ sys_programirq: add edi,0x10 add eax,[edi] - mov edx,ebx - shl edx,2 - add edx,irq_owner - mov edx,[edx] + cmp ebx,16 + jae .not_owner mov edi,[0x3010] mov edi,[edi+0x4] - cmp edx,edi + cmp edi,[irq_owner+ebx*4] je spril1 +.not_owner: mov [esp+36],dword 1 ret spril1: @@ -3584,7 +3615,8 @@ sys_programirq: align 4 get_irq_data: - + cmp eax,16 + jae .not_owner mov edx,eax ; check for correct owner shl edx,2 add edx,irq_owner @@ -3593,9 +3625,8 @@ get_irq_data: mov edi,[edi+0x4] cmp edx,edi je gidril1 - mov [esp+36],eax - mov [esp+32],dword 2 - mov [esp+24],ebx +.not_owner: + mov [esp+32],dword 2 ; ecx=2 ret gidril1: @@ -3618,7 +3649,7 @@ get_irq_data: mov ecx,4000 / 4 cld rep movsd - xor ecx,ecx +; xor ecx,ecx ; as result of 'rep' ecx=0 gid1: mov [esp+36],eax mov [esp+32],ecx @@ -3678,18 +3709,20 @@ r_f_port_area: pushad cmp ebx,ecx ; beginning > end ? - jg rpal1 + ja rpal1 + cmp ecx,65536 + jae rpal1 mov esi,[0x2d0000] - cmp esi,0 ; no reserved areas ? + test esi,esi ; no reserved areas ? je rpal2 cmp esi,255 ; max reserved - jge rpal1 + jae rpal1 rpal3: mov edi,esi shl edi,4 add edi,0x2d0000 cmp ebx,[edi+8] - jg rpal4 + ja rpal4 cmp ecx,[edi+4] jae rpal1 ; jb rpal4 @@ -3721,7 +3754,7 @@ r_f_port_area: pushad - mov ebp,0 ; enable - eax = port + xor ebp,ebp ; enable - eax = port call set_io_access_rights popad @@ -3757,7 +3790,7 @@ free_port_area: pushad mov esi,[0x2d0000] ; no reserved areas ? - cmp esi,0 + test esi,esi je frpal2 mov edx,[0x3010] mov edx,[edx+4] @@ -3825,43 +3858,35 @@ free_port_area: reserve_free_irq: - cmp eax,0 + mov ecx, 1 + cmp ebx, 16 + jae fril1 + test eax,eax jz reserve_irq - mov edi,ebx - shl edi,2 - add edi,irq_owner + lea edi,[irq_owner+ebx*4] mov edx,[edi] mov eax,[0x3010] - mov eax,[eax+0x4] - mov ecx,1 - cmp edx,eax + cmp edx,[eax+0x4] jne fril1 - mov [edi],dword 0 - mov ecx,0 + dec ecx + mov [edi],ecx fril1: mov [esp+36],ecx ; return in eax ret reserve_irq: - mov edi,ebx - shl edi,2 - add edi,irq_owner - mov edx,[edi] - mov ecx,1 - cmp edx,0 - jne ril1 + lea edi,[irq_owner+ebx*4] + cmp dword [edi], 0 + jnz ril1 mov edx,[0x3010] mov edx,[edx+0x4] mov [edi],edx - mov ecx,0 - + dec ecx ril1: - mov [esp+36],ecx ; return in eax - ret @@ -3904,7 +3929,13 @@ drawbackground: call [draw_pointer] ret +align 4 +syscall_putimage: ; PutImage + + mov edx,ecx + mov ecx,ebx + lea ebx, [eax+std_application_base_address] sys_putimage: test ecx,0x80008000 @@ -3916,29 +3947,21 @@ sys_putimage: .exit: ret @@: -; inc [mouse_pause] - cmp [0xfe0c],word 0x12 - jne spiv20 - call vga_putimage -; dec [mouse_pause] - call [draw_pointer] - ret - spiv20: - cmp [0xfe0c],word 0100000000000000b - jge piv20 - cmp [0xfe0c],word 0x13 - je piv20 - call vesa12_putimage -; dec [mouse_pause] - call [draw_pointer] - ret - piv20: - call vesa20_putimage -; dec [mouse_pause] - call [draw_pointer] - ret - - + mov eax, vga_putimage + cmp [0xfe0c], word 0x12 + jz .doit + mov eax, vesa12_putimage + cmp [0xfe0c], word 0100000000000000b + jae @f + cmp [0xfe0c], word 0x13 + jnz .doit +@@: + mov eax, vesa20_putimage +.doit: +; inc [mouse_pause] + call eax +; dec [mouse_pause] + jmp [draw_pointer] ; eax x beginning ; ebx y beginning @@ -4458,7 +4481,7 @@ sys_ipc: mov eax,edi add eax,ecx cmp eax,ebx - jge ipc_err3 ; not enough room ? + jg ipc_err3 ; not enough room ? push ecx @@ -4598,20 +4621,6 @@ syscall_openramdiskfile: ; OpenRamdiskFile align 4 -syscall_putimage: ; PutImage - - mov edi,[0x3010] - add edi,0x10 - add eax,[edi] - mov edx,ecx - mov ecx,ebx - mov ebx,eax - call sys_putimage - mov [esp+36],eax - ret - -align 4 - syscall_drawrect: ; DrawRect mov edi,ecx @@ -4642,14 +4651,6 @@ syscall_getscreensize: ; GetScreenSize align 4 -syscall_system: ; System - - call sys_system - mov [esp+36],eax - ret - -align 4 - syscall_startapp: ; StartApp mov edi,[0x3010] add edi,0x10 @@ -4673,32 +4674,33 @@ syscall_cdaudio: ; CD mov [esp+36],eax ret -align 4 +; ReadHd and StartHdApp functions are obsolete. Use 58 or 70 functions instead. +;align 4 +; +;syscall_readhd: ; ReadHd +; +; mov edi,[0x3010] +; add edi,0x10 +; add esi,[edi] +; add eax,[edi] +; call read_hd_file +; mov [esp+36],eax +; mov [esp+24],ebx +; ret -syscall_readhd: ; ReadHd - - mov edi,[0x3010] - add edi,0x10 - add esi,[edi] - add eax,[edi] - call read_hd_file - mov [esp+36],eax - mov [esp+24],ebx - ret - -align 4 - -syscall_starthdapp: ; StartHdApp - - mov edi,[0x3010] - add edi,0x10 - add eax,[edi] - add ecx,[edi] - xor ebp,ebp - xor edx,edx ; compatibility - flags=0 - call start_application_hd - mov [esp+36],eax - ret +;align 4 +; +;syscall_starthdapp: ; StartHdApp +; +; mov edi,[0x3010] +; add edi,0x10 +; add eax,[edi] +; add ecx,[edi] +; xor ebp,ebp +; xor edx,edx ; compatibility - flags=0 +; call start_application_hd +; mov [esp+36],eax +; ret align 4 @@ -4769,12 +4771,16 @@ syscall_drawline: ; DrawLine align 4 syscall_getirqowner: ; GetIrqOwner - + cmp eax,16 + jae .err shl eax,2 add eax,irq_owner mov eax,[eax] mov [esp+36],eax ret +.err: + or dword [esp+36], -1 + ret align 4 @@ -4860,17 +4866,18 @@ write_to_hd: ; Write a file to hd call file_write ret -align 4 - -delete_from_hd: ; Delete a file from hd - - mov edi,[0x3010] - add edi,0x10 - add eax,[edi] - add ecx,[edi] - call file_delete - ret - +; Sysfunction 57, delete_from_hd, is obsolete. Use 58 or 70 functions instead. +;align 4 +; +;delete_from_hd: ; Delete a file from hd +; +; mov edi,[0x3010] +; add edi,0x10 +; add eax,[edi] +; add ecx,[edi] +; call file_delete +; ret +; align 4 diff --git a/kernel/trunk/video/vesa20.inc b/kernel/trunk/video/vesa20.inc index f69b48ab45..3c6dfef16c 100644 --- a/kernel/trunk/video/vesa20.inc +++ b/kernel/trunk/video/vesa20.inc @@ -131,8 +131,6 @@ vesa20_putimage: ja @f add esp, putimg.stack_data popad - xor eax, eax - inc eax ret @@: cmp ebx, [putimg.image_sx] @@ -149,8 +147,6 @@ vesa20_putimage: ja @f add esp, putimg.stack_data popad - xor eax, eax - inc eax ret @@: cmp ebx, [putimg.image_sy] @@ -248,7 +244,6 @@ vesa20_putimage: .finish: add esp, putimg.stack_data popad - xor eax, eax ;sti ; !!!!!!!!!!!!!!!!!!!!! ret @@ -286,7 +281,6 @@ put_image_end_32: .finish: add esp, putimg.stack_data popad - xor eax, eax ret