LibC: Add x86_64 Registers

This commit is contained in:
Hendiadyoin1 2021-03-07 16:11:25 +01:00 committed by Andreas Kling
parent 60caffb113
commit 009b196a04
Notes: sideshowbarker 2024-07-18 21:13:07 +09:00
4 changed files with 180 additions and 2 deletions

View File

@ -6,14 +6,15 @@ set(LOADER_SOURCES
file(GLOB AK_SOURCES "../../AK/*.cpp")
file(GLOB ELF_SOURCES "../Libraries/LibELF/*.cpp")
set(ELF_SOURCES ${ELF_SOURCES} ../Libraries/LibELF/Arch/i386/plt_trampoline.S)
file(GLOB LIBC_SOURCES1 "../Libraries/LibC/*.cpp")
file(GLOB LIBC_SOURCES2 "../Libraries/LibC/*/*.cpp")
if ("${SERENITY_ARCH}" STREQUAL "i686")
file(GLOB LIBC_SOURCES3 "../Libraries/LibC/arch/i386/*.S")
set(ELF_SOURCES ${ELF_SOURCES} ../Libraries/LibELF/Arch/i386/plt_trampoline.S)
elseif ("${SERENITY_ARCH}" STREQUAL "x86_64")
file(GLOB LIBC_SOURCES3 "../Libraries/LibC/arch/x86_64/*.S")
file(GLOB LIBC_SOURCES3 "../Libraries/LibC/arch/x86_64/*.S") # FIXME: this does not exist at this point!
set(ELF_SOURCES ${ELF_SOURCES} ../Libraries/LibELF/Arch/x86_64/plt_trampoline.S)
endif()
file(GLOB LIBSYSTEM_SOURCES "../Libraries/LibSystem/*.cpp")

View File

@ -60,6 +60,7 @@ if ("${SERENITY_ARCH}" STREQUAL "i686")
set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/i386/plt_trampoline.S)
elseif ("${SERENITY_ARCH}" STREQUAL "x86_64")
set(ASM_SOURCES "arch/x86_64/setjmp.S")
set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/x86_64/plt_trampoline.S)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -DSERENITY_LIBC_BUILD")

View File

@ -0,0 +1,33 @@
/*
* 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
#if ARCH(I386)
# include "i386/regs.h"
#elif ARCH(X86_64)
# include "x86_64/regs.h"
#endif

View File

@ -0,0 +1,143 @@
/*
* 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>
#define RREGISTER(num) \
union { \
u64 r##num; \
struct { \
u32 _; \
union { \
u32 r##num##d; \
struct { \
u16 __; \
union { \
u16 r##num##w; \
struct { \
u8 ___; \
u8 r##num##b; \
}; \
}; \
}; \
}; \
}; \
}
#define GPREGISTER(letter) \
union { \
u64 r##letter##x; \
struct \
{ \
u32 _; \
union { \
u32 e##letter##x; \
struct \
{ \
u16 __; \
union { \
u16 letter##x; \
struct { \
u8 letter##h; \
u8 letter##l; \
}; \
}; \
}; \
}; \
}; \
}
#define SPREGISTER(name) \
union { \
u64 r##name; \
struct \
{ \
u32 _; \
union { \
u32 e##name; \
struct \
{ \
u16 __; \
union { \
u16 name; \
struct { \
u8 ___; \
u8 name##l; \
}; \
}; \
}; \
}; \
}; \
}
struct [[gnu::packed]] PtraceRegisters {
GPREGISTER(a);
GPREGISTER(b);
GPREGISTER(c);
GPREGISTER(d);
SPREGISTER(sp);
SPREGISTER(bp);
SPREGISTER(si);
SPREGISTER(di);
SPREGISTER(ip); // technically there is no ipl, but what ever
RREGISTER(8);
RREGISTER(9);
RREGISTER(10);
RREGISTER(11);
RREGISTER(12);
RREGISTER(13);
RREGISTER(14);
RREGISTER(15);
// flags
union {
u64 rflags;
struct {
u32 _;
union {
u32 eflags;
struct {
u16 __;
u16 flags;
};
};
};
};
// These may not be used, unless we go back into compatability mode
u32 cs;
u32 ss;
u32 ds;
u32 es;
u32 fs;
u32 gs;
// FIXME: Add FPU registers and Flags
// FIXME: Add Ymm Xmm etc.
};