Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / lcom / lcf.h @ 13

History | View | Annotate | Download (9.99 KB)

1 13 up20180614
#pragma once
2
3
#include <stdbool.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <time.h>
7
#include <unistd.h>
8
9
#include <machine/int86.h>
10
#include <minix/const.h>
11
#include <minix/driver.h>
12
#include <minix/endpoint.h>
13
#include <minix/sef.h>
14
#include <minix/syslib.h>
15
#include <minix/sysutil.h>
16
#include <minix/type.h>
17
#include <minix/vm.h>
18
#include <sys/mman.h>
19
#include <sys/time.h>
20
#include <sys/timespec.h>
21
#include <sys/types.h>
22
23
#include <lcom/liblm.h>
24
25
#include "lab2.h"
26
#include "lab3.h"
27
#include "lab4.h"
28
#include "types.h"
29
30
#ifdef __LCOM__
31
32
// undef all MINIX functions defined as macros
33
34
#  undef driver_receive
35
#  undef sys_inb
36
#  undef sys_irqdisable
37
#  undef sys_irqenable
38
#  undef sys_irqrmpolicy
39
#  undef sys_irqsetpolicy
40
#  undef sys_outb
41
42
/*
43
 *
44
 * Macros used to replace the set of functions being wrapped / "intercepted".
45
 *
46
 */
