2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-02-08 19:34:41 +01:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2018-10-16 11:01:38 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-07-06 07:27:22 -06:00
|
|
|
#include <AK/Atomic.h>
|
2021-07-01 14:51:41 +02:00
|
|
|
#include <AK/Concepts.h>
|
2020-06-27 17:06:33 -06:00
|
|
|
#include <AK/Vector.h>
|
2021-03-07 21:28:28 +01:00
|
|
|
|
|
|
|
|
#include <Kernel/Arch/x86/DescriptorTable.h>
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2021-06-21 17:34:09 +02:00
|
|
|
/* Map IRQ0-15 @ ISR 0x50-0x5F */
|
|
|
|
|
#define IRQ_VECTOR_BASE 0x50
|
2020-07-06 07:27:22 -06:00
|
|
|
#define GENERIC_INTERRUPT_HANDLERS_COUNT (256 - IRQ_VECTOR_BASE)
|
2021-07-17 00:49:12 +02:00
|
|
|
#define PAGE_MASK (~(FlatPtr)0xfffu)
|
2018-10-18 13:05:00 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-06-29 10:35:00 +02:00
|
|
|
struct RegisterState;
|
2021-06-21 17:34:09 +02:00
|
|
|
class GenericInterruptHandler;
|
2019-06-26 21:45:56 +02:00
|
|
|
|
2020-12-22 18:23:34 +01:00
|
|
|
static constexpr u32 safe_eflags_mask = 0xdff;
|
2020-12-23 14:18:13 +01:00
|
|
|
static constexpr u32 iopl_mask = 3u << 12;
|
|
|
|
|
|
|
|
|
|
inline u32 get_iopl_from_eflags(u32 eflags)
|
|
|
|
|
{
|
|
|
|
|
return (eflags & iopl_mask) >> 12;
|
|
|
|
|
}
|
2020-12-22 18:23:34 +01:00
|
|
|
|
2020-06-04 09:10:16 -06:00
|
|
|
const DescriptorTablePointer& get_gdtr();
|
|
|
|
|
const DescriptorTablePointer& get_idtr();
|
2021-06-21 17:34:09 +02:00
|
|
|
|
2021-07-18 09:59:50 -07:00
|
|
|
[[noreturn]] void handle_crash(RegisterState const&, char const* description, int signal, bool out_of_memory = false);
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
#define LSW(x) ((u32)(x)&0xFFFF)
|
|
|
|
|
#define MSW(x) (((u32)(x) >> 16) & 0xFFFF)
|
2019-05-28 11:53:16 +02:00
|
|
|
#define LSB(x) ((x)&0xFF)
|
|
|
|
|
#define MSB(x) (((x) >> 8) & 0xFF)
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2020-10-20 10:08:13 -06:00
|
|
|
constexpr FlatPtr page_base_of(FlatPtr address)
|
2018-10-18 13:05:00 +02:00
|
|
|
{
|
2020-01-09 23:33:36 +02:00
|
|
|
return address & PAGE_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 10:36:51 +01:00
|
|
|
inline FlatPtr page_base_of(const void* address)
|
2020-01-20 13:06:41 +01:00
|
|
|
{
|
2020-03-08 10:36:51 +01:00
|
|
|
return page_base_of((FlatPtr)address);
|
2020-01-20 13:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-20 10:08:13 -06:00
|
|
|
constexpr FlatPtr offset_in_page(FlatPtr address)
|
2020-01-09 23:33:36 +02:00
|
|
|
{
|
|
|
|
|
return address & (~PAGE_MASK);
|
2018-10-18 13:05:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-08 10:36:51 +01:00
|
|
|
inline FlatPtr offset_in_page(const void* address)
|
2020-01-20 13:06:41 +01:00
|
|
|
{
|
2020-03-08 10:36:51 +01:00
|
|
|
return offset_in_page((FlatPtr)address);
|
2020-01-20 13:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|