Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rarvm.h
Go to the documentation of this file.
1 /* Copyright 2015 the unarr project authors (see AUTHORS file).
2  License: LGPLv3 */
3 
4 /* adapted from https://code.google.com/p/theunarchiver/source/browse/XADMaster/RARVirtualMachine.h */
5 
6 #ifndef rar_vm_h
7 #define rar_vm_h
8 
9 #include <stdint.h>
10 #include <stdbool.h>
11 
12 #define RARProgramMemorySize 0x40000
13 #define RARProgramMemoryMask (RARProgramMemorySize - 1)
14 #define RARProgramWorkSize 0x3c000
15 #define RARProgramGlobalSize 0x2000
16 #define RARProgramSystemGlobalAddress RARProgramWorkSize
17 #define RARProgramSystemGlobalSize 64
18 #define RARProgramUserGlobalAddress (RARProgramSystemGlobalAddress + RARProgramSystemGlobalSize)
19 #define RARProgramUserGlobalSize (RARProgramGlobalSize - RARProgramSystemGlobalSize)
20 #define RARRuntimeMaxInstructions 250000000
21 
22 #define RARRegisterAddressingMode(n) (0 + (n))
23 #define RARRegisterIndirectAddressingMode(n) (8 + (n))
24 #define RARIndexedAbsoluteAddressingMode(n) (16 + (n))
25 #define RARAbsoluteAddressingMode 24
26 #define RARImmediateAddressingMode 25
27 #define RARNumberOfAddressingModes 26
28 
30 
32  uint32_t registers[8];
33  uint8_t memory[RARProgramMemorySize + sizeof(uint32_t) /* overflow sentinel */];
34 };
35 
36 typedef struct RARProgram_s RARProgram;
37 
38 /* Program building */
39 
40 enum {
82 };
83 
85 void RARDeleteProgram(RARProgram *prog);
86 bool RARProgramAddInstr(RARProgram *prog, uint8_t instruction, bool bytemode);
87 bool RARSetLastInstrOperands(RARProgram *prog, uint8_t addressingmode1, uint32_t value1, uint8_t addressingmode2, uint32_t value2);
89 
90 /* Execution */
91 
93 
94 /* Memory and register access (convenience) */
95 
96 void RARSetVirtualMachineRegisters(RARVirtualMachine *vm, uint32_t registers[8]);
97 uint32_t RARVirtualMachineRead32(RARVirtualMachine *vm, uint32_t address);
98 void RARVirtualMachineWrite32(RARVirtualMachine *vm, uint32_t address, uint32_t val);
99 uint8_t RARVirtualMachineRead8(RARVirtualMachine *vm, uint32_t address);
100 void RARVirtualMachineWrite8(RARVirtualMachine *vm, uint32_t address, uint8_t val);
101 
102 /* Instruction properties */
103 
104 int NumberOfRARInstructionOperands(uint8_t instruction);
105 bool RARInstructionHasByteMode(uint8_t instruction);
106 bool RARInstructionIsUnconditionalJump(uint8_t instruction);
107 bool RARInstructionIsRelativeJump(uint8_t instruction);
108 bool RARInstructionWritesFirstOperand(uint8_t instruction);
109 bool RARInstructionWritesSecondOperand(uint8_t instruction);
110 
111 /* Program debugging */
112 
113 #ifndef NDEBUG
114 void RARPrintProgram(RARProgram *prog);
115 #endif
116 
117 #endif