[PATCH] ppc64: make arch/ppc64/boot standalone

Make the bootheader for ppc64 independent from kernel and libc headers.
* add -nostdinc -isystem $gccincludes to not include libc headers
* declare all functions in header files, also the stuff from string.S
* declare some functions static
* use stddef.h to get size_t (hopefully ok)
* remove ppc32-types.h, only elf.h used the __NN types

With further modifications by Paul Mackerras and Stephen Rothwell.

Signed-off-by: Olaf Hering <olh@suse.de>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Olaf Hering and committed by
Paul Mackerras
decd300b 02b3e4e2

+348 -246
+2 -2
arch/ppc64/boot/Makefile
··· 22 22 23 23 24 24 HOSTCC := gcc 25 - BOOTCFLAGS := $(HOSTCFLAGS) $(LINUXINCLUDE) -fno-builtin 26 - BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional 25 + BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem $(shell $(CROSS32CC) -print-file-name=include) 26 + BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc 27 27 BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds 28 28 OBJCOPYFLAGS := contents,alloc,load,readonly,data 29 29
+2 -2
arch/ppc64/boot/addnote.c
··· 157 157 PUT_32BE(ns, strlen(arch) + 1); 158 158 PUT_32BE(ns + 4, N_DESCR * 4); 159 159 PUT_32BE(ns + 8, 0x1275); 160 - strcpy(&buf[ns + 12], arch); 160 + strcpy((char *) &buf[ns + 12], arch); 161 161 ns += 12 + strlen(arch) + 1; 162 162 for (i = 0; i < N_DESCR; ++i, ns += 4) 163 163 PUT_32BE(ns, descr[i]); ··· 172 172 PUT_32BE(ns, strlen(rpaname) + 1); 173 173 PUT_32BE(ns + 4, sizeof(rpanote)); 174 174 PUT_32BE(ns + 8, 0x12759999); 175 - strcpy(&buf[ns + 12], rpaname); 175 + strcpy((char *) &buf[ns + 12], rpaname); 176 176 ns += 12 + ROUNDUP(strlen(rpaname) + 1); 177 177 for (i = 0; i < N_RPA_DESCR; ++i, ns += 4) 178 178 PUT_32BE(ns, rpanote[i]);
+1 -1
arch/ppc64/boot/crt0.S
··· 9 9 * NOTE: this code runs in 32 bit mode and is packaged as ELF32. 10 10 */ 11 11 12 - #include <asm/ppc_asm.h> 12 + #include "ppc_asm.h" 13 13 14 14 .text 15 15 .globl _start
+1 -1
arch/ppc64/boot/div64.S
··· 13 13 * as published by the Free Software Foundation; either version 14 14 * 2 of the License, or (at your option) any later version. 15 15 */ 16 - #include <asm/ppc_asm.h> 16 + #include "ppc_asm.h" 17 17 18 18 .globl __div64_32 19 19 __div64_32:
+149
arch/ppc64/boot/elf.h
··· 1 + #ifndef _PPC_BOOT_ELF_H_ 2 + #define _PPC_BOOT_ELF_H_ 3 + 4 + /* 32-bit ELF base types. */ 5 + typedef unsigned int Elf32_Addr; 6 + typedef unsigned short Elf32_Half; 7 + typedef unsigned int Elf32_Off; 8 + typedef signed int Elf32_Sword; 9 + typedef unsigned int Elf32_Word; 10 + 11 + /* 64-bit ELF base types. */ 12 + typedef unsigned long long Elf64_Addr; 13 + typedef unsigned short Elf64_Half; 14 + typedef signed short Elf64_SHalf; 15 + typedef unsigned long long Elf64_Off; 16 + typedef signed int Elf64_Sword; 17 + typedef unsigned int Elf64_Word; 18 + typedef unsigned long long Elf64_Xword; 19 + typedef signed long long Elf64_Sxword; 20 + 21 + /* These constants are for the segment types stored in the image headers */ 22 + #define PT_NULL 0 23 + #define PT_LOAD 1 24 + #define PT_DYNAMIC 2 25 + #define PT_INTERP 3 26 + #define PT_NOTE 4 27 + #define PT_SHLIB 5 28 + #define PT_PHDR 6 29 + #define PT_TLS 7 /* Thread local storage segment */ 30 + #define PT_LOOS 0x60000000 /* OS-specific */ 31 + #define PT_HIOS 0x6fffffff /* OS-specific */ 32 + #define PT_LOPROC 0x70000000 33 + #define PT_HIPROC 0x7fffffff 34 + #define PT_GNU_EH_FRAME 0x6474e550 35 + 36 + #define PT_GNU_STACK (PT_LOOS + 0x474e551) 37 + 38 + /* These constants define the different elf file types */ 39 + #define ET_NONE 0 40 + #define ET_REL 1 41 + #define ET_EXEC 2 42 + #define ET_DYN 3 43 + #define ET_CORE 4 44 + #define ET_LOPROC 0xff00 45 + #define ET_HIPROC 0xffff 46 + 47 + /* These constants define the various ELF target machines */ 48 + #define EM_NONE 0 49 + #define EM_PPC 20 /* PowerPC */ 50 + #define EM_PPC64 21 /* PowerPC64 */ 51 + 52 + #define EI_NIDENT 16 53 + 54 + typedef struct elf32_hdr { 55 + unsigned char e_ident[EI_NIDENT]; 56 + Elf32_Half e_type; 57 + Elf32_Half e_machine; 58 + Elf32_Word e_version; 59 + Elf32_Addr e_entry; /* Entry point */ 60 + Elf32_Off e_phoff; 61 + Elf32_Off e_shoff; 62 + Elf32_Word e_flags; 63 + Elf32_Half e_ehsize; 64 + Elf32_Half e_phentsize; 65 + Elf32_Half e_phnum; 66 + Elf32_Half e_shentsize; 67 + Elf32_Half e_shnum; 68 + Elf32_Half e_shstrndx; 69 + } Elf32_Ehdr; 70 + 71 + typedef struct elf64_hdr { 72 + unsigned char e_ident[16]; /* ELF "magic number" */ 73 + Elf64_Half e_type; 74 + Elf64_Half e_machine; 75 + Elf64_Word e_version; 76 + Elf64_Addr e_entry; /* Entry point virtual address */ 77 + Elf64_Off e_phoff; /* Program header table file offset */ 78 + Elf64_Off e_shoff; /* Section header table file offset */ 79 + Elf64_Word e_flags; 80 + Elf64_Half e_ehsize; 81 + Elf64_Half e_phentsize; 82 + Elf64_Half e_phnum; 83 + Elf64_Half e_shentsize; 84 + Elf64_Half e_shnum; 85 + Elf64_Half e_shstrndx; 86 + } Elf64_Ehdr; 87 + 88 + /* These constants define the permissions on sections in the program 89 + header, p_flags. */ 90 + #define PF_R 0x4 91 + #define PF_W 0x2 92 + #define PF_X 0x1 93 + 94 + typedef struct elf32_phdr { 95 + Elf32_Word p_type; 96 + Elf32_Off p_offset; 97 + Elf32_Addr p_vaddr; 98 + Elf32_Addr p_paddr; 99 + Elf32_Word p_filesz; 100 + Elf32_Word p_memsz; 101 + Elf32_Word p_flags; 102 + Elf32_Word p_align; 103 + } Elf32_Phdr; 104 + 105 + typedef struct elf64_phdr { 106 + Elf64_Word p_type; 107 + Elf64_Word p_flags; 108 + Elf64_Off p_offset; /* Segment file offset */ 109 + Elf64_Addr p_vaddr; /* Segment virtual address */ 110 + Elf64_Addr p_paddr; /* Segment physical address */ 111 + Elf64_Xword p_filesz; /* Segment size in file */ 112 + Elf64_Xword p_memsz; /* Segment size in memory */ 113 + Elf64_Xword p_align; /* Segment alignment, file & memory */ 114 + } Elf64_Phdr; 115 + 116 + #define EI_MAG0 0 /* e_ident[] indexes */ 117 + #define EI_MAG1 1 118 + #define EI_MAG2 2 119 + #define EI_MAG3 3 120 + #define EI_CLASS 4 121 + #define EI_DATA 5 122 + #define EI_VERSION 6 123 + #define EI_OSABI 7 124 + #define EI_PAD 8 125 + 126 + #define ELFMAG0 0x7f /* EI_MAG */ 127 + #define ELFMAG1 'E' 128 + #define ELFMAG2 'L' 129 + #define ELFMAG3 'F' 130 + #define ELFMAG "\177ELF" 131 + #define SELFMAG 4 132 + 133 + #define ELFCLASSNONE 0 /* EI_CLASS */ 134 + #define ELFCLASS32 1 135 + #define ELFCLASS64 2 136 + #define ELFCLASSNUM 3 137 + 138 + #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 139 + #define ELFDATA2LSB 1 140 + #define ELFDATA2MSB 2 141 + 142 + #define EV_NONE 0 /* e_version, EI_VERSION */ 143 + #define EV_CURRENT 1 144 + #define EV_NUM 2 145 + 146 + #define ELFOSABI_NONE 0 147 + #define ELFOSABI_LINUX 3 148 + 149 + #endif /* _PPC_BOOT_ELF_H_ */
+18 -33
arch/ppc64/boot/main.c
··· 8 8 * as published by the Free Software Foundation; either version 9 9 * 2 of the License, or (at your option) any later version. 10 10 */ 11 - #include "ppc32-types.h" 11 + #include <stdarg.h> 12 + #include <stddef.h> 13 + #include "elf.h" 14 + #include "page.h" 15 + #include "string.h" 16 + #include "stdio.h" 17 + #include "prom.h" 12 18 #include "zlib.h" 13 - #include <linux/elf.h> 14 - #include <linux/string.h> 15 - #include <asm/processor.h> 16 - #include <asm/page.h> 17 19 18 - extern void *finddevice(const char *); 19 - extern int getprop(void *, const char *, void *, int); 20 - extern void printf(const char *fmt, ...); 21 - extern int sprintf(char *buf, const char *fmt, ...); 22 - void gunzip(void *, int, unsigned char *, int *); 23 - void *claim(unsigned int, unsigned int, unsigned int); 24 - void flush_cache(void *, unsigned long); 25 - void pause(void); 26 - extern void exit(void); 20 + static void gunzip(void *, int, unsigned char *, int *); 21 + extern void flush_cache(void *, unsigned long); 27 22 28 - unsigned long strlen(const char *s); 29 - void *memmove(void *dest, const void *src, unsigned long n); 30 - void *memcpy(void *dest, const void *src, unsigned long n); 31 23 32 24 /* Value picked to match that used by yaboot */ 33 25 #define PROG_START 0x01400000 34 26 #define RAM_END (256<<20) // Fixme: use OF */ 35 27 36 - char *avail_ram; 37 - char *begin_avail, *end_avail; 38 - char *avail_high; 39 - unsigned int heap_use; 40 - unsigned int heap_max; 28 + static char *avail_ram; 29 + static char *begin_avail, *end_avail; 30 + static char *avail_high; 31 + static unsigned int heap_use; 32 + static unsigned int heap_max; 41 33 42 34 extern char _start[]; 43 35 extern char _vmlinux_start[]; ··· 44 52 unsigned long size; 45 53 unsigned long memsize; 46 54 }; 47 - struct addr_range vmlinux = {0, 0, 0}; 48 - struct addr_range vmlinuz = {0, 0, 0}; 49 - struct addr_range initrd = {0, 0, 0}; 55 + static struct addr_range vmlinux = {0, 0, 0}; 56 + static struct addr_range vmlinuz = {0, 0, 0}; 57 + static struct addr_range initrd = {0, 0, 0}; 50 58 51 59 static char scratch[128<<10]; /* 128kB of scratch space for gunzip */ 52 60 ··· 55 63 void *, 56 64 void *); 57 65 58 - 59 - int (*prom)(void *); 60 - 61 - void *chosen_handle; 62 - void *stdin; 63 - void *stdout; 64 - void *stderr; 65 66 66 67 #undef DEBUG 67 68 ··· 262 277 263 278 #define DEFLATED 8 264 279 265 - void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) 280 + static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) 266 281 { 267 282 z_stream s; 268 283 int r, i, flags;
+34
arch/ppc64/boot/page.h
··· 1 + #ifndef _PPC_BOOT_PAGE_H 2 + #define _PPC_BOOT_PAGE_H 3 + /* 4 + * Copyright (C) 2001 PPC64 Team, IBM Corp 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License 8 + * as published by the Free Software Foundation; either version 9 + * 2 of the License, or (at your option) any later version. 10 + */ 11 + 12 + #ifdef __ASSEMBLY__ 13 + #define ASM_CONST(x) x 14 + #else 15 + #define __ASM_CONST(x) x##UL 16 + #define ASM_CONST(x) __ASM_CONST(x) 17 + #endif 18 + 19 + /* PAGE_SHIFT determines the page size */ 20 + #define PAGE_SHIFT 12 21 + #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT) 22 + #define PAGE_MASK (~(PAGE_SIZE-1)) 23 + 24 + /* align addr on a size boundary - adjust address up/down if needed */ 25 + #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) 26 + #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1))) 27 + 28 + /* align addr on a size boundary - adjust address up if needed */ 29 + #define _ALIGN(addr,size) _ALIGN_UP(addr,size) 30 + 31 + /* to align the pointer to the (next) page boundary */ 32 + #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE) 33 + 34 + #endif /* _PPC_BOOT_PAGE_H */
-36
arch/ppc64/boot/ppc32-types.h
··· 1 - #ifndef _PPC64_TYPES_H 2 - #define _PPC64_TYPES_H 3 - 4 - typedef __signed__ char __s8; 5 - typedef unsigned char __u8; 6 - 7 - typedef __signed__ short __s16; 8 - typedef unsigned short __u16; 9 - 10 - typedef __signed__ int __s32; 11 - typedef unsigned int __u32; 12 - 13 - typedef __signed__ long long __s64; 14 - typedef unsigned long long __u64; 15 - 16 - typedef signed char s8; 17 - typedef unsigned char u8; 18 - 19 - typedef signed short s16; 20 - typedef unsigned short u16; 21 - 22 - typedef signed int s32; 23 - typedef unsigned int u32; 24 - 25 - typedef signed long long s64; 26 - typedef unsigned long long u64; 27 - 28 - typedef struct { 29 - __u32 u[4]; 30 - } __attribute((aligned(16))) __vector128; 31 - 32 - #define BITS_PER_LONG 32 33 - 34 - typedef __vector128 vector128; 35 - 36 - #endif /* _PPC64_TYPES_H */
+62
arch/ppc64/boot/ppc_asm.h
··· 1 + #ifndef _PPC64_PPC_ASM_H 2 + #define _PPC64_PPC_ASM_H 3 + /* 4 + * 5 + * Definitions used by various bits of low-level assembly code on PowerPC. 6 + * 7 + * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan. 8 + * 9 + * This program is free software; you can redistribute it and/or 10 + * modify it under the terms of the GNU General Public License 11 + * as published by the Free Software Foundation; either version 12 + * 2 of the License, or (at your option) any later version. 13 + */ 14 + 15 + /* Condition Register Bit Fields */ 16 + 17 + #define cr0 0 18 + #define cr1 1 19 + #define cr2 2 20 + #define cr3 3 21 + #define cr4 4 22 + #define cr5 5 23 + #define cr6 6 24 + #define cr7 7 25 + 26 + 27 + /* General Purpose Registers (GPRs) */ 28 + 29 + #define r0 0 30 + #define r1 1 31 + #define r2 2 32 + #define r3 3 33 + #define r4 4 34 + #define r5 5 35 + #define r6 6 36 + #define r7 7 37 + #define r8 8 38 + #define r9 9 39 + #define r10 10 40 + #define r11 11 41 + #define r12 12 42 + #define r13 13 43 + #define r14 14 44 + #define r15 15 45 + #define r16 16 46 + #define r17 17 47 + #define r18 18 48 + #define r19 19 49 + #define r20 20 50 + #define r21 21 51 + #define r22 22 52 + #define r23 23 53 + #define r24 24 54 + #define r25 25 55 + #define r26 26 56 + #define r27 27 57 + #define r28 28 58 + #define r29 29 59 + #define r30 30 60 + #define r31 31 61 + 62 + #endif /* _PPC64_PPC_ASM_H */
+27 -169
arch/ppc64/boot/prom.c
··· 7 7 * 2 of the License, or (at your option) any later version. 8 8 */ 9 9 #include <stdarg.h> 10 - #include <linux/types.h> 11 - #include <linux/string.h> 12 - #include <linux/ctype.h> 13 - 14 - extern __u32 __div64_32(unsigned long long *dividend, __u32 divisor); 15 - 16 - /* The unnecessary pointer compare is there 17 - * to check for type safety (n must be 64bit) 18 - */ 19 - # define do_div(n,base) ({ \ 20 - __u32 __base = (base); \ 21 - __u32 __rem; \ 22 - (void)(((typeof((n)) *)0) == ((unsigned long long *)0)); \ 23 - if (((n) >> 32) == 0) { \ 24 - __rem = (__u32)(n) % __base; \ 25 - (n) = (__u32)(n) / __base; \ 26 - } else \ 27 - __rem = __div64_32(&(n), __base); \ 28 - __rem; \ 29 - }) 10 + #include <stddef.h> 11 + #include "string.h" 12 + #include "stdio.h" 13 + #include "prom.h" 30 14 31 15 int (*prom)(void *); 32 16 33 17 void *chosen_handle; 18 + 34 19 void *stdin; 35 20 void *stdout; 36 21 void *stderr; 37 22 38 - void exit(void); 39 - void *finddevice(const char *name); 40 - int getprop(void *phandle, const char *name, void *buf, int buflen); 41 - void chrpboot(int a1, int a2, void *prom); /* in main.c */ 42 - 43 - int printf(char *fmt, ...); 44 - 45 - /* there is no convenient header to get this from... -- paulus */ 46 - extern unsigned long strlen(const char *); 47 23 48 24 int 49 25 write(void *handle, void *ptr, int nb) ··· 186 210 return write(f, str, n) == n? 0: -1; 187 211 } 188 212 189 - int 190 - readchar(void) 191 - { 192 - char ch; 193 - 194 - for (;;) { 195 - switch (read(stdin, &ch, 1)) { 196 - case 1: 197 - return ch; 198 - case -1: 199 - printf("read(stdin) returned -1\r\n"); 200 - return -1; 201 - } 202 - } 203 - } 204 - 205 - static char line[256]; 206 - static char *lineptr; 207 - static int lineleft; 208 - 209 - int 210 - getchar(void) 211 - { 212 - int c; 213 - 214 - if (lineleft == 0) { 215 - lineptr = line; 216 - for (;;) { 217 - c = readchar(); 218 - if (c == -1 || c == 4) 219 - break; 220 - if (c == '\r' || c == '\n') { 221 - *lineptr++ = '\n'; 222 - putchar('\n'); 223 - break; 224 - } 225 - switch (c) { 226 - case 0177: 227 - case '\b': 228 - if (lineptr > line) { 229 - putchar('\b'); 230 - putchar(' '); 231 - putchar('\b'); 232 - --lineptr; 233 - } 234 - break; 235 - case 'U' & 0x1F: 236 - while (lineptr > line) { 237 - putchar('\b'); 238 - putchar(' '); 239 - putchar('\b'); 240 - --lineptr; 241 - } 242 - break; 243 - default: 244 - if (lineptr >= &line[sizeof(line) - 1]) 245 - putchar('\a'); 246 - else { 247 - putchar(c); 248 - *lineptr++ = c; 249 - } 250 - } 251 - } 252 - lineleft = lineptr - line; 253 - lineptr = line; 254 - } 255 - if (lineleft == 0) 256 - return -1; 257 - --lineleft; 258 - return *lineptr++; 259 - } 260 - 261 - 262 - 263 - /* String functions lifted from lib/vsprintf.c and lib/ctype.c */ 264 - unsigned char _ctype[] = { 265 - _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 266 - _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 267 - _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 268 - _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 269 - _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 270 - _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 271 - _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 272 - _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 273 - _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 274 - _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 275 - _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 276 - _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 277 - _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 278 - _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 279 - _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 280 - _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 281 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ 282 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ 283 - _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ 284 - _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ 285 - _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ 286 - _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ 287 - _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ 288 - _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ 289 - 290 213 size_t strnlen(const char * s, size_t count) 291 214 { 292 215 const char *sc; ··· 195 320 return sc - s; 196 321 } 197 322 198 - unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) 199 - { 200 - unsigned long result = 0,value; 323 + extern unsigned int __div64_32(unsigned long long *dividend, 324 + unsigned int divisor); 201 325 202 - if (!base) { 203 - base = 10; 204 - if (*cp == '0') { 205 - base = 8; 206 - cp++; 207 - if ((*cp == 'x') && isxdigit(cp[1])) { 208 - cp++; 209 - base = 16; 210 - } 211 - } 212 - } 213 - while (isxdigit(*cp) && 214 - (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) { 215 - result = result*base + value; 216 - cp++; 217 - } 218 - if (endp) 219 - *endp = (char *)cp; 220 - return result; 221 - } 222 - 223 - long simple_strtol(const char *cp,char **endp,unsigned int base) 224 - { 225 - if(*cp=='-') 226 - return -simple_strtoul(cp+1,endp,base); 227 - return simple_strtoul(cp,endp,base); 228 - } 326 + /* The unnecessary pointer compare is there 327 + * to check for type safety (n must be 64bit) 328 + */ 329 + # define do_div(n,base) ({ \ 330 + unsigned int __base = (base); \ 331 + unsigned int __rem; \ 332 + (void)(((typeof((n)) *)0) == ((unsigned long long *)0)); \ 333 + if (((n) >> 32) == 0) { \ 334 + __rem = (unsigned int)(n) % __base; \ 335 + (n) = (unsigned int)(n) / __base; \ 336 + } else \ 337 + __rem = __div64_32(&(n), __base); \ 338 + __rem; \ 339 + }) 229 340 230 341 static int skip_atoi(const char **s) 231 342 { 232 - int i=0; 343 + int i, c; 233 344 234 - while (isdigit(**s)) 235 - i = i*10 + *((*s)++) - '0'; 345 + for (i = 0; '0' <= (c = **s) && c <= '9'; ++*s) 346 + i = i*10 + c - '0'; 236 347 return i; 237 348 } 238 349 ··· 297 436 return str; 298 437 } 299 438 300 - /* Forward decl. needed for IP address printing stuff... */ 301 - int sprintf(char * buf, const char *fmt, ...); 302 - 303 439 int vsprintf(char *buf, const char *fmt, va_list args) 304 440 { 305 441 int len; ··· 335 477 336 478 /* get field width */ 337 479 field_width = -1; 338 - if (isdigit(*fmt)) 480 + if ('0' <= *fmt && *fmt <= '9') 339 481 field_width = skip_atoi(&fmt); 340 482 else if (*fmt == '*') { 341 483 ++fmt; ··· 351 493 precision = -1; 352 494 if (*fmt == '.') { 353 495 ++fmt; 354 - if (isdigit(*fmt)) 496 + if ('0' <= *fmt && *fmt <= '9') 355 497 precision = skip_atoi(&fmt); 356 498 else if (*fmt == '*') { 357 499 ++fmt; ··· 486 628 static char sprint_buf[1024]; 487 629 488 630 int 489 - printf(char *fmt, ...) 631 + printf(const char *fmt, ...) 490 632 { 491 633 va_list args; 492 634 int n;
+18
arch/ppc64/boot/prom.h
··· 1 + #ifndef _PPC_BOOT_PROM_H_ 2 + #define _PPC_BOOT_PROM_H_ 3 + 4 + extern int (*prom) (void *); 5 + extern void *chosen_handle; 6 + 7 + extern void *stdin; 8 + extern void *stdout; 9 + extern void *stderr; 10 + 11 + extern int write(void *handle, void *ptr, int nb); 12 + extern int read(void *handle, void *ptr, int nb); 13 + extern void exit(void); 14 + extern void pause(void); 15 + extern void *finddevice(const char *); 16 + extern void *claim(unsigned long virt, unsigned long size, unsigned long align); 17 + extern int getprop(void *phandle, const char *name, void *buf, int buflen); 18 + #endif /* _PPC_BOOT_PROM_H_ */
+16
arch/ppc64/boot/stdio.h
··· 1 + #ifndef _PPC_BOOT_STDIO_H_ 2 + #define _PPC_BOOT_STDIO_H_ 3 + 4 + extern int printf(const char *fmt, ...); 5 + 6 + extern int sprintf(char *buf, const char *fmt, ...); 7 + 8 + extern int vsprintf(char *buf, const char *fmt, va_list args); 9 + 10 + extern int putc(int c, void *f); 11 + extern int putchar(int c); 12 + extern int getchar(void); 13 + 14 + extern int fputs(char *str, void *f); 15 + 16 + #endif /* _PPC_BOOT_STDIO_H_ */
+1 -1
arch/ppc64/boot/string.S
··· 9 9 * NOTE: this code runs in 32 bit mode and is packaged as ELF32. 10 10 */ 11 11 12 - #include <asm/ppc_asm.h> 12 + #include "ppc_asm.h" 13 13 14 14 .text 15 15 .globl strcpy
+16
arch/ppc64/boot/string.h
··· 1 + #ifndef _PPC_BOOT_STRING_H_ 2 + #define _PPC_BOOT_STRING_H_ 3 + 4 + extern char *strcpy(char *dest, const char *src); 5 + extern char *strncpy(char *dest, const char *src, size_t n); 6 + extern char *strcat(char *dest, const char *src); 7 + extern int strcmp(const char *s1, const char *s2); 8 + extern size_t strlen(const char *s); 9 + extern size_t strnlen(const char *s, size_t count); 10 + 11 + extern void *memset(void *s, int c, size_t n); 12 + extern void *memmove(void *dest, const void *src, unsigned long n); 13 + extern void *memcpy(void *dest, const void *src, unsigned long n); 14 + extern int memcmp(const void *s1, const void *s2, size_t n); 15 + 16 + #endif /* _PPC_BOOT_STRING_H_ */
+1 -1
arch/ppc64/boot/zlib.c
··· 107 107 108 108 /* Diagnostic functions */ 109 109 #ifdef DEBUG_ZLIB 110 - # include <stdio.h> 110 + # include "stdio.h" 111 111 # ifndef verbose 112 112 # define verbose 0 113 113 # endif