Use a static variable to store idt
This commit is contained in:
parent
592c7d5882
commit
832e42fd0a
@ -28,14 +28,10 @@
|
|||||||
#include <kaneton.h>
|
#include <kaneton.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ---------- externs ---------------------------------------------------------
|
* ---------- globals ---------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
at_idte _idt[ARCHITECTURE_IDT_SIZE];
|
||||||
* the segment manager which contains the current IDT.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern m_segment _segment;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ---------- functions -------------------------------------------------------
|
* ---------- functions -------------------------------------------------------
|
||||||
@ -49,31 +45,30 @@ t_error architecture_idt_dump(void)
|
|||||||
|
|
||||||
module_call(console, message,
|
module_call(console, message,
|
||||||
'#', "IDT: table(0x%08x) size(%u)\n",
|
'#', "IDT: table(0x%08x) size(%u)\n",
|
||||||
_segment.machine.idt.table,
|
_idt, ARCHITECTURE_IDT_SIZE);
|
||||||
_segment.machine.idt.size);
|
|
||||||
|
|
||||||
for (i = 0; i < _segment.machine.idt.size; i++)
|
for (i = 0; i < ARCHITECTURE_IDT_SIZE; i++)
|
||||||
{
|
{
|
||||||
t_privilege privilege;
|
t_privilege privilege;
|
||||||
t_paddr offset;
|
t_paddr offset;
|
||||||
char* type;
|
char* type;
|
||||||
char flag;
|
char flag;
|
||||||
|
|
||||||
if (!(_segment.machine.idt.table[i] & ARCHITECTURE_IDTE_PRESENT))
|
if (!(_idt[i] & ARCHITECTURE_IDTE_PRESENT))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
offset = ARCHITECTURE_IDTE_OFFSET_GET(_segment.machine.idt.table[i]);
|
offset = ARCHITECTURE_IDTE_OFFSET_GET(_idt[i]);
|
||||||
|
|
||||||
privilege = ARCHITECTURE_IDTE_DPL_GET(_segment.machine.idt.table[i]);
|
privilege = ARCHITECTURE_IDTE_DPL_GET(_idt[i]);
|
||||||
|
|
||||||
if (_segment.machine.idt.table[i] & ARCHITECTURE_GDTE_32BIT)
|
if (_idt[i] & ARCHITECTURE_GDTE_32BIT)
|
||||||
flag = 's';
|
flag = 's';
|
||||||
else
|
else
|
||||||
flag = '.';
|
flag = '.';
|
||||||
|
|
||||||
if ((_segment.machine.idt.table[i] & ARCHITECTURE_IDTE_TRAP) == ARCHITECTURE_IDTE_TRAP)
|
if ((_idt[i] & ARCHITECTURE_IDTE_TRAP) == ARCHITECTURE_IDTE_TRAP)
|
||||||
type = "trap";
|
type = "trap";
|
||||||
else if ((_segment.machine.idt.table[i] & ARCHITECTURE_IDTE_INTERRUPT) == ARCHITECTURE_IDTE_INTERRUPT)
|
else if ((_idt[i] & ARCHITECTURE_IDTE_INTERRUPT) == ARCHITECTURE_IDTE_INTERRUPT)
|
||||||
type = "interrupt";
|
type = "interrupt";
|
||||||
else
|
else
|
||||||
type = "task";
|
type = "task";
|
||||||
@ -87,61 +82,23 @@ t_error architecture_idt_dump(void)
|
|||||||
MACHINE_LEAVE();
|
MACHINE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error architecture_idt_import(as_idt* idt)
|
|
||||||
{
|
|
||||||
as_idtr idtr;
|
|
||||||
|
|
||||||
if (idt == NULL)
|
|
||||||
MACHINE_ESCAPE("the 'idt' argument is null");
|
|
||||||
|
|
||||||
idtr.base = (t_paddr)idt->table;
|
|
||||||
idtr.limit = idt->size * sizeof (at_idte);
|
|
||||||
|
|
||||||
ARCHITECTURE_LIDT(idtr);
|
|
||||||
|
|
||||||
memcpy(&_segment.machine.idt, idt, sizeof (as_idt));
|
|
||||||
|
|
||||||
MACHINE_LEAVE();
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error architecture_idt_export(as_idt* idt)
|
|
||||||
{
|
|
||||||
as_idtr idtr;
|
|
||||||
at_idte* source;
|
|
||||||
at_idte* dest;
|
|
||||||
|
|
||||||
if (idt == NULL)
|
|
||||||
MACHINE_ESCAPE("the 'idt' argument is null");
|
|
||||||
|
|
||||||
ARCHITECTURE_SIDT(idtr);
|
|
||||||
|
|
||||||
source = (at_idte*)idtr.base;
|
|
||||||
dest = idt->table;
|
|
||||||
|
|
||||||
memcpy(dest, source, idtr.limit);
|
|
||||||
|
|
||||||
idt->size = idtr.limit / sizeof (at_idte);
|
|
||||||
|
|
||||||
MACHINE_LEAVE();
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error architecture_idt_insert(t_uint16 index,
|
t_error architecture_idt_insert(t_uint16 index,
|
||||||
t_paddr offset,
|
t_paddr offset,
|
||||||
t_flags flags)
|
t_flags flags)
|
||||||
{
|
{
|
||||||
if (index >= _segment.machine.idt.size)
|
if (index >= ARCHITECTURE_IDT_SIZE)
|
||||||
MACHINE_ESCAPE("out-of-bound insertion");
|
MACHINE_ESCAPE("out-of-bound insertion");
|
||||||
|
|
||||||
if (_segment.machine.idt.table[index] & ARCHITECTURE_IDTE_PRESENT)
|
if (_idt[index] & ARCHITECTURE_IDTE_PRESENT)
|
||||||
MACHINE_ESCAPE("the IDT entry to update is already in use");
|
MACHINE_ESCAPE("the IDT entry to update is already in use");
|
||||||
|
/*
|
||||||
_segment.machine.idt.table[index] =
|
_idt[index] =
|
||||||
ARCHITECTURE_IDTE_INTERRUPT |
|
ARCHITECTURE_IDTE_INTERRUPT |
|
||||||
ARCHITECTURE_IDTE_PRESENT |
|
ARCHITECTURE_IDTE_PRESENT |
|
||||||
ARCHITECTURE_IDTE_OFFSET_SET(offset) |
|
ARCHITECTURE_IDTE_OFFSET_SET(offset) |
|
||||||
ARCHITECTURE_IDTE_32BIT |
|
ARCHITECTURE_IDTE_32BIT |
|
||||||
flags;
|
flags;
|
||||||
|
*/
|
||||||
MACHINE_LEAVE();
|
MACHINE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,8 +113,8 @@ t_error architecture_idt_reserve(t_paddr base,
|
|||||||
|
|
||||||
*index = 0;
|
*index = 0;
|
||||||
|
|
||||||
for (i = 0; i < _segment.machine.idt.size; i++)
|
for (i = 0; i < ARCHITECTURE_IDT_SIZE; i++)
|
||||||
if (!(_segment.machine.idt.table[i] & ARCHITECTURE_IDTE_PRESENT))
|
if (!(_idt[i] & ARCHITECTURE_IDTE_PRESENT))
|
||||||
{
|
{
|
||||||
*index = i;
|
*index = i;
|
||||||
|
|
||||||
@ -172,35 +129,20 @@ t_error architecture_idt_reserve(t_paddr base,
|
|||||||
|
|
||||||
t_error architecture_idt_delete(t_uint16 index)
|
t_error architecture_idt_delete(t_uint16 index)
|
||||||
{
|
{
|
||||||
if (index >= _segment.machine.idt.size)
|
if (index >= ARCHITECTURE_IDT_SIZE)
|
||||||
MACHINE_ESCAPE("out-of-bound insertion");
|
MACHINE_ESCAPE("out-of-bound insertion");
|
||||||
|
|
||||||
if (!(_segment.machine.idt.table[index] & ARCHITECTURE_IDTE_PRESENT))
|
if (!(_idt[index] & ARCHITECTURE_IDTE_PRESENT))
|
||||||
MACHINE_ESCAPE("the IDT entry to delete is not present");
|
MACHINE_ESCAPE("the IDT entry to delete is not present");
|
||||||
|
|
||||||
memset(&_segment.machine.idt.table[index], 0x0, sizeof (at_idte));
|
memset(&_idt[index], 0x0, sizeof (at_idte));
|
||||||
|
|
||||||
MACHINE_LEAVE();
|
MACHINE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error architecture_idt_build(t_paddr base,
|
t_error architecture_idt_build()
|
||||||
t_psize size,
|
|
||||||
as_idt* idt)
|
|
||||||
{
|
{
|
||||||
if (idt == NULL)
|
memset(_idt, 0x0, ARCHITECTURE_IDT_SIZE * sizeof (at_idte));
|
||||||
MACHINE_ESCAPE("the 'idt' argument is null");
|
|
||||||
|
|
||||||
if (size > (ARCHITECTURE_IDT_SIZE * sizeof (at_idte)))
|
|
||||||
MACHINE_ESCAPE("the given size is too large as exceeding the IDT's "
|
|
||||||
"theoretically maximum capacity");
|
|
||||||
|
|
||||||
if (base % sizeof (at_idte))
|
|
||||||
base += sizeof (at_idte) - (base % sizeof (at_idte));
|
|
||||||
|
|
||||||
idt->table = (at_idte*)base;
|
|
||||||
idt->size = size / sizeof (at_idte);
|
|
||||||
|
|
||||||
memset(idt->table, 0x0, idt->size * sizeof (at_idte));
|
|
||||||
|
|
||||||
MACHINE_LEAVE();
|
MACHINE_LEAVE();
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
* ../handler.c
|
* ../handler.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void handler(int num);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* eop
|
* eop
|
||||||
|
@ -142,12 +142,6 @@
|
|||||||
|
|
||||||
typedef t_uint64 at_idte;
|
typedef t_uint64 at_idte;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
at_idte* table;
|
|
||||||
t_uint16 size;
|
|
||||||
} as_idt;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
t_uint16 limit;
|
t_uint16 limit;
|
||||||
@ -166,16 +160,8 @@ typedef struct
|
|||||||
|
|
||||||
t_error architecture_idt_dump(void);
|
t_error architecture_idt_dump(void);
|
||||||
|
|
||||||
t_error architecture_idt_build(t_paddr base,
|
|
||||||
t_psize size,
|
|
||||||
as_idt* idt);
|
|
||||||
|
|
||||||
t_error architecture_idt_import(as_idt* idt);
|
|
||||||
|
|
||||||
t_error architecture_idt_export(as_idt* idt);
|
|
||||||
|
|
||||||
t_error architecture_idt_insert(t_uint16 index,
|
t_error architecture_idt_insert(t_uint16 index,
|
||||||
t_paddr base,
|
t_paddr offset,
|
||||||
t_flags flags);
|
t_flags flags);
|
||||||
|
|
||||||
t_error architecture_idt_reserve(t_paddr base,
|
t_error architecture_idt_reserve(t_paddr base,
|
||||||
@ -184,6 +170,9 @@ t_error architecture_idt_reserve(t_paddr base,
|
|||||||
|
|
||||||
t_error architecture_idt_delete(t_uint16 index);
|
t_error architecture_idt_delete(t_uint16 index);
|
||||||
|
|
||||||
|
t_error architecture_idt_build();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* eop
|
* eop
|
||||||
*/
|
*/
|
||||||
|
@ -47,15 +47,6 @@ d_event glue_event_dispatch =
|
|||||||
|
|
||||||
/* FIXED at K1 */
|
/* FIXED at K1 */
|
||||||
|
|
||||||
/*
|
|
||||||
* ---------- globals ---------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* the init structure.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern m_segment* _segment;
|
|
||||||
/*
|
/*
|
||||||
* ---------- functions -------------------------------------------------------
|
* ---------- functions -------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -63,11 +54,8 @@ extern m_segment* _segment;
|
|||||||
t_error glue_event_initialize(void)
|
t_error glue_event_initialize(void)
|
||||||
{
|
{
|
||||||
t_uint16 i;
|
t_uint16 i;
|
||||||
as_idt idt;
|
|
||||||
|
|
||||||
if (architecture_idt_build((t_paddr) &_segment->machine.idt,
|
if (architecture_idt_build() != ERROR_OK)
|
||||||
ARCHITECTURE_IDT_SIZE * sizeof (at_idte),
|
|
||||||
&idt) != ERROR_OK)
|
|
||||||
MACHINE_ESCAPE("unable to initialize the IDT");
|
MACHINE_ESCAPE("unable to initialize the IDT");
|
||||||
|
|
||||||
architecture_idt_insert(i, (t_uint32) &idt_wrapper_0, ARCHITECTURE_IDTE_DPL_SET(ARCHITECTURE_PRIVILEGE_RING0));
|
architecture_idt_insert(i, (t_uint32) &idt_wrapper_0, ARCHITECTURE_IDTE_DPL_SET(ARCHITECTURE_PRIVILEGE_RING0));
|
||||||
|
@ -75,14 +75,9 @@
|
|||||||
* ../event.c
|
* ../event.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
t_error glue_event_reserve(i_event id,
|
|
||||||
t_type type,
|
|
||||||
u_event_handler handler,
|
|
||||||
t_data data);
|
|
||||||
|
|
||||||
|
|
||||||
t_error glue_event_initialize(void);
|
t_error glue_event_initialize(void);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* eop
|
* eop
|
||||||
*/
|
*/
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
struct \
|
struct \
|
||||||
{ \
|
{ \
|
||||||
as_gdt gdt; \
|
as_gdt gdt; \
|
||||||
as_idt idt; \
|
|
||||||
} machine;
|
} machine;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user