Skip to content

Commit

Permalink
rust morestack assembly for arm
Browse files Browse the repository at this point in the history
Conflicts:
	src/rt/arch/arm/morestack.S
  • Loading branch information
ILyoan authored and brson committed Apr 11, 2013
1 parent 4b4f482 commit 3d0d144
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 42 deletions.
55 changes: 54 additions & 1 deletion src/rt/arch/arm/morestack.S
Expand Up @@ -8,6 +8,59 @@
.arm
.align

.globl __morestack
.global upcall_new_stack
.global upcall_del_stack
.global __morestack
.hidden __morestack

// r4 and r5 are scratch registers for __morestack due to llvm
// ARMFrameLowering::adjustForSegmentedStacks() implementation.
.align 2
.type __morestack,%function
__morestack:

// Save frame pointer and return address
push {fp, lr}

mov fp, sp

// Save argument registers of the original function
push {r0, r1, r2, r3, lr}

mov r0, r4 // The amount of stack needed
add r1, fp, #20 // Address of stack arguments
mov r2, r5 // Size of stack arguments

// Create new stack
bl upcall_new_stack@plt

// Hold new stack pointer
mov r5, r0

// Pop the saved arguments
pop {r0, r1, r2, r3, lr}

// Grab the return pointer
add r4, lr, #16 // Skip past the return
mov sp, r5 // Swich to the new stack
mov lr, pc
mov pc, r4 // Call the original function

// Switch back to rust stack
mov sp, fp

// Save return value
push {r0, r1}

// Remove the new allocated stack
bl upcall_del_stack@plt

// Restore return value
pop {r0, r1}

// Return
pop {fp, lr}
mov pc, lr
.endofmorestack:
.size __morestack, .endofmorestack-__morestack

47 changes: 6 additions & 41 deletions src/rt/arch/arm/record_sp.S
Expand Up @@ -14,53 +14,18 @@
.globl get_sp

record_sp_limit:
mov r3, r0
ldr r0, =my_cpu
mov r1, #0
mov r2, #0
stmfd sp!, {r3, r7}
ldr r7, =345
swi #0
ldmfd sp!, {r3, r7}
movs r0, r0
movmi r0, #0

ldr r1, =my_array
str r3, [r1, r0]
mrc p15, #0, r3, c13, c0, #3
add r3, r3, #252
str r0, [r3]
mov pc, lr


get_sp_limit:
ldr r0, =my_cpu
mov r1, #0
mov r2, #0
stmfd sp!, {r4, r7}
ldr r7, =345
swi #0
ldmfd sp!, {r4, r7}
movs r0, r0
movmi r0, #0
mov r3, r0

ldr r1, =my_array
ldr r0, [r1, r3]
mrc p15, #0, r3, c13, c0, #3
add r3, r3, #252
ldr r0, [r3]
mov pc, lr


get_sp:
mov r0, sp
mov pc, lr

.data
my_cpu: .long 0
.global my_array
my_array:
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.end

0 comments on commit 3d0d144

Please sign in to comment.