Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
5bfb7599
Commit
5bfb7599
authored
Oct 5, 2013
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Incorporate emit_thumb into new emit framework.
parent
6cdd3af6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
py/Makefile
+1
-1
1 addition, 1 deletion
py/Makefile
py/asmthumb.c
+46
-56
46 additions, 56 deletions
py/asmthumb.c
py/asmthumb.h
+1
-1
1 addition, 1 deletion
py/asmthumb.h
py/compile.c
+8
-0
8 additions, 0 deletions
py/compile.c
py/emitthumb.c
+227
-119
227 additions, 119 deletions
py/emitthumb.c
with
283 additions
and
177 deletions
py/Makefile
+
1
−
1
View file @
5bfb7599
CC
=
gcc
CC
=
gcc
CFLAGS
=
-Wall
-ansi
-std
=
gnu99
-Os
-DEMIT_ENABLE_CPY
-DEMIT_ENABLE_X64
#-DNDEBUG
CFLAGS
=
-Wall
-ansi
-std
=
gnu99
-Os
-DEMIT_ENABLE_CPY
-DEMIT_ENABLE_X64
-DEMIT_ENABLE_THUMB
#-DNDEBUG
LDFLAGS
=
LDFLAGS
=
SRC
=
\
SRC
=
\
...
...
This diff is collapsed.
Click to expand it.
py/asmthumb.c
+
46
−
56
View file @
5bfb7599
...
@@ -28,7 +28,7 @@ struct _asm_thumb_t {
...
@@ -28,7 +28,7 @@ struct _asm_thumb_t {
uint
stack_adjust
;
uint
stack_adjust
;
};
};
asm_thumb_t
*
asm_thumb_new
()
{
asm_thumb_t
*
asm_thumb_new
(
uint
max_num_labels
)
{
asm_thumb_t
*
as
;
asm_thumb_t
*
as
;
as
=
m_new
(
asm_thumb_t
,
1
);
as
=
m_new
(
asm_thumb_t
,
1
);
...
@@ -36,7 +36,8 @@ asm_thumb_t *asm_thumb_new() {
...
@@ -36,7 +36,8 @@ asm_thumb_t *asm_thumb_new() {
as
->
code_offset
=
0
;
as
->
code_offset
=
0
;
as
->
code_size
=
0
;
as
->
code_size
=
0
;
as
->
code_base
=
NULL
;
as
->
code_base
=
NULL
;
as
->
label_offsets
=
NULL
;
as
->
max_num_labels
=
max_num_labels
;
as
->
label_offsets
=
m_new
(
int
,
max_num_labels
);
as
->
num_locals
=
0
;
as
->
num_locals
=
0
;
return
as
;
return
as
;
...
@@ -65,23 +66,13 @@ void asm_thumb_start_pass(asm_thumb_t *as, int pass) {
...
@@ -65,23 +66,13 @@ void asm_thumb_start_pass(asm_thumb_t *as, int pass) {
as
->
pass
=
pass
;
as
->
pass
=
pass
;
as
->
code_offset
=
0
;
as
->
code_offset
=
0
;
as
->
next_label
=
1
;
as
->
next_label
=
1
;
if
(
pass
==
ASM_THUMB_PASS_1
)
{
as
->
max_num_labels
=
0
;
}
else
{
if
(
pass
==
ASM_THUMB_PASS_2
)
{
if
(
pass
==
ASM_THUMB_PASS_2
)
{
memset
(
as
->
label_offsets
,
-
1
,
as
->
max_num_labels
*
sizeof
(
int
));
memset
(
as
->
label_offsets
,
-
1
,
as
->
max_num_labels
*
sizeof
(
int
));
}
}
}
}
}
void
asm_thumb_end_pass
(
asm_thumb_t
*
as
)
{
void
asm_thumb_end_pass
(
asm_thumb_t
*
as
)
{
if
(
as
->
pass
==
ASM_THUMB_PASS_1
)
{
if
(
as
->
pass
==
ASM_THUMB_PASS_2
)
{
// calculate number of labels need
if
(
as
->
next_label
>
as
->
max_num_labels
)
{
as
->
max_num_labels
=
as
->
next_label
;
}
as
->
label_offsets
=
m_new
(
int
,
as
->
max_num_labels
);
}
else
if
(
as
->
pass
==
ASM_THUMB_PASS_2
)
{
// calculate size of code in bytes
// calculate size of code in bytes
as
->
code_size
=
as
->
code_offset
;
as
->
code_size
=
as
->
code_offset
;
as
->
code_base
=
m_new
(
byte
,
as
->
code_size
);
as
->
code_base
=
m_new
(
byte
,
as
->
code_size
);
...
@@ -226,7 +217,6 @@ int asm_thumb_label_new(asm_thumb_t *as) {
...
@@ -226,7 +217,6 @@ int asm_thumb_label_new(asm_thumb_t *as) {
}
}
void
asm_thumb_label_assign
(
asm_thumb_t
*
as
,
int
label
)
{
void
asm_thumb_label_assign
(
asm_thumb_t
*
as
,
int
label
)
{
if
(
as
->
pass
>
ASM_THUMB_PASS_1
)
{
assert
(
label
<
as
->
max_num_labels
);
assert
(
label
<
as
->
max_num_labels
);
if
(
as
->
pass
==
ASM_THUMB_PASS_2
)
{
if
(
as
->
pass
==
ASM_THUMB_PASS_2
)
{
// assign label offset
// assign label offset
...
@@ -238,6 +228,10 @@ void asm_thumb_label_assign(asm_thumb_t *as, int label) {
...
@@ -238,6 +228,10 @@ void asm_thumb_label_assign(asm_thumb_t *as, int label) {
assert
(
as
->
label_offsets
[
label
]
==
as
->
code_offset
);
assert
(
as
->
label_offsets
[
label
]
==
as
->
code_offset
);
}
}
}
}
static
int
get_label_dest
(
asm_thumb_t
*
as
,
int
label
)
{
assert
(
label
<
as
->
max_num_labels
);
return
as
->
label_offsets
[
label
];
}
}
// the i8 value will be zero extended into the r32 register!
// the i8 value will be zero extended into the r32 register!
...
@@ -339,8 +333,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
...
@@ -339,8 +333,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
int
label
)
{
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
int
label
)
{
if
(
as
->
pass
>
ASM_THUMB_PASS_1
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
dest
=
as
->
label_offsets
[
label
];
int
rel
=
dest
-
as
->
code_offset
;
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
if
(
dest
>=
0
&&
rel
<=
-
4
)
{
if
(
dest
>=
0
&&
rel
<=
-
4
)
{
...
@@ -357,7 +350,6 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) {
...
@@ -357,7 +350,6 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) {
asm_thumb_write_op32
(
as
,
OP_BW_HI
(
rel
),
OP_BW_LO
(
rel
));
asm_thumb_write_op32
(
as
,
OP_BW_HI
(
rel
),
OP_BW_LO
(
rel
));
}
}
}
}
}
#define OP_CMP_REG_IMM(rlo, i8) (0x2800 | ((rlo) << 8) | (i8))
#define OP_CMP_REG_IMM(rlo, i8) (0x2800 | ((rlo) << 8) | (i8))
// all these bit arithmetics need coverage testing!
// all these bit arithmetics need coverage testing!
...
@@ -372,8 +364,7 @@ void asm_thumb_cmp_reg_bz_label(asm_thumb_t *as, uint rlo, int label) {
...
@@ -372,8 +364,7 @@ void asm_thumb_cmp_reg_bz_label(asm_thumb_t *as, uint rlo, int label) {
asm_thumb_write_op16
(
as
,
OP_CMP_REG_IMM
(
rlo
,
0
));
asm_thumb_write_op16
(
as
,
OP_CMP_REG_IMM
(
rlo
,
0
));
// branch if equal
// branch if equal
if
(
as
->
pass
>
ASM_THUMB_PASS_1
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
dest
=
as
->
label_offsets
[
label
];
int
rel
=
dest
-
as
->
code_offset
;
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
if
(
dest
>=
0
&&
rel
<=
-
4
)
{
if
(
dest
>=
0
&&
rel
<=
-
4
)
{
...
@@ -390,7 +381,6 @@ void asm_thumb_cmp_reg_bz_label(asm_thumb_t *as, uint rlo, int label) {
...
@@ -390,7 +381,6 @@ void asm_thumb_cmp_reg_bz_label(asm_thumb_t *as, uint rlo, int label) {
asm_thumb_write_op32
(
as
,
OP_BEQW_HI
(
rel
),
OP_BEQW_LO
(
rel
));
asm_thumb_write_op32
(
as
,
OP_BEQW_HI
(
rel
),
OP_BEQW_LO
(
rel
));
}
}
}
}
}
#define OP_BLX(reg) (0x4780 | ((reg) << 3))
#define OP_BLX(reg) (0x4780 | ((reg) << 3))
#define OP_SVC(arg) (0xdf00 | (arg))
#define OP_SVC(arg) (0xdf00 | (arg))
...
...
This diff is collapsed.
Click to expand it.
py/asmthumb.h
+
1
−
1
View file @
5bfb7599
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
typedef
struct
_asm_thumb_t
asm_thumb_t
;
typedef
struct
_asm_thumb_t
asm_thumb_t
;
asm_thumb_t
*
asm_thumb_new
();
asm_thumb_t
*
asm_thumb_new
(
uint
max_num_labels
);
void
asm_thumb_free
(
asm_thumb_t
*
as
,
bool
free_code
);
void
asm_thumb_free
(
asm_thumb_t
*
as
,
bool
free_code
);
void
asm_thumb_start_pass
(
asm_thumb_t
*
as
,
int
pass
);
void
asm_thumb_start_pass
(
asm_thumb_t
*
as
,
int
pass
);
void
asm_thumb_end_pass
(
asm_thumb_t
*
as
);
void
asm_thumb_end_pass
(
asm_thumb_t
*
as
);
...
...
This diff is collapsed.
Click to expand it.
py/compile.c
+
8
−
0
View file @
5bfb7599
...
@@ -30,6 +30,7 @@ typedef enum {
...
@@ -30,6 +30,7 @@ typedef enum {
#define EMIT_OPT_NONE (0)
#define EMIT_OPT_NONE (0)
#define EMIT_OPT_BYTE_CODE (1)
#define EMIT_OPT_BYTE_CODE (1)
#define EMIT_OPT_NATIVE_PYTHON (2)
#define EMIT_OPT_NATIVE_PYTHON (2)
#define EMIT_OPT_ASM_THUMB (3)
typedef
struct
_compiler_t
{
typedef
struct
_compiler_t
{
qstr
qstr___class__
;
qstr
qstr___class__
;
...
@@ -41,6 +42,7 @@ typedef struct _compiler_t {
...
@@ -41,6 +42,7 @@ typedef struct _compiler_t {
qstr
qstr_assertion_error
;
qstr
qstr_assertion_error
;
qstr
qstr_micropython
;
qstr
qstr_micropython
;
qstr
qstr_native
;
qstr
qstr_native
;
qstr
qstr_asm_thumb
;
pass_kind_t
pass
;
pass_kind_t
pass
;
...
@@ -759,6 +761,8 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, py_parse_
...
@@ -759,6 +761,8 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, py_parse_
qstr
attr
=
PY_PARSE_NODE_LEAF_ARG
(
name_nodes
[
1
]);
qstr
attr
=
PY_PARSE_NODE_LEAF_ARG
(
name_nodes
[
1
]);
if
(
attr
==
comp
->
qstr_native
)
{
if
(
attr
==
comp
->
qstr_native
)
{
*
emit_options
=
EMIT_OPT_NATIVE_PYTHON
;
*
emit_options
=
EMIT_OPT_NATIVE_PYTHON
;
}
else
if
(
attr
==
comp
->
qstr_asm_thumb
)
{
*
emit_options
=
EMIT_OPT_ASM_THUMB
;
}
else
{
}
else
{
printf
(
"SyntaxError: invalid micropython decorator
\n
"
);
printf
(
"SyntaxError: invalid micropython decorator
\n
"
);
}
}
...
@@ -2551,6 +2555,7 @@ void py_compile(py_parse_node_t pn) {
...
@@ -2551,6 +2555,7 @@ void py_compile(py_parse_node_t pn) {
comp
->
qstr_assertion_error
=
qstr_from_str_static
(
"AssertionError"
);
comp
->
qstr_assertion_error
=
qstr_from_str_static
(
"AssertionError"
);
comp
->
qstr_micropython
=
qstr_from_str_static
(
"micropython"
);
comp
->
qstr_micropython
=
qstr_from_str_static
(
"micropython"
);
comp
->
qstr_native
=
qstr_from_str_static
(
"native"
);
comp
->
qstr_native
=
qstr_from_str_static
(
"native"
);
comp
->
qstr_asm_thumb
=
qstr_from_str_static
(
"asm_thumb"
);
comp
->
max_num_labels
=
0
;
comp
->
max_num_labels
=
0
;
comp
->
break_label
=
0
;
comp
->
break_label
=
0
;
...
@@ -2588,6 +2593,9 @@ void py_compile(py_parse_node_t pn) {
...
@@ -2588,6 +2593,9 @@ void py_compile(py_parse_node_t pn) {
comp
->
emit_method_table
=
&
emit_x64_method_table
;
comp
->
emit_method_table
=
&
emit_x64_method_table
;
break
;
break
;
//case EMIT_OPT_ASM_THUMB:
//if (em
default:
default:
if
(
emit_bc
==
NULL
)
{
if
(
emit_bc
==
NULL
)
{
emit_bc
=
emit_bc_new
(
comp
->
max_num_labels
);
emit_bc
=
emit_bc_new
(
comp
->
max_num_labels
);
...
...
This diff is collapsed.
Click to expand it.
py/emitthumb.c
+
227
−
119
View file @
5bfb7599
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