Bläddra i källkod

Merge branch 'jorn_dev' of SingOS/SingOS into master

go32
Jørn Flemming Guldberg 5 år sedan
committed by Gogs
förälder
incheckning
c94d75e9e6
6 ändrade filer med 412 tillägg och 75 borttagningar
  1. +1
    -1
      CLI/CLI.nasm
  2. +1
    -3
      build
  3. +1
    -3
      build.sh
  4. +16
    -12
      kernel.nasm
  5. +12
    -56
      lib/svim.nasm
  6. +381
    -0
      vsfs/lsfs.nasm

+ 1
- 1
CLI/CLI.nasm Visa fil

@ -159,7 +159,7 @@ CLI_EXECUTE:
.tmp dw 0
.Num_Commands dw 9
.Command_Name_List dw .CMD1, .CMD2, .CMD3, .CMD4, .CMD5, .CMD6, .CMD7, .CMD8, .CMD9
.Command_Function_Pointers dw dumpmem_hardcoded_args, keyprint, svim, vsfs_list_files_command, vsfs_create_file, vsfs_format_disk, vsfs_get_fs_info, os_clear_screen, print_help_message
.Command_Function_Pointers dw dumpmem_hardcoded_args, keyprint, svim, lsfs_list_files_command, lsfs_create_file, lsfs_format_disk, lsfs_get_fs_info, os_clear_screen, print_help_message
.CMD1 db 'dumpmem', 0
.CMD2 db 'keyprint', 0
.CMD3 db 'svim', 0

+ 1
- 3
build Visa fil

@ -6,9 +6,7 @@ if [ "$1" == "build" ] || [ "$1" == "run" ]; then
cat bootloader.bin kernel.bin > SingOS.img
if [ $1 == "run" ]; then
#qemu-system-x86_64 -drive format=raw,file=SingOS.img
#qemu-system-x86_64 -hda SingOS.img
qemu-system-x86_64 -drive index=0,if=floppy,format=raw,file=SingOS.img
qemu-system-x86_64 -drive index=0,format=raw,file=SingOS.img
else
bash -c "echo;echo;echo 'Press [ENTER] to exit'; read line"
fi

+ 1
- 3
build.sh Visa fil

@ -7,9 +7,7 @@ if [ "$1" != "run" ]; then
fi
if [ "$1" != "make" ]; then
#qemu-system-x86_64 -drive format=raw,file=SingOS.img
#qemu-system-x86_64 -hda SingOS.img
qemu-system-x86_64 -drive index=0,if=floppy,format=raw,file=SingOS.img
qemu-system-x86_64 -drive index=0,format=raw,file=SingOS.img
fi
echo "Done"

+ 16
- 12
kernel.nasm Visa fil

@ -2,10 +2,10 @@ BITS 16
start_sing:
; loading essentials for SingOS to run
; VSFS is loaded:
mov [global_disk_identifier], dl ; saving disk_identifier, this is the number the disk that we are booting from.
; This number is set by the bios
call lsfs_check_extended_support ; Check that the int 0x13 extended read and write is available
jmp sing_loaded
%include "mem_lib/mem_lib.nasm"
%include "lib/os_lib.nasm"
@ -13,7 +13,8 @@ jmp sing_loaded
%include "lib/debug_tools.nasm"
%include "lib/std_power.nasm"
%include "lib/svim.nasm"
%include "vsfs/vsfs.nasm"
;%include "vsfs/vsfs.nasm"
%include "vsfs/lsfs.nasm"
%include "CLI/CLI.nasm"
sing_loaded: ; SingOS is ready for the user:
@ -24,7 +25,7 @@ sing_loaded: ; SingOS is ready for the user:
mov bp, sp
sing_ready: ; SingOS is ready for the user:
;call os_clear_screen
call os_clear_screen
mov si, welcome ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
@ -153,7 +154,7 @@ wait_for_key:
.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, vsfs_list_files_command, 0
.compare_with_LIST_POINTERS dw dumpmem, keyprint, .change_display, svim, .clearcommand, lsfs_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
@ -283,12 +284,12 @@ wait_for_key:
global_vars:
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_lsfs_master_record dw 2064 ; 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
; 2064 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.
global_lsfs_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.
@ -296,7 +297,7 @@ global_vars:
; this is the bios ID
data:
welcome db "###############################################################################", 13, 10, "# Welcome to SingOS anniversary edition. #", 13, 10, "# This build marks 1 year of SingOS! #", 13, 10, "###############################################################################", 13, 10, 'Press ESC to halt.', 13, 10, 13, 10, 0
welcome db "###############################################################################", 13, 10, "# Welcome to SingOS VERSION 0.0.3.12 #", 13, 10, "# #", 13, 10, "###############################################################################", 13, 10, 'Press ESC to halt.', 13, 10, 13, 10, 0
exit_message db 13, 10, 'Goodbye from SingOS',13,10,'The system has halted.', 0
command_line db 13, 10, 'groot@SingOS $ ', 0
number_one_zstring db '71', 0
@ -304,4 +305,7 @@ data:
;times 131072-($-$$) db 0 ; 256 sectos
;GLOBAL_VSFS_START db 'VSFS v0.1' ; sector 257 reserved for file system information
times (1<<20)-($-$$) db 0 ; sector 258 to sector 2048 should be avaliable to the filesystem.
times ((1<<20)-($-$$) - 26) db 0 ; sector 258 to sector 2048 should be avaliable to the filesystem.
magic_string_end_of_SingOS_kernel db '** END OF KERNEL SingOS **'
times ((1<<23)-($-$$)) db 0

