From: Andy P. <at...@us...> - 2002-04-10 18:30:53
|
Update of /cvsroot/linux-vax/kernel-2.4/arch/ppc/boot/pmac In directory usw-pr-cvs1:/tmp/cvs-serv25860/ppc/boot/pmac Added Files: Makefile chrpmain.c coffmain.c dummy.c ld.script misc.S start.c Log Message: synch 2.4.15 commit 43 --- NEW FILE --- # BK Id: SCCS/s.Makefile 1.14 07/27/01 20:24:17 trini # # Makefile for making XCOFF bootable images for booting on PowerMacs # using Open Firmware. # # Paul Mackerras January 1997 # # Cleaned up, moved into arch/ppc/boot/pmac # Tom Rini January 2001 OBJCOPY_ARGS = -O aixcoff-rs6000 -R .stab -R .stabstr -R .comment COFF_LD_ARGS = -e _start -T ld.script -Ttext 500000 -Tdata 510000 -Bstatic CHRP_LD_ARGS = -Ttext 0x01000000 COMMONOBJS = start.o misc.o ../common/string.o image.o ../common/ofcommon.o COFFOBJS = ../common/coffcrt0.o $(COMMONOBJS) coffmain.o CHRPOBJS = ../common/crt0.o $(COMMONOBJS) chrpmain.o LIBS = $(TOPDIR)/lib/lib.a ../lib/zlib.a MKNOTE := ../utils/mknote SIZE := ../utils/size OFFSET := ../utils/offset PIGGYBACK := ../utils/piggyback HACKCOFF := ../utils/hack-coff ifeq ($(CONFIG_PPC64BRIDGE),y) MSIZE=.64 else MSIZE= endif ifeq ($(CONFIG_SMP),y) TFTPIMAGE=/tftpboot/zImage.pmac.smp$(MSIZE) else TFTPIMAGE=/tftpboot/zImage.pmac$(MSIZE) endif ../common/crt0.o: $(MAKE) -C ../common crt0.o ../common/coffcrt0.o: $(MAKE) -C ../common coffcrt0.o chrpmain.o: chrpmain.c $(CC) $(CFLAGS) -DSYSMAP_OFFSET=0 -DSYSMAP_SIZE=0 -c chrpmain.c znetboot: vmlinux.coff vmlinux.elf-pmac zImage cp ../images/vmlinux.coff $(TFTPIMAGE) cp ../images/vmlinux.elf-pmac $(TFTPIMAGE).elf znetboot.initrd: vmlinux.coff.initrd vmlinux.initrd.elf-pmac cp ../images/vmlinux.coff.initrd $(TFTPIMAGE) cp ../images/vmlinux.elf-pmac.initrd $(TFTPIMAGE).elf #floppy: zImage # mount -t hfs /dev/fd0 /mnt # cp vmlinux.coff /mnt # umount /mnt miboot.image: dummy.o ../images/vmlinux.gz $(OBJCOPY) $(OBJCOPY_ARGS) --add-section=image=../images/vmlinux.gz \ dummy.o ../images/$@ miboot.image.initrd: miboot.image ../images/ramdisk.image.gz $(OBJCOPY) $(OBJCOPY_ARGS) --add-section=initrd=../images/ramdisk.image.gz \ ../images/miboot.image ../images/$@ coffboot: $(COFFOBJS) $(LIBS) ../common/no_initrd.o ld.script ../images/vmlinux.gz $(LD) -o $@ $(COFF_LD_ARGS) $(COFFOBJS) ../common/no_initrd.o $(LIBS) coffboot.initrd: $(COFFOBJS) $(LIBS) initrd.o ld.script ../images/vmlinux.gz $(LD) -o $@ $(COFF_LD_ARGS) $(COFFOBJS) initrd.o $(LIBS) image.o: $(PIGGYBACK) ../images/vmlinux.gz $(PIGGYBACK) image < ../images/vmlinux.gz | $(AS) -o $@ initrd.o: ../images/ramdisk.image.gz $(PIGGYBACK) $(PIGGYBACK) initrd < ../images/ramdisk.image.gz | $(AS) -o $@ vmlinux.coff: coffboot $(HACKCOFF) $(OBJCOPY) $(OBJCOPY_ARGS) coffboot ../images/$@ $(HACKCOFF) ../images/$@ rm -f coffboot ln -sf vmlinux.coff ../images/zImage.pmac vmlinux.coff.initrd: coffboot.initrd $(HACKCOFF) $(OBJCOPY) $(OBJCOPY_ARGS) coffboot.initrd ../images/$@ $(HACKCOFF) ../images/$@ rm -f coffboot.initrd ln -sf vmlinux.coff.initrd ../images/zImage.initrd.pmac vmlinux.elf-pmac: $(CHRPOBJS) $(LIBS) ../common/no_initrd.o $(MKNOTE) ../images/vmlinux.gz $(LD) $(CHRP_LD_ARGS) -o ../images/$@ $(CHRPOBJS) ../common/no_initrd.o $(LIBS) $(MKNOTE) > note $(OBJCOPY) ../images/$@ ../images/$@ --add-section=.note=note \ --add-section=sysmap=$(TOPDIR)/System.map -R .comment $(CC) $(CFLAGS) chrpmain.c -c -o chrpmain.o \ -DSYSMAP_OFFSET=`sh $(OFFSET) $(OBJDUMP) ../images/$@ sysmap` \ -DSYSMAP_SIZE=`sh $(SIZE) $(OBJDUMP) ../images/$@ sysmap` $(LD) $(CHRP_LD_ARGS) -o ../images/$@ $(CHRPOBJS) ../common/no_initrd.o $(LIBS) $(OBJCOPY) ../images/$@ ../images/$@ --add-section=.note=note \ --add-section=sysmap=$(TOPDIR)/System.map -R .comment rm -f note vmlinux.initrd.elf-pmac: $(CHRPOBJS) $(LIBS) initrd.o $(MKNOTE) ../images/vmlinux.gz $(LD) $(CHRP_LD_ARGS) -o ../images/$@ $(CHRPOBJS) initrd.o $(LIBS) $(MKNOTE) > note $(OBJCOPY) ../images/$@ ../images/$@ --add-section=.note=note -R .comment rm -f note zImage: vmlinux.coff vmlinux.elf-pmac miboot.image zImage.initrd: vmlinux.coff.initrd vmlinux.initrd.elf-pmac miboot.image.initrd include $(TOPDIR)/Rules.make --- NEW FILE --- /* * BK Id: SCCS/s.chrpmain.c 1.16 07/27/01 20:24:18 trini */ /* * Copyright (C) Paul Mackerras 1997. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include "nonstdio.h" #include "zlib.h" #include <asm/processor.h> extern char _end[]; extern char image_data[], initrd_data[]; extern int image_len, initrd_len; extern int getprop(void *, const char *, void *, int); extern unsigned int heap_max; extern void *claim(unsigned int, unsigned int, unsigned int); extern void *finddevice(const char *); extern void flush_cache(void *start, unsigned int len); extern void gunzip(void *, int, unsigned char *, int *); extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach, unsigned int progend); extern void pause(void); extern void release(void *ptr, unsigned int len); char *avail_ram; char *begin_avail, *end_avail; char *avail_high; #define RAM_END (16 << 20) #define PROG_START 0x00010000 #define PROG_SIZE 0x003f0000 #define SCRATCH_SIZE (128 << 10) void boot(int a1, int a2, void *prom) { unsigned sa, len; void *dst; unsigned char *im; unsigned initrd_start, initrd_size; extern char _start; printf("chrpboot starting: loaded at 0x%p\n", &_start); if (initrd_len) { initrd_size = initrd_len; initrd_start = (RAM_END - initrd_size) & ~0xFFF; a1 = initrd_start; a2 = initrd_size; claim(initrd_start, RAM_END - initrd_start, 0); printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n", initrd_start, initrd_data,initrd_size); memcpy((char *)initrd_start, initrd_data, initrd_size); } im = image_data; len = image_len; /* claim 3MB starting at PROG_START */ claim(PROG_START, PROG_SIZE, 0); dst = (void *) PROG_START; if (im[0] == 0x1f && im[1] == 0x8b) { /* claim some memory for scratch space */ avail_ram = (char *) claim(0, SCRATCH_SIZE, 0x10); begin_avail = avail_high = avail_ram; end_avail = avail_ram + SCRATCH_SIZE; printf("heap at 0x%p\n", avail_ram); printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len); gunzip(dst, PROG_SIZE, im, &len); printf("done %u bytes\n", len); printf("%u bytes of heap consumed, max in use %u\n", avail_high - begin_avail, heap_max); release(begin_avail, SCRATCH_SIZE); } else { memmove(dst, im, len); } flush_cache(dst, len); make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_Pmac, (PROG_START + PROG_SIZE)); sa = (unsigned long)PROG_START; printf("start address = 0x%x\n", sa); (*(void (*)())sa)(a1, a2, prom); printf("returned?\n"); pause(); } --- NEW FILE --- /* * BK Id: SCCS/s.coffmain.c 1.14 07/27/01 20:24:18 trini */ /* * Copyright (C) Paul Mackerras 1997. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include "nonstdio.h" #include "zlib.h" #include <asm/processor.h> extern char _start[], _end[]; extern char *claim(unsigned, unsigned, unsigned); extern char image_data[], initrd_data[]; extern int initrd_len, image_len; extern int getprop(void *, const char *, void *, int); extern unsigned int heap_max; extern void *finddevice(const char *); extern void flush_cache(void *start, unsigned int len); extern void gunzip(void *, int, unsigned char *, int *); extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach, unsigned int progend); extern void pause(void); extern void setup_bats(unsigned long start); char *avail_ram; char *begin_avail, *end_avail; char *avail_high; #define RAM_START 0 #define RAM_END (RAM_START + 0x800000) /* only 8M mapped with BATs */ #define PROG_START RAM_START #define PROG_SIZE 0x00400000 #define SCRATCH_SIZE (128 << 10) static char heap[SCRATCH_SIZE]; void boot(int a1, int a2, void *prom) { unsigned sa, len; void *dst; unsigned char *im; unsigned initrd_start, initrd_size; printf("coffboot starting: loaded at 0x%p\n", &_start); setup_bats(RAM_START); if (initrd_len) { initrd_size = initrd_len; initrd_start = (RAM_END - initrd_size) & ~0xFFF; a1 = initrd_start; a2 = initrd_size; claim(initrd_start - RAM_START, RAM_END - initrd_start, 0); printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n", initrd_start, initrd_data, initrd_size); memcpy((char *)initrd_start, initrd_data, initrd_size); } im = image_data; len = image_len; /* claim 4MB starting at 0 */ claim(0, PROG_SIZE, 0); dst = (void *) RAM_START; if (im[0] == 0x1f && im[1] == 0x8b) { /* set up scratch space */ begin_avail = avail_high = avail_ram = heap; end_avail = heap + sizeof(heap); printf("heap at 0x%p\n", avail_ram); printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len); gunzip(dst, PROG_SIZE, im, &len); printf("done %u bytes\n", len); printf("%u bytes of heap consumed, max in use %u\n", avail_high - begin_avail, heap_max); } else { memmove(dst, im, len); } flush_cache(dst, len); make_bi_recs(((unsigned long) dst + len), "coffboot", _MACH_Pmac, (PROG_START + PROG_SIZE)); sa = (unsigned long)PROG_START; printf("start address = 0x%x\n", sa); (*(void (*)())sa)(a1, a2, prom); printf("returned?\n"); pause(); } --- NEW FILE --- /* * BK Id: SCCS/s.dummy.c 1.6 05/18/01 15:17:15 cort */ int main(void) { return 0; } --- NEW FILE --- OUTPUT_ARCH(powerpc) SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/local/powerpc-any-elf/lib); /* Do we need any of these for elf? __DYNAMIC = 0; */ SECTIONS { /* Read-only sections, merged into text segment: */ . = + SIZEOF_HEADERS; .interp : { *(.interp) } .hash : { *(.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .rel.text : { *(.rel.text) } .rela.text : { *(.rela.text) } .rel.data : { *(.rel.data) } .rela.data : { *(.rela.data) } .rel.rodata : { *(.rel.rodata) } .rela.rodata : { *(.rela.rodata) } .rel.got : { *(.rel.got) } .rela.got : { *(.rela.got) } .rel.ctors : { *(.rel.ctors) } .rela.ctors : { *(.rela.ctors) } .rel.dtors : { *(.rel.dtors) } .rela.dtors : { *(.rela.dtors) } .rel.bss : { *(.rel.bss) } .rela.bss : { *(.rela.bss) } .rel.plt : { *(.rel.plt) } .rela.plt : { *(.rela.plt) } .init : { *(.init) } =0 .plt : { *(.plt) } .text : { *(.text) *(.rodata) *(.rodata.*) *(.rodata1) *(.got1) } .fini : { *(.fini) } =0 .ctors : { *(.ctors) } .dtors : { *(.dtors) } _etext = .; PROVIDE (etext = .); /* Read-write section, merged into data segment: */ . = (. + 0x0FFF) & 0xFFFFF000; .data : { *(.data) *(.data1) *(.sdata) *(.sdata2) *(.got.plt) *(.got) *(.dynamic) CONSTRUCTORS } _edata = .; PROVIDE (edata = .); __bss_start = .; .bss : { *(.sbss) *(.scommon) *(.dynbss) *(.bss) *(COMMON) } _end = . ; PROVIDE (end = .); } --- NEW FILE --- /* * BK Id: SCCS/s.misc.S 1.6 05/18/01 15:17:15 cort */ /* * Copyright (C) Paul Mackerras 1997. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ .text /* * Use the BAT3 registers to map the 1st 8MB of RAM to * the address given as the 1st argument. */ .globl setup_bats setup_bats: mfpvr 5 rlwinm 5,5,16,16,31 /* r3 = 1 for 601, 4 for 604 */ cmpi 0,5,1 li 0,0 bne 4f mtibatl 3,0 /* invalidate BAT first */ ori 3,3,4 /* set up BAT registers for 601 */ li 4,0x7f mtibatu 3,3 mtibatl 3,4 b 5f 4: mtdbatu 3,0 /* invalidate BATs first */ mtibatu 3,0 ori 3,3,0xff /* set up BAT registers for 604 */ li 4,2 mtdbatl 3,4 mtdbatu 3,3 mtibatl 3,4 mtibatu 3,3 5: sync isync blr /* * Flush the dcache and invalidate the icache for a range of addresses. * * flush_cache(addr, len) */ .global flush_cache flush_cache: addi 4,4,0x1f /* len = (len + 0x1f) / 0x20 */ rlwinm. 4,4,27,5,31 mtctr 4 beqlr 1: dcbf 0,3 icbi 0,3 addi 3,3,0x20 bdnz 1b sync isync blr --- NEW FILE --- /* * BK Id: SCCS/s.start.c 1.10 07/25/01 18:13:07 trini */ /* * Copyright (C) Paul Mackerras 1997. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <stdarg.h> extern int strlen(const char *s); extern void boot(int a1, int a2, void *prom); int (*prom)(); void *chosen_handle; void *stdin; void *stdout; void *stderr; void exit(void); void *finddevice(const char *name); int getprop(void *phandle, const char *name, void *buf, int buflen); void printk(char *fmt, ...); void start(int a1, int a2, void *promptr) { prom = (int (*)()) promptr; chosen_handle = finddevice("/chosen"); if (chosen_handle == (void *) -1) exit(); if (getprop(chosen_handle, "stdout", &stdout, sizeof(stdout)) != 4) exit(); stderr = stdout; if (getprop(chosen_handle, "stdin", &stdin, sizeof(stdin)) != 4) exit(); boot(a1, a2, promptr); for (;;) exit(); } int write(void *handle, void *ptr, int nb) { struct prom_args { char *service; int nargs; int nret; void *ihandle; void *addr; int len; int actual; } args; args.service = "write"; args.nargs = 3; args.nret = 1; args.ihandle = handle; args.addr = ptr; args.len = nb; args.actual = -1; (*prom)(&args); return args.actual; } int writestring(void *f, char *ptr, int nb) { int w = 0, i; char *ret = "\r"; for (i = 0; i < nb; ++i) { if (ptr[i] == '\n') { if (i > w) { write(f, ptr + w, i - w); w = i; } write(f, ret, 1); } } if (w < nb) write(f, ptr + w, nb - w); return nb; } int read(void *handle, void *ptr, int nb) { struct prom_args { char *service; int nargs; int nret; void *ihandle; void *addr; int len; int actual; } args; args.service = "read"; args.nargs = 3; args.nret = 1; args.ihandle = handle; args.addr = ptr; args.len = nb; args.actual = -1; (*prom)(&args); return args.actual; } void exit(void) { struct prom_args { char *service; } args; for (;;) { args.service = "exit"; (*prom)(&args); } } void pause(void) { struct prom_args { char *service; } args; args.service = "enter"; (*prom)(&args); } void * finddevice(const char *name) { struct prom_args { char *service; int nargs; int nret; const char *devspec; void *phandle; } args; args.service = "finddevice"; args.nargs = 1; args.nret = 1; args.devspec = name; args.phandle = (void *) -1; (*prom)(&args); return args.phandle; } void * claim(unsigned int virt, unsigned int size, unsigned int align) { struct prom_args { char *service; int nargs; int nret; unsigned int virt; unsigned int size; unsigned int align; void *ret; } args; args.service = "claim"; args.nargs = 3; args.nret = 1; args.virt = virt; args.size = size; args.align = align; (*prom)(&args); return args.ret; } void release(void *virt, unsigned int size) { struct prom_args { char *service; int nargs; int nret; void *virt; unsigned int size; } args; args.service = "release"; args.nargs = 2; args.nret = 0; args.virt = virt; args.size = size; (*prom)(&args); } int getprop(void *phandle, const char *name, void *buf, int buflen) { struct prom_args { char *service; int nargs; int nret; void *phandle; const char *name; void *buf; int buflen; int size; } args; args.service = "getprop"; args.nargs = 4; args.nret = 1; args.phandle = phandle; args.name = name; args.buf = buf; args.buflen = buflen; args.size = -1; (*prom)(&args); return args.size; } int putc(int c, void *f) { char ch = c; return writestring(f, &ch, 1) == 1? c: -1; } int putchar(int c) { return putc(c, stdout); } int fputs(char *str, void *f) { int n = strlen(str); return writestring(f, str, n) == n? 0: -1; } int readchar(void) { char ch; for (;;) { switch (read(stdin, &ch, 1)) { case 1: return ch; case -1: printk("read(stdin) returned -1\n"); return -1; } } } static char line[256]; static char *lineptr; static int lineleft; int getchar(void) { int c; if (lineleft == 0) { lineptr = line; for (;;) { c = readchar(); if (c == -1 || c == 4) break; if (c == '\r' || c == '\n') { *lineptr++ = '\n'; putchar('\n'); break; } switch (c) { case 0177: case '\b': if (lineptr > line) { putchar('\b'); putchar(' '); putchar('\b'); --lineptr; } break; case 'U' & 0x1F: while (lineptr > line) { putchar('\b'); putchar(' '); putchar('\b'); --lineptr; } break; default: if (lineptr >= &line[sizeof(line) - 1]) putchar('\a'); else { putchar(c); *lineptr++ = c; } } } lineleft = lineptr - line; lineptr = line; } if (lineleft == 0) return -1; --lineleft; return *lineptr++; } extern int vsprintf(char *buf, const char *fmt, va_list args); static char sprint_buf[1024]; void printk(char *fmt, ...) { va_list args; int n; va_start(args, fmt); n = vsprintf(sprint_buf, fmt, args); va_end(args); writestring(stdout, sprint_buf, n); } int printf(char *fmt, ...) { va_list args; int n; va_start(args, fmt); n = vsprintf(sprint_buf, fmt, args); va_end(args); writestring(stdout, sprint_buf, n); return n; } |