-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptor_tables.c
63 lines (50 loc) · 1.8 KB
/
descriptor_tables.c
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
/* descriptor_talbles.c - Initialises the GDT and IDT Defines the default ISR
* and IRQ handler.
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-
* ShareAlike 3.0 Unported License. To view a copy of this license, visit
* http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to:
* Creative Commons
* 444 Castro Street, Suite 900
* Mountain View, California, 94041, USA.
*
* Author(s): Drew Cross <[email protected]>
*/
#include "common.h"
#include "descriptor_tables.h"
// Allow access the ASM functions from C code
//
extern void gdt_flush(u32int);
// Internal function prototypes
static void init_gdt();
static void gdt_set_gate(s32int, u32int, u8int, u8int);
gdt_entry_t gdt_enteries[5];
gdt_ptr_t gdt_ptr;
idt_entry_t idt_entries[256];
idt_ptr_t idt_ptr;
void init_descrpitor_tables()
{
// Initializes the GDT
init_gtd();
}
static void init_gdt()
{
gdt_ptr.limit = (sizeof(gdt_entry_t) *5) -1;
gdt_ptr.base = (u32int)&gdt_entries;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment
gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment
gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment
gdt_flush((u32int)&gdt_ptr);
}
tatic void gdt_set_gate(s32int num, u32int base, u32int limit, u8int access, u8int gran)
{
gdt_entries[num].base_low = (base & 0xFFFF);
gdt_entries[num].base_middle = (base >> 16) & 0xFF;
gdt_entries[num].base_high = (base >> 24) & 0xFF;
gdt_entries[num].limit_low = (limit & 0xFFFF);
gdt_entries[num].granularity = (limit >> 16) & 0x0F;
gdt_entries[num].granularity |= gran & 0xF0;
gdt_entries[num].access = access;
}