2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include "linux/kernel.h"
7 #include "linux/module.h"
8 #include "linux/unistd.h"
9 #include "linux/stddef.h"
10 #include "linux/spinlock.h"
11 #include "linux/time.h"
12 #include "linux/sched.h"
13 #include "linux/interrupt.h"
14 #include "linux/init.h"
15 #include "linux/delay.h"
17 #include "asm/param.h"
18 #include "asm/current.h"
19 #include "kern_util.h"
20 #include "user_util.h"
21 #include "time_user.h"
26 EXPORT_SYMBOL(jiffies_64);
33 /* Changed at early boot */
34 int timer_irq_inited = 0;
36 /* missed_ticks will be modified after kernel memory has been
37 * write-protected, so this puts it in a section which will be left
40 int __attribute__ ((__section__ (".unprotected"))) missed_ticks[NR_CPUS];
42 void timer_irq(union uml_pt_regs *regs)
44 int cpu = current->thread_info->cpu, ticks = missed_ticks[cpu];
46 if(!timer_irq_inited) return;
47 missed_ticks[cpu] = 0;
48 while(ticks--) do_IRQ(TIMER_IRQ, regs);
51 void boot_timer_handler(int sig)
56 (UPT_SC(®s.regs) = (struct sigcontext *) (&sig + 1)),
57 (void) (regs.regs.skas.is_user = 0));
61 void um_timer(int irq, void *dev, struct pt_regs *regs)
64 write_seqlock(&xtime_lock);
66 write_sequnlock(&xtime_lock);
69 long um_time(int * tloc)
73 do_gettimeofday(&now);
75 if (put_user(now.tv_sec,tloc))
81 long um_stime(int * tptr)
86 if (get_user(value, tptr))
90 do_settimeofday(&new);
94 /* XXX Needs to be moved under sys-i386 */
95 void __delay(um_udelay_t time)
97 /* Stolen from the i386 __loop_delay */
104 "2:\tdecl %0\n\tjns 2b"
109 void __udelay(um_udelay_t usecs)
113 n = (loops_per_jiffy * HZ * usecs) / 1000000;
117 void __const_udelay(um_udelay_t usecs)
121 n = (loops_per_jiffy * HZ * usecs) / 1000000;
125 void timer_handler(int sig, union uml_pt_regs *regs)
128 update_process_times(user_context(UPT_SP(regs)));
130 if(current->thread_info->cpu == 0)
134 static spinlock_t timer_spinlock = SPIN_LOCK_UNLOCKED;
136 unsigned long time_lock(void)
139 spin_lock_irqsave(&timer_spinlock, flags);
143 void time_unlock(unsigned long flags)
145 spin_unlock_irqrestore(&timer_spinlock, flags);
148 int __init timer_init(void)
152 CHOOSE_MODE(user_time_init_tt(), user_time_init_skas());
153 if((err = request_irq(TIMER_IRQ, um_timer, SA_INTERRUPT, "timer",
155 printk(KERN_ERR "timer_init : request_irq failed - "
156 "errno = %d\n", -err);
157 timer_irq_inited = 1;
161 __initcall(timer_init);
165 * Overrides for Emacs so that we follow Linus's tabbing style.
166 * Emacs will notice this stuff at the end of the file and automatically
167 * adjust the settings for this buffer only. This must remain at the end
169 * ---------------------------------------------------------------------------
171 * c-file-style: "linux"