Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libtcg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton
libtcg
Commits
194abcf1
Commit
194abcf1
authored
2 years ago
by
Anton Johansson
Committed by
Anton
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add `max_pc`
parent
ddbdeeee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
accel/tcg/translator.c
+2
-1
2 additions, 1 deletion
accel/tcg/translator.c
include/exec/translation-block.h
+2
-0
2 additions, 0 deletions
include/exec/translation-block.h
libtcg/libtcg.c
+47
-40
47 additions, 40 deletions
libtcg/libtcg.c
with
51 additions
and
41 deletions
accel/tcg/translator.c
+
2
−
1
View file @
194abcf1
...
...
@@ -203,7 +203,8 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
/* Stop translation if the output buffer is full,
or we have executed all of the allowed instructions. */
if
(
tcg_op_buf_full
()
||
db
->
num_insns
>=
db
->
max_insns
)
{
if
(
tcg_op_buf_full
()
||
db
->
num_insns
>=
db
->
max_insns
||
db
->
pc_next
>=
tb
->
max_pc
)
{
db
->
is_jmp
=
DISAS_TOO_MANY
;
break
;
}
...
...
This diff is collapsed.
Click to expand it.
include/exec/translation-block.h
+
2
−
0
View file @
194abcf1
...
...
@@ -63,6 +63,8 @@ struct TranslationBlock {
*/
uint64_t
cs_base
;
vaddr
max_pc
;
/* maximum PC for this block */
uint32_t
flags
;
/* flags defining in which context the code was generated */
uint32_t
cflags
;
/* compile flags */
...
...
This diff is collapsed.
Click to expand it.
libtcg/libtcg.c
+
47
−
40
View file @
194abcf1
...
...
@@ -35,10 +35,10 @@
*/
#include
"libtcg/libtcg.h"
typedef
struct
LibT
inyCode
Context
{
LibT
inyCode
Desc
desc
;
typedef
struct
LibT
cg
Context
{
LibT
cg
Desc
desc
;
CPUState
*
cpu
;
}
LibT
inyCode
Context
;
}
LibT
cg
Context
;
/*
* Here we hold some information about the bytecode we're going
...
...
@@ -61,6 +61,9 @@ typedef struct BytecodeRegion {
CPUState *cpu = env_cpu(env); \
BytecodeRegion *region = cpu->opaque; \
uint64_t offset = (uintptr_t)ptr - region->virtual_address; \
printf(" offset: %lu\n", offset); \
printf(" region->size: %lu\n", region->size);\
printf(" region->virtual_address: %lu\n", region->virtual_address);\
assert(offset + sizeof(read_type) <= region->size); \
return *(read_type *) ((uintptr_t) region->buffer + offset); \
}
...
...
@@ -81,13 +84,13 @@ static inline bool instruction_has_label_argument(TCGOpcode opc)
opc
==
INDEX_op_brcond2_i32
);
}
const
char
*
libtcg_get_instruction_name
(
LibT
inyCode
Opcode
opcode
)
const
char
*
libtcg_get_instruction_name
(
LibT
cg
Opcode
opcode
)
{
TCGOpDef
def
=
tcg_op_defs
[(
TCGOpcode
)
opcode
];
return
def
.
name
;
}
LibT
inyCode
CallInfo
libtcg_get_call_info
(
LibT
inyCode
Instruction
*
insn
)
LibT
cg
CallInfo
libtcg_get_call_info
(
LibT
cg
Instruction
*
insn
)
{
/*
* For a call instruction, the first constant argument holds
...
...
@@ -102,13 +105,13 @@ LibTinyCodeCallInfo libtcg_get_call_info(LibTinyCodeInstruction *insn)
assert
(
insn
->
opcode
==
LIBTCG_op_call
);
uintptr_t
ptr_to_helper_info
=
insn
->
constant_args
[
1
].
constant
;
TCGHelperInfo
*
info
=
(
void
*
)
ptr_to_helper_info
;
return
(
LibT
inyCode
CallInfo
)
{
return
(
LibT
cg
CallInfo
)
{
.
func_name
=
info
->
name
,
.
func_flags
=
info
->
flags
,
};
}
LibT
inyCode
Context
*
libtcg_context_create
(
LibT
inyCode
Desc
*
desc
)
LibT
cg
Context
*
libtcg_context_create
(
LibT
cg
Desc
*
desc
)
{
assert
(
desc
);
...
...
@@ -122,7 +125,7 @@ LibTinyCodeContext *libtcg_context_create(LibTinyCodeDesc *desc)
}
/* Initialize context */
LibT
inyCode
Context
*
context
=
desc
->
mem_alloc
(
sizeof
(
LibT
inyCode
Context
));
LibT
cg
Context
*
context
=
desc
->
mem_alloc
(
sizeof
(
LibT
cg
Context
));
if
(
context
==
NULL
)
return
NULL
;
context
->
desc
=
*
desc
;
...
...
@@ -157,12 +160,12 @@ LibTinyCodeContext *libtcg_context_create(LibTinyCodeDesc *desc)
return
context
;
}
void
libtcg_context_destroy
(
LibT
inyCode
Context
*
context
)
void
libtcg_context_destroy
(
LibT
cg
Context
*
context
)
{
context
->
desc
.
mem_free
(
context
);
}
LibT
inyCode
InstructionList
libtcg_translate
(
LibT
inyCode
Context
*
context
,
LibT
cg
InstructionList
libtcg_translate
(
LibT
cg
Context
*
context
,
const
unsigned
char
*
buffer
,
size_t
size
,
uint64_t
virtual_address
)
...
...
@@ -203,19 +206,21 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
TranslationBlock
tb
=
{
.
pc
=
pc
,
.
cs_base
=
cs_base
,
.
max_pc
=
virtual_address
+
size
,
.
flags
=
flags
,
.
cflags
=
cflags
,
};
gen_intermediate_code
(
context
->
cpu
,
&
tb
,
max_insns
);
LibT
inyCode
InstructionList
instruction_list
=
{
.
list
=
context
->
desc
.
mem_alloc
(
sizeof
(
LibT
inyCode
Instruction
)
*
LIBTCG_MAX_INSTRUCTIONS
),
LibT
cg
InstructionList
instruction_list
=
{
.
list
=
context
->
desc
.
mem_alloc
(
sizeof
(
LibT
cg
Instruction
)
*
tcg_ctx
->
nb_ops
),
.
instruction_count
=
0
,
.
temps
=
context
->
desc
.
mem_alloc
(
sizeof
(
LibTinyCodeTemp
)
*
LIBTCG_MAX_TEMPS
),
/* Note: tcg_ctx->nb_temps includes tcg_ctx->nb_globals */
.
temps
=
context
->
desc
.
mem_alloc
(
sizeof
(
LibTcgTemp
)
*
tcg_ctx
->
nb_temps
),
.
temp_count
=
0
,
.
labels
=
context
->
desc
.
mem_alloc
(
sizeof
(
LibT
inyCode
Label
)
*
LIBTCG_MAX_LABELS
),
.
labels
=
context
->
desc
.
mem_alloc
(
sizeof
(
LibT
cg
Label
)
*
(
tcg_ctx
->
nb_labels
)
),
.
label_count
=
0
,
.
size_in_bytes
=
tb
.
size
,
...
...
@@ -236,8 +241,8 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
assert
(
def
.
nb_oargs
<=
LIBTCG_INSN_MAX_ARGS
);
assert
(
def
.
nb_iargs
<=
LIBTCG_INSN_MAX_ARGS
);
assert
(
def
.
nb_cargs
<=
LIBTCG_INSN_MAX_ARGS
);
LibT
inyCode
Instruction
insn
=
{
.
opcode
=
(
LibT
inyCode
Opcode
)
opc
,
LibT
cg
Instruction
insn
=
{
.
opcode
=
(
LibT
cg
Opcode
)
opc
,
.
flags
=
def
.
flags
,
.
nb_oargs
=
def
.
nb_oargs
,
.
nb_iargs
=
def
.
nb_iargs
,
...
...
@@ -273,14 +278,16 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
* TCG enums are stable.
*/
assert
(
instruction_list
.
temp_count
<
LIBTCG_MAX_TEMPS
);
LibTinyCodeTemp
*
temp
=
&
instruction_list
.
temps
[
instruction_list
.
temp_count
++
];
temp
->
kind
=
(
LibTinyCodeTempKind
)
ts
->
kind
;
temp
->
type
=
(
LibTinyCodeTempType
)
ts
->
type
;
assert
(
idx
<
LIBTCG_MAX_TEMPS
);
LibTcgTemp
*
temp
=
&
instruction_list
.
temps
[
idx
];
temp
->
kind
=
(
LibTcgTempKind
)
ts
->
kind
;
temp
->
type
=
(
LibTcgTempType
)
ts
->
type
;
temp
->
val
=
ts
->
val
;
temp
->
num
=
idx
-
tcg_ctx
->
nb_globals
;
temp
->
index
=
idx
;
temp
->
mem_offset
=
ts
->
mem_offset
;
tcg_get_arg_str
(
tcg_ctx
,
temp
->
name
,
LIBTCG_MAX_NAME_LEN
,
op
->
args
[
i
]);
insn
.
output_args
[
i
]
=
(
LibT
inyCode
Argument
)
{
insn
.
output_args
[
i
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_TEMP
,
.
temp
=
temp
,
};
...
...
@@ -295,14 +302,16 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
* TCG enums are stable.
*/
assert
(
instruction_list
.
temp_count
<
LIBTCG_MAX_TEMPS
);
LibTinyCodeTemp
*
temp
=
&
instruction_list
.
temps
[
instruction_list
.
temp_count
++
];
temp
->
kind
=
(
LibTinyCodeTempKind
)
ts
->
kind
;
temp
->
type
=
(
LibTinyCodeTempType
)
ts
->
type
;
assert
(
idx
<
LIBTCG_MAX_TEMPS
);
LibTcgTemp
*
temp
=
&
instruction_list
.
temps
[
idx
];
temp
->
kind
=
(
LibTcgTempKind
)
ts
->
kind
;
temp
->
type
=
(
LibTcgTempType
)
ts
->
type
;
temp
->
val
=
ts
->
val
;
temp
->
num
=
idx
-
tcg_ctx
->
nb_globals
;
temp
->
index
=
idx
;
temp
->
mem_offset
=
ts
->
mem_offset
;
tcg_get_arg_str
(
tcg_ctx
,
temp
->
name
,
LIBTCG_MAX_NAME_LEN
,
op
->
args
[
insn
.
nb_oargs
+
i
]);
insn
.
input_args
[
i
]
=
(
LibT
inyCode
Argument
)
{
insn
.
input_args
[
i
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_TEMP
,
.
temp
=
temp
,
};
...
...
@@ -322,9 +331,9 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
// if (false && i == 0 && instruction_has_label_argument(opc)) {
// TCGLabel *label =
// arg_label(op->args[insn.nb_oargs + insn.nb_iargs + i]);
// LibT
inyCode
Label *our_label = &instruction_list.labels[label->id];
// LibT
cg
Label *our_label = &instruction_list.labels[label->id];
// our_label->id = label->id;
// insn.constant_args[i] = (LibT
inyCode
Argument) {
// insn.constant_args[i] = (LibT
cg
Argument) {
// .kind = LIBTCG_ARG_LABEL,
// .label = our_label
// };
...
...
@@ -333,14 +342,13 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
// * If we get to here the constant arg was actually a
// * constant
// */
// insn.constant_args[i] = (LibT
inyCode
Argument) {
// insn.constant_args[i] = (LibT
cg
Argument) {
// .kind = LIBTCG_ARG_CONSTANT,
// .constant = op->args[insn.nb_oargs + insn.nb_iargs + i],
// };
// }
//}
uint32_t
start_index
=
0
;
switch
(
opc
)
{
...
...
@@ -354,7 +362,7 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
case
INDEX_op_movcond_i64
:
case
INDEX_op_cmp_vec
:
case
INDEX_op_cmpsel_vec
:
insn
.
constant_args
[
start_index
]
=
(
LibT
inyCode
Argument
)
{
insn
.
constant_args
[
start_index
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_COND
,
.
cond
=
op
->
args
[
insn
.
nb_oargs
+
insn
.
nb_iargs
+
start_index
],
};
...
...
@@ -367,7 +375,7 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
case
INDEX_op_qemu_st_i64
:
{
MemOpIdx
oi
=
op
->
args
[
insn
.
nb_oargs
+
insn
.
nb_iargs
+
start_index
];
insn
.
constant_args
[
start_index
]
=
(
LibT
inyCode
Argument
)
{
insn
.
constant_args
[
start_index
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_MEM_OP_INDEX
,
.
mem_op_index
=
{
.
op
=
get_memop
(
oi
),
...
...
@@ -383,7 +391,7 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
case
INDEX_op_bswap32_i64
:
case
INDEX_op_bswap64_i64
:
{
insn
.
constant_args
[
start_index
]
=
(
LibT
inyCode
Argument
)
{
insn
.
constant_args
[
start_index
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_BSWAP
,
.
bswap_flag
=
op
->
args
[
insn
.
nb_oargs
+
insn
.
nb_iargs
+
start_index
],
};
...
...
@@ -403,9 +411,9 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
{
TCGLabel
*
label
=
arg_label
(
op
->
args
[
insn
.
nb_oargs
+
insn
.
nb_iargs
+
start_index
]);
LibT
inyCode
Label
*
our_label
=
&
instruction_list
.
labels
[
label
->
id
];
LibT
cg
Label
*
our_label
=
&
instruction_list
.
labels
[
label
->
id
];
our_label
->
id
=
label
->
id
;
insn
.
constant_args
[
start_index
]
=
(
LibT
inyCode
Argument
)
{
insn
.
constant_args
[
start_index
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_LABEL
,
.
label
=
our_label
};
...
...
@@ -417,28 +425,27 @@ LibTinyCodeInstructionList libtcg_translate(LibTinyCodeContext *context,
}
for
(
uint32_t
i
=
start_index
;
i
<
insn
.
nb_cargs
;
++
i
)
{
insn
.
constant_args
[
i
]
=
(
LibT
inyCode
Argument
)
{
insn
.
constant_args
[
i
]
=
(
LibT
cg
Argument
)
{
.
kind
=
LIBTCG_ARG_CONSTANT
,
.
constant
=
op
->
args
[
insn
.
nb_oargs
+
insn
.
nb_iargs
+
i
],
};
}
assert
(
instruction_list
.
instruction_count
<
LIBTCG_MAX_INSTRUCTIONS
);
instruction_list
.
list
[
instruction_list
.
instruction_count
++
]
=
insn
;
}
return
instruction_list
;
}
void
libtcg_instruction_list_destroy
(
LibT
inyCode
Context
*
context
,
LibT
inyCode
InstructionList
instruction_list
)
void
libtcg_instruction_list_destroy
(
LibT
cg
Context
*
context
,
LibT
cg
InstructionList
instruction_list
)
{
context
->
desc
.
mem_free
(
instruction_list
.
list
);
context
->
desc
.
mem_free
(
instruction_list
.
temps
);
context
->
desc
.
mem_free
(
instruction_list
.
labels
);
}
uint8_t
*
libtcg_env_ptr
(
LibT
inyCode
Context
*
context
)
uint8_t
*
libtcg_env_ptr
(
LibT
cg
Context
*
context
)
{
return
(
uint8_t
*
)
context
->
cpu
->
env_ptr
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment