diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/common.make | 8 | ||||
-rw-r--r-- | src/include/tce/vfs.h | 10 | ||||
-rw-r--r-- | src/kernel/mem/paging.cpp | 2 | ||||
-rw-r--r-- | src/kernel/task/task.cpp | 5 | ||||
-rw-r--r-- | src/kernel/vfs/node.h | 2 | ||||
-rw-r--r-- | src/kernel/vfs/vfile.cpp | 14 | ||||
-rw-r--r-- | src/kernel/vfs/vfile.h | 2 | ||||
-rwxr-xr-x | src/tools/makeinitrd/makeinitrd | bin | 16358 -> 0 bytes | |||
-rw-r--r-- | src/user/app/led/Makefile | 6 | ||||
-rw-r--r-- | src/user/app/led/main.c | 195 |
12 files changed, 234 insertions, 17 deletions
@@ -2,6 +2,7 @@ *.swp *.map *.elf +src/tools/makeinitrd/makeinitrd cdrom/* tmp TCE.fl.img @@ -1,6 +1,6 @@ .PHONY: clean, mrproper, Init.rfs, floppy, commit -Projects = tools/makeinitrd kernel user/lib/libc user/lib/fwik user/app/init user/app/test user/app/yosh user/app/prime +Projects = tools/makeinitrd kernel user/lib/libc user/lib/fwik user/app/init user/app/test user/app/yosh user/app/prime user/app/led QemuCmd = qemu-system-i386 BasePath = $(shell pwd) @@ -36,7 +36,7 @@ commit: mrproper git commit -a; exit 0 git push origin -$(Cdrom): menu_cdrom.lst src/kernel/kernel.elf src/user/app/test/test.elf src/user/app/init/init.elf src/user/app/yosh/yosh.elf src/user/app/prime/prime.elf +$(Cdrom): menu_cdrom.lst src/kernel/kernel.elf src/user/app/test/test.elf src/user/app/init/init.elf src/user/app/yosh/yosh.elf src/user/app/prime/prime.elf src/user/app/led/led.elf mkdir -p cdrom/boot/grub if [ ! -e cdrom/boot/grub/stage2_eltorito ]; then \ echo "Please copy grub's stage2_eltorito to cdrom/boot/grub."; \ @@ -48,10 +48,12 @@ $(Cdrom): menu_cdrom.lst src/kernel/kernel.elf src/user/app/test/test.elf src/us cp src/user/app/test/test.elf cdrom; strip cdrom/test.elf cp src/user/app/yosh/yosh.elf cdrom; strip cdrom/yosh.elf cp src/user/app/prime/prime.elf cdrom; strip cdrom/prime.elf + cp src/user/app/led/led.elf cdrom; strip cdrom/led.elf src/tools/makeinitrd/makeinitrd cdrom/initrd \ cdrom/test.elf:/bin/test \ cdrom/yosh.elf:/bin/yosh \ cdrom/prime.elf:/bin/prime \ + cdrom/led.elf:/bin/led \ README:/readme genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 \ -boot-info-table -input-charset ascii -A TCE -o $(Cdrom) cdrom diff --git a/src/common.make b/src/common.make index 71cea37..4ffb6c6 100644 --- a/src/common.make +++ b/src/common.make @@ -19,7 +19,7 @@ AFLAGS = -f elf all: $(Out) $(Out): $(Obj) $(ExtObj) - echo ""; echo "- Linking $@..." + echo "- Linking $@..." $(LD) $(LDFLAGS) $^ -o $@ # ============== GENERAL CLEAINING PROCEDURES @@ -34,13 +34,13 @@ mrproper: clean # ============== SOURCE FILE BUILD PROCEDURES %.o: %.asm - echo ""; echo "- $<" + echo "- $<" $(ASM) $(AFLAGS) -o $@ $< %.o: %.c - echo ""; echo "- $<" + echo "- $<" $(CC) -c $< -o $@ $(CFLAGS) $(CCFLAGS) %.o: %.cpp - echo ""; echo "- $<" + echo "- $<" $(CXX) -c $< -o $@ $(CFLAGS) $(CXXFLAGS) diff --git a/src/include/tce/vfs.h b/src/include/tce/vfs.h index 329bd8b..4425a18 100644 --- a/src/include/tce/vfs.h +++ b/src/include/tce/vfs.h @@ -27,11 +27,11 @@ typedef struct _file_info { #define LM_OUTPUT_TO 4 // file type flags -#define FT_FILE 0x00000001 -#define FT_DIR 0x00000002 -#define FT_SYMLINK 0x00000004 -#define FT_DEV 0x00000008 -#define FT_TERMINAL 0x00000010 +#define FT_FILE 0x00000101 +#define FT_DIR 0x00000102 +#define FT_SYMLINK 0x00000104 +#define FT_DEV 0x00000108 +#define FT_TERMINAL 0x00000110 // device types #define DT_BLOCK 1 diff --git a/src/kernel/mem/paging.cpp b/src/kernel/mem/paging.cpp index 03c6e2d..2ac190f 100644 --- a/src/kernel/mem/paging.cpp +++ b/src/kernel/mem/paging.cpp @@ -136,7 +136,7 @@ uint32_t paging_fault(registers *regs) { } if (seg == 0) { - NL; WHERE; *ke_vt << "Unhandled Page Fault\t"; + NL; WHERE; *ke_vt << "Unhandled Page Fault (PID " << current_thread->process->pid << ")\t"; *ke_vt << "cr2:" << addr; NL; TAB; if (regs->err_code & 0x1) *ke_vt << "present"; TAB; diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp index 46fb4d4..4a802b8 100644 --- a/src/kernel/task/task.cpp +++ b/src/kernel/task/task.cpp @@ -116,11 +116,12 @@ uint32_t tasking_handleException(registers *regs) { *ke_vt << "\nException in kernel. Stack trace:\n"; stack_trace(regs->ebp); } + *ke_vt << "\n (PID " << current_thread->process->pid << ") "; if (regs->int_no == 14) { - *ke_vt << "\n>>> Process exiting.\n"; + *ke_vt << ">>> Process exiting.\n"; thread_exit_stackJmp(EX_PR_EXCEPTION); } else { - *ke_vt << "\n>>> Thread exiting.\n"; + *ke_vt << ">>> Thread exiting.\n"; thread_exit_stackJmp(EX_TH_EXCEPTION); } PANIC("This should never have happened. Please report this."); diff --git a/src/kernel/vfs/node.h b/src/kernel/vfs/node.h index b0ade41..c3b1585 100644 --- a/src/kernel/vfs/node.h +++ b/src/kernel/vfs/node.h @@ -28,7 +28,7 @@ class node { virtual size_t get_size() { return 0; } virtual int link(node* other, int mode) { return E_NOT_IMPLEMENTED; } - // kind of like dynamic_cast'int these things + // kind of like dynamic_cast'ing these things virtual display *as_display() { return 0; } virtual vt *as_vt() { return 0; } }; diff --git a/src/kernel/vfs/vfile.cpp b/src/kernel/vfs/vfile.cpp index ff57c9e..38ea291 100644 --- a/src/kernel/vfs/vfile.cpp +++ b/src/kernel/vfs/vfile.cpp @@ -12,7 +12,19 @@ vfile::~vfile() { if (own_data) kfree(data); } +int vfile::open(process *proc, int mode) { + if (mode & FM_TRUNC) { + if (own_data) kfree(data); + size = 0; + own_data = false; + data = 0; + } + return 0; +} + int vfile::read(size_t offset, size_t len, char* buffer) { + if (size == 0) return 0; + if (offset + len > size) len = size - offset; memcpy(buffer, data + offset, len); return len; @@ -22,7 +34,7 @@ int vfile::write(size_t offset, size_t len, char* buffer) { size_t new_size = MAX(offset + len, size); if (!own_data || new_size > size) { char* new_data = (char*)kmalloc(new_size); - memcpy(new_data, data, size); + if (size > 0) memcpy(new_data, data, size); if (new_size > size) memset(new_data + size, 0, new_size - size); if (own_data) kfree(data); data = new_data; diff --git a/src/kernel/vfs/vfile.h b/src/kernel/vfs/vfile.h index 9b68b68..ffbccf9 100644 --- a/src/kernel/vfs/vfile.h +++ b/src/kernel/vfs/vfile.h @@ -13,7 +13,7 @@ class vfile : public node { vfile(node* parent, char* data = 0, size_t size = 0); virtual ~vfile(); - // TODO: handle open(TRUNC) + virtual int open(process *proc, int mode); virtual int read(size_t offset, size_t len, char* buffer); virtual int write(size_t offset, size_t len, char* buffer); virtual size_t get_size() { return size; } diff --git a/src/tools/makeinitrd/makeinitrd b/src/tools/makeinitrd/makeinitrd Binary files differdeleted file mode 100755 index 6ad60bb..0000000 --- a/src/tools/makeinitrd/makeinitrd +++ /dev/null diff --git a/src/user/app/led/Makefile b/src/user/app/led/Makefile new file mode 100644 index 0000000..ee4cffb --- /dev/null +++ b/src/user/app/led/Makefile @@ -0,0 +1,6 @@ +Obj = main.o +Out = led.elf + +include $(SrcPath)/user/app/common.make + +LDFLAGS += -Map led.map diff --git a/src/user/app/led/main.c b/src/user/app/led/main.c new file mode 100644 index 0000000..5e73c59 --- /dev/null +++ b/src/user/app/led/main.c @@ -0,0 +1,195 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <readline.h> + +void parse_range(char *k, int *l1, int *l2) { + *l1 = 0; + *l2 = 0; + while (k[0] == ' ' || k[0] == '\t') k++; + + while (k[0] >= '0' && k[0] <= '9') { + (*l1) *= 10; + (*l1) += (k[0] - '0'); + k++; + } + if (k[0] == '-') { + k++; + while (k[0] >= '0' && k[0] <= '9') { + (*l2) *= 10; + (*l2) += (k[0] - '0'); + k++; + } + } + + if (k[0] != 0) { + *l1 = 0; + } + if (*l2 == 0) *l2 = *l1; + + if (*l1 == 0 || *l2 < *l1) { + printf("Invalid range."); + *l1 = 0; + } +} + +int main(char **args) { + int linecount; + char **lines; + int i, j; + + readline_history hist; + hist.str = 0; hist.max = 10; + + if (args[1] == 0) { + printf("Usage: %s filename\n", args[0]); + } else { + // load file + file_info info; + int e = stat(args[1], &info); + if (e == E_NOT_FOUND) { + printf("File not found. Creating new file.\n"); + linecount = 0; + lines = malloc(1 * sizeof(char*)); + lines[0] = 0; + } else if (info.type & FT_FILE) { + FILE f = open(args[1], FM_READ); + char* buff = (char*)malloc(info.size); + read(f, 0, info.size, buff); + close(f); + + // count newlines + linecount = 1; + for (i = 0; i < info.size; i++) { + if (buff[i] == '\n') linecount++; + } + lines = malloc(linecount * sizeof(char*)); + + // copy lines + i = 0; + int p = 0, l = 0; + while (i <= info.size) { + if ((i == info.size && buff[i-1] != 0) || buff[i] == '\n') { + lines[l] = malloc(i - p + 1); + for (j = 0; j < i-p; j++) lines[l][j] = buff[p+j]; + lines[l][i-p] = 0; + l++; + p = i+1; + } + i++; + } + while (l < linecount) linecount--; + + if (linecount > 0 && lines[linecount-1][0] == 0) { + free(lines[linecount-1]); + linecount--; + } + + // free buffer + free(buff); + } else { + printf("%s is not a file. Exiting.\n", args[1]); + return -1; + } + + // run + while (lines) { + printf("[%d lines] ", linecount); + char *s = freadline(term, &hist); + if (strcmp(s, "q") == 0) { + break; + } else if (strcmp(s, "l") == 0) { + for (i = 0; i < linecount; i++) { + printf("%d\t%s\n", i + 1, lines[i]); + } + } else if (s[0] == 'l') { + int l1, l2; + parse_range(s + 1, &l1, &l2); + if (l1 != 0) { + if (l2 > linecount) { + printf("There are only %d lines.\n", linecount); + } else { + for (i = l1; i <= l2; i++) { + printf("%d\t%s\n", i, lines[i-1]); + } + } + } + } else if (strcmp(s, "w") == 0) { + // calculate buffer size + int buffsz = 0; + for (i = 0; i < linecount; i++) { + buffsz += strlen(lines[i]) + 1; + } + + //write buffer + char *buff = malloc(buffsz); + char *p = buff; + for (i = 0; i < linecount; i++) { + for (j = 0; lines[i][j]; j++) { + *(p++) = lines[i][j]; + } + *(p++) = '\n'; + } + + // write buffer + FILE f = open(args[1], FM_WRITE | FM_TRUNC | FM_CREATE | FT_FILE); + if (f > 0) { + write(f, 0, buffsz, buff); + close(f); + printf("%s written, %d lines, %d characters\n", args[1], linecount, buffsz); + } else { + printf("Error %d in opening %s\n", f, args[1]); + } + free(buff); + } else if (s[0] >= '1' && s[0] <= '9') { + int line = 0; + i = 0; + while (s[i] >= '0' && s[i] <= '9') { + line *= 10; + line += (s[i] - '0'); + i++; + } + if(s[i] == ' ' || s[i] == '\t') i++; + char *nl = s + i; + + if (line < 1) { + printf("Invalid line number.\n"); + continue; + } + + if (line > linecount) { + char **lines2 = malloc(line * sizeof(char*)); + for (i = 0; i < linecount; i++) { + lines2[i] = lines[i]; + } + for (i = linecount; i < line; i++) { + lines2[i] = strdup(""); + } + free(lines); //PB + lines = lines2; + linecount = line; + } + + free(lines[line-1]); + lines[line-1] = strdup(nl); + } else if (s[0] == 'd') { + int l1, l2; + parse_range(s + 1, &l1, &l2); + if (l1 != 0) { + l1--; + for (i = l1; i < l2; i++) { + free(lines[i]); + } + for (i = l2; i < linecount; i++) { + lines[i - (l2 - l1)] = lines[i]; + } + linecount -= (l2 - l1); + } + } else { + printf("Unknown command: %s\n", s); + } + } + } + + return 0; +} |