mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Split descriptor_tables.cpp into a gdt.cpp and idt.cpp.
This was about time, since descriptor_tables was a really bad name!
This commit is contained in:
parent
5162a12d03
commit
b4f47f0f79
14 changed files with 212 additions and 118 deletions
|
@ -34,6 +34,9 @@ ifdef X86FAMILY
|
|||
x86-family/memorymanagement.o \
|
||||
$(CPU)/interrupt.o \
|
||||
$(CPU)/gdt.o \
|
||||
x86-family/gdt.o \
|
||||
$(CPU)/idt.o \
|
||||
x86-family/idt.o \
|
||||
$(CPU)/syscall.o \
|
||||
$(CPU)/thread.o \
|
||||
$(CPU)/scheduler.o \
|
||||
|
@ -74,7 +77,6 @@ STATICLIBS=\
|
|||
|
||||
OBJS=$(CPUOBJS) \
|
||||
kernel.o \
|
||||
descriptor_tables.o \
|
||||
interrupt.o \
|
||||
time.o \
|
||||
log.o \
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include "descriptor_tables.h"
|
||||
#include "x86-family/idt.h"
|
||||
#include "interrupt.h"
|
||||
|
||||
#include "process.h" // Hack for SIGSEGV
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <libmaxsi/format.h>
|
||||
#include "log.h"
|
||||
#include "panic.h"
|
||||
#include "descriptor_tables.h"
|
||||
#include "x86-family/gdt.h"
|
||||
#include "time.h"
|
||||
#include "keyboard.h"
|
||||
#include "multiboot.h"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "memorymanagement.h"
|
||||
#include "syscall.h"
|
||||
#include "sound.h" // HACK FOR SIGINT
|
||||
#include "descriptor_tables.h"
|
||||
#include "x86-family/gdt.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -14,13 +14,13 @@
|
|||
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 Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
x64/gdt.cpp
|
||||
x64/gdt.s
|
||||
Handles initialization of the 64-bit global descriptor table.
|
||||
|
||||
******************************************************************************/
|
||||
*******************************************************************************/
|
||||
|
||||
.section .text
|
||||
|
||||
|
@ -44,13 +44,6 @@ gdt_flush:
|
|||
gdt_flush_postjmp:
|
||||
ret
|
||||
|
||||
.global idt_flush
|
||||
.type idt_flush, @function
|
||||
idt_flush:
|
||||
# Load the IDT pointer.
|
||||
lidt (%rdi)
|
||||
ret
|
||||
|
||||
.global tss_flush
|
||||
.type tss_flush, @function
|
||||
tss_flush:
|
||||
|
|
33
sortix/x64/idt.s
Normal file
33
sortix/x64/idt.s
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix 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 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix 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
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
x64/idt.s
|
||||
Handles initialization of the 64-bit IDT.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
.section .text
|
||||
|
||||
.global idt_flush
|
||||
.type idt_flush, @function
|
||||
idt_flush:
|
||||
# Load the IDT pointer.
|
||||
lidt (%rdi)
|
||||
ret
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
#include "platform.h"
|
||||
#include "scheduler.h"
|
||||
#include "../memorymanagement.h"
|
||||
#include "descriptor_tables.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
|
|
|
@ -17,16 +17,14 @@
|
|||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
descriptor_tables.cpp
|
||||
Initializes and handles the GDT, TSS and IDT.
|
||||
x86-family/gdt.cpp
|
||||
Initializes and handles the GDT and TSS.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include "../platform.h"
|
||||
#include <libmaxsi/memory.h>
|
||||
#include "descriptor_tables.h"
|
||||
#include "panic.h"
|
||||
#include "syscall.h"
|
||||
#include "gdt.h"
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
|
@ -156,40 +154,5 @@ namespace Sortix
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
namespace IDT
|
||||
{
|
||||
extern "C" void idt_flush(addr_t);
|
||||
|
||||
idt_entry_t idt_entries[256];
|
||||
idt_ptr_t idt_ptr;
|
||||
|
||||
void Init()
|
||||
{
|
||||
idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1;
|
||||
idt_ptr.base = (addr_t) &idt_entries;
|
||||
|
||||
Memory::Set(&idt_entries, 0, sizeof(idt_entry_t)*256);
|
||||
}
|
||||
|
||||
void Flush()
|
||||
{
|
||||
idt_flush((addr_t) &idt_ptr);
|
||||
}
|
||||
|
||||
void SetGate(uint8_t num, addr_t base, uint16_t sel, uint8_t flags)
|
||||
{
|
||||
idt_entries[num].base_low = base & 0xFFFF;
|
||||
idt_entries[num].base_high = (base >> 16) & 0xFFFF;
|
||||
#ifdef PLATFORM_X64
|
||||
idt_entries[num].base_highest = (base >> 32 ) & 0xFFFFFFFFU;
|
||||
idt_entries[num].zero1 = 0;
|
||||
#endif
|
||||
|
||||
idt_entries[num].sel = sel;
|
||||
idt_entries[num].always0 = 0;
|
||||
idt_entries[num].flags = flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,13 +17,13 @@
|
|||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
descriptor_tables.h
|
||||
Initializes and handles the GDT, TSS and IDT.
|
||||
x86-family/gdt.h
|
||||
Initializes and handles the GDT and TSS.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_DESCRIPTOR_TABLES_H
|
||||
#define SORTIX_DESCRIPTOR_TABLES_H
|
||||
#ifndef SORTIX_X86_FAMILY_GDT_H
|
||||
#define SORTIX_X86_FAMILY_GDT_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
|
@ -122,53 +122,6 @@ namespace Sortix
|
|||
void WriteTSS(int32_t num, uint16_t ss0, addr_t stack0);
|
||||
void SetKernelStack(size_t* stack);
|
||||
}
|
||||
|
||||
namespace IDT
|
||||
{
|
||||
// A struct describing an interrupt gate.
|
||||
struct idt_entry32_struct
|
||||
{
|
||||
uint16_t base_low; // The lower 16 bits of the address to jump to when this interrupt fires.
|
||||
uint16_t sel; // Kernel segment selector.
|
||||
uint8_t always0; // This must always be zero.
|
||||
uint8_t flags; // More flags. See documentation.
|
||||
uint16_t base_high; // The upper 16 bits of the address to jump to.
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idt_entry64_struct
|
||||
{
|
||||
uint16_t base_low; // The lower 16 bits of the address to jump to when this interrupt fires.
|
||||
uint16_t sel; // Kernel segment selector.
|
||||
uint8_t always0; // This must always be zero.
|
||||
uint8_t flags; // More flags. See documentation.
|
||||
uint16_t base_high; // The upper 16 bits of the address to jump to.
|
||||
uint32_t base_highest;
|
||||
uint32_t zero1; // Reserved
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct idt_entry32_struct idt_entry32_t;
|
||||
typedef struct idt_entry64_struct idt_entry64_t;
|
||||
#ifdef PLATFORM_X64
|
||||
typedef idt_entry64_t idt_entry_t;
|
||||
#else
|
||||
typedef idt_entry32_t idt_entry_t;
|
||||
|
||||
#endif
|
||||
|
||||
// A struct describing a pointer to an array of interrupt handlers.
|
||||
// This is in a format suitable for giving to 'lidt'.
|
||||
struct idt_ptr_struct
|
||||
{
|
||||
uint16_t limit;
|
||||
addr_t base; // The address of the first element in our idt_entry_t array.
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct idt_ptr_struct idt_ptr_t;
|
||||
|
||||
void Init();
|
||||
void SetGate(uint8_t num, addr_t base, uint16_t sel, uint8_t flags);
|
||||
void Flush();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
68
sortix/x86-family/idt.cpp
Normal file
68
sortix/x86-family/idt.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix 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 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix 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
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
x86-family/idt.cpp
|
||||
Initializes and handles the IDT.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include "../platform.h"
|
||||
#include <libmaxsi/memory.h>
|
||||
#include "idt.h"
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace IDT
|
||||
{
|
||||
extern "C" void idt_flush(addr_t);
|
||||
|
||||
idt_entry_t idt_entries[256];
|
||||
idt_ptr_t idt_ptr;
|
||||
|
||||
void Init()
|
||||
{
|
||||
idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1;
|
||||
idt_ptr.base = (addr_t) &idt_entries;
|
||||
|
||||
Memory::Set(&idt_entries, 0, sizeof(idt_entry_t)*256);
|
||||
}
|
||||
|
||||
void Flush()
|
||||
{
|
||||
idt_flush((addr_t) &idt_ptr);
|
||||
}
|
||||
|
||||
void SetGate(uint8_t num, addr_t base, uint16_t sel, uint8_t flags)
|
||||
{
|
||||
idt_entries[num].base_low = base & 0xFFFF;
|
||||
idt_entries[num].base_high = (base >> 16) & 0xFFFF;
|
||||
#ifdef PLATFORM_X64
|
||||
idt_entries[num].base_highest = (base >> 32 ) & 0xFFFFFFFFU;
|
||||
idt_entries[num].zero1 = 0;
|
||||
#endif
|
||||
|
||||
idt_entries[num].sel = sel;
|
||||
idt_entries[num].always0 = 0;
|
||||
idt_entries[num].flags = flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
78
sortix/x86-family/idt.h
Normal file
78
sortix/x86-family/idt.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix 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 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix 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
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
x86-family/idt.h
|
||||
Initializes and handles the IDT.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_X86_FAMILY_IDT_H
|
||||
#define SORTIX_X86_FAMILY_IDT_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace IDT
|
||||
{
|
||||
// A struct describing an interrupt gate.
|
||||
struct idt_entry32_struct
|
||||
{
|
||||
uint16_t base_low; // The lower 16 bits of the address to jump to when this interrupt fires.
|
||||
uint16_t sel; // Kernel segment selector.
|
||||
uint8_t always0; // This must always be zero.
|
||||
uint8_t flags; // More flags. See documentation.
|
||||
uint16_t base_high; // The upper 16 bits of the address to jump to.
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idt_entry64_struct
|
||||
{
|
||||
uint16_t base_low; // The lower 16 bits of the address to jump to when this interrupt fires.
|
||||
uint16_t sel; // Kernel segment selector.
|
||||
uint8_t always0; // This must always be zero.
|
||||
uint8_t flags; // More flags. See documentation.
|
||||
uint16_t base_high; // The upper 16 bits of the address to jump to.
|
||||
uint32_t base_highest;
|
||||
uint32_t zero1; // Reserved
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct idt_entry32_struct idt_entry32_t;
|
||||
typedef struct idt_entry64_struct idt_entry64_t;
|
||||
#ifdef PLATFORM_X64
|
||||
typedef idt_entry64_t idt_entry_t;
|
||||
#else
|
||||
typedef idt_entry32_t idt_entry_t;
|
||||
#endif
|
||||
|
||||
// A struct describing a pointer to an array of interrupt handlers.
|
||||
// This is in a format suitable for giving to 'lidt'.
|
||||
struct idt_ptr_struct
|
||||
{
|
||||
uint16_t limit;
|
||||
addr_t base; // The address of the first element in our idt_entry_t array.
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct idt_ptr_struct idt_ptr_t;
|
||||
|
||||
void Init();
|
||||
void SetGate(uint8_t num, addr_t base, uint16_t sel, uint8_t flags);
|
||||
void Flush();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -20,13 +20,6 @@ gdt_flush:
|
|||
.flush:
|
||||
ret
|
||||
|
||||
[GLOBAL idt_flush] ; Allows the C code to call idt_flush().
|
||||
|
||||
idt_flush:
|
||||
mov eax, [esp+4] ; Get the pointer to the IDT, passed as a parameter.
|
||||
lidt [eax] ; Load the IDT pointer.
|
||||
ret
|
||||
|
||||
[GLOBAL tss_flush] ; Allows our C code to call tss_flush().
|
||||
tss_flush:
|
||||
mov ax, 0x2B ; Load the index of our TSS structure - The index is
|
||||
|
|
13
sortix/x86/idt.asm
Normal file
13
sortix/x86/idt.asm
Normal file
|
@ -0,0 +1,13 @@
|
|||
;
|
||||
; idt.s -- contains global descriptor table and interrupt descriptor table
|
||||
; setup code.
|
||||
; Based on code from Bran's kernel development tutorials.
|
||||
; Rewritten for JamesM's kernel development tutorials.
|
||||
|
||||
[GLOBAL idt_flush] ; Allows the C code to call idt_flush().
|
||||
|
||||
idt_flush:
|
||||
mov eax, [esp+4] ; Get the pointer to the IDT, passed as a parameter.
|
||||
lidt [eax] ; Load the IDT pointer.
|
||||
ret
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
#include "platform.h"
|
||||
#include "scheduler.h"
|
||||
#include "../memorymanagement.h"
|
||||
#include "descriptor_tables.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue