// The OS/K Team licences this file to you under the MIT license. // See the LICENCE file in the project root for more information. #include #include #include #define log printf #define packed __attribute__ ((__packed__)) #define static_assert _Static_assert typedef unsigned int bool; typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef struct reg_t reg_t; typedef struct ctx_t ctx_t; typedef struct instr_t instr_t; typedef struct acc_t acc_t; typedef struct arch_t arch_t; enum { RAX, RBX, RCX, RDX, RDI, RSI, RBP, RSP, R08, R09, R10, R11, R12, R13, R14, R15, K00, K01, K02, K03, K04, K05, K06, K07, CR0, CR1, CR2, CR3, CR4, CR5, CR6, CR7, RIP, RFG, NREGS }; enum { I_ADD, I_SUB, I_MUL, I_DIV, I_INC, I_DEC, I_AND, I_OR, I_XOR, I_NEG, I_CMD, I_TST, I_PUSH, I_PUSHF, I_PUSHA, I_POP, I_POPF, I_POPA, I_MOV, I_XCHG, I_BSWP, I_PSE, I_HLT, I_INT, NINSTRS }; enum { GPR = 1 << 0, // General CTL = 1 << 1, // Control SEG = 1 << 2, // Segment RES = 1 << 8, // Reserved for insternal use SYS = 1 << 9, // Reserved for supervisor mode }; struct reg_t { char *name; char *desc; ulong val; ulong flags; }; enum { A_MEM=0x7000 }; struct acc_t { bool mem; enum { A_REG=0, A_IMM16=0x7001, A_IMM32, A_IMM64 } type; ulong val; }; enum { NOPREF, PREF_REP=0x8000, PREF_LOCK, NPREFS }; #define ISPREF(x) ((x) & 0x8000 && (x)