Patches to make Bochs 2.6.2 work with Pintos
[pintos-anon] / solutions / p1.patch
index 046989fbba893eaec65b4f849aeaef170ca09021..8ebd1e9e911d6b7f30826fd33b20158e867682a9 100644 (file)
@@ -1,7 +1,8 @@
-diff -Nur ../../src/devices/timer.c src/devices/timer.c
---- ../../src/devices/timer.c  2008-08-27 08:04:38.000000000 -0400
-+++ src/devices/timer.c        2008-08-27 12:42:33.000000000 -0400
-@@ -24,6 +24,9 @@
+diff --git a/src/devices/timer.c b/src/devices/timer.c
+index befaaae..1aebae7 100644
+--- a/src/devices/timer.c
++++ b/src/devices/timer.c
+@@ -24,6 +24,9 @@ static int64_t ticks;
     Initialized by timer_calibrate(). */
  static unsigned loops_per_tick;
  
@@ -11,16 +12,16 @@ diff -Nur ../../src/devices/timer.c src/devices/timer.c
  static intr_handler_func timer_interrupt;
  static bool too_many_loops (unsigned loops);
  static void busy_wait (int64_t loops);
-@@ -45,6 +48,8 @@
-   outb (0x40, count >> 8);
+@@ -37,6 +40,8 @@ timer_init (void)
+ {
+   pit_configure_channel (0, 2, TIMER_FREQ);
    intr_register_ext (0x20, timer_interrupt, "8254 Timer");
 +
 +  list_init (&wait_list);
  }
  
  /* Calibrates loops_per_tick, used to implement brief delays. */
-@@ -93,16 +98,37 @@
+@@ -84,16 +89,37 @@ timer_elapsed (int64_t then)
    return timer_ticks () - then;
  }
  
@@ -61,7 +62,7 @@ diff -Nur ../../src/devices/timer.c src/devices/timer.c
  }
  
  /* Sleeps for approximately MS milliseconds.  Interrupts must be
-@@ -181,6 +207,17 @@
+@@ -172,6 +198,17 @@ timer_interrupt (struct intr_frame *args UNUSED)
  {
    ticks++;
    thread_tick ();
@@ -79,9 +80,11 @@ diff -Nur ../../src/devices/timer.c src/devices/timer.c
  }
  
  /* Returns true if LOOPS iterations waits for more than one timer
-diff -Nur ../../src/threads/fixed-point.h src/threads/fixed-point.h
---- ../../src/threads/fixed-point.h    1969-12-31 19:00:00.000000000 -0500
-+++ src/threads/fixed-point.h  2008-08-27 12:42:33.000000000 -0400
+diff --git a/src/threads/fixed-point.h b/src/threads/fixed-point.h
+new file mode 100644
+index 0000000..ca88f97
+--- /dev/null
++++ b/src/threads/fixed-point.h
 @@ -0,0 +1,120 @@
 +#ifndef THREADS_FIXED_POINT_H
 +#define THREADS_FIXED_POINT_H
@@ -203,10 +206,11 @@ diff -Nur ../../src/threads/fixed-point.h src/threads/fixed-point.h
 +}
 +
 +#endif /* threads/fixed-point.h */
-diff -Nur ../../src/threads/synch.c src/threads/synch.c
---- ../../src/threads/synch.c  2006-07-20 22:05:37.000000000 -0400
-+++ src/threads/synch.c        2008-08-27 12:42:33.000000000 -0400
-@@ -113,10 +113,28 @@
+diff --git a/src/threads/synch.c b/src/threads/synch.c
+index 317c68a..53197bb 100644
+--- a/src/threads/synch.c
++++ b/src/threads/synch.c
+@@ -113,10 +113,28 @@ sema_up (struct semaphore *sema)
    ASSERT (sema != NULL);
  
    old_level = intr_disable ();
@@ -238,7 +242,7 @@ diff -Nur ../../src/threads/synch.c src/threads/synch.c
    intr_set_level (old_level);
  }
  
