source: branches/minix3-book/kernel/const.h@ 11

Last change on this file since 11 was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 2.8 KB
Line 
1/* General macros and constants used by the kernel. */
2#ifndef CONST_H
3#define CONST_H
4
5#include <ibm/interrupt.h> /* interrupt numbers and hardware vectors */
6#include <ibm/ports.h> /* port addresses and magic numbers */
7#include <ibm/bios.h> /* BIOS addresses, sizes and magic numbers */
8#include <ibm/cpu.h> /* BIOS addresses, sizes and magic numbers */
9#include <minix/config.h>
10#include "config.h"
11
12/* To translate an address in kernel space to a physical address. This is
13 * the same as umap_local(proc_ptr, D, vir, sizeof(*vir)), but less costly.
14 */
15#define vir2phys(vir) (kinfo.data_base + (vir_bytes) (vir))
16
17/* Map a process number to a privilege structure id. */
18#define s_nr_to_id(n) (NR_TASKS + (n) + 1)
19
20/* Translate a pointer to a field in a structure to a pointer to the structure
21 * itself. So it translates '&struct_ptr->field' back to 'struct_ptr'.
22 */
23#define structof(type, field, ptr) \
24 ((type *) (((char *) (ptr)) - offsetof(type, field)))
25
26/* Constants used in virtual_copy(). Values must be 0 and 1, respectively. */
27#define _SRC_ 0
28#define _DST_ 1
29
30/* Number of random sources */
31#define RANDOM_SOURCES 16
32
33/* Constants and macros for bit map manipulation. */
34#define BITCHUNK_BITS (sizeof(bitchunk_t) * CHAR_BIT)
35#define BITMAP_CHUNKS(nr_bits) (((nr_bits)+BITCHUNK_BITS-1)/BITCHUNK_BITS)
36#define MAP_CHUNK(map,bit) (map)[((bit)/BITCHUNK_BITS)]
37#define CHUNK_OFFSET(bit) ((bit)%BITCHUNK_BITS))
38#define GET_BIT(map,bit) ( MAP_CHUNK(map,bit) & (1 << CHUNK_OFFSET(bit) )
39#define SET_BIT(map,bit) ( MAP_CHUNK(map,bit) |= (1 << CHUNK_OFFSET(bit) )
40#define UNSET_BIT(map,bit) ( MAP_CHUNK(map,bit) &= ~(1 << CHUNK_OFFSET(bit) )
41
42#define get_sys_bit(map,bit) \
43 ( MAP_CHUNK(map.chunk,bit) & (1 << CHUNK_OFFSET(bit) )
44#define set_sys_bit(map,bit) \
45 ( MAP_CHUNK(map.chunk,bit) |= (1 << CHUNK_OFFSET(bit) )
46#define unset_sys_bit(map,bit) \
47 ( MAP_CHUNK(map.chunk,bit) &= ~(1 << CHUNK_OFFSET(bit) )
48#define NR_SYS_CHUNKS BITMAP_CHUNKS(NR_SYS_PROCS)
49
50/* Program stack words and masks. */
51#define INIT_PSW 0x0200 /* initial psw */
52#define INIT_TASK_PSW 0x1200 /* initial psw for tasks (with IOPL 1) */
53#define TRACEBIT 0x0100 /* OR this with psw in proc[] for tracing */
54#define SETPSW(rp, new) /* permits only certain bits to be set */ \
55 ((rp)->p_reg.psw = (rp)->p_reg.psw & ~0xCD5 | (new) & 0xCD5)
56#define IF_MASK 0x00000200
57#define IOPL_MASK 0x003000
58
59/* Disable/ enable hardware interrupts. The parameters of lock() and unlock()
60 * are used when debugging is enabled. See debug.h for more information.
61 */
62#define lock(c, v) intr_disable();
63#define unlock(c) intr_enable();
64
65/* Sizes of memory tables. The boot monitor distinguishes three memory areas,
66 * namely low mem below 1M, 1M-16M, and mem after 16M. More chunks are needed
67 * for DOS MINIX.
68 */
69#define NR_MEMS 8
70
71#endif /* CONST_H */
72
73
74
75
76
Note: See TracBrowser for help on using the repository browser.