mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +00:00
Kernel::CPU: Move headers into common directory
Alot of code is shared between i386/i686/x86 and x86_64 and a lot probably will be used for compatability modes. So we start by moving the headers into one Directory. We will probalby be able to move some cpp files aswell.
This commit is contained in:
parent
5a8cc07485
commit
0d934fc991
60 changed files with 412 additions and 208 deletions
1063
Kernel/Arch/x86/CPU.h
Normal file
1063
Kernel/Arch/x86/CPU.h
Normal file
File diff suppressed because it is too large
Load diff
114
Kernel/Arch/x86/DescriptorTable.h
Normal file
114
Kernel/Arch/x86/DescriptorTable.h
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/VirtualAddress.h>
|
||||
|
||||
#define GDT_SELECTOR_CODE0 0x08
|
||||
#define GDT_SELECTOR_DATA0 0x10
|
||||
#define GDT_SELECTOR_CODE3 0x18
|
||||
#define GDT_SELECTOR_DATA3 0x20
|
||||
#define GDT_SELECTOR_TLS 0x28
|
||||
#define GDT_SELECTOR_PROC 0x30
|
||||
#define GDT_SELECTOR_TSS 0x38
|
||||
|
||||
// SYSENTER makes certain assumptions on how the GDT is structured:
|
||||
static_assert(GDT_SELECTOR_CODE0 + 8 == GDT_SELECTOR_DATA0); // SS0 = CS0 + 8
|
||||
|
||||
// SYSEXIT makes certain assumptions on how the GDT is structured:
|
||||
static_assert(GDT_SELECTOR_CODE0 + 16 == GDT_SELECTOR_CODE3); // CS3 = CS0 + 16
|
||||
static_assert(GDT_SELECTOR_CODE0 + 24 == GDT_SELECTOR_DATA3); // SS3 = CS0 + 32
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
struct [[gnu::packed]] DescriptorTablePointer {
|
||||
u16 limit;
|
||||
void* address;
|
||||
};
|
||||
|
||||
union [[gnu::packed]] Descriptor {
|
||||
struct {
|
||||
u16 limit_lo;
|
||||
u16 base_lo;
|
||||
u8 base_hi;
|
||||
u8 type : 4;
|
||||
u8 descriptor_type : 1;
|
||||
u8 dpl : 2;
|
||||
u8 segment_present : 1;
|
||||
u8 limit_hi : 4;
|
||||
u8 : 1;
|
||||
u8 operation_size64 : 1;
|
||||
u8 operation_size32 : 1;
|
||||
u8 granularity : 1;
|
||||
u8 base_hi2;
|
||||
};
|
||||
struct {
|
||||
u32 low;
|
||||
u32 high;
|
||||
};
|
||||
|
||||
enum Type {
|
||||
Invalid = 0,
|
||||
AvailableTSS_16bit = 0x1,
|
||||
LDT = 0x2,
|
||||
BusyTSS_16bit = 0x3,
|
||||
CallGate_16bit = 0x4,
|
||||
TaskGate = 0x5,
|
||||
InterruptGate_16bit = 0x6,
|
||||
TrapGate_16bit = 0x7,
|
||||
AvailableTSS_32bit = 0x9,
|
||||
BusyTSS_32bit = 0xb,
|
||||
CallGate_32bit = 0xc,
|
||||
InterruptGate_32bit = 0xe,
|
||||
TrapGate_32bit = 0xf,
|
||||
};
|
||||
|
||||
VirtualAddress base() const
|
||||
{
|
||||
FlatPtr base = base_lo;
|
||||
base |= base_hi << 16u;
|
||||
base |= base_hi2 << 24u;
|
||||
return VirtualAddress { base };
|
||||
}
|
||||
|
||||
void set_base(VirtualAddress base)
|
||||
{
|
||||
base_lo = base.get() & 0xffffu;
|
||||
base_hi = (base.get() >> 16u) & 0xffu;
|
||||
base_hi2 = (base.get() >> 24u) & 0xffu;
|
||||
}
|
||||
|
||||
void set_limit(u32 length)
|
||||
{
|
||||
limit_lo = length & 0xffff;
|
||||
limit_hi = (length >> 16) & 0xf;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
206
Kernel/Arch/x86/ISRStubs.h
Normal file
206
Kernel/Arch/x86/ISRStubs.h
Normal file
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Arch/x86/Interrupts.h>
|
||||
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(80)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(81)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(82)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(83)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(84)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(85)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(86)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(87)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(88)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(89)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(90)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(91)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(92)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(93)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(94)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(95)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(96)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(97)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(98)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(99)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(100)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(101)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(102)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(103)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(104)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(105)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(106)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(107)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(108)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(109)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(110)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(111)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(112)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(113)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(114)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(115)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(116)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(117)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(118)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(119)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(120)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(121)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(122)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(123)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(124)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(125)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(126)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(127)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(128)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(129)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(130)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(131)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(132)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(133)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(134)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(135)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(136)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(137)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(138)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(139)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(140)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(141)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(142)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(143)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(144)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(145)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(146)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(147)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(148)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(149)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(150)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(151)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(152)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(153)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(154)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(155)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(156)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(157)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(158)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(159)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(160)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(161)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(162)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(163)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(164)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(165)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(166)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(167)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(168)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(169)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(170)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(171)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(172)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(173)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(174)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(175)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(176)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(177)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(178)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(179)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(180)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(181)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(182)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(183)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(184)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(185)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(186)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(187)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(188)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(189)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(190)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(191)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(192)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(193)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(194)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(195)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(196)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(197)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(198)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(199)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(200)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(201)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(202)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(203)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(204)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(205)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(206)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(207)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(208)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(209)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(210)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(211)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(212)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(213)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(214)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(215)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(216)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(217)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(218)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(219)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(220)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(221)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(222)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(223)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(224)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(225)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(226)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(227)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(228)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(229)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(230)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(231)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(232)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(233)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(234)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(235)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(236)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(237)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(238)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(239)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(240)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(241)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(242)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(243)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(244)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(245)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(246)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(247)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(248)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(249)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(250)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(251)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(252)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(253)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(254)
|
||||
GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(255)
|
52
Kernel/Arch/x86/Interrupts.h
Normal file
52
Kernel/Arch/x86/Interrupts.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class GenericInterruptHandeler;
|
||||
|
||||
extern "C" void interrupt_common_asm_entry();
|
||||
|
||||
#define GENERATE_GENERIC_INTERRUPT_HANDLER_ASM_ENTRY(isr_number) \
|
||||
extern "C" void interrupt_##isr_number##_asm_entry(); \
|
||||
asm(".globl interrupt_" #isr_number "_asm_entry\n" \
|
||||
"interrupt_" #isr_number "_asm_entry:\n" \
|
||||
" pushw $" #isr_number "\n" \
|
||||
" pushw $0\n" \
|
||||
" jmp interrupt_common_asm_entry\n");
|
||||
|
||||
void register_interrupt_handler(u8 number, void (*handler)());
|
||||
void register_user_callable_interrupt_handler(u8 number, void (*handler)());
|
||||
GenericInterruptHandler& get_interrupt_handler(u8 interrupt_number);
|
||||
void register_generic_interrupt_handler(u8 number, GenericInterruptHandler&);
|
||||
void unregister_generic_interrupt_handler(u8 number, GenericInterruptHandler&);
|
||||
|
||||
}
|
170
Kernel/Arch/x86/PageDirectory.h
Normal file
170
Kernel/Arch/x86/PageDirectory.h
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class PageDirectory;
|
||||
class PageTableEntry;
|
||||
|
||||
class PageDirectoryEntry {
|
||||
public:
|
||||
const PageTableEntry* page_table_base() const { return reinterpret_cast<PageTableEntry*>(m_raw & 0xfffff000u); }
|
||||
PageTableEntry* page_table_base() { return reinterpret_cast<PageTableEntry*>(m_raw & 0xfffff000u); }
|
||||
void set_page_table_base(u32 value)
|
||||
{
|
||||
m_raw &= 0x8000000000000fffULL;
|
||||
m_raw |= value & 0xfffff000;
|
||||
}
|
||||
|
||||
bool is_null() const { return m_raw == 0; }
|
||||
void clear() { m_raw = 0; }
|
||||
|
||||
u64 raw() const { return m_raw; }
|
||||
void copy_from(Badge<PageDirectory>, const PageDirectoryEntry& other) { m_raw = other.m_raw; }
|
||||
|
||||
enum Flags {
|
||||
Present = 1 << 0,
|
||||
ReadWrite = 1 << 1,
|
||||
UserSupervisor = 1 << 2,
|
||||
WriteThrough = 1 << 3,
|
||||
CacheDisabled = 1 << 4,
|
||||
Huge = 1 << 7,
|
||||
Global = 1 << 8,
|
||||
NoExecute = 0x8000000000000000ULL,
|
||||
};
|
||||
|
||||
bool is_present() const { return raw() & Present; }
|
||||
void set_present(bool b) { set_bit(Present, b); }
|
||||
|
||||
bool is_user_allowed() const { return raw() & UserSupervisor; }
|
||||
void set_user_allowed(bool b) { set_bit(UserSupervisor, b); }
|
||||
|
||||
bool is_huge() const { return raw() & Huge; }
|
||||
void set_huge(bool b) { set_bit(Huge, b); }
|
||||
|
||||
bool is_writable() const { return raw() & ReadWrite; }
|
||||
void set_writable(bool b) { set_bit(ReadWrite, b); }
|
||||
|
||||
bool is_write_through() const { return raw() & WriteThrough; }
|
||||
void set_write_through(bool b) { set_bit(WriteThrough, b); }
|
||||
|
||||
bool is_cache_disabled() const { return raw() & CacheDisabled; }
|
||||
void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); }
|
||||
|
||||
bool is_global() const { return raw() & Global; }
|
||||
void set_global(bool b) { set_bit(Global, b); }
|
||||
|
||||
bool is_execute_disabled() const { return raw() & NoExecute; }
|
||||
void set_execute_disabled(bool b) { set_bit(NoExecute, b); }
|
||||
|
||||
void set_bit(u64 bit, bool value)
|
||||
{
|
||||
if (value)
|
||||
m_raw |= bit;
|
||||
else
|
||||
m_raw &= ~bit;
|
||||
}
|
||||
|
||||
private:
|
||||
u64 m_raw;
|
||||
};
|
||||
|
||||
class PageTableEntry {
|
||||
public:
|
||||
void* physical_page_base() { return reinterpret_cast<void*>(m_raw & 0xfffff000u); }
|
||||
void set_physical_page_base(u32 value)
|
||||
{
|
||||
m_raw &= 0x8000000000000fffULL;
|
||||
m_raw |= value & 0xfffff000;
|
||||
}
|
||||
|
||||
u64 raw() const { return (u32)m_raw; }
|
||||
|
||||
enum Flags {
|
||||
Present = 1 << 0,
|
||||
ReadWrite = 1 << 1,
|
||||
UserSupervisor = 1 << 2,
|
||||
WriteThrough = 1 << 3,
|
||||
CacheDisabled = 1 << 4,
|
||||
Global = 1 << 8,
|
||||
NoExecute = 0x8000000000000000ULL,
|
||||
};
|
||||
|
||||
bool is_present() const { return raw() & Present; }
|
||||
void set_present(bool b) { set_bit(Present, b); }
|
||||
|
||||
bool is_user_allowed() const { return raw() & UserSupervisor; }
|
||||
void set_user_allowed(bool b) { set_bit(UserSupervisor, b); }
|
||||
|
||||
bool is_writable() const { return raw() & ReadWrite; }
|
||||
void set_writable(bool b) { set_bit(ReadWrite, b); }
|
||||
|
||||
bool is_write_through() const { return raw() & WriteThrough; }
|
||||
void set_write_through(bool b) { set_bit(WriteThrough, b); }
|
||||
|
||||
bool is_cache_disabled() const { return raw() & CacheDisabled; }
|
||||
void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); }
|
||||
|
||||
bool is_global() const { return raw() & Global; }
|
||||
void set_global(bool b) { set_bit(Global, b); }
|
||||
|
||||
bool is_execute_disabled() const { return raw() & NoExecute; }
|
||||
void set_execute_disabled(bool b) { set_bit(NoExecute, b); }
|
||||
|
||||
bool is_null() const { return m_raw == 0; }
|
||||
void clear() { m_raw = 0; }
|
||||
|
||||
void set_bit(u64 bit, bool value)
|
||||
{
|
||||
if (value)
|
||||
m_raw |= bit;
|
||||
else
|
||||
m_raw &= ~bit;
|
||||
}
|
||||
|
||||
private:
|
||||
u64 m_raw;
|
||||
};
|
||||
|
||||
static_assert(sizeof(PageDirectoryEntry) == 8);
|
||||
static_assert(sizeof(PageTableEntry) == 8);
|
||||
|
||||
class PageDirectoryPointerTable {
|
||||
public:
|
||||
PageDirectoryEntry* directory(size_t index)
|
||||
{
|
||||
return (PageDirectoryEntry*)(raw[index] & ~0xfffu);
|
||||
}
|
||||
|
||||
u64 raw[4];
|
||||
};
|
||||
|
||||
}
|
61
Kernel/Arch/x86/ProcessorInfo.h
Normal file
61
Kernel/Arch/x86/ProcessorInfo.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Processor;
|
||||
|
||||
class ProcessorInfo {
|
||||
Processor& m_processor;
|
||||
String m_cpuid;
|
||||
String m_brandstr;
|
||||
String m_features;
|
||||
u32 m_display_model;
|
||||
u32 m_display_family;
|
||||
u32 m_stepping;
|
||||
u32 m_type;
|
||||
u32 m_apic_id;
|
||||
|
||||
public:
|
||||
ProcessorInfo(Processor& processor);
|
||||
|
||||
const String& cpuid() const { return m_cpuid; }
|
||||
const String& brandstr() const { return m_brandstr; }
|
||||
const String& features() const { return m_features; }
|
||||
u32 display_model() const { return m_display_model; }
|
||||
u32 display_family() const { return m_display_family; }
|
||||
u32 stepping() const { return m_stepping; }
|
||||
u32 type() const { return m_type; }
|
||||
u32 apic_id() const { return m_apic_id; }
|
||||
|
||||
void set_apic_id(u32 apic_id) { m_apic_id = apic_id; }
|
||||
};
|
||||
|
||||
}
|
120
Kernel/Arch/x86/SafeMem.h
Normal file
120
Kernel/Arch/x86/SafeMem.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Atomic.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
struct RegisterState;
|
||||
|
||||
[[nodiscard]] bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at);
|
||||
[[nodiscard]] ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at);
|
||||
[[nodiscard]] bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at);
|
||||
[[nodiscard]] Optional<u32> safe_atomic_fetch_add_relaxed(volatile u32* var, u32 val);
|
||||
[[nodiscard]] Optional<u32> safe_atomic_exchange_relaxed(volatile u32* var, u32 val);
|
||||
[[nodiscard]] Optional<u32> safe_atomic_load_relaxed(volatile u32* var);
|
||||
[[nodiscard]] bool safe_atomic_store_relaxed(volatile u32* var, u32 val);
|
||||
[[nodiscard]] Optional<bool> safe_atomic_compare_exchange_relaxed(volatile u32* var, u32& expected, u32 val);
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE Optional<u32> safe_atomic_fetch_and_relaxed(volatile u32* var, u32 val)
|
||||
{
|
||||
auto expected_value = safe_atomic_load_relaxed(var);
|
||||
if (!expected_value.has_value())
|
||||
return {}; // fault
|
||||
u32& expected = expected_value.value();
|
||||
for (;;) {
|
||||
auto result = safe_atomic_compare_exchange_relaxed(var, expected, expected & val);
|
||||
if (!result.has_value())
|
||||
return {}; // fault
|
||||
if (result.value())
|
||||
return expected; // exchanged
|
||||
|
||||
// This is only so that we don't saturate the bus...
|
||||
AK::atomic_thread_fence(AK::MemoryOrder::memory_order_acquire);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE Optional<u32> safe_atomic_fetch_and_not_relaxed(volatile u32* var, u32 val)
|
||||
{
|
||||
auto expected_value = safe_atomic_load_relaxed(var);
|
||||
if (!expected_value.has_value())
|
||||
return {}; // fault
|
||||
u32& expected = expected_value.value();
|
||||
for (;;) {
|
||||
auto result = safe_atomic_compare_exchange_relaxed(var, expected, expected & ~val);
|
||||
if (!result.has_value())
|
||||
return {}; // fault
|
||||
if (result.value())
|
||||
return expected; // exchanged
|
||||
|
||||
// This is only so that we don't saturate the bus...
|
||||
AK::atomic_thread_fence(AK::MemoryOrder::memory_order_acquire);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE Optional<u32> safe_atomic_fetch_or_relaxed(volatile u32* var, u32 val)
|
||||
{
|
||||
auto expected_value = safe_atomic_load_relaxed(var);
|
||||
if (!expected_value.has_value())
|
||||
return {}; // fault
|
||||
u32& expected = expected_value.value();
|
||||
for (;;) {
|
||||
auto result = safe_atomic_compare_exchange_relaxed(var, expected, expected | val);
|
||||
if (!result.has_value())
|
||||
return {}; // fault
|
||||
if (result.value())
|
||||
return expected; // exchanged
|
||||
|
||||
// This is only so that we don't saturate the bus...
|
||||
AK::atomic_thread_fence(AK::MemoryOrder::memory_order_acquire);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE Optional<u32> safe_atomic_fetch_xor_relaxed(volatile u32* var, u32 val)
|
||||
{
|
||||
auto expected_value = safe_atomic_load_relaxed(var);
|
||||
if (!expected_value.has_value())
|
||||
return {}; // fault
|
||||
u32& expected = expected_value.value();
|
||||
for (;;) {
|
||||
auto result = safe_atomic_compare_exchange_relaxed(var, expected, expected ^ val);
|
||||
if (!result.has_value())
|
||||
return {}; // fault
|
||||
if (result.value())
|
||||
return expected; // exchanged
|
||||
|
||||
// This is only so that we don't saturate the bus...
|
||||
AK::atomic_thread_fence(AK::MemoryOrder::memory_order_acquire);
|
||||
}
|
||||
}
|
||||
|
||||
bool handle_safe_access_fault(RegisterState& regs, u32 fault_address);
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Arch/x86/CPU.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
|
|
88
Kernel/Arch/x86/TSS.h
Normal file
88
Kernel/Arch/x86/TSS.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
struct [[gnu::packed]] TSS32 {
|
||||
u16 backlink, __blh;
|
||||
u32 esp0;
|
||||
u16 ss0, __ss0h;
|
||||
u32 esp1;
|
||||
u16 ss1, __ss1h;
|
||||
u32 esp2;
|
||||
u16 ss2, __ss2h;
|
||||
u32 cr3, eip, eflags;
|
||||
u32 eax, ecx, edx, ebx, esp, ebp, esi, edi;
|
||||
u16 es, __esh;
|
||||
u16 cs, __csh;
|
||||
u16 ss, __ssh;
|
||||
u16 ds, __dsh;
|
||||
u16 fs, __fsh;
|
||||
u16 gs, __gsh;
|
||||
u16 ldt, __ldth;
|
||||
u16 trace, iomapbase;
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] TSS64 {
|
||||
u32 __1; // Link?
|
||||
u32 rsp0l;
|
||||
u32 rsp0h;
|
||||
u32 rsp1l;
|
||||
u32 rsp1h;
|
||||
u32 rsp2l;
|
||||
u32 rsp2h;
|
||||
u64 __2; //probably CR3 and EIP?
|
||||
u32 ist1l;
|
||||
u32 ist1h;
|
||||
u32 ist2l;
|
||||
u32 ist2h;
|
||||
u32 ist3l;
|
||||
u32 ist3h;
|
||||
u32 ist4l;
|
||||
u32 ist4h;
|
||||
u32 ist5l;
|
||||
u32 ist5h;
|
||||
u32 ist6l;
|
||||
u32 ist6h;
|
||||
u32 ist7l;
|
||||
u32 ist7h;
|
||||
u64 __3; // GS and LDTR?
|
||||
u16 __4;
|
||||
u16 iomapbase;
|
||||
};
|
||||
|
||||
#if ARCH(I386)
|
||||
using TSS = TSS32;
|
||||
#elif ARCH(X86_64)
|
||||
using TSS = TSS64;
|
||||
#endif
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue