Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. push {r0, r1} // Free up some registers for us to use
  2. ldr r0, =current_thread
  3. ldr r0, [r0] // turn the symbol current_thread into its value (a pointer to struct Thread)
  4. ldr r0, [r0] // take the first word in the struct- a pointer to struct ThreadState. 196 bytes long, exactly: uint32_t core_registers[16]; uint32_t cpsr; uint64_t ext_registers[16];
  5. pop {r1} // note that the program's r0 is now in r1
  6. stmia r0, {r1}^ // Store only r0
  7. pop {r1}
  8. add r0, r0, #4 // no writeback on stm for user registers
  9. stmia r0, {r1-r14}^ // Store r1-r14
  10. add r0, r0, #56 // again, no writeback. 14 4-byte registers = 56 bytes. r0 is currently offset 60 bytes.
  11. stmia r0!, {lr} // store our lr- which is the interrupted thread's pc (plus an offset, but ignore that for now). r0 is now offset 64 bytes, past ThreadState->core_registers
  12. mrs r1, spsr
  13. str r1, [r0, #4]! // Hooray, writeback. r0 is now offset 68 bytes, past ThreadState->cpsr
  14. vstmia r0!, {q0-q15} // more writeback. r0 is now offset 128 (16 8-byte registers) more bytes, past ThreadState->ext_registers, for a grand total of 196 bytes!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement