Index: generic/src/debug/print.c
===================================================================
--- generic/src/debug/print.c	(revision 169c408f8774661800aa0a9685c9914cbb5a974c)
+++ generic/src/debug/print.c	(revision c4e8ed9d860723e9a528a63a1c23c93516a1e0ba)
@@ -42,5 +42,69 @@
 #define DEFAULT_DOUBLE_BUFFER_SIZE 128
 
-void print_double(double num, __u8 modifier, __u16 precision) 
+
+/** Print NULL terminated string
+ *
+ * Print characters from str using putchar() until
+ * \\0 character is reached.
+ *
+ * @param str Characters to print.
+ *
+ */
+static void print_str(const char *str)
+{
+	int i = 0;
+	char c;
+	
+	while (c = str[i++])
+		putchar(c);
+}
+
+
+/** Print hexadecimal digits
+ *
+ * Print fixed count of hexadecimal digits from
+ * the number num. The digits are printed in
+ * natural left-to-right order starting with
+ * the width-th digit.
+ *
+ * @param num   Number containing digits.
+ * @param width Count of digits to print.
+ *
+ */
+static void print_fixed_hex(const __u64 num, const int width)
+{
+	int i;
+    
+	for (i = width*8 - 4; i >= 0; i -= 4)
+	    putchar(digits[(num>>i) & 0xf]);
+}
+
+
+/** Print number in given base
+ *
+ * Print significant digits of a number in given
+ * base.
+ *
+ * @param num  Number to print.
+ * @param base Base to print the number in (should
+ *             be in range 2 .. 16).
+ *
+ */
+static void print_number(const __native num, const unsigned int base)
+{
+	int val = num;
+	char d[sizeof(__native)*8+1];		/* this is good enough even for base == 2 */
+	int i = sizeof(__native)*8-1;
+	
+	do {
+		d[i--] = digits[val % base];
+	} while (val /= base);
+	
+	d[sizeof(__native)*8] = 0;	
+	print_str(&d[i + 1]);
+}
+
+
+static void print_double(double num, __u8 modifier, __u16 precision) 
 {
 	double intval,intval2;
@@ -143,66 +207,4 @@
 }
 
-/** Print NULL terminated string
- *
- * Print characters from str using putchar() until
- * \\0 character is reached.
- *
- * @param str Characters to print.
- *
- */
-void print_str(const char *str)
-{
-	int i = 0;
-	char c;
-	
-	while (c = str[i++])
-		putchar(c);
-}
-
-
-/** Print hexadecimal digits
- *
- * Print fixed count of hexadecimal digits from
- * the number num. The digits are printed in
- * natural left-to-right order starting with
- * the width-th digit.
- *
- * @param num   Number containing digits.
- * @param width Count of digits to print.
- *
- */
-void print_fixed_hex(const __u64 num, const int width)
-{
-	int i;
-    
-	for (i = width*8 - 4; i >= 0; i -= 4)
-	    putchar(digits[(num>>i) & 0xf]);
-}
-
-
-/** Print number in given base
- *
- * Print significant digits of a number in given
- * base.
- *
- * @param num  Number to print.
- * @param base Base to print the number in (should
- *             be in range 2 .. 16).
- *
- */
-void print_number(const __native num, const unsigned int base)
-{
-	int val = num;
-	char d[sizeof(__native)*8+1];		/* this is good enough even for base == 2 */
-	int i = sizeof(__native)*8-1;
-	
-	do {
-		d[i--] = digits[val % base];
-	} while (val /= base);
-	
-	d[sizeof(__native)*8] = 0;	
-	print_str(&d[i + 1]);
-}
-
 
 /** General formatted text print
Index: generic/src/main/kinit.c
===================================================================
--- generic/src/main/kinit.c	(revision 169c408f8774661800aa0a9685c9914cbb5a974c)
+++ generic/src/main/kinit.c	(revision c4e8ed9d860723e9a528a63a1c23c93516a1e0ba)
@@ -123,9 +123,12 @@
 	 */
 	m = vm_create(NULL);
-	if (!m)	panic("vm_create");
+	if (!m)
+		panic("vm_create");
 	u = task_create(m);
-	if (!u)	panic("task_create");
+	if (!u)
+		panic("task_create");
 	t = thread_create(uinit, NULL, u, THREAD_USER_STACK);
-	if (!t) panic("thread_create");
+	if (!t)
+		panic("thread_create");
 
 	/*
@@ -133,5 +136,6 @@
 	 */	
 	a = vm_area_create(m, VMA_TEXT, 1, UTEXT_ADDRESS);
-	if (!a) panic("vm_area_create: vm_text");
+	if (!a)
+		panic("vm_area_create: vm_text");
 	vm_area_map(a, m);
 	memcpy((void *) PA2KA(a->mapping[0]), (void *) utext, utext_size < PAGE_SIZE ? utext_size : PAGE_SIZE);
