-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linker support to securely inline arithmetic functions.
Transparently intercept relocatable arithmetic library calls inserted by the compiler back-end, so as to redirect them to a custom code stub inserted in the SM's text section. This addresses issue #6.
- Loading branch information
1 parent
fd9f839
commit 3e00e24
Showing
7 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.section ".sm.text" | ||
.align 2 | ||
.global __sm_divhi3 | ||
.type __sm_divhi3,@function | ||
|
||
__sm_divhi3: | ||
clr r13 | ||
tst r15 | ||
jge 1f | ||
mov #3, r13 | ||
inv r15 | ||
inc r15 | ||
1: tst r14 | ||
jge 2f | ||
xor.b #1, r13 | ||
inv r14 | ||
inc r14 | ||
2: push r13 | ||
call #__sm_udivhi3 | ||
pop r13 | ||
bit.b #2, r13 | ||
jz 3f | ||
inv r14 | ||
inc r14 | ||
3: bit.b #1, r13 | ||
jz 4f | ||
inv r15 | ||
inc r15 | ||
4: ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.section ".sm.text" | ||
.align 2 | ||
.global __sm_modhi3 | ||
.type __sm_modhi3,@function | ||
|
||
__sm_modhi3: | ||
call #__sm_divhi3 | ||
mov r14, r15 | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.section ".sm.text" | ||
.align 2 | ||
.global __sm_mulhi3 | ||
.type __sm_mulhi3,@function | ||
|
||
; \arg r14: a | ||
; \arg r15: b | ||
; \ret r15: a*b | ||
; \note: clobbers r13 | ||
__sm_mulhi3: | ||
mov r15, r13 | ||
clr r15 | ||
1: tst r14 | ||
jz 3f | ||
clrc | ||
rrc r13 | ||
jnc 2f | ||
add r14, r15 | ||
2: rla r14 | ||
tst r13 | ||
jnz 1b | ||
3: ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.section ".sm.text" | ||
.align 2 | ||
.global __sm_udivhi3 | ||
.type __sm_udivhi3,@function | ||
|
||
__sm_udivhi3: | ||
mov.b #16, r12 | ||
mov r14, r13 | ||
clr r14 | ||
1: rla r15 | ||
rlc r14 | ||
cmp r13, r14 | ||
jnc 2f | ||
sub r13, r14 | ||
bis #1, r15 | ||
2: dec r12 | ||
jnz 1b | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.section ".sm.text" | ||
.align 2 | ||
.global __sm_umodhi3 | ||
.type __sm_umodhi3,@function | ||
|
||
__sm_umodhi3: | ||
call #__sm_udivhi3 | ||
mov r14, r15 | ||
ret |