summaryrefslogtreecommitdiff
path: root/src/x86.h
blob: 484e5c22bcd88408101278f6cae07617ae11e663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//|_   _   _.     _  ._  |_   _.  _ |
//| | (/_ (_| \/ (/_ | | | | (_| (_ |<

#pragma once
#include "typedef.h"

enum X86Regs_t : U8 {
  eax = 0,
  ecx,
  edx,
  ebx,
  esp,
  ebp,
  esi,
  edi
};

enum X64Regs_t : U8 {
  rax = 0,
  rcx,
  rdx,
  rbx,
  rsp,
  rbp,
  rsi,
  rdi,
  r8,
  r9,
  r10,
  r11,
  r12,
  r13,
  r14,
  r15
};

union REG64 {
  REG64() = default;
  REG64( U64 x ) : u64( x ) {}
  REG64( U32 x ) { u64 = x; }

  REG64( I64 x ) : u64( *(U64*)( &x ) ) {}
  REG64( I32 x ) { u64 = *(U32*)( &x ); } 
  
  U32 u32[2];
  U64 u64;
};

constexpr U32 x86_encode_mov_imm32( U32 reg ) { return ( 0xb8 + reg ); }
constexpr U32 x86_encode_push_reg( U32 reg ) { return 0x50 | ( reg & 7 ); }
constexpr U32 x86_encoded_pop_reg( U32 reg ) { return 0x58 | ( reg & 7 ); }

enum X86Instructions_t : U8 {
  RET_NEAR = 0xc3,
  RET_FAR = 0xcb,
  RET_NEAR_IMM16 = 0xc2,
  RET_FAR_IMM16 = 0xca,
};