summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2013-06-09 14:35:40 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2013-06-09 14:35:40 +0200
commit9c74cb8c5bb5661d7f71f43b88816e70cc9fc022 (patch)
tree77a893ff826dcb14e9b8768c23e4970033e934ea
parent4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4 (diff)
downloadTCE-9c74cb8c5bb5661d7f71f43b88816e70cc9fc022.tar.gz
TCE-9c74cb8c5bb5661d7f71f43b88816e70cc9fc022.zip
Many bug corrections.
-rw-r--r--Makefile5
-rw-r--r--media/2013-06-09-kbasic-1.pngbin0 -> 7972 bytes
-rw-r--r--media/2013-06-09-kbasic-2.pngbin0 -> 7739 bytes
-rw-r--r--media/2013-06-09-kbasic-3.pngbin0 -> 6911 bytes
-rw-r--r--media/2013-06-09-kbasic-4.pngbin0 -> 6996 bytes
-rw-r--r--media/2013-06-09-kbasic-5.pngbin0 -> 6892 bytes
-rw-r--r--media/2013-06-09-kbasic-crash.pngbin0 -> 9655 bytes
-rw-r--r--src/kernel/core/main.cpp0
-rw-r--r--src/kernel/mem/paging.cpp24
-rw-r--r--src/kernel/task/idt.cpp2
-rw-r--r--src/kernel/task/task.cpp32
-rw-r--r--src/kernel/ui/vt.cpp2
-rw-r--r--src/user/app/kbasic/basic.h2
-rw-r--r--src/user/app/kbasic/commands.c24
-rw-r--r--src/user/app/kbasic/control.c45
-rw-r--r--src/user/app/kbasic/count.bas7
-rw-r--r--src/user/app/kbasic/guess.bas14
-rw-r--r--src/user/app/kbasic/lex.c23
-rw-r--r--src/user/app/kbasic/main.c24
-rw-r--r--src/user/app/kbasic/pppg.bas14
-rw-r--r--src/user/app/kbasic/prime.bas20
-rw-r--r--src/user/app/kbasic/tables.bas6
-rw-r--r--src/user/app/kbasic/var.c2
-rw-r--r--src/user/app/test/main.c10
-rw-r--r--src/user/app/yosh/main.c2
-rw-r--r--src/user/lib/libc/include/readline.h6
-rw-r--r--src/user/lib/libc/include/tce/syscall.h2
-rw-r--r--src/user/lib/libc/std/ctype.c4
-rw-r--r--src/user/lib/libc/std/readline.c38
-rw-r--r--src/user/lib/libc/std/stdio.c2
-rw-r--r--src/user/lib/libc/std/stdlib.c1
-rw-r--r--src/user/lib/libc/tce/syscall.c2
32 files changed, 189 insertions, 124 deletions
diff --git a/Makefile b/Makefile
index c44c64f..f4c878a 100644
--- a/Makefile
+++ b/Makefile
@@ -54,12 +54,17 @@ $(Cdrom): menu_cdrom.lst src/kernel/kernel.elf src/user/app/test/test.elf src/us
cp src/user/app/prime/prime.elf cdrom; strip cdrom/prime.elf
cp src/user/app/led/led.elf cdrom; strip cdrom/led.elf
cp src/user/app/kbasic/kbasic.elf cdrom; strip cdrom/kbasic.elf
+ cp src/user/app/kbasic/*.bas cdrom
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 \
cdrom/kbasic.elf:/bin/kbasic \
+ cdrom/guess.bas:/bas/guess \
+ cdrom/tables.bas:/bas/tables \
+ cdrom/count.bas:/bas/count \
+ cdrom/prime.bas:/bas/prime \
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/media/2013-06-09-kbasic-1.png b/media/2013-06-09-kbasic-1.png
new file mode 100644
index 0000000..8478906
--- /dev/null
+++ b/media/2013-06-09-kbasic-1.png
Binary files differ
diff --git a/media/2013-06-09-kbasic-2.png b/media/2013-06-09-kbasic-2.png
new file mode 100644
index 0000000..48a279d
--- /dev/null
+++ b/media/2013-06-09-kbasic-2.png
Binary files differ
diff --git a/media/2013-06-09-kbasic-3.png b/media/2013-06-09-kbasic-3.png
new file mode 100644
index 0000000..5edadd8
--- /dev/null
+++ b/media/2013-06-09-kbasic-3.png
Binary files differ
diff --git a/media/2013-06-09-kbasic-4.png b/media/2013-06-09-kbasic-4.png
new file mode 100644
index 0000000..8b1bb5b
--- /dev/null
+++ b/media/2013-06-09-kbasic-4.png
Binary files differ
diff --git a/media/2013-06-09-kbasic-5.png b/media/2013-06-09-kbasic-5.png
new file mode 100644
index 0000000..1d77725
--- /dev/null
+++ b/media/2013-06-09-kbasic-5.png
Binary files differ
diff --git a/media/2013-06-09-kbasic-crash.png b/media/2013-06-09-kbasic-crash.png
new file mode 100644
index 0000000..c93200a
--- /dev/null
+++ b/media/2013-06-09-kbasic-crash.png
Binary files differ
diff --git a/src/kernel/core/main.cpp b/src/kernel/core/main.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/kernel/core/main.cpp
diff --git a/src/kernel/mem/paging.cpp b/src/kernel/mem/paging.cpp
index 2ac190f..5c5a929 100644
--- a/src/kernel/mem/paging.cpp
+++ b/src/kernel/mem/paging.cpp
@@ -136,14 +136,22 @@ uint32_t paging_fault(registers *regs) {
}
if (seg == 0) {
- 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;
- if (regs->err_code & 0x2) *ke_vt << "write"; TAB;
- if (regs->err_code & 0x4) *ke_vt << "user"; TAB;
- if (regs->err_code & 0x8) *ke_vt << "rsvd"; TAB;
- if (regs->err_code & 0x10) *ke_vt << "opfetch";
+ node *n = current_thread->process->fd.at(0);
+ vt *vt = (n && n->as_vt() ? n->as_vt() : ke_vt);
+
+ vt->writeStr("\n");
+ vt->writeStr("[ke:"); vt->writeStr(__FILE__); vt->writeStr(":");
+ vt->writeDec(__LINE__); vt->writeStr("] ");
+ vt->writeStr("Unhandled Page Fault");
+
+ *vt << "\n\tPID: " << (int)current_thread->process->pid;
+ *vt << "\n\tcr2: " << addr;
+ *vt << "\n\tflags: ";
+ if (regs->err_code & 0x1) *vt << "present ";
+ if (regs->err_code & 0x2) *vt << "write ";
+ if (regs->err_code & 0x4) *vt << "user ";
+ if (regs->err_code & 0x8) *vt << "rsvd ";
+ if (regs->err_code & 0x10) *vt << "opfetch ";
return 1;
}
return 0;
diff --git a/src/kernel/task/idt.cpp b/src/kernel/task/idt.cpp
index e56a51b..94a31b7 100644
--- a/src/kernel/task/idt.cpp
+++ b/src/kernel/task/idt.cpp
@@ -78,7 +78,7 @@ static struct irq_waiter {
/* Called in idt_.asm when an exception fires (interrupt 0 to 31).
Tries to handle the exception, panics if fails. */
extern "C" void idt_isrHandler(registers regs) {
- if ((regs.int_no == 14 && paging_fault(&regs) != 0) || regs.int_no != 14) {
+ if (regs.int_no != 14 || paging_fault(&regs)) {
if (tasking_handleException(&regs) == 0) {
*ke_vt << "\nREALLY BAD THIS TIME\t\tUnhandled exception\t#";
*ke_vt << regs.int_no;
diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp
index 91f802d..2af0441 100644
--- a/src/kernel/task/task.cpp
+++ b/src/kernel/task/task.cpp
@@ -104,24 +104,40 @@ void schedule() {
/* Called when an exception happens. Provides a stack trace if it was in kernel land.
Ends the thread for most exceptions, ends the whole process for page faults. */
uint32_t tasking_handleException(registers *regs) {
+ node *n = current_thread->process->fd.at(0);
+ vt *vt = (n && n->as_vt() ? n->as_vt() : ke_vt);
+
if (current_thread == 0) return 0; //No tasking yet
- NL; WHERE; ke_vt->writeStr("Exception: `");
+
+ vt->writeStr("\n");
+ vt->writeStr("[ke:"); vt->writeStr(__FILE__); vt->writeStr(":");
+ vt->writeDec(__LINE__); vt->writeStr("] ");
+ vt->writeStr("Exception: ");
+
char *exception_messages[] = {"Division By Zero","Debug","Non Maskable Interrupt","Breakpoint",
"Into Detected Overflow","Out of Bounds","Invalid Opcode","No Coprocessor", "Double Fault",
"Coprocessor Segment Overrun","Bad TSS","Segment Not Present","Stack Fault","General Protection Fault",
"Page Fault","Unknown Interrupt","Coprocessor Fault","Alignment Check","Machine Check"};
- *ke_vt << exception_messages[regs->int_no];
- *ke_vt << "'\teip:" << regs->eip;
+ *vt << exception_messages[regs->int_no];;
+ *vt << "\n\tPID: " << (int)current_thread->process->pid;
+ *vt << "\n\teip: " << regs->eip;
+
if (regs->eip >= K_HIGHHALF_ADDR) {
- *ke_vt << "\nException in kernel. Stack trace:\n";
- stack_trace(regs->ebp);
+ *vt << "\n\tException in kernel.";
+ stack_trace(regs->ebp); // useless
+ }
+ *vt << "\n\tTrace:";
+ uint32_t *stack = (uint32_t*)regs->ebp, i;
+ for (i = 0; i < 7 && (size_t)stack < (regs->ebp + 0x4000) && (size_t) stack >= regs->ebp; i++) {
+ *vt << "\n\t " << (size_t)stack << " next: " << stack[0] << " ret: " << stack[1];
+ stack = (uint32_t*)stack[0];
}
- *ke_vt << "\n (PID " << current_thread->process->pid << ") ";
+
if (regs->int_no == 14) {
- *ke_vt << ">>> Process exiting.\n";
+ *vt << "\n\tKilling process.\n";
thread_exit_stackJmp(EX_PAGEFAULT);
} else {
- *ke_vt << ">>> Thread exiting.\n";
+ *vt << "\n\tKilling thread.\n";
thread_exit_stackJmp(EX_EXCEPTION);
}
PANIC("This should never have happened. Please report this.");
diff --git a/src/kernel/ui/vt.cpp b/src/kernel/ui/vt.cpp
index 6876806..ec18808 100644
--- a/src/kernel/ui/vt.cpp
+++ b/src/kernel/ui/vt.cpp
@@ -310,7 +310,7 @@ int vt::write(size_t offset, size_t len, char* buffer) {
fgcolor &= TC_MAKE_DARK;
} else if (n >= 30 && n <= 37) {
fgcolor = (fgcolor & TC_MAKE_LIGHT) | (n - 30);
- } else if (n >= 40 && n <= 47) {
+ } else if (n >= 40 && n <= 55) {
bgcolor = (n - 40);
} else {
// others to do.
diff --git a/src/user/app/kbasic/basic.h b/src/user/app/kbasic/basic.h
index b3491da..0cc5f0c 100644
--- a/src/user/app/kbasic/basic.h
+++ b/src/user/app/kbasic/basic.h
@@ -35,6 +35,7 @@
#define LIST 13
#define PRINT 20 // Built-in commands
#define INPUT 21
+#define COLOR 22
#define RND 50 // Built-in functions
// Buffer size definitions
@@ -67,6 +68,7 @@ void serror(int);
// BASIC commands
void exec_print(), input();
+void color(); void set_color();
void assignment();
void get_exp(int*);
diff --git a/src/user/app/kbasic/commands.c b/src/user/app/kbasic/commands.c
index f60f32a..b88e57e 100644
--- a/src/user/app/kbasic/commands.c
+++ b/src/user/app/kbasic/commands.c
@@ -4,6 +4,9 @@
#include "basic.h"
+static int fg_color = 7, bg_color = 0;
+
+
/* Assign a variable a value. */
void assignment()
{
@@ -33,8 +36,6 @@ void assignment()
*var = value;
}
-
-
/* Execute a simple version of the BASIC PRINT statement */
void exec_print()
{
@@ -95,9 +96,26 @@ void input()
var = find_var(token); /* get the input var */
- scanf("%d\n", var); /* read input */
+ scanf("%d", var); /* read input */
/* flush input */
while ((tmp = getchar()) != '\n' && tmp != EOF);
}
+
+/* COLOR statement */
+void color() {
+ get_exp(&fg_color);
+
+ get_token();
+ if (*token == ',') {
+ get_exp(&bg_color);
+ } else if (token_type != DELIMITER) {
+ serror(0);
+ }
+ set_color();
+}
+
+void set_color() {
+ printf("\x1b[%dm\x1b[%dm\x1b[%dm", fg_color % 8 + 30, (fg_color > 7 ? 1 : 22), bg_color % 16 + 40);
+}
diff --git a/src/user/app/kbasic/control.c b/src/user/app/kbasic/control.c
index 1ab22ff..87731c4 100644
--- a/src/user/app/kbasic/control.c
+++ b/src/user/app/kbasic/control.c
@@ -1,7 +1,7 @@
+#include <tce/syscall.h>
+
#include <stdio.h>
#include <string.h>
-// #include <sys/wait.h>
-// #include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <setjmp.h>
@@ -94,18 +94,25 @@ void insert_line(char *l, int n) {
}
}
- p = malloc(prog_l + strlen(l) + 3);
+ p = malloc(prog_l + strlen(l) + 4);
strncpy(p, program, (a - program)); // copy [0, a[
- p[a - program] = 0;
+
+ char *p2 = p + (a - program);
+ if (*(p2-1) != '\n') *(p2++) = '\n';
+ *p2 = 0;
+
// if l is an empty line, do not copy.
for (i_n = 0; l[i_n]; i_n++) {
if (!isdigit(l[i_n]) && l[i_n] != '\n' && l[i_n] != '\r') {
- strcpy(p + (a - program), l); // copy l
+ strcpy(p2, l); // copy l
break;
}
}
- strcat(p + (a - program), b); // copy [b, end[
+ if (p2[strlen(p2)-1] != '\n') strcat(p2, "\n");
+
+ strcat(p2, b); // copy [b, end[
+ if (p2[strlen(p2)-1] != '\n') strcat(p2, "\n");
load_program(p); // reparse labels
}
@@ -140,6 +147,9 @@ int start(char *entry) {
case PRINT:
exec_print();
break;
+ case COLOR:
+ color();
+ break;
case GOTO:
exec_goto();
break;
@@ -455,30 +465,25 @@ char *gpop()
Forks and runs another instance of the interpreter
*/
void exec_exec() {
-
- /* TODO
int pid;
get_token();
if (token_type==QUOTE) {
- pid = fork();
- if (pid < 0) {
- printf("Error: could not fork.\n");
+ char *args[2];
+ args[0] = token;
+ args[1] = 0;
+
+ pid = run(interp_name, args, term.fd);
+ if (pid <= 0) {
+ printf("Error: could not run '%s'.\n", interp_name);
} else {
- if (pid == 0) {
- execlp(interp_name, interp_name, token, 0);
- printf("Error: could not exec.\n");
- exit(0);
- } else {
- wait(0);
- }
+ int ret = waitpid(pid, 1);
+ printf("[exited: %i]\n", ret);
}
get_token();
} else {
serror(0);
}
- */
- printf("EXEC not available.\n");
}
/* LOAD function
diff --git a/src/user/app/kbasic/count.bas b/src/user/app/kbasic/count.bas
new file mode 100644
index 0000000..5741a72
--- /dev/null
+++ b/src/user/app/kbasic/count.bas
@@ -0,0 +1,7 @@
+05 print "Let me count to 100:"
+10 a = 0
+20 print a;
+30 a = a + 1
+40 if a = 100 then goto 60
+50 goto 20
+60 end
diff --git a/src/user/app/kbasic/guess.bas b/src/user/app/kbasic/guess.bas
new file mode 100644
index 0000000..f15ba49
--- /dev/null
+++ b/src/user/app/kbasic/guess.bas
@@ -0,0 +1,14 @@
+
+n = RND % 100
+e = 0
+
+20 input "Guess the number: ", i
+e = e + 1
+if i > n then print "Too big!"
+if i < n then print "Too small!"
+if i = n then goto 42
+goto 20
+
+42 print "That's right! You got it with only ", e, " guesses!"
+end
+
diff --git a/src/user/app/kbasic/lex.c b/src/user/app/kbasic/lex.c
index 055b502..5d3487b 100644
--- a/src/user/app/kbasic/lex.c
+++ b/src/user/app/kbasic/lex.c
@@ -11,6 +11,7 @@ struct commands { /* keyword lookup table */
} table[] = { /* Commands must be entered lowercase */
{"print", PRINT}, /* in this table. */
{"input", INPUT},
+ {"color", COLOR},
{"if", IF},
{"then", THEN},
@@ -84,7 +85,8 @@ int get_token()
if(*prog_ip=='\0') { /* end of file */
*token=0;
tok = FINISHED;
- return(token_type=DELIMITER);
+ token_type=DELIMITER;
+ goto get_tok_end;
}
while(iswhite(*prog_ip)) ++prog_ip; /* skip over white space */
@@ -93,12 +95,14 @@ int get_token()
++prog_ip; ++prog_ip;
tok = EOL; *token='\r';
token[1]='\n'; token[2]=0;
- return (token_type = DELIMITER);
+ token_type = DELIMITER;
+ goto get_tok_end;
}
if (*prog_ip=='\n') { /* lf (unix newline) */
++prog_ip;
tok = EOL; *token='\n'; token[1] = 0;
- return (token_type = DELIMITER);
+ token_type = DELIMITER;
+ goto get_tok_end;
}
if(strchr("+-*^/%=;(),><", *prog_ip)){ /* delimiter */
@@ -106,7 +110,8 @@ int get_token()
prog_ip++; /* advance to next position */
temp++;
*temp=0;
- return (token_type=DELIMITER);
+ token_type=DELIMITER;
+ goto get_tok_end;
}
if(*prog_ip=='"') { /* quoted string */
@@ -117,7 +122,8 @@ int get_token()
}
if(*prog_ip=='\r' || *prog_ip=='\n') serror(1);
prog_ip++;*temp=0;
- return(token_type=QUOTE);
+ token_type=QUOTE;
+ goto get_tok_end;
}
if(isdigit(*prog_ip)) { /* number */
@@ -126,7 +132,8 @@ int get_token()
prog_ip++;
}
*temp = '\0';
- return(token_type = NUMBER);
+ token_type = NUMBER;
+ goto get_tok_end;
}
if(isalpha(*prog_ip)) { /* var or command */
@@ -145,6 +152,10 @@ int get_token()
if(!tok) token_type = VARIABLE;
else token_type = COMMAND; /* is a command */
}
+
+get_tok_end:
+ //printf("[%d.%d.%s]", token_type, tok, token);
+
return token_type;
}
diff --git a/src/user/app/kbasic/main.c b/src/user/app/kbasic/main.c
index 1003a7b..c76980c 100644
--- a/src/user/app/kbasic/main.c
+++ b/src/user/app/kbasic/main.c
@@ -7,10 +7,7 @@
int main(int argc, char **argv) {
char *p_buf;
- srand(0); // not very usefull...
-
- readline_history hist;
- hist.str = 0; hist.max = 10;
+ srand(1); // not very usefull...
interp_name = argv[0];
init();
@@ -22,18 +19,19 @@ int main(int argc, char **argv) {
load_program(p_buf);
start(p_buf);
} else if (argc == 1) {
+ readline_history hist;
+ hist.str = 0; hist.max = 10;
+
printf("KBASIC 0.1\n"
"Press ^D to quit interpreter.\n\n");
for (;;) {
- printf("> ");
+ printf("\x1b[0m\x1b[32m> \x1b[1m");
char *l = freadline(stdin, &hist);
- if (l == NULL) break;
+ set_color();
- if (!strcmp(l, "exit")) {
- free(l);
- break;
- }
+ if (l == NULL) break;
+ if (!strcmp(l, "exit")) break;
prog_ip = l;
get_token();
@@ -42,11 +40,11 @@ int main(int argc, char **argv) {
} else { // directly execute
start(l);
}
- free(l);
}
} else {
- printf("usage:\n\t%s <filename>\trun BASIC file\n", argv[0]);
- printf("\n\t%s\t\t\tinteractive BASIC interpreter\n", argv[0]);
+ printf("usage:\n");
+ printf(" %s <filename> run BASIC file\n", argv[0]);
+ printf(" %s interactive BASIC interpreter\n", argv[0]);
exit(1);
}
diff --git a/src/user/app/kbasic/pppg.bas b/src/user/app/kbasic/pppg.bas
deleted file mode 100644
index 32fc050..0000000
--- a/src/user/app/kbasic/pppg.bas
+++ /dev/null
@@ -1,14 +0,0 @@
-
-n = RND % 100
-e = 0
-
-20 input "Devinez le nombre: ", i
-e = e + 1
-if i > n then print "Trop grand !"
-if i < n then print "Trop petit !"
-if i = n then goto 42
-goto 20
-
-42 print "Bravo, vous avez trouvé en ", e, " essais!"
-end
-
diff --git a/src/user/app/kbasic/prime.bas b/src/user/app/kbasic/prime.bas
new file mode 100644
index 0000000..bbe4bd0
--- /dev/null
+++ b/src/user/app/kbasic/prime.bas
@@ -0,0 +1,20 @@
+10 i = 2
+20 gosub 100
+30 if p = 1 then print i;
+40 i = i + 1
+50 if i > 1000 then goto 300
+60 goto 20
+
+100 p = 1
+110 d = 2
+120 if d * d > i then return
+130 if i % d = 0 then goto 200
+140 d = d + 1
+150 goto 120
+200 p = 0
+210 return
+
+300 print
+310 print "That's all primes for today!"
+320 end
+
diff --git a/src/user/app/kbasic/tables.bas b/src/user/app/kbasic/tables.bas
index 31e9ce3..a6aaf9c 100644
--- a/src/user/app/kbasic/tables.bas
+++ b/src/user/app/kbasic/tables.bas
@@ -1,12 +1,12 @@
-input "Taille de la table: ", k
-print "Table d'addition:"
+input "Table size: ", k
+print "Addition table:"
for i = 0 to k
for j = 0 to k
print i+j;
next
print
next
-print "Table de multiplication:"
+print "Multiplication table:"
for i = 1 to k
for j = 1 to k
print i * j;
diff --git a/src/user/app/kbasic/var.c b/src/user/app/kbasic/var.c
index a49ce61..6ed2255 100644
--- a/src/user/app/kbasic/var.c
+++ b/src/user/app/kbasic/var.c
@@ -17,3 +17,5 @@ int* find_var(char *s)
}
return variables + (toupper(*s)-'A');
}
+
+
diff --git a/src/user/app/test/main.c b/src/user/app/test/main.c
index 3db24b3..2c42cf8 100644
--- a/src/user/app/test/main.c
+++ b/src/user/app/test/main.c
@@ -1,11 +1,15 @@
#include <tce/syscall.h>
#include <stdio.h>
+#include <stdlib.h>
int threads = 1;
void thread_cascade(void* d) {
int n = (int)d;
+ char *v = malloc(2048);
+ if (!v) printk("!");
+
if (d == 0) {
//printk("{#} 0 cascade element started => end\n");
printk("*");
@@ -29,6 +33,8 @@ void thread_cascade(void* d) {
printk(".");
}
+ free(v);
+
threads--;
}
@@ -50,9 +56,9 @@ int main(int argc, char** args) {
printk("\n");
}
- printk("(test) Creating thread cascade (total 2**5 = 32 threads)\n");
+ printk("(test) Creating thread cascade (total 2**6 = 64 threads)\n");
thread_new(useless_thread, 0);
- thread_new(thread_cascade, (void*)5);
+ thread_new(thread_cascade, (void*)6);
while (1) {
schedule();
diff --git a/src/user/app/yosh/main.c b/src/user/app/yosh/main.c
index 7c9b875..f7ee7e7 100644
--- a/src/user/app/yosh/main.c
+++ b/src/user/app/yosh/main.c
@@ -265,7 +265,7 @@ int main(int argc, char **sh_args) {
}
first_arg++;
- int pid = run(c, (const char**)first_arg, vt_fd);
+ int pid = run(c, first_arg, vt_fd);
if (pid <= 0) {
if (pid == E_NOT_FOUND) {
printf("Error: no such file %s\n", c);
diff --git a/src/user/lib/libc/include/readline.h b/src/user/lib/libc/include/readline.h
index 9fa2ee7..b5e0a1a 100644
--- a/src/user/lib/libc/include/readline.h
+++ b/src/user/lib/libc/include/readline.h
@@ -13,9 +13,11 @@ typedef struct _rdln_hist {
#ifdef __cplusplus
extern "C" { namespace libc {
#endif
-char *readln();
-char* freadln(FILE *f); // minimal line-reading function. user must free the returned value.
+
+
char* freadline(FILE *f, readline_history *h);
+
+
#ifdef __cplusplus
} }
#endif
diff --git a/src/user/lib/libc/include/tce/syscall.h b/src/user/lib/libc/include/tce/syscall.h
index 4a1c6ef..478ed3e 100644
--- a/src/user/lib/libc/include/tce/syscall.h
+++ b/src/user/lib/libc/include/tce/syscall.h
@@ -23,7 +23,7 @@ int proc_priv();
void* sbrk(ptrdiff_t size);
void brk(void* ptr);
-int run(const char* file, const char** args, int zero_fd);
+int run(const char* file, char** args, int zero_fd);
int waitpid(int pid, int block);
int open(const char* filename, int mode);
diff --git a/src/user/lib/libc/std/ctype.c b/src/user/lib/libc/std/ctype.c
index f0e7750..13f2ab0 100644
--- a/src/user/lib/libc/std/ctype.c
+++ b/src/user/lib/libc/std/ctype.c
@@ -15,14 +15,14 @@ int isalnum(int c) {
int tolower(int c) {
if (c >= 'A' && c <= 'Z') {
- return c + ('a' - 'A');
+ c += ('a' - 'A');
}
return c;
}
int toupper(int c) {
if (c >= 'a' && c <= 'z') {
- return c - ('a' - 'A');
+ c -= ('a' - 'A');
}
return c;
}
diff --git a/src/user/lib/libc/std/readline.c b/src/user/lib/libc/std/readline.c
index 4177bf6..5dfd442 100644
--- a/src/user/lib/libc/std/readline.c
+++ b/src/user/lib/libc/std/readline.c
@@ -1,44 +1,6 @@
#include <readline.h>
#include <stdlib.h>
-char* freadln(FILE *f) {
- int i;
-
- char *p = (char*)malloc(256);
- char *b = p;
-
- while (1) {
- int l = fread(b, 255, 1, f);
- if (l < 0) {
- free(b);
- return 0;
- }
-
- for (i = 0; i < l; i++) {
- if (b[i] == '\n') {
- b[i+1] = 0;
- return p;
- } else if (b[i] == 27) { // ignore escape sequences
- b[i] = 0;
- l = i;
- }
- }
-
- int d = b - p + l;
-
- char* newp = (char*)malloc(d + 256);
- memcpy(newp, p, d);
- free(p);
- p = newp;
- b = p + d;
- }
-}
-
-char* readln() {
- return freadln(&term);
-}
-
-
// ** READLINE
char *freadline(FILE *f, readline_history *h) {
diff --git a/src/user/lib/libc/std/stdio.c b/src/user/lib/libc/std/stdio.c
index be65505..043cc59 100644
--- a/src/user/lib/libc/std/stdio.c
+++ b/src/user/lib/libc/std/stdio.c
@@ -42,6 +42,8 @@ void __tce_libc_fsetup(FILE *f) {
f->tib_u_begin = f->tib_begin;
f->tib_u_end = f->tib_u_begin;
f->term_echo = 1;
+ } else {
+ f->tib_begin = f->tib_end = f->tib_u_begin = f->tib_u_end = 0;
}
}
diff --git a/src/user/lib/libc/std/stdlib.c b/src/user/lib/libc/std/stdlib.c
index 15f9ddc..10bce0a 100644
--- a/src/user/lib/libc/std/stdlib.c
+++ b/src/user/lib/libc/std/stdlib.c
@@ -33,6 +33,7 @@ int atoi(char *s) {
while (*s >= '0' && *s <= '9') {
r *= 10;
r += (*s) - '0';
+ s++;
};
return r;
}
diff --git a/src/user/lib/libc/tce/syscall.c b/src/user/lib/libc/tce/syscall.c
index f4f1333..780b573 100644
--- a/src/user/lib/libc/tce/syscall.c
+++ b/src/user/lib/libc/tce/syscall.c
@@ -75,7 +75,7 @@ void brk(void* ptr) {
// ********** proc
-int run(const char* filename, const char** args, int zero_fd) {
+int run(const char* filename, char** args, int zero_fd) {
return call(SC_RUN, (unsigned)filename, (unsigned)args, (unsigned)zero_fd, 0, 0);
}