changeset 383:3f243b59bcee

move global variable in console.cbc to kernel_context
author anatofuz
date Mon, 20 Jul 2020 16:42:45 +0900
parents 663e69a94246
children 287581b5d348
files src/console.cbc src/gearsTools/lib/Gears/Context/Template/XV6.pm src/impl/KernelError.cbc src/spinlock.h
diffstat 4 files changed, 40 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/console.cbc	Mon Jul 20 15:10:40 2020 +0900
+++ b/src/console.cbc	Mon Jul 20 16:42:45 2020 +0900
@@ -12,6 +12,7 @@
 #include "mmu.h"
 #include "proc.h"
 
+#include "kernel.h"
 
 #define __ncode __code
 
@@ -20,12 +21,6 @@
 
 static void consputc (int);
 
-int panicked = 0;
-
-struct {
-    struct spinlock lock;
-    int locking;
-} cons;
 
 static void printint (int xx, int base, int sign)
 {
@@ -63,10 +58,11 @@
     uint *argp;
     char *s;
 
-    locking = cons.locking;
+    struct cons_arg* cons = &kernel_context->cons_arg;
+    locking = cons->locking;
 
     if (locking) {
-        acquire(&cons.lock);
+        acquire(&cons->lock);
     }
 
     if (fmt == 0) {
@@ -120,7 +116,7 @@
     }
 
     if (locking) {
-        release(&cons.lock);
+        release(&cons->lock);
     }
 }
 
@@ -128,12 +124,14 @@
 {
     cli();
 
-    cons.locking = 0;
+    struct cons_arg* cons = &kernel_context->cons_arg;
+    cons->locking = 0;
 
     cprintf("cpu%d: panic: ", cpu->id);
 
     show_callstk(s);
-    panicked = 1; // freeze other CPU
+    int* panicked = &kernel_context->panicked;
+    *panicked = 1; // freeze other CPU
 
     while (1)
         ;
@@ -143,12 +141,14 @@
 {
     cli();
 
-    cons.locking = 0;
+    struct cons_arg* cons = &kernel_context->cons_arg;
+    cons->locking = 0;
 
     cprintf("cpu%d: panic: ", cpu->id);
 
     show_callstk(s);
-    panicked = 1; // freeze other CPU
+    int* panicked = &kernel_context->panicked;
+    *panicked = 1; // freeze other CPU
 
     while (1)
         ;
@@ -160,7 +160,8 @@
 
 void consputc (int c)
 {
-    if (panicked) {
+    int* panicked = &kernel_context->panicked;
+    if (*panicked) {
         cli();
         while (1)
             ;
@@ -368,13 +369,14 @@
 
     iunlock(ip);
 
-    acquire(&cons.lock);
+    struct cons_arg* cons = &kernel_context->cons_arg;
+    acquire(&cons->lock);
 
     for (i = 0; i < n; i++) {
         consputc(buf[i] & 0xff);
     }
 
-    release(&cons.lock);
+    release(&cons->lock);
 
     ilock(ip);
 
@@ -383,7 +385,8 @@
 
 void consoleinit (void)
 {
-    initlock(&cons.lock, "console");
+    struct cons_arg* cons = &kernel_context->cons_arg;
+    initlock(&cons->lock, "console");
     initlock(&input.lock, "input");
 
     devsw[CONSOLE].write = consolewrite;
@@ -391,6 +394,6 @@
     //cbc_devsw[CONSOLE].write = cbc_consolewrite;
     cbc_devsw[CONSOLE].read = cbc_consoleread;
 
-    cons.locking = 1;
+    cons->locking = 1;
 }
 
--- a/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Mon Jul 20 15:10:40 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Mon Jul 20 16:42:45 2020 +0900
@@ -173,13 +173,23 @@
 
 };
 
+#include "spinlock.h"
+struct cons_arg {
+    struct spinlock lock;
+    int locking;
+};
+typedef struct cons_arg cons_arg;
+
 typedef struct KernelContext {
     struct Context context;
     __code (*syscalls[10]) (void);
     struct Context* proc_contexts[NPROC];
     struct proc* now_proc;
+    int panicked;
+    struct cons_arg cons_arg;
 } KernelContext;
 
+
 #include "spinlock.h"
 typedef int Int;
 #ifndef USE_CUDAWorker
--- a/src/impl/KernelError.cbc	Mon Jul 20 15:10:40 2020 +0900
+++ b/src/impl/KernelError.cbc	Mon Jul 20 16:42:45 2020 +0900
@@ -2,6 +2,8 @@
 #include "proc.h"
 #interface "Err.h"
 
+#include "kernel.h"
+
 // ----
 // typedef struct KernelError <Type, Isa> impl Error {
 //   __code infinity_loop(Type* error, next(...));
@@ -29,13 +31,17 @@
 }
 
 __code panicKernelError(struct KernelError* err, char* msg) {
+    struct cons_arg* cons = &kernel_context->cons_arg;
+    int* panicked = &kernel_context->panicked;
+
     cli();
-    cons.locking = 0;
+
+    cons->locking = 0;
 
     cprintf("cpu%d: panic: ", cpu->id);
 
     show_callstk(msg);
-    panicked = 1; // freeze other CPU
+    *panicked = 1; // freeze other CPU
 
     goto infinity_loopKernelError(err, err->inifinity_loop);
 }
--- a/src/spinlock.h	Mon Jul 20 15:10:40 2020 +0900
+++ b/src/spinlock.h	Mon Jul 20 16:42:45 2020 +0900
@@ -9,5 +9,5 @@
     uint        pcs[10];    // The call stack (an array of program counters)
     // that locked the lock.
 };
+#define SPINLOCK_H
 #endif // SPINLOCK_H
-#define SPINLOCK_H