From 46d65e85a1c0449f86497264d5958b3d85784767 Mon Sep 17 00:00:00 2001 From: Jeremy Jackson Date: Wed, 11 Apr 2007 18:44:42 +0000 Subject: Jeremy Jackson wrote: I'm guessing nobody has tried compiling it with 64bit userspace? Patch makes it compile cleanly and stops a "SEGV instead of working" issue. I also added a few checks for errors on system calls. Signed-off-by: Jeremy Jackson Reworked and Acked-by: Stefan Reinauer git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2602 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- util/getpir/getpir.c | 59 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 16 deletions(-) (limited to 'util/getpir/getpir.c') diff --git a/util/getpir/getpir.c b/util/getpir/getpir.c index 7f08af6f6a..12b4a20f22 100644 --- a/util/getpir/getpir.c +++ b/util/getpir/getpir.c @@ -1,14 +1,28 @@ /* getpir.c : This software is released under GPL - For Linuxbios use only - Aug 26 2001 , Nikolai Vladychevski, -*/ + * For LinuxBIOS use only + * Aug 26 2001 , Nikolai Vladychevski, + * 2007.04.09 Jeremy Jackson + * updated for amd64 and general 64 bit portability + */ #include +#include +#include +#include +#include #include +#include +#include -#include +#include "pirq_routing.h" +#include "checksum.h" +#include "code_gen.h" -#define O_RDONLY 0x00 +#if defined (__sun) && (defined(__i386) || defined(__amd64)) +# define MEM_DEV "/dev/xsvc" +#else +# define MEM_DEV "/dev/mem" +#endif static struct irq_routing_table *probe_table(int fd_mem) { @@ -18,40 +32,53 @@ static struct irq_routing_table *probe_table(int fd_mem) ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED, fd_mem, (off_t) 0xf0000); + if (ptr == MAP_FAILED) { + perror("Mapping system memory failed: "); + exit(1); + } + rt = (struct irq_routing_table *) memmem(ptr, 0xFFFF, signature, 4); if (rt != NULL) { - printf("Found PCI IRQ Routing table signature at 0x%04x of system memory\n", - (char *) rt - ptr + 0xf0000); + printf("Found PCI IRQ routing table signature at %p.\n", + (void *)((char *)rt - ptr + 0xf0000)); } else { - printf("No PCI IRQ Routing table signature in the memory\n"); + printf("No PCI IRQ routing table signature found.\n"); exit(1); } return rt; } -main() +int main(void) { int fd_mem; struct irq_routing_table *rt; if (getuid()) { - perror("Run me as root, I need access to /dev/mem"); + fprintf(stderr, "Run me as root, I need access to " MEM_DEV ".\n"); + } + + fd_mem = open(MEM_DEV, O_RDONLY); + if (fd_mem < 0) { + perror("Could not open " MEM_DEV ":"); exit(1); } - fd_mem = open("/dev/mem", O_RDONLY); - printf("Probing PIRQ table in memory\n"); + printf("Probing PIRQ table in memory.\n"); rt = probe_table(fd_mem); - printf("Validating..\n"); + printf("Validating... "); if (!calc_checksum(rt)) - printf("Checksum is ok!\n"); + printf("checksum is ok.\n"); + else + printf("checksum is wrong.\n"); - printf("Creating irq_tables.c .....\n"); + printf("Creating irq_tables.c ...\n"); code_gen("irq_tables.c", rt); close(fd_mem); - printf("Done, you can move the file to the LinuxBios tree now.\n"); + printf("Done, you can move the file to the LinuxBIOS tree now.\n"); + + return 0; } -- cgit v1.2.3