summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/kernel/con.h4
-rw-r--r--include/kernel/fs.h2
-rw-r--r--include/kernel/hd.h1
-rw-r--r--kernel/boot.s13
-rw-r--r--kernel/con.c43
-rw-r--r--kernel/hd.c2
-rw-r--r--kernel/sched.c2
-rw-r--r--kernel/tty.c3
-rw-r--r--usrbin/main.c3
9 files changed, 66 insertions, 7 deletions
diff --git a/include/kernel/con.h b/include/kernel/con.h
index 9dd9dbe..6bc24da 100644
--- a/include/kernel/con.h
+++ b/include/kernel/con.h
@@ -7,6 +7,10 @@
#ifndef _CON_H
#define _CON_H
+#include <kernel/tty.h>
+
+extern struct tty_struct tty_con;
+
void con_init(void);
void con_clear(void);
diff --git a/include/kernel/fs.h b/include/kernel/fs.h
index a2b0086..a752ddf 100644
--- a/include/kernel/fs.h
+++ b/include/kernel/fs.h
@@ -15,7 +15,7 @@
struct file {
uint16_t f_mode;
uint16_t f_flags;
- /* TODO: inode pointer here */
+ struct m_inode *f_inode;
off_t f_pos;
};
diff --git a/include/kernel/hd.h b/include/kernel/hd.h
index 2a2f3c6..7244c92 100644
--- a/include/kernel/hd.h
+++ b/include/kernel/hd.h
@@ -1,7 +1,6 @@
#ifndef _HD_H
#define _HD_H
-#include <stdint.h>
#include <sys/types.h>
void hd_init(void);
diff --git a/kernel/boot.s b/kernel/boot.s
index 8d07354..5050705 100644
--- a/kernel/boot.s
+++ b/kernel/boot.s
@@ -18,6 +18,7 @@ extern tty_init
; Multiboot header
section .mboothdr
+jmp kboot
mboot_hdr:
align 4
dd 0x1BADB002
@@ -44,10 +45,10 @@ kboot:
call printk
add esp, 4
; initialize secondary subsystems
+ call timer_init
call fs_init
call tty_init
; last minute setup, then transfer to kmain
- call timer_init
call kmain
; if kmain decides to return (which it shouldn't),
; disable interrupts and halt the system.
@@ -243,6 +244,14 @@ enable_a20:
xchg ax, cx
or al, 0x02
out 0x60, al
+ ; check if the gate is now enabled
+ call .testgate
+ jne .end
+ ; if the gate is still not working, try the fast-gate method
+ in al, 0x92
+ and al, 0xFE
+ or al, 0x02
+ out 0x92, al
; make sure the gate is working (panic if not)
call .testgate
jne .end
@@ -272,7 +281,7 @@ enable_a20:
pop ebp
ret
.tmp: dw 0xDEAD
-.msg: db "Failed to enable A20 gate!", 10, 0
+.msg: db "Failed to enable the A20 gate!", 10, 0
pic_init:
push ebp
diff --git a/kernel/con.c b/kernel/con.c
index 2000fbc..5a9d2e9 100644
--- a/kernel/con.c
+++ b/kernel/con.c
@@ -5,6 +5,7 @@
*/
#include <asm/io.h>
+#include <kernel/tty.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
@@ -12,6 +13,14 @@
#define COLS 80
#define ROWS 25
+/* internal function prototypes */
+static void con_write(void);
+
+struct tty_struct tty_con = {
+ .init = NULL,
+ .write = &con_write
+};
+
static uint8_t *vram = (uint8_t*) 0xB8000;
static int pos;
@@ -91,6 +100,40 @@ static int con_puts(char *s) {
return 0;
}
+/* same as con_puts() but deals with bytes rather than strings */
+static void con_write(void) {
+ char c;
+ int copied = 0;
+ uint8_t *p = &vram[pos];
+ struct tty_queue *q = &tty_con.wqueue;
+
+ while(q->pread != q->pwrite) {
+ c = q->buf[q->pread];
+ if(c == '\n') {
+ pos = (int) (p - vram);
+ pos = ((pos / (COLS << 1)) + 1) * (COLS << 1);
+ p = &vram[pos];
+ } else {
+ *p = c;
+ p += 2;
+ }
+
+ q->pread = (q->pread + 1) % TTY_BUF_SIZE;
+ copied = 1;
+
+ pos = (int) (p - vram);
+
+ if(pos >= (COLS * ROWS) << 1)
+ scroll_up();
+ }
+
+ /* update the cursor position */
+ cursorpos(pos);
+
+ if(copied)
+ wake_up(&q->waiting);
+}
+
int printk(char *fmt, ...) {
int ret;
char buf[1024];
diff --git a/kernel/hd.c b/kernel/hd.c
index eab82dc..3b2aa3c 100644
--- a/kernel/hd.c
+++ b/kernel/hd.c
@@ -183,5 +183,5 @@ void hd_init(void) {
return;
}
- printk("[hd] Primary bus master drive initialized! (status: 0x%02x, nblocks: 0x%01x)\n", s, nblocks);
+ printk("[hd] Primary bus master drive initialized! (status: 0x%02x, nsects: 0x%01x)\n", s, nblocks);
}
diff --git a/kernel/sched.c b/kernel/sched.c
index a17b58c..da55fa3 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -209,7 +209,7 @@ void sched_init(void) {
ctask = NULL;
create_proc(&_usrbin_start, (size_t) &_usrbin_size);
- /* create_proc(&_usrbin_start, (size_t) &_usrbin_size); */
+ create_proc(&_usrbin_start, (size_t) &_usrbin_size);
switch_to(0, &tasks[0]);
}
diff --git a/kernel/tty.c b/kernel/tty.c
index bfbf775..529d955 100644
--- a/kernel/tty.c
+++ b/kernel/tty.c
@@ -1,5 +1,6 @@
#include <asm/interrupt.h>
#include <errno.h>
+#include <kernel/con.h>
#include <kernel/sched.h>
#include <kernel/serial.h>
#include <kernel/tty.h>
@@ -12,7 +13,7 @@
(sizeof(ttys) / sizeof(struct tty_struct*))
static struct tty_struct *ttys[] = {
- NULL,
+ &tty_con,
&tty_rs
};
diff --git a/usrbin/main.c b/usrbin/main.c
index 3b6dd97..6acf5fe 100644
--- a/usrbin/main.c
+++ b/usrbin/main.c
@@ -46,6 +46,9 @@ void pid2(void) {
if(time() == 2)
kill(1, 1);
printf("0x%04x:0x%08x: 0x%08x, 0x%08x\n", getpid(), (uint32_t) getpdir(), time(), x++);
+
+ if(x > 3)
+ kill(getpid(), SIGKILL);
}
}