2017-10-18 22:19:53 +02:00
|
|
|
format ELF
|
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
__DEBUG__ = 1
|
2017-11-02 21:41:11 +01:00
|
|
|
__DEBUG_LEVEL__ = 1
|
2017-10-18 22:19:53 +02:00
|
|
|
|
2018-05-18 19:16:00 +02:00
|
|
|
extrn malloc
|
|
|
|
malloc fix __malloc
|
|
|
|
_malloc fix malloc
|
2018-06-13 03:29:17 +02:00
|
|
|
extrn free
|
|
|
|
free fix __free
|
|
|
|
_free fix free
|
2018-04-23 12:09:46 +02:00
|
|
|
include 'macros.inc'
|
2017-10-18 22:19:53 +02:00
|
|
|
include 'proc32.inc'
|
|
|
|
include 'struct.inc'
|
|
|
|
include 'const.inc'
|
|
|
|
include 'system.inc'
|
|
|
|
include 'debug-fdo.inc'
|
2018-05-04 20:18:09 +02:00
|
|
|
include 'blkdev/disk.inc'
|
|
|
|
include 'blkdev/disk_cache.inc'
|
|
|
|
include 'fs/fs_lfn.inc'
|
|
|
|
include 'crc.inc'
|
2017-10-18 22:19:53 +02:00
|
|
|
|
2018-05-18 09:09:05 +02:00
|
|
|
struct FILE_DISK
|
|
|
|
fd dd ?
|
|
|
|
Sectors dd ?
|
|
|
|
Logical dd ? ; sector size
|
|
|
|
ends
|
|
|
|
|
2017-10-18 22:19:53 +02:00
|
|
|
purge section,mov,add,sub
|
|
|
|
section '.text' executable align 16
|
|
|
|
|
2018-04-24 18:51:48 +02:00
|
|
|
;uint32_t kos_time_to_epoch(uint8_t *time);
|
|
|
|
public kos_time_to_epoch
|
|
|
|
kos_time_to_epoch:
|
|
|
|
push ebx esi edi ebp
|
|
|
|
|
|
|
|
mov esi, [esp + 0x14]
|
|
|
|
call fsCalculateTime
|
|
|
|
add eax, 978307200 ; epoch to 2001.01.01
|
|
|
|
|
|
|
|
pop ebp edi esi ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2018-05-18 18:48:50 +02:00
|
|
|
;void *kos_fuse_init(int fd, uint32_t sect_cnt, uint32_t sect_sz);
|
2017-10-18 22:19:53 +02:00
|
|
|
public kos_fuse_init
|
|
|
|
kos_fuse_init:
|
|
|
|
push ebx esi edi ebp
|
|
|
|
|
2018-05-06 21:58:05 +02:00
|
|
|
mov [pg_data.pages_free], (128*1024*1024)/0x1000
|
|
|
|
|
2017-10-18 22:19:53 +02:00
|
|
|
mov eax, [esp + 0x14]
|
2018-05-09 23:08:52 +02:00
|
|
|
mov [file_disk.fd], eax
|
|
|
|
mov eax, [esp + 0x18]
|
|
|
|
mov [file_disk.Sectors], eax
|
2018-05-18 18:48:50 +02:00
|
|
|
mov eax, [esp + 0x1c]
|
|
|
|
mov [file_disk.Logical], eax
|
2018-05-04 20:18:09 +02:00
|
|
|
stdcall disk_add, disk_functions, disk_name, file_disk, DISK_NO_INSERT_NOTIFICATION
|
2018-05-14 09:54:05 +02:00
|
|
|
push eax
|
|
|
|
stdcall disk_media_changed, eax, 1
|
|
|
|
pop eax
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, [eax + DISK.NumPartitions]
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
pop ebp edi esi ebx
|
|
|
|
ret
|
|
|
|
|
2018-04-24 18:51:48 +02:00
|
|
|
|
2018-05-09 23:08:52 +02:00
|
|
|
public kos_fuse_lfn
|
|
|
|
kos_fuse_lfn:
|
|
|
|
push ebx
|
|
|
|
mov ebx, [esp + 8]
|
2018-05-06 21:58:05 +02:00
|
|
|
pushad ; file_system_lfn writes here
|
|
|
|
call file_system_lfn
|
|
|
|
popad
|
2018-06-18 03:55:51 +02:00
|
|
|
mov ecx, [esp + 12]
|
|
|
|
mov [ecx + 0], eax
|
|
|
|
mov [ecx + 4], ebx
|
2018-05-09 23:08:52 +02:00
|
|
|
pop ebx
|
2017-11-16 02:16:20 +01:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
proc disk_read stdcall, userdata, buffer, startsector:qword, numsectors
|
2017-10-18 22:19:53 +02:00
|
|
|
pushad
|
2018-05-04 20:18:09 +02:00
|
|
|
mov eax, dword[startsector + 0] ; sector lo
|
|
|
|
mov edx, dword[startsector + 4] ; sector hi
|
2018-05-18 18:48:50 +02:00
|
|
|
mov edx, [userdata]
|
|
|
|
mul [edx + FILE_DISK.Logical]
|
|
|
|
mov ecx, edx
|
|
|
|
mov edx, eax
|
2018-05-17 10:20:54 +02:00
|
|
|
;DEBUGF 1, "lseek to: %x\n", edx
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, [userdata]
|
|
|
|
mov ebx, [eax + FILE_DISK.fd]
|
2018-05-15 08:54:22 +02:00
|
|
|
sub esp, 8
|
|
|
|
mov esi, esp
|
|
|
|
mov edi, SEEK_SET
|
|
|
|
mov eax, SYS_LLSEEK
|
2017-10-18 22:19:53 +02:00
|
|
|
int 0x80
|
2018-05-15 08:54:22 +02:00
|
|
|
add esp, 8
|
|
|
|
;DEBUGF 1, "lseek: %x\n",eax
|
2017-10-18 22:19:53 +02:00
|
|
|
popad
|
|
|
|
|
|
|
|
pushad
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, [userdata]
|
|
|
|
mov ebx, [eax + FILE_DISK.fd]
|
2018-05-04 20:18:09 +02:00
|
|
|
mov ecx, [buffer]
|
|
|
|
mov edx, [numsectors]
|
|
|
|
mov edx, [edx]
|
2018-05-09 23:08:52 +02:00
|
|
|
imul edx, [eax + FILE_DISK.Logical]
|
|
|
|
mov eax, SYS_READ
|
2017-10-18 22:19:53 +02:00
|
|
|
int 0x80
|
2018-05-06 21:58:05 +02:00
|
|
|
;DEBUGF 1, "read: %d\n", eax
|
2017-10-18 22:19:53 +02:00
|
|
|
popad
|
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
movi eax, DISK_STATUS_OK
|
2017-10-18 22:19:53 +02:00
|
|
|
ret
|
2018-05-04 20:18:09 +02:00
|
|
|
endp
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
proc disk_write stdcall, userdata, buffer, startsector:qword, numsectors
|
2017-10-18 22:19:53 +02:00
|
|
|
pushad
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, dword[startsector + 0] ; sector lo
|
|
|
|
mov edx, dword[startsector + 4] ; sector hi
|
2018-05-18 18:48:50 +02:00
|
|
|
mov edx, [userdata]
|
|
|
|
mul [edx + FILE_DISK.Logical]
|
|
|
|
mov ecx, edx
|
|
|
|
mov edx, eax
|
2018-05-15 08:54:22 +02:00
|
|
|
;DEBUGF 1, "lseek to: %x\n", ecx
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, [userdata]
|
|
|
|
mov ebx, [eax + FILE_DISK.fd]
|
2018-05-15 08:54:22 +02:00
|
|
|
sub esp, 8
|
|
|
|
mov esi, esp
|
|
|
|
mov edi, SEEK_SET
|
|
|
|
mov eax, SYS_LLSEEK
|
2017-10-18 22:19:53 +02:00
|
|
|
int 0x80
|
2018-05-15 08:54:22 +02:00
|
|
|
add esp, 8
|
|
|
|
;DEBUGF 1, "lseek: %x\n",eax
|
2017-10-18 22:19:53 +02:00
|
|
|
popad
|
|
|
|
|
|
|
|
pushad
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, [userdata]
|
|
|
|
mov ebx, [eax + FILE_DISK.fd]
|
|
|
|
mov ecx, [buffer]
|
|
|
|
mov edx, [numsectors]
|
|
|
|
mov edx, [edx]
|
|
|
|
imul edx, [eax + FILE_DISK.Logical]
|
2018-05-04 20:18:09 +02:00
|
|
|
mov eax, SYS_WRITE
|
2017-10-18 22:19:53 +02:00
|
|
|
int 0x80
|
2018-05-04 20:18:09 +02:00
|
|
|
;DEBUGF 1, "write: %d\n", eax
|
2017-10-18 22:19:53 +02:00
|
|
|
popad
|
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
movi eax, DISK_STATUS_OK
|
2017-10-18 22:19:53 +02:00
|
|
|
ret
|
2018-05-04 20:18:09 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
; int querymedia(void* userdata, DISKMEDIAINFO* info);
|
|
|
|
proc disk_querymedia stdcall, hd_data, mediainfo
|
|
|
|
mov ecx, [mediainfo]
|
2018-05-09 23:08:52 +02:00
|
|
|
mov edx, [hd_data]
|
2018-05-04 20:18:09 +02:00
|
|
|
mov [ecx + DISKMEDIAINFO.Flags], 0
|
2018-05-09 23:08:52 +02:00
|
|
|
mov eax, [edx + FILE_DISK.Logical]
|
|
|
|
mov [ecx + DISKMEDIAINFO.SectorSize], eax
|
|
|
|
mov eax, [edx + FILE_DISK.Sectors]
|
2018-05-04 20:18:09 +02:00
|
|
|
mov dword [ecx + DISKMEDIAINFO.Capacity], eax
|
|
|
|
mov dword [ecx + DISKMEDIAINFO.Capacity + 4], 0
|
|
|
|
|
|
|
|
movi eax, DISK_STATUS_OK
|
2017-10-18 22:19:53 +02:00
|
|
|
ret
|
2018-05-04 20:18:09 +02:00
|
|
|
endp
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
|
2018-05-18 19:16:00 +02:00
|
|
|
__malloc:
|
2018-05-18 09:09:05 +02:00
|
|
|
push ecx edx
|
2018-05-18 19:16:00 +02:00
|
|
|
ccall _malloc, eax
|
2018-05-18 09:09:05 +02:00
|
|
|
pop edx ecx
|
2017-10-18 22:19:53 +02:00
|
|
|
ret
|
|
|
|
|
2018-05-18 19:16:00 +02:00
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
proc kernel_alloc _size
|
|
|
|
mov eax, [_size]
|
|
|
|
call malloc
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
proc alloc_kernel_space _size
|
|
|
|
mov eax, [_size]
|
|
|
|
call malloc
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2018-05-06 21:58:05 +02:00
|
|
|
proc alloc_pages _cnt
|
|
|
|
mov eax, [_cnt]
|
2018-05-04 20:18:09 +02:00
|
|
|
shl eax, 12
|
|
|
|
call malloc
|
2017-10-18 22:19:53 +02:00
|
|
|
ret
|
2018-05-04 20:18:09 +02:00
|
|
|
endp
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
|
2018-06-13 03:29:17 +02:00
|
|
|
__free:
|
|
|
|
ccall _free, eax
|
2018-05-04 20:18:09 +02:00
|
|
|
ret
|
|
|
|
|
2018-05-09 23:08:52 +02:00
|
|
|
|
2018-06-13 03:29:17 +02:00
|
|
|
proc kernel_free base
|
|
|
|
mov eax, [base]
|
|
|
|
call free
|
|
|
|
xor eax, eax
|
2017-10-18 22:19:53 +02:00
|
|
|
ret
|
2018-05-06 21:58:05 +02:00
|
|
|
endp
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
put_board:
|
|
|
|
pushad
|
|
|
|
mov eax, SYS_WRITE
|
|
|
|
mov ebx, STDOUT
|
|
|
|
push ecx
|
|
|
|
mov ecx, esp
|
|
|
|
mov edx, 1
|
|
|
|
int 0x80
|
|
|
|
pop ecx
|
|
|
|
popad
|
|
|
|
ret
|
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2017-10-18 22:19:53 +02:00
|
|
|
|
2018-05-04 20:18:09 +02:00
|
|
|
|
|
|
|
sys_msg_board_str:
|
|
|
|
protect_from_terminate:
|
|
|
|
unprotect_from_terminate:
|
|
|
|
change_task:
|
|
|
|
ReadCDWRetr:
|
|
|
|
WaitUnitReady:
|
|
|
|
prevent_medium_removal:
|
|
|
|
Read_TOC:
|
|
|
|
commit_pages:
|
|
|
|
release_pages:
|
2018-05-09 23:08:52 +02:00
|
|
|
fs_execute:
|
|
|
|
mutex_init:
|
|
|
|
mutex_lock:
|
|
|
|
mutex_unlock:
|
2018-05-04 20:18:09 +02:00
|
|
|
ret
|
|
|
|
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
section '.data' writeable align 16
|
|
|
|
include_debug_strings
|
2018-05-04 20:18:09 +02:00
|
|
|
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:
|
|
|
|
|
2018-05-06 21:58:05 +02:00
|
|
|
disk_name db 'hd0',0
|
2018-05-09 23:08:52 +02:00
|
|
|
IncludeIGlobals
|
2017-10-18 22:19:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
section '.bss' writeable align 16
|
2018-05-09 23:08:52 +02:00
|
|
|
file_disk FILE_DISK
|
2018-05-06 21:58:05 +02:00
|
|
|
IncludeUGlobals
|
2018-05-09 23:08:52 +02:00
|
|
|
; crap
|
2018-05-04 20:18:09 +02:00
|
|
|
DiskNumber db ?
|
|
|
|
ChannelNumber db ?
|
|
|
|
DevErrorCode dd ?
|
|
|
|
CDSectorAddress dd ?
|
|
|
|
CDDataBuf_pointer dd ?
|
|
|
|
DRIVE_DATA: rb 0x4000
|
|
|
|
cdpos dd ?
|
2018-05-09 23:08:52 +02:00
|
|
|
cd_appl_data dd ?
|
2018-05-18 09:09:05 +02:00
|
|
|
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
|