From 4e8ef5f37833c0c880ff55a1735bd2725374a096 Mon Sep 17 00:00:00 2001
From: Abinader <abinade2@illinois.edu>
Date: Mon, 23 Apr 2018 15:58:01 -0500
Subject: [PATCH] terminal switch working, but buffers are wrong

---
 student-distrib/kernel.c   |  4 ++--
 student-distrib/paging.c   | 30 ++++++++++++++++++++++++++++--
 student-distrib/paging.h   |  2 ++
 student-distrib/terminal.c |  8 +++++---
 student-distrib/terminal.h |  3 +++
 5 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/student-distrib/kernel.c b/student-distrib/kernel.c
index e5f8a61..00b9854 100644
--- a/student-distrib/kernel.c
+++ b/student-distrib/kernel.c
@@ -193,8 +193,8 @@ void entry(unsigned long magic, unsigned long addr) {
     //launch_tests();
 #endif
     /* Execute the first program ("shell") ... */
-    //if(switch_terminal(0) == 0)
-        execute((uint8_t*) "shell");
+    switch_terminal(0);
+    execute((uint8_t*) "shell");
 
     /* Spin (nicely, so we don't chew up cycles) */
     asm volatile (".1: hlt; jmp .1;");
diff --git a/student-distrib/paging.c b/student-distrib/paging.c
index 86698e2..9bdd3d6 100644
--- a/student-distrib/paging.c
+++ b/student-distrib/paging.c
@@ -43,13 +43,37 @@ void paging_initi(void){
     return;
 }
 
+
+
+
+
+
+//term_id = current
+void remap1(int32_t term_id){
+    page_table[ 0xB8 + term_id + 1] = ((uint32_t)(0xB8000 + (term_id+1)*0x1000 )) | USER | READ_WRITE | PRESENT;
+    flush_tlb();
+    return;
+}
+
+
+//term_id = ther terminal we want to display
+void remap2(int32_t term_id){
+    page_table[ 0xB8 + term_id + 1] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT;
+    flush_tlb();
+    return;
+}
+
+
+
+
+
 /* remap_vidmem
  * Inputs: PID number of process
  * Return Value: void
  * Function: Initialises page for video memory
  */
 uint8_t* remap_vidmem(uint32_t pid){
-
+    
     int32_t addr = VIDEO_MEM + pid * 4 + 3; //3 = offset for multiple terminals
 
     page_table[addr] = VIDEO_ADDR | USER | READ_WRITE | PRESENT;
@@ -90,7 +114,9 @@ void remap_term(int32_t term_id){
     if (control.cur_terminal == term_id)
         addr = TERM_VID;
 
-	page_table[VIDEO_MEM] = addr | USER | READ_WRITE | PRESENT;
+	//page_table[VIDEO_MEM] = addr | USER | READ_WRITE | PRESENT;
+    page_directory[33] = ((uint32_t)vid_table) | USER | READ_WRITE | PRESENT ;
+    vid_table[VIDEO_MEM] = addr | USER | READ_WRITE | PRESENT;
 
     // flush TLB
 	flush_tlb();
diff --git a/student-distrib/paging.h b/student-distrib/paging.h
index 1711f89..3bae8d9 100644
--- a/student-distrib/paging.h
+++ b/student-distrib/paging.h
@@ -58,6 +58,8 @@ void loadPageDirectory(unsigned int*);
  */
 void enablePaging(void);
 
+extern void remap1(int32_t term_id);
+extern void remap2(int32_t term_id);
 
 
 extern uint8_t* remap_vidmem(uint32_t pid);
diff --git a/student-distrib/terminal.c b/student-distrib/terminal.c
index 39b7bfa..c18b3fa 100644
--- a/student-distrib/terminal.c
+++ b/student-distrib/terminal.c
@@ -202,11 +202,13 @@ int32_t switch_terminal(int32_t term_id)
     control.cur_terminal = term_id;
     control.visible_terminal = term_id;
 
+    //restore paging from 0xb8000 to prev_terminal video mapping
+    remap1(prev_terminal);
+
     //store previous terminal data into memory
     memcpy( (void*)control.terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB );
 
-    //restore paging from 0xb8000 to prev_terminal video mapping
-    remap_term(prev_terminal);
+    
 
     //clear();
     
@@ -214,7 +216,7 @@ int32_t switch_terminal(int32_t term_id)
     memcpy( (void*)TERM_VID, (const void*)control.terminal[control.cur_terminal].vid_mem, _4_KB );
 
     //set new terminal to update to physical video memory
-    remap_term(control.cur_terminal);
+    remap2(control.cur_terminal);
 
     update_cursor();
 
diff --git a/student-distrib/terminal.h b/student-distrib/terminal.h
index 17b2648..6709b04 100644
--- a/student-distrib/terminal.h
+++ b/student-distrib/terminal.h
@@ -15,6 +15,9 @@ extern int32_t terminal_write(int32_t fd, const void* buf, int32_t nbytes);
 extern int32_t terminal_open(const uint8_t* filename);
 extern int32_t terminal_close(int32_t fd);
 
+void remap1(int32_t term_id);
+void remap2(int32_t term_id);
+
 extern int32_t switch_terminal(int32_t term_id);
 
 void init_terminal(void);
-- 
GitLab