AUTHORS, util/: Drop individual copyright notices
[coreboot.git] / util / post / post.c
blobef769161b194c9decf2bf7de773865e152a38638
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #include <errno.h>
14 #include <limits.h>
15 #include <stdarg.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <sys/io.h>
20 #define POST_DEFAULT_IO_PORT 0x80
22 void usage(char *progname, const char *error, ...)
24 printf("Usage: %s <VALUE> [PORT]\n", progname);
25 printf("The VALUE argument is an integer between 0x00 and 0xff\n");
26 printf("The PORT argument is an integer between 0x00 and 0xffff\n");
28 if (error) {
29 va_list args;
31 va_start(args, error);
32 vprintf(error, args);
33 va_end(args);
37 void check_int(long val, int min, int max, int err, char *string, char *endptr,
38 char *progname)
40 if (val < min || val > max) {
41 usage(progname,
42 "\nError: The value has to be between 0x%x and 0x%x\n",
43 min, max);
44 exit(EXIT_FAILURE);
47 if (endptr == string || *endptr != '\0') {
48 usage(progname, "\nError: An integer is required\n");
49 exit(EXIT_FAILURE);
52 if ((err) && (!val)) {
53 perror("strtol");
54 exit(EXIT_FAILURE);
58 int main(int argc, char *argv[])
60 unsigned long val;
61 unsigned long port = POST_DEFAULT_IO_PORT;
62 char *endptr;
63 int err;
65 if (argc != 2 && argc != 3) {
66 usage(argv[0], NULL);
67 exit(EXIT_FAILURE);
70 val = strtol(argv[1], &endptr, 0);
71 err = errno;
72 check_int(val, 0x00, 0xff, err, argv[1], endptr, argv[0]);
74 if (argc > 2) {
75 port = strtol(argv[2], &endptr, 0);
76 err = errno;
77 check_int(port, 0x0000, 0xffff, err, argv[2], endptr, argv[0]);
80 err = iopl(3);
81 if (err == -1) {
82 perror("Not root");
83 exit(EXIT_FAILURE);
86 outb(val, port);
88 return 0;