1 /* 2 * Interrupt handling. 3 * 4 * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "board-defs.h" 21 22 #include "init.h" 23 #include "board.h" 24 #include "lcd.h" 25 #include "jzlcd.h" 26 #include "cpu.h" 27 #include "paging.h" 28 #include "irq.h" 29 30 extern vidinfo_t panel_info; 31 32 void next_pixel(unsigned short *x, unsigned short *y) 33 { 34 (*x)++; 35 if (*x >= panel_info.vl_col) { 36 *x = 0; 37 (*y)++; 38 if (*y >= panel_info.vl_row) 39 *y = 0; 40 } 41 } 42 43 /* Task management. */ 44 45 enum { max_tasks = 3 }; 46 static u32 stack_pointers[max_tasks]; 47 static u32 registers[max_tasks][32]; 48 49 u8 current_task; 50 u32 *current_stack_pointer; 51 u32 *current_registers; 52 53 extern u32 _got_copy_start; 54 55 const u32 stack_start = 0x00080000; 56 const u32 stack_size = 0x00002000; 57 const u32 pagesize = 4 * 1024; 58 59 /* Tasks. */ 60 61 void plot_pattern(unsigned short pixel_type, unsigned short x, unsigned short y) 62 { 63 while (1) { 64 if (pixel_type) 65 test_pixel(x, y, pixel_type); 66 else 67 clear_pixel(x, y); 68 next_pixel(&x, &y); 69 udelay(100); 70 } 71 } 72 73 /* Initialisation and handling. */ 74 75 void irq_init() 76 { 77 handle_error_level(); 78 timer_init_irq(); 79 init_interrupts(); 80 } 81 82 void irq_handle() 83 { 84 unsigned short i; 85 86 /* Check interrupt identity. */ 87 88 if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { 89 90 /* Switch task. */ 91 92 switch_task(); 93 94 /* Clear interrupt status. */ 95 96 timer_clear(); 97 98 /* Handle other interrupts, anyway. */ 99 100 } else { 101 for (i = 0; i < 32; i++) { 102 if (REG_INTC_IPR & (1 << i)) 103 __intc_ack_irq(i); 104 } 105 } 106 } 107 108 void init_tasks() 109 { 110 current_task = 0; 111 current_stack_pointer = &stack_pointers[current_task]; 112 current_registers = registers[current_task]; 113 } 114 115 void start_task(unsigned short task) 116 { 117 u32 args[] = {task, 0, (task - 1) * 60}; 118 u32 virtual, physical; 119 120 /* 121 Each task employs a stack at a multiple of the given start address in 122 physical memory, but at the same address in virtual memory. 123 */ 124 125 virtual = stack_start; 126 physical = stack_start - stack_size * task; 127 128 init_page_table(page_table_start, virtual - pagesize * 2, physical - pagesize * 2, pagesize, 0x1e, task); 129 130 stack_pointers[task] = virtual - 12; 131 132 /* 133 Set the registers for the new task, initialising the global pointer and 134 return address. 135 */ 136 137 init_registers(registers[task], _got_copy_start, (void (*)()) plot_pattern, args, 3); 138 } 139 140 void switch_task() 141 { 142 /* Switch the current task. */ 143 144 current_task++; 145 if (current_task == max_tasks) current_task = 0; 146 147 /* Indicate the current stack pointer and task registers. */ 148 149 current_stack_pointer = &stack_pointers[current_task]; 150 current_registers = registers[current_task]; 151 }