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