Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
Container Registry
Model registry
Operate
Environments
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
03d41243
Commit
03d41243
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Add b_n opcode to inline thumb asm.
parent
b14de21f
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
py/asmthumb.c
+14
-2
14 additions, 2 deletions
py/asmthumb.c
py/asmthumb.h
+1
-0
1 addition, 0 deletions
py/asmthumb.h
py/emitinlinethumb.c
+13
-3
13 additions, 3 deletions
py/emitinlinethumb.c
with
28 additions
and
5 deletions
py/asmthumb.c
+
14
−
2
View file @
03d41243
...
...
@@ -288,6 +288,19 @@ void asm_thumb_cmp_rlo_i8(asm_thumb_t *as, uint rlo, int i8) {
asm_thumb_write_op16
(
as
,
OP_CMP_RLO_I8
(
rlo
,
i8
));
}
#define OP_B_N(byte_offset) (0xe000 | (((byte_offset) >> 1) & 0x07ff))
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
int
label
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
if
(
SIGNED_FIT12
(
rel
))
{
asm_thumb_write_op16
(
as
,
OP_B_N
(
rel
));
}
else
{
printf
(
"asm_thumb_b_n: branch does not fit in 12 bits
\n
"
);
}
}
#define OP_BEQ_N(byte_offset) (0xd000 | (((byte_offset) >> 1) & 0x00ff))
#define OP_BNE_N(byte_offset) (0xd100 | (((byte_offset) >> 1) & 0x00ff))
#define OP_BCS_N(byte_offset) (0xd200 | (((byte_offset) >> 1) & 0x00ff))
...
...
@@ -371,7 +384,6 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
asm_thumb_write_op16
(
as
,
0xbfac
);
}
#define OP_B(byte_offset) (0xe000 | (((byte_offset) >> 1) & 0x07ff))
// this could be wrong, because it should have a range of +/- 16MiB...
#define OP_BW_HI(byte_offset) (0xf000 | (((byte_offset) >> 12) & 0x07ff))
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
...
...
@@ -384,7 +396,7 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) {
// is a backwards jump, so we know the size of the jump on the first pass
// calculate rel assuming 12 bit relative jump
if
(
SIGNED_FIT12
(
rel
))
{
asm_thumb_write_op16
(
as
,
OP_B
(
rel
));
asm_thumb_write_op16
(
as
,
OP_B
_N
(
rel
));
}
else
{
goto
large_jump
;
}
...
...
This diff is collapsed.
Click to expand it.
py/asmthumb.h
+
1
−
0
View file @
03d41243
...
...
@@ -49,6 +49,7 @@ void asm_thumb_movt_reg_i16(asm_thumb_t *as, uint reg_dest, int i16_src);
void
asm_thumb_mov_reg_reg
(
asm_thumb_t
*
as
,
uint
reg_dest
,
uint
reg_src
);
void
asm_thumb_subs_rlo_rlo_i3
(
asm_thumb_t
*
as
,
uint
rlo_dest
,
uint
rlo_src
,
int
i3_src
);
void
asm_thumb_cmp_rlo_i8
(
asm_thumb_t
*
as
,
uint
rlo
,
int
i8
);
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
int
label
);
void
asm_thumb_bgt_n
(
asm_thumb_t
*
as
,
int
label
);
void
asm_thumb_mov_reg_i32
(
asm_thumb_t
*
as
,
uint
reg_dest
,
machine_uint_t
i32_src
);
// convenience
...
...
This diff is collapsed.
Click to expand it.
py/emitinlinethumb.c
+
13
−
3
View file @
03d41243
...
...
@@ -52,7 +52,7 @@ static void emit_inline_thumb_end_pass(emit_inline_asm_t *emit) {
static
int
emit_inline_thumb_count_params
(
emit_inline_asm_t
*
emit
,
int
n_params
,
py_parse_node_t
*
pn_params
)
{
if
(
n_params
>
4
)
{
printf
(
"SyntaxError: can only have up to
3
parameters to inline assembl
er
\n
"
);
printf
(
"SyntaxError: can only have up to
4
parameters to inline
thumb
assembl
y
\n
"
);
return
0
;
}
for
(
int
i
=
0
;
i
<
n_params
;
i
++
)
{
...
...
@@ -62,7 +62,7 @@ static int emit_inline_thumb_count_params(emit_inline_asm_t *emit, int n_params,
}
const
char
*
p
=
qstr_str
(
PY_PARSE_NODE_LEAF_ARG
(
pn_params
[
i
]));
if
(
!
(
strlen
(
p
)
==
2
&&
p
[
0
]
==
'r'
&&
p
[
1
]
==
'0'
+
i
))
{
printf
(
"SyntaxError: parameter %d to inline assembler must be r%d
\n
"
,
i
,
i
);
printf
(
"SyntaxError: parameter %d to inline assembler must be r%d
\n
"
,
i
+
1
,
i
);
return
0
;
}
}
...
...
@@ -128,6 +128,9 @@ static int get_arg_label(emit_inline_asm_t *emit, qstr op, py_parse_node_t *pn_a
static
void
emit_inline_thumb_op
(
emit_inline_asm_t
*
emit
,
qstr
op
,
int
n_args
,
py_parse_node_t
*
pn_args
)
{
// TODO perhaps make two tables:
// one_args =
// "b", LAB, asm_thumb_b_n,
// "bgt", LAB, asm_thumb_bgt_n,
// two_args =
// "movs", RLO, I8, asm_thumb_movs_reg_i8
// "movw", REG, REG, asm_thumb_movw_reg_i16
...
...
@@ -135,7 +138,14 @@ static void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, p
// "subs", RLO, RLO, I3, asm_thumb_subs_reg_reg_i3
// 1 arg
if
(
strcmp
(
qstr_str
(
op
),
"bgt"
)
==
0
)
{
if
(
strcmp
(
qstr_str
(
op
),
"b"
)
==
0
)
{
if
(
!
check_n_arg
(
op
,
n_args
,
1
))
{
return
;
}
int
label_num
=
get_arg_label
(
emit
,
op
,
pn_args
,
0
);
// TODO check that this succeeded, ie branch was within range
asm_thumb_b_n
(
emit
->
as
,
label_num
);
}
else
if
(
strcmp
(
qstr_str
(
op
),
"bgt"
)
==
0
)
{
if
(
!
check_n_arg
(
op
,
n_args
,
1
))
{
return
;
}
...
...
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