@@ -141,5 +145,6 @@
 	 */
 	a = vm_area_create(m, VMA_STACK, 1, USTACK_ADDRESS);
-	if (!a) panic("vm_area_create: vm_stack");
+	if (!a)
+		panic("vm_area_create: vm_stack");
 	vm_area_map(a, m);	
 	
Index: generic/src/proc/scheduler.c
===================================================================
--- generic/src/proc/scheduler.c	(revision 169c408f8774661800aa0a9685c9914cbb5a974c)
+++ generic/src/proc/scheduler.c	(revision c4e8ed9d860723e9a528a63a1c23c93516a1e0ba)
@@ -117,5 +117,5 @@
  *
  */
-struct thread *find_best_thread(void)
+static struct thread *find_best_thread(void)
 {
 	thread_t *t;
@@ -223,5 +223,5 @@
  *
  */
-void relink_rq(int start)
+static void relink_rq(int start)
 {
 	link_t head;
@@ -255,4 +255,144 @@
 
 
+/** Scheduler stack switch wrapper
+ *
+ * Second part of the scheduler() function
+ * using new stack. Handling the actual context
+ * switch to a new thread.
+ *
+ */
+static void scheduler_separated_stack(void)
+{
+	int priority;
+
+	ASSERT(CPU != NULL);
+
+	if (THREAD) {
+		switch (THREAD->state) {
+		    case Running:
+			THREAD->state = Ready;
+			spinlock_unlock(&THREAD->lock);
+			thread_ready(THREAD);
+			break;
+
+		    case Exiting:
+			frame_free((__address) THREAD->kstack);
+			if (THREAD->ustack) {
+				frame_free((__address) THREAD->ustack);
+			}
+
+			/*
+			 * Detach from the containing task.
+			 */
+			spinlock_lock(&TASK->lock);
+			list_remove(&THREAD->th_link);
+			spinlock_unlock(&TASK->lock);
+
+			spinlock_unlock(&THREAD->lock);
+    
+			spinlock_lock(&threads_lock);
+			list_remove(&THREAD->threads_link);
+			spinlock_unlock(&threads_lock);
+
+			spinlock_lock(&CPU->lock);
+			if(CPU->fpu_owner==THREAD) CPU->fpu_owner=NULL;
+			spinlock_unlock(&CPU->lock);
+
+			free(THREAD);
+
+			break;
+    
+		    case Sleeping:
+			/*
+			 * Prefer the thread after it's woken up.
+			 */
+			THREAD->priority = -1;
+
+			/*
+			 * We need to release wq->lock which we locked in waitq_sleep().
+			 * Address of wq->lock is kept in THREAD->sleep_queue.
+			 */
+			spinlock_unlock(&THREAD->sleep_queue->lock);
+
+			/*
+			 * Check for possible requests for out-of-context invocation.
+			 */
+			if (THREAD->call_me) {
+				THREAD->call_me(THREAD->call_me_with);
+				THREAD->call_me = NULL;
+				THREAD->call_me_with = NULL;
+			}
+
+			spinlock_unlock(&THREAD->lock);
+
+			break;
+
+		    default:
+			/*
+			 * Entering state is unexpected.
+			 */
+			panic("tid%d: unexpected state %s\n", THREAD->tid, thread_states[THREAD->state]);
+			break;
+		}
+		THREAD = NULL;
+	}
+
+
+	THREAD = find_best_thread();
+	
+	spinlock_lock(&THREAD->lock);
+	priority = THREAD->priority;
+	spinlock_unlock(&THREAD->lock);	
+
+	relink_rq(priority);		
+
+	spinlock_lock(&THREAD->lock);	
+
+	/*
+	 * If both the old and the new task are the same, lots of work is avoided.
+	 */
+	if (TASK != THREAD->task) {
+		vm_t *m1 = NULL;
+		vm_t *m2;
+
+		if (TASK) {
+			spinlock_lock(&TASK->lock);
+			m1 = TASK->vm;
+			spinlock_unlock(&TASK->lock);
+		}
+
+		spinlock_lock(&THREAD->task->lock);
+		m2 = THREAD->task->vm;
+		spinlock_unlock(&THREAD->task->lock);
+		
+		/*
+		 * Note that it is possible for two tasks to share one vm mapping.
+		 */
+		if (m1 != m2) {
+			/*
+			 * Both tasks and vm mappings are different.
+			 * Replace the old one with the new one.
+			 */
+			vm_install(m2);
+		}
+		TASK = THREAD->task;	
+	}
+
+	THREAD->state = Running;
+
+	#ifdef SCHEDULER_VERBOSE
+	printf("cpu%d: tid %d (priority=%d,ticks=%d,nrdy=%d)\n", CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks, CPU->nrdy);
+	#endif	
+
+	/*
+	 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to thread's stack.
+	 */
+	the_copy(THE, (the_t *) THREAD->kstack);
+	
+	context_restore(&THREAD->saved_context);
+	/* not reached */
+}
+
+
 /** The scheduler
  *
@@ -320,142 +460,5 @@
 
 
-/** Scheduler stack switch wrapper
- *
- * Second part of the scheduler() function
- * using new stack. Handling the actual context
- * switch to a new thread.
- *
- */
-void scheduler_separated_stack(void)
-{
-	int priority;
-
-	ASSERT(CPU != NULL);
-
-	if (THREAD) {
-		switch (THREAD->state) {
-		    case Running:
-			THREAD->state = Ready;
-			spinlock_unlock(&THREAD->lock);
-			thread_ready(THREAD);
-			break;
-
-		    case Exiting:
-			frame_free((__address) THREAD->kstack);
-			if (THREAD->ustack) {
-				frame_free((__address) THREAD->ustack);
-			}
-
-			/*
-			 * Detach from the containing task.
-			 */
-			spinlock_lock(&TASK->lock);
-			list_remove(&THREAD->th_link);
-			spinlock_unlock(&TASK->lock);
-
-			spinlock_unlock(&THREAD->lock);
-    
-			spinlock_lock(&threads_lock);
-			list_remove(&THREAD->threads_link);
-			spinlock_unlock(&threads_lock);
-
-			spinlock_lock(&CPU->lock);
-			if(CPU->fpu_owner==THREAD) CPU->fpu_owner=NULL;
-			spinlock_unlock(&CPU->lock);
-
-			free(THREAD);
-
-			break;
-    
-		    case Sleeping:
-			/*
-			 * Prefer the thread after it's woken up.
-			 */
-			THREAD->priority = -1;
-
-			/*
-			 * We need to release wq->lock which we locked in waitq_sleep().
-			 * Address of wq->lock is kept in THREAD->sleep_queue.
-			 */
-			spinlock_unlock(&THREAD->sleep_queue->lock);
-
-			/*
-			 * Check for possible requests for out-of-context invocation.
-			 */
-			if (THREAD->call_me) {
-				THREAD->call_me(THREAD->call_me_with);
-				THREAD->call_me = NULL;
-				THREAD->call_me_with = NULL;
-			}
-
-			spinlock_unlock(&THREAD->lock);
-
-			break;
-
-		    default:
-			/*
-			 * Entering state is unexpected.
-			 */
-			panic("tid%d: unexpected state %s\n", THREAD->tid, thread_states[THREAD->state]);
-			break;
-		}
-		THREAD = NULL;
-	}
-
-
-	THREAD = find_best_thread();
-	
-	spinlock_lock(&THREAD->lock);
-	priority = THREAD->priority;
-	spinlock_unlock(&THREAD->lock);	
-
-	relink_rq(priority);		
-
-	spinlock_lock(&THREAD->lock);	
-
-	/*
-	 * If both the old and the new task are the same, lots of work is avoided.
-	 */
-	if (TASK != THREAD->task) {
-		vm_t *m1 = NULL;
-		vm_t *m2;
-
-		if (TASK) {
-			spinlock_lock(&TASK->lock);
-			m1 = TASK->vm;
-			spinlock_unlock(&TASK->lock);
-		}
-
-		spinlock_lock(&THREAD->task->lock);
-		m2 = THREAD->task->vm;
-		spinlock_unlock(&THREAD->task->lock);
-		
-		/*
-		 * Note that it is possible for two tasks to share one vm mapping.
-		 */
-		if (m1 != m2) {
-			/*
-			 * Both tasks and vm mappings are different.
-			 * Replace the old one with the new one.
-			 */
-			vm_install(m2);
-		}
-		TASK = THREAD->task;	
-	}
-
-	THREAD->state = Running;
-
-	#ifdef SCHEDULER_VERBOSE
-	printf("cpu%d: tid %d (priority=%d,ticks=%d,nrdy=%d)\n", CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks, CPU->nrdy);
-	#endif	
-
-	/*
-	 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to thread's stack.
-	 */
-	the_copy(THE, (the_t *) THREAD->kstack);
-	
-	context_restore(&THREAD->saved_context);
-	/* not reached */
-}
+
 
 
Index: generic/src/proc/thread.c
===================================================================
--- generic/src/proc/thread.c	(revision 169c408f8774661800aa0a9685c9914cbb5a974c)
+++ generic/src/proc/thread.c	(revision c4e8ed9d860723e9a528a63a1c23c93516a1e0ba)
@@ -71,5 +71,5 @@
  *
  */
-void cushion(void)
+static void cushion(void)
 {
 	void (*f)(void *) = THREAD->thread_code;
