From 205c8d0a35e015214b84a0974caf4adaf4f88b4d Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 23:46:44 +0200 Subject: [PATCH 1/3] Run through clang-format. --- util/cmisc/tabgen.c | 364 ++++++++++++++++++++++++-------------------- 1 file changed, 199 insertions(+), 165 deletions(-) diff --git a/util/cmisc/tabgen.c b/util/cmisc/tabgen.c index c88794f4f..ba66931fa 100644 --- a/util/cmisc/tabgen.c +++ b/util/cmisc/tabgen.c @@ -15,44 +15,47 @@ #include #ifndef NORCSID -static char *RcsId = "$Id$"; +static char* RcsId = "$Id$"; #endif -#define MAXBUF 256 +#define MAXBUF 256 #define MAXTAB 10000 -#define COMCOM '-' -#define FILECOM '%' +#define COMCOM '-' +#define FILECOM '%' -int InputForm = 'c'; /* default input format (and, currently, only one) */ +int InputForm = 'c'; /* default input format (and, currently, only one) */ char OutputForm[MAXBUF] = "%s,\n"; - /* format for spitting out a string */ -char *Table[MAXTAB]; -char *ProgCall; /* callname of this program */ -int TabSize = 128; /* default size of generated table */ -char *InitialValue; /* initial value of all table entries */ +/* format for spitting out a string */ +char* Table[MAXTAB]; +char* ProgCall; /* callname of this program */ +int TabSize = 128; /* default size of generated table */ +char* InitialValue; /* initial value of all table entries */ -void option(char *); -void option_F(char *); -void InitTable(char *); +void option(char*); +void option_F(char*); +void InitTable(char*); void PrintTable(void); -int process(char *, int); -int c_proc(char *, char *); -int setval(int, char *); -int quoted(char **); -void DoFile(char *); +int process(char*, int); +int c_proc(char*, char*); +int setval(int, char*); +int quoted(char**); +void DoFile(char*); -int -main(int argc, char *argv[]) +int main(int argc, char* argv[]) { ProgCall = *argv++; argc--; - while (argc-- > 0) { - if (**argv == COMCOM) { + while (argc-- > 0) + { + if (**argv == COMCOM) + { option(*argv++); } - else { - if (! process(*argv++, InputForm)) { + else + { + if (!process(*argv++, InputForm)) + { exit(1); } } @@ -61,81 +64,85 @@ main(int argc, char *argv[]) /*NOTREACHED*/ } -char * -Salloc(char *s) +char* Salloc(char* s) { - char *ns = strdup(s); + char* ns = strdup(s); - if (!ns) { + if (!ns) + { fprintf(stderr, "%s: out of memory\n", ProgCall); exit(1); } return ns; } -void -option(char *str) +void option(char* str) { /* note that *str indicates the source of the option: either COMCOM (from command line) or FILECOM (from a file). */ - switch (*++str) { - - case ' ': /* command */ - case '\t': - case '\0': - break; - case 'I': /* for future extension */ - InputForm = *++str; - break; - case 'f': /* input from file ... */ - if (*++str == '\0') { - fprintf(stderr, "%s: -f: name expected\n", ProgCall); - exit(1); - } - DoFile(str); - break; - case 'F': /* new output format string */ - option_F(++str); - break; - case 'T': /* insert text literally */ - printf("%s\n", ++str); - break; - case 'p': /* print table */ - PrintTable(); - break; - case 'C': /* clear table */ - InitTable((char *)0); - break; - case 'i': /* initialize table with given value */ - if (*++str == '\0') { - InitTable((char *)0); - } - else InitTable(str); - break; - case 'S': + switch (*++str) { - int i = atoi(++str); - if (i <= 0 || i > MAXTAB) { - fprintf(stderr, "%s: size would exceed maximum\n", - ProgCall); + case ' ': /* command */ + case '\t': + case '\0': + break; + case 'I': /* for future extension */ + InputForm = *++str; + break; + case 'f': /* input from file ... */ + if (*++str == '\0') + { + fprintf(stderr, "%s: -f: name expected\n", ProgCall); + exit(1); + } + DoFile(str); + break; + case 'F': /* new output format string */ + option_F(++str); + break; + case 'T': /* insert text literally */ + printf("%s\n", ++str); + break; + case 'p': /* print table */ + PrintTable(); + break; + case 'C': /* clear table */ + InitTable((char*)0); + break; + case 'i': /* initialize table with given value */ + if (*++str == '\0') + { + InitTable((char*)0); + } + else + InitTable(str); + break; + case 'S': + { + int i = atoi(++str); + + if (i <= 0 || i > MAXTAB) + { + fprintf(stderr, "%s: size would exceed maximum\n", + ProgCall); + } + else + { + TabSize = i; + } + break; } - else { - TabSize = i; - } - break; - } - default: - fprintf(stderr, "%s: bad option -%s\n", ProgCall, str); + default: + fprintf(stderr, "%s: bad option -%s\n", ProgCall, str); } } -void -option_F(char *form) +void option_F(char* form) { int len; - char *cp; + char* cp; /* * The format string must have one '%s' and no other '%'. @@ -154,180 +161,203 @@ bad: exit(1); } -void -InitTable(char *ival) +void InitTable(char* ival) { int i; - for (i = 0; i < TabSize; i++) { + for (i = 0; i < TabSize; i++) + { Table[i] = 0; } InitialValue = 0; - if (ival) { + if (ival) + { InitialValue = Salloc(ival); } } -void -PrintTable(void) +void PrintTable(void) { int i; - for (i = 0; i < TabSize; i++) { - if (Table[i]) { + for (i = 0; i < TabSize; i++) + { + if (Table[i]) + { printf(OutputForm, Table[i]); } - else if (InitialValue) { + else if (InitialValue) + { printf(OutputForm, InitialValue); } - else { + else + { printf(OutputForm, "0"); } } } -int -process(char *str, int format) +int process(char* str, int format) { - char *cstr = str; - char *Name = cstr; /* overwrite original string! */ + char* cstr = str; + char* Name = cstr; /* overwrite original string! */ /* strip of the entry name */ - while (*str && *str != ':') { - if (*str == '\\') { + while (*str && *str != ':') + { + if (*str == '\\') + { ++str; } *cstr++ = *str++; } - if (*str != ':') { + if (*str != ':') + { fprintf(stderr, "%s: bad specification: \"%s\", ignored\n", - ProgCall, Name); + ProgCall, Name); return 0; } *cstr = '\0'; str++; - switch (format) { + switch (format) + { - case 'c': - return c_proc(str, Name); - default: - fprintf(stderr, "%s: bad input format\n", ProgCall); + case 'c': + return c_proc(str, Name); + default: + fprintf(stderr, "%s: bad input format\n", ProgCall); } return 0; } -int -c_proc(char *str, char *Name) +int c_proc(char* str, char* Name) { int ch, ch2; - char *name = Salloc(Name); + char* name = Salloc(Name); - while (*str) { - if (*str == '\\') { + while (*str) + { + if (*str == '\\') + { ch = quoted(&str); } - else { + else + { ch = *str++ & 0377; } - if (*str == '-') { - if (*++str == '\\') { + if (*str == '-') + { + if (*++str == '\\') + { ch2 = quoted(&str); } - else { + else + { ch2 = (*str++ & 0377); - if (!ch2) str--; + if (!ch2) + str--; } - if (ch > ch2) { + if (ch > ch2) + { fprintf(stderr, "%s: bad range\n", ProgCall); return 0; } - while (ch <= ch2) { - if (! setval(ch, name)) return 0; + while (ch <= ch2) + { + if (!setval(ch, name)) + return 0; ch++; } } - else { - if (! setval(ch, name)) return 0; + else + { + if (!setval(ch, name)) + return 0; } } return 1; } -int -setval(int ch, char *nm) +int setval(int ch, char* nm) { - char **p = &Table[ch]; + char** p = &Table[ch]; - if (ch < 0 || ch >= TabSize) { + if (ch < 0 || ch >= TabSize) + { fprintf(stderr, "Illegal index: %d\n", ch); return 0; } - if (*(p = &Table[ch])) { + if (*(p = &Table[ch])) + { fprintf(stderr, "Warning: redefinition of index %d\n", ch); } *p = nm; return 1; } -int -quoted(char **pstr) +int quoted(char** pstr) { int ch; int i; - char *str = *pstr; + char* str = *pstr; - if ((*++str >= '0') && (*str <= '9')) { + if ((*++str >= '0') && (*str <= '9')) + { ch = 0; - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) + { ch = 8 * ch + (*str - '0'); if (*++str < '0' || *str > '9') break; } } - else { - switch (*str++) { - case 'n': - ch = '\n'; - break; - case 't': - ch = '\t'; - break; - case 'b': - ch = '\b'; - break; - case 'r': - ch = '\r'; - break; - case 'f': - ch = '\f'; - break; - case 'v': - ch = 013; - break; - default : - ch = *(str - 1); - break; + else + { + switch (*str++) + { + case 'n': + ch = '\n'; + break; + case 't': + ch = '\t'; + break; + case 'b': + ch = '\b'; + break; + case 'r': + ch = '\r'; + break; + case 'f': + ch = '\f'; + break; + case 'v': + ch = 013; + break; + default: + ch = *(str - 1); + break; } } *pstr = str; return ch & 0377; } -char * -getln(char *s, int n, FILE *fp) +char* getln(char* s, int n, FILE* fp) { int c = getc(fp); - char *str = s; + char* str = s; - while (n--) { - if (c == EOF) { + while (n--) + { + if (c == EOF) + { return NULL; } - else - if (c == '\n') { + else if (c == '\n') + { *str++ = '\0'; return s; } @@ -340,22 +370,26 @@ getln(char *s, int n, FILE *fp) #define BUFSIZE 1024 -void -DoFile(char *name) +void DoFile(char* name) { char text[BUFSIZE]; - FILE *fp; + FILE* fp; - if ((fp = fopen(name, "r")) == NULL) { + if ((fp = fopen(name, "r")) == NULL) + { fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name); exit(1); } - while (getln(text, BUFSIZE, fp) != NULL) { - if (text[0] == FILECOM) { + while (getln(text, BUFSIZE, fp) != NULL) + { + if (text[0] == FILECOM) + { option(text); } - else { - if (! process(text, InputForm)) { + else + { + if (!process(text, InputForm)) + { exit(1); } } From 1fc20e90c0c484842b2e06462509eb95106ccdf0 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 23:56:34 +0200 Subject: [PATCH 2/3] Remove c99-isms. --- plat/pc86/emu/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plat/pc86/emu/main.c b/plat/pc86/emu/main.c index 1558884a8..f5131229b 100644 --- a/plat/pc86/emu/main.c +++ b/plat/pc86/emu/main.c @@ -96,6 +96,8 @@ static void int13_cb(int num) int main(int argc, const char* argv[]) { + int i; + if (argc != 2) { printk("syntax: pc86emu \n"); @@ -116,7 +118,7 @@ int main(int argc, const char* argv[]) /* Load the boot sector at 0x07c0:0000. */ - for (int i=0; i<512; i++) + for (i=0; i<512; i++) { uint8_t b; read(floppy_fd, &b, 1); @@ -125,7 +127,7 @@ int main(int argc, const char* argv[]) /* Initialise. */ - for (int i=0; i<256; i++) + for (i=0; i<256; i++) intr_funcs[i] = unknown_interrupt_cb; intr_funcs[0x10] = int10_cb; intr_funcs[0x13] = int13_cb; From f45b357740612b91d8e6105e76c23d5947947906 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 24 Jun 2018 00:01:06 +0200 Subject: [PATCH 3/3] Remove the dependency on the glibc-only byteswap.h. --- plat/linuxppc/emu/emu.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plat/linuxppc/emu/emu.c b/plat/linuxppc/emu/emu.c index 90c9fd518..91ae87a8b 100644 --- a/plat/linuxppc/emu/emu.c +++ b/plat/linuxppc/emu/emu.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "emu.h" @@ -24,8 +23,23 @@ static inline bool carry(void) fatal("carry() not supported yet"); } -#define swb16(x) bswap_16(x) -#define swb32(x) bswap_32(x) +/* Byte-swaps a 16-bit value. */ +static inline uint16_t swb16(uint16_t n) +{ + return + (((n >> 8) & 0xff) | + ((n & 0xff) << 8)); +} + +/* Byte-swaps a 32-bit value. */ +static inline uint32_t swb32(uint32_t n) +{ + return + (((n & 0xff000000) >> 24) | + ((n & 0x00ff0000) >> 8) | + ((n & 0x0000ff00) << 8) | + ((n & 0x000000ff) << 24)); +} /* Returns the state of a carry flag after a three-way add. */ static inline bool carry_3(uint32_t a, uint32_t b, uint32_t c)