bond/x64/src/hal/hal_intr.c

58 lines
1.9 KiB
C
Raw Normal View History

2016-05-24 07:27:26 +00:00
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
2016-06-01 05:00:29 +00:00
#include "hal_intr.h"
#include "hal_print.h"
#include "hal_mem.h"
2015-04-22 08:06:15 +00:00
2016-06-01 05:00:29 +00:00
void KAPI hal_write_gate(void *const gate,
uint64_t const offset,
uint32_t const selector,
uint32_t const attr)
2015-04-22 08:06:15 +00:00
{
((uint8_t *) gate)[0] = (uint8_t) (offset & 0xFF);
((uint8_t *) gate)[1] = (uint8_t) ((offset >> 8) & 0xFF);
((uint8_t *) gate)[2] = (uint8_t) (selector & 0xFF);
((uint8_t *) gate)[3] = (uint8_t) ((selector >> 8) & 0xFF);
((uint8_t *) gate)[4] = (uint8_t) (attr & 0xFF);
((uint8_t *) gate)[5] = (uint8_t) ((attr >> 8) & 0xFF);
((uint8_t *) gate)[6] = (uint8_t) ((offset >> 16) & 0xFF);
((uint8_t *) gate)[7] = (uint8_t) ((offset >> 24) & 0xFF);
((uint8_t *) gate)[8] = (uint8_t) ((offset >> 32) & 0xFF);
((uint8_t *) gate)[9] = (uint8_t) ((offset >> 40) & 0xFF);
((uint8_t *) gate)[10] = (uint8_t) ((offset >> 48) & 0xFF);
((uint8_t *) gate)[11] = (uint8_t) ((offset >> 56) & 0xFF);
((uint8_t *) gate)[12] = 0;
((uint8_t *) gate)[13] = 0;
((uint8_t *) gate)[14] = 0;
((uint8_t *) gate)[15] = 0;
return;
2015-04-22 08:06:15 +00:00
}
2016-06-01 05:00:29 +00:00
void KAPI hal_set_interrupt_handler(uint64_t index,
void (*handler)(void))
2015-04-22 08:06:15 +00:00
{
hal_write_gate(g_idt + 16 * index, (uint64_t) handler, seg_selector(1, 0),
GATE_DPL_0 | GATE_PRESENT | GATE_TYPE_INTERRUPT);
return;
2015-09-03 14:45:28 +00:00
}
2016-06-01 05:00:29 +00:00
void KAPI hal_assert(int64_t expression,
char *message)
2015-09-03 14:45:28 +00:00
{
if (!expression)
2015-09-03 14:45:28 +00:00
{
hal_printf("HAL: Assertion failed. Detail: %s", message == NULL ? "NULL" : message);
hal_halt_cpu();
2015-09-03 14:45:28 +00:00
}
return;
}
void KAPI hal_interrupt_dispatcher(void)
{
hal_printf("Yep... That just happened, an interrupt...\n");
return;
}