47
48
// not a wrapper, just a way to solve pseudo-random number generation issue in Minix 3.4.0-rc6
49
#  define rand() rand_()
50
51
//
52
// Minix / C library functions
53
//
54
55
#  define driver_receive(src, m_ptr, status_ptr) \
56
    driver_receive_(src, m_ptr, status_ptr, CTX_INFO(#src "\0" #m_ptr "\0" #status_ptr))
57
58
#  define micros_to_ticks(micros) \
59
    micros_to_ticks_(micros, CTX_INFO(#micros))
60
61
#  define nanosleep(req, rem) \
62
    nanosleep_(req, rem, CTX_INFO(#req "\0" #rem))
63
64
// printf is a variadic function, therefore it is treated differently:
65
//   1) format argument is included within variadic argument list to avoid any warnings;
66
//   2) the code string is set as a single argument;
67
//   3) context information is the first argument, not the last one.
68
#  define printf(...) \
69
    printf_(CTX_INFO(#__VA_ARGS__), __VA_ARGS__)
70
71
#  define sleep(seconds) \
72
    sleep_(seconds, CTX_INFO(#seconds))
73
74
#  define sys_enable_iop(proc_ep) \
75
    sys_enable_iop_(proc_ep, CTX_INFO(#proc_ep))
76
77
#  define sys_inb(port, value) \
78
    sys_inb_(port, value, CTX_INFO(#port "\0" #value))
79
80
#  define sys_int86(reg86p) \
81
    sys_int86_(reg86p, CTX_INFO(#reg86p))
82
83
#  define sys_irqdisable(irq_hook_id) \
84
    sys_irqdisable_(irq_hook_id, CTX_INFO(#irq_hook_id))
85
86
#  define sys_irqenable(irq_hook_id) \
87
    sys_irqenable_(irq_hook_id, CTX_INFO(#irq_hook_id))
88
89
#  define sys_irqrmpolicy(irq_hook_id) \
90
    sys_irqrmpolicy_(irq_hook_id, CTX_INFO(#irq_hook_id))
91
92
#  define sys_irqsetpolicy(irq_vec, policy, hook_id) sys_irqsetpolicy_( \
93
    irq_vec, policy, hook_id, CTX_INFO(#  irq_vec "\0" #  policy "\0" #  hook_id))
94
95
#  define sys_outb(port, value) \
96
    sys_outb_(port, value, CTX_INFO(#port "\0" #value))
97
98
#  define sys_privctl(proc_ep, req, p) \
99
    sys_privctl_(proc_ep, req, p, CTX_INFO(#proc_ep "\0" #req "\0" #p))
100
101
#  define tickdelay(ticks) \
102
    tickdelay_(ticks, CTX_INFO(#ticks))
103
104
#  define usleep(useconds) \
105
    usleep_(useconds, CTX_INFO(#useconds))
106
107
#  define vm_map_phys(who, physaddr, len) \
108
    vm_map_phys_(who, physaddr, len, CTX_INFO(#who "\0" #physaddr "\0" #len))
109
110
#  define vm_unmap_phys(who, vaddr, len) \
111
    vm_unmap_phys_(who, vaddr, len, CTX_INFO(#who "\0" #vaddr "\0" #len))
112
113
//
114
// LCOM liblm
115
//
116
117
#  define lm_init(enable_logging) \
118
    lm_init_(enable_logging, CTX_INFO(#enable_logging))
119
120
#  define lm_alloc(size, map) \
121
    lm_alloc_(size, map, CTX_INFO(#size "\0" #map))
122
123
#  define lm_free(map) \
124
    lm_free_(map, CTX_INFO(#map))
125
126
//
127
// LCOM Lab 2 functions
128
//
129
130
#  define timer_test_read_config(timer, field) \
131
    timer_test_read_config_(timer, field, CTX_INFO(#timer "\0" #field))
132
133
#  define timer_test_time_base(timer, freq) \
134
    timer_test_time_base_(timer, freq, CTX_INFO(#timer "\0" #freq))
135
136
#  define timer_test_int(time) \
137
    timer_test_int_(time, CTX_INFO(#time))
138
139
#  define util_get_LSB(val, lsb) \
140
    util_get_LSB_(val, lsb, CTX_INFO(#val "\0" #lsb))
141
142
#  define util_get_MSB(val, msb) \
143
    util_get_MSB_(val, msb, CTX_INFO(#val "\0" #msb))
144
145
#  define timer_set_frequency(timer, freq) \
146
    timer_set_frequency_(timer, freq, CTX_INFO(#timer "\0" #freq))
147
148
#  define timer_subscribe_int(bit_no) \
149
    timer_subscribe_int_(bit_no, CTX_INFO(#bit_no))
150
151
#  define timer_unsubscribe_int() \
152
    timer_unsubscribe_int_(CTX_INFO(""))
153
154
#  define timer_int_handler() \
155
    timer_int_handler_(CTX_INFO(""))
156
157
#  define timer_get_conf(timer, st) \
158
    timer_get_conf_(timer, st, CTX_INFO(#timer "\0" #st))
159
160
#  define timer_display_conf(timer, st, field) \
161
    timer_display_conf_(timer, st, field, CTX_INFO(#timer "\0" #st "\0" #field))
162
163
#  define timer_print_config(timer, field, val) \
164
    timer_print_config_(timer, field, val, CTX_INFO(#timer "\0" #field "\0" #val))
165
166
#  define timer_print_elapsed_time() \
167
    timer_print_elapsed_time_(CTX_INFO(""))
168
169
//
170
// LCOM Lab 3 functions
171
//
172
173
#  define kbd_test_scan() \
174
    kbd_test_scan_(CTX_INFO(""))
175
176
#  define kbd_test_poll() \
177
    kbd_test_poll_(CTX_INFO(""))
178
179
#  define kbd_test_timed_scan(n) \
180
    kbd_test_timed_scan_(n, CTX_INFO(#n))
181
182
#  define kbc_ih() \
183
    kbc_ih_(CTX_INFO(""))
184
185
#  define kbd_print_scancode(make, size, bytes) \
186
    kbd_print_scancode_(make, size, bytes, CTX_INFO(#make "\0" #size "\0" #bytes))
187
188
#  define kbd_print_no_sysinb(cnt) \
189
    kbd_print_no_sysinb_(cnt, CTX_INFO(#cnt))
190
191
//
192
// LCOM Lab 4 functions
193
//
194
195
#  define mouse_test_packet(cnt) \
196
    mouse_test_packet_(cnt, CTX_INFO(#cnt))
197
198
#  define mouse_test_async(idle_time) \
199
    mouse_test_async_(idle_time, CTX_INFO(#idle_time))
200
201
#  define mouse_test_remote(period, cnt) \
202
    mouse_test_remote_(period, cnt, CTX_INFO(#period "\0" #cnt))
203
204
#  define mouse_test_gesture(x_len, tolerance) \
205
    mouse_test_gesture_(x_len, tolerance, CTX_INFO(#x_len "\0" #tolerance))
206
207
#  define mouse_ih() \
208
    mouse_ih_(CTX_INFO(""))
209
210
#  define mouse_print_packet(pp) \
211
    mouse_print_packet_(pp, CTX_INFO(#pp))
212
213
#  define mouse_enable_data_reporting() \
214
    mouse_enable_data_reporting_(CTX_INFO(""))
215
216
/*
217
 *
218
 * Wrappers entry point.
219
 *
220
 */
221
222
// not a wrapper, used as a way to solve pseudo-random number generation in Minix 3.4.0-rc6
223
int rand_();
224
225
//
226
// Minix / C library functions
227
//
228
229
int driver_receive_(endpoint_t src, message *m_ptr, int *status_ptr, const ctx_t ctx);
230
231
u32_t micros_to_ticks_(u32_t micros, const ctx_t ctx);
232
233
int nanosleep_(const struct timespec *req, struct timespec *rem, const ctx_t ctx);
234
235
int printf_(const ctx_t ctx, const char *__restrict format, ...);
236
237
// void sef_startup_(const ctx_t ctx);
238
239
unsigned int sleep_(unsigned int seconds, const ctx_t ctx);
240
241
int sys_enable_iop_(endpoint_t proc_ep, const ctx_t ctx);
242
243
int sys_inb_(int port, u32_t *value, const ctx_t ctx);
244
245
#  if defined(__i386__)
246
int sys_int86_(reg86_t *reg86p, const ctx_t ctx);
247
#  endif
248
249
int sys_irqdisable_(int *irq_hook_id, const ctx_t ctx);
250
251
int sys_irqenable_(int *irq_hook_id, const ctx_t ctx);
252
253
int sys_irqrmpolicy_(int *irq_hook_id, const ctx_t ctx);
254
255
int sys_irqsetpolicy_(int irq_vec, int policy, int *irq_hook_id, const ctx_t ctx);
256
257
int sys_outb_(int port, u32_t value, const ctx_t ctx);
258
259
int sys_privctl_(endpoint_t proc_ep, int req, void *p, const ctx_t ctx);
260
261
int tickdelay_(clock_t ticks, const ctx_t ctx);
262
263
int usleep_(useconds_t useconds, const ctx_t ctx);
264
265
void *vm_map_phys_(endpoint_t who, void *physaddr, size_t len, const ctx_t ctx);
266
267
int vm_unmap_phys_(endpoint_t who, void *vaddr, size_t len, const ctx_t ctx);
268
269
//
270
// LCOM liblm
271
//
272
273
void *lm_init_(bool enable_logging, const ctx_t ctx);
274
275
void *lm_alloc_(size_t size, mmap_t *map, const ctx_t ctx);
276
277
bool lm_free_(mmap_t *map, const ctx_t ctx);
278
279
//
280
// LCOM Lab 2
281
//
282
283
int timer_test_read_config_(uint8_t timer, enum timer_status_field field, const ctx_t ctx);
284
285
int timer_test_time_base_(uint8_t timer, uint32_t freq, const ctx_t ctx);
286
287
int timer_test_int_(uint8_t time, const ctx_t ctx);
288
289
int util_get_LSB_(uint16_t val, uint8_t *lsb, const ctx_t ctx);
290
291
int util_get_MSB_(uint16_t val, uint8_t *msb, const ctx_t ctx);
292
293
int timer_set_frequency_(uint8_t timer, uint32_t freq, const ctx_t ctx);
294
295
int timer_subscribe_int_(uint8_t *bit_no, const ctx_t ctx);
296
297
int timer_unsubscribe_int_(const ctx_t ctx);
298
299
void timer_int_handler_(const ctx_t ctx);
300
301
int timer_get_conf_(uint8_t timer, uint8_t *st, const ctx_t ctx);
302
303
int timer_display_conf_(uint8_t timer, uint8_t st, enum timer_status_field field, const ctx_t ctx);
304
305
int timer_print_config_(uint8_t timer, enum timer_status_field field,
306
                        union timer_status_field_val val, const ctx_t ctx);
307
308
uint32_t timer_print_elapsed_time_(const ctx_t ctx);
309
310
//
311
// LCOM Lab 3
312
//
313
314
int kbd_test_scan_(const ctx_t ctx);
315
316
int kbd_test_poll_(const ctx_t ctx);
317
318
int kbd_test_timed_scan_(uint8_t n, const ctx_t ctx);
319
320
void kbc_ih_(const ctx_t ctx);
321
322
int kbd_print_scancode_(bool make, uint8_t size, uint8_t *bytes, const ctx_t ctx);
323
324
int kbd_print_no_sysinb_(uint32_t cnt, const ctx_t ctx);
325
326
//
327
// LCOM Lab 4
328
//
329
330
int mouse_test_packet_(uint32_t cnt, const ctx_t ctx);
331
332
int mouse_test_remote_(uint16_t period, uint8_t cnt, const ctx_t ctx);
333
334
int mouse_test_async_(uint8_t idle_time, const ctx_t ctx);
335
336
int mouse_test_gesture_(uint8_t x_len, uint8_t tolerance, const ctx_t ctx);
337
338
void mouse_ih_(const ctx_t ctx);
339
340
void mouse_print_packet_(struct packet *pp, const ctx_t ctx);
341
342
int mouse_enable_data_reporting_(const ctx_t ctx);
343
344
//
345
// LCF library functions
346
//
347
348
#  define lcf_start(argc, argv) \
349
    lcf_start_(argc, argv, CTX_INFO(#argc "\0" #argv))
350
351
#  define lcf_cleanup() \
352
    lcf_cleanup_(true, CTX_INFO(""))
353
354
#  define lcf_log_output(output) \
355
    lcf_log_output_(output, CTX_INFO(#output))
356
357
#  define lcf_trace_calls(syslog) \
358
    lcf_trace_calls_(syslog, CTX_INFO(#syslog))
359
360
#  define lcf_set_language(lang) \
361
    lcf_set_language_(lang, CTX_INFO(#lang))
362
363
// initialize LCF library by passing the command line arguments
364
// [sef_startup() is invoked internally]
365
int lcf_start_(int argc, char *argv[], const ctx_t ctx);
366
367
// LCF library clean up operations (invoked immediately before exiting)
368
int lcf_cleanup_(bool usercall, const ctx_t ctx);
369
370
// if set, creates a file to save all the output
371
bool lcf_log_output_(const char *output, const ctx_t ctx);
372
373
// if set, creates a file to save the invocations of all functions being wrapped / "intercepted"
374
bool lcf_trace_calls_(const char *syslog, const ctx_t ctx);
375
376
// enables to set the language for LCF messages
377
bool lcf_set_language_(const char *lang, const ctx_t ctx);
378
379
#endif // __LCOM__