summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-23 14:56:34 -0400
committerHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-23 14:56:34 -0400
commitf5df2e1d666a943e17261d089456c9483bc9e998 (patch)
tree119cf8284593389e0309224143a0793e242435e8
parent8b93cd18bc1ff2ec1cfd96ead5ff5606cbc35831 (diff)
pts console
-rw-r--r--kern/console.c201
-rw-r--r--kern/hvcall.c53
-rw-r--r--kern/inc/console.h94
-rw-r--r--kern/inc/sched.h2
-rw-r--r--kern/inc/usermem.h2
-rw-r--r--kern/sched.c17
-rw-r--r--kern/syscall_io.c28
-rw-r--r--kern/syscall_thread.c4
-rw-r--r--kern/toad.c15
-rw-r--r--kern/usermem.c4
10 files changed, 211 insertions, 209 deletions
diff --git a/kern/console.c b/kern/console.c
index 2b25fcc..716ee50 100644
--- a/kern/console.c
+++ b/kern/console.c
@@ -15,26 +15,13 @@
#include <x86/video_defines.h>
#include <console.h>
-
-/** how many bits in a x86 byte */
-#define NUM_OF_BITS_X86 8
-/** Mask bits for a 8-bit byte */
-#define BYTE_MASK_X86 0xFF
+#include <sched.h>
/** index of the register to start displaying cursor */
#define CRTC_CURSOR_START 10
/** bit to start displaying cursor */
#define CURSOR_ENABLE_BIT 0x20
-/**
- * Someone is not satisfied with the type name char_t so we use this
- * to reperesent a char on screen so that nobody will mistake it with 'char'
- */
-typedef struct a_char_on_screen_s {
- uint8_t ch; /** char */
- uint8_t color; /** color */
-} a_char_on_screen_t;
-
/** pointer to the viedo memory at B800h */
a_char_on_screen_t (*console_mem)[CONSOLE_WIDTH] =
(a_char_on_screen_t(*)[CONSOLE_WIDTH])CONSOLE_MEM_BASE;
@@ -44,17 +31,18 @@ a_char_on_screen_t (*console_mem)[CONSOLE_WIDTH] =
/** initial color of the cursor */
#define DEFAULT_COLOR (FGND_WHITE | BGND_BLACK)
-/** x position of the cursor */
-static int cur_x = 0;
-/** y position of the cursor */
-static int cur_y = 0;
-/** current color of the cursor */
-static char cur_color = DEFAULT_COLOR;
-/** should the cursor be displayed? */
-static int cur_shown = true;
-
-/** mutex for console operations */
-mutex_t console_lock = MUTEX_INIT;
+pts_t* active_pts = NULL;
+spl_t pts_lock = SPL_INIT;
+queue_t* all_pts = NULL;
+
+void pts_init(pts_t* pts) {
+ pts->cur_x = pts->cur_y = 0;
+ pts->cur_color = DEFAULT_COLOR;
+ pts->cur_shown = 1;
+ pts->lock = MUTEX_INIT;
+ pts->refcount = 0;
+ queue_insert_head(&all_pts, &pts->pts_link);
+}
/**
* @brief Move the cursor to a position. Position is checked before calling this
@@ -62,151 +50,140 @@ mutex_t console_lock = MUTEX_INIT;
* @param x x
* @param y y
*/
-static void move_cursor(int x, int y) {
- cur_x = x;
- cur_y = y;
- int pos = y * CONSOLE_WIDTH + x;
- outb(CRTC_IDX_REG, CRTC_CURSOR_LSB_IDX);
- outb(CRTC_DATA_REG, pos & BYTE_MASK_X86);
- outb(CRTC_IDX_REG, CRTC_CURSOR_MSB_IDX);
- outb(CRTC_DATA_REG, pos >> NUM_OF_BITS_X86);
+static inline void move_cursor(pts_t* pts, int x, int y) {
+ pts->cur_x = x;
+ pts->cur_y = y;
+ int old_if = spl_lock(&pts_lock);
+ if (active_pts == pts) {
+ int pos = y * CONSOLE_WIDTH + x;
+ outb(CRTC_IDX_REG, CRTC_CURSOR_LSB_IDX);
+ outb(CRTC_DATA_REG, pos & 0xff);
+ outb(CRTC_IDX_REG, CRTC_CURSOR_MSB_IDX);
+ outb(CRTC_DATA_REG, pos >> 8);
+ }
+ spl_unlock(&pts_lock, old_if);
}
/**
* @brief Scroll the console by one line and clean the last line
*/
-static void scroll_page() {
+static inline void scroll_page(pts_t* pts) {
/* move all but last line forward */
- memmove(console_mem[0], console_mem[1],
+ memmove(pts->mem[0], pts->mem[1],
sizeof(a_char_on_screen_t) * CONSOLE_WIDTH * (CONSOLE_HEIGHT - 1));
int i;
for (i = 0; i < CONSOLE_WIDTH; i++) {
- console_mem[CONSOLE_HEIGHT - 1][i] =
- (a_char_on_screen_t){BLANK_CH, cur_color};
+ pts->mem[CONSOLE_HEIGHT - 1][i] =
+ (a_char_on_screen_t){BLANK_CH, pts->cur_color};
}
+ int old_if = spl_lock(&pts_lock);
+ if (active_pts == pts) {
+ memmove(
+ console_mem[0], console_mem[1],
+ sizeof(a_char_on_screen_t) * CONSOLE_WIDTH * (CONSOLE_HEIGHT - 1));
+ int i;
+ for (i = 0; i < CONSOLE_WIDTH; i++) {
+ console_mem[CONSOLE_HEIGHT - 1][i] =
+ (a_char_on_screen_t){BLANK_CH, pts->cur_color};
+ }
+ }
+ spl_unlock(&pts_lock, old_if);
+}
+
+static inline void draw_char(pts_t* pts,
+ int row,
+ int col,
+ a_char_on_screen_t ch) {
+ pts->mem[row][col] = ch;
+ int old_if = spl_lock(&pts_lock);
+ if (active_pts == pts) {
+ console_mem[row][col] = ch;
+ }
+ spl_unlock(&pts_lock, old_if);
}
int putbyte(char ch) {
+ return pts_putbyte(get_current()->pts, ch);
+}
+
+int pts_putbyte(pts_t* pts, char ch) {
if (ch == '\n') {
- if (cur_y < CONSOLE_HEIGHT - 1) {
- move_cursor(0, cur_y + 1);
+ if (pts->cur_y < CONSOLE_HEIGHT - 1) {
+ move_cursor(pts, 0, pts->cur_y + 1);
} else {
- scroll_page();
- move_cursor(0, cur_y);
+ scroll_page(pts);
+ move_cursor(pts, 0, pts->cur_y);
}
return ch;
}
if (ch == '\r') {
- move_cursor(0, cur_y);
+ move_cursor(pts, 0, pts->cur_y);
return ch;
}
if (ch == '\b') {
- if (cur_x > 0) {
- move_cursor(cur_x - 1, cur_y);
+ if (pts->cur_x > 0) {
+ move_cursor(pts, pts->cur_x - 1, pts->cur_y);
- } else if (cur_y > 0) {
- move_cursor(CONSOLE_WIDTH - 1, cur_y - 1);
+ } else if (pts->cur_y > 0) {
+ move_cursor(pts, CONSOLE_WIDTH - 1, pts->cur_y - 1);
}
- console_mem[cur_y][cur_x] = (a_char_on_screen_t){BLANK_CH, cur_color};
+ a_char_on_screen_t c = {BLANK_CH, pts->cur_color};
+ draw_char(pts, pts->cur_y, pts->cur_x, c);
return ch;
}
/* save the position where we should show the char */
- int prev_x = cur_x, prev_y = cur_y;
- if (cur_x < CONSOLE_WIDTH - 1) {
+ int prev_x = pts->cur_x, prev_y = pts->cur_y;
+ if (pts->cur_x < CONSOLE_WIDTH - 1) {
/* move forward */
- move_cursor(cur_x + 1, cur_y);
- } else if (cur_y < CONSOLE_HEIGHT - 1) {
+ move_cursor(pts, pts->cur_x + 1, pts->cur_y);
+ } else if (pts->cur_y < CONSOLE_HEIGHT - 1) {
/* go to next line */
- move_cursor(0, cur_y + 1);
+ move_cursor(pts, 0, pts->cur_y + 1);
} else {
/* scroll and go to beginning of the line */
- scroll_page();
- move_cursor(0, cur_y);
+ scroll_page(pts);
+ move_cursor(pts, 0, pts->cur_y);
prev_y -= 1;
}
- console_mem[prev_y][prev_x] = (a_char_on_screen_t){ch, cur_color};
+ a_char_on_screen_t c = {ch, pts->cur_color};
+ draw_char(pts, prev_y, prev_x, c);
return ch;
}
-void putbytes(const char* s, int len) {
+void pts_putbytes(pts_t* pts, const char* s, int len) {
if (s == NULL || len <= 0) {
return;
}
int i;
for (i = 0; i < len; i++) {
- putbyte(s[i]);
- }
-}
-
-void draw_char(int row, int col, int ch, int color) {
- if (row >= CONSOLE_HEIGHT || row < 0) {
- return;
+ pts_putbyte(pts, s[i]);
}
- if (col >= CONSOLE_WIDTH || col < 0) {
- return;
- }
- if (color > BYTE_MASK_X86 || color < 0) {
- return;
- }
- console_mem[row][col] = (a_char_on_screen_t){ch, color};
}
-int set_term_color(int color) {
- if (color > BYTE_MASK_X86 || color < 0) {
+int pts_set_term_color(pts_t* pts, int color) {
+ if (color > 0xff || color < 0) {
return -1;
}
- cur_color = (char)color;
+ pts->cur_color = (char)color;
return 0;
}
-void get_term_color(int* color) {
- *color = cur_color;
+void pts_get_term_color(pts_t* pts, int* color) {
+ *color = pts->cur_color;
}
-int set_cursor(int row, int col) {
+int pts_set_cursor(pts_t* pts, int row, int col) {
if (row >= CONSOLE_HEIGHT || row < 0) {
return -1;
}
if (col >= CONSOLE_WIDTH || col < 0) {
return -1;
}
- move_cursor(col, row);
+ move_cursor(pts, col, row);
return 0;
}
-void get_cursor(int* row, int* col) {
- *row = cur_y;
- *col = cur_x;
-}
-
-void hide_cursor(void) {
- cur_shown = 0;
- outb(CRTC_IDX_REG, CRTC_CURSOR_START);
- outb(CRTC_DATA_REG, inb(CRTC_DATA_REG) | CURSOR_ENABLE_BIT);
-}
-
-void show_cursor(void) {
- cur_shown = 1;
- outb(CRTC_IDX_REG, CRTC_CURSOR_START);
- outb(CRTC_DATA_REG, inb(CRTC_DATA_REG) & ~CURSOR_ENABLE_BIT);
-}
-
-void clear_console(void) {
- move_cursor(0, 0);
- int i, j;
- for (i = 0; i < CONSOLE_HEIGHT - 1; i++) {
- for (j = 0; j < CONSOLE_WIDTH - 1; j++) {
- console_mem[i][j] = (a_char_on_screen_t){BLANK_CH, cur_color};
- }
- }
-}
-
-char get_char(int row, int col) {
- if (row >= CONSOLE_HEIGHT || row < 0) {
- return BLANK_CH;
- }
- if (col >= CONSOLE_WIDTH || col < 0) {
- return BLANK_CH;
- }
- return console_mem[row][col].ch;
+void pts_get_cursor(pts_t* pts, int* row, int* col) {
+ *row = pts->cur_y;
+ *col = pts->cur_x;
}
diff --git a/kern/hvcall.c b/kern/hvcall.c
index fb5eb95..65f3e42 100644
--- a/kern/hvcall.c
+++ b/kern/hvcall.c
@@ -549,9 +549,10 @@ static void hvcall_print(stack_frame_t* f) {
if (copy_from_user(esp + sizeof(va_t), sizeof(va_t), &base) != 0) {
goto read_arg_fail;
}
- mutex_lock(&console_lock);
- int result = print_buf_from_user(base, len);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ int result = print_buf_from_user(pts, base, len);
+ mutex_unlock(&pts->lock);
if (result != 0) {
goto print_fail;
}
@@ -571,9 +572,10 @@ static void hvcall_set_color(stack_frame_t* f) {
if (copy_from_user(esp, sizeof(int), &color) != 0) {
goto read_arg_fail;
}
- mutex_lock(&console_lock);
- int result = set_term_color(color);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ int result = pts_set_term_color(pts, color);
+ mutex_unlock(&pts->lock);
if (result != 0) {
goto set_fail;
}
@@ -594,9 +596,10 @@ static void hvcall_set_cursor(stack_frame_t* f) {
if (copy_from_user(esp + sizeof(va_t), sizeof(int), &col) != 0) {
goto read_arg_fail;
}
- mutex_lock(&console_lock);
- int result = set_cursor(row, col);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ int result = pts_set_cursor(pts, row, col);
+ mutex_unlock(&pts->lock);
if (result != 0) {
goto set_fail;
}
@@ -618,9 +621,10 @@ static void hvcall_get_cursor(stack_frame_t* f) {
goto read_arg_fail;
}
int row, col;
- mutex_lock(&console_lock);
- get_cursor(&row, &col);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ pts_get_cursor(pts, &row, &col);
+ mutex_unlock(&pts->lock);
if (copy_to_user(prow, sizeof(int), &row) != 0) {
goto bad_arg;
}
@@ -655,29 +659,30 @@ static void hvcall_print_at(stack_frame_t* f) {
if (copy_from_user(esp + 4 * sizeof(va_t), sizeof(int), &color) != 0) {
goto read_arg_fail;
}
- mutex_lock(&console_lock);
- get_cursor(&old_row, &old_col);
- if (set_cursor(row, col) != 0) {
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ pts_get_cursor(pts, &old_row, &old_col);
+ if (pts_set_cursor(pts, row, col) != 0) {
goto bad_pos;
}
- get_term_color(&old_color);
- if (set_term_color(color) != 0) {
+ pts_get_term_color(pts, &old_color);
+ if (pts_set_term_color(pts, color) != 0) {
goto bad_color;
}
- if (print_buf_from_user(base, len) != 0) {
+ if (print_buf_from_user(pts, base, len) != 0) {
goto bad_print;
}
- set_term_color(old_color);
- set_cursor(old_row, old_col);
- mutex_unlock(&console_lock);
+ pts_set_term_color(pts, old_color);
+ pts_set_cursor(pts, old_row, old_col);
+ mutex_unlock(&pts->lock);
return;
bad_print:
- set_term_color(old_color);
+ pts_set_term_color(pts, old_color);
bad_color:
- set_cursor(old_row, old_col);
+ pts_set_cursor(pts, old_row, old_col);
bad_pos:
- mutex_unlock(&console_lock);
+ mutex_unlock(&pts->lock);
pv_die("Bad argument");
read_arg_fail:
pv_die("Bad argument address");
diff --git a/kern/inc/console.h b/kern/inc/console.h
index a3649de..0d65922 100644
--- a/kern/inc/console.h
+++ b/kern/inc/console.h
@@ -26,12 +26,43 @@
#ifndef _CONSOLE_H
#define _CONSOLE_H
-#include <video_defines.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <x86/asm.h>
+#include <x86/video_defines.h>
+
+#include <common.h>
#include <sync.h>
-/** mutex for console operations */
-extern mutex_t console_lock;
+/**
+ * Someone is not satisfied with the type name char_t so we use this
+ * to reperesent a char on screen so that nobody will mistake it with 'char'
+ */
+typedef struct a_char_on_screen_s {
+ uint8_t ch; /** char */
+ uint8_t color; /** color */
+} a_char_on_screen_t;
+
+typedef struct pts_s {
+ queue_t pts_link;
+ int refcount;
+ mutex_t lock;
+ a_char_on_screen_t mem[CONSOLE_HEIGHT][CONSOLE_WIDTH];
+ int cur_x;
+ int cur_y;
+ char cur_color;
+ int cur_shown;
+} pts_t;
+
+extern pts_t* active_pts;
+extern spl_t pts_lock;
+
+void pts_init(pts_t* pts);
+
+int putbyte(char ch);
/** @brief Prints character ch at the current location
* of the cursor.
@@ -48,7 +79,7 @@ extern mutex_t console_lock;
* @param ch the character to print
* @return The input character
*/
-int putbyte(char ch);
+int pts_putbyte(pts_t* pts, char ch);
/** @brief Prints the string s, starting at the current
* location of the cursor.
@@ -67,7 +98,7 @@ int putbyte(char ch);
* @param len The length of the string s.
* @return Void.
*/
-void putbytes(const char* s, int len);
+void pts_putbytes(pts_t* pts, const char* s, int len);
/** @brief Changes the foreground and background color
* of future characters printed on the console.
@@ -78,7 +109,7 @@ void putbytes(const char* s, int len);
* @return 0 on success or integer error code less than 0 if
* color code is invalid.
*/
-int set_term_color(int color);
+int pts_set_term_color(pts_t* pts, int color);
/** @brief Writes the current foreground and background
* color of characters printed on the console
@@ -87,7 +118,7 @@ int set_term_color(int color);
* information will be written.
* @return Void.
*/
-void get_term_color(int* color);
+void pts_get_term_color(pts_t* pts, int* color);
/** @brief Sets the position of the cursor to the
* position (row, col).
@@ -102,7 +133,7 @@ void get_term_color(int* color);
* @return 0 on success or integer error code less than 0 if
* cursor location is invalid.
*/
-int set_cursor(int row, int col);
+int pts_set_cursor(pts_t* pts, int row, int col);
/** @brief Writes the current position of the cursor
* into the arguments row and col.
@@ -112,51 +143,6 @@ int set_cursor(int row, int col);
* column will be written.
* @return Void.
*/
-void get_cursor(int* row, int* col);
-
-/** @brief Hides the cursor.
- *
- * Subsequent calls to putbytes do not cause the
- * cursor to show again.
- *
- * @return Void.
- */
-void hide_cursor(void);
-
-/** @brief Shows the cursor.
- *
- * If the cursor is already shown, the function has no effect.
- *
- * @return Void.
- */
-void show_cursor(void);
-
-/** @brief Clears the entire console.
- *
- * The cursor is reset to the first row and column
- *
- * @return Void.
- */
-void clear_console(void);
-
-/** @brief Prints character ch with the specified color
- * at position (row, col).
- *
- * If any argument is invalid, the function has no effect.
- *
- * @param row The row in which to display the character.
- * @param col The column in which to display the character.
- * @param ch The character to display.
- * @param color The color to use to display the character.
- * @return Void.
- */
-void draw_char(int row, int col, int ch, int color);
-
-/** @brief Returns the character displayed at position (row, col).
- * @param row Row of the character.
- * @param col Column of the character.
- * @return The character at (row, col).
- */
-char get_char(int row, int col);
+void pts_get_cursor(pts_t* pts, int* row, int* col);
#endif /* _CONSOLE_H */
diff --git a/kern/inc/sched.h b/kern/inc/sched.h
index eddb849..718fdae 100644
--- a/kern/inc/sched.h
+++ b/kern/inc/sched.h
@@ -16,6 +16,7 @@
#include <x86/seg.h>
#include <common.h>
+#include <console.h>
#include <paging.h>
#include <pv.h>
#include <sync.h>
@@ -148,6 +149,7 @@ typedef struct thread_s {
queue_t process_link; /* in process_t's threads queue */
+ pts_t* pts;
process_t* process;
reg_t esp3;
diff --git a/kern/inc/usermem.h b/kern/inc/usermem.h
index c5622e8..2b90c1b 100644
--- a/kern/inc/usermem.h
+++ b/kern/inc/usermem.h
@@ -45,6 +45,6 @@ char* copy_string_from_user(va_t addr, int maxlen);
* @param maxlen maximum length of to print
* @return 0 on success, -1 on failure
*/
-int print_buf_from_user(va_t addr, int maxlen);
+int print_buf_from_user(pts_t* pts, va_t addr, int maxlen);
#endif
diff --git a/kern/sched.c b/kern/sched.c
index b0fd584..396c31d 100644
--- a/kern/sched.c
+++ b/kern/sched.c
@@ -15,6 +15,7 @@
#include <x86/seg.h>
#include <asm_instr.h>
+#include <console.h>
#include <loader.h>
#include <malloc.h>
#include <mm.h>
@@ -145,6 +146,10 @@ thread_t* create_empty_process() {
t->pending_exit = 0;
queue_insert_head(&p->threads, &t->process_link);
t->rb_node.parent = NULL; /* mark that the thread is not added to rbtree */
+ t->pts = get_current()->pts;
+ mutex_lock(&t->pts->lock);
+ t->pts->refcount++;
+ mutex_unlock(&t->pts->lock);
t->process = p;
t->eip3 = 0;
t->esp0 = t->kernel_esp = (reg_t)&t->stack[K_STACK_SIZE];
@@ -329,6 +334,9 @@ alloc_tcb_fail:
}
void destroy_thread(thread_t* t) {
+ mutex_lock(&t->pts->lock);
+ t->pts->refcount--;
+ mutex_unlock(&t->pts->lock);
process_t* p = t->process;
sfree(t->stack, K_STACK_SIZE);
sfree(t, sizeof(thread_t));
@@ -588,6 +596,7 @@ void swap_process_inplace(thread_t* newt) {
pa_t cr3 = oldp->cr3;
vector_t regions = oldp->regions;
queue_t* p_threads = oldp->threads;
+ pts_t* pts = oldt->pts;
pv_t* pv = oldp->pv;
oldp->cr3 = newp->cr3;
oldp->regions = newp->regions;
@@ -597,8 +606,10 @@ void swap_process_inplace(thread_t* newt) {
newp->regions = regions;
newp->threads = p_threads;
newp->pv = pv;
- newt->process = oldp;
oldt->process = newp;
+ oldt->pts = newt->pts;
+ newt->process = oldp;
+ newt->pts = pts;
set_cr3(newp->cr3);
mutex_lock(&threads_lock);
/* move oldt's rbtree node to newt */
@@ -654,6 +665,10 @@ void kill_current() {
}
}
+ mutex_lock(&current->pts->lock);
+ current->pts->refcount--;
+ mutex_unlock(&current->pts->lock);
+
if (current->rb_node.parent != NULL) {
remove_thread(current);
}
diff --git a/kern/syscall_io.c b/kern/syscall_io.c
index 3a9dc99..fafc4cb 100644
--- a/kern/syscall_io.c
+++ b/kern/syscall_io.c
@@ -41,9 +41,10 @@ void sys_print_real(stack_frame_t* f) {
if (copy_from_user((va_t)esi + sizeof(va_t), sizeof(va_t), &base) != 0) {
goto read_fail;
}
- mutex_lock(&console_lock);
- f->eax = (reg_t)print_buf_from_user(base, len);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ f->eax = (reg_t)print_buf_from_user(pts, base, len);
+ mutex_unlock(&pts->lock);
return;
read_fail:
@@ -60,9 +61,10 @@ bad_length:
*/
void sys_set_term_color_real(stack_frame_t* f) {
reg_t esi = f->esi;
- mutex_lock(&console_lock);
- f->eax = (reg_t)set_term_color((int)esi);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ f->eax = (reg_t)pts_set_term_color(pts, (int)esi);
+ mutex_unlock(&pts->lock);
}
/**
@@ -78,9 +80,10 @@ void sys_set_cursor_pos_real(stack_frame_t* f) {
if (copy_from_user((va_t)(esi + sizeof(va_t)), sizeof(int), &col) != 0) {
goto read_arg_fail;
}
- mutex_lock(&console_lock);
- f->eax = (reg_t)set_cursor(row, col);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ f->eax = (reg_t)pts_set_cursor(pts, row, col);
+ mutex_unlock(&pts->lock);
return;
read_arg_fail:
@@ -102,9 +105,10 @@ void sys_get_cursor_pos_real(stack_frame_t* f) {
goto read_arg_fail;
}
int row, col;
- mutex_lock(&console_lock);
- get_cursor(&row, &col);
- mutex_unlock(&console_lock);
+ pts_t* pts = get_current()->pts;
+ mutex_lock(&pts->lock);
+ pts_get_cursor(pts, &row, &col);
+ mutex_unlock(&pts->lock);
if (copy_to_user(prow, sizeof(int), &row) != 0) {
goto bad_arg;
}
diff --git a/kern/syscall_thread.c b/kern/syscall_thread.c
index d8984b0..2cb62d9 100644
--- a/kern/syscall_thread.c
+++ b/kern/syscall_thread.c
@@ -63,6 +63,10 @@ void sys_thread_fork_real(stack_frame_t* f) {
yf->eflags = DEFAULT_EFLAGS;
yf->raddr = (reg_t)return_to_user;
+ t->pts = get_current()->pts;
+ mutex_lock(&t->pts->lock);
+ t->pts->refcount++;
+ mutex_unlock(&t->pts->lock);
t->process = p;
mutex_lock(&p->refcount_lock);
p->refcount++;
diff --git a/kern/toad.c b/kern/toad.c
index a83deaf..86ce9c6 100644
--- a/kern/toad.c
+++ b/kern/toad.c
@@ -1,4 +1,5 @@
#include <console.h>
+#include <sched.h>
const char toad[] =
"..:. ......::.. ..^7JYYJJJJJYJJJJ??7~^:.. ^~^^:........ "
@@ -56,7 +57,15 @@ const char toad[] =
"........:^!J5PBBBBBB";
void print_toad() {
- set_cursor(0, 0);
- set_term_color(FGND_WHITE | BGND_BLACK);
- putbytes(toad, sizeof(toad) - 1);
+ pts_t* pts = smalloc(sizeof(pts_t));
+ pts_init(pts);
+ get_current()->pts = pts;
+ pts->refcount++;
+
+ active_pts = pts;
+ pts->refcount++;
+
+ pts_set_cursor(pts, 0, 0);
+ pts_set_term_color(pts, FGND_WHITE | BGND_BLACK);
+ pts_putbytes(pts, toad, sizeof(toad) - 1);
}
diff --git a/kern/usermem.c b/kern/usermem.c
index c4ce8d6..2d7c7b6 100644
--- a/kern/usermem.c
+++ b/kern/usermem.c
@@ -125,7 +125,7 @@ read_string_finished:
return buf;
}
-int print_buf_from_user(va_t addr, int len) {
+int print_buf_from_user(pts_t* pts, va_t addr, int len) {
reg_t old_eip0 = usermem_setup();
int i, result = 0;
char c;
@@ -134,7 +134,7 @@ int print_buf_from_user(va_t addr, int len) {
result = -1;
break;
}
- putbyte(c);
+ pts_putbyte(pts, c);
}
usermem_finish(old_eip0);
return result;