From cfa3eac65c680c5da7fc2f291206c3592d14d297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Kj=C3=A6r-Kammersgaard?= Date: Tue, 11 Sep 2018 13:00:24 +0200 Subject: [PATCH] No additions, Moved stuff around --- .gitignore | 1 + CLI/CLI.nasm | 2 +- SingOS.img | Bin 1056768 -> 1056768 bytes build | 17 ++++++ build.sh | 1 + kernel.bin | Bin 1048576 -> 1048576 bytes kernel.nasm | 47 ++++++++-------- legacy/source/build.sh | 4 +- lib/debug_tools.nasm | 119 +++++++++++++++++++++++++++++++++++++++++ lib/dumpmem.nasm | 26 --------- lib/os_lib.nasm | 71 +++--------------------- lib/printkey.nasm | 20 ------- lib/std_power.nasm | 4 +- lib/svim.nasm | 16 +++--- vsfs/vsfs.nasm | 18 +++---- 15 files changed, 190 insertions(+), 156 deletions(-) create mode 100755 build mode change 100644 => 100755 build.sh create mode 100644 lib/debug_tools.nasm delete mode 100644 lib/dumpmem.nasm delete mode 100644 lib/printkey.nasm diff --git a/.gitignore b/.gitignore index e43b0f9..fc65553 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +*.sublime* \ No newline at end of file diff --git a/CLI/CLI.nasm b/CLI/CLI.nasm index a6235c4..6d584e4 100644 --- a/CLI/CLI.nasm +++ b/CLI/CLI.nasm @@ -122,7 +122,7 @@ CLI_EXECUTE: add bx, bx ; The pointers are two bytes long. This compensates for that. pusha - call printCRLF_os + call printCRLF popa mov dx, [.Command_Function_Pointers + bx] ; Program pointer diff --git a/SingOS.img b/SingOS.img index 7d7be07773b81a1598b30e4a1c384e14d9aafb30..c005e0986be0f2c8ce3c3f82ac06255f51420e82 100644 GIT binary patch delta 740 zcmZoT;LvcuVFQ-}iy_O4S(Et`syU`HzwX+=_@aOELsf)xc`9B~GyY$EX?V%gH%r(HE`}Wnd}jrmUcXJ8te~PWxsp+vX9t78SutB_ z#uDKdD8ja)^-*V|sI=QG25i<7NS-53-}g MXc$m69lU1(0DsaD1^@s6 delta 798 zcmZoT;LvcuVFQ-}OBKrtv&no4)f`)yUw3U_e6eowL24W}KX&ymxY! ziag5}*0TbWD;TvWtEqTu`2WB7((sbysbc>0ZkDhY5&w56@SPQKdi^%>aKa7-fwN+^ z(u^g-FB~R6P?2X;n4~(F@%iL=sv8;KZw^pn;$f2hG&#gbhjBx5qfvXK5##noBc^)Z z#rw6GI5Sdna`N>`DoQ3ZGLJe+x@xk;%-3Wf$K5(wR+Eab2p4GoOY_#puR$t)xB diff --git a/build b/build new file mode 100755 index 0000000..3652081 --- /dev/null +++ b/build @@ -0,0 +1,17 @@ +#!/usr/bin/bash + +if [ "$1" == "build" ] || [ "$1" == "run" ]; then + nasm -fbin bootloader.nasm -o bootloader.bin + nasm -fbin kernel.nasm -o kernel.bin + 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 + else + bash -c "echo;echo;echo 'Press [ENTER] to exit'; read line" + fi +fi + +echo "Done" \ No newline at end of file diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 065cd77..ba74090 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ #!/bin/bash + if [ "$1" != "run" ]; then nasm -fbin bootloader.nasm -o bootloader.bin nasm -fbin kernel.nasm -o kernel.bin diff --git a/kernel.bin b/kernel.bin index e2f12d18e3695db0d4fda98e0bf910c20a5fb310..ff12a64232790bbc7561b01cced7c6b41fbce19b 100644 GIT binary patch delta 203 zcmZo@aA;_7;M>>D{NgL~z8}ml3|U^xn#fnpF^&0k*9OKH{SzlDGNy0byq<~a5X0mY z=DjRiSkDSf&SUYCn(_bQOT$Z+r;7R0yII0sa53yq;5#ee^!jb$WCa$5$*wF~ya_uP z1kQ@tN;8%SzgRi>0gF6i=Oos-jPoYXW8KJjVRHZ*6A#m+kCQ`$bQsf{8->~%g&2XD p35c12m<5PgftU@5*@2h?h&h3n3y8Uam>D{NgL~z8}mls#so_P2{WQ*vkC6YXjqpbrUBlGH%$oc|8*oH{;|K z=Dm}m5%GVA0^eByr`K;24=3zk z5I8GlE6rFU{K8@K0~UEkg-NV)8J|y{$GVa6{pJ8RCLSi~Pm@E0bQm`@Hwv{k3NZpP p6A&{4F$)m00x=s9vjZ^)5OV@C7Z7s;F%J;)0x{qAMj`(Cw*YnwOH%*< diff --git a/kernel.nasm b/kernel.nasm index 4ce73e8..a2d2ec1 100644 --- a/kernel.nasm +++ b/kernel.nasm @@ -1,5 +1,5 @@ BITS 16 -start_sing_os: +start_sing: ; loading essentials for SingOS to run ; VSFS is loaded: @@ -8,7 +8,7 @@ start_sing_os: ; 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 + call print ; Call our string-printing routine mov si, number_one_zstring call zstring_to_integer @@ -16,14 +16,14 @@ start_sing_os: mov si, command_line - call print_os + call print jmp terminal terminal: - call wait_for_key_os + call wait_for_key jmp terminal -wait_for_key_os: +wait_for_key: pusha mov ax, 0 @@ -71,7 +71,7 @@ wait_for_key_os: .os_buffer_full: mov si, .os_str_full - call print_os + call print popa ret @@ -117,7 +117,7 @@ wait_for_key_os: .no_str: mov si, command_line - call print_os + call print jmp .return_enter .compare_with_LIST_searchindex dw 0 @@ -132,7 +132,7 @@ wait_for_key_os: .end: mov si, exit_message - call print_os + call print call power_off @@ -178,30 +178,30 @@ wait_for_key_os: mov bx, [.os_command_buffer_counter] cmp bx, 0x00 je near .no_str ; First byte is 0 => No command - call printCRLF_os + 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_os ; Echo the command + 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_os + ;call printCRLF ;mov ax, cx - ;call dumpax_os + ;call dumpax ;mov bx, [.compare_with_LIST_searchindex] mov bx, cx add bx, bx ; The pointers are 2 bytes long. Compensate here - ;call printCRLF_os + ;call printCRLF ;mov ax, cx - ;call dumpax_os + ;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 @@ -229,21 +229,21 @@ wait_for_key_os: jmp .no_str .command_interpreter_foundcommand: - call printCRLF_os + 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_os + ;call printCRLF ;mov ax, cx - ;call dumpax_os + ;call dumpax mov dx, [.compare_with_LIST_POINTERS+bx] ; This is where the program is. ;mov ax, dx - ;call printCRLF_os - ;call dumpax_os + ;call printCRLF + ;call dumpax call dx @@ -251,7 +251,7 @@ wait_for_key_os: ; -global_vars_os: +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 @@ -262,7 +262,7 @@ global_vars_os: ; Changed my mind, the index is currently loaded and written back to disk under ; creation of a new file. -data_os: +data: welcome db 'This is SingOS! v0.0.3', 13, 10, 'Press ESC to halt.', 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 @@ -271,8 +271,7 @@ data_os: %include "mem_lib/mem_lib.nasm" %include "lib/os_lib.nasm" %include "lib/string.nasm" -%include "lib/dumpmem.nasm" -%include "lib/printkey.nasm" +%include "lib/debug_tools.nasm" %include "lib/std_power.nasm" %include "lib/svim.nasm" %include "vsfs/vsfs.nasm" @@ -280,4 +279,4 @@ data_os: ;times 131072-($-$$) db 0 ; 256 sectos ;GLOBAL_VSFS_START db 'VSFS v0.1' ; sector 257 reserved for file system information -times 1048576-($-$$) db 0 ; sector 258 to sector 2048 should be avaliable to the filesystem. +times (1<<20)-($-$$) db 0 ; sector 258 to sector 2048 should be avaliable to the filesystem. diff --git a/legacy/source/build.sh b/legacy/source/build.sh index d7b90b0..6570a4b 100755 --- a/legacy/source/build.sh +++ b/legacy/source/build.sh @@ -1,3 +1,3 @@ as sing_boot_alt.s -o ../compile_folder/alt.o -ld -Ttext 0x7c00 --oformat=binary ../compile_folder/alt.o -o ../compile_folder/sing_os.bin -dd if=../compile_folder/sing_os.bin of=../compile_folder/sing_os.img +ld -Ttext 0x7c00 --oformat=binary ../compile_folder/alt.o -o ../compile_folder/sing.bin +dd if=../compile_folder/sing.bin of=../compile_folder/sing.img diff --git a/lib/debug_tools.nasm b/lib/debug_tools.nasm new file mode 100644 index 0000000..b304548 --- /dev/null +++ b/lib/debug_tools.nasm @@ -0,0 +1,119 @@ +BITS 16 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +dumpmem: +; Dumps memory +; IN From-pointer in 'si' +; IN Amount of bytes do dump in 'cx' +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + pusha + ;push ax + ;push dx + mov si, start_sing + mov cx, 512 + 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 + popa + ret + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +dumpax: +; Prints the contens of ax as a hexadecimal number +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + pusha ; save registers + mov dx, ax + mov ah, 0xE ; Teletype output + + mov cx, 4 ; 4 nipples in a 16 bit word + .loop: + rol dx, 4 ; rotate to next nipple + mov al, dl ; we copy to al because we need to mask only the low 4 bits + and al, 1111b ; Do the masking + add al, '0' ; convert to ASCII + cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A' + jbe .skip ; -|- + add al, 7 ; -|- + .skip: ; -|- + mov bl, 0xe2 ;color + int 0x10 ; BIOS call 'output' + loop .loop + + popa ; restore registers + ret + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +dumpax10: +; Prints the contens of ax as a decimal number +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + pusha + + mov bx, 10 ; Divisor + + mov cx, 5 ; Loop 5 times +.loop1: ; finds digits and pushes them to stack + xor dx, dx + div bx + add dl, '0' + push dx + loop .loop1 + + + mov ah, 0xE + mov cx, 5 ; Loop 5 times + mov bl, '0' + +.loop2: ; Pops from stack until it hits a non-'0' value. It then jumps to nonzero_nopop to print it. + pop dx + mov al, dl + cmp al, bl + jne .nonzero_nopop + loop .loop2 + +.nonzero_loop: ; Pops values from the stack and prints them. + pop dx + mov al, dl +.nonzero_nopop: ; Part of the loop that prints the value. Jump to here to print without popping on first iteration. + int 0x10 + loop .nonzero_loop + + popa + ret + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +keyprint: +; Enters a loop where the keycode of each pressed key is printed +; [ESC] exits the loop +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + pusha +.keyprint_loop: + mov ax, 0x1000 ; BIOS call to wait for key + int 0x16 + cmp ax, 0x11b ; ESC key + je .end_keyprint + + call dumpax + mov bx, ax + mov ax, 0xe20 + int 0x10 ; print space + mov al, bl + int 0x10 ; print char + call printCRLF + jmp .keyprint_loop +.end_keyprint: + popa + ret \ No newline at end of file diff --git a/lib/dumpmem.nasm b/lib/dumpmem.nasm deleted file mode 100644 index 6457e76..0000000 --- a/lib/dumpmem.nasm +++ /dev/null @@ -1,26 +0,0 @@ -BITS 16 -; Routine for dumping memory -; pointer in 'si', length is 'cx' -dumpmem: - pusha - ;push ax - ;push dx - mov si, start_sing_os - mov cx, 512 - call printCRLF_os - shr cx, 1 - xor dx, dx ; zero dx -.loop: - cmp dx, cx - jae .end - mov ax, word [esi + 2*edx] - call dumpax_os - mov ax, 0xe20 - int 0x10 - inc dx - jmp .loop -.end: - ;pop dx - ;pop ax - popa - ret diff --git a/lib/os_lib.nasm b/lib/os_lib.nasm index 1842339..f4850b2 100644 --- a/lib/os_lib.nasm +++ b/lib/os_lib.nasm @@ -1,20 +1,20 @@ BITS 16 ; Routine for outputting string in 'si' register to screen -print_os: +print: ;mov bh, 0x00 mov bl, 0x02 mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)] -.printchar_os: +.printchar: lodsb ; Load byte at address SI into AL, and increment SI cmp al, 0 - je .done_os ; If the character is zero (NUL), stop writing the string + je .done ; If the character is zero (NUL), stop writing the string int 0x10 ; Otherwise, print the character via 'int 0x10' - jmp .printchar_os ; Repeat for the next character -.done_os: + jmp .printchar ; Repeat for the next character +.done: ret -printCRLF_os: +printCRLF: mov ah, 0xE mov al, 13 int 0x10 @@ -33,28 +33,6 @@ printALChar: int 0x10 ret -dumpax_os: - pusha ; save registers - mov dx, ax - mov ah, 0xE ; Teletype output - - mov cx, 4 ; 4 nipples in a 16 bit word - .loop: - rol dx, 4 ; rotate to next nipple - mov al, dl ; we copy to al because we need to mask only the low 4 bits - and al, 1111b ; Do the masking - add al, '0' ; convert to ASCII - cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A' - jbe .skip ; -|- - add al, 7 ; -|- - .skip: ; -|- - mov bl, 0xe2 ;color - int 0x10 ; BIOS call 'output' - loop .loop - - popa ; restore registers - ret - ; Changing the screen the user i looking at. ; value in 'al' is the screen we want to switch to. ; starting from 0x00 @@ -63,39 +41,4 @@ os_change_screen: ; and base pointer has to be set. mov ah, 0x05 int 0x10 - ret - -dumpax10: ; Prints ax as 16-bit decimal number - pusha - - mov bx, 10 ; Divisor - - mov cx, 5 ; Loop 5 times -.loop1: ; finds digits and pushes them to stack - xor dx, dx - div bx - add dl, '0' - push dx - loop .loop1 - - - mov ah, 0xE - mov cx, 5 ; Loop 5 times - mov bl, '0' - -.loop2: ; Pops from stack until it hits a non-'0' value. It then jumps to nonzero_nopop to print it. - pop dx - mov al, dl - cmp al, bl - jne .nonzero_nopop - loop .loop2 - -.nonzero_loop: ; Pops values from the stack and prints them. - pop dx - mov al, dl -.nonzero_nopop: ; Part of the loop that prints the value. Jump to here to print without popping on first iteration. - int 0x10 - loop .nonzero_loop - - popa - ret \ No newline at end of file + ret \ No newline at end of file diff --git a/lib/printkey.nasm b/lib/printkey.nasm deleted file mode 100644 index abb9d9c..0000000 --- a/lib/printkey.nasm +++ /dev/null @@ -1,20 +0,0 @@ -BITS 16 -keyprint: - pusha -.keyprint_loop: - mov ax, 0x1000 ; BIOS call to wait for key - int 0x16 - cmp ax, 0x11b ; ESC key - je .end_keyprint - - call dumpax_os - mov bx, ax - mov ax, 0xe20 - int 0x10 ; print space - mov al, bl - int 0x10 ; print char - call printCRLF_os - jmp .keyprint_loop -.end_keyprint: - popa - ret diff --git a/lib/std_power.nasm b/lib/std_power.nasm index 02deab8..5f764cf 100644 --- a/lib/std_power.nasm +++ b/lib/std_power.nasm @@ -8,8 +8,8 @@ power_check: mov al,00h ;installation check command xor bx,bx ;device id (0 = APM BIOS) int 15h ;call the BIOS function through interrupt 15h - call printCRLF_os - call dumpax_os + call printCRLF + call dumpax ;jc APM_error ;if the carry flag is set there was an error ;the function was successful ;AX = APM version number diff --git a/lib/svim.nasm b/lib/svim.nasm index ca4400d..50a35ff 100644 --- a/lib/svim.nasm +++ b/lib/svim.nasm @@ -2,7 +2,7 @@ BITS 16 svim: pusha ; save state before program ;mov si, .os_clear_screen_str - ;call print_os + ;call print xor bx, bx mov [.buffer_counter_svim], bx xor cx, cx ; Upper and left coordinate @@ -19,8 +19,8 @@ svim: mov dl, 0x17 ; coloumn zero int 0x10 mov si, .welcome_svim_select_file - call print_os - call printCRLF_os + call print + call printCRLF call vsfs_list_files_command ; move cursor to the bootom @@ -33,10 +33,10 @@ svim: int 0x10 mov si, .welcome_svim - call print_os - call printCRLF_os + call print + call printCRLF mov si, .welcome_svim_enter_fileindex - call print_os + call print ; Ask the user for the filename xor bx, bx @@ -109,14 +109,14 @@ svim: ; print buffer mov si, .buffer_for_svim mov es, si - call print_os + call print .svim_loop: mov ax, 0x1000 ; BIOS call to wait for key int 0x16 cmp ax, 0x1c0d ; enter key jne .no_enter_fileindex - call printCRLF_os + call printCRLF jmp .svim_loop .no_enter_fileindex: cmp ax, 0x11b ; ESC key diff --git a/vsfs/vsfs.nasm b/vsfs/vsfs.nasm index 9e0d76d..f7cc0ba 100644 --- a/vsfs/vsfs.nasm +++ b/vsfs/vsfs.nasm @@ -51,7 +51,7 @@ vsfs_get_fs_info: int 0x13 mov si, vsfs_loading_buffer - call print_os + call print popa ret @@ -121,7 +121,7 @@ vsfs_create_file: pusha ; save all register state mov si, .vsfs_create_file_type_filename - call print_os + call print ; Ask the user for the filename xor bx, bx @@ -151,7 +151,7 @@ vsfs_create_file: .filename_done: pop cx ; Cleanup, and now contain filename size - call printCRLF_os + call printCRLF ; We first need to know the index for the file. @@ -239,10 +239,10 @@ vsfs_list_files_command: int 0x13 mov si, .ls_header - call print_os + call print mov si, .seperate_line - call print_os + call print mov ax, [vsfs_loading_buffer + 126] @@ -274,13 +274,13 @@ vsfs_list_files_command: .stop_index: mov si, .fileentry_line ; printing the buffer - call print_os + call print mov si, vsfs_loading_buffer ; printing the buffer - call print_os + call print - call printCRLF_os + call printCRLF mov si, .seperate_line - call print_os + call print .end_ls: popa ret