Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
851f15f3
Commit
851f15f3
authored
Sep 29, 2014
by
Damien George
Browse files
py: In asmthumb, clean up unit/int types and ite ops.
parent
860805aa
Changes
4
Hide whitespace changes
Inline
Side-by-side
py/asmthumb.c
View file @
851f15f3
...
...
@@ -42,17 +42,16 @@
#define SIGNED_FIT12(x) (((x) & 0xfffff800) == 0) || (((x) & 0xfffff800) == 0xfffff800)
struct
_asm_thumb_t
{
uint
pass
;
uint
code_offset
;
uint
code_size
;
mp_
uint
_t
pass
;
mp_
uint
_t
code_offset
;
mp_
uint
_t
code_size
;
byte
*
code_base
;
byte
dummy_data
[
4
];
uint
max_num_labels
;
int
*
label_offsets
;
int
num_locals
;
uint
push_reglist
;
uint
stack_adjust
;
mp_uint_t
max_num_labels
;
mp_uint_t
*
label_offsets
;
mp_uint_t
push_reglist
;
mp_uint_t
stack_adjust
;
};
asm_thumb_t
*
asm_thumb_new
(
uint
max_num_labels
)
{
...
...
@@ -60,7 +59,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) {
as
=
m_new0
(
asm_thumb_t
,
1
);
as
->
max_num_labels
=
max_num_labels
;
as
->
label_offsets
=
m_new
(
in
t
,
max_num_labels
);
as
->
label_offsets
=
m_new
(
mp_uint_
t
,
max_num_labels
);
return
as
;
}
...
...
@@ -88,7 +87,7 @@ void asm_thumb_start_pass(asm_thumb_t *as, uint pass) {
as
->
pass
=
pass
;
as
->
code_offset
=
0
;
if
(
pass
==
ASM_THUMB_PASS_COMPUTE
)
{
memset
(
as
->
label_offsets
,
-
1
,
as
->
max_num_labels
*
sizeof
(
in
t
));
memset
(
as
->
label_offsets
,
-
1
,
as
->
max_num_labels
*
sizeof
(
mp_uint_
t
));
}
}
...
...
@@ -169,7 +168,7 @@ STATIC void asm_thumb_write_word32(asm_thumb_t *as, int w32) {
// locals:
// - stored on the stack in ascending order
// - numbered 0 through
as->
num_locals-1
// - numbered 0 through num_locals-1
// - SP points to first local
//
// | SP
...
...
@@ -222,7 +221,6 @@ void asm_thumb_entry(asm_thumb_t *as, int num_locals) {
}
as
->
push_reglist
=
reglist
;
as
->
stack_adjust
=
stack_adjust
;
as
->
num_locals
=
num_locals
;
}
void
asm_thumb_exit
(
asm_thumb_t
*
as
)
{
...
...
@@ -262,7 +260,7 @@ void asm_thumb_data(asm_thumb_t* as, uint bytesize, uint val) {
}
}
STATIC
in
t
get_label_dest
(
asm_thumb_t
*
as
,
uint
label
)
{
STATIC
mp_uint_
t
get_label_dest
(
asm_thumb_t
*
as
,
uint
label
)
{
assert
(
label
<
as
->
max_num_labels
);
return
as
->
label_offsets
[
label
];
}
...
...
@@ -348,15 +346,11 @@ void asm_thumb_movt_reg_i16(asm_thumb_t *as, uint reg_dest, int i16_src) {
asm_thumb_mov_reg_i16
(
as
,
OP_MOVT
,
reg_dest
,
i16_src
);
}
void
asm_thumb_ite_ge
(
asm_thumb_t
*
as
)
{
asm_thumb_op16
(
as
,
0xbfac
);
}
#define OP_B_N(byte_offset) (0xe000 | (((byte_offset) >> 1) & 0x07ff))
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
uint
label
)
{
in
t
dest
=
get_label_dest
(
as
,
label
);
in
t
rel
=
dest
-
as
->
code_offset
;
mp_uint_
t
dest
=
get_label_dest
(
as
,
label
);
mp_int_
t
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_op16
(
as
,
OP_B_N
(
rel
));
...
...
@@ -368,8 +362,8 @@ void asm_thumb_b_n(asm_thumb_t *as, uint label) {
#define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff))
void
asm_thumb_bcc_n
(
asm_thumb_t
*
as
,
int
cond
,
uint
label
)
{
in
t
dest
=
get_label_dest
(
as
,
label
);
in
t
rel
=
dest
-
as
->
code_offset
;
mp_uint_
t
dest
=
get_label_dest
(
as
,
label
);
mp_int_
t
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
if
(
SIGNED_FIT9
(
rel
))
{
asm_thumb_op16
(
as
,
OP_BCC_N
(
cond
,
rel
));
...
...
@@ -442,8 +436,8 @@ void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num)
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
uint
label
)
{
in
t
dest
=
get_label_dest
(
as
,
label
);
in
t
rel
=
dest
-
as
->
code_offset
;
mp_uint_
t
dest
=
get_label_dest
(
as
,
label
);
mp_int_
t
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
if
(
dest
>=
0
&&
rel
<=
-
4
)
{
// is a backwards jump, so we know the size of the jump on the first pass
...
...
@@ -465,8 +459,8 @@ void asm_thumb_b_label(asm_thumb_t *as, uint label) {
#define OP_BCC_W_LO(byte_offset) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff))
void
asm_thumb_bcc_label
(
asm_thumb_t
*
as
,
int
cond
,
uint
label
)
{
in
t
dest
=
get_label_dest
(
as
,
label
);
in
t
rel
=
dest
-
as
->
code_offset
;
mp_uint_
t
dest
=
get_label_dest
(
as
,
label
);
mp_int_
t
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
if
(
dest
>=
0
&&
rel
<=
-
4
)
{
// is a backwards jump, so we know the size of the jump on the first pass
...
...
py/asmthumb.h
View file @
851f15f3
...
...
@@ -80,6 +80,14 @@ void asm_thumb_data(asm_thumb_t* as, uint bytesize, uint val);
// argument order follows ARM, in general dest is first
// note there is a difference between movw and mov.w, and many others!
#define ASM_THUMB_OP_ITE_EQ (0xbf0c)
#define ASM_THUMB_OP_ITE_CS (0xbf2c)
#define ASM_THUMB_OP_ITE_MI (0xbf4c)
#define ASM_THUMB_OP_ITE_VS (0xbf6c)
#define ASM_THUMB_OP_ITE_HI (0xbf8c)
#define ASM_THUMB_OP_ITE_GE (0xbfac)
#define ASM_THUMB_OP_ITE_GT (0xbfcc)
#define ASM_THUMB_OP_NOP (0xbf00)
#define ASM_THUMB_OP_WFI (0xbf30)
#define ASM_THUMB_OP_CPSID_I (0xb672) // cpsid i, disable irq
...
...
@@ -165,17 +173,20 @@ static inline void asm_thumb_str_rlo_rlo_i5(asm_thumb_t *as, uint rlo_src, uint
{
asm_thumb_format_9_10
(
as
,
ASM_THUMB_FORMAT_9_STR
|
ASM_THUMB_FORMAT_9_WORD_TRANSFER
,
rlo_src
,
rlo_base
,
word_offset
);
}
static
inline
void
asm_thumb_strb_rlo_rlo_i5
(
asm_thumb_t
*
as
,
uint
rlo_src
,
uint
rlo_base
,
uint
byte_offset
)
{
asm_thumb_format_9_10
(
as
,
ASM_THUMB_FORMAT_9_STR
|
ASM_THUMB_FORMAT_9_BYTE_TRANSFER
,
rlo_src
,
rlo_base
,
byte_offset
);
}
static
inline
void
asm_thumb_strh_rlo_rlo_i5
(
asm_thumb_t
*
as
,
uint
rlo_src
,
uint
rlo_base
,
uint
byte_offset
)
{
asm_thumb_format_9_10
(
as
,
ASM_THUMB_FORMAT_10_STRH
,
rlo_src
,
rlo_base
,
byte_offset
);
}
static
inline
void
asm_thumb_ldr_rlo_rlo_i5
(
asm_thumb_t
*
as
,
uint
rlo_dest
,
uint
rlo_base
,
uint
word_offset
)
{
asm_thumb_format_9_10
(
as
,
ASM_THUMB_FORMAT_9_LDR
|
ASM_THUMB_FORMAT_9_WORD_TRANSFER
,
rlo_dest
,
rlo_base
,
word_offset
);
}
static
inline
void
asm_thumb_ldrb_rlo_rlo_i5
(
asm_thumb_t
*
as
,
uint
rlo_dest
,
uint
rlo_base
,
uint
byte_offset
)
{
asm_thumb_format_9_10
(
as
,
ASM_THUMB_FORMAT_9_LDR
|
ASM_THUMB_FORMAT_9_BYTE_TRANSFER
,
rlo_dest
,
rlo_base
,
byte_offset
);
}
static
inline
void
asm_thumb_ldrh_rlo_rlo_i5
(
asm_thumb_t
*
as
,
uint
rlo_dest
,
uint
rlo_base
,
uint
byte_offset
)
{
asm_thumb_format_9_10
(
as
,
ASM_THUMB_FORMAT_10_LDRH
,
rlo_dest
,
rlo_base
,
byte_offset
);
}
// TODO convert these to above format style
void
asm_thumb_mov_reg_reg
(
asm_thumb_t
*
as
,
uint
reg_dest
,
uint
reg_src
);
void
asm_thumb_movw_reg_i16
(
asm_thumb_t
*
as
,
uint
reg_dest
,
int
i16_src
);
void
asm_thumb_movt_reg_i16
(
asm_thumb_t
*
as
,
uint
reg_dest
,
int
i16_src
);
void
asm_thumb_ite_ge
(
asm_thumb_t
*
as
);
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
uint
label
);
void
asm_thumb_bcc_n
(
asm_thumb_t
*
as
,
int
cond
,
uint
label
);
...
...
@@ -189,4 +200,3 @@ void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num)
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
uint
label
);
// convenience ?
void
asm_thumb_bcc_label
(
asm_thumb_t
*
as
,
int
cc
,
uint
label
);
// convenience: picks narrow or wide branch
void
asm_thumb_bl_ind
(
asm_thumb_t
*
as
,
void
*
fun_ptr
,
uint
fun_id
,
uint
reg_temp
);
// convenience ?
py/emitinlinethumb.c
View file @
851f15f3
...
...
@@ -274,7 +274,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
}
else
if
(
strcmp
(
op_str
,
"wfi"
)
==
0
)
{
asm_thumb_op16
(
emit
->
as
,
ASM_THUMB_OP_WFI
);
}
else
if
(
strcmp
(
op_str
,
"ite.ge"
)
==
0
)
{
// TODO correct name for this op?
asm_thumb_
ite_ge
(
emit
->
as
);
asm_thumb_
op16
(
emit
->
as
,
ASM_THUMB_OP_ITE_GE
);
}
else
{
goto
unknown_op
;
}
...
...
py/emitnative.c
View file @
851f15f3
...
...
@@ -1537,7 +1537,7 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
asm_x86_setcc_r8
(
emit
->
as
,
ASM_X86_CC_JL
,
REG_RET
);
#elif N_THUMB
asm_thumb_cmp_rlo_rlo
(
emit
->
as
,
REG_ARG_2
,
REG_ARG_3
);
asm_thumb_
ite_ge
(
emit
->
as
);
asm_thumb_
op16
(
emit
->
as
,
ASM_THUMB_OP_ITE_GE
);
asm_thumb_mov_rlo_i8
(
emit
->
as
,
REG_RET
,
0
);
// if r0 >= r1
asm_thumb_mov_rlo_i8
(
emit
->
as
,
REG_RET
,
1
);
// if r0 < r1
#elif N_ARM
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment