diff --git a/Makefile b/Makefile index cfe6f9b..f5f7263 100644 --- a/Makefile +++ b/Makefile @@ -9,11 +9,19 @@ SRC = ./src BUILD = ./build # C_FILES = $(shell find $(SRC) -name "*.c" -exec basename -s ".c" {} \;) +.PHONY: os clean run + # Main compilation target -os: bootloader kernel - @cat $(BUILD)/boot.bin $(BUILD)/kernel.bin > $(BUILD)/os.bin +os: $(BUILD) bootloader kernel + @$(AS) -fbin -o $(BUILD)/filetable.bin $(SRC)/filetable.asm + @cat $(BUILD)/boot.bin $(BUILD)/filetable.bin $(BUILD)/kernel.bin > $(BUILD)/os.bin @dd if=/dev/zero of=kern.iso bs=512 count=2880 @dd if=$(BUILD)/os.bin of=kern.iso conv=notrunc + @dd if=$(SRC)/fs/test.txt of=kern.iso bs=512 seek=22 conv=notrunc + +$(BUILD): + @[ -d $(BUILD) ] || mkdir $(BUILD) + @rm -rf $(BUILD)/* # Bootloader: This target is responsible for creating boot.bin bootloader: @@ -31,6 +39,6 @@ run: # Clean all build files clean: - @rm -rf $(BUILD)/* + @rm -rf $(BUILD) @rm -f kern.iso diff --git a/docs/main.md b/docs/main.md index 775fb5d..350307e 100644 --- a/docs/main.md +++ b/docs/main.md @@ -11,7 +11,8 @@ Kern uses a shell (for now), so you'll have to type commands to do stuff. It is currently quite simple. It supports these commands: - clear: Clears the screen -- echo : Prints msg to the screen +- disk \ \ [data]: Reads/Writes data from/to sector on disk +- echo \: Prints msg to the screen - exit: Exits the shell - help: Prints all available commands - ls: Prints all files diff --git a/src/boot.asm b/src/boot.asm index cc123f4..6ac2b36 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -36,7 +36,7 @@ start: mov al, KERNEL_SIZE mov ch, 0 ; Cylinder mov dh, 0 ; Head - mov cl, 2 ; Sector + mov cl, 3 ; Sector - 1 is this file, 2 is filetable mov dl, [driveNum] mov ah, 2 ; Read from disk diff --git a/src/filetable.asm b/src/filetable.asm new file mode 100644 index 0000000..5495cfa --- /dev/null +++ b/src/filetable.asm @@ -0,0 +1,19 @@ +[bits 16] + +;; +;; Filetable layout +;; 0-9 : Filename +;; 10-12 : Filetype +;; 13 : RESERVED +;; 14 : Starting sector +;; 15 : File Length (in sectors) +;; + +filetable: + db "boot",0,0,0,0,0,0, "bin",0,0,1 + db "filetable",0, "tab",0,1,1 + db "kernel",0,0,0,0, "bin",0,2,20 + db "test",0,0,0,0,0,0, "txt",0,22,1 + +times 512-($-$$) db 0 + diff --git a/src/fs/test.txt b/src/fs/test.txt new file mode 100644 index 0000000..0defdad --- /dev/null +++ b/src/fs/test.txt @@ -0,0 +1 @@ +This is a test file. Should be saved in test.txt! \ No newline at end of file diff --git a/src/kernel.c b/src/kernel.c index fdf8c24..d809f93 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -111,9 +111,50 @@ void main() { print(" echo | Prints a message to stdout\n", 0x0f); print(" exit | Exits shell\n", 0x0f); print(" help | Prints this message\n", 0x0f); - // TODO: print(" ls | Lists all available files\n", 0x0f); + print(" ls | Lists all available files\n", 0x0f); // TODO: print(" reboot | Reboots the system\n", 0x0f); print(" test | Performs tests\n", 0x0f); + } else if (strcmp(input, "ls") == 0) { + char filetab[512]; + char* ft = filetab; + diskRead(1, 1, filetab); + + while (*ft != '\0') { + char filename[15] = { 0 }; + uint8_t offset = 0; + for (uint8_t i = 0; i < 14; i++) { + if (i == 9) { + filename[offset++] = '.'; + continue; + } + if (*ft != '\0') { filename[offset++] = *ft; } + ft++; + } + ft++; // RESERVED + + uint8_t sector = *ft++; + uint8_t size = *ft++; + + if (sector < 10) putc('0', 0x0f); + if (sector == 0) putc('0', 0x0f); + else print(itoa(sector, 10), 0x0f); + print(": ", 0x0f); + print(filename, 0x0f); + + for (uint8_t i = 14 - strlen(filename); i > 0; i--) { + putc(' ', 0x0f); + } + + print(" | ", 0x0f); + if (size >> 1) { + print(itoa(size >> 1, 10), 0x0f); + if (size & 0x01) { print(".5", 0x0f); } + print("kB\n", 0x0f); + } else { + print(itoa(size*512, 10), 0x0f); + print("B\n", 0x0f); + } + } } else if (strcmp(input, "test") == 0) { print("Running Tests...\n", 0x0f); uint8_t buf[512]; @@ -142,3 +183,4 @@ void main() { } } } +