16842bc34SLaurent Vivier /* 26842bc34SLaurent Vivier * processor control and status function 3*b1a6fd7dSThomas Huth * 4*b1a6fd7dSThomas Huth * This code is free software; you can redistribute it and/or modify it 5*b1a6fd7dSThomas Huth * under the terms of the GNU Library General Public License version 2. 66842bc34SLaurent Vivier */ 76842bc34SLaurent Vivier 86842bc34SLaurent Vivier #include <libcflat.h> 96842bc34SLaurent Vivier #include <asm/processor.h> 106842bc34SLaurent Vivier #include <asm/ptrace.h> 11f4d8d939SSuraj Jitindar Singh #include <asm/setup.h> 12f4d8d939SSuraj Jitindar Singh #include <asm/barrier.h> 136842bc34SLaurent Vivier 146842bc34SLaurent Vivier static struct { 156842bc34SLaurent Vivier void (*func)(struct pt_regs *, void *data); 166842bc34SLaurent Vivier void *data; 176842bc34SLaurent Vivier } handlers[16]; 186842bc34SLaurent Vivier 196842bc34SLaurent Vivier void handle_exception(int trap, void (*func)(struct pt_regs *, void *), 206842bc34SLaurent Vivier void * data) 216842bc34SLaurent Vivier { 226842bc34SLaurent Vivier trap >>= 8; 236842bc34SLaurent Vivier 246842bc34SLaurent Vivier if (trap < 16) { 256842bc34SLaurent Vivier handlers[trap].func = func; 266842bc34SLaurent Vivier handlers[trap].data = data; 276842bc34SLaurent Vivier } 286842bc34SLaurent Vivier } 296842bc34SLaurent Vivier 306842bc34SLaurent Vivier void do_handle_exception(struct pt_regs *regs) 316842bc34SLaurent Vivier { 326842bc34SLaurent Vivier unsigned char v; 336842bc34SLaurent Vivier 346842bc34SLaurent Vivier v = regs->trap >> 8; 356842bc34SLaurent Vivier 366842bc34SLaurent Vivier if (v < 16 && handlers[v].func) { 376842bc34SLaurent Vivier handlers[v].func(regs, handlers[v].data); 386842bc34SLaurent Vivier return; 396842bc34SLaurent Vivier } 406842bc34SLaurent Vivier 416842bc34SLaurent Vivier printf("unhandled cpu exception 0x%lx\n", regs->trap); 426842bc34SLaurent Vivier abort(); 436842bc34SLaurent Vivier } 44f4d8d939SSuraj Jitindar Singh 45f4d8d939SSuraj Jitindar Singh void delay(uint64_t cycles) 46f4d8d939SSuraj Jitindar Singh { 47f4d8d939SSuraj Jitindar Singh uint64_t start = get_tb(); 48f4d8d939SSuraj Jitindar Singh 49f4d8d939SSuraj Jitindar Singh while ((get_tb() - start) < cycles) 50f4d8d939SSuraj Jitindar Singh cpu_relax(); 51f4d8d939SSuraj Jitindar Singh } 52f4d8d939SSuraj Jitindar Singh 53f4d8d939SSuraj Jitindar Singh void udelay(uint64_t us) 54f4d8d939SSuraj Jitindar Singh { 55f4d8d939SSuraj Jitindar Singh delay((us * tb_hz) / 1000000); 56f4d8d939SSuraj Jitindar Singh } 57