diff --git a/.DS_Store b/.DS_Store index 5008ddf..9f4315b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/brewos.iso b/brewos.iso index 8654b31..79f39b4 100644 Binary files a/brewos.iso and b/brewos.iso differ diff --git a/build/brewos.elf b/build/brewos.elf index 257bd0d..c33e912 100755 Binary files a/build/brewos.elf and b/build/brewos.elf differ diff --git a/build/cli_apps/cc.o b/build/cli_apps/cc.o index 4d79d89..3f0d347 100644 Binary files a/build/cli_apps/cc.o and b/build/cli_apps/cc.o differ diff --git a/build/cmd.o b/build/cmd.o index b93ccad..ae4a6d9 100644 Binary files a/build/cmd.o and b/build/cmd.o differ diff --git a/build/fat32.o b/build/fat32.o index 3903abd..9b608cc 100644 Binary files a/build/fat32.o and b/build/fat32.o differ diff --git a/iso_root/brewos.elf b/iso_root/brewos.elf index 257bd0d..c33e912 100755 Binary files a/iso_root/brewos.elf and b/iso_root/brewos.elf differ diff --git a/src/kernel/cli_apps/cc.c b/src/kernel/cli_apps/cc.c index 3106fbf..2cbcf31 100644 --- a/src/kernel/cli_apps/cc.c +++ b/src/kernel/cli_apps/cc.c @@ -6,11 +6,11 @@ #include "../cmd.h" // --- Compiler Limits --- -#define MAX_SOURCE 8192 -#define MAX_TOKENS 2048 -#define MAX_VARS 64 -#define CODE_SIZE 4096 -#define STR_POOL_SIZE 2048 +#define MAX_SOURCE 65536 +#define MAX_TOKENS 16384 +#define MAX_VARS 512 +#define CODE_SIZE 32768 +#define STR_POOL_SIZE 16384 static int compile_error = 0; @@ -312,7 +312,7 @@ typedef struct { static Symbol symbols[MAX_VARS]; static int symbol_count = 0; -static int next_var_addr = 4096; +static int next_var_addr = 32768; static int find_symbol(const char *name) { for (int i = 0; i < symbol_count; i++) { @@ -629,19 +629,27 @@ void cli_cmd_cc(char *args) { return; } - char source[MAX_SOURCE]; + char *source = (char*)kmalloc(MAX_SOURCE); + if (!source) { + cmd_write("Error: Out of memory for source buffer.\n"); + fat32_close(fh); + return; + } + int len = fat32_read(fh, source, MAX_SOURCE - 1); source[len] = 0; fat32_close(fh); lexer(source); + kfree(source); + if (compile_error) return; code_pos = 0; symbol_count = 0; cur_token = 0; str_pool_pos = 0; - next_var_addr = 4096; + next_var_addr = 32768; const char* magic = VM_MAGIC; for(int i=0; i<7; i++) emit(magic[i]); diff --git a/src/kernel/cmd.c b/src/kernel/cmd.c index 2f3d543..511fbf3 100644 --- a/src/kernel/cmd.c +++ b/src/kernel/cmd.c @@ -431,9 +431,7 @@ static const CommandEntry commands[] = { {NULL, NULL} }; -// --- Dispatcher --- -// Find pipe operator in command string (||) static const char* find_pipe(const char* cmd) { while (*cmd) { if (*cmd == '|' && *(cmd + 1) == '|') { @@ -444,20 +442,23 @@ static const char* find_pipe(const char* cmd) { return NULL; } -// Execute a single command static void cmd_exec_single(char *cmd) { while (*cmd == ' ') cmd++; if (!*cmd) return; - // Check for file execution ./filename if (cmd[0] == '.' && cmd[1] == '/') { char *filename = cmd + 2; FAT32_FileHandle *fh = fat32_open(filename, "r"); if (fh) { - // It's a file, try to execute it - // Limit executable size to 4KB for now - uint8_t buffer[4096]; - int size = fat32_read(fh, buffer, 4096); + + uint8_t *buffer = (uint8_t*)kmalloc(VM_MEMORY_SIZE); + if (!buffer) { + cmd_write("Error: Out of memory.\n"); + fat32_close(fh); + return; + } + + int size = fat32_read(fh, buffer, VM_MEMORY_SIZE); fat32_close(fh); if (size > 0) { @@ -468,6 +469,7 @@ static void cmd_exec_single(char *cmd) { } else { cmd_write("Error: Empty file.\n"); } + kfree(buffer); } else { cmd_write("Error: Command not found or file does not exist.\n"); } @@ -1022,29 +1024,69 @@ static void create_test_files(void) { fh = fat32_open("Apps/wordofgod.c", "w"); if (fh) { - char *h = "int main(){int l;l=malloc(400);"; + char *h = "int main(){int l;l=malloc(1200);"; fat32_write(fh, h, cmd_strlen(h)); - char *w1 = "poke(l+0,\"In\");poke(l+4,\"the\");poke(l+8,\"beginning\");poke(l+12,\"God\");poke(l+16,\"created\");poke(l+20,\"heaven\");poke(l+24,\"and\");poke(l+28,\"earth\");poke(l+32,\"light\");poke(l+36,\"darkness\");"; + char *w1 = "poke(l+0,\"In \");poke(l+4,\"the \");poke(l+8,\"beginning \");poke(l+12,\"God \");poke(l+16,\"created \");poke(l+20,\"heaven \");poke(l+24,\"and \");poke(l+28,\"earth \");poke(l+32,\"light \");poke(l+36,\"darkness \");"; fat32_write(fh, w1, cmd_strlen(w1)); - char *w2 = "poke(l+40,\"day\");poke(l+44,\"night\");poke(l+48,\"waters\");poke(l+52,\"firmament\");poke(l+56,\"evening\");poke(l+60,\"morning\");poke(l+64,\"land\");poke(l+68,\"seas\");poke(l+72,\"grass\");poke(l+76,\"herb\");"; + char *w2 = "poke(l+40,\"day \");poke(l+44,\"night \");poke(l+48,\"waters \");poke(l+52,\"firmament \");poke(l+56,\"evening \");poke(l+60,\"morning \");poke(l+64,\"land \");poke(l+68,\"seas \");poke(l+72,\"grass \");poke(l+76,\"herb \");"; fat32_write(fh, w2, cmd_strlen(w2)); - char *w3 = "poke(l+80,\"seed\");poke(l+84,\"fruit\");poke(l+88,\"tree\");poke(l+92,\"sun\");poke(l+96,\"moon\");poke(l+100,\"stars\");poke(l+104,\"signs\");poke(l+108,\"seasons\");poke(l+112,\"days\");poke(l+116,\"years\");"; + char *w3 = "poke(l+80,\"seed \");poke(l+84,\"fruit \");poke(l+88,\"tree \");poke(l+92,\"sun \");poke(l+96,\"moon \");poke(l+100,\"stars \");poke(l+104,\"signs \");poke(l+108,\"seasons \");poke(l+112,\"days \");poke(l+116,\"years \");"; fat32_write(fh, w3, cmd_strlen(w3)); - char *w4 = "poke(l+120,\"creature\");poke(l+124,\"life\");poke(l+128,\"fowl\");poke(l+132,\"whales\");poke(l+136,\"cattle\");poke(l+140,\"creeping\");poke(l+144,\"beast\");poke(l+148,\"man\");poke(l+152,\"image\");poke(l+156,\"likeness\");"; + char *w4 = "poke(l+120,\"creature \");poke(l+124,\"life \");poke(l+128,\"fowl \");poke(l+132,\"whales \");poke(l+136,\"cattle \");poke(l+140,\"creeping \");poke(l+144,\"beast \");poke(l+148,\"man \");poke(l+152,\"image \");poke(l+156,\"likeness \");"; fat32_write(fh, w4, cmd_strlen(w4)); - char *w5 = "poke(l+160,\"dominion\");poke(l+164,\"fish\");poke(l+168,\"air\");poke(l+172,\"every\");poke(l+176,\"green\");poke(l+180,\"meat\");poke(l+184,\"holy\");poke(l+188,\"rest\");poke(l+192,\"dust\");poke(l+196,\"breath\");"; + char *w5 = "poke(l+160,\"dominion \");poke(l+164,\"fish \");poke(l+168,\"air \");poke(l+172,\"every \");poke(l+176,\"CIA \");poke(l+180,\"meat \");poke(l+184,\"holy \");poke(l+188,\"rest \");poke(l+192,\"dust \");poke(l+196,\"breath \");"; fat32_write(fh, w5, cmd_strlen(w5)); - char *w6 = "poke(l+200,\"soul\");poke(l+204,\"garden\");poke(l+208,\"east\");poke(l+212,\"Eden\");poke(l+216,\"ground\");poke(l+220,\"sight\");poke(l+224,\"good\");poke(l+228,\"evil\");poke(l+232,\"river\");poke(l+236,\"gold\");"; + char *w6 = "poke(l+200,\"soul \");poke(l+204,\"garden \");poke(l+208,\"east \");poke(l+212,\"Eden \");poke(l+216,\"ground \");poke(l+220,\"sight \");poke(l+224,\"good \");poke(l+228,\"evil \");poke(l+232,\"river \");poke(l+236,\"gold \");"; fat32_write(fh, w6, cmd_strlen(w6)); - char *w7 = "poke(l+240,\"stone\");poke(l+244,\"woman\");poke(l+248,\"wife\");poke(l+252,\"flesh\");poke(l+256,\"bone\");poke(l+260,\"naked\");poke(l+264,\"serpent\");poke(l+268,\"subtle\");poke(l+272,\"eat\");poke(l+276,\"eyes\");"; + char *w7 = "poke(l+240,\"stone \");poke(l+244,\"woman \");poke(l+248,\"wife \");poke(l+252,\"flesh \");poke(l+256,\"bone \");poke(l+260,\"naked \");poke(l+264,\"serpent \");poke(l+268,\"subtle \");poke(l+272,\"eat \");poke(l+276,\"eyes \");"; fat32_write(fh, w7, cmd_strlen(w7)); - char *w8 = "poke(l+280,\"wise\");poke(l+284,\"cool\");poke(l+288,\"voice\");poke(l+292,\"fear\");poke(l+296,\"hid\");poke(l+300,\"cursed\");poke(l+304,\"belly\");poke(l+308,\"enmity\");poke(l+312,\"sorrow\");poke(l+316,\"conception\");"; + char *w8 = "poke(l+280,\"wise \");poke(l+284,\"cool \");poke(l+288,\"voice \");poke(l+292,\"fear \");poke(l+296,\"hid \");poke(l+300,\"cursed \");poke(l+304,\"belly \");poke(l+308,\"enmity \");poke(l+312,\"sorrow \");poke(l+316,\"conception \");"; fat32_write(fh, w8, cmd_strlen(w8)); - char *w9 = "poke(l+320,\"children\");poke(l+324,\"desire\");poke(l+328,\"husband\");poke(l+332,\"thorns\");poke(l+336,\"thistles\");poke(l+340,\"sweat\");poke(l+344,\"bread\");poke(l+348,\"mother\");poke(l+352,\"skin\");poke(l+356,\"coats\");"; + char *w9 = "poke(l+320,\"children \");poke(l+324,\"desire \");poke(l+328,\"husband \");poke(l+332,\"thorns \");poke(l+336,\"thistles \");poke(l+340,\"sweat \");poke(l+344,\"bread \");poke(l+348,\"mother \");poke(l+352,\"skin \");poke(l+356,\"coats \");"; fat32_write(fh, w9, cmd_strlen(w9)); - char *w10 = "poke(l+360,\"cherubims\");poke(l+364,\"sword\");poke(l+368,\"gate\");poke(l+372,\"offering\");poke(l+376,\"respect\");poke(l+380,\"sin\");poke(l+384,\"door\");poke(l+388,\"blood\");poke(l+392,\"brother\");poke(l+396,\"keeper\");"; + char *w10 = "poke(l+360,\"cherubims \");poke(l+364,\"sword \");poke(l+368,\"gate \");poke(l+372,\"offering \");poke(l+376,\"respect \");poke(l+380,\"sin \");poke(l+384,\"door \");poke(l+388,\"blood \");poke(l+392,\"brother \");poke(l+396,\"keeper \");"; fat32_write(fh, w10, cmd_strlen(w10)); - char *e = "int c;int r;r=rand();r=r-(r/3)*3;c=5+r;int i;i=0;while(ivalid = true; handle->cluster = entry->start_cluster; + handle->start_cluster = entry->start_cluster; handle->position = 0; handle->size = entry->size; @@ -283,6 +284,17 @@ FAT32_FileHandle* fat32_open(const char *path, const char *mode) { } else { handle->mode = 2; // append handle->position = entry->size; + + // Walk to the correct cluster for the current position + uint32_t current_cluster = handle->start_cluster; + uint32_t pos = 0; + while (pos + FAT32_CLUSTER_SIZE <= handle->position) { + uint32_t next = fat_table[current_cluster]; + if (next >= 0xFFFFFFF8) break; + current_cluster = next; + pos += FAT32_CLUSTER_SIZE; + } + handle->cluster = current_cluster; } return handle; @@ -342,8 +354,18 @@ int fat32_write(FAT32_FileHandle *handle, const void *buffer, int size) { int bytes_written = 0; const uint8_t *buf = (const uint8_t *)buffer; - uint32_t initial_cluster = handle->cluster; + // Check if we are at a cluster boundary from a previous write + if (handle->position > 0 && (handle->position % FAT32_CLUSTER_SIZE) == 0) { + uint32_t next = fat_table[handle->cluster]; + if (next >= 0xFFFFFFF8) { + next = allocate_cluster(); + if (!next) return 0; + fat_table[handle->cluster] = next; + } + handle->cluster = next; + } + while (bytes_written < size) { uint32_t offset_in_cluster = handle->position % FAT32_CLUSTER_SIZE; int to_write = size - bytes_written; @@ -379,7 +401,7 @@ int fat32_write(FAT32_FileHandle *handle, const void *buffer, int size) { // Update file entry for (int i = 0; i < MAX_FILES; i++) { - if (files[i].used && files[i].start_cluster == initial_cluster) { + if (files[i].used && files[i].start_cluster == handle->start_cluster) { files[i].size = handle->size; break; } diff --git a/src/kernel/fat32.h b/src/kernel/fat32.h index c3124b1..f4eb119 100644 --- a/src/kernel/fat32.h +++ b/src/kernel/fat32.h @@ -78,6 +78,7 @@ typedef struct { // File Handle typedef struct { uint32_t cluster; // Current cluster + uint32_t start_cluster; // Start cluster (for file entry lookup) uint32_t position; // Current position in file uint32_t size; // File size uint32_t mode; // 0=read, 1=write, 2=append