Browse Source

Merge pull request #19 from Rhodez-x/second_stage

Second stage
special_first_anniversary_edition
Jørn Guldberg 7 years ago committed by GitHub
parent
commit
5fb30b1dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      CLI/CLI.nasm
  2. 65
      bootloader.nasm
  3. 34
      kernel.nasm
  4. 26
      lib/os_lib.nasm
  5. 129
      lib/svim.nasm
  6. 16
      vsfs/vsfs.nasm

7
CLI/CLI.nasm

@ -135,9 +135,9 @@ CLI_EXECUTE:
ret
.tmp dw 0
.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
.Num_Commands dw 8
.Command_Name_List dw .CMD1, .CMD2, .CMD3, .CMD4, .CMD5, .CMD6, .CMD7, .CMD8
.Command_Function_Pointers dw dumpmem, keyprint, svim, vsfs_list_files_command, vsfs_create_file, vsfs_format_disk, vsfs_get_fs_info, os_clear_screen
.CMD1 db 'dumpmem', 0
.CMD2 db 'keyprint', 0
.CMD3 db 'svim', 0
@ -145,5 +145,6 @@ CLI_EXECUTE:
.CMD5 db 'createfile', 0
.CMD6 db 'formatdisk', 0
.CMD7 db 'fsinfo', 0
.CMD8 db 'clear', 0

65
bootloader.nasm

@ -12,6 +12,7 @@ start:
mov ax, 0x7C0 ; Set 'ax' equal to the location of this bootloader divided by 16
mov ds, ax ; Set 'ds' to the this location
mov [disk_identifier], dl
; Print our message and stop execution
mov si, message ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
@ -33,21 +34,6 @@ start:
; entering system check:
mov si, enter_system_check
call print
mov ax, 0x0123
call dumpax
mov ax, 0x4567
call dumpax
call printCRLF
mov ax, 0x89AB
call dumpax
mov ax, 0xCDEF
call dumpax
call printCRLF
mov ax, 42
call dumpax10
call printCRLF
mov si, sys_check_ok ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
@ -63,7 +49,7 @@ start:
mov ch, 0x0 ;Low 8 bits of cylinder
mov cl, 0x11 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x0 ;Head number
mov dl, 0x0 ;Drive number
mov dl, [disk_identifier] ;0x0 ;Drive number
mov bx, 0x7e00 ;Offset into section
int 0x13 ;Low level disk services
;mov [0x7000], es ; saving retult of read
@ -83,10 +69,12 @@ start:
call print
call printCRLF
call printCRLF
call printCRLF
;mov ax, [0x7000]
;call printWordHex
xor ax, ax
mov al, [disk_identifier]
call dumpax
mov dl, [disk_identifier]
mov ax, 0x7e0
mov ds, ax
jmp 0x7e0:0x00
@ -110,6 +98,7 @@ data:
boot_system db 'Read SingOS from disk', 13, 10, 0
error_str db 'Error', 0
success_str db 'Success', 0
disk_identifier db 0
; Routine for printing a 'ax' as hex
dumpax:
@ -213,25 +202,25 @@ print:
.done:
ret
b_dumpmem:
push ax
push dx
call printCRLF
shr cx, 1
xor dx, dx ; zero dx
.loop:
cmp dx, cx
jae .end
mov ax, word [esi + 2*edx]
call dumpax
mov ax, 0xe20
int 0x10
inc dx
jmp .loop
.end:
pop dx
pop ax
ret
; b_dumpmem:
; push ax
; push dx
; call printCRLF
; shr cx, 1
; xor dx, dx ; zero dx
; .loop:
; cmp dx, cx
; jae .end
; mov ax, word [esi + 2*edx]
; call dumpax
; mov ax, 0xe20
; int 0x10
; inc dx
; jmp .loop
; .end:
; pop dx
; pop ax
; ret
; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature
times 510-($-$$) db 0
dw 0xAA55 ; => 0x55 0xAA (little endian byte order)

34
kernel.nasm

@ -3,29 +3,27 @@ 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 printCRLF ; only for debug
xor ax, ax
mov al, dl
call dumpax
call printCRLF
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
mov ah, 0x0F
int 10
call dumpax
call printCRLF
; SingOS is ready for the user:
mov si, welcome ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
mov si, number_one_zstring
call zstring_to_integer
call dumpax10
call printCRLF
call dump_stack_registers
call printCRLF
call dump_general_registers
call printCRLF
call printCRLF
; mov dx, ('N'<<8)|'T'
; call dump_dx_as_two_chars
call dump_status_flags
mov si, command_line
call print
jmp terminal
@ -272,6 +270,8 @@ global_vars:
; 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
data:
welcome db 'This is SingOS! v0.0.3', 13, 10, 'Press ESC to halt.', 13, 10, 0

26
lib/os_lib.nasm

@ -46,3 +46,29 @@ os_change_screen:
mov ah, 0x05
int 0x10
ret
os_clear_screen:
pusha
; move cursor to the bootom
xor ax, ax
xor bx, bx
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x18 ; row zero
mov dl, 0x00 ; coloumn zero
int 0x10
xor cx, cx
.loop:
call printCRLF
add cx, 1
cmp cx, 0x19 ; until blank screen
jne .loop
; 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
popa
ret

129
lib/svim.nasm

@ -4,14 +4,14 @@ svim:
;mov si, .os_clear_screen_str
;call print
xor bx, bx
mov [.buffer_counter_svim], bx
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
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
mov ah, 0x02
mov bh, 0x00 ; page number 0
@ -44,11 +44,34 @@ svim:
xor dx, dx
.enter_fileindex_loop:
push cx
.loop_no_push:
mov ax, 0x10 ; BIOS call to wait for key
int 0x16
cmp ax, 0x1c0d ; enter key
je .fileindex_done
.no_enter:
cmp ax, 0x0e08 ; backspace
jne .no_enter_fileindex
cmp cx, 0
je .loop_no_push
pop cx
sub cx, 1
mov bx, .buffer_for_svim
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_fileindex_loop
.no_enter_fileindex:
mov bh, 0x00
mov bl, 0x02
mov ah, 0x0E
@ -66,28 +89,15 @@ svim:
.fileindex_done:
pop cx ; Cleanup, and now contain filename size
add cx, .buffer_for_svim
mov bx, cx
mov ax, cx
add ax, .buffer_for_svim
mov bx, ax
mov BYTE [bx], 0
mov si, .buffer_for_svim
call zstring_to_integer ; ax now contain the interger index for the file
mov [.fileindex_for_open_file], ax ; save the file index
xor bx, bx
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
; move cursor back up to the top
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x00 ; row zero
mov dl, 0x00 ; coloumn zero
int 0x10
call os_clear_screen
; Load from disk and, enter it, into the buffer
@ -103,9 +113,13 @@ svim:
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
mov dl, [global_disk_identifier] ;Drive number
int 0x13
mov bx, .fileindex_for_open_file
add bx, 510
mov ax, [bx]
mov [.buffer_counter_svim], ax
; print buffer
mov si, .buffer_for_svim
mov es, si
@ -115,14 +129,17 @@ svim:
mov ax, 0x1000 ; BIOS call to wait for key
int 0x16
cmp ax, 0x1c0d ; enter key
jne .no_enter_fileindex
jne .no_enter
call printCRLF
jmp .svim_loop
.no_enter_fileindex:
.no_enter:
cmp ax, 0x11b ; ESC key
je .end_svim
cmp ax, 0x3c00 ; f2 key
je .f_key_pushed
cmp ax, 0x0e08 ; backspace
je .backspace_pushed
mov bx, ax
mov ax, 0xe20
mov al, bl
@ -144,6 +161,11 @@ svim:
;DH Head
;DL Drive
;ES:BX Buffer Address Pointer
mov ax, [.buffer_counter_svim]
mov bx, .fileindex_for_open_file
add bx, 510
mov [bx], ax
mov bx, ds
mov es, bx
mov bx, .buffer_for_svim
@ -155,26 +177,47 @@ svim:
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 dh, 0x00 ;Head number
mov dl, 0x0 ;Drive number
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
; 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 )
;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
.backspace_pushed:
pusha
mov bx, [.buffer_counter_svim]
cmp bx, 0
je .svim_loop
mov cx, bx
sub cx, 1
mov bx, .buffer_for_svim
add bx, cx
mov BYTE [bx], 0
mov [.buffer_counter_svim], cx
; Go back one space
mov ax, 0x0e08 ; ah=0x0e means teletype output. al=0x08 means backspace character.
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
; 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
popa
ret
jmp .svim_loop
.f_key_pushed:
mov al, 0x01 ;arg: index 1

16
vsfs/vsfs.nasm

@ -26,7 +26,7 @@ vsfs_format_disk:
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
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
popa
@ -47,7 +47,7 @@ vsfs_get_fs_info:
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
mov dl, [global_disk_identifier] ; Drive number
int 0x13
mov si, vsfs_loading_buffer
@ -72,7 +72,7 @@ vsfs_read_file_index_in_ax:
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
mov dl, [global_disk_identifier] ; Drive number
int 0x13
popa
ret
@ -98,7 +98,7 @@ vsfs_write_file_to_index_in_ax:
mov cl, 0x03 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov ch, 0x02
mov dh, 0x01 ;Head number
mov dl, 0x0 ;Drive number
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
popa
ret
@ -167,7 +167,7 @@ vsfs_create_file:
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
mov dl, [global_disk_identifier] ; Drive number
int 0x13
mov ax, [vsfs_loading_buffer + 510]
@ -184,7 +184,7 @@ vsfs_create_file:
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
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
; Now we have the index in ax.
@ -213,7 +213,7 @@ vsfs_create_file:
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
mov ch, 0x08
mov dh, 0x00 ;Head number
mov dl, 0x00 ;Drive number
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
popa
ret
@ -259,7 +259,7 @@ vsfs_list_files_command:
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes)
mov ch, 0x08 ; cylinder
mov dh, 0x00 ; Head number
mov dl, 0x00 ; Drive number
mov dl, [global_disk_identifier] ; Drive number
int 0x13
mov ax, [vsfs_loading_buffer + 126]

Loading…
Cancel
Save