3 Copyright (C) 2007-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <kernel/x86_shared/gdt.hpp>
20 #include <kernel/processor.hpp>
21 using namespace kernel
;
29 } __attribute__((packed
)) gdtr
= {static_cast<uint16_t>(mSize
* 8 - 1), reinterpret_cast<uintptr_t>(mGdt
)};
31 asm volatile("lgdt %0" :: "m"(gdtr
));
34 void gdt::clear_tss_busy_bit(size_t index
)
36 mGdt
[index
].x86
.flags
&= ~0x02;
39 size_t gdt::get_descriptor_count()
41 return 1 + // Zero descriptor
42 4 + // Kernel Data & Code, User Data & Code
44 2 + // Virtual-8086-mode TSS & Kernel TSS
46 processor::count(); // Thread TSS
48 size_t gdt::tss_descriptor_size()
52 void gdt::set_tss_descriptor( size_t index
,
55 set_segment_descriptor( index
,
57 sizeof(task_state_segment
),
61 void gdt::set_segment_descriptor( size_t index
,
67 mGdt
[index
].x86
.limit
= limit
& 0xFFFF;
68 mGdt
[index
].x86
.address0
= address
& 0xFFFF;
69 mGdt
[index
].x86
.address1
= (address
>> 16) & 0xFF;
70 mGdt
[index
].x86
.flags
= flags
;
71 mGdt
[index
].x86
.flags_limit
= (flags2
<< 4) | ((limit
>> 16) & 0x0F);
72 mGdt
[index
].x86
.address2
= (address
>> 24) & 0xFF;