From 184c58b96271cae1421f9feaead892a9ca16a8b4 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sat, 2 Dec 2023 20:31:59 -0800 Subject: [PATCH 01/17] Add dumb multiplier code test --- .gitlab-ci.yml | 18 +++++++ sw/test_code/multiplier_test/Makefile | 39 ++++++++++++++ sw/test_code/multiplier_test/link.ld | 35 ++++++++++++ sw/test_code/multiplier_test/main.s | 73 ++++++++++++++++++++++++++ sw/test_code/multiplier_test/vectors.s | 14 +++++ 5 files changed, 179 insertions(+) create mode 100644 sw/test_code/multiplier_test/Makefile create mode 100644 sw/test_code/multiplier_test/link.ld create mode 100644 sw/test_code/multiplier_test/main.s create mode 100644 sw/test_code/multiplier_test/vectors.s diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index afdd6ae..aa9505a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -140,6 +140,24 @@ mapper_code sim: - TEST_PROGRAM_NAME=mapper_test make mapper_code_tb - ./mapper_code_tb +multiplier_code sim: + tags: + - linux + - iverilog + stage: simulate + needs: + - job: build toolchain + artifacts: true + artifacts: + paths: + - hw/efinix_fpga/simulation/mapper_code_tb.vcd + script: + - source init_env.sh + - cd hw/efinix_fpga/simulation + - make clean + - TEST_PROGRAM_NAME=multiplier_test make mapper_code_tb + - ./mapper_code_tb + interrupt_controller sim: tags: - linux diff --git a/sw/test_code/multiplier_test/Makefile b/sw/test_code/multiplier_test/Makefile new file mode 100644 index 0000000..1f04f9c --- /dev/null +++ b/sw/test_code/multiplier_test/Makefile @@ -0,0 +1,39 @@ +CC=../../cc65/bin/cl65 +LD=../../cc65/bin/cl65 +CFLAGS=-T -t none -I. --cpu "65C02" +LDFLAGS=-C link.ld -m $(NAME).map + +NAME=multiplier_test + +BIN=$(NAME).bin +HEX=$(NAME).hex + +LISTS=lists + +SRCS=$(wildcard *.s) $(wildcard *.c) +SRCS+=$(wildcard **/*.s) $(wildcard **/*.c) +OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) +OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) + +# Make sure the kernel linked to correct address, no relocation! +all: $(HEX) + +$(HEX): $(BIN) + objcopy --input-target=binary --output-target=verilog $(BIN) $(HEX) + +$(BIN): $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ + +%.o: %.c $(LISTS) + $(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@ + +%.o: %.s $(LISTS) + $(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@ + +$(LISTS): + mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS)))) + +.PHONY: clean +clean: + rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map + diff --git a/sw/test_code/multiplier_test/link.ld b/sw/test_code/multiplier_test/link.ld new file mode 100644 index 0000000..66a42fe --- /dev/null +++ b/sw/test_code/multiplier_test/link.ld @@ -0,0 +1,35 @@ +MEMORY +{ + ZP: start = $0, size = $100, type = rw, define = yes; + SDRAM: start = $9200, size = $4d00, type = rw, define = yes; + ROM: start = $F000, size = $1000, file = %O; +} + +SEGMENTS { + ZEROPAGE: load = ZP, type = zp, define = yes; + DATA: load = ROM, type = rw, define = yes, run = SDRAM; + BSS: load = SDRAM, type = bss, define = yes; + HEAP: load = SDRAM, type = bss, optional = yes; + STARTUP: load = ROM, type = ro; + ONCE: load = ROM, type = ro, optional = yes; + CODE: load = ROM, type = ro; + RODATA: load = ROM, type = ro; + VECTORS: load = ROM, type = ro, start = $FFFA; +} + +FEATURES { + CONDES: segment = STARTUP, + type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__; + CONDES: segment = STARTUP, + type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__; +} + +SYMBOLS { + # Define the stack size for the application + __STACKSIZE__: value = $0200, type = weak; + __STACKSTART__: type = weak, value = $0800; # 2k stack +} diff --git a/sw/test_code/multiplier_test/main.s b/sw/test_code/multiplier_test/main.s new file mode 100644 index 0000000..f3fa369 --- /dev/null +++ b/sw/test_code/multiplier_test/main.s @@ -0,0 +1,73 @@ +.MACPACK generic + +.export _init, _nmi_int, _irq_int + +MULTIPLIER_BASE = $eff0 + +MULTIPLIER_AL = MULTIPLIER_BASE + 0 +MULTIPLIER_AH = MULTIPLIER_BASE + 1 +MULTIPLIER_BL = MULTIPLIER_BASE + 2 +MULTIPLIER_BH = MULTIPLIER_BASE + 3 + +MULTIPLIER_OLL = MULTIPLIER_BASE + 4 +MULTIPLIER_OLH = MULTIPLIER_BASE + 5 +MULTIPLIER_OHL = MULTIPLIER_BASE + 6 +MULTIPLIER_OHH = MULTIPLIER_BASE + 7 + +GOLDEN_OUTPUT_0 = $03 +GOLDEN_OUTPUT_1 = $0a +GOLDEN_OUTPUT_2 = $08 +GOLDEN_OUTPUT_3 = $00 + +.zeropage +finish: .res 1 + +.data + +output: .res 4 + +.code + +_nmi_int: +_irq_int: + +_init: + ldx #$ff + txs + + lda #$01 + sta MULTIPLIER_AL + lda #$02 + sta MULTIPLIER_AH + + lda #$03 + sta MULTIPLIER_BL + lda #$04 + sta MULTIPLIER_BH + + ldx #$00 +L1: lda MULTIPLIER_OLL,x + sta output,x + inx + cpx #$4 + bne L1 + + lda output + cmp #GOLDEN_OUTPUT_0 + bne fail + lda output+1 + cmp #GOLDEN_OUTPUT_1 + bne fail + lda output+2 + cmp #GOLDEN_OUTPUT_2 + bne fail + lda output+3 + cmp #GOLDEN_OUTPUT_3 + bne fail + + lda #$6d + sta finish + +fail: + lda #$bd + sta finish \ No newline at end of file diff --git a/sw/test_code/multiplier_test/vectors.s b/sw/test_code/multiplier_test/vectors.s new file mode 100644 index 0000000..81ae6e0 --- /dev/null +++ b/sw/test_code/multiplier_test/vectors.s @@ -0,0 +1,14 @@ +; --------------------------------------------------------------------------- +; vectors.s +; --------------------------------------------------------------------------- +; +; Defines the interrupt vector table. + +.import _init +.import _nmi_int, _irq_int + +.segment "VECTORS" + +.addr _nmi_int ; NMI vector +.addr _init ; Reset vector +.addr _irq_int ; IRQ/BRK vector \ No newline at end of file From 5c74d161d449d9754dbab09a82d18a52c4786780 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sun, 3 Dec 2023 23:27:45 -0800 Subject: [PATCH 02/17] Add some basic fat32 code --- sw/kernel/devices/io.inc65 | 19 ++++- sw/kernel/devices/multiplier.h | 12 +++ sw/kernel/devices/multiplier.s | 36 +++++++++ sw/kernel/filesystems/fat32.h | 34 +++++++++ sw/kernel/filesystems/fat32.s | 115 +++++++++++++++++++++++++++++ sw/kernel/filesystems/fs.h | 19 +++++ sw/kernel/kernel.c | 15 ++-- sw/test_code/fs_test/Makefile | 48 ++++++++++++ sw/test_code/fs_test/asm_harness.s | 5 ++ sw/test_code/fs_test/harness.c | 21 ++++++ sw/test_code/fs_test/main.c | 9 +++ 11 files changed, 326 insertions(+), 7 deletions(-) create mode 100644 sw/kernel/devices/multiplier.h create mode 100644 sw/kernel/devices/multiplier.s create mode 100644 sw/kernel/filesystems/fat32.h create mode 100644 sw/kernel/filesystems/fat32.s create mode 100644 sw/kernel/filesystems/fs.h create mode 100644 sw/test_code/fs_test/Makefile create mode 100644 sw/test_code/fs_test/asm_harness.s create mode 100644 sw/test_code/fs_test/harness.c create mode 100644 sw/test_code/fs_test/main.c diff --git a/sw/kernel/devices/io.inc65 b/sw/kernel/devices/io.inc65 index 42b0910..56ccdc1 100644 --- a/sw/kernel/devices/io.inc65 +++ b/sw/kernel/devices/io.inc65 @@ -10,4 +10,21 @@ SPI_BAUD = $efd8 SPI_INPUT = $efd9 SPI_OUTPUT = $efda SPI_CTRL = $efdb -SPI_STATUS = SPI_CTRL \ No newline at end of file +SPI_STATUS = SPI_CTRL + +MULTIPLIER_BASE = $eff0 + +MULTIPLIER_AL = MULTIPLIER_BASE + 0 +MULTIPLIER_AH = MULTIPLIER_BASE + 1 +MULTIPLIER_BL = MULTIPLIER_BASE + 2 +MULTIPLIER_BH = MULTIPLIER_BASE + 3 + +MULTIPLIER_OLL = MULTIPLIER_BASE + 4 +MULTIPLIER_OLH = MULTIPLIER_BASE + 5 +MULTIPLIER_OHL = MULTIPLIER_BASE + 6 +MULTIPLIER_OHH = MULTIPLIER_BASE + 7 + +GOLDEN_OUTPUT_0 = $03 +GOLDEN_OUTPUT_1 = $0a +GOLDEN_OUTPUT_2 = $08 +GOLDEN_OUTPUT_3 = $00 \ No newline at end of file diff --git a/sw/kernel/devices/multiplier.h b/sw/kernel/devices/multiplier.h new file mode 100644 index 0000000..e60764f --- /dev/null +++ b/sw/kernel/devices/multiplier.h @@ -0,0 +1,12 @@ +#ifndef _MULTIPLER_H +#define _MULTIPLER_H + +#include + +/* Multiply 2 integers into 1 long */ +uint32_t lmulii(uint16_t a, uint16_t b); + +/* Multiply 2 integers into 1 integer, discarding upper bits. */ +uint16_t imulii(uint16_t a, uint16_t b); + +#endif \ No newline at end of file diff --git a/sw/kernel/devices/multiplier.s b/sw/kernel/devices/multiplier.s new file mode 100644 index 0000000..7c3d6a3 --- /dev/null +++ b/sw/kernel/devices/multiplier.s @@ -0,0 +1,36 @@ +.include "io.inc65" + +.MACPACK generic + +.import popax +.importzp sreg + +.export _lmulii, _imulii + +.code + +.proc _lmulii + sta MULTIPLIER_BL + stx MULTIPLIER_BH + jsr popax + sta MULTIPLIER_AL + stx MULTIPLIER_AH + lda MULTIPLIER_OHL + sta sreg + lda MULTIPLIER_OHH + sta sreg+1 + lda MULTIPLIER_OLL + ldx MULTIPLIER_OLH + rts +.endproc + +.proc _imulii + sta MULTIPLIER_BL + stx MULTIPLIER_BH + jsr popax + sta MULTIPLIER_AL + stx MULTIPLIER_AH + lda MULTIPLIER_OLL + ldx MULTIPLIER_OLH + rts +.endproc \ No newline at end of file diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h new file mode 100644 index 0000000..fcdd45f --- /dev/null +++ b/sw/kernel/filesystems/fat32.h @@ -0,0 +1,34 @@ +#ifndef _FAT32_H +#define _FAT32_H + +#include + +void fat32_init(); + +struct fat32_directory_entry { + char file_name[8]; + char file_ext[3]; + uint8_t attr1; + uint8_t create_time_10ms; + uint16_t create_time; + uint16_t create_date; + uint16_t access_date; + uint16_t cluster_high; + uint16_t modified_time; + uint16_t modified_date; + uint16_t cluster_low; + uint32_t file_size; +}; + +struct lfn_entry { + uint8_t sequence_number; + uint16_t name_0[5]; + uint8_t attributes; + uint8_t type; + uint8_t checksum; + uint16_t name_1[6]; + uint16_t cluster_low; + uint16_t name_2[2]; +}; + +#endif diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s new file mode 100644 index 0000000..267d570 --- /dev/null +++ b/sw/kernel/filesystems/fat32.s @@ -0,0 +1,115 @@ +.MACPACK generic + +.autoimport +.feature string_escapes + +.importzp ptr1, sreg + +.import _SD_readSingleBlock + +.export _fat32_init + + +.data +fat_start_sector: .res 2 +data_start_sector: .res 2 +sd_buf: .res 512 + +bps_val_str: .asciiz "Bytes Per Sector: 0x%x\n" +sps_val_str: .asciiz "Sectors Per Cluster: 0x%x\n" +rsv_val_str: .asciiz "Reserved Sectors: 0x%x\n" +fat_count_str: .asciiz "FAT count: 0x%x\n" +fat_sect_str: .asciiz "Sectors per FAT: 0x%x\n" +fat_size_tot_str: .asciiz "Total fat size: 0x%lx\n" +rsv_sect_bytes_str: .asciiz "Total reserved bytes: 0x%x\n" +rsv_sd_sectors: .asciiz "Reserved SD Sectors: 0x%x\n" + +.code + +bytes_per_sector = sd_buf + $0B +sectors_per_cluster = sd_buf + $0D +reserved_sectors = sd_buf + $0E +fat_count = sd_buf + $10 +sectors_per_fat = sd_buf + $24 + +.proc _fat32_init + ; load sector 0 into sd_buf + lda #$00 + ldx #$00 + stz sreg + stz sreg+1 + jsr pusheax + lda #sd_buf + jsr pushax + lda #ptr1 + jsr _SD_readSingleBlock + + lda #bps_val_str + jsr pushax + lda bytes_per_sector + ldx bytes_per_sector+1 + jsr pushax + ldy #$4 + jsr _printf + + lda #sps_val_str + jsr pushax + lda sectors_per_cluster + ldx #$00 + jsr pushax + ldy #$4 + jsr _cprintf + + lda #rsv_val_str + jsr pushax + lda reserved_sectors + ldx #$00 + jsr pushax + ldy #$4 + jsr _cprintf + + lda #fat_count_str + jsr pushax + lda fat_count + ldx #$00 + jsr pushax + ldy #$4 + jsr _cprintf + + + lda #rsv_sect_bytes_str + jsr pushax + + lda reserved_sectors + jsr pusha0 + lda bytes_per_sector + ldx bytes_per_sector+1 + jsr _imulii + jsr pushax + ldy #$4 + jsr _cprintf + + lda #fat_size_tot_str + jsr pushax + + ; multiply fat size and number of fats + + lda fat_count + jsr pusha0 + lda sectors_per_fat + ldx sectors_per_fat+1 + jsr _lmulii + jsr pusheax + ldy #$6 + jsr _cprintf + + rts +.endproc diff --git a/sw/kernel/filesystems/fs.h b/sw/kernel/filesystems/fs.h new file mode 100644 index 0000000..b1e738b --- /dev/null +++ b/sw/kernel/filesystems/fs.h @@ -0,0 +1,19 @@ +#ifndef _FS_H +#define _FS_H + +#include + +/* syscalls for files */ +int8_t file_read(int8_t fd, void* buf, int8_t nbytes); +int8_t file_write(int8_t fd, const void* buf, int8_t nbytes); +int8_t file_open(const uint8_t* filename); +int8_t file_close(int8_t fd); + +/* syscalls for directories */ +int8_t directory_read(int8_t fd, void* buf, int8_t nbytes); +int8_t directory_write(int8_t fd, const void* buf, int8_t nbytes); +int8_t directory_open(const uint8_t* filename); +int8_t directory_close(int8_t fd); + + +#endif \ No newline at end of file diff --git a/sw/kernel/kernel.c b/sw/kernel/kernel.c index e81a8fc..b9e56e0 100644 --- a/sw/kernel/kernel.c +++ b/sw/kernel/kernel.c @@ -6,9 +6,10 @@ #include "devices/mapper.h" #include "devices/rtc.h" #include "devices/serial.h" - #include "devices/terminal.h" +#include "filesystems/fat32.h" + void handle_rtc_interrupt() { // cputs("In IRQ interrupt!\n"); @@ -22,16 +23,16 @@ char buf[128]; int main() { cputs("Kernel\n"); - // cputs("Init Mapper\n"); + cputs("Init Mapper\n"); init_mapper(); - // cputs("Initialize Interrupts\n"); + cputs("Initialize Interrupts\n"); init_interrupts(); - // cputs("Initialize Interrupt Controller\n"); + cputs("Initialize Interrupt Controller\n"); init_interrupt_controller(); - // cputs("Initialize RTC\n"); + cputs("Initialize RTC\n"); init_rtc(); register_irq(&handle_rtc_interrupt, 0); @@ -41,10 +42,12 @@ int main() { asm volatile("cli"); - // cputs("Initialize Serial\n"); + cputs("Initialize Serial\n"); serial_init(); serial_puts("Hello from serial!\n"); + + fat32_init(); terminal_open(NULL); terminal_write(0, "Terminal Write\n", 15); diff --git a/sw/test_code/fs_test/Makefile b/sw/test_code/fs_test/Makefile new file mode 100644 index 0000000..2405c9c --- /dev/null +++ b/sw/test_code/fs_test/Makefile @@ -0,0 +1,48 @@ +CC=../../cc65/bin/cl65 +LD=../../cc65/bin/cl65 +SIM=../../cc65/bin/sim65 +CFLAGS=-T -t sim65c02 -I. +LDFLAGS=-m $(NAME).map + +NAME=fs_test + +BIN=$(NAME).bin + +FS=$(REPO_TOP)/sw/script/fs.fat + +LISTS=lists + +EXT_SRCS=$(REPO_TOP)/sw/kernel/filesystems/fat32.s + +SRCS=$(wildcard *.s) $(wildcard *.c) +SRCS+=$(wildcard **/*.s) $(wildcard **/*.c) +OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) +OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) + +run: all + $(SIM) $(BIN) + +all: fs.fat fat32.s $(BIN) + +$(BIN): $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ + +%.o: %.c $(LISTS) + $(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@ + +%.o: %.s $(LISTS) + $(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@ + +fat32.s: $(EXT_SRCS) + cp $^ . + +fs.fat: $(FS) + cp $^ . + +$(LISTS): + mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS)))) + +.PHONY: clean +clean: + rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map fat32.s + diff --git a/sw/test_code/fs_test/asm_harness.s b/sw/test_code/fs_test/asm_harness.s new file mode 100644 index 0000000..c227854 --- /dev/null +++ b/sw/test_code/fs_test/asm_harness.s @@ -0,0 +1,5 @@ +.import _printf +.export _cprintf + +_cprintf: + jmp _printf \ No newline at end of file diff --git a/sw/test_code/fs_test/harness.c b/sw/test_code/fs_test/harness.c new file mode 100644 index 0000000..5fcb855 --- /dev/null +++ b/sw/test_code/fs_test/harness.c @@ -0,0 +1,21 @@ +#include +#include +#include + +#define FILE_PATH "fs.fat" + +uint32_t lmulii(uint16_t a, uint16_t b) { + printf("lmulii: %x * %x = %x\n", a, b, a*b); + return a * b; +} + +uint16_t imulii(uint16_t a, uint16_t b) { + printf("imulii: %x * %x = %x\n", a, b, a*b); + return a * b; +} + +uint8_t SD_readSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *error) { + FILE* f = fopen(FILE_PATH, "rb"); + // fseek(f, addr * 512, SEEK_SET); + fread(buf, 512, 1, f); +} diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c new file mode 100644 index 0000000..93d9085 --- /dev/null +++ b/sw/test_code/fs_test/main.c @@ -0,0 +1,9 @@ +#include + +void fat32_init(void); + +int main(void) { + printf("Hello, world!\n"); + fat32_init(); + return 0; +} \ No newline at end of file From 16a7f4db4d1c81e5629ed8528c376ec7fe151d25 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Mon, 4 Dec 2023 00:13:16 -0800 Subject: [PATCH 03/17] Update cc65 pointer with PVSeek --- sw/cc65 | 2 +- sw/kernel/filesystems/fat32.s | 2 +- sw/test_code/fs_test/Makefile | 4 +++- sw/test_code/fs_test/harness.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sw/cc65 b/sw/cc65 index 58518b6..84af5e6 160000 --- a/sw/cc65 +++ b/sw/cc65 @@ -1 +1 @@ -Subproject commit 58518b6ff56a4e3339c6faeb1251d73d1a6a6b99 +Subproject commit 84af5e6887c39dfd7d38b261e2410bf29dcdaa66 diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 267d570..878818d 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -53,7 +53,7 @@ sectors_per_fat = sd_buf + $24 ldx bytes_per_sector+1 jsr pushax ldy #$4 - jsr _printf + jsr _cprintf lda #sps_val_str diff --git a/sw/test_code/fs_test/Makefile b/sw/test_code/fs_test/Makefile index 2405c9c..0cb286b 100644 --- a/sw/test_code/fs_test/Makefile +++ b/sw/test_code/fs_test/Makefile @@ -6,6 +6,8 @@ LDFLAGS=-m $(NAME).map NAME=fs_test +SIMARGS= + BIN=$(NAME).bin FS=$(REPO_TOP)/sw/script/fs.fat @@ -20,7 +22,7 @@ OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) run: all - $(SIM) $(BIN) + $(SIM) $(SIMARGS) $(BIN) all: fs.fat fat32.s $(BIN) diff --git a/sw/test_code/fs_test/harness.c b/sw/test_code/fs_test/harness.c index 5fcb855..93b9f9b 100644 --- a/sw/test_code/fs_test/harness.c +++ b/sw/test_code/fs_test/harness.c @@ -16,6 +16,6 @@ uint16_t imulii(uint16_t a, uint16_t b) { uint8_t SD_readSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *error) { FILE* f = fopen(FILE_PATH, "rb"); - // fseek(f, addr * 512, SEEK_SET); + fseek(f, addr * 512, SEEK_SET); fread(buf, 512, 1, f); } From 84814f05f9f56bf4c5c2cff2f9713522ad62d6ed Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Mon, 4 Dec 2023 18:40:21 -0800 Subject: [PATCH 04/17] Calculate data start --- sw/kernel/filesystems/fat32.s | 59 ++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 878818d..029ce48 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -12,7 +12,9 @@ .data fat_start_sector: .res 2 -data_start_sector: .res 2 +data_start_sector: .res 4 +fat_size: .res 4 + sd_buf: .res 512 bps_val_str: .asciiz "Bytes Per Sector: 0x%x\n" @@ -23,6 +25,7 @@ fat_sect_str: .asciiz "Sectors per FAT: 0x%x\n" fat_size_tot_str: .asciiz "Total fat size: 0x%lx\n" rsv_sect_bytes_str: .asciiz "Total reserved bytes: 0x%x\n" rsv_sd_sectors: .asciiz "Reserved SD Sectors: 0x%x\n" +data_start_sect_str: .asciiz "Data sector start: 0x%lx\n" .code @@ -93,9 +96,15 @@ sectors_per_fat = sd_buf + $24 ldx bytes_per_sector+1 jsr _imulii jsr pushax + phx ldy #$4 jsr _cprintf + pla + lsr + sta fat_start_sector + stz fat_start_sector + 1 + lda #fat_size_tot_str jsr pushax @@ -107,9 +116,57 @@ sectors_per_fat = sd_buf + $24 lda sectors_per_fat ldx sectors_per_fat+1 jsr _lmulii + sta fat_size + stx fat_size+1 + lda sreg + sta fat_size+2 + lda sreg+1 + sta fat_size+3 + lda fat_size + ldx fat_size+1 jsr pusheax ldy #$6 jsr _cprintf + + lda fat_size + adc fat_start_sector + sta data_start_sector + lda fat_size+1 + adc fat_start_sector+1 + sta data_start_sector+1 + lda fat_size+2 + sta data_start_sector+2 + lda fat_size+3 + sta data_start_sector+3 + + lda #data_start_sect_str + jsr pushax + lda data_start_sector+2 + sta sreg + lda data_start_sector+3 + sta sreg+1 + lda data_start_sector + ldx data_start_sector+1 + jsr pusheax + ldy #$6 + jsr _cprintf + + ; load sector into sd_buf + lda data_start_sector+2 + sta sreg + lda data_start_sector+3 + sta sreg+1 + lda data_start_sector + ldx data_start_sector+1 + jsr pusheax + lda #sd_buf + jsr pushax + lda #ptr1 + jsr _SD_readSingleBlock + rts .endproc From 902b1b5bb968b73bf0ccf00df91821b21886ff77 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Mon, 4 Dec 2023 21:57:36 -0800 Subject: [PATCH 05/17] Save root cluster number --- sw/cc65 | 2 +- sw/kernel/filesystems/fat32.s | 77 ++++++---------------------------- sw/test_code/fs_test/harness.c | 3 ++ sw/test_code/fs_test/main.c | 1 - 4 files changed, 17 insertions(+), 66 deletions(-) diff --git a/sw/cc65 b/sw/cc65 index 84af5e6..9824f6e 160000 --- a/sw/cc65 +++ b/sw/cc65 @@ -1 +1 @@ -Subproject commit 84af5e6887c39dfd7d38b261e2410bf29dcdaa66 +Subproject commit 9824f6e3d40752e4bd8d0a4b40cb65d922e36fce diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 029ce48..0c106ca 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -11,21 +11,16 @@ .data +root_cluster: .res 4 fat_start_sector: .res 2 data_start_sector: .res 4 fat_size: .res 4 sd_buf: .res 512 -bps_val_str: .asciiz "Bytes Per Sector: 0x%x\n" -sps_val_str: .asciiz "Sectors Per Cluster: 0x%x\n" -rsv_val_str: .asciiz "Reserved Sectors: 0x%x\n" -fat_count_str: .asciiz "FAT count: 0x%x\n" -fat_sect_str: .asciiz "Sectors per FAT: 0x%x\n" -fat_size_tot_str: .asciiz "Total fat size: 0x%lx\n" -rsv_sect_bytes_str: .asciiz "Total reserved bytes: 0x%x\n" -rsv_sd_sectors: .asciiz "Reserved SD Sectors: 0x%x\n" data_start_sect_str: .asciiz "Data sector start: 0x%lx\n" +starting_cluster_str: .asciiz "Root cluster num: %lx\n"; +value_str: .asciiz "Value: 0x%x\n" .code @@ -34,6 +29,7 @@ sectors_per_cluster = sd_buf + $0D reserved_sectors = sd_buf + $0E fat_count = sd_buf + $10 sectors_per_fat = sd_buf + $24 +root_cluster_offs = sd_buf + $2C .proc _fat32_init ; load sector 0 into sd_buf @@ -49,68 +45,25 @@ sectors_per_fat = sd_buf + $24 ldx #>ptr1 jsr _SD_readSingleBlock - lda #bps_val_str - jsr pushax - lda bytes_per_sector - ldx bytes_per_sector+1 - jsr pushax - ldy #$4 - jsr _cprintf - - lda #sps_val_str - jsr pushax - lda sectors_per_cluster ldx #$00 - jsr pushax - ldy #$4 - jsr _cprintf - - lda #rsv_val_str - jsr pushax - lda reserved_sectors - ldx #$00 - jsr pushax - ldy #$4 - jsr _cprintf - - lda #fat_count_str - jsr pushax - lda fat_count - ldx #$00 - jsr pushax - ldy #$4 - jsr _cprintf - - - lda #rsv_sect_bytes_str - jsr pushax +L1: lda root_cluster_offs,x + sta root_cluster,x + inx + cpx #$4 + blt L1 + ; Multiply reserved sectors and bytes per sector, then divide by 512 to get sd sectors lda reserved_sectors jsr pusha0 lda bytes_per_sector ldx bytes_per_sector+1 jsr _imulii - jsr pushax - phx - ldy #$4 - jsr _cprintf - - pla + txa lsr sta fat_start_sector stz fat_start_sector + 1 - lda #fat_size_tot_str - jsr pushax - - ; multiply fat size and number of fats - + ; multiply fat size and number of fats to get total fat size lda fat_count jsr pusha0 lda sectors_per_fat @@ -122,13 +75,9 @@ sectors_per_fat = sd_buf + $24 sta fat_size+2 lda sreg+1 sta fat_size+3 - lda fat_size - ldx fat_size+1 - jsr pusheax - ldy #$6 - jsr _cprintf + ; Add fat size to starting fat sector to get data start sector lda fat_size adc fat_start_sector sta data_start_sector diff --git a/sw/test_code/fs_test/harness.c b/sw/test_code/fs_test/harness.c index 93b9f9b..cd72522 100644 --- a/sw/test_code/fs_test/harness.c +++ b/sw/test_code/fs_test/harness.c @@ -16,6 +16,9 @@ uint16_t imulii(uint16_t a, uint16_t b) { uint8_t SD_readSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *error) { FILE* f = fopen(FILE_PATH, "rb"); + (void)error; fseek(f, addr * 512, SEEK_SET); fread(buf, 512, 1, f); + fclose(f); + return 0; } diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 93d9085..410c999 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -3,7 +3,6 @@ void fat32_init(void); int main(void) { - printf("Hello, world!\n"); fat32_init(); return 0; } \ No newline at end of file From 2859055f983931f73f606262afe4956cd414bee6 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Mon, 4 Dec 2023 23:06:00 -0800 Subject: [PATCH 06/17] Add some basic code, build kernel stuff in tree --- sw/fsdir/test.txt | 1 + sw/kernel/filesystems/fat32.h | 9 ++++ sw/kernel/filesystems/fat32.s | 90 ++++++++++++--------------------- sw/kernel/filesystems/fat32_c.c | 26 ++++++++++ sw/test_code/fs_test/Makefile | 13 +++-- sw/test_code/fs_test/main.c | 3 ++ 6 files changed, 77 insertions(+), 65 deletions(-) create mode 100644 sw/fsdir/test.txt create mode 100644 sw/kernel/filesystems/fat32_c.c diff --git a/sw/fsdir/test.txt b/sw/fsdir/test.txt new file mode 100644 index 0000000..1b99b87 --- /dev/null +++ b/sw/fsdir/test.txt @@ -0,0 +1 @@ +This is a text file, which is composed of text. \ No newline at end of file diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index fcdd45f..d938e00 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -5,6 +5,12 @@ void fat32_init(); +extern uint32_t root_cluster; +extern uint16_t fat_start_sector; +extern uint32_t data_start_sector; +extern uint32_t fat_size; +extern uint8_t* sd_buf; + struct fat32_directory_entry { char file_name[8]; char file_ext[3]; @@ -31,4 +37,7 @@ struct lfn_entry { uint16_t name_2[2]; }; +uint8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry); +uint8_t fat32_read_cluster(uint32_t cluster, void* buf); + #endif diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 0c106ca..4349d0b 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -9,14 +9,16 @@ .export _fat32_init +.export _root_cluster, _fat_start_sector, _data_start_sector, _fat_size, _sd_buf + .data -root_cluster: .res 4 -fat_start_sector: .res 2 -data_start_sector: .res 4 -fat_size: .res 4 +_root_cluster: .res 4 +_fat_start_sector: .res 2 +_data_start_sector: .res 4 +_fat_size: .res 4 -sd_buf: .res 512 +_sd_buf: .res 512 data_start_sect_str: .asciiz "Data sector start: 0x%lx\n" starting_cluster_str: .asciiz "Root cluster num: %lx\n"; @@ -24,12 +26,12 @@ value_str: .asciiz "Value: 0x%x\n" .code -bytes_per_sector = sd_buf + $0B -sectors_per_cluster = sd_buf + $0D -reserved_sectors = sd_buf + $0E -fat_count = sd_buf + $10 -sectors_per_fat = sd_buf + $24 -root_cluster_offs = sd_buf + $2C +bytes_per_sector = _sd_buf + $0B +sectors_per_cluster = _sd_buf + $0D +reserved_sectors = _sd_buf + $0E +fat_count = _sd_buf + $10 +sectors_per_fat = _sd_buf + $24 +root_cluster_offs = _sd_buf + $2C .proc _fat32_init ; load sector 0 into sd_buf @@ -38,8 +40,8 @@ root_cluster_offs = sd_buf + $2C stz sreg stz sreg+1 jsr pusheax - lda #sd_buf + lda #<_sd_buf + ldx #>_sd_buf jsr pushax lda #ptr1 @@ -47,7 +49,7 @@ root_cluster_offs = sd_buf + $2C ldx #$00 L1: lda root_cluster_offs,x - sta root_cluster,x + sta _root_cluster,x inx cpx #$4 blt L1 @@ -60,8 +62,8 @@ L1: lda root_cluster_offs,x jsr _imulii txa lsr - sta fat_start_sector - stz fat_start_sector + 1 + sta _fat_start_sector + stz _fat_start_sector + 1 ; multiply fat size and number of fats to get total fat size lda fat_count @@ -69,53 +71,25 @@ L1: lda root_cluster_offs,x lda sectors_per_fat ldx sectors_per_fat+1 jsr _lmulii - sta fat_size - stx fat_size+1 + sta _fat_size + stx _fat_size+1 lda sreg - sta fat_size+2 + sta _fat_size+2 lda sreg+1 - sta fat_size+3 + sta _fat_size+3 ; Add fat size to starting fat sector to get data start sector - lda fat_size - adc fat_start_sector - sta data_start_sector - lda fat_size+1 - adc fat_start_sector+1 - sta data_start_sector+1 - lda fat_size+2 - sta data_start_sector+2 - lda fat_size+3 - sta data_start_sector+3 - - lda #data_start_sect_str - jsr pushax - lda data_start_sector+2 - sta sreg - lda data_start_sector+3 - sta sreg+1 - lda data_start_sector - ldx data_start_sector+1 - jsr pusheax - ldy #$6 - jsr _cprintf - - ; load sector into sd_buf - lda data_start_sector+2 - sta sreg - lda data_start_sector+3 - sta sreg+1 - lda data_start_sector - ldx data_start_sector+1 - jsr pusheax - lda #sd_buf - jsr pushax - lda #ptr1 - jsr _SD_readSingleBlock + lda _fat_size + adc _fat_start_sector + sta _data_start_sector + lda _fat_size+1 + adc _fat_start_sector+1 + sta _data_start_sector+1 + lda _fat_size+2 + sta _data_start_sector+2 + lda _fat_size+3 + sta _data_start_sector+3 rts .endproc diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c new file mode 100644 index 0000000..4163141 --- /dev/null +++ b/sw/kernel/filesystems/fat32_c.c @@ -0,0 +1,26 @@ +#include "fat32.h" +#include +#include + +#include + +uint8_t fat32_read_cluster(uint32_t cluster, void* buf) { + uint8_t error; + uint32_t addr = (cluster - 2) + data_start_sector; + SD_readSingleBlock(addr, buf, &error); + return error; +} + +uint8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry) { + struct fat32_directory_entry* local_entry; + int i = 0; + fat32_read_cluster(root_cluster, sd_buf); + for (i = 0; i < 16; i++){ + local_entry = sd_buf + i*32; + if (local_entry->attr1 == 0xf || local_entry->attr1 & 0x8 || !local_entry->attr1) { + continue; + } + cprintf("Name: %.11s\n", local_entry->file_name, local_entry->file_ext); + cprintf("attr1: %x\n", local_entry->attr1); + } +} diff --git a/sw/test_code/fs_test/Makefile b/sw/test_code/fs_test/Makefile index 0cb286b..c37e3e4 100644 --- a/sw/test_code/fs_test/Makefile +++ b/sw/test_code/fs_test/Makefile @@ -1,7 +1,7 @@ CC=../../cc65/bin/cl65 LD=../../cc65/bin/cl65 SIM=../../cc65/bin/sim65 -CFLAGS=-T -t sim65c02 -I. +CFLAGS=-T -t sim65c02 -I. -I $(REPO_TOP)/sw/kernel LDFLAGS=-m $(NAME).map NAME=fs_test @@ -14,17 +14,18 @@ FS=$(REPO_TOP)/sw/script/fs.fat LISTS=lists -EXT_SRCS=$(REPO_TOP)/sw/kernel/filesystems/fat32.s +EXT_SRCS=$(REPO_TOP)/sw/kernel/filesystems/fat32.s $(REPO_TOP)/sw/kernel/filesystems/fat32_c.c SRCS=$(wildcard *.s) $(wildcard *.c) SRCS+=$(wildcard **/*.s) $(wildcard **/*.c) +SRCS+=$(EXT_SRCS) OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) run: all $(SIM) $(SIMARGS) $(BIN) -all: fs.fat fat32.s $(BIN) +all: fs.fat $(BIN) $(BIN): $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ @@ -35,16 +36,14 @@ $(BIN): $(OBJS) %.o: %.s $(LISTS) $(CC) $(CFLAGS) -l $(LISTS)/$<.list -c $< -o $@ -fat32.s: $(EXT_SRCS) - cp $^ . - fs.fat: $(FS) cp $^ . + $(LISTS): mkdir -p $(addprefix $(LISTS)/,$(sort $(dir $(SRCS)))) .PHONY: clean clean: - rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map fat32.s + rm -rf $(OBJS) $(BIN) $(HEX) $(LISTS) $(NAME).map diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 410c999..f0ecc4e 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -1,8 +1,11 @@ #include +#include void fat32_init(void); int main(void) { + struct fat32_directory_entry dentry; fat32_init(); + fat32_get_cluster_by_name("KERNEL O65", &dentry); return 0; } \ No newline at end of file From 946234381d1d9d7a1cee773a233d328f90ac650e Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Tue, 5 Dec 2023 08:08:20 -0800 Subject: [PATCH 07/17] Look through files without trying too hard --- sw/kernel/filesystems/fat32.h | 6 ++++-- sw/kernel/filesystems/fat32.s | 7 ++++++- sw/kernel/filesystems/fat32_c.c | 25 +++++++++++++++++++++---- sw/test_code/fs_test/main.c | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index d938e00..fdaf57e 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -10,11 +10,13 @@ extern uint16_t fat_start_sector; extern uint32_t data_start_sector; extern uint32_t fat_size; extern uint8_t* sd_buf; +extern uint8_t sectors_per_cluster; struct fat32_directory_entry { char file_name[8]; char file_ext[3]; uint8_t attr1; + uint8_t attr2; uint8_t create_time_10ms; uint16_t create_time; uint16_t create_date; @@ -37,7 +39,7 @@ struct lfn_entry { uint16_t name_2[2]; }; -uint8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry); -uint8_t fat32_read_cluster(uint32_t cluster, void* buf); +int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry); +int8_t fat32_read_cluster(uint32_t cluster, void* buf); #endif diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 4349d0b..c30f2e5 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -9,7 +9,8 @@ .export _fat32_init -.export _root_cluster, _fat_start_sector, _data_start_sector, _fat_size, _sd_buf +.export _root_cluster, _fat_start_sector, _data_start_sector +.export _fat_size, _sd_buf, _sectors_per_cluster .data @@ -17,6 +18,7 @@ _root_cluster: .res 4 _fat_start_sector: .res 2 _data_start_sector: .res 4 _fat_size: .res 4 +_sectors_per_cluster: .res 1 _sd_buf: .res 512 @@ -47,6 +49,9 @@ root_cluster_offs = _sd_buf + $2C ldx #>ptr1 jsr _SD_readSingleBlock + lda sectors_per_cluster + sta _sectors_per_cluster + ldx #$00 L1: lda root_cluster_offs,x sta _root_cluster,x diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 4163141..64fa1c0 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -1,19 +1,23 @@ #include "fat32.h" + #include #include - #include +#include -uint8_t fat32_read_cluster(uint32_t cluster, void* buf) { +int8_t fat32_read_cluster(uint32_t cluster, void* buf) { uint8_t error; uint32_t addr = (cluster - 2) + data_start_sector; SD_readSingleBlock(addr, buf, &error); return error; } -uint8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry) { +int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry) { struct fat32_directory_entry* local_entry; int i = 0; + + cprintf("Sectors per cluster: %hhx\n", sectors_per_cluster); + fat32_read_cluster(root_cluster, sd_buf); for (i = 0; i < 16; i++){ local_entry = sd_buf + i*32; @@ -21,6 +25,19 @@ uint8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dent continue; } cprintf("Name: %.11s\n", local_entry->file_name, local_entry->file_ext); - cprintf("attr1: %x\n", local_entry->attr1); + if (!strncmp(local_entry->file_name, name, 11)) { + i = -1; + break; + } } + if (i != -1) { + cprintf("Failed to find file.\n"); + return -1; + } + + cprintf("Found file!\n"); + + cprintf("attr1: %x\n", local_entry->attr1); + cprintf("cluster: %x %x\n", local_entry->cluster_high, local_entry->cluster_low); + cprintf("File Size: %lx\n", local_entry->file_size); } diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index f0ecc4e..7b4df75 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -6,6 +6,6 @@ void fat32_init(void); int main(void) { struct fat32_directory_entry dentry; fat32_init(); - fat32_get_cluster_by_name("KERNEL O65", &dentry); + fat32_get_cluster_by_name("TEST TXT", &dentry); return 0; } \ No newline at end of file From 13738fc0d86fe2899c87679213c185da8f346793 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Tue, 5 Dec 2023 08:15:24 -0800 Subject: [PATCH 08/17] Read a little bit of the data from the file --- sw/kernel/filesystems/fat32_c.c | 6 ++---- sw/test_code/fs_test/main.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 64fa1c0..91f8b5e 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -36,8 +36,6 @@ int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentr } cprintf("Found file!\n"); - - cprintf("attr1: %x\n", local_entry->attr1); - cprintf("cluster: %x %x\n", local_entry->cluster_high, local_entry->cluster_low); - cprintf("File Size: %lx\n", local_entry->file_size); + memcpy(dentry, local_entry, 32); + return 0; } diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 7b4df75..2067d4b 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -1,11 +1,30 @@ #include #include +#include void fat32_init(void); int main(void) { struct fat32_directory_entry dentry; + int i; + uint32_t offset = 0; + uint32_t cluster; fat32_init(); + + /* This is what is going to be part of open */ fat32_get_cluster_by_name("TEST TXT", &dentry); + cprintf("attr1: %x\n", dentry.attr1); + cprintf("cluster: %x%x\n", dentry.cluster_high, dentry.cluster_low); + cprintf("File Size: %lx\n", dentry.file_size); + + + /* This will become part of read */ + cluster = (dentry.cluster_high << 16) | dentry.cluster_low; + fat32_read_cluster(cluster + offset/512, sd_buf); + + for (i = 0; i < dentry.file_size; i++) { + cprintf("%c", sd_buf[i]); + } + return 0; } \ No newline at end of file From 9ae15939573d3aabf5bbaf5b103fdd9da01d66a3 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Tue, 5 Dec 2023 08:29:44 -0800 Subject: [PATCH 09/17] Read out very long file, but not very long name --- sw/fsdir/verylargetextwithverylongname.txt | 33 ++++++++++++++++++++++ sw/kernel/filesystems/fat32.h | 1 + sw/kernel/filesystems/fat32_c.c | 13 +++++++++ sw/test_code/fs_test/main.c | 15 ++++++++-- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 sw/fsdir/verylargetextwithverylongname.txt diff --git a/sw/fsdir/verylargetextwithverylongname.txt b/sw/fsdir/verylargetextwithverylongname.txt new file mode 100644 index 0000000..a5e31d9 --- /dev/null +++ b/sw/fsdir/verylargetextwithverylongname.txt @@ -0,0 +1,33 @@ +very large text file with a very long name +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ +ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ +abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz +~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>?~!@#$%^&*()_+`1234567890-=[]\{}|;':",./<>? diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index fdaf57e..2a02f8a 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -41,5 +41,6 @@ struct lfn_entry { int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry); int8_t fat32_read_cluster(uint32_t cluster, void* buf); +uint32_t fat32_next_cluster(uint32_t cluster); #endif diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 91f8b5e..438377a 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -12,10 +12,23 @@ int8_t fat32_read_cluster(uint32_t cluster, void* buf) { return error; } +uint32_t fat32_next_cluster(uint32_t cluster) { + uint8_t error; + uint32_t addr = fat_start_sector; + uint32_t cluster_val; + SD_readSingleBlock(addr, sd_buf, &error); + cluster_val = ((uint32_t*)sd_buf)[cluster]; + return cluster_val; +} + int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry) { struct fat32_directory_entry* local_entry; int i = 0; + uint32_t cluster; + + cluster = fat32_next_cluster(root_cluster); + cprintf("Sectors per cluster: %hhx\n", sectors_per_cluster); fat32_read_cluster(root_cluster, sd_buf); diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 2067d4b..2245139 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -9,10 +9,11 @@ int main(void) { int i; uint32_t offset = 0; uint32_t cluster; + uint8_t cluster_count; fat32_init(); /* This is what is going to be part of open */ - fat32_get_cluster_by_name("TEST TXT", &dentry); + fat32_get_cluster_by_name("VERYLA~1TXT", &dentry); cprintf("attr1: %x\n", dentry.attr1); cprintf("cluster: %x%x\n", dentry.cluster_high, dentry.cluster_low); cprintf("File Size: %lx\n", dentry.file_size); @@ -20,10 +21,18 @@ int main(void) { /* This will become part of read */ cluster = (dentry.cluster_high << 16) | dentry.cluster_low; + cluster++; fat32_read_cluster(cluster + offset/512, sd_buf); - for (i = 0; i < dentry.file_size; i++) { - cprintf("%c", sd_buf[i]); + cluster_count = (dentry.file_size/512)/sectors_per_cluster; + cprintf("Cluster count: %x\n", cluster_count); + + while (cluster < 0xffffff0) { + for (i = 0; i < dentry.file_size && i < 512; i++) { + cprintf("%c", sd_buf[i]); + } + cluster = fat32_next_cluster(cluster); + fat32_read_cluster(cluster + offset/512, sd_buf); } return 0; From 48b39eb92d3da4c462f4e88529fe41c436ab864d Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Tue, 5 Dec 2023 18:04:08 -0800 Subject: [PATCH 10/17] Hack together open() --- sw/kernel/filesystems/fat32.h | 4 +++ sw/kernel/filesystems/fat32_c.c | 61 +++++++++++++++++++++++++++++++-- sw/kernel/filesystems/fs.h | 6 ++-- sw/kernel/process/process.c | 6 ++++ sw/kernel/process/process.h | 46 +++++++++++++++++++++++++ sw/test_code/fs_test/harness.c | 8 +++++ sw/test_code/fs_test/main.c | 30 ++-------------- 7 files changed, 130 insertions(+), 31 deletions(-) create mode 100644 sw/kernel/process/process.c create mode 100644 sw/kernel/process/process.h diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index 2a02f8a..d4fd80d 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -43,4 +43,8 @@ int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentr int8_t fat32_read_cluster(uint32_t cluster, void* buf); uint32_t fat32_next_cluster(uint32_t cluster); +int8_t fat32_file_open(const int8_t* filename); +int8_t fat32_file_read(int8_t fd, const void* buf, int8_t nbytes); +int8_t fat32_file_write(int8_t fd, const void* buf, int8_t nbytes); +int8_t fat32_file_close(int8_t fd); #endif diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 438377a..43769cc 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -1,10 +1,67 @@ -#include "fat32.h" - #include +#include #include #include #include +#include "fat32.h" +#include "fs.h" + +static struct fops fat32_file_ops = {fat32_file_open, fat32_file_close, fat32_file_read, fat32_file_write}; + +int8_t fd_val; + + +//TODO +int8_t fat32_file_write(int8_t fd, const void* buf, int8_t nbytes) { + return -1; +} + +int8_t fat32_file_close(int8_t fd) { + return -1; +} + +int8_t fat32_file_open(const int8_t* filename) { + int8_t ret; + int8_t i; + int8_t fd; + + struct fat32_directory_entry dentry; + + struct pcb* pcb = get_pcb_ptr(); + + ret = fat32_get_cluster_by_name(filename, &dentry); + if (ret) { + cprintf("Error finding cluster for filename"); + return -1; + } + + /* try to find an empty file desciptor, fail otherwise */ + //TODO We start at 3 here because 0, 1, 2 will be reserved later + for (i = 3; i < FILE_DESC_SIZE; i++) { + if (pcb->file_desc_array[i].flags == !IN_USE) { + fd = i; + break; + } + } + if (fd == -1){ + return -1; + } + + /* add process */ + pcb->file_desc_array[fd].f32_dentry = dentry; + pcb->file_desc_array[fd].flags = IN_USE; + pcb->file_desc_array[fd].file_pos = 0; + + pcb->file_desc_array[fd].file_ops = &fat32_file_ops; + + return fd; +} + +int8_t fat32_file_read(int8_t fd, const void* buf, int8_t nbytes) { + struct pcb* pcb = get_pcb_ptr(); +} + int8_t fat32_read_cluster(uint32_t cluster, void* buf) { uint8_t error; uint32_t addr = (cluster - 2) + data_start_sector; diff --git a/sw/kernel/filesystems/fs.h b/sw/kernel/filesystems/fs.h index b1e738b..c457ecc 100644 --- a/sw/kernel/filesystems/fs.h +++ b/sw/kernel/filesystems/fs.h @@ -3,16 +3,18 @@ #include +#include + /* syscalls for files */ int8_t file_read(int8_t fd, void* buf, int8_t nbytes); int8_t file_write(int8_t fd, const void* buf, int8_t nbytes); -int8_t file_open(const uint8_t* filename); +int8_t file_open(const int8_t* filename); int8_t file_close(int8_t fd); /* syscalls for directories */ int8_t directory_read(int8_t fd, void* buf, int8_t nbytes); int8_t directory_write(int8_t fd, const void* buf, int8_t nbytes); -int8_t directory_open(const uint8_t* filename); +int8_t directory_open(const int8_t* filename); int8_t directory_close(int8_t fd); diff --git a/sw/kernel/process/process.c b/sw/kernel/process/process.c new file mode 100644 index 0000000..489b371 --- /dev/null +++ b/sw/kernel/process/process.c @@ -0,0 +1,6 @@ +#include + + +struct pcb* get_pcb_ptr() { + return 0; +} \ No newline at end of file diff --git a/sw/kernel/process/process.h b/sw/kernel/process/process.h new file mode 100644 index 0000000..f624a3d --- /dev/null +++ b/sw/kernel/process/process.h @@ -0,0 +1,46 @@ +#ifndef _PROCESS_H +#define _PROCESS_H + +#include + +#include + +#define FILE_DESC_SIZE 8 + + +#define IN_USE 1 + + +struct fops { + int8_t (*open)(const int8_t* filename); + int8_t (*close)(int8_t fd); + int8_t (*read)(int8_t fd, void* buf, int8_t nbytes); + int8_t (*write)(int8_t fd, const void* buf, int8_t nbytes); +}; + +struct file_desc { + struct fops* file_ops; + uint8_t fs_type; + union { + struct fat32_directory_entry f32_dentry; + }; + uint32_t file_pos; + uint32_t flags; +}; + +/* Process Control Block struct */ +struct pcb { + struct file_desc file_desc_array[FILE_DESC_SIZE]; + int32_t is_vidmapped; + uint8_t args[128]; + uint32_t execute_return; + int32_t pid; + int32_t parent_pid; + uint32_t parent_esp; + uint32_t parent_ebp; +}; + + +struct pcb* get_pcb_ptr(); + +#endif \ No newline at end of file diff --git a/sw/test_code/fs_test/harness.c b/sw/test_code/fs_test/harness.c index cd72522..d11e150 100644 --- a/sw/test_code/fs_test/harness.c +++ b/sw/test_code/fs_test/harness.c @@ -1,9 +1,17 @@ #include #include #include +#include #define FILE_PATH "fs.fat" +struct pcb fake_pcb; + +//TODO +struct pcb* get_pcb_ptr() { + return &fake_pcb; +} + uint32_t lmulii(uint16_t a, uint16_t b) { printf("lmulii: %x * %x = %x\n", a, b, a*b); return a * b; diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 2245139..014cc8f 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -5,35 +5,11 @@ void fat32_init(void); int main(void) { - struct fat32_directory_entry dentry; - int i; - uint32_t offset = 0; - uint32_t cluster; - uint8_t cluster_count; + int8_t fd; fat32_init(); /* This is what is going to be part of open */ - fat32_get_cluster_by_name("VERYLA~1TXT", &dentry); - cprintf("attr1: %x\n", dentry.attr1); - cprintf("cluster: %x%x\n", dentry.cluster_high, dentry.cluster_low); - cprintf("File Size: %lx\n", dentry.file_size); + fd = fat32_file_open("VERYLA~1TXT"); - - /* This will become part of read */ - cluster = (dentry.cluster_high << 16) | dentry.cluster_low; - cluster++; - fat32_read_cluster(cluster + offset/512, sd_buf); - - cluster_count = (dentry.file_size/512)/sectors_per_cluster; - cprintf("Cluster count: %x\n", cluster_count); - - while (cluster < 0xffffff0) { - for (i = 0; i < dentry.file_size && i < 512; i++) { - cprintf("%c", sd_buf[i]); - } - cluster = fat32_next_cluster(cluster); - fat32_read_cluster(cluster + offset/512, sd_buf); - } - - return 0; + cprintf("fd: %x\n", fd); } \ No newline at end of file From 4c3c3fd7312dd4f3c665f33e642ecb5250bd57d9 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Tue, 5 Dec 2023 22:47:24 -0800 Subject: [PATCH 11/17] Get something working with read It is not reading offset correctly --- sw/kernel/filesystems/fat32.h | 10 +++++---- sw/kernel/filesystems/fat32_c.c | 40 ++++++++++++++++++++++++++++----- sw/kernel/filesystems/fs.h | 13 ++++++----- sw/kernel/process/process.h | 7 +++--- sw/test_code/fs_test/main.c | 10 ++++++++- 5 files changed, 61 insertions(+), 19 deletions(-) diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index d4fd80d..7c3e8af 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -2,6 +2,7 @@ #define _FAT32_H #include +#include void fat32_init(); @@ -39,12 +40,13 @@ struct lfn_entry { uint16_t name_2[2]; }; -int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry); +int8_t fat32_get_cluster_by_name(const char* name, struct fat32_directory_entry* dentry); int8_t fat32_read_cluster(uint32_t cluster, void* buf); uint32_t fat32_next_cluster(uint32_t cluster); -int8_t fat32_file_open(const int8_t* filename); -int8_t fat32_file_read(int8_t fd, const void* buf, int8_t nbytes); -int8_t fat32_file_write(int8_t fd, const void* buf, int8_t nbytes); +int8_t fat32_file_open(const char* filename); +int8_t fat32_file_read(int8_t fd, void* buf, size_t nbytes); +int8_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes); int8_t fat32_file_close(int8_t fd); + #endif diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 43769cc..f99dc7e 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -13,15 +13,19 @@ int8_t fd_val; //TODO -int8_t fat32_file_write(int8_t fd, const void* buf, int8_t nbytes) { +int8_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes) { + (void)fd; + (void)buf; + (void)nbytes; return -1; } int8_t fat32_file_close(int8_t fd) { + (void)fd; return -1; } -int8_t fat32_file_open(const int8_t* filename) { +int8_t fat32_file_open(const char* filename) { int8_t ret; int8_t i; int8_t fd; @@ -58,8 +62,33 @@ int8_t fat32_file_open(const int8_t* filename) { return fd; } -int8_t fat32_file_read(int8_t fd, const void* buf, int8_t nbytes) { +int8_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { + uint16_t i; + uint8_t error; + size_t offset; struct pcb* pcb = get_pcb_ptr(); + struct file_desc* fdesc = &pcb->file_desc_array[fd]; + uint32_t cluster_seq = fdesc->file_pos >> 9; + uint32_t cluster = ((uint32_t)fdesc->f32_dentry.cluster_high << 16) | fdesc->f32_dentry.cluster_low; + + /* validate starting position isn't past end of file */ + if (fdesc->file_pos >= fdesc->f32_dentry.file_size){ + return 0; + } + /* validate final pos isn't past end of file */ + if (fdesc->file_pos+nbytes > fdesc->f32_dentry.file_size){ + nbytes = fdesc->f32_dentry.file_size - fdesc->file_pos; + } + + + for (i = 0; i < cluster_seq; i++) { + cluster = fat32_next_cluster(cluster); + } + + fat32_read_cluster(cluster, sd_buf); + memcpy(buf, sd_buf, nbytes); + fdesc->file_pos += nbytes; + return error; } int8_t fat32_read_cluster(uint32_t cluster, void* buf) { @@ -69,6 +98,7 @@ int8_t fat32_read_cluster(uint32_t cluster, void* buf) { return error; } +// This will not handle clusters numbers that leaves a sector uint32_t fat32_next_cluster(uint32_t cluster) { uint8_t error; uint32_t addr = fat_start_sector; @@ -78,7 +108,7 @@ uint32_t fat32_next_cluster(uint32_t cluster) { return cluster_val; } -int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentry) { +int8_t fat32_get_cluster_by_name(const char* name, struct fat32_directory_entry* dentry) { struct fat32_directory_entry* local_entry; int i = 0; @@ -90,7 +120,7 @@ int8_t fat32_get_cluster_by_name(char* name, struct fat32_directory_entry* dentr fat32_read_cluster(root_cluster, sd_buf); for (i = 0; i < 16; i++){ - local_entry = sd_buf + i*32; + local_entry = (struct fat32_directory_entry*)(sd_buf + i*32); if (local_entry->attr1 == 0xf || local_entry->attr1 & 0x8 || !local_entry->attr1) { continue; } diff --git a/sw/kernel/filesystems/fs.h b/sw/kernel/filesystems/fs.h index c457ecc..b9834eb 100644 --- a/sw/kernel/filesystems/fs.h +++ b/sw/kernel/filesystems/fs.h @@ -2,19 +2,20 @@ #define _FS_H #include +#include #include /* syscalls for files */ -int8_t file_read(int8_t fd, void* buf, int8_t nbytes); -int8_t file_write(int8_t fd, const void* buf, int8_t nbytes); -int8_t file_open(const int8_t* filename); +int8_t file_read(int8_t fd, void* buf, size_t nbytes); +int8_t file_write(int8_t fd, const void* buf, size_t nbytes); +int8_t file_open(const char* filename); int8_t file_close(int8_t fd); /* syscalls for directories */ -int8_t directory_read(int8_t fd, void* buf, int8_t nbytes); -int8_t directory_write(int8_t fd, const void* buf, int8_t nbytes); -int8_t directory_open(const int8_t* filename); +int8_t directory_read(int8_t fd, void* buf, size_t nbytes); +int8_t directory_write(int8_t fd, const void* buf, size_t nbytes); +int8_t directory_open(const char* filename); int8_t directory_close(int8_t fd); diff --git a/sw/kernel/process/process.h b/sw/kernel/process/process.h index f624a3d..2627886 100644 --- a/sw/kernel/process/process.h +++ b/sw/kernel/process/process.h @@ -4,6 +4,7 @@ #include #include +#include #define FILE_DESC_SIZE 8 @@ -12,10 +13,10 @@ struct fops { - int8_t (*open)(const int8_t* filename); + int8_t (*open)(const char* filename); int8_t (*close)(int8_t fd); - int8_t (*read)(int8_t fd, void* buf, int8_t nbytes); - int8_t (*write)(int8_t fd, const void* buf, int8_t nbytes); + int8_t (*read)(int8_t fd, void* buf, size_t nbytes); + int8_t (*write)(int8_t fd, const void* buf, size_t nbytes); }; struct file_desc { diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 014cc8f..9e8ac87 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -4,12 +4,20 @@ void fat32_init(void); +char data [256]; + int main(void) { int8_t fd; + size_t i; fat32_init(); /* This is what is going to be part of open */ fd = fat32_file_open("VERYLA~1TXT"); - cprintf("fd: %x\n", fd); + + while (fat32_file_read(fd, data, 256)){ + for (i = 0; i < 256; i++) { + cprintf("%c", data[i]); + } + } } \ No newline at end of file From 066bb0ee8c49674f152826a9b452c7b7d94fbe00 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Tue, 5 Dec 2023 23:29:00 -0800 Subject: [PATCH 12/17] Get read working a little bit more. Need to handle edge cases! --- sw/kernel/filesystems/fat32.h | 4 ++-- sw/kernel/filesystems/fat32_c.c | 14 ++++++++++---- sw/kernel/filesystems/fs.h | 8 ++++---- sw/kernel/process/process.h | 4 ++-- sw/test_code/fs_test/main.c | 5 +++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index 7c3e8af..50b508d 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -45,8 +45,8 @@ int8_t fat32_read_cluster(uint32_t cluster, void* buf); uint32_t fat32_next_cluster(uint32_t cluster); int8_t fat32_file_open(const char* filename); -int8_t fat32_file_read(int8_t fd, void* buf, size_t nbytes); -int8_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes); +size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes); +size_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes); int8_t fat32_file_close(int8_t fd); #endif diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index f99dc7e..d5334d1 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -13,7 +13,7 @@ int8_t fd_val; //TODO -int8_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes) { +size_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes) { (void)fd; (void)buf; (void)nbytes; @@ -62,7 +62,7 @@ int8_t fat32_file_open(const char* filename) { return fd; } -int8_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { +size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { uint16_t i; uint8_t error; size_t offset; @@ -84,11 +84,17 @@ int8_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { for (i = 0; i < cluster_seq; i++) { cluster = fat32_next_cluster(cluster); } + + offset = fdesc->file_pos % 512; + + if (offset + nbytes > 512) { + cprintf("Need to do something about this!\n"); + } fat32_read_cluster(cluster, sd_buf); - memcpy(buf, sd_buf, nbytes); + memcpy(buf, sd_buf + offset, nbytes); fdesc->file_pos += nbytes; - return error; + return nbytes; } int8_t fat32_read_cluster(uint32_t cluster, void* buf) { diff --git a/sw/kernel/filesystems/fs.h b/sw/kernel/filesystems/fs.h index b9834eb..29b7cc1 100644 --- a/sw/kernel/filesystems/fs.h +++ b/sw/kernel/filesystems/fs.h @@ -7,14 +7,14 @@ #include /* syscalls for files */ -int8_t file_read(int8_t fd, void* buf, size_t nbytes); -int8_t file_write(int8_t fd, const void* buf, size_t nbytes); +size_t file_read(int8_t fd, void* buf, size_t nbytes); +size_t file_write(int8_t fd, const void* buf, size_t nbytes); int8_t file_open(const char* filename); int8_t file_close(int8_t fd); /* syscalls for directories */ -int8_t directory_read(int8_t fd, void* buf, size_t nbytes); -int8_t directory_write(int8_t fd, const void* buf, size_t nbytes); +size_t directory_read(int8_t fd, void* buf, size_t nbytes); +size_t directory_write(int8_t fd, const void* buf, size_t nbytes); int8_t directory_open(const char* filename); int8_t directory_close(int8_t fd); diff --git a/sw/kernel/process/process.h b/sw/kernel/process/process.h index 2627886..ad177ff 100644 --- a/sw/kernel/process/process.h +++ b/sw/kernel/process/process.h @@ -15,8 +15,8 @@ struct fops { int8_t (*open)(const char* filename); int8_t (*close)(int8_t fd); - int8_t (*read)(int8_t fd, void* buf, size_t nbytes); - int8_t (*write)(int8_t fd, const void* buf, size_t nbytes); + size_t (*read)(int8_t fd, void* buf, size_t nbytes); + size_t (*write)(int8_t fd, const void* buf, size_t nbytes); }; struct file_desc { diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 9e8ac87..71b9da9 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -9,14 +9,15 @@ char data [256]; int main(void) { int8_t fd; size_t i; + size_t nbytes; fat32_init(); /* This is what is going to be part of open */ fd = fat32_file_open("VERYLA~1TXT"); cprintf("fd: %x\n", fd); - while (fat32_file_read(fd, data, 256)){ - for (i = 0; i < 256; i++) { + while ((nbytes = fat32_file_read(fd, data, 256))){ + for (i = 0; i < nbytes; i++) { cprintf("%c", data[i]); } } From 0327ab6a2b3e8382ee5b738d50f8ccf77185d1f7 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Wed, 6 Dec 2023 21:02:41 -0800 Subject: [PATCH 13/17] Handle non-aligned reads --- sw/kernel/filesystems/fat32_c.c | 57 ++++++++++++++++++++++++++++----- sw/test_code/fs_test/main.c | 5 +++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index d5334d1..6518553 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -66,6 +66,9 @@ size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { uint16_t i; uint8_t error; size_t offset; + size_t leftover_length; + size_t bytes_read = 0; + size_t clusters; struct pcb* pcb = get_pcb_ptr(); struct file_desc* fdesc = &pcb->file_desc_array[fd]; uint32_t cluster_seq = fdesc->file_pos >> 9; @@ -85,16 +88,54 @@ size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { cluster = fat32_next_cluster(cluster); } - offset = fdesc->file_pos % 512; + // This is an upper bound. It is possible that a 512 chunk can span + // 2 clusters, but the first one will already be handled. + clusters = nbytes >> 9; - if (offset + nbytes > 512) { - cprintf("Need to do something about this!\n"); + + /* Handle first unaligned block */ + offset = fdesc->file_pos % 512; + leftover_length = 512 - offset; + + if (leftover_length != 0) { + if (nbytes <= leftover_length) { + fat32_read_cluster(cluster, sd_buf); + memcpy(buf, sd_buf + offset, nbytes); + bytes_read += nbytes; + fdesc->file_pos += bytes_read; + return bytes_read; + } else { + fat32_read_cluster(cluster, sd_buf); + memcpy(buf, sd_buf + offset, leftover_length); + bytes_read += leftover_length; + fdesc->file_pos += bytes_read; + } } - - fat32_read_cluster(cluster, sd_buf); - memcpy(buf, sd_buf + offset, nbytes); - fdesc->file_pos += nbytes; - return nbytes; + + + /* Handle middle aligned blocks */ + for (i = 0; i < clusters; i++) { + cluster = fat32_next_cluster(cluster); + if (cluster >= 0xffffff00) { + // cprintf("Last cluster in file!\n"); + } + + if (nbytes - bytes_read > 512) { + leftover_length = 512; + } else { + leftover_length = nbytes - bytes_read; + } + + fat32_read_cluster(cluster, sd_buf); + memcpy((uint8_t*)buf+bytes_read, sd_buf, leftover_length); + bytes_read += leftover_length; + fdesc->file_pos += bytes_read; + if (bytes_read == nbytes) { + return bytes_read; + } + } + + return bytes_read; } int8_t fat32_read_cluster(uint32_t cluster, void* buf) { diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 71b9da9..974fa85 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -16,6 +16,11 @@ int main(void) { fd = fat32_file_open("VERYLA~1TXT"); cprintf("fd: %x\n", fd); + nbytes = fat32_file_read(fd, data, 123); + for (i = 0; i < nbytes; i++) { + cprintf("%c", data[i]); + } + while ((nbytes = fat32_file_read(fd, data, 256))){ for (i = 0; i < nbytes; i++) { cprintf("%c", data[i]); From 6f16ac4daf10464d3e894c3af51e5e10086766ad Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Thu, 7 Dec 2023 08:10:45 -0800 Subject: [PATCH 14/17] Add close, add filesystem code to main kernel for hardware testing --- sw/kernel/filesystems/fat32_c.c | 17 ++++++++++++++--- sw/kernel/kernel.c | 23 ++++++++++++++--------- sw/kernel/process/process.h | 9 ++++----- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 6518553..433b6a6 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -20,9 +20,21 @@ size_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes) { return -1; } +/* + * file_close + * DESCRIPTION: close device abstracted as file + * INPUTS: fd -- file descriptor for file to be closed + * OUTPUTS: none + * RETURN VALUE: none + * SIDE EFFECTS: none + */ int8_t fat32_file_close(int8_t fd) { - (void)fd; - return -1; + struct pcb* pcb; + pcb = get_pcb_ptr(); + + /* update pcb to remove process */ + pcb->file_desc_array[fd].flags = !IN_USE; + return 0; } int8_t fat32_file_open(const char* filename) { @@ -64,7 +76,6 @@ int8_t fat32_file_open(const char* filename) { size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { uint16_t i; - uint8_t error; size_t offset; size_t leftover_length; size_t bytes_read = 0; diff --git a/sw/kernel/kernel.c b/sw/kernel/kernel.c index b9e56e0..d96edf4 100644 --- a/sw/kernel/kernel.c +++ b/sw/kernel/kernel.c @@ -21,6 +21,9 @@ void handle_rtc_interrupt() { char buf[128]; int main() { + int8_t fd; + size_t nbytes, i; + cputs("Kernel\n"); cputs("Init Mapper\n"); @@ -49,17 +52,19 @@ int main() { fat32_init(); - terminal_open(NULL); - terminal_write(0, "Terminal Write\n", 15); + /* This is what is going to be part of open */ + fd = fat32_file_open("VERYLA~1TXT"); + cprintf("fd: %x\n", fd); - while(1) { - if (terminal_read(0, buf, 128)) { - cprintf("Fail\n"); - break; + nbytes = fat32_file_read(fd, buf, 23); + for (i = 0; i < nbytes; i++) { + cprintf("%c", buf[i]); + } + + while ((nbytes = fat32_file_read(fd, buf, 128))){ + for (i = 0; i < nbytes; i++) { + cprintf("%c", buf[i]); } - terminal_write(0, "Got: ", 5); - terminal_write(0, buf, strlen(buf)); - terminal_write(0, "\n", 1); } return 0; diff --git a/sw/kernel/process/process.h b/sw/kernel/process/process.h index ad177ff..2a569df 100644 --- a/sw/kernel/process/process.h +++ b/sw/kernel/process/process.h @@ -34,11 +34,10 @@ struct pcb { struct file_desc file_desc_array[FILE_DESC_SIZE]; int32_t is_vidmapped; uint8_t args[128]; - uint32_t execute_return; - int32_t pid; - int32_t parent_pid; - uint32_t parent_esp; - uint32_t parent_ebp; + uint16_t execute_return; + uint16_t pid; + uint16_t parent_pid; + uint16_t parent_esp; }; From 15e9b443180b4f9f5b712aa8831add69ab6b09a2 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Thu, 7 Dec 2023 23:29:18 -0800 Subject: [PATCH 15/17] Try clearing carry flag, that always helps. Also don't need verilog image anymore --- sw/kernel/filesystems/fat32.s | 1 + sw/script/create_verilog_image.sh | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index c30f2e5..b286dc8 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -85,6 +85,7 @@ L1: lda root_cluster_offs,x ; Add fat size to starting fat sector to get data start sector + cli lda _fat_size adc _fat_start_sector sta _data_start_sector diff --git a/sw/script/create_verilog_image.sh b/sw/script/create_verilog_image.sh index 51249fd..a4dfe2c 100644 --- a/sw/script/create_verilog_image.sh +++ b/sw/script/create_verilog_image.sh @@ -35,6 +35,4 @@ udisksctl unmount -b $LOOP udisksctl loop-delete -b $LOOP -echo "$(tput bold setaf 11)Converting Image to Verilog$(tput sgr 0)" -objcopy --input-target=binary --output-target=verilog --verilog-data-width=1 $FILE $FILE.hex echo "$(tput bold setaf 10)Done!$(tput sgr 0)" From 5259fa8e6536fef08e0368248d7b4ddee5fb17d8 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Fri, 8 Dec 2023 08:12:50 -0800 Subject: [PATCH 16/17] Clear the carry flag, not the interrupt flag... --- sw/kernel/filesystems/fat32.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index b286dc8..9b62b85 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -85,7 +85,7 @@ L1: lda root_cluster_offs,x ; Add fat size to starting fat sector to get data start sector - cli + clc lda _fat_size adc _fat_start_sector sta _data_start_sector From 0aca4af272754a06527ff6e5c794f973140dd46c Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Fri, 8 Dec 2023 23:11:52 -0800 Subject: [PATCH 17/17] Add fixes for multiple sectors per cluster --- sw/kernel/filesystems/fat32.h | 3 ++- sw/kernel/filesystems/fat32.s | 13 ++++++++++++- sw/kernel/filesystems/fat32_c.c | 30 +++++++++++++++++++----------- sw/kernel/process/process.c | 5 ++++- sw/test_code/fs_test/main.c | 2 ++ 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/sw/kernel/filesystems/fat32.h b/sw/kernel/filesystems/fat32.h index 50b508d..e9c97ad 100644 --- a/sw/kernel/filesystems/fat32.h +++ b/sw/kernel/filesystems/fat32.h @@ -12,6 +12,7 @@ extern uint32_t data_start_sector; extern uint32_t fat_size; extern uint8_t* sd_buf; extern uint8_t sectors_per_cluster; +extern uint8_t log2_sectors_per_cluster; struct fat32_directory_entry { char file_name[8]; @@ -41,7 +42,7 @@ struct lfn_entry { }; int8_t fat32_get_cluster_by_name(const char* name, struct fat32_directory_entry* dentry); -int8_t fat32_read_cluster(uint32_t cluster, void* buf); +int8_t fat32_read_sector(uint32_t cluster, uint32_t sector, void* buf); uint32_t fat32_next_cluster(uint32_t cluster); int8_t fat32_file_open(const char* filename); diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 9b62b85..6e6346f 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -10,7 +10,7 @@ .export _fat32_init .export _root_cluster, _fat_start_sector, _data_start_sector -.export _fat_size, _sd_buf, _sectors_per_cluster +.export _fat_size, _sd_buf, _sectors_per_cluster, _log2_sectors_per_cluster .data @@ -19,6 +19,7 @@ _fat_start_sector: .res 2 _data_start_sector: .res 4 _fat_size: .res 4 _sectors_per_cluster: .res 1 +_log2_sectors_per_cluster: .res 1 _sd_buf: .res 512 @@ -52,6 +53,16 @@ root_cluster_offs = _sd_buf + $2C lda sectors_per_cluster sta _sectors_per_cluster + ldx #$0 +@1: bit #$01 + bne L0 + inx + lsr + bra @1 + +L0: txa + sta _log2_sectors_per_cluster + ldx #$00 L1: lda root_cluster_offs,x sta _root_cluster,x diff --git a/sw/kernel/filesystems/fat32_c.c b/sw/kernel/filesystems/fat32_c.c index 433b6a6..a391212 100644 --- a/sw/kernel/filesystems/fat32_c.c +++ b/sw/kernel/filesystems/fat32_c.c @@ -80,9 +80,12 @@ size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { size_t leftover_length; size_t bytes_read = 0; size_t clusters; + uint32_t sector; struct pcb* pcb = get_pcb_ptr(); struct file_desc* fdesc = &pcb->file_desc_array[fd]; - uint32_t cluster_seq = fdesc->file_pos >> 9; + + uint32_t cluster_seq = fdesc->file_pos >> (9 + log2_sectors_per_cluster); + uint32_t cluster = ((uint32_t)fdesc->f32_dentry.cluster_high << 16) | fdesc->f32_dentry.cluster_low; /* validate starting position isn't past end of file */ @@ -95,28 +98,30 @@ size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { } + // This can stay for now, as long as cluster_seq is correct. for (i = 0; i < cluster_seq; i++) { cluster = fat32_next_cluster(cluster); } - // This is an upper bound. It is possible that a 512 chunk can span - // 2 clusters, but the first one will already be handled. - clusters = nbytes >> 9; + clusters = nbytes >> (9 + log2_sectors_per_cluster); /* Handle first unaligned block */ - offset = fdesc->file_pos % 512; + offset = fdesc->file_pos % 512; // This is the offset into the sector, not the cluster leftover_length = 512 - offset; + sector = (fdesc->file_pos >> 9) & (sectors_per_cluster-1); + if (leftover_length != 0) { if (nbytes <= leftover_length) { - fat32_read_cluster(cluster, sd_buf); + + fat32_read_sector(cluster, sector, sd_buf); memcpy(buf, sd_buf + offset, nbytes); bytes_read += nbytes; fdesc->file_pos += bytes_read; return bytes_read; } else { - fat32_read_cluster(cluster, sd_buf); + fat32_read_sector(cluster, sector, sd_buf); memcpy(buf, sd_buf + offset, leftover_length); bytes_read += leftover_length; fdesc->file_pos += bytes_read; @@ -137,7 +142,7 @@ size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { leftover_length = nbytes - bytes_read; } - fat32_read_cluster(cluster, sd_buf); + fat32_read_sector(cluster, cluster, sd_buf); memcpy((uint8_t*)buf+bytes_read, sd_buf, leftover_length); bytes_read += leftover_length; fdesc->file_pos += bytes_read; @@ -149,9 +154,12 @@ size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { return bytes_read; } -int8_t fat32_read_cluster(uint32_t cluster, void* buf) { +// Read the sector offset from a given cluster into buf +// Why do we need this though, this is just doing a single multiplication? +// No, it is also doing an addition +int8_t fat32_read_sector(uint32_t cluster, uint32_t sector, void* buf) { uint8_t error; - uint32_t addr = (cluster - 2) + data_start_sector; + uint32_t addr = (cluster - 2) * sectors_per_cluster + sector + data_start_sector; SD_readSingleBlock(addr, buf, &error); return error; } @@ -176,7 +184,7 @@ int8_t fat32_get_cluster_by_name(const char* name, struct fat32_directory_entry* cprintf("Sectors per cluster: %hhx\n", sectors_per_cluster); - fat32_read_cluster(root_cluster, sd_buf); + fat32_read_sector(root_cluster, 0, sd_buf); for (i = 0; i < 16; i++){ local_entry = (struct fat32_directory_entry*)(sd_buf + i*32); if (local_entry->attr1 == 0xf || local_entry->attr1 & 0x8 || !local_entry->attr1) { diff --git a/sw/kernel/process/process.c b/sw/kernel/process/process.c index 489b371..cbc5210 100644 --- a/sw/kernel/process/process.c +++ b/sw/kernel/process/process.c @@ -1,6 +1,9 @@ #include +struct pcb fake_pcb; + +//TODO struct pcb* get_pcb_ptr() { - return 0; + return &fake_pcb; } \ No newline at end of file diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 974fa85..62042cf 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -12,6 +12,8 @@ int main(void) { size_t nbytes; fat32_init(); + cprintf("log2 sectors per cluster: %x\n", log2_sectors_per_cluster); + /* This is what is going to be part of open */ fd = fat32_file_open("VERYLA~1TXT"); cprintf("fd: %x\n", fd);