blob: 5fb4eb9c99253746045891bbc13394aad2771f63 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/***************************************************************
__CPU_CONTEXT.H
This file contains CPU CONTEXT operation functions & data
declarations.
PART OF : CPU - library .
USAGE : Internal only .
NOTE : Include "libcpu.h" before this FILE .
Copyright (C) 2026 by Andrew V.Kosteltsev.
All Rights Reserved.
***************************************************************/
#ifndef __CPU_CONTEXT_H
#define __CPU_CONTEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#define CPU_GUEST_FD_MAX 256
typedef struct __cpu_fd_entry
{
int host_fd;
unsigned int owned;
unsigned int flags;
} __cpu_fd_entry;
typedef struct __cpu_context cpu_context;
struct __cpu_context
{
__mpu_uint64_t _pc;
__mpu_uint64_t _sp;
__mpu_uint64_t _fp;
__mpu_uint32_t _psw;
cpu_stop_reason _stop_reason;
__mpu_int32_t _exit_status;
__mpu_UNIT_t *_program;
__mpu_uint64_t _program_size;
__mpu_uint64_t _program_capacity;
__mpu_UNIT_t *_data;
__mpu_uint64_t _data_size;
__mpu_uint64_t _data_capacity;
__mpu_UNIT_t *_stack;
__mpu_uint64_t _stack_size;
__mpu_uint64_t _stack_capacity;
__mpu_UNIT_t *_control;
__mpu_uint64_t _control_size;
__mpu_uint64_t _control_capacity;
__mpu_UNIT_t *_input;
__mpu_uint64_t _input_size;
__mpu_uint64_t _input_capacity;
__mpu_UNIT_t *_output;
__mpu_uint64_t _output_size;
__mpu_uint64_t _output_capacity;
__mpu_UNIT_t *_trace;
__mpu_uint64_t _trace_size;
__mpu_uint64_t _trace_capacity;
__mpu_UNIT_t *_heap;
__mpu_uint64_t _heap_brk;
__mpu_uint64_t _heap_size;
__mpu_uint64_t _heap_capacity;
__mpu_uint64_t _heap_limit;
int _fd_initialized;
__cpu_fd_entry _fd[CPU_GUEST_FD_MAX];
int _cwd_initialized;
int _cwd_fd;
__mpu_UNIT_t _regs[CPU_REGISTERS_MEM_SIZE_IN_UNITS];
};
extern __thread struct __cpu_context *pcctx;
#define __PC (pcctx->_pc)
#define __SP (pcctx->_sp)
#define __FP (pcctx->_fp)
#define __REGS ((__mpu_UNIT_t *)&pcctx->_regs[0])
#define __PROGRAM (pcctx->_program)
#define __PSIZE (pcctx->_program_size)
#define __PCAP (pcctx->_program_capacity)
#define __DATA (pcctx->_data)
#define __DSIZE (pcctx->_data_size)
#define __DCAP (pcctx->_data_capacity)
#define __STACK (pcctx->_stack)
#define __SSIZE (pcctx->_stack_size)
#define __SCAP (pcctx->_stack_capacity)
#define __CONTROL (pcctx->_control)
#define __CSIZE (pcctx->_control_size)
#define __CCAP (pcctx->_control_capacity)
#define __INPUT (pcctx->_input)
#define __ISIZE (pcctx->_input_size)
#define __ICAP (pcctx->_input_capacity)
#define __OUTPUT (pcctx->_output)
#define __OSIZE (pcctx->_output_size)
#define __OCAP (pcctx->_output_capacity)
#define __TRACE (pcctx->_trace)
#define __TSIZE (pcctx->_trace_size)
#define __TCAP (pcctx->_trace_capacity)
#define __HEAP (pcctx->_heap)
#define __HBRK (pcctx->_heap_brk)
#define __HSIZE (pcctx->_heap_size)
#define __HCAP (pcctx->_heap_capacity)
#define __HLIMIT (pcctx->_heap_limit)
#define __STOP_REASON (pcctx->_stop_reason)
#define __EXIT_STATUS (pcctx->_exit_status)
#define __CPU_PSW (pcctx->_psw)
#define __SET_CFLAG(mask) (pcctx->_psw |= (mask))
#define __CLEAR_CFLAG(mask) (pcctx->_psw &= ~(mask))
#define __INVERT_CFLAG(mask) (pcctx->_psw ^= (mask))
#define __CFLAG(mask,shift) ((pcctx->_psw & (mask)) >> (shift))
extern __mpu_uint64_t __cpu_heap_brk( __mpu_uint64_t new_brk );
#ifdef __cplusplus
}
#endif
#endif
|