summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorJake Mannens <jake72360@gmail.com>2018-08-01 02:27:57 +1000
committerJake Mannens <jake72360@gmail.com>2018-08-01 02:27:57 +1000
commit8e933fac9fd068343bb602f13175c8d70a6c5768 (patch)
tree2d0c2ef1c1165d701d94617986e80c7598d0fc4d /kernel
parent7babda5d4573d432441a416f880cb8cc8c15b55b (diff)
Defined EOF as -1 in stdio.h.
Implemented the sprintf() library function in lib/stdio.c which uses the vsprintf() function. Implemented a very primative controlling TTY for each process. This is achieved by a switch in the sys_puts system call which uses the 'ctty' element of the process' task structure to determine an appropriate I/O channel. A negative ctty value doesn't equate to any I/O channel effectively disabling the process' output. Added the sys_ctty system call which allows a process to set it's own ctty value. Removed the sys_rsputs system call. Output to serial is now performed by the process first setting it's ctty value to 1, then invoking sys_puts.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/serial.c20
-rw-r--r--kernel/sys.c25
-rw-r--r--kernel/traps.s4
3 files changed, 38 insertions, 11 deletions
diff --git a/kernel/serial.c b/kernel/serial.c
index 7f23298..86bbd87 100644
--- a/kernel/serial.c
+++ b/kernel/serial.c
@@ -15,10 +15,20 @@
#define RSMODEMS (RSBASE + 6)
#define RSSCRATCH (RSBASE + 7)
-static int rsputs(char *s) {
+#define rswait()\
+ while((inb(RSLINES) & 0x20) == 0);
+
+int rsputs(char *s) {
while(*s) {
- while((inb(RSLINES) & 0x20) == 0);
- outb(RSDATA, *s++);
+ rswait();
+ if(*s == '\n') {
+ outb(RSDATA, '\n');
+ rswait();
+ outb(RSDATA, '\r');
+ s++;
+ } else {
+ outb(RSDATA, *s++);
+ }
}
return 0;
@@ -46,7 +56,3 @@ void serial_init(void) {
rsputs("[kernel] Serial monitor initialized!\n\r");
printk("[rs] Serial port COM0 initialized!\n");
}
-
-int sys_rsputs(char *s) {
- return rsputs(s);
-}
diff --git a/kernel/sys.c b/kernel/sys.c
index c2256c1..986c4dd 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -3,13 +3,28 @@
#include <kernel/sched.h>
#include <signal.h>
#include <stdint.h>
+#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
int sys_puts(char *s) {
- printk("[%04x] ", ctask->pid);
- return printk(s);
+ char buf[8];
+ sprintf(buf, "[%04x] ", ctask->pid);
+
+ if(ctask->ctty < 0)
+ return EOF;
+
+ switch(ctask->ctty) {
+ case 1:
+ rsputs(buf);
+ return rsputs(s);
+ break;
+ default:
+ printk("%s", buf);
+ return printk(s);
+ break;
+ }
}
time_t sys_time(void) {
@@ -56,6 +71,12 @@ int sys_pause(void) {
return -1;
}
+int sys_ctty(int ctty) {
+ ctask->ctty = ctty;
+
+ return 0;
+}
+
int sys_dummy(void) {
return -ENOSYS;
}
diff --git a/kernel/traps.s b/kernel/traps.s
index 0a0d202..408a650 100644
--- a/kernel/traps.s
+++ b/kernel/traps.s
@@ -21,8 +21,8 @@ extern ticked
; too.
%define ts_signal 6
-%define ts_sig_handlers 14
-%define ts_tss_esp0 146
+%define ts_sig_handlers 18
+%define ts_tss_esp0 150
%macro SAVE 0
pusha