Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.74 KB | None | 0 0
  1. interrupt_vector_table:
  2.   // ARM core does the following on interrupt:
  3.   // 1) save cpsr into spsr
  4.   // 2) set mode bits in current cpsr
  5.   // 3) disable further interrupts of lower/same priority
  6.   // 4) store return address in lr
  7.   // 5) set pc to correct vector table entry below
  8.   ldr pc, _reset_asm_handler                 // priority: 1st
  9.   ldr pc, _undefined_instruction_asm_handler // priority: 6th
  10.   ldr pc, _swi_asm_handler                   // priority: 6th
  11.   ldr pc, _prefetch_abort_asm_handler        // priority: 5th
  12.   ldr pc, _data_abort_asm_handler            // priority: 2nd
  13.   ldr pc, _reset_asm_handler                 // priority: undefined
  14.   ldr pc, _irq_asm_handler                   // priority: 4th
  15.   ldr pc, _fiq_asm_handler                   // priority: 3rd
  16.  
  17. /**
  18.  * SOFT vector table that is loaded by install_vector_table ABOVE
  19.  * interrupt_vector_table
  20.  */
  21. // to make sure the addresses are aligned this must follow the
  22. // actual vector table above!
  23. _reset_asm_handler:                 .word reset_asm_handler
  24. _undefined_instruction_asm_handler: .word undefined_instruction_asm_handler
  25. _swi_asm_handler:                   .word swi_asm_handler
  26. _prefetch_abort_asm_handler:        .word prefetch_abort_asm_handler
  27. _data_abort_asm_handler:            .word data_abort_asm_handler
  28. _irq_asm_handler:                   .word irq_asm_handler
  29. _fiq_asm_handler:                   .word fiq_asm_handler
  30.  
  31.  
  32. /**
  33.  * called to install the vector table at address 0x0
  34.  */
  35. .global install_interrupt_table
  36. install_interrupt_table:
  37.   copy the vector table into multiple registers
  38.   copy the values of the vector table into the actual memory location
  39.   do the same for soft vector table
  40.   move lr into pc
  41.  
  42. irq_asm_handler:
  43.   push shit
  44.   bl irq_c_handler
  45.   pop shit
  46.   cpsr/spsr somewhere inbetween
  47.  
  48.  
  49.   //Everything restored
  50.   movs pc, lr       @ returns and sets flag like that thing you showed me
  51.  
  52.  
  53.  
  54. reset_asm_handler:
  55.   b _start // just reset the kernel
  56.  
  57.  
  58. /************************************************************
  59.  * If you fall into one of these handlers something bad is
  60.  * happening. bkpt will drop back into gdb so you can debug.
  61.  ************************************************************/
  62. undefined_instruction_asm_handler:
  63.   bkpt
  64.  
  65. prefetch_abort_asm_handler:
  66.   bkpt
  67.  
  68. data_abort_asm_handler:
  69.   bkpt
  70.  
  71. fiq_asm_handler:
  72.   bkpt
  73.  
  74.  
  75. /************************************************************/
  76. /* Initializes cpsr for user mode and jumps to user program */
  77. /************************************************************/
  78. .global enter_user_mode
  79. enter_user_mode:
  80.   push {r0-r12}
  81.   mrs r0, cpsr
  82.   and r0, #0xffffff00
  83.   add r0, #0xD0
  84.   msr cpsr, r0
  85.   ldr sp, =__user_stack_top
  86.   bl __user_program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement