Use disk.inc from kolibri. Compiles, doesn't work.

This commit is contained in:
Ivan Baravy 2018-05-04 21:18:09 +03:00
parent d480fffdb0
commit f3946d5a7d
4 changed files with 180 additions and 425 deletions

203
disk.inc
View File

@ -1,203 +0,0 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2011-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision: 6917 $
; =============================================================================
; ================================= Constants =================================
; =============================================================================
; Error codes for callback functions.
DISK_STATUS_OK = 0 ; success
DISK_STATUS_GENERAL_ERROR = -1; if no other code is suitable
DISK_STATUS_INVALID_CALL = 1 ; invalid input parameters
DISK_STATUS_NO_MEDIA = 2 ; no media present
DISK_STATUS_END_OF_MEDIA = 3 ; end of media while reading/writing data
DISK_STATUS_NO_MEMORY = 4 ; insufficient memory for driver operation
; Driver flags. Represent bits in DISK.DriverFlags.
DISK_NO_INSERT_NOTIFICATION = 1
; Media flags. Represent bits in DISKMEDIAINFO.Flags.
DISK_MEDIA_READONLY = 1
; If too many partitions are detected,there is probably an error on the disk.
; 256 partitions should be enough for any reasonable use.
; Also, the same number is limiting the number of MBRs to process; if
; too many MBRs are visible,there probably is a loop in the MBR structure.
MAX_NUM_PARTITIONS = 256
; This structure holds information on a medium.
; Objects with this structure are allocated by the kernel as a part of the DISK
; structure and are filled by a driver in the 'querymedia' callback.
struct DISKMEDIAINFO
Flags dd ?
; Combination of DISK_MEDIA_* bits.
SectorSize dd ?
; Size of the sector.
Capacity dq ?
; Size of the media in sectors.
ends
; This structure represents the disk cache. To follow the old implementation,
; there are two distinct caches for a disk, one for "system" data,and the other
; for "application" data.
struct DISKCACHE
; The following fields are inherited from data32.inc:cache_ideX.
pointer dd ?
data_size dd ? ; unused
data dd ?
sad_size dd ?
search_start dd ?
sector_size_log dd ?
ends
; This structure represents a disk device and its media for the kernel.
; This structure is allocated by the kernel in the 'disk_add' function,
; freed in the 'disk_dereference' function.
struct DISK
; Fields of disk object
Next dd ?
Prev dd ?
; All disk devices are linked in one list with these two fields.
; Head of the list is the 'disk_list' variable.
Functions dd ?
; Pointer to the 'DISKFUNC' structure with driver functions.
Name dd ?
; Pointer to the string used for accesses through the global filesystem.
UserData dd ?
; This field is passed to all callback functions so a driver can decide which
; physical device is addressed.
DriverFlags dd ?
; Bitfield. Currently only DISK_NO_INSERT_NOTIFICATION bit is defined.
; If it is set, the driver will never issue 'disk_media_changed' notification
; with argument set to true, so the kernel must try to detect media during
; requests from the file system.
RefCount dd ?
; Count of active references to this structure. One reference is kept during
; the lifetime of the structure between 'disk_add' and 'disk_del'.
; Another reference is taken during any filesystem operation for this disk.
; One reference is added if media is inserted.
; The structure is destroyed when the reference count decrements to zero:
; this usually occurs in 'disk_del', but can be delayed to the end of last
; filesystem operation, if one is active.
MediaLock MUTEX
; Lock to protect the MEDIA structure. See the description after
; 'disk_list_mutex' for the locking strategy.
; Fields of media object
MediaInserted db ?
; 0 if media is not inserted, nonzero otherwise.
MediaUsed db ?
; 0 if media fields are not used, nonzero otherwise. If .MediaRefCount is
; nonzero, this field is nonzero too; however, when .MediaRefCount goes
; to zero, there is some time interval during which media object is still used.
dw ? ; padding
; The following fields are not valid unless either .MediaInserted is nonzero
; or they are accessed from a code which has obtained the reference when
; .MediaInserted was nonzero.
MediaRefCount dd ?
; Count of active references to the media object. One reference is kept during
; the lifetime of the media between two calls to 'disk_media_changed'.
; Another reference is taken during any filesystem operation for this media.
; The callback 'closemedia' is called when the reference count decrements to
; zero: this usually occurs in 'disk_media_changed', but can be delayed to the
; end of the last filesystem operation, if one is active.
MediaInfo DISKMEDIAINFO
; This field keeps information on the current media.
NumPartitions dd ?
; Number of partitions on this media.
Partitions dd ?
; Pointer to array of .NumPartitions pointers to PARTITION structures.
cache_size dd ?
; inherited from cache_ideX_size
CacheLock MUTEX
; Lock to protect both caches.
SysCache DISKCACHE
AppCache DISKCACHE
; Two caches for the disk.
ends
; This structure represents one partition for the kernel. This is a base
; template, the actual contents after common fields is determined by the
; file system code for this partition.
struct PARTITION
FirstSector dq ?
; First sector of the partition.
Length dq ?
; Length of the partition in sectors.
Disk dd ?
; Pointer to parent DISK structure.
FSUserFunctions dd ?
; Handlers for the sysfunction 70h. This field is a pointer to the following
; array. The first dword is pointer to disconnect handler.
; The first dword is a number of supported subfunctions, other dwords
; point to handlers of corresponding subfunctions.
; ...fs-specific data may follow...
ends
; This is an external structure, it represents an entry in the partition table.
struct PARTITION_TABLE_ENTRY
Bootable db ?
; 80h = bootable partition, 0 = non-bootable partition, other values = invalid
FirstHead db ?
FirstSector db ?
FirstTrack db ?
; Coordinates of first sector in CHS.
Type db ?
; Partition type, one of predefined constants. 0 = empty, several types denote
; extended partition (see process_partition_table_entry), we are not interested
; in other values.
LastHead db ?
LastSector db ?
LastTrack db ?
; Coordinates of last sector in CHS.
FirstAbsSector dd ?
; Coordinate of first sector in LBA.
Length dd ?
; Length of the partition in sectors.
ends
; GUID Partition Table Header, UEFI 2.6, Table 18
struct GPTH
Signature rb 8
; 'EFI PART'
Revision dd ?
; 0x00010000
HeaderSize dd ?
; Size of this header in bytes, must fit to one sector.
HeaderCRC32 dd ?
; Set this field to zero, compute CRC32 via 0xEDB88320, compare.
Reserved dd ?
; Must be zero.
MyLBA dq ?
; LBA of the sector containing this GPT header.
AlternateLBA dq ?
; LBA of the sector containing the other GPT header.
; AlternateLBA of Primary GPTH points to Backup one and vice versa.
FirstUsableLBA dq ?
; Only sectors between first and last UsableLBA may form partitions
LastUsableLBA dq ?
DiskGUID rb 16
; Globally Unique IDentifier
PartitionEntryLBA dq ?
; First LBA of Partition Entry Array.
; Length in bytes is computed as a product of two following fields.
NumberOfPartitionEntries dd ?
; Actual number of partitions depends on the contents of Partition Entry Array.
; A partition entry is unused if zeroed.
SizeOfPartitionEntry dd ? ; in bytes
PartitionEntryArrayCRC32 dd ?
; Same CRC as for GPT header.
ends
; GPT Partition Entry, UEFI 2.6, Table 19
struct GPE
PartitionTypeGUID rb 16
UniquePartitionGUID rb 16
StartingLBA dq ?
EndingLBA dq ?
; Length in sectors is EndingLBA - StartingLBA + 1.
Attributes dq ?
PartitionName rb 72
ends

View File

@ -1,142 +0,0 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision: 6462 $
fsReadCMOS:
out 70h, al
in al, 71h
xor ah, ah
shl ax, 4
shr al, 4
aad
ret
fsGetTime:
mov al, 7
call fsReadCMOS
ror eax, 8
mov al, 8
call fsReadCMOS
ror eax, 8
mov al, 9
call fsReadCMOS
add eax, 2000
ror eax, 16
push eax
xor eax, eax
call fsReadCMOS
ror eax, 8
mov al, 2
call fsReadCMOS
ror eax, 8
mov al, 4
call fsReadCMOS
ror eax, 16
push eax
mov esi, esp
add esp, 8
fsCalculateTime:
; in: esi -> data block
; out: eax = seconds since 01.01.2001
movzx eax, word [esi+6]
sub eax, 2001
jnc @f
xor eax, eax
@@:
mov edx, months
mov ebx, eax
inc eax
test eax, 3
jnz @f
add edx, 12
@@:
movzx eax, byte [esi+5]
dec eax
xor ecx, ecx
@@:
dec eax
js @f
add cl, [edx+eax]
adc ch, 0
jmp @b
@@:
mov eax, ebx ; years
mov edx, 365
mul edx
shr ebx, 2
add eax, ebx
add eax, ecx
mov bl, [esi+4]
dec eax
add eax, ebx ; days
mov dl, 24
mul edx
mov bl, [esi+2]
add eax, ebx ; hours
mov ecx, 60
mul ecx
mov bl, [esi+1]
add eax, ebx ; minutes
mul ecx
mov bl, [esi]
add eax, ebx
ret
;iglobal
months db 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
months2 db 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
;endg
fsTime2bdfe:
; in: eax = seconds since 01.01.2001
; edi -> data block
; out: edi = edi+8
xor edx, edx
mov ecx, 60
div ecx
mov [edi], dl
xor edx, edx
div ecx
mov [edi+1], dl
xor edx, edx
mov cl, 24
div ecx
mov [edi+2], dx
xor edx, edx
mov cx, 365
div ecx
mov ebx, eax
add ebx, 2001
shr eax, 2
sub edx, eax
jns @f
dec ebx
add edx, 365
test ebx, 3
jnz @f
inc edx
@@:
xor eax, eax
mov ecx, months-1
test ebx, 3
jnz @f
add ecx, 12
@@:
inc ecx
inc eax
sub dl, [ecx]
jnc @b
dec dh
jns @b
add dl, [ecx]
inc edx
mov [edi+4], dl
mov [edi+5], al
mov [edi+6], bx
add edi, 8
ret

