6 changed files with 412 additions and 75 deletions
@ -0,0 +1,381 @@
|
||||
BITS 16 |
||||
%define LSFS_FIX_FILE_SIZE 0x10 |
||||
%define LSFS_magic_start_sector 2064 ; This is the sector right after the SingOS kernel stops and is a magic number that has to be changed when the kernel grows. |
||||
|
||||
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. |
||||
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: |
||||
xor ax, ax |
||||
xor bx, bx |
||||
xor cx, cx |
||||
xor dx, dx |
||||
|
||||
.DAPACK: |
||||
db 0x10 |
||||
db 0x0 |
||||
.blkcnt: dw 0x1 ; int 13 resets this to # of blocks actually read/written |
||||
.db_add_first: dw 0x0 ; memory buffer destination address (0:7c00) |
||||
.db_add_second: dw 0x050 ; in memory page zero |
||||
.d_lba: dd LSFS_magic_start_sector ; put the lba to read in this spot |
||||
dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes ) |
||||
|
||||
;mov WORD [.db_add_second], 0x50 |
||||
|
||||
mov ax, [.db_add_second] |
||||
call dumpax |
||||
call printCRLF |
||||
|
||||
mov WORD [.db_add_first], .lsfs_format_disk_buffer |
||||
mov ax, [.db_add_first] |
||||
call dumpax |
||||
call printCRLF |
||||
|
||||
mov si, .DAPACK ; address of "disk address packet" |
||||
mov ah, 0x43 ; AL is unused |
||||
mov dl, [global_disk_identifier] ; drive number 0 (OR the drive # with 0x80) |
||||
int 0x13 |
||||
|
||||
call dumpax |
||||
call printCRLF |
||||
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_one], LSFS_magic_start_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 |
||||
; Save the buffer addr |
||||
mov WORD [DAPACK.db_addr_offset], bx |
||||
|
||||
; The file index, has to be multiplied by the magic file_size |
||||
mov bx, LSFS_FIX_FILE_SIZE |
||||
mul bx |
||||
; OBS HARDCODED, The mul can give us a much higher number and DAPACK.lba_addr_dw_one takes a DWORD. |
||||
add ax, LSFS_magic_start_sector |
||||
mov WORD [DAPACK.lba_addr_dw_one], ax |
||||
mov WORD [DAPACK.blkcnt], 0x2 ; 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 |
||||
ret |
||||
|
||||
|
||||
lsfs_write_file: |
||||
; INPUT ax = file index |
||||
; INPUT bx = filebuffer |
||||
pusha ; save all register state |
||||
; Save the buffer addr |
||||
mov WORD [DAPACK.db_addr_offset], bx |
||||
|
||||
; The file index, has to be multiplied by the magic file_size |
||||
mov bx, LSFS_FIX_FILE_SIZE |
||||
mul bx |
||||
; OBS HARDCODED, The mul can give us a much higher number and DAPACK.lba_addr_dw_one takes a DWORD. |
||||
add ax, LSFS_magic_start_sector |
||||
mov WORD [DAPACK.lba_addr_dw_one], ax |
||||
mov WORD [DAPACK.blkcnt], 0x2 ; 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 |
||||
|
||||
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_one], LSFS_magic_start_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 ax, [lsfs_loading_buffer + 510] |
||||
mov [.to_write_fileindex], ax |
||||
|
||||
; We have to do modulo 4, to know where in the sector the |
||||
; file entry has to be written |
||||
add DWORD [lsfs_loading_buffer + 510], 1 |
||||
add DWORD [lsfs_loading_buffer + 508], 1 |
||||
|
||||
; Write the buffer back. |
||||
mov DWORD [DAPACK.lba_addr_dw_one], LSFS_magic_start_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, [lsfs_loading_buffer + 508] ; 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_one], 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 122 db 0 |
||||
.new_file_size dw 0, 0 |
||||
.to_write_fileindex dw 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], LSFS_magic_start_sector |
||||
.load_next_fileinfo: |
||||
add WORD [.ls_counter], 1 |
||||
|
||||
mov bx, [.ls_counter] |
||||
mov WORD [DAPACK.lba_addr_dw_one], 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 + 126] |
||||
mov bx, ax |
||||
mov cx, ' ' |
||||
mov dx, 'X' |
||||
|
||||
cmp ax, 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 |
||||
|
||||
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_one: dd 0x0 ; put the lba to read in this spot |
||||
.lba_addr_dw_two: dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes ) |
||||
|
||||
lsfs_global_is_suported db 0x0 ; 0 means is not supported, when SingOS i booted it will check if it is supported (int 0x13 extended read/write) |
Loading…
Reference in new issue