diff --git a/CLI/CLI.nasm b/CLI/CLI.nasm index d3ccea5..a6235c4 100644 --- a/CLI/CLI.nasm +++ b/CLI/CLI.nasm @@ -135,13 +135,15 @@ CLI_EXECUTE: ret .tmp dw 0 - .Num_Commands dw 5 - .Command_Name_List dw .CMD1, .CMD2, .CMD3, .CMD4, .CMD5 - .Command_Function_Pointers dw dumpmem, keyprint, svim, vfsf_list_files_command, vfsf_create_file + .Num_Commands dw 7 + .Command_Name_List dw .CMD1, .CMD2, .CMD3, .CMD4, .CMD5, .CMD6, .CMD7 + .Command_Function_Pointers dw dumpmem, keyprint, svim, vsfs_list_files_command, vsfs_create_file, vsfs_format_disk, vsfs_get_fs_info .CMD1 db 'dumpmem', 0 .CMD2 db 'keyprint', 0 .CMD3 db 'svim', 0 .CMD4 db 'ls', 0 .CMD5 db 'createfile', 0 + .CMD6 db 'formatdisk', 0 + .CMD7 db 'fsinfo', 0 diff --git a/SingOS.img b/SingOS.img index f4c574c..dcf6c95 100644 Binary files a/SingOS.img and b/SingOS.img differ diff --git a/bootloader.bin b/bootloader.bin index 58596f2..abec0e1 100644 Binary files a/bootloader.bin and b/bootloader.bin differ diff --git a/kernel.bin b/kernel.bin index 4e44bb7..4ac4ca2 100644 Binary files a/kernel.bin and b/kernel.bin differ diff --git a/kernel.nasm b/kernel.nasm index 83c2290..4ce73e8 100644 --- a/kernel.nasm +++ b/kernel.nasm @@ -1,5 +1,12 @@ BITS 16 start_sing_os: + ; loading essentials for SingOS to run + + ; VSFS is loaded: + + + ; SingOS is ready for the user: + mov si, welcome ; Put address of the null-terminated string to output into 'si' call print_os ; Call our string-printing routine @@ -115,7 +122,7 @@ wait_for_key_os: .compare_with_LIST_searchindex dw 0 .compare_with_LIST_NAMES dw .compare_with_dumpmem, .compare_with_keyprint, .compare_with_display, .compare_with_svim, .compare_with_clear, .compare_with_ls, 0 - .compare_with_LIST_POINTERS dw dumpmem, keyprint, .change_display, svim, .clearcommand, vfsf_list_files_command, 0 + .compare_with_LIST_POINTERS dw dumpmem, keyprint, .change_display, svim, .clearcommand, vsfs_list_files_command, 0 .compare_with_dumpmem db 'dumpmem', 0 .compare_with_keyprint db 'keyprint', 0 .compare_with_display db 'display', 0 ; original this is the display command for better grapichs @@ -244,6 +251,16 @@ wait_for_key_os: ; +global_vars_os: + global_vsfs_master_record dw 8 ; this is the index of the start of the master table for the filesystem + ; This should maby contain more information. + ; and somehow be setted in a fix sector, which holds all the variabels for SingOS + ; 8 is currently the magic number where the file system starts on our disk. + + global_vsfs_next_index dw 0 ; This is the next index to the next file created. + ; this var is set durling load of SingOS + ; Changed my mind, the index is currently loaded and written back to disk under + ; creation of a new file. data_os: welcome db 'This is SingOS! v0.0.3', 13, 10, 'Press ESC to halt.', 13, 10, 0 @@ -251,7 +268,7 @@ data_os: command_line db 13, 10, 'groot@SingOS $ ', 0 number_one_zstring db '71', 0 - +%include "mem_lib/mem_lib.nasm" %include "lib/os_lib.nasm" %include "lib/string.nasm" %include "lib/dumpmem.nasm" diff --git a/mem_lib/mem_lib.nasm b/mem_lib/mem_lib.nasm new file mode 100644 index 0000000..204616d --- /dev/null +++ b/mem_lib/mem_lib.nasm @@ -0,0 +1,4 @@ +BITS 16 + +mem_get_zstack_buffer: + ; INPUT size of zeroed buffer ax in bytes diff --git a/vsfs/vsfs.nasm b/vsfs/vsfs.nasm index 7d65bb9..e38196f 100644 --- a/vsfs/vsfs.nasm +++ b/vsfs/vsfs.nasm @@ -1,10 +1,71 @@ BITS 16 +vsfs_format_disk: + ; When SingOS it booted for the first time, + ; we have to format the disk to create the global structure + ; of the VSFS. + + ;AH 03h + ;AL Sectors To Write Count + ;CH Track + ;CL Sector + ;DH Head + ;DL Drive + + ; 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 + + ; Set the bx to point to the pointer of the sector we have to write + ; to the disk. + mov bx, .vsfs_format_disk_buffer + mov ah, 0x03 ;Write sectors to drive + mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes) + mov cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) + mov ch, 0x08 + mov dh, 0x00 ;Head number + mov dl, 0x00 ;Drive number + int 0x13 ;Low level disk services + + ret + + .vsfs_format_disk_buffer db 'VSFS v0.1', 13, 10, '(VerySimpelFileSystem)', 13, 10, 'Developed to SingOS', 13, 10, 'by Jorn Guldberg', 13, 10 ; 66 chars + 8 bytes + times 434 db 0 + dw 8, 9 + +vsfs_get_fs_info: + popa + mov bx, ds + mov es, bx + mov bx, vsfs_loading_buffer + + mov ch, al ; Low 8 bits of cylinder + ; the file index into ch, we need to calculatet this, if the number is larger than 16-bits + mov ah, 0x02 ; Read sectors from drive + mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes) + mov ch, 0x08 ; cylinder + mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) + mov dh, 0x00 ; Head number + mov dl, 0x00 ; Drive number + int 0x13 + + mov si, vsfs_loading_buffer + call print_os + pusha + vsfs_read_file_index_in_ax: ; INPUT ax = file index - ; INPUT FOR FUNCTION file index at bx + ; INPUT bx = filebuffer pusha ; save all register state - call vsfs_convert_index_into_regs + ;call vsfs_convert_index_into_regs ;mov bx, .buffer_for_svim + push bx + mov bx, ds + mov es, bx + pop bx + mov ch, al ; Low 8 bits of cylinder ; the file index into ch, we need to calculatet this, if the number is larger than 16-bits mov ah, 0x02 ; Read sectors from drive @@ -52,51 +113,103 @@ vsfs_convert_index_into_regs: ret -vfsf_write_file_system_information: - - ret - -vfsf_create_file: +vsfs_create_file: ; ax pointer to filename ; bx size ; cx fileIndex pusha ; save all register state - - mov si, .vfsf_create_file_type_filename + + mov si, .vsfs_create_file_type_filename call print_os + + ; 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 +.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 + call printCRLF_os + + + ; 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 bx, ds + mov es, bx + + mov bx, vsfs_loading_buffer + mov ch, 0x08 ; Low 8 bits of cylinder + ; the file index into ch, we need to calculatet this, if the number is larger than 16-bits + mov ah, 0x02 ; Read sectors from drive + mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes) + mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) + mov dh, 0x00 ; Head number + mov dl, 0x00 ; Drive number + int 0x13 + + mov ax, [vsfs_loading_buffer + 510] + ; We have to do modulo 4, to know where in the sector the + ; file entry has to be written + + mov [.to_write_fileindex], ax + ; Now we have the index in ax. + ;AH 03h ;AL Sectors To Write Count ;CH Track ;CL Sector ;DH Head ;DL Drive - ;ES:BX Buffer Address Pointer + + ; 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 - xor bx, bx - mov bx, .test_file_name - xor cx, cx - xor ax, ax + + ; Set the bx to point to the pointer of the sector we have to write + ; to the disk. + mov bx, .new_filename_buffer mov ah, 0x03 ;Write sectors to drive mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes) - mov cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) - mov ch, 0x09 + mov cl, 0x02 ;First sector to write (bits 0-5), upper bits of cylinder (bits 6-7) + mov ch, 0x08 mov dh, 0x00 ;Head number mov dl, 0x00 ;Drive number int 0x13 ;Low level disk services popa ret - ret - - .vfsf_create_file_type_filename db 'Enter filename: ', 0 - .vfsf_create_file_type_filetype db 'Enter file index: ', 0 - .test_file_name db 'README.md' - times 118 db 0 - dw 9 + .vsfs_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 -vfsf_list_files_command: +vsfs_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 @@ -105,12 +218,26 @@ vfsf_list_files_command: pusha ; Load the master table into memory - mov ax, 9 ; file index for master record - mov bx, vfsf_loading_buffer ; pointer to the input buffer - call vsfs_read_file_index_in_ax ; call the fucntion which read the master record + ;mov ax, 8 ; file index for master record + ;mov bx, vsfs_loading_buffer ; pointer to the input buffer + ;call vsfs_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 bx, vsfs_loading_buffer + + ;mov ch, al ; Low 8 bits of cylinder + ; the file index into ch, we need to calculatet this, if the number is larger than 16-bits + mov ah, 0x02 ; Read sectors from drive + mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes) + mov ch, 0x08 ; cylinder + mov cl, 0x02 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) + mov dh, 0x00 ; Head number + mov dl, 0x00 ; Drive number + int 0x13 + mov si, .ls_header call print_os @@ -118,7 +245,7 @@ vfsf_list_files_command: call print_os - mov ax, [vfsf_loading_buffer + 127] + mov ax, [vsfs_loading_buffer + 126] mov bx, ax mov cx, ' ' mov dx, 'X' @@ -148,30 +275,12 @@ vfsf_list_files_command: mov si, .fileentry_line ; printing the buffer call print_os - mov si, vfsf_loading_buffer ; printing the buffer + mov si, vsfs_loading_buffer ; printing the buffer call print_os call printCRLF_os mov si, .seperate_line call print_os - ;mov si, .seperate_line - ;call print_os - ;mov si, .File_name_1 - ;call print_os - ;mov si, .seperate_line - ;call print_os - ;mov si, .File_name_2 - ;call print_os - ;mov si, .seperate_line - ;call print_os - ;mov si, .File_name_3 - ;call print_os - ;mov si, .seperate_line - ;call print_os - ;mov si, .File_name_4 - ;call print_os - ;mov si, .seperate_line - ;call print_os .end_ls: popa ret @@ -180,4 +289,4 @@ vfsf_list_files_command: .seperate_line db '- - - - - - - - - - - - - - - - ', 13, 10, 0 .fileentry_line db ' 456 | ', 0 -vfsf_loading_buffer times 512 db 0 \ No newline at end of file +vsfs_loading_buffer times 512 db 0 \ No newline at end of file