-@@ -192,12 +210,33 @@
+@@ -192,12 +210,33 @@ lock_init (struct lock *lock)
  void
  lock_acquire (struct lock *lock)
  {
@@ -272,7 +276,7 @@ diff -Nur ../../src/threads/synch.c src/threads/synch.c
  }
  
  /* Tries to acquires LOCK and returns true if successful or false
-@@ -228,11 +267,39 @@
+@@ -228,11 +267,39 @@ lock_try_acquire (struct lock *lock)
  void
  lock_release (struct lock *lock) 
  {
@@ -312,7 +316,7 @@ diff -Nur ../../src/threads/synch.c src/threads/synch.c
  }
  
  /* Returns true if the current thread holds LOCK, false
-@@ -251,6 +318,7 @@
+@@ -251,6 +318,7 @@ struct semaphore_elem
    {
      struct list_elem elem;              /* List element. */
      struct semaphore semaphore;         /* This semaphore. */
@@ -320,7 +324,7 @@ diff -Nur ../../src/threads/synch.c src/threads/synch.c
    };
  
  /* Initializes condition variable COND.  A condition variable
-@@ -295,12 +363,26 @@
+@@ -295,12 +363,26 @@ cond_wait (struct condition *cond, struct lock *lock)
    ASSERT (lock_held_by_current_thread (lock));
    
    sema_init (&waiter.semaphore, 0);
@@ -347,7 +351,7 @@ diff -Nur ../../src/threads/synch.c src/threads/synch.c
  /* If any threads are waiting on COND (protected by LOCK), then
     this function signals one of them to wake up from its wait.
     LOCK must be held before calling this function.
-@@ -317,8 +399,12 @@
+@@ -317,8 +399,12 @@ cond_signal (struct condition *cond, struct lock *lock UNUSED)
    ASSERT (lock_held_by_current_thread (lock));
  
    if (!list_empty (&cond->waiters)) 
@@ -362,9 +366,10 @@ diff -Nur ../../src/threads/synch.c src/threads/synch.c
  }
  
  /* Wakes up all threads, if any, waiting on COND (protected by
-diff -Nur ../../src/threads/thread.c src/threads/thread.c
---- ../../src/threads/thread.c 2008-08-27 13:06:01.000000000 -0400
-+++ src/threads/thread.c       2008-08-27 13:14:12.000000000 -0400
+diff --git a/src/threads/thread.c b/src/threads/thread.c
+index 87f22b8..86614f5 100644
+--- a/src/threads/thread.c
++++ b/src/threads/thread.c
 @@ -5,11 +5,13 @@
  #include <stdio.h>
  #include <string.h>
@@ -379,7 +384,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  #include "threads/vaddr.h"
  #ifdef USERPROG
  #include "userprog/process.h"
-@@ -53,6 +55,7 @@
+@@ -53,6 +55,7 @@ static long long user_ticks;    /* # of timer ticks in user programs. */
  /* Scheduling. */
  #define TIME_SLICE 4            /* # of timer ticks to give each thread. */
  static unsigned thread_ticks;   /* # of timer ticks since last yield. */
@@ -387,7 +392,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  
  /* If false (default), use round-robin scheduler.
     If true, use multi-level feedback queue scheduler.
-@@ -92,6 +95,7 @@
+@@ -92,6 +95,7 @@ thread_init (void)
    lock_init (&tid_lock);
    list_init (&ready_list);
    list_init (&all_list);
@@ -395,7 +400,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  
    /* Set up a thread structure for the running thread. */
    initial_thread = running_thread ();
-@@ -117,6 +121,18 @@
+@@ -117,6 +121,18 @@ thread_start (void)
    sema_down (&idle_started);
  }
  
@@ -414,7 +419,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  /* Called by the timer interrupt handler at each timer tick.
     Thus, this function runs in an external interrupt context. */
  void
-@@ -134,9 +150,41 @@
+@@ -134,9 +150,41 @@ thread_tick (void)
    else
      kernel_ticks++;
  
@@ -459,7 +464,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  }
  
  /* Prints thread statistics. */
