diff --git a/Makefile b/Makefile index 6757948..4b15f3e 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ $(BUILD_DIR)/crawos.iso: floppy_image # Floppy image # Fat12 floppy_image: $(BUILD_DIR)/crawos.img -$(BUILD_DIR)/crawos.img: bootloader kernel +$(BUILD_DIR)/crawos.img: bootloader kernel check-fat83 mkdir -p disk_images dd if=/dev/zero of=$(BUILD_DIR)/crawos.img bs=512 count=2880 # Use dd to make a disk image mkfs.fat -F 12 -n "CRAWOS" $(BUILD_DIR)/crawos.img # Format the disk image with fat12 @@ -36,6 +36,11 @@ $(BUILD_DIR)/kernel.bin: mkdir -p disk_images $(ASM) $(SRC_DIR)/kernel/kernel.asm -f bin -o $ $(BUILD_DIR)/kernel.bin +check-fat83: + @echo "Checking filenames for FAT 8.3 compliance..." + @find ./data -type f | awk -F/ '{print $$NF}' | \ + awk -F. 'length($$1)>8 || length($$2)>3 || NF>2 {print "Invalid FAT 8.3 filename:", $$0; bad=1} END{exit bad}' + # Clean clean: rm -f disk_images/* diff --git a/data/README.md b/data/README.md index 14b687a..777df75 100644 --- a/data/README.md +++ b/data/README.md @@ -1,9 +1,14 @@ -Kernel written in Assmebly -I'm using a modified JazzOS Bootloader +# What is this? +This is a simple implementation of a computer kernel +written in pure x86 assembly with features including +- Read/Write disk operations +- The ability to boot from the BIOS using the JazzOS Bootloader +- A modified MikeOS BASIC interpreter +- A functional POSIX inspired CLI -Commands: -CAT -HELP -CLEAR -REBOOT -PONG +# Commands +- CAT : outputs the contents of the file. +- LS: outputs a list of files on the system . +- CLEAR: clears the screen. +- REBOOT: or esc reboots the system +- BAS : runs a basic script. diff --git a/data/hello.bas b/data/hello.bas index 92d7719..8018bd4 100644 --- a/data/hello.bas +++ b/data/hello.bas @@ -1,2 +1,2 @@ -PORT OUT 80 5 +PRINT "Hello World" END diff --git a/data/var.cws b/data/var.cws deleted file mode 100644 index fed79d0..0000000 --- a/data/var.cws +++ /dev/null @@ -1 +0,0 @@ -x = 5 diff --git a/source/kernel/data.asm b/source/kernel/data.asm index b74148c..6da61a7 100644 --- a/source/kernel/data.asm +++ b/source/kernel/data.asm @@ -34,6 +34,7 @@ reboot_string: db 'REBOOT', 0 basic_string: db 'BAS', 0 cat_string: db 'CAT', 0 ls_string: db 'LS', 0 +ed_string: db 'ED', 0 help_text: db 'This is for Cowards:\n"LS" to list the directory,\n"CAT" to output the contents of a file,\n"BAS" to run a basic script,\n"HELP" for this helpful text,\n"CLEAR" to clear the screen,\n"REBOOT" or esc to reboot\n', 0 basic_text: db 'BASIC PROGRAM BEGUN:\n', 0 command_result_text: db 'You typed: ', 0 diff --git a/source/kernel/features/basic.asm b/source/kernel/features/basic.asm index 8c952ae..55d0334 100644 --- a/source/kernel/features/basic.asm +++ b/source/kernel/features/basic.asm @@ -842,14 +842,14 @@ do_break: do_call: call get_token cmp ax, NUMBER - je .is_number + je .check_is_number mov ax, 0 mov byte al, [token] call get_var jmp .execute_call -.is_number: +.check_is_number: mov si, token call string_cast_to_int @@ -1325,7 +1325,7 @@ do_for: cmp ax, NUMBER jne .error -.second_is_number: +.second_check_is_number: mov si, token ; Get target number call string_cast_to_int jmp .continue2 @@ -1625,7 +1625,7 @@ do_if: je .equals_char mov byte al, [token] - call is_letter + call check_is_letter jc .equals_var mov si, token ; Otherwise it's, eg 'X = 1' (a number) @@ -1711,7 +1711,7 @@ do_if: .greater: call get_token ; Greater than a variable or number? mov byte al, [token] - call is_letter + call check_is_letter jc .greater_var mov si, token ; Must be a number here... @@ -1736,7 +1736,7 @@ do_if: .less: call get_token mov byte al, [token] - call is_letter + call check_is_letter jc .less_var mov si, token @@ -2636,7 +2636,7 @@ do_peekint: cmp ax, NUMBER jne .error -.address_is_number: +.address_check_is_number: mov si, token call string_cast_to_int jmp .load_data @@ -3770,14 +3770,14 @@ do_string: call get_token ; Now there should be a number cmp ax, NUMBER - je .third_is_number + je .third_check_is_number cmp ax, VARIABLE je .third_is_variable jmp .error -.third_is_number: +.third_check_is_number: mov si, token call string_cast_to_int jmp .got_number @@ -3984,7 +3984,7 @@ get_token: cmp al, ' ' je .newline - call is_number + call check_is_number jc get_number_token cmp al, '"' @@ -4030,7 +4030,7 @@ get_number_token: je .done cmp al, ' ' je .done - call is_number + call check_is_number jc .fine mov si, err_char_in_num @@ -4153,7 +4153,7 @@ get_string_token: .is_not_string: mov byte al, [token] - call is_letter + call check_is_letter jc .is_var mov ax, UNKNOWN @@ -4164,37 +4164,6 @@ get_string_token: ret -; ------------------------------------------------------------------ -; Set carry flag if AL contains ASCII number - -is_number: - cmp al, 48 - jl .not_number - cmp al, 57 - jg .not_number - stc - ret -.not_number: - clc - ret - - -; ------------------------------------------------------------------ -; Set carry flag if AL contains ASCII letter - -is_letter: - cmp al, 65 - jl .not_letter - cmp al, 90 - jg .not_letter - stc - ret - -.not_letter: - clc - ret - - ; ------------------------------------------------------------------ ; Print error message and quit out diff --git a/source/kernel/features/cli.asm b/source/kernel/features/cli.asm index aa4e37b..153950f 100644 --- a/source/kernel/features/cli.asm +++ b/source/kernel/features/cli.asm @@ -30,14 +30,14 @@ os_read_cli: mov di, help_string call os_compare_strings cmp cl, 1 - je help + je .help ; Clear screen mov si, user_input mov di, clear_string call os_compare_strings cmp cl, 1 - je clear + je .clear ; Reboot mov si, user_input @@ -51,21 +51,28 @@ os_read_cli: mov di, basic_string call os_compare_strings cmp cl, 1 - je basic + je .basic ; Cat mov si, user_input mov di, cat_string call os_compare_strings cmp cl, 1 - je cat + je .cat ; LS mov si, user_input mov di, ls_string call os_compare_strings cmp cl, 1 - je ls + je .ls + + ; ED + mov si, user_input + mov di, ed_string + call os_compare_strings + cmp cl, 1 + je .ed jmp .unkown @@ -80,21 +87,25 @@ os_read_cli: popa call os_start_cli -clear: +.clear: call os_set_text_mode call os_read_cli.finish -help: +.help: mov si, help_text call os_print_string call os_read_cli.finish -basic: +.basic: call util_basic call os_read_cli.finish -cat: +.cat: call util_cat call os_read_cli.finish -ls: +.ls: call util_ls call os_read_cli.finish +.ed: + call util_ed + call os_read_cli.finish + diff --git a/source/kernel/features/keyboard.asm b/source/kernel/features/keyboard.asm index a011c31..edaef1c 100644 --- a/source/kernel/features/keyboard.asm +++ b/source/kernel/features/keyboard.asm @@ -32,7 +32,6 @@ keyboard_display_input: pusha mov di, ax mov ax, bx - mov bx,20 .check_key_pressed: call os_read_input diff --git a/source/kernel/features/text.asm b/source/kernel/features/text.asm index f2fdc1f..4de53c9 100644 --- a/source/kernel/features/text.asm +++ b/source/kernel/features/text.asm @@ -68,6 +68,9 @@ text_print_raw: int 10h mov al, 0Dh int 10h + push ax + call os_read_input ; wait until key is pressed until it prints the next line + pop ax jmp .repeat .finish: popa diff --git a/source/kernel/features/utils.asm b/source/kernel/features/utils.asm index 347eaec..308cd22 100644 --- a/source/kernel/features/utils.asm +++ b/source/kernel/features/utils.asm @@ -1,30 +1,30 @@ util_cat: - pusha + pusha - call disk_clear_file_buffer - mov si, user_input - ; TODO make this more consistent to account for double spaces - add si, 4 ; Move si to after 'CAT' + call disk_clear_file_buffer + mov si, user_input + ; TODO make this more consistent to account for double spaces + add si, 4 ; Move si to after 'CAT' - call disk_load_file - mov si, file_buffer - mov cx, [file_length] - call text_print_raw + call disk_load_file + mov si, file_buffer + mov cx, [file_length] + call text_print_raw - popa - ret + popa + ret util_ls: - pusha + pusha - call disk_list_contents + call disk_list_contents - mov si, output_buffer - call os_print_string - call disk_clear_output_buffer + mov si, output_buffer + call os_print_string + call disk_clear_output_buffer - popa - ret + popa + ret util_basic: pusha @@ -43,3 +43,13 @@ util_basic: popa ret + +util_ed: + pusha + call disk_load_root + call disk_load_file + + call ed + + popa + ret diff --git a/source/kernel/kernel.asm b/source/kernel/kernel.asm index fa7c67c..7e40b0a 100644 --- a/source/kernel/kernel.asm +++ b/source/kernel/kernel.asm @@ -33,13 +33,19 @@ halt: %INCLUDE "source/kernel/features/sound.asm" %INCLUDE "source/kernel/features/disk.asm" %INCLUDE "source/kernel/features/math.asm" + %INCLUDE "source/kernel/features/check.asm" %INCLUDE "source/kernel/features/time.asm" %INCLUDE "source/kernel/features/utils.asm" %INCLUDE "source/kernel/features/cli.asm" %INCLUDE "source/kernel/features/misc.asm" %INCLUDE "source/kernel/features/basic.asm" + +; PROGRAMS + %INCLUDE "source/kernel/programs/ed.asm" ; DATA/VARIABLES %INCLUDE "source/kernel/data.asm" + + diff --git a/source/kernel/programs/ed.asm b/source/kernel/programs/ed.asm index e69de29..5e6805f 100644 --- a/source/kernel/programs/ed.asm +++ b/source/kernel/programs/ed.asm @@ -0,0 +1,35 @@ +; Planned commands: +; i insert +; a append +; l prints lines +; w save to disk +; q quit +ed: + pusha + mov si, ed_welcome + call os_print_string + .main_loop: + mov ax, ed_prompt + mov bx, 40 + call keyboard_display_input ; AX = string location, BX = max prompt length + mov si, ed_prompt + jmp .get_token + + ; Types of tokens: + ; Number: eg 123 + ; Doller (refers to the last line) $ + ; Comma , + ; Command: eg i + ; 123 + .get_token: + xor ax,ax + lodsb + call check_is_number + jmp .exit + + .exit: + popa + ret + +ed_prompt: times 40 db 0 +ed_welcome: db "This is ED\n", 0