View File

@ -1,6 +1,6 @@
format ELF
__DEBUG__ = 0
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
include 'macros.inc'
@ -9,22 +9,10 @@ include 'struct.inc'
include 'const.inc'
include 'system.inc'
include 'debug-fdo.inc'
include 'disk.inc'
include 'fs_common.inc'
ERROR_SUCCESS = 0
ERROR_DISK_BASE = 1
ERROR_UNSUPPORTED_FS = 2
ERROR_UNKNOWN_FS = 3
ERROR_PARTITION = 4
ERROR_FILE_NOT_FOUND = 5
ERROR_END_OF_FILE = 6
ERROR_MEMORY_POINTER = 7
ERROR_DISK_FULL = 8
ERROR_FS_FAIL = 9
ERROR_ACCESS_DENIED = 10
ERROR_DEVICE = 11
ERROR_OUT_OF_MEMORY = 12
include 'blkdev/disk.inc'
include 'blkdev/disk_cache.inc'
include 'fs/fs_lfn.inc'
include 'crc.inc'
struct FS_FUNCTIONS
Free dd ?
@ -66,26 +54,21 @@ kos_fuse_init:
mov eax, [esp + 0x14]
mov [fd], eax
mov eax, 0
mov ebx, mbr_buffer
mov ebp, partition
call fs_read32_sys
mov [file_disk.Size], 65536
stdcall disk_add, disk_functions, disk_name, file_disk, DISK_NO_INSERT_NOTIFICATION
mov [disk], eax
stdcall disk_media_changed, [disk], 1
mov esi, disk
mov [esi + DISK.MediaInfo.SectorSize], 512
mov ebp, partition
mov [ebp + PARTITION.Disk], esi
mov ebx, mbr_buffer
call xfs_create_partition
test eax, eax
jnz @f
mov eax, [disk]
cmp [eax + DISK.NumPartitions], 0
jnz .done
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg_not_xfs_partition
mov edx, msg_not_xfs_partition.size
mov ecx, msg_no_partition
mov edx, msg_no_partition.size
int 0x80
xor eax, eax
@@:
.done:
mov [fs_struct], eax
pop ebp edi esi ebx
@ -169,7 +152,7 @@ kos_fuse_read:
mov ebx, sf70_params
mov esi, eax
push 0
call xfs_ReadFile
call xfs_Read
pop eax
pop ebp edi esi ebx
@ -177,10 +160,36 @@ kos_fuse_read:
ret
proc disk_read stdcall, userdata, buffer, startsector:qword, numsectors
pushad
mov eax, dword[startsector + 0] ; sector lo
mov edx, dword[startsector + 4] ; sector hi
imul ecx, eax, 512
mov eax, SYS_LSEEK
mov ebx, [fd]
mov edx, SEEK_SET
int 0x80
DEBUGF 1, "lseek: %x\n", eax
popad
pushad
mov eax, SYS_READ
mov ebx, [fd]
mov ecx, [buffer]
mov edx, [numsectors]
mov edx, [edx]
imul edx, 512
int 0x80
DEBUGF 1, "read: %d\n", eax
popad
movi eax, DISK_STATUS_OK
ret
endp
; in: eax = sector, ebx = buffer, ebp = pointer to PARTITION structure
fs_read32_sys:
proc disk_write stdcall, userdata, buffer, startsector:qword, numsectors
ud2
pushad
imul ecx, eax, 512
add ecx, 2048*512
@ -192,49 +201,32 @@ fs_read32_sys:
popad
pushad
mov eax, SYS_READ
mov eax, SYS_WRITE
mov ecx, ebx
mov ebx, [fd]
mov edx, 512
int 0x80
;DEBUGF 1, "read: %d\n", eax
;DEBUGF 1, "write: %d\n", eax
popad
xor eax, eax
movi eax, DISK_STATUS_OK
ret
endp
fs_read32_app:
ret
fs_read64_sys:
pushad
imul ecx, eax, 512
add ecx, 2048*512
mov eax, SYS_LSEEK
mov ebx, [fd]
mov edx, SEEK_SET
int 0x80
;DEBUGF 1, "lseek: %x\n", eax
popad
pushad
mov eax, SYS_READ
imul edx, ecx, 512
mov ecx, ebx
mov ebx, [fd]
int 0x80
;DEBUGF 1, "read: %d\n", eax
popad
xor eax, eax
ret
fs_read64_app:
; int querymedia(void* userdata, DISKMEDIAINFO* info);
proc disk_querymedia stdcall, hd_data, mediainfo
mov ecx, [mediainfo]
mov [ecx + DISKMEDIAINFO.Flags], 0
mov [ecx + DISKMEDIAINFO.SectorSize], 512
mov eax, [hd_data]
mov eax, dword[eax + FILE_DISK.Size + 0]
mov dword [ecx + DISKMEDIAINFO.Capacity], eax
mov dword [ecx + DISKMEDIAINFO.Capacity + 4], 0
movi eax, DISK_STATUS_OK
ret
endp
malloc:
@ -243,10 +235,31 @@ malloc:
pop eax
ret
proc kernel_alloc _size
mov eax, [_size]
call malloc
ret
endp
proc alloc_kernel_space _size
mov eax, [_size]
call malloc
ret
endp
proc alloc_pages _size
shl eax, 12
call malloc
ret
endp
free:
ret
kernel_free:
ret
@ -268,27 +281,114 @@ put_board:
popad
ret
align 16 ;very often call this subrutine
memmove: ; memory move in bytes
; eax = from
; ebx = to
; ecx = no of bytes
test ecx, ecx
jle .ret
;include 'ext.inc'
include 'xfs.asm'
push esi edi ecx
mov edi, ebx
mov esi, eax
test ecx, not 11b
jz @f
push ecx
shr ecx, 2
rep movsd
pop ecx
and ecx, 11b
jz .finish
;--------------------------------------
align 4
@@:
rep movsb
;--------------------------------------
align 4
.finish:
pop ecx edi esi
;--------------------------------------
align 4
.ret:
ret
sys_msg_board_str:
protect_from_terminate:
unprotect_from_terminate:
change_task:
ReadCDWRetr:
WaitUnitReady:
prevent_medium_removal:
Read_TOC:
commit_pages:
release_pages:
ret
proc fs_execute
; edx = flags
; ecx -> cmdline
; ebx -> absolute file path
; eax = string length
ret
endp
section '.data' writeable align 16
include_debug_strings
disk_functions:
dd disk_functions_end - disk_functions
dd 0
dd 0
dd disk_querymedia
dd disk_read
dd disk_write
dd 0
dd 0
disk_functions_end:
partition_offset dd 2048*512
struct FILE_DISK
Size dd ?
ends
file_disk FILE_DISK
;partition_offset dd 2048*512
alloc_pos dd alloc_base
sf70_params rd 6
msg_not_xfs_partition db 'not XFS partition',0x0a ; TODO: return codes, report in C
msg_not_xfs_partition.size = $ - msg_not_xfs_partition
msg_no_partition db 'no partition detected',0x0a
msg_no_partition.size = $ - msg_no_partition
disk_name db 'hd',0
current_slot dd ?
pg_data PG_DATA
ide_channel1_mutex MUTEX
ide_channel2_mutex MUTEX
ide_channel3_mutex MUTEX
ide_channel4_mutex MUTEX
ide_channel5_mutex MUTEX
ide_channel6_mutex MUTEX
ide_channel7_mutex MUTEX
ide_channel8_mutex MUTEX
IncludeIGlobals
section '.bss' writeable align 16
mbr_buffer rb 4096*3
;mbr_buffer rb 4096*3
DiskNumber db ?
ChannelNumber db ?
DevErrorCode dd ?
CDSectorAddress dd ?
CDDataBuf_pointer dd ?
DRIVE_DATA: rb 0x4000
cdpos dd ?
cd_appl_data rd 1
fd rd 1
partition PARTITION
disk DISK
alloc_base rb 1024*1024
disk dd ?
alloc_base rb 4*1024*1024
fs_struct rd 1
sf70_buffer rb 1024*1024
IncludeUGlobals

View File

@ -11,8 +11,8 @@ kofu: kofu.o kocdecl.o
kofuse: kofuse.o kocdecl.o
$(CC) $(LDFLAGS) $^ -o $@ `pkg-config fuse3 --libs`
kocdecl.o: kocdecl.asm kocdecl.h $(KERNEL_TRUNK)/fs/xfs.inc $(KERNEL_TRUNK)/fs/xfs.asm
INCLUDE="$(KERNEL_TRUNK);$(KERNEL_TRUNK)/fs" $(FASM) $< $@
kocdecl.o: kocdecl.asm kocdecl.h $(KERNEL_TRUNK)/fs/ext.inc $(KERNEL_TRUNK)/fs/xfs.inc $(KERNEL_TRUNK)/fs/xfs.asm
INCLUDE="$(KERNEL_TRUNK);$(KERNEL_TRUNK)/fs;$(KERNEL_TRUNK)/blkdev" $(FASM) $< $@ -m 123456
kofu.o: kofu.c kocdecl.h
$(CC) $(CFLAGS) -c $<