-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp1.diff
299 lines (279 loc) · 7.38 KB
/
mp1.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
diff -r -C 4 linux-2.6.22.5/drivers/char/Makefile mp1-linux/drivers/char/Makefile
*** linux-2.6.22.5/drivers/char/Makefile 2011-09-01 09:13:50.326010900 -0500
--- mp1-linux/drivers/char/Makefile 2011-08-29 15:54:53.203072800 -0500
***************
*** 6,14 ****
# This file contains the font map for the default (hardware) font
#
FONTMAPFILE = cp437.uni
! obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o
obj-$(CONFIG_LEGACY_PTYS) += pty.o
obj-$(CONFIG_UNIX98_PTYS) += pty.o
obj-y += misc.o
--- 6,14 ----
# This file contains the font map for the default (hardware) font
#
FONTMAPFILE = cp437.uni
! obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o mp1.o
obj-$(CONFIG_LEGACY_PTYS) += pty.o
obj-$(CONFIG_UNIX98_PTYS) += pty.o
obj-y += misc.o
diff -r -C 4 linux-2.6.22.5/drivers/char/rtc.c mp1-linux/drivers/char/rtc.c
*** linux-2.6.22.5/drivers/char/rtc.c 2011-09-01 09:13:50.505968400 -0500
--- mp1-linux/drivers/char/rtc.c 2011-09-01 09:14:18.026268700 -0500
***************
*** 100,107 ****
--- 100,112 ----
#ifdef CONFIG_HPET_RTC_IRQ
#undef RTC_IRQ
#endif
+ /* Declare the student functions external (they are in mp1.S) */
+ extern asmlinkage void mp1_rtc_tasklet(unsigned long);
+ extern asmlinkage int mp1_ioctl(unsigned long arg, unsigned int cmd);
+ static struct task_struct* missile_command_id = 0;
+
#ifdef RTC_IRQ
static int rtc_has_irq = 1;
#endif
***************
*** 224,232 ****
--- 229,354 ----
spin_unlock_irqrestore(&rtc_lock, flags);
return uip;
}
+ /* Global variable pointing to the upper-left character in
+ * the text-mode video buffer. Used by mp1.S to write chars to the screen */
+ char *vmem_base_addr;
+
+ /* Since the actual copy_to_user and copy_from_user are C macros,
+ * we can't call them by that name directly from assembly. */
+ asmlinkage unsigned long
+ mp1_copy_from_user(void *to, const void *from, unsigned long n)
+ {
+ unsigned long ret;
+ local_irq_enable();
+ ret = copy_from_user(to, from, n);
+ local_irq_disable();
+ return ret;
+ }
+
+ asmlinkage unsigned long
+ mp1_copy_to_user(void *to, const void *from, unsigned long n)
+ {
+ unsigned long ret;
+ local_irq_enable();
+ ret = copy_to_user(to, from, n);
+ local_irq_disable();
+ return ret;
+ }
+
+ /* Kernel wrappers for memory allocation */
+ asmlinkage void* mp1_malloc(unsigned long size)
+ {
+ void *ret;
+ local_irq_enable();
+ ret = kmalloc(size, GFP_KERNEL);
+ local_irq_disable();
+ return ret;
+ }
+
+ asmlinkage void mp1_free(void *ptr)
+ {
+ local_irq_enable();
+ kfree(ptr);
+ local_irq_disable();
+ }
+
+ asmlinkage void mp1_notify_user(void)
+ {
+ send_sig_info(SIGUSR1, NULL, missile_command_id);
+ }
+
+ /* Given code to relieve students of a bit of the work */
+
+ /* Data declared in mp1.c */
+ extern char base_alive[3];
+ extern struct missile* mp1_missile_list;
+ extern int mp1_score;
+
+ /* explode_base()
+ * Test whether an explosion touches a base. If any bases die, update the
+ * base_alive[] array and return nonzero.
+ */
+ static int explode_base(int x, int y){
+ int bases_killed = 0;
+ if(y >= 23){
+ if(17 <= x && x <= 23){
+ if(base_alive[0])
+ bases_killed++;
+ base_alive[0] = 0;
+ }else
+ if(37 <= x && x <= 43){
+ if(base_alive[1])
+ bases_killed++;
+ base_alive[1] = 0;
+ }else
+ if(57 <= x && x <= 63){
+ if(base_alive[2])
+ bases_killed++;
+ base_alive[2] = 0;
+ }
+ }
+ return bases_killed;
+ }
+
+ /* missile_explode()
+ * Check to see whether an explosion causes any bases or missiles to explode.
+ * Enemy missiles ('e') can destroy bases - if this happens, return nonzero.
+ * Friendly missiles ('*') can destroy enemy missiles. If this happens,
+ * update the mp1_score and return nonzero
+ */
+ asmlinkage int missile_explode(struct missile *m){
+ struct missile *i = mp1_missile_list;
+ int exploded = 0;
+ if(!m->exploded){
+ m->exploded = 50;
+ }
+ if(m->c == 'e'){
+ exploded += explode_base(m->x>>16, m->y>>16);
+ }
+
+ while(i){
+ if(i != m){
+ int dx, dy;
+ dx = (m->x>>16) - (i->x>>16);
+ dy = (m->y>>16) - (i->y>>16);
+ if(dx >= -2 && dx <= 2 && dy >= -1 && dy <= 1 &&
+ i->exploded == 0 && i->c == 'e' && m->c == '*'){
+ mp1_score++;
+ exploded++;
+ i->exploded = 50;
+ }
+ }
+ i = i->next;
+ }
+ return exploded;
+ }
+
#ifdef RTC_IRQ
+ /* Student's tasklet */
+ static DECLARE_TASKLET(mp1_rtc_tasklet_struct, mp1_rtc_tasklet, 0);
+
/*
* A very tiny interrupt handler. It runs with IRQF_DISABLED set,
* but there is possibility of conflicting with the set_rtc_mmss()
* call (the rtc irq and the timer irq can easily run at the same
***************
*** 263,270 ****
--- 385,395 ----
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);
spin_unlock (&rtc_lock);
+ /* Schedule the MP1 tasklet to run later */
+ tasklet_schedule(&mp1_rtc_tasklet_struct);
+
/* Now do the rest of the actions */
spin_lock(&rtc_task_lock);
if (rtc_callback)
rtc_callback->func(rtc_callback->private_data);
***************
*** 409,416 ****
--- 534,546 ----
case RTC_UIE_OFF:
case RTC_UIE_ON:
case RTC_IRQP_READ:
case RTC_IRQP_SET:
+ case RTC_STARTGAME:
+ case RTC_ADDMISSILE:
+ case RTC_MOVEXHAIRS:
+ case RTC_GETSTATUS:
+ case RTC_ENDGAME:
return -EINVAL;
};
}
#endif
***************
*** 692,699 ****
--- 822,862 ----
epoch = arg;
return 0;
}
+
+ { int ret;
+ case RTC_STARTGAME:
+ missile_command_id = current;
+ local_irq_disable();
+ ret = mp1_ioctl(arg, 0);
+ local_irq_enable();
+ return ret;
+
+ case RTC_ADDMISSILE:
+ local_irq_disable();
+ ret = mp1_ioctl(arg, 1);
+ local_irq_enable();
+ return ret;
+
+ case RTC_MOVEXHAIRS:
+ local_irq_disable();
+ ret = mp1_ioctl(arg, 2);
+ local_irq_enable();
+ return ret;
+
+ case RTC_GETSTATUS:
+ local_irq_disable();
+ ret = mp1_ioctl(arg, 3);
+ local_irq_enable();
+ return ret;
+
+ case RTC_ENDGAME:
+ local_irq_disable();
+ ret = mp1_ioctl(arg, 4);
+ local_irq_enable();
+ return ret;
+ }
default:
return -ENOTTY;
}
return copy_to_user((void __user *)arg, &wtime, sizeof wtime) ? -EFAULT : 0;
***************
*** 1093,1101 ****
#endif
(void) init_sysctl();
! printk(KERN_INFO "Real Time Clock Driver v" RTC_VERSION "\n");
return 0;
}
--- 1256,1268 ----
#endif
(void) init_sysctl();
! /* Map video memory into the kernel's virtual address space */
! vmem_base_addr = ioremap(0xb8000, 4000);
!
! printk(KERN_INFO "Real Time Clock Driver v" RTC_VERSION
! " Modified for ECE391 MP1\n");
return 0;
}
diff -r -C 4 linux-2.6.22.5/include/linux/rtc.h mp1-linux/include/linux/rtc.h
*** linux-2.6.22.5/include/linux/rtc.h 2011-09-01 09:13:57.235070100 -0500
--- mp1-linux/include/linux/rtc.h 2011-08-29 15:55:10.586024400 -0500
***************
*** 209,213 ****
--- 209,230 ----
irqreturn_t rtc_interrupt(int irq, void *dev_id);
#endif /* __KERNEL__ */
+ /* MP1 stuff - MJM ; 2.6.22.5 update by SSL */
+
+ #define RTC_STARTGAME _IO('M', 0x13)
+ #define RTC_ADDMISSILE _IO('M', 0x14)
+ #define RTC_MOVEXHAIRS _IO('M', 0x15)
+ #define RTC_GETSTATUS _IO('M', 0x16)
+ #define RTC_ENDGAME _IO('M', 0x17)
+
+ struct missile {
+ struct missile* next;
+ int x, y;
+ int vx, vy;
+ int dest_x, dest_y;
+ int exploded;
+ char c;
+ } __attribute__((packed));
+
#endif /* _LINUX_RTC_H_ */