|
|
- BITS 16
- start_sing:
- ; loading essentials for SingOS to run
- mov ax, 0x0150
- mov ds, ax
- mov es, ax
-
- ; Setup stack
- mov ax, 0x8fc0
- mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
- mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
- mov bp, sp
-
- mov [global_disk_FSCI_LBA_position], bx ; passed by the volume boot record.
-
- 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
-
- ; setup file system information
- ; mov cx, [global_disk_FSCI_LBA_position]
- ; mov WORD [Parameter_Struct.buffer_segment], 0x50
- ; mov WORD [Parameter_Struct.buffer_address], 0x2000 ; Heap memory start adresses for the file system
- ; mov WORD [Parameter_Struct.buffer_size], 0x3000 ; End address for the heap
- ; mov WORD [Parameter_Struct.data_length], cx
- ;
- ; mov bx, ds
- ; mov cx, Parameter_Struct
- ; mov ax, 0x1
- ; push cx
- ; push bx
- ; push ax
- ; mov cx, 0x50
- ; mov ds, cx
- ; mov es, cx
- ; call 0x50:0x00
- ; add sp, 0x6 ; skip the paramerts
- ; mov cx, 0x0150
- ; mov ds, cx
- ; mov es, cx
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; SYSTEM CALL TABLE STARTING AT POSITION 0x0050:0x0000
- ; To already support 64-bit, the entries is 64-bit
- ; But in 16-bit, the adresses is only 16-bit
- ; These are stored in the first 16-bits
- ; There is reserved 2 sectors to the table witch means that we have room for
- ; 128 System Calls
- ; |----|----------------------------------------------------------------------------|
- ; | 1 | Master Table| call [0x0050:0x0000] Pointer to the Master File Table |
- ; |----|----------------------------------------------------------------------------|
- ; | 2 | FILE SYSTEM | call [0x0050:0x0008] for arguments see under the file system |
- ; |----|----------------------------------------------------------------------------|
- ; | 3 | OS_LIB | call [0x0050:0x0016] for arguments see under the file system |
- ; |----|----------------------------------------------------------------------------|
- ; | 1 | FILE SYSTEM | call [0x0050:0x0000] for arguments see under the file system |
- ; |----|----------------------------------------------------------------------------|
- ; | 2 | OS_LIB | call [0x0050:0x0008] for arguments see under the file system |
- ; |----|----------------------------------------------------------------------------|
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- xor bx, bx
- mov al, 0x49
- mov ah, 0x0E
- int 0x10
- jmp 0x0150:sing_loaded
- ;%include "mem_lib/mem_lib.nasm"
- %include "lib/os_lib.nasm"
- %include "lib/string.nasm"
- %include "lib/debug_tools.nasm"
- %include "lib/std_power.nasm"
- %include "lib/svim.nasm"
- %include "lib/xex.nasm"
- %include "filesystems/lsfs/lsfs.nasm" ; old filesystem was ;%include "vsfs/vsfs.nasm"
- %include "CLI/CLI.nasm"
-
- sing_loaded: ; SingOS is ready for the user:
- xor bx, bx
- mov al, 0x49
- mov ah, 0x0E
- int 0x10
- ; mov ax, 0x8fc0
- ; mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
- ; mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
- ; mov bp, sp
- ;
- sing_ready: ; SingOS is ready for the user:
- %if 0
- call Go32Bit
- %endif
-
- 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
-
- print_format example_format_string, 0xdead, 0xbeef, 0xbabe, 420
-
- call printCRLF
-
- call dump_general_registers
- call printCRLF
-
- call dump_segment_registers
- call printCRLF
-
- call dump_stack_registers
- call printCRLF
-
- call dump_status_flags
- call printCRLF
-
- call print_help_message
-
- mov si, command_line
- call print
- jmp terminal
- terminal:
- call wait_for_key
- jmp terminal
-
- wait_for_key:
- pusha
-
- mov ax, 0
- mov ah, 0x10 ; BIOS call to wait for key
- int 0x16
-
- cmp ax, 0x11b; ESC key
- je near .end
- cmp ax, 0x3b00 ; f1 key
- je .change_one
- cmp ax, 0x3c00 ; f2 key
- je .change_two
- cmp ax, 0x1c0d ; enter key
- je .enter_hit
- mov [.tmp_buf], ax ; save the key pressed befor printing it
-
- mov cx, [.tmp_buf]
- cmp cx, 0x0e08 ; backspace key
- ;je .backspace_handler
- jne .dont_backspace
-
- call CLI_DELETE
- popa
- ret
-
- .dont_backspace:
- call CLI_ASCII_INPUT
-
- .return_enter:
-
- popa ; But restore all other regs
- ret
-
- .os_buffer_full:
- mov si, .os_str_full
- call print
- popa
- ret
-
- .backspace_handler:
- ; bx already set to the current buffer count
- mov bx, [.os_command_buffer_counter]
- cmp bx, 0x00
- je .backspace_stop
- sub bx, 0x01
- mov [.os_command_buffer_counter], bx
- add bx, .os_command_buffer
- mov ax, 0x00
- mov [bx], ax
- mov ax, [.tmp_buf] ; load the backpace
- mov ah, 0xE ; print the backspace
- int 0x10
- mov al, 0
- int 0x10
- mov al, 0x08
- int 0x10
- ;mov al, 0x20 ; now the curser is one back
- ;int 0x10 ; print null charecter
- .backspace_stop:
- popa ; But restore all other regs
- ret
-
- .change_one:
-
- mov al, 0x00 ; arg: index 0
- call os_change_screen
- jmp terminal
-
- .change_two:
-
- mov al, 0x01 ; arg: index 0
- call os_change_screen
- jmp terminal
-
-
- .enter_hit:
- call CLI_CONFIRM_INPUT
- jmp .command_interpreter
-
- .no_str:
- mov si, command_line
- call print
- jmp .return_enter
-
- .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, 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
- .compare_with_svim db 'svim', 0 ; SingOS vim edition 'svim'
- .compare_with_clear db 'clear', 0 ; Clear the screen
- .compare_with_ls db 'ls', 0 ; List file table
-
- .end:
- mov si, exit_message
- call print
-
- call power_off
-
- cli
- hlt
-
- .change_display:
- mov ax, 0x4F02 ; set VBE mode
- mov bx, 0x4118 ; VBE mode number; notice that bits 0-13 contain the mode number and bit 14 (LFB) is set and bit 15 (DM) is clear.
- ;xor bx, bx
- ;xor cx, cx
- ;xor dx, dx
- ;mov ah, 0x06
- ;mov al, 0xff
- int 0x10
- ret
-
- .clearcommand:
- 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
-
- ; move curser back to the top of the screen
- mov ah, 0x02
- mov bh, 0x00 ; page number 0
- mov dh, 0x00 ; row zero
- mov dl, 0x00 ; coloumn zero
- int 0x10
- ret
-
- .tmp_buf dw 0
- .os_command_buffer times 255 dw 0
- .os_command_buffer_counter dw 0
- .os_str_full db 13, 10, 'Buffer is full', 13, 10, 0
-
- .command_interpreter:
-
- mov bx, [.os_command_buffer_counter]
- cmp bx, 0x00
- je near .no_str ; First byte is 0 => No command
- call printCRLF
- add bx, .os_command_buffer ; Note addition. Sets bx to the end of the string, which should be guaranteed to be 0
- mov ax, 0x00
- mov [bx], ax ; Ensure that the command is null-terminated
- xor bx, bx
- mov [.os_command_buffer_counter], bx
- mov si, .os_command_buffer
- call print ; Echo the command
-
- lea si, [.os_command_buffer]
- ;mov dword [.compare_with_LIST_searchindex], 0 ; Next time, start at 0
- mov cx, 0 ; Index
-
- .command_interpreter_searchloop:
- ;call printCRLF
- ;mov ax, cx
- ;call dumpax
- ;mov bx, [.compare_with_LIST_searchindex]
- mov bx, cx
- add bx, bx ; The pointers are 2 bytes long. Compensate here
-
- ;call printCRLF
- ;mov ax, cx
- ;call dumpax
-
- mov dx, [.compare_with_LIST_NAMES+bx] ; Here it HAS to be bx. Otherwise it is invalid for some reason
- mov bx, dx
-
- lea di, [bx]
-
- call stringcompare
-
- je .command_interpreter_foundcommand
-
- ; I don't assume here that the registers contain the same values they used to after the calls
- ;mov bx, [.compare_with_LIST_searchindex]
- ;inc bx
- ;mov [.compare_with_LIST_searchindex], bx
- inc cx
-
- mov bx, cx
- add bx, bx
- mov dx, [.compare_with_LIST_NAMES+bx]
-
- cmp dx, 0 ;Is it at the null terminator?
-
- jne .command_interpreter_searchloop ; There is another command to check
-
- jmp .no_str
-
- .command_interpreter_foundcommand:
- call printCRLF
-
- ;mov bx, [.compare_with_LIST_searchindex] ; Remember this thing
- mov bx, cx
- add bx, bx ;The pointers are 2 bytes long. Compensate here
-
- ;call printCRLF
- ;mov ax, cx
- ;call dumpax
-
- mov dx, [.compare_with_LIST_POINTERS+bx] ; This is where the program is.
-
- ;mov ax, dx
- ;call printCRLF
- ;call dumpax
-
- call dx
-
- jmp .no_str
- ;
-
- global_vars:
- 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_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.
- global_disk_identifier db 0 ; set by the bios passed by the bootloader,
- ; this is the bios ID
- global_disk_FSCI_LBA_position db 0
-
- data:
- welcome db "###############################################################################", 13, 10, "# Welcome to SingOS - VERSION 0.0.6.1 #", 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
- example_format_string db "(%x-%x-%x){%d%%}",0
-
-
- Parameter_Struct:
- .path dw 0x00 ; char*
- .new_path dw 0x00 ; char*
- .buffer_segment dw 0x00 ; int
- .buffer_address dw 0x00 ; int
- .buffer_size dw 0x00 ; int
- .data_length dw 0x00 ; int
- .byte_offset_into_file dw 0x00 ; int
- .entry_kind dw 0x00 ; Table_Entry_Kind
-
- ;times 131072-($-$$) db 0 ; 256 sectos
- ;GLOBAL_VSFS_START db 'VSFS v0.1' ; sector 257 reserved for file system information
-
- %include "go32bit.nasm"
|