Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. void hilevel_handler_rst( ctx_t* ctx ) {
  2. /* Initialise PCBs representing processes stemming from execution of
  3. * the two user programs. Note in each case that
  4. *
  5. * - the CPSR value of 0x50 means the processor is switched into USR
  6. * mode, with IRQ interrupts enabled, and
  7. * - the PC and SP values matche the entry point and top of stack.
  8. */
  9. TIMER0->Timer1Load = 0x00100000; // select period = 2^20 ticks ~= 1 sec
  10. TIMER0->Timer1Ctrl = 0x00000002; // select 32-bit timer
  11. TIMER0->Timer1Ctrl |= 0x00000040; // select periodic timer
  12. TIMER0->Timer1Ctrl |= 0x00000020; // enable timer interrupt
  13. TIMER0->Timer1Ctrl |= 0x00000080; // enable timer
  14.  
  15. GICC0->PMR = 0x000000F0; // unmask all interrupts
  16. GICD0->ISENABLER1 |= 0x00000010; // enable timer interrupt
  17. GICC0->CTLR = 0x00000001; // enable GIC interface
  18. GICD0->CTLR = 0x00000001; // enable GIC distributor
  19.  
  20. int_enable_irq();
  21.  
  22. memset( &pcb[ 0 ], 0, sizeof( pcb_t ) );
  23. pcb[ 0 ].pid = 1;
  24. pcb[ 0 ].ctx.cpsr = 0x50;
  25. pcb[ 0 ].ctx.pc = ( uint32_t )( &main_P1 );
  26. pcb[ 0 ].ctx.sp = ( uint32_t )( &tos_P1 );
  27.  
  28. memset( &pcb[ 1 ], 0, sizeof( pcb_t ) );
  29. pcb[ 1 ].pid = 2;
  30. pcb[ 1 ].ctx.cpsr = 0x50;
  31. pcb[ 1 ].ctx.pc = ( uint32_t )( &main_P2 );
  32. pcb[ 1 ].ctx.sp = ( uint32_t )( &tos_P2 );
  33.  
  34. /* Once the PCBs are initialised, we (arbitrarily) select one to be
  35. * restored (i.e., executed) when the function then returns.
  36. */
  37.  
  38. current = &pcb[ 0 ]; memcpy( ctx, &current->ctx, sizeof( ctx_t ) );
  39.  
  40. return;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement