Commit Graph

67 Commits

Author SHA1 Message Date
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Dan Klishch
96d44b1572 Userland: Make bit-fields compatible with MSVC C++ ABI 2023-12-07 10:28:19 -07:00
Simon Wanner
5557f05bb5 LibX86: Support decoding F2 SSE instructions
Previously the F2 table was generated, but not used by the instruction
decoder.
2023-11-10 11:01:59 +01:00
Simon Wanner
1d68c64b98 LibX86: Apply REX.W to B9-BF MOVs
All the MOVs in the B8-BF range can use the REX.W prefix, not just B8.
Previously instructions like `48 B9... mov rcx, imm64` were interpreted
as `mov rcx, imm32` because the REX.W prefix was only applied to
`48 B8... mov rax, imm64`.
2023-10-27 21:49:55 +02:00
Liav A
e1ee8f89f2 LibX86: Remove i686 support 2022-12-28 11:53:41 +01:00
Itamar
108a8e4c88 LibX86: Only pass ProcessorMode to Instruction constructor
We previously passed both OperandSize and AddressSize to the
constructor.

Both values were only ever 32-bit at construction.
We used AddressSize::Size64 to signify Long mode which was needlessly
complicated.
2022-12-11 22:06:30 +01:00
Itamar
9a136e354d LibX86: Use AddressSize::32 in Long mode
As the existing near-by comment says, the default size of displacements
& immediates is 32 bits even in Long mode.

This makes `disasm` work on our binaries in x86-64 builds.
2022-12-11 22:06:30 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Simon Wanner
0c8da1478a LibX86: Use '+' format parameter to include signs for displacements 2022-11-26 12:50:38 +01:00
Simon Wanner
2ae228dac7 LibX86: Add basic x86-64 support
Most of the 64-bit instructions default to 32-bit operands and select
64-bit using REX.W prefixes. Because of that instead of defining new
instruction formats, this reuses the 32-bit formats and changes them
to take the REX prefixes into account when necessary.

Additionally this removes, adds or modifies the instruction
descriptors in the 64-bit table, where they are different from 32-bit.

Using 'disasm' these changes seem to cover pretty much all of our
64-bit binaries (except for AVX) :^)

Note that UserspaceEmulator will need to account for these prefixed
versions in its 32-bit instruction handlers before being usable on
x86-64.
2022-11-26 12:50:38 +01:00
Simon Wanner
735fd5f5db LibX86: Split up the ModRM and SIB bytes into multiple members
This will allow adding extra bits with REX prefixes
2022-11-26 12:50:38 +01:00
Simon Wanner
4041ea835c LibX86: Add OP_regW_immW
This is a variation of OP_reg32_imm32 that turns into
"OP_reg64_imm64" with a REX.W prefix.
2022-11-26 12:50:38 +01:00
Simon Wanner
c5681e06c6 LibX86: Make Instruction::length work for invalid instructions 2022-11-26 12:50:38 +01:00
Simon Wanner
ab1f28d566 LibX86: Templatize the opcode table builders 2022-11-26 12:50:38 +01:00
Simon Wanner
06ece474e9 LibX86: Add {Address,Operand}Size::Size64
For now the opcode tables for OperandSize::Size64 are empty
2022-11-26 12:50:38 +01:00
Simon Wanner
a7268c3c74 LibX86+UserspaceEmulator: Introduce AddressSize and OperandSize enums
These replace the bools a32 and o32, which will make implementing
64-bit sizes possible. :^)
2022-11-26 12:50:38 +01:00
Tim Schumacher
7834e26ddb Everywhere: Explicitly link all binaries against the LibC target
Even though the toolchain implicitly links against -lc, it does not know
where it should get LibC from except for the sysroot. In the case of
Clang this causes it to pick up the LibC stub instead, which might be
slightly outdated and feature missing symbols.

This is currently not an issue that manifests because we pass through
the dependency on LibC and other libraries by accident, which causes
CMake to link against the LibC target (instead of just the library),
and thus points the linker at the build output directory.

Since we are looking to fix that in the upcoming commits, let's make
sure that everything will still be able to find the proper LibC first.
2022-11-01 14:49:09 +00:00
Nico Weber
2af028132a AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most places
Doesn't use them in libc headers so that those don't have to pull in
AK/Platform.h.

AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is
defined in clang builds as well.) Using AK_COMPILER_GCC simplifies
things some.

AK_COMPILER_CLANG isn't as much of a win, other than that it's
consistent with AK_COMPILER_GCC.
2022-10-04 23:35:07 +01:00
Brian Gianforcaro
d0a1775369 Everywhere: Fix a variety of typos
Spelling fixes found by `codespell`.
2022-09-14 04:46:49 +00:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
a4c251f858 LibX86: Convert register names to StringViews 2022-07-12 23:11:35 +02:00
Hendiadyoin1
f602bbf135 LibX86+disasm: Use an output format closer to objdump
This mainly does two things,
1. Removes spaces after commas
2. Elides "0x" and leading zeros in most contexts

Remaining differences are:
1. objdump always has memory size annotations
   We lack these and probably have some annotations wrong
2. Boolean check names
   We use jump-zero, while objdump uses jump-equal for example
3. We sometimes add "00 00" symbols, which objdump elides
4. We always demangle (This is a good thing)
5. We always resolve relocations (This is a good thing)
6. We seem to detect some symbols differently/incorrectly
2022-04-07 16:50:34 +02:00
Hendiadyoin1
6bb1505902 LibX86: Fix weird formatting in Interpreter.h 2022-04-07 16:50:34 +02:00
Hendiadyoin1
7ba2e5e3e7 LibX86: Add CMPXCHG8B, RDRAND and RDSEED
With this we can run following script with no errors:
```sh
for /usr/lib/*.so {
    disasm "$it" > /dev/zero
}
```
2022-04-06 18:30:22 +02:00
Hendiadyoin1
3e3b677852 LibX86: Support SSE2 :^)
This allows disassembly of binaries with SSE2 instructions in them.
SSE2 also extends all MMX instructions without affecting the mnemonic,
therefore these are just directed to the same function for now.
The UserspaceEmulator does not know this as of
this commit.
2022-04-06 18:30:22 +02:00
Hendiadyoin1
5987f0a8f5 LibX86: Mark MMX instructions as SSE instructions
SSE2 expands on the same opcodes as MMX, so we have to mutate on prefix
here.
2022-04-06 18:30:22 +02:00
Hendiadyoin1
fd2af972ed LibX86: Correct CVTSS2SI's register signature
This was annotated the wrong way around.
2022-04-06 18:30:22 +02:00
Hendiadyoin1
b7a8cfdde9 LibX86: Correctly name CVTTSS2SI_r32_xmm2m32
This was previously erroneously called CVTTPS2PI_r32_xmm2m32, while
the mnemonic was correctly CVTTSS2SI.
2022-04-02 18:37:38 +02:00
Hendiadyoin1
1432b6ab0a LibX86: Use the correct code for UNPCKLS
We were accidentally using 0x15, which was immediately overridden by
UNPCKHS
2022-04-02 18:37:38 +02:00
Hendiadyoin1
3cae69a6c2 LibX86: Correctly name the first xmm argument
We were accidentally calling it a mm-register
2022-04-02 18:37:38 +02:00
Hendiadyoin1
f951849fd5 LibX86: Don't print repz prefix for SSE instructions 2022-04-02 18:37:38 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Lenny Maiorani
f912a48315 Userland: Change static const variables to static constexpr
`static const` variables can be computed and initialized at run-time
during initialization or the first time a function is called. Change
them to `static constexpr` to ensure they are computed at
compile-time.

This allows some removal of `strlen` because the length of the
`StringView` can be used which is pre-computed at compile-time.
2022-03-18 19:58:57 +01:00
Lenny Maiorani
5c21f963ff Libraries: Use default constructors/destructors in LibX86
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-13 22:34:38 +01:00
mjz19910
10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
Hendiadyoin1
d001f8ba70 LibX86: Mark two InstructionDescriptor functions as const
Thanks clang-tidy
2021-12-23 12:45:36 -08:00
Daniel Bertalan
15a14d3d21 LibX86: Take load base address into consideration during disassembly
Since our executables are position-independent, the address values
extraced from processes don't correspond to their values within the ELF
file. We have to offset the absolute addresses by the load base address
to get the relative symbol that we need for disassembly.
2021-10-25 12:14:26 +02:00
Hediadyoin1
3ad6d87a45 LibX86: Add SSE support
This only adds the decodeing support for SSE, not SSE2, etc.
may contain traces of SSE2.
2021-10-17 13:06:23 -07:00
Brian Gianforcaro
677f227774 LibX86: Use default instead of an empty constructor/destructor
Default implementations allow for more optimizations.
See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-16 17:17:13 +02:00
Gunnar Beutner
594903742b LibX86: Stub out Disassembler::next() for x86_64
LibX86 doesn't currently support x86_64 opcodes which causes Profiler
to crash when clicking on any symbol in the call graph.
2021-08-02 17:11:47 +02:00
Brian Gianforcaro
18d6f9ed5c Libraries: Remove unused header includes 2021-08-01 08:10:16 +02:00
Hendiadyoin1
eb6af29421 LibX86: Add missing MovD and MovQ instructions
These are placeholders for now
2021-07-22 23:33:21 +02:00
Hendiadyoin1
efa42c4d45 LibX86: Use names closer to the spec for the Modrm
This gets rid of a lot of magic number shifts and ands.
2021-07-22 23:33:21 +02:00
Andreas Kling
e7136399a1 LibX86: Add INT1 instruction (needed for disassembly) 2021-07-20 18:05:05 +02:00
Hendiadyoin1
8e575d2f62 Debugger: Compile on x86_64
This is not guaranteed to work at all
2021-06-30 19:05:51 +02:00
Hendiadyoin1
5ffe23e4f3 AK+LibX86: Generalize u128/256 to AK::UFixedBigInt
Doing these as custom classes might be faster, especially when writing
them in SSE, but this would cause a lot of Code duplication and due to
the nature of constexprs and the intelligence of the compiler they might
be using SSE/MMX either way
2021-06-11 18:14:11 +04:30
Linus Groh
3a7574de82 LibX86: Replace fprintf(stderr) with warnln() 2021-05-31 17:43:54 +01:00
Linus Groh
d60ebbbba6 Revert "Userland: static vs non-static constexpr variables"
This reverts commit 800ea8ea96.

Booting the system no longer worked after these changes.
2021-05-21 10:30:52 +01:00