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

34
kernel.nasm

@ -3,29 +3,27 @@ start_sing:
; loading essentials for SingOS to run ; loading essentials for SingOS to run
; VSFS is loaded: ; 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: ; SingOS is ready for the user:
mov si, welcome ; Put address of the null-terminated string to output into 'si' mov si, welcome ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine 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 mov si, command_line
call print call print
jmp terminal jmp terminal
@ -272,6 +270,8 @@ global_vars:
; this var is set durling load of SingOS ; this var is set durling load of SingOS
; Changed my mind, the index is currently loaded and written back to disk under ; Changed my mind, the index is currently loaded and written back to disk under
; creation of a new file. ; creation of a new file.
global_disk_identifier db 0 ; set by the bios passed by the bootloader,
; this is the bios ID
data: data:
welcome db 'This is SingOS! v0.0.3', 13, 10, 'Press ESC to halt.', 13, 10, 0 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 mov ah, 0x05
int 0x10 int 0x10
ret 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 ;mov si, .os_clear_screen_str
;call print ;call print
xor bx, bx xor bx, bx
mov [.buffer_counter_svim], bx call os_clear_screen
xor cx, cx ; Upper and left coordinate ;xor cx, cx ; Upper and left coordinate
mov bh, 0x0a ; color for new screen 0 = black a = light green ;mov bh, 0x0a ; color for new screen 0 = black a = light green
mov dh, 0xff ; Select all screen ;mov dh, 0xff ; Select all screen
mov dl, 0xff ; Select all screen ;mov dl, 0xff ; Select all screen
mov ah, 0x07 ; scrool down ;mov ah, 0x07 ; scrool down
mov al, 0x00 ; scrool 0 lines (means blank screen ) ;mov al, 0x00 ; scrool 0 lines (means blank screen )
int 0x10 ;int 0x10
mov ah, 0x02 mov ah, 0x02
mov bh, 0x00 ; page number 0 mov bh, 0x00 ; page number 0
@ -44,11 +44,34 @@ svim:
xor dx, dx xor dx, dx
.enter_fileindex_loop: .enter_fileindex_loop:
push cx push cx
.loop_no_push:
mov ax, 0x10 ; BIOS call to wait for key mov ax, 0x10 ; BIOS call to wait for key
int 0x16 int 0x16
cmp ax, 0x1c0d ; enter key cmp ax, 0x1c0d ; enter key
je .fileindex_done 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 bh, 0x00
mov bl, 0x02 mov bl, 0x02
mov ah, 0x0E mov ah, 0x0E
@ -66,28 +89,15 @@ svim:
.fileindex_done: .fileindex_done:
pop cx ; Cleanup, and now contain filename size pop cx ; Cleanup, and now contain filename size
add cx, .buffer_for_svim mov ax, cx
mov bx, cx add ax, .buffer_for_svim
mov bx, ax
mov BYTE [bx], 0 mov BYTE [bx], 0
mov si, .buffer_for_svim mov si, .buffer_for_svim
call zstring_to_integer ; ax now contain the interger index for the file call zstring_to_integer ; ax now contain the interger index for the file
mov [.fileindex_for_open_file], ax ; save the file index mov [.fileindex_for_open_file], ax ; save the file index
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
; 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
; Load from disk and, enter it, into the buffer ; 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 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 cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ;Head number mov dh, 0x00 ;Head number
mov dl, 0x00 ;Drive number mov dl, [global_disk_identifier] ;Drive number
int 0x13 int 0x13
mov bx, .fileindex_for_open_file
add bx, 510
mov ax, [bx]
mov [.buffer_counter_svim], ax
; print buffer ; print buffer
mov si, .buffer_for_svim mov si, .buffer_for_svim
mov es, si mov es, si
@ -115,14 +129,17 @@ svim:
mov ax, 0x1000 ; BIOS call to wait for key mov ax, 0x1000 ; BIOS call to wait for key
int 0x16 int 0x16
cmp ax, 0x1c0d ; enter key cmp ax, 0x1c0d ; enter key
jne .no_enter_fileindex jne .no_enter
call printCRLF call printCRLF
jmp .svim_loop jmp .svim_loop
.no_enter_fileindex:
.no_enter:
cmp ax, 0x11b ; ESC key cmp ax, 0x11b ; ESC key
je .end_svim je .end_svim
cmp ax, 0x3c00 ; f2 key cmp ax, 0x3c00 ; f2 key
je .f_key_pushed je .f_key_pushed
cmp ax, 0x0e08 ; backspace
je .backspace_pushed
mov bx, ax mov bx, ax
mov ax, 0xe20 mov ax, 0xe20
mov al, bl mov al, bl
@ -144,6 +161,11 @@ svim:
;DH Head ;DH Head
;DL Drive ;DL Drive
;ES:BX Buffer Address Pointer ;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 bx, ds
mov es, bx mov es, bx
mov bx, .buffer_for_svim mov bx, .buffer_for_svim
@ -155,26 +177,47 @@ svim:
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes) 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 cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ;Head number mov dh, 0x00 ;Head number
mov dl, 0x0 ;Drive number mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services int 0x13 ;Low level disk services
; clean up swim ; clean up swim
xor bx, bx ;xor bx, bx
xor cx, cx ; Upper and left coordinate ;xor cx, cx ; Upper and left coordinate
mov bh, 0x0f ; color for new screen 0 = black f = white ;mov bh, 0x0f ; color for new screen 0 = black f = white
mov dh, 0xff ; Select all screen ;mov dh, 0xff ; Select all screen
mov dl, 0xff ; Select all screen ;mov dl, 0xff ; Select all screen
mov ah, 0x07 ; scrool down ;mov ah, 0x07 ; scrool down
mov al, 0x00 ; scrool 0 lines (means blank screen ) ;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 int 0x10
; Move curser back to the top of the screen
mov ah, 0x02 ; Place a NULL
mov bh, 0x00 ; page number 0 mov al, 0x0 ; NULL
mov dh, 0x00 ; row zero int 0x10
mov dl, 0x00 ; coloumn zero
; Go back one space again as the above print of NULL pushes the cursor forward again.
mov ax, 0x0e08
int 0x10 int 0x10
popa popa
ret jmp .svim_loop
.f_key_pushed: .f_key_pushed:
mov al, 0x01 ;arg: index 1 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 cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov ch, 0x08 mov ch, 0x08
mov dh, 0x00 ;Head number mov dh, 0x00 ;Head number
mov dl, 0x00 ;Drive number mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services int 0x13 ;Low level disk services
popa popa
@ -47,7 +47,7 @@ vsfs_get_fs_info:
mov ch, 0x08 ; cylinder mov ch, 0x08 ; cylinder
mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ; Head number mov dh, 0x00 ; Head number
mov dl, 0x00 ; Drive number mov dl, [global_disk_identifier] ; Drive number
int 0x13 int 0x13
mov si, vsfs_loading_buffer 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 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 cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ; Head number mov dh, 0x00 ; Head number
mov dl, 0x00 ; Drive number mov dl, [global_disk_identifier] ; Drive number
int 0x13 int 0x13
popa popa
ret 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 cl, 0x03 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov ch, 0x02 mov ch, 0x02
mov dh, 0x01 ;Head number mov dh, 0x01 ;Head number
mov dl, 0x0 ;Drive number mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services int 0x13 ;Low level disk services
popa popa
ret ret
@ -167,7 +167,7 @@ vsfs_create_file:
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes) 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 cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ; Head number mov dh, 0x00 ; Head number
mov dl, 0x00 ; Drive number mov dl, [global_disk_identifier] ; Drive number
int 0x13 int 0x13
mov ax, [vsfs_loading_buffer + 510] 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 cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov ch, 0x08 mov ch, 0x08
mov dh, 0x00 ;Head number mov dh, 0x00 ;Head number
mov dl, 0x00 ;Drive number mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services int 0x13 ;Low level disk services
; Now we have the index in ax. ; 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 al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
mov ch, 0x08 mov ch, 0x08
mov dh, 0x00 ;Head number mov dh, 0x00 ;Head number
mov dl, 0x00 ;Drive number mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services int 0x13 ;Low level disk services
popa popa
ret ret
@ -259,7 +259,7 @@ vsfs_list_files_command:
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes) mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes)
mov ch, 0x08 ; cylinder mov ch, 0x08 ; cylinder
mov dh, 0x00 ; Head number mov dh, 0x00 ; Head number
mov dl, 0x00 ; Drive number mov dl, [global_disk_identifier] ; Drive number
int 0x13 int 0x13
mov ax, [vsfs_loading_buffer + 126] mov ax, [vsfs_loading_buffer + 126]

Loading…
Cancel
Save