-@@ -166,12 +214,13 @@
+@@ -166,6 +214,7 @@ tid_t
  thread_create (const char *name, int priority,
                 thread_func *function, void *aux) 
  {
@@ -467,14 +472,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
    struct thread *t;
    struct kernel_thread_frame *kf;
    struct switch_entry_frame *ef;
-   struct switch_threads_frame *sf;
--  tid_t tid;
-   enum intr_level old_level;
-+  tid_t tid;
-   ASSERT (function != NULL);
-@@ -181,8 +230,10 @@
+@@ -180,8 +229,10 @@ thread_create (const char *name, int priority,
      return TID_ERROR;
  
    /* Initialize thread. */
@@ -484,9 +482,9 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
 +  t->nice = cur->nice;
 +  t->recent_cpu = cur->recent_cpu;
  
-   /* Prepare thread for first run by initializing its stack.
-      Do this atomically so intermediate values for the 'stack' 
-@@ -208,6 +259,8 @@
+   /* Stack frame for kernel_thread(). */
+   kf = alloc_frame (t, sizeof *kf);
+@@ -200,6 +251,8 @@ thread_create (const char *name, int priority,
  
    /* Add to run queue. */
    thread_unblock (t);
@@ -495,7 +493,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  
    return tid;
  }
-@@ -228,6 +281,19 @@
+@@ -220,6 +273,19 @@ thread_block (void)
    schedule ();
  }
  
@@ -515,7 +513,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  /* Transitions a blocked thread T to the ready-to-run state.
     This is an error if T is not blocked.  (Use thread_yield() to
     make the running thread ready.)
-@@ -339,11 +405,26 @@
+@@ -331,11 +397,26 @@ thread_foreach (thread_action_func *func, void *aux)
      }
  }
  
@@ -545,7 +543,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  }
  
  /* Returns the current thread's priority. */
-@@ -355,33 +436,98 @@
+@@ -347,33 +428,98 @@ thread_get_priority (void)
  
  /* Sets the current thread's nice value to NICE. */
  void
@@ -654,22 +652,20 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  }
  \f
  /* Idle thread.  Executes when no other thread is ready to run.
-@@ -467,11 +613,13 @@
+@@ -461,9 +607,10 @@ init_thread (struct thread *t, const char *name, int priority)
    t->status = THREAD_BLOCKED;
    strlcpy (t->name, name, sizeof t->name);
    t->stack = (uint8_t *) t + PGSIZE;
 -  t->priority = priority;
 +  t->priority = t->normal_priority = priority;
    t->magic = THREAD_MAGIC;
+-
 +  sema_init (&t->timer_sema, 0);
 +  list_init (&t->donors);
    old_level = intr_disable ();
    list_push_back (&all_list, &t->allelem);
    intr_set_level (old_level);
- }
-@@ -495,8 +643,14 @@
+@@ -492,8 +639,14 @@ next_thread_to_run (void)
  {
    if (list_empty (&ready_list))
      return idle_thread;
@@ -686,9 +682,10 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c
  }
  
  /* Completes a thread switch by activating the new thread's page
-diff -Nur ../../src/threads/thread.h src/threads/thread.h
---- ../../src/threads/thread.h 2008-08-27 08:45:26.000000000 -0400
-+++ src/threads/thread.h       2008-08-27 12:45:31.000000000 -0400
+diff --git a/src/threads/thread.h b/src/threads/thread.h
+index 7965c06..6601963 100644
+--- a/src/threads/thread.h
++++ b/src/threads/thread.h
 @@ -4,6 +4,8 @@
  #include <debug.h>
  #include <list.h>
@@ -698,7 +695,7 @@ diff -Nur ../../src/threads/thread.h src/threads/thread.h
  
  /* States in a thread's life cycle. */
  enum thread_status
-@@ -87,12 +89,26 @@
+@@ -87,12 +89,26 @@ struct thread
      enum thread_status status;          /* Thread state. */
      char name[16];                      /* Name (for debugging purposes). */
      uint8_t *stack;                     /* Saved stack pointer. */
@@ -726,7 +723,7 @@ diff -Nur ../../src/threads/thread.h src/threads/thread.h
  #ifdef USERPROG
      /* Owned by userprog/process.c. */
      uint32_t *pagedir;                  /* Page directory. */
-@@ -125,6 +141,10 @@
+@@ -125,6 +141,10 @@ const char *thread_name (void);
  
  void thread_exit (void) NO_RETURN;
  void thread_yield (void);