summaryrefslogtreecommitdiff
path: root/cpu/cpu-context.h
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
committerkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
commit065da3509019b15dd0e678072e6be629e5330bef (patch)
tree69c934c9e786ac048b4fbe8f4c4c5571661521f4 /cpu/cpu-context.h
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'cpu/cpu-context.h')
-rw-r--r--cpu/cpu-context.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/cpu/cpu-context.h b/cpu/cpu-context.h
new file mode 100644
index 0000000..1957df9
--- /dev/null
+++ b/cpu/cpu-context.h
@@ -0,0 +1,120 @@
+/***************************************************************
+ __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