Du kannst nicht mehr als 25 Themen auswählen
Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
441 Zeilen
13 KiB
441 Zeilen
13 KiB
BITS 16 |
|
%define LSFS_FIX_FILE_SIZE 0x10 |
|
%define LSFS_magic_start_sector 23 ; This is the sector right after the SingOS kernel stops and is a magic number that has to be changed when the kernel grows. |
|
%define FSCI_sector 88 |
|
|
|
lsfs_check_extended_support: |
|
; We have to test if the System support exented read/write bios int 13, |
|
; If not, the system cannot use the disk. |
|
xor ax, ax |
|
mov BYTE al, [global_disk_identifier] |
|
call dumpax |
|
|
|
mov ah, 0x41 ;Set AH = 0x41 |
|
mov bx, 0x55aa ;BX = 0x55AA |
|
mov dl, [global_disk_identifier] ;DL = disk_id |
|
int 0x13 |
|
;Issue an INT 0x13. |
|
jnc .is_supported |
|
; The System does support exented read write |
|
mov si, lsfs_disk_error_msg |
|
call print |
|
|
|
mov si, lsfs_disk_error_halt |
|
call print |
|
|
|
mov ax, 0 |
|
mov ah, 0x10 |
|
int 0x16 |
|
jmp .return |
|
|
|
.is_supported: |
|
mov BYTE [lsfs_global_is_suported], 0x1 |
|
|
|
.return: |
|
ret |
|
|
|
lsfs_format_disk: |
|
; When SingOS it booted for the first time, |
|
; we have to format the disk to create the global structure |
|
; of the lSFS. |
|
pusha |
|
cmp BYTE [lsfs_global_is_suported], 0x0 |
|
je .error |
|
|
|
.no_carry: |
|
|
|
; Write the buffer back. |
|
mov DWORD [DAPACK.lba_addr_dw_low], LSFS_magic_start_sector |
|
mov WORD [DAPACK.blkcnt], 0x1 |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov WORD [DAPACK.db_addr_offset], .lsfs_format_disk_buffer |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x43 ; WRITE |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
jmp .return |
|
.error: |
|
mov si, lsfs_disk_error_msg |
|
call print |
|
|
|
.return: |
|
popa |
|
ret |
|
|
|
.lsfs_format_disk_buffer db 'LSFS v0.0.6', 13, 10, '(LessSimpelFileSystem)', 13, 10, 'Developed to SingOS', 13, 10, 'by Jorn Guldberg', 13, 10, 0 ; 66 chars + 8 bytes |
|
times 429 db 0 |
|
dw LSFS_magic_start_sector, 0, 1 ; Start index, number of files, next free index |
|
|
|
lsfs_get_fs_info: |
|
pusha |
|
|
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov WORD [DAPACK.lba_addr_dw_low], FSCI_sector |
|
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x42 ; READ |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
mov si, lsfs_loading_buffer |
|
call print |
|
|
|
popa |
|
ret |
|
|
|
lsfs_read_file: |
|
; INPUT ax = file index |
|
; INPUT bx = filebuffer |
|
pusha ; save all register state |
|
; We need to find the data pointers for the file. |
|
|
|
push bx |
|
|
|
mov dx, LSFS_magic_start_sector |
|
add ax, dx ; senctor number, into the master Table. |
|
|
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov WORD [DAPACK.lba_addr_dw_low], ax |
|
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x42 ; READ |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
pop bx |
|
|
|
; Save the buffer addr |
|
mov WORD [DAPACK.db_addr_offset], bx |
|
mov bx, [lsfs_loading_buffer + 288] ; this is the first data pointer |
|
mov ax, bx |
|
|
|
mov WORD [DAPACK.lba_addr_dw_low], bx |
|
mov WORD [DAPACK.blkcnt], 0x4 ; Read to sectors, that is what the space is for the buffer in svim |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x42 ; READ |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
popa |
|
|
|
mov ax, [lsfs_loading_buffer + 264] |
|
ret |
|
|
|
|
|
lsfs_write_file: |
|
|
|
; INPUT ax = file index |
|
; INPUT bx = filebuffer |
|
; INOUT cx = file size |
|
pusha ; save all register state |
|
; We need to find the data pointers for the file. |
|
|
|
push bp |
|
mov bp, sp |
|
sub sp, 6 |
|
|
|
%define var_file_id [bp - 0] |
|
%define var_file_buffer [bp - 2] |
|
%define var_file_size [bp - 4] |
|
|
|
mov var_file_buffer, bx |
|
mov var_file_size, cx |
|
|
|
mov dx, LSFS_magic_start_sector |
|
add ax, dx ; senctor number, into the master Table. |
|
mov var_file_id, ax |
|
|
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov WORD [DAPACK.lba_addr_dw_low], ax |
|
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x42 ; READ |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
; Save the buffer addr |
|
mov bx, var_file_buffer |
|
mov WORD [DAPACK.db_addr_offset], bx |
|
mov bx, [lsfs_loading_buffer + 288] ; this is the first data pointer |
|
mov WORD [DAPACK.lba_addr_dw_low], bx |
|
mov ax, bx |
|
mov WORD [DAPACK.blkcnt], 0x4 ; Read to sectors, that is what the space is for the buffer in svim |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x43 ; WRITE |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
mov ax, var_file_id |
|
mov bx, var_file_size |
|
|
|
mov [lsfs_loading_buffer + 264], bx |
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov WORD [DAPACK.lba_addr_dw_low], ax |
|
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x43 ; WRITE |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
mov sp, bp |
|
pop bp |
|
popa |
|
ret |
|
|
|
lsfs_create_file: |
|
; ax pointer to filename |
|
; bx size |
|
; cx fileIndex |
|
|
|
pusha ; save all register state |
|
|
|
mov si, .lsfs_create_file_type_filename |
|
call print |
|
|
|
; Ask the user for the filename |
|
xor bx, bx |
|
xor cx, cx ; are going to be the counter |
|
xor dx, dx |
|
.enter_filename_loop: |
|
push cx |
|
mov ax, 0x10 ; BIOS call to wait for key |
|
int 0x16 |
|
cmp ax, 0x1c0d ; enter key |
|
je .filename_done |
|
|
|
cmp ax, 0x0e08 ; backspace |
|
jne .no_enter |
|
pop cx |
|
cmp cx, 0 |
|
je .enter_filename_loop |
|
|
|
sub cx, 1 |
|
mov bx, .new_filename_buffer |
|
add bx, cx |
|
mov BYTE [bx], 0 |
|
; Go back one space |
|
mov ax, 0x0e08 ; ah=0x0e means teletype output. al=0x08 means backspace character. |
|
int 0x10 |
|
|
|
; Place a NULL |
|
mov al, 0x0 ; NULL |
|
int 0x10 |
|
|
|
; Go back one space again as the above print of NULL pushes the cursor forward again. |
|
mov ax, 0x0e08 |
|
int 0x10 |
|
jmp .enter_filename_loop |
|
|
|
.no_enter: |
|
mov bh, 0x00 |
|
mov bl, 0x02 |
|
mov ah, 0x0E |
|
int 0x10 ; print char |
|
pop cx |
|
mov bx, .new_filename_buffer |
|
add bx, cx |
|
mov [bx], al |
|
add cx, 1 |
|
; filename must only be 120 chars |
|
cmp cx, 120 |
|
jae .filename_done |
|
|
|
jmp .enter_filename_loop |
|
|
|
.filename_done: |
|
pop cx ; Cleanup, and now contain filename size |
|
mov bx, .new_filename_buffer |
|
add bx, cx |
|
mov BYTE [bx], 0 |
|
call printCRLF |
|
|
|
|
|
; We first need to know the index for the file. |
|
; The next avaliable index are we going to get from the |
|
; FSinfo sctor of the disk: |
|
mov DWORD [DAPACK.lba_addr_dw_low], FSCI_sector |
|
mov WORD [DAPACK.blkcnt], 0x1 |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x42 ; READ |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
mov bx, [lsfs_loading_buffer + 510] |
|
mov [.new_file_data_pointer], bx |
|
|
|
mov ax, [lsfs_loading_buffer + 508] |
|
mov [.to_write_fileindex_16_bit_part], ax |
|
|
|
add DWORD [lsfs_loading_buffer + 510], 4 ; First save the data pointer, and then add 4 sectors to get the next free sectors. |
|
add DWORD [lsfs_loading_buffer + 508], 1 ; Increment since we are creating a new file. |
|
|
|
; Write the buffer back. |
|
mov DWORD [DAPACK.lba_addr_dw_low], FSCI_sector |
|
mov WORD [DAPACK.blkcnt], 0x1 |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x43 ; WRITE |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
; Now we have the index in ax. |
|
|
|
; Set the es to point to the data segment, |
|
; this is the global segment, where we calculate all |
|
; our adresses from |
|
; ES:BX Buffer Address Pointer |
|
mov bx, ds |
|
mov es, bx |
|
|
|
mov ax, [.to_write_fileindex_16_bit_part] ; The number of files in the system |
|
add ax, LSFS_magic_start_sector ; The Master Record is at LSFS_magic_start_sector, plus the file index, then we have the sector where the file information has to be placed. |
|
|
|
mov WORD [DAPACK.lba_addr_dw_low], ax |
|
mov WORD [DAPACK.blkcnt], 0x1 |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov WORD [DAPACK.db_addr_offset], .new_filename_buffer |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x43 ; WRITE |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
popa |
|
ret |
|
|
|
.lsfs_create_file_type_filename db 'Enter filename: ', 0 |
|
|
|
.new_filename_buffer times 256 db 0 |
|
;.file_id: |
|
.to_write_fileindex_16_bit_part dw 0 |
|
.to_write_fileindex dw 0, 0, 0 |
|
;.file_size |
|
.new_file_size dw 0, 0, 0 |
|
.new_file_size_16_bit_part dw 0 |
|
|
|
.ext_file_data dw 0, 0, 0, 0 |
|
.control_bits dw 0, 0, 0, 0 |
|
;.file_data_pointers |
|
.new_file_data_pointer dw 0 |
|
times 222 db 0 |
|
|
|
lsfs_list_files_command: |
|
; This function takes the adress of the first sector of the disk |
|
; which the OS has to know |
|
; the adress is given by ax |
|
|
|
; Check which registers to save |
|
pusha |
|
|
|
; Load the master table into memory |
|
;mov ax, 8 ; file index for master record |
|
;mov bx, lsfs_loading_buffer ; pointer to the input buffer |
|
;call lsfs_read_file_index_in_ax ; call the fucntion which read the master record |
|
; TODO we might want this to be in memory at all times |
|
; loaded already from boot |
|
|
|
mov bx, ds |
|
mov es, bx |
|
|
|
mov si, .ls_header |
|
call print |
|
|
|
mov si, .seperate_line |
|
call print |
|
|
|
mov WORD [.ls_counter], 23 |
|
.load_next_fileinfo: |
|
add WORD [.ls_counter], 1 |
|
|
|
mov bx, [.ls_counter] |
|
mov WORD [DAPACK.lba_addr_dw_low], bx |
|
mov WORD [DAPACK.blkcnt], 0x1 |
|
mov WORD [DAPACK.db_addr_segment], 0x50 |
|
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer |
|
mov si, DAPACK ; address of "disk address packet" |
|
mov ah, 0x42 ; READ |
|
mov dl, [global_disk_identifier] |
|
int 0x13 |
|
|
|
mov ax, [lsfs_loading_buffer + 256] |
|
mov bx, ax |
|
mov cx, ' ' |
|
mov dx, 'X' |
|
|
|
cmp BYTE [lsfs_loading_buffer], 0 |
|
je .end_ls |
|
cmp ax, 10 |
|
ja .index_over_10 |
|
mov [.fileentry_line + 3 ], cx |
|
mov [.fileentry_line + 4 ], cx |
|
add bx, 48 ; get ascii value |
|
mov [.fileentry_line + 5 ], bl |
|
jmp .stop_index |
|
.index_over_10: |
|
cmp ax, 10 |
|
ja .index_over_100 |
|
mov [.fileentry_line + 3 ], cx |
|
mov [.fileentry_line + 4 ], dx |
|
mov [.fileentry_line + 5 ], dx |
|
jmp .stop_index |
|
|
|
.index_over_100: |
|
mov [.fileentry_line + 3 ], dx |
|
mov [.fileentry_line + 4 ], dx |
|
mov [.fileentry_line + 5 ], dx |
|
|
|
|
|
.stop_index: |
|
|
|
mov si, .fileentry_line ; printing the buffer |
|
call print |
|
mov si, lsfs_loading_buffer ; printing the buffer |
|
call print |
|
|
|
call printCRLF |
|
mov si, .seperate_line |
|
|
|
call print |
|
jmp .load_next_fileinfo |
|
|
|
.end_ls: |
|
popa |
|
ret |
|
|
|
.ls_counter dw 0 |
|
.ls_header db 'List of files:', 13, 10, 'Index | Filename ', 13, 10, 0 |
|
.seperate_line db '- - - - - - - - - - - - - - - - ', 13, 10, 0 |
|
.fileentry_line db ' 456 | ', 0 |
|
|
|
lsfs_disk_error_msg db 'The system does not support disk operations,', 13, 10, 0 |
|
lsfs_disk_error_halt db 'press a key to continue with no disk operations', 13, 10, 0 |
|
|
|
align 2 |
|
lsfs_loading_buffer times 512 db 0 |
|
|
|
MetaInformationFormat: |
|
.filename: times 252 db 0 |
|
.file_id: dw 0 |
|
.file_size dw 0 |
|
.file_data_pointers times 256 db 0 |
|
|
|
|
|
DAPACK: |
|
.dap_Size: db 0x10 ; This is always 16 bytes (0x10) |
|
.rev_byte: db 0x0 ; reserved byte, should always be zero |
|
.blkcnt: dw 0x0 ; int 13 resets this to # of blocks actually read/written |
|
.db_addr_offset: dw 0x0 ; memory buffer destination address (0:7c00) |
|
.db_addr_segment: dw 0x0 ; in memory page zero |
|
.lba_addr_dw_low: dd 0x0 ; put the lba to read in this spot |
|
.lba_addr_dw_high: dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes ) |
|
|
|
lsfs_global_is_suported db 0x1 ; 0 means is not supported, when SingOS i booted it will check if it is supported (int 0x13 extended read/write) |