2010-07-31 15:53:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
|
|
|
|
* RWTH Aachen University
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* This file is part of MetalSVM.
|
|
|
|
*/
|
|
|
|
|
2011-04-03 19:41:46 +02:00
|
|
|
/**
|
|
|
|
* @author Stefan Lankes
|
|
|
|
* @file arch/x86/include/asm/idt.h
|
|
|
|
* @brief Definition of IDT flags and functions to set interrupts
|
|
|
|
*
|
|
|
|
* This file contains define-constants for interrupt flags
|
|
|
|
* and installer functions for interrupt gates.\n
|
|
|
|
* See idt.c for structure definitions.
|
|
|
|
*/
|
|
|
|
|
2010-07-31 15:53:30 +00:00
|
|
|
#ifndef __ARCH_IDT_H__
|
|
|
|
#define __ARCH_IDT_H__
|
|
|
|
|
|
|
|
#include <metalsvm/stddef.h>
|
|
|
|
|
2011-04-03 19:41:46 +02:00
|
|
|
/// This bit shall be set to 0 if the IDT slot is empty
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_PRESENT 0x80
|
2011-04-03 19:41:46 +02:00
|
|
|
/// Interrupt can be called from within RING0
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_RING0 0x00
|
2011-04-03 19:41:46 +02:00
|
|
|
/// Interrupt can be called from within RING1 and lower
|
2010-08-24 05:43:39 +00:00
|
|
|
#define IDT_FLAG_RING1 0x20
|
2011-04-03 19:41:46 +02:00
|
|
|
/// Interrupt can be called from within RING2 and lower
|
2010-08-24 05:43:39 +00:00
|
|
|
#define IDT_FLAG_RING2 0x40
|
2011-04-03 19:41:46 +02:00
|
|
|
/// Interrupt can be called from within RING3 and lower
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_RING3 0x60
|
2011-04-03 19:41:46 +02:00
|
|
|
/// Size of gate is 16 bit
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_16BIT 0x00
|
2011-04-03 19:41:46 +02:00
|
|
|
/// Size of gate is 32 bit
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_32BIT 0x08
|
2011-04-03 19:41:46 +02:00
|
|
|
/// The entry describes an interrupt gate
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_INTTRAP 0x06
|
2011-04-03 19:41:46 +02:00
|
|
|
/// The entry describes a trap gate
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_TRAPGATE 0x07
|
2011-04-03 19:41:46 +02:00
|
|
|
/// The entry describes a task gate
|
2010-08-09 11:47:51 +00:00
|
|
|
#define IDT_FLAG_TASKGATE 0x05
|
|
|
|
|
2011-04-03 19:41:46 +02:00
|
|
|
/*
|
|
|
|
* This is not IDT-flag related. It's the segment selectors for kernel code and data.
|
|
|
|
*/
|
2010-08-24 05:43:39 +00:00
|
|
|
#define KERNEL_CODE_SELECTOR 0x08
|
|
|
|
#define KERNEL_DATA_SELECTOR 0x10
|
|
|
|
|
2010-07-31 15:53:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-04-15 15:08:41 +02:00
|
|
|
/** @brief Defines an IDT entry
|
|
|
|
*
|
|
|
|
* This structure defines interrupt descriptor table entries.\n
|
|
|
|
* They consist of the handling function's base address, some flags
|
|
|
|
* and a segment selector.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/// Handler function's lower 16 address bits
|
2012-06-10 08:05:24 +02:00
|
|
|
uint16_t base_lo;
|
2011-04-15 15:08:41 +02:00
|
|
|
/// Handler function's segment selector.
|
2012-06-10 08:05:24 +02:00
|
|
|
uint16_t sel;
|
2011-04-15 15:08:41 +02:00
|
|
|
/// These bits are reserved by Intel
|
2012-06-10 08:05:24 +02:00
|
|
|
uint8_t always0;
|
2011-04-15 15:08:41 +02:00
|
|
|
/// These 8 bits contain flags. Exact use depends on the type of interrupt gate.
|
2012-06-10 08:05:24 +02:00
|
|
|
uint8_t flags;
|
2011-04-15 15:08:41 +02:00
|
|
|
/// Higher 16 bits of handler function's base address
|
2012-06-10 08:05:24 +02:00
|
|
|
uint16_t base_hi;
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/// In 64 bit mode, the "highest" 32 bits of the handler function's base address
|
|
|
|
uint32_t base_hi64;
|
|
|
|
/// resvered entries
|
|
|
|
uint32_t reserved;
|
|
|
|
#endif
|
2011-04-15 15:08:41 +02:00
|
|
|
} __attribute__ ((packed)) idt_entry_t;
|
|
|
|
|
|
|
|
/** @brief Defines the idt pointer structure.
|
|
|
|
*
|
|
|
|
* This structure keeps information about
|
|
|
|
* base address and size of the interrupt descriptor table.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/// Size of the IDT in bytes (not the number of entries!)
|
2012-06-10 08:05:24 +02:00
|
|
|
uint16_t limit;
|
2011-04-15 15:08:41 +02:00
|
|
|
/// Base address of the IDT
|
2012-06-10 08:05:24 +02:00
|
|
|
size_t base;
|
2011-04-15 15:08:41 +02:00
|
|
|
} __attribute__ ((packed)) idt_ptr_t;
|
|
|
|
|
2011-04-03 19:41:46 +02:00
|
|
|
/** @brief Installs IDT
|
|
|
|
*
|
|
|
|
* The installation involves the following steps:
|
|
|
|
* - Set up the IDT pointer
|
|
|
|
* - Set up int 0x80 for syscalls
|
|
|
|
* - process idt_load()
|
|
|
|
*/
|
2010-07-31 15:53:30 +00:00
|
|
|
void idt_install(void);
|
2011-04-03 19:41:46 +02:00
|
|
|
|
|
|
|
/** @brief Set an entry in the IDT
|
|
|
|
*
|
|
|
|
* @param num index in the IDT
|
|
|
|
* @param base base-address of the handler function being installed
|
|
|
|
* @param sel Segment the IDT will use
|
|
|
|
* @param flags Flags this entry will have
|
|
|
|
*/
|
2011-07-31 19:17:42 +02:00
|
|
|
void idt_set_gate(unsigned char num, size_t base, unsigned short sel,
|
2010-07-31 15:53:30 +00:00
|
|
|
unsigned char flags);
|
|
|
|
|
2012-06-13 09:57:01 +02:00
|
|
|
/** @brief Configures and returns a IDT entry with chosen attributes
|
|
|
|
*
|
|
|
|
* Just feed this function with base, selector and the flags
|
|
|
|
* you have seen in idt.h
|
|
|
|
*
|
|
|
|
* @return a preconfigured idt descriptor
|
|
|
|
*/
|
|
|
|
void configure_idt_entry(idt_entry_t *dest_entry, size_t base,
|
|
|
|
unsigned short sel, unsigned char flags);
|
|
|
|
|
2010-07-31 15:53:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|