+ 12
- 56
lib/svim.nasm Visa fil

@ -1,18 +1,9 @@
BITS 16
svim:
pusha ; save state before program
;mov si, .os_clear_screen_str
;call print
xor bx, bx
call os_clear_screen
;xor cx, cx ; Upper and left coordinate
;mov bh, 0x0a ; color for new screen 0 = black a = light green
;mov dh, 0xff ; Select all screen
;mov dl, 0xff ; Select all screen
;mov ah, 0x07 ; scrool down
;mov al, 0x00 ; scrool 0 lines (means blank screen )
;int 0x10
xor bx, bx
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x00 ; row zero
@ -23,7 +14,7 @@ svim:
call printCRLF
mov si, .seperate_line
call print
call vsfs_list_files_command
call lsfs_list_files_command
; move cursor to the bootom
xor ax, ax
@ -136,23 +127,15 @@ svim:
mov si, .seperate_line
call print
; LOAD FILE
; Prepare to ask the filesystem to load the file
; The file system should be given the file_id and the buffer where we can write
mov ax, [.fileindex_for_open_file]
mov ch, al ; move the fileindex in the ch
mov bx, ds
mov es, bx
xor bx, bx
mov bx, .buffer_for_svim
xor ax, ax
mov ah, 0x02 ;Read sectors from drive
mov al, 0x04 ;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, [global_disk_identifier] ;Drive number
int 0x13
call lsfs_read_file
mov bx, .buffer_for_svim
add bx, 2046
add bx, 1022
mov ax, [bx]
mov [.buffer_counter_svim], ax
; print buffer
@ -207,42 +190,15 @@ svim:
int 0x10 ; print char
jmp .svim_loop
.end_svim:
; save the written buffer
;AH 03h
;AL Sectors To Write Count
;CH Track
;CL Sector
;DH Head
;DL Drive
;ES:BX Buffer Address Pointer
mov ax, [.buffer_counter_svim]
mov bx, .buffer_for_svim
add bx, 2046
add bx, 1022
mov [bx], ax
mov bx, ds
mov es, bx
mov bx, .buffer_for_svim
mov ax, [.fileindex_for_open_file]
mov ch, al ; move the fileindex in the ch
mov ah, 0x03 ;Write sectors to drive
mov al, 0x04 ;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 dh, 0x00 ;Head number
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
mov bx, .buffer_for_svim
call lsfs_write_file
; clean up swim
;xor bx, bx
;xor cx, cx ; Upper and left coordinate
;mov bh, 0x0f ; color for new screen 0 = black f = white
;mov dh, 0xff ; Select all screen
;mov dl, 0xff ; Select all screen
;mov ah, 0x07 ; scrool down
;mov al, 0x00 ; scrool 0 lines (means blank screen )
;int 0x10
call os_clear_screen
popa
ret
@ -282,9 +238,9 @@ svim:
.debug_buffer_counter db 'Buffer count: %d', 13, 10, 0
.welcome_svim db 'Vim like text editor for SingOS, ESC to exit', 0
.welcome_svim_select_file db 'svim - Open file: ', 0
.welcome_svim_select_file db 'svim v0.0.2 - Open file: ', 0
.welcome_svim_enter_fileindex db 'Enter fileindex: ', 0
.seperate_line db '________________________________________________________________________________', 0
.fileindex_for_open_file dw 0
.buffer_for_svim times 2048 db 0 ; db 'this is the buffer', 0, times 32 db 0
.buffer_for_svim times 1024 db 0 ; db 'this is the buffer', 0, times 32 db 0
.buffer_counter_svim dw 0

+ 381
- 0
vsfs/lsfs.nasm Visa fil

@ -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)

Laddar…
Avbryt
Spara