summaryrefslogtreecommitdiff
path: root/sos-code-article6.5/hwcore/idt.h
blob: 2d165b05570b5c84088e6fc554daa99d9ebc6063 (plain) (blame)
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
/* Copyright (C) 2004  David Decotigny

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
   USA. 
*/
#ifndef _SOS_IDT_H_
#define _SOS_IDT_H_

/**
 * @file idt.h
 *
 * Manage the x86 Interrupt Descriptor Table, the table which maps the
 * hardware interrupt lines, hardware exceptions, and software
 * interrupts, to software routines. We only define "interrupt gate"
 * IDT entries. Don't use it directly; refer instead to interrupt.c,
 * exceptions.c and syscall.c.
 *
 * @see Intel x86 doc, Vol 3, chapter 5
 */

#include <sos/errno.h>
#include <sos/types.h>

/* Mapping of the CPU exceptions in the IDT (imposed by Intel
   standards) */
#define SOS_EXCEPT_BASE 0
#define SOS_EXCEPT_NUM  32
#define SOS_EXCEPT_MAX  (SOS_HWEXCEPT_BASE + SOS_HWEXCEPT_NUM - 1)

/* Mapping of the IRQ lines in the IDT */
#define SOS_IRQ_BASE    32
#define SOS_IRQ_NUM     16
#define SOS_IRQ_MAX     (SOS_IRQ_BASE + SOS_IRQ_NUM - 1)

/**
 * Number of IDT entries.
 *
 * @note Must be large enough to map the hw interrupts, the exceptions
 * (=> total is 48 entries), and the syscall(s). Since our syscall
 * will be 0x42, it must be >= 0x43. Intel doc limits this to 256
 * entries, we use this limit.
 */
#define SOS_IDTE_NUM      256 /* 0x100 */

/** Initialization routine: all the IDT entries (or "IDTE") are marked
    "not present". */
sos_ret_t sos_idt_subsystem_setup(void);

/**
 * Enable the IDT entry if handler_address != NULL, with the given
 * lowest_priviledge.\ Disable the IDT entry when handler_address ==
 * NULL (the lowest_priviledge parameter is then ignored). Intel doc
 * says that there must not be more than 256 entries.
 *
 * @note IRQ Unsafe
 */
sos_ret_t sos_idt_set_handler(int index,
			      sos_vaddr_t handler_address,
			      int lowest_priviledge /* 0..3 */);


/**
 * @note IRQ Unsafe
 *
 * @return the handler address and DPL in the 2nd and 3rd
 * parameters
 */
sos_ret_t sos_idt_get_handler(int index,
			      sos_vaddr_t *handler_address,
			      int *lowest_priviledge);

#endif /* _SOS_IDT_H_ */