Commit bca7dfa6 authored by Todd Inglett's avatar Todd Inglett

zImage now holds vmlinux, System.map and config in sections.

parent 47f81bc1
......@@ -24,35 +24,45 @@ CROSS32_COMPILE =
#CROSS32_COMPILE = /usr/local/ppc/bin/powerpc-linux-
BOOTCC := $(CROSS32_COMPILE)gcc
BOOTCFLAGS := $(HOSTCFLAGS) -Iinclude
BOOTLD := $(CROSS32_COMPILE)ld
HOSTCC := gcc
BOOTCFLAGS := $(HOSTCFLAGS) -Iinclude -fno-builtin
BOOTAS := $(CROSS32_COMPILE)as
BOOTAFLAGS := -D__ASSEMBLY__ $(HOSTCFLAGS)
CFLAGS := $(CPPFLAGS) -O -fno-builtin -DSTDC_HEADERS
LD_ARGS := -Ttext 0x00400000 -e _start
OBJCOPYFLAGS := -S -O binary
BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional
BOOTLD := $(CROSS32_COMPILE)ld
BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(obj)/zImage.lds
BOOTOBJCOPY := $(CROSS32_COMPILE)objcopy
OBJCOPYFLAGS := contents,alloc,load,readonly,data
obj-boot := start.o main.o zlib.o imagesize.o no_initrd.o
OBJS := crt0.o start.o main.o zlib.o imagesize.o image.o
obj-boot := $(addprefix $(obj)/,$(obj-boot))
OBJS := $(addprefix $(obj)/,$(OBJS))
targets += $(obj-boot) $(addprefix $(obj)/,image.c image.o)
src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c
src-boot := $(addprefix $(obj)/, $(src-boot))
obj-boot := $(addsuffix .o, $(basename $(src-boot)))
quiet_cmd_bootcc = BOOTCC $@
cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
$(obj-boot): %.o: %.c FORCE
$(call if_changed_dep,bootcc)
quiet_cmd_bootas = BOOTAS $@
cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -traditional \
-c -o $@ $<
$(obj)/crt0.o: %.o: %.S FORCE
cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
$(call if_changed_dep,bootcc)
$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
$(call if_changed_dep,bootas)
host-progs := piggyback addnote addSystemMap addRamDisk
HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE)
EXTRA_TARGETS += zImage zImage.initrd vmlinux.bin vmlinux.gz \
#-----------------------------------------------------------
# ELF sections within the zImage bootloader/wrapper
#-----------------------------------------------------------
required := vmlinux .config System.map
initrd := initrd
obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
host-progs := piggy addnote addSystemMap addRamDisk
EXTRA_TARGETS += zImage zImage.initrd imagesize.c \
$(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
$(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
$(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
vmlinux.sm vmlinux.initrd vmlinux.sminitrd \
sysmap.o initrd.o
......@@ -69,42 +79,48 @@ $(obj)/vmlinux.initrd: vmlinux $(obj)/addRamDisk $(obj)/ramdisk.image.gz System.
$(obj)/vmlinux.sminitrd: $(obj)/vmlinux.sm $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
$(call if_changed,ramdisk)
$(obj)/sysmap.o: System.map $(obj)/piggyback
$(call if_changed,piggy)
addsection = $(BOOTOBJCOPY) $(1) \
--add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(patsubst %.o,%.gz, $(1)) \
--set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(OBJCOPYFLAGS)
quiet_cmd_addnote = ADDNOTE $@
cmd_addnote = $(BOOTLD) $(BOOTLFLAGS) -o $@ $(obj-boot) && $(obj)/addnote $@
quiet_cmd_piggy = PIGGY $@
cmd_piggy = $(obj)/piggyback $(@:.o=) < $< | $(BOOTAS) -o $@
$(obj)/image.o: $(obj)/vmlinux.gz $(obj)/piggyback FORCE
$(call if_changed,piggy)
$(call gz-sec, $(required)): $(obj)/kernel-%.gz: %
$(call if_changed,gzip)
$(obj)/sysmap.o: System.map $(obj)/piggyback FORCE
$(call if_changed,piggy)
$(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
cp -f $(obj)/ramdisk.image.gz $@
$(obj)/initrd.o: $(obj)/ramdisk.image.gz $(obj)/piggyback FORCE
$(call if_changed,piggy)
$(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz
touch $@
quiet_cmd_addnote = ADDNOTE $@
cmd_addnote = $(BOOTLD) $(LD_ARGS) -T $(obj)/zImage.lds -o $@ $(OBJS) $<\
&& $(obj)/addnote $@
$(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c
$(call if_changed_dep,bootcc)
$(call addsection, $@)
$(obj)/zImage: $(obj)/no_initrd.o $(OBJS) $(obj)/addnote FORCE
$(obj)/zImage: obj-boot += $(call obj-sec, $(required))
$(obj)/zImage: $(call obj-sec, $(required)) $(obj-boot) $(obj)/addnote FORCE
$(call if_changed,addnote)
$(obj)/zImage.initrd: $(obj)/initrd.o $(OBJS) $(obj)/addnote FORCE
$(obj)/zImage.initrd: obj-boot += $(call obj-sec, $(required) $(initrd))
$(obj)/zImage.initrd: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(obj)/addnote FORCE
$(call if_changed,addnote)
$(obj)/vmlinux.bin: vmlinux FORCE
$(call if_changed,objcopy)
$(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
$(call if_changed,gzip)
$(obj)/imagesize.c: vmlinux
@echo Generating $@
ls -l vmlinux | \
awk '{printf "/* generated -- do not edit! */\n" \
"int uncompressed_size = %d;\n", $$5}' > $(obj)/imagesize.c
"unsigned long vmlinux_filesize = %d;\n", $$5}' > $(obj)/imagesize.c
$(CROSS_COMPILE)nm -n vmlinux | tail -1 | \
awk '{printf "long vmlinux_end = 0x%s;\n", substr($$1,8)}' \
awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' \
>> $(obj)/imagesize.c
clean-files := $(targets)
clean-files := $(patsubst $(obj)/%,%, $(obj-boot))
To extract the kernel vmlinux, System.map, .config or initrd from the zImage binary:
objcopy -j .kernel:vmlinux -O binary zImage vmlinux.gz
objcopy -j .kernel:System.map -O binary zImage System.map.gz
objcopy -j .kernel:.config -O binary zImage config.gz
objcopy -j .kernel:initrd -O binary zImage.initrd initrd.gz
Peter
......@@ -25,7 +25,7 @@ void put4k(FILE *file, char *buf )
void death(const char *msg, FILE *fdesc, const char *fname)
{
printf(msg);
fprintf(stderr, msg);
fclose(fdesc);
unlink(fname);
exit(1);
......@@ -66,47 +66,47 @@ int main(int argc, char **argv)
if (argc < 2) {
printf("Name of RAM disk file missing.\n");
fprintf(stderr, "Name of RAM disk file missing.\n");
exit(1);
}
if (argc < 3) {
printf("Name of System Map input file is missing.\n");
fprintf(stderr, "Name of System Map input file is missing.\n");
exit(1);
}
if (argc < 4) {
printf("Name of vmlinux file missing.\n");
fprintf(stderr, "Name of vmlinux file missing.\n");
exit(1);
}
if (argc < 5) {
printf("Name of vmlinux output file missing.\n");
fprintf(stderr, "Name of vmlinux output file missing.\n");
exit(1);
}
ramDisk = fopen(argv[1], "r");
if ( ! ramDisk ) {
printf("RAM disk file \"%s\" failed to open.\n", argv[1]);
fprintf(stderr, "RAM disk file \"%s\" failed to open.\n", argv[1]);
exit(1);
}
sysmap = fopen(argv[2], "r");
if ( ! sysmap ) {
printf("System Map file \"%s\" failed to open.\n", argv[2]);
fprintf(stderr, "System Map file \"%s\" failed to open.\n", argv[2]);
exit(1);
}
inputVmlinux = fopen(argv[3], "r");
if ( ! inputVmlinux ) {
printf("vmlinux file \"%s\" failed to open.\n", argv[3]);
fprintf(stderr, "vmlinux file \"%s\" failed to open.\n", argv[3]);
exit(1);
}
outputVmlinux = fopen(argv[4], "w+");
if ( ! outputVmlinux ) {
printf("output vmlinux file \"%s\" failed to open.\n", argv[4]);
fprintf(stderr, "output vmlinux file \"%s\" failed to open.\n", argv[4]);
exit(1);
}
......@@ -118,7 +118,7 @@ int main(int argc, char **argv)
fseek(inputVmlinux, 0, SEEK_SET);
printf("kernel file size = %d\n", kernelLen);
if ( kernelLen == 0 ) {
printf("You must have a linux kernel specified as argv[3]\n");
fprintf(stderr, "You must have a linux kernel specified as argv[3]\n");
exit(1);
}
......@@ -154,15 +154,14 @@ int main(int argc, char **argv)
/* Process the Sysmap file to determine where _end is */
sysmapPages = sysmapLen / 4096;
for (i=0; i<sysmapPages; ++i) {
get4k(sysmap, inbuf);
}
/* read the whole file line by line, expect that it doesnt fail */
while ( fgets(inbuf, 4096, sysmap) ) ;
/* search for _end in the last page of the system map */
ptr_end = strstr(inbuf, " _end");
if (!ptr_end) {
printf("Unable to find _end in the sysmap file \n");
printf("inbuf: \n");
printf("%s \n", inbuf);
fprintf(stderr, "Unable to find _end in the sysmap file \n");
fprintf(stderr, "inbuf: \n");
fprintf(stderr, "%s \n", inbuf);
exit(1);
}
printf("Found _end in the last page of the sysmap - backing up 10 characters it looks like %s", ptr_end-10);
......
......@@ -64,38 +64,38 @@ int main(int argc, char **argv)
long padPages = 0;
if ( argc < 2 )
{
printf("Name of System Map file missing.\n");
fprintf(stderr, "Name of System Map file missing.\n");
exit(1);
}
if ( argc < 3 )
{
printf("Name of vmlinux file missing.\n");
fprintf(stderr, "Name of vmlinux file missing.\n");
exit(1);
}
if ( argc < 4 )
{
printf("Name of vmlinux output file missing.\n");
fprintf(stderr, "Name of vmlinux output file missing.\n");
exit(1);
}
sysmap = fopen(argv[1], "r");
if ( ! sysmap )
{
printf("System Map file \"%s\" failed to open.\n", argv[1]);
fprintf(stderr, "System Map file \"%s\" failed to open.\n", argv[1]);
exit(1);
}
inputVmlinux = fopen(argv[2], "r");
if ( ! inputVmlinux )
{
printf("vmlinux file \"%s\" failed to open.\n", argv[2]);
fprintf(stderr, "vmlinux file \"%s\" failed to open.\n", argv[2]);
exit(1);
}
outputVmlinux = fopen(argv[3], "w");
if ( ! outputVmlinux )
{
printf("output vmlinux file \"%s\" failed to open.\n", argv[3]);
fprintf(stderr, "output vmlinux file \"%s\" failed to open.\n", argv[3]);
exit(1);
}
......@@ -107,7 +107,7 @@ int main(int argc, char **argv)
printf("kernel file size = %ld\n", kernelLen);
if ( kernelLen == 0 )
{
printf("You must have a linux kernel specified as argv[2]\n");
fprintf(stderr, "You must have a linux kernel specified as argv[2]\n");
exit(1);
}
......@@ -146,17 +146,15 @@ int main(int argc, char **argv)
/* Process the Sysmap file to determine the true end of the kernel */
sysmapPages = sysmapLen / 4096;
printf("System map pages to copy = %ld\n", sysmapPages);
for (i=0; i<sysmapPages; ++i)
{
get4k(sysmap, inbuf);
}
/* read the whole file line by line, expect that it doesnt fail */
while ( fgets(inbuf, 4096, sysmap) ) ;
/* search for _end in the last page of the system map */
ptr_end = strstr(inbuf, " _end");
if (!ptr_end)
{
printf("Unable to find _end in the sysmap file \n");
printf("inbuf: \n");
printf("%s \n", inbuf);
fprintf(stderr, "Unable to find _end in the sysmap file \n");
fprintf(stderr, "inbuf: \n");
fprintf(stderr, "%s \n", inbuf);
exit(1);
}
printf("Found _end in the last page of the sysmap - backing up 10 characters it looks like %s", ptr_end-10);
......
......@@ -8,258 +8,41 @@
*
* NOTE: this code runs in 32 bit mode and is packaged as ELF32.
*/
#include <asm/ppc_asm.h>
.text
.globl _start
_start:
lis 9,_start@h
lis 8,_etext@ha
addi 8,8,_etext@l
1: dcbf 0,9
icbi 0,9
addi 9,9,0x20
cmplwi 0,9,8
lis r9,_start@h
lis r8,_etext@ha
addi r8,r8,_etext@l
1: dcbf r0,r9
icbi r0,r9
addi r9,r9,0x20
cmplwi 0,r9,8
blt 1b
sync
isync
## Clear out the BSS as per ANSI C requirements
lis 7,_end@ha
addi 7,7,_end@l # r7 = &_end
lis 8,__bss_start@ha #
addi 8,8,__bss_start@l # r8 = &_bss_start
lis r7,_end@ha
addi r7,r7,_end@l # r7 = &_end
lis r8,__bss_start@ha #
addi r8,r8,__bss_start@l # r8 = &_bss_start
## Determine how large an area, in number of words, to clear
subf 7,8,7 # r7 = &_end - &_bss_start + 1
addi 7,7,3 # r7 += 3
srwi. 7,7,2 # r7 = size in words.
beq 3f # If the size is zero, do not bother
addi 8,8,-4 # r8 -= 4
mtctr 7 # SPRN_CTR = number of words to clear
li 0,0 # r0 = 0
2: stwu 0,4(8) # Clear out a word
bdnz 2b # If we are not done yet, keep clearing
subf r7,r8,r7 # r7 = &_end - &_bss_start + 1
addi r7,r7,3 # r7 += 3
srwi. r7,r7,2 # r7 = size in words.
beq 3f # If the size is zero, don't bother
addi r8,r8,-4 # r8 -= 4
mtctr r7 # SPRN_CTR = number of words to clear
li r0,0 # r0 = 0
2: stwu r0,4(r8) # Clear out a word
bdnz 2b # Keep clearing until done
3:
b start
/*
* 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
#define r0 0
#define r3 3
#define r4 4
#define r5 5
#define r6 6
#define r7 7
#define r8 8
.globl strcpy
strcpy:
addi r5,r3,-1
addi r4,r4,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
stbu r0,1(r5)
bne 1b
blr
.globl strncpy
strncpy:
cmpwi 0,r5,0
beqlr
mtctr r5
addi r6,r3,-1
addi r4,r4,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
stbu r0,1(r6)
bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
blr
.globl strcat
strcat:
addi r5,r3,-1
addi r4,r4,-1
1: lbzu r0,1(r5)
cmpwi 0,r0,0
bne 1b
addi r5,r5,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
stbu r0,1(r5)
bne 1b
blr
.globl strcmp
strcmp:
addi r5,r3,-1
addi r4,r4,-1
1: lbzu r3,1(r5)
cmpwi 1,r3,0
lbzu r0,1(r4)
subf. r3,r0,r3
beqlr 1
beq 1b
blr
.globl strlen
strlen:
addi r4,r3,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
bne 1b
subf r3,r3,r4
blr
.globl memset
memset:
rlwimi r4,r4,8,16,23
rlwimi r4,r4,16,0,15
addi r6,r3,-4
cmplwi 0,r5,4
blt 7f
stwu r4,4(r6)
beqlr
andi. r0,r6,3
add r5,r0,r5
subf r6,r0,r6
rlwinm r0,r5,32-2,2,31
mtctr r0
bdz 6f
1: stwu r4,4(r6)
bdnz 1b
6: andi. r5,r5,3
7: cmpwi 0,r5,0
beqlr
mtctr r5
addi r6,r6,3
8: stbu r4,1(r6)
bdnz 8b
blr
.globl bcopy
bcopy:
mr r6,r3
mr r3,r4
mr r4,r6
b memcpy
.globl memmove
memmove:
cmplw 0,r3,r4
bgt backwards_memcpy
/* fall through */
.globl memcpy
memcpy:
rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
addi r6,r3,-4
addi r4,r4,-4
beq 2f /* if less than 8 bytes to do */
andi. r0,r6,3 /* get dest word aligned */
mtctr r7
bne 5f
1: lwz r7,4(r4)
lwzu r8,8(r4)
stw r7,4(r6)
stwu r8,8(r6)
bdnz 1b
andi. r5,r5,7
2: cmplwi 0,r5,4
blt 3f
lwzu r0,4(r4)
addi r5,r5,-4
stwu r0,4(r6)
3: cmpwi 0,r5,0
beqlr
mtctr r5
addi r4,r4,3
addi r6,r6,3
4: lbzu r0,1(r4)
stbu r0,1(r6)
bdnz 4b
blr
5: subfic r0,r0,4
mtctr r0
6: lbz r7,4(r4)
addi r4,r4,1
stb r7,4(r6)
addi r6,r6,1
bdnz 6b
subf r5,r0,r5
rlwinm. r7,r5,32-3,3,31
beq 2b
mtctr r7
b 1b
.globl backwards_memcpy
backwards_memcpy:
rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
add r6,r3,r5
add r4,r4,r5
beq 2f
andi. r0,r6,3
mtctr r7
bne 5f
1: lwz r7,-4(r4)
lwzu r8,-8(r4)
stw r7,-4(r6)
stwu r8,-8(r6)
bdnz 1b
andi. r5,r5,7
2: cmplwi 0,r5,4
blt 3f
lwzu r0,-4(r4)
subi r5,r5,4
stwu r0,-4(r6)
3: cmpwi 0,r5,0
beqlr
mtctr r5
4: lbzu r0,-1(r4)
stbu r0,-1(r6)
bdnz 4b
blr
5: mtctr r0
6: lbzu r7,-1(r4)
stbu r7,-1(r6)
bdnz 6b
subf r5,r0,r5
rlwinm. r7,r5,32-3,3,31
beq 2b
mtctr r7
b 1b
.globl memcmp
memcmp:
cmpwi 0,r5,0
blelr
mtctr r5
addi r6,r3,-1
addi r4,r4,-1
1: lbzu r3,1(r6)
lbzu r0,1(r4)
subf. r3,r0,r3
bdnzt 2,1b
blr
/*
* Copyright (C) Paul Mackerras 1997.
*
* Updates for PPC64 by Todd Inglett & Dave Engebretsen.
* Updates for PPC64 by Todd Inglett, Dave Engebretsen & Peter Bergner.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -9,31 +9,31 @@
* 2 of the License, or (at your option) any later version.
*/
#define __KERNEL__
#include "ppc32-types.h"
#include "zlib.h"
#include <linux/elf.h>
#include <asm/processor.h>
#include <asm/page.h>
#include <asm/bootinfo.h>
#undef DEBUG
void memmove(void *dst, void *im, int len);
extern void *finddevice(const char *);
extern int getprop(void *, const char *, void *, int);
extern void printk(char *fmt, ...);
extern void printf(const char *fmt, ...);
extern int sprintf(char *buf, const char *fmt, ...);
void gunzip(void *, int, unsigned char *, int *);
void *claim(unsigned int, unsigned int, unsigned int);
void flush_cache(void *, int);
void flush_cache(void *, unsigned long);
void pause(void);
extern void exit(void);
static struct bi_record *make_bi_recs(unsigned long);
#define RAM_START 0x00000000
#define RAM_END (64<<20)
#define BOOT_START ((unsigned long)_start)
#define BOOT_END ((unsigned long)_end)
/* Value picked to match that used by yaboot */
#define PROG_START 0x01400000
......@@ -42,18 +42,26 @@ char *begin_avail, *end_avail;
char *avail_high;
unsigned int heap_use;
unsigned int heap_max;
unsigned long initrd_start = 0;
unsigned long initrd_size = 0;
extern char _end[];
extern char image_data[];
extern int image_len;
extern char initrd_data[];
extern int initrd_len;
extern char sysmap_data[];
extern int sysmap_len;
extern int uncompressed_size;
extern long vmlinux_end;
extern char _vmlinux_start[];
extern char _vmlinux_end[];
extern char _sysmap_start[];
extern char _sysmap_end[];
extern char _initrd_start[];
extern char _initrd_end[];
extern unsigned long vmlinux_filesize;
extern unsigned long vmlinux_memsize;
struct addr_range {
unsigned long addr;
unsigned long size;
unsigned long memsize;
};
struct addr_range vmlinux = {0, 0, 0};
struct addr_range vmlinuz = {0, 0, 0};
struct addr_range sysmap = {0, 0, 0};
struct addr_range initrd = {0, 0, 0};
static char scratch[128<<10]; /* 128kB of scratch space for gunzip */
......@@ -62,67 +70,126 @@ typedef void (*kernel_entry_t)( unsigned long,
void *,
struct bi_record *);
int (*prom)(void *);
void *chosen_handle;
void *stdin;
void *stdout;
void *stderr;
void
chrpboot(unsigned long a1, unsigned long a2, void *prom)
start(unsigned long a1, unsigned long a2, void *promptr)
{
unsigned len;
void *dst = (void *)-1;
unsigned long claim_addr;
unsigned char *im;
unsigned long i, claim_addr, claim_size;
extern char _start;
struct bi_record *bi_recs;
kernel_entry_t kernel_entry;
printf("chrpboot starting: loaded at 0x%x\n\r", (unsigned)&_start);
Elf64_Ehdr *elf64;
Elf64_Phdr *elf64ph;
if (initrd_len) {
initrd_size = initrd_len;
initrd_start = (RAM_END - initrd_size) & ~0xFFF;
prom = (int (*)(void *)) 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();
printf("zImage starting: loaded at 0x%x\n\r", (unsigned)&_start);
#if 0
sysmap.size = (unsigned long)(_sysmap_end - _sysmap_start);
sysmap.memsize = sysmap.size;
if ( sysmap.size > 0 ) {
sysmap.addr = (RAM_END - sysmap.size) & ~0xFFF;
claim(sysmap.addr, RAM_END - sysmap.addr, 0);
printf("initial ramdisk moving 0x%lx <- 0x%lx (%lx bytes)\n\r",
sysmap.addr, (unsigned long)_sysmap_start, sysmap.size);
memcpy((void *)sysmap.addr, (void *)_sysmap_start, sysmap.size);
}
#endif
initrd.size = (unsigned long)(_initrd_end - _initrd_start);
initrd.memsize = initrd.size;
if ( initrd.size > 0 ) {
initrd.addr = (RAM_END - initrd.size) & ~0xFFF;
a1 = a2 = 0;
claim(initrd_start, RAM_END - initrd_start, 0);
claim(initrd.addr, RAM_END - initrd.addr, 0);
printf("initial ramdisk moving 0x%lx <- 0x%lx (%lx bytes)\n\r",
initrd_start, (unsigned long)initrd_data, initrd_size);
memcpy((void *)initrd_start, (void *)initrd_data, initrd_size);
initrd.addr, (unsigned long)_initrd_start, initrd.size);
memcpy((void *)initrd.addr, (void *)_initrd_start, initrd.size);
}
im = image_data;
len = image_len;
uncompressed_size = PAGE_ALIGN(uncompressed_size);
vmlinuz.addr = (unsigned long)_vmlinux_start;
vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start);
vmlinux.addr = (unsigned long)(void *)-1;
vmlinux.size = PAGE_ALIGN(vmlinux_filesize);
vmlinux.memsize = vmlinux_memsize;
claim_size = vmlinux.memsize /* PPPBBB: + fudge for bi_recs */;
for(claim_addr = PROG_START;
claim_addr <= PROG_START * 8;
claim_addr += 0x100000) {
#ifdef DEBUG
printf(" trying: 0x%08lx\n\r", claim_addr);
#endif
dst = claim(claim_addr, uncompressed_size, 0);
if (dst != (void *)-1) break;
vmlinux.addr = (unsigned long)claim(claim_addr, claim_size, 0);
if ((void *)vmlinux.addr != (void *)-1) break;
}
if (dst == (void *)-1) {
if ((void *)vmlinux.addr == (void *)-1) {
printf("claim error, can't allocate kernel memory\n\r");
return;
exit();
}
if (im[0] == 0x1f && im[1] == 0x8b) {
/* PPPBBB: should kernel always be gziped? */
if (*(unsigned short *)vmlinuz.addr == 0x1f8b) {
avail_ram = scratch;
begin_avail = avail_high = avail_ram;
end_avail = scratch + sizeof(scratch);
printf("gunzipping (0x%x <- 0x%x:0x%0x)...",
(unsigned)dst, (unsigned)im, (unsigned)im+len);
gunzip(dst, uncompressed_size, im, &len);
printf("done %u bytes\n\r", len);
printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...",
vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
gunzip((void *)vmlinux.addr, vmlinux.size,
(unsigned char *)vmlinuz.addr, (int *)&vmlinuz.size);
printf("done %lu bytes\n\r", vmlinuz.size);
printf("%u bytes of heap consumed, max in use %u\n\r",
(unsigned)(avail_high - begin_avail), heap_max);
} else {
memmove(dst, im, len);
memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size);
}
/* Skip over the ELF header */
elf64 = (Elf64_Ehdr *)vmlinux.addr;
if ( elf64->e_ident[EI_MAG0] != ELFMAG0 ||
elf64->e_ident[EI_MAG1] != ELFMAG1 ||
elf64->e_ident[EI_MAG2] != ELFMAG2 ||
elf64->e_ident[EI_MAG3] != ELFMAG3 ||
elf64->e_ident[EI_CLASS] != ELFCLASS64 ||
elf64->e_ident[EI_DATA] != ELFDATA2MSB ||
elf64->e_type != ET_EXEC ||
elf64->e_machine != EM_PPC64 )
{
printf("Error: not a valid PPC64 ELF file!\n\r");
exit();
}
elf64ph = (Elf64_Phdr *)((unsigned long)elf64 +
(unsigned long)elf64->e_phoff);
for(i=0; i < (unsigned int)elf64->e_phnum ;i++,elf64ph++) {
if (elf64ph->p_type == PT_LOAD && elf64ph->p_offset != 0)
break;
}
printf("... skipping 0x%lx bytes of ELF header\n\r",
(unsigned long)elf64ph->p_offset);
vmlinux.addr += (unsigned long)elf64ph->p_offset;
vmlinux.size -= (unsigned long)elf64ph->p_offset;
flush_cache(dst, len);
flush_cache((void *)vmlinux.addr, vmlinux.memsize);
bi_recs = make_bi_recs((unsigned long)dst + vmlinux_end);
bi_recs = make_bi_recs(vmlinux.addr + vmlinux.memsize);
kernel_entry = (kernel_entry_t)dst;
#ifdef DEBUG
kernel_entry = (kernel_entry_t)vmlinux.addr;
printf( "kernel:\n\r"
" entry addr = 0x%lx\n\r"
" a1 = 0x%lx,\n\r"
......@@ -131,13 +198,12 @@ chrpboot(unsigned long a1, unsigned long a2, void *prom)
" bi_recs = 0x%lx,\n\r",
(unsigned long)kernel_entry, a1, a2,
(unsigned long)prom, (unsigned long)bi_recs);
#endif
kernel_entry( a1, a2, prom, bi_recs );
printf("returned?\n\r");
printf("Error: Linux kernel returned to zImage bootloader!\n\r");
pause();
exit();
}
static struct bi_record *
......@@ -162,21 +228,19 @@ make_bi_recs(unsigned long addr)
rec->data[0] = PLATFORM_PSERIES;
rec->data[1] = 1;
if ( initrd_size > 0 ) {
if ( initrd.size > 0 ) {
rec = bi_rec_alloc(rec, 2);
rec->tag = BI_INITRD;
rec->data[0] = initrd_start;
rec->data[1] = initrd_size;
rec->data[0] = initrd.addr;
rec->data[1] = initrd.size;
}
#if 0
if ( sysmap_len > 0 ) {
if ( sysmap.size > 0 ) {
rec = bi_rec_alloc(rec, 2);
rec->tag = BI_SYSMAP;
rec->data[0] = (unsigned long)sysmap_data;
rec->data[1] = sysmap_len;
rec->data[0] = (unsigned long)sysmap.addr;
rec->data[1] = (unsigned long)sysmap.size;
}
#endif
rec = bi_rec_alloc(rec, 1);
rec->tag = BI_LAST;
......
#ifndef _PPC64_TYPES_H
#define _PPC64_TYPES_H
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
typedef __signed__ long long __s64;
typedef unsigned long long __u64;
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;
typedef signed long long s64;
typedef unsigned long long u64;
#define BITS_PER_LONG 32
#endif /* _PPC64_TYPES_H */
This diff is collapsed.
/*
* 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.
*
* NOTE: this code runs in 32 bit mode and is packaged as ELF32.
*/
#include <asm/ppc_asm.h>
.text
.globl strcpy
strcpy:
addi r5,r3,-1
addi r4,r4,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
stbu r0,1(r5)
bne 1b
blr
.globl strncpy
strncpy:
cmpwi 0,r5,0
beqlr
mtctr r5
addi r6,r3,-1
addi r4,r4,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
stbu r0,1(r6)
bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
blr
.globl strcat
strcat:
addi r5,r3,-1
addi r4,r4,-1
1: lbzu r0,1(r5)
cmpwi 0,r0,0
bne 1b
addi r5,r5,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
stbu r0,1(r5)
bne 1b
blr
.globl strcmp
strcmp:
addi r5,r3,-1
addi r4,r4,-1
1: lbzu r3,1(r5)
cmpwi 1,r3,0
lbzu r0,1(r4)
subf. r3,r0,r3
beqlr 1
beq 1b
blr
.globl strlen
strlen:
addi r4,r3,-1
1: lbzu r0,1(r4)
cmpwi 0,r0,0
bne 1b
subf r3,r3,r4
blr
.globl memset
memset:
rlwimi r4,r4,8,16,23
rlwimi r4,r4,16,0,15
addi r6,r3,-4
cmplwi 0,r5,4
blt 7f
stwu r4,4(r6)
beqlr
andi. r0,r6,3
add r5,r0,r5
subf r6,r0,r6
rlwinm r0,r5,32-2,2,31
mtctr r0
bdz 6f
1: stwu r4,4(r6)
bdnz 1b
6: andi. r5,r5,3
7: cmpwi 0,r5,0
beqlr
mtctr r5
addi r6,r6,3
8: stbu r4,1(r6)
bdnz 8b
blr
.globl bcopy
bcopy:
mr r6,r3
mr r3,r4
mr r4,r6
b memcpy
.globl memmove
memmove:
cmplw 0,r3,r4
bgt backwards_memcpy
/* fall through */
.globl memcpy
memcpy:
rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
addi r6,r3,-4
addi r4,r4,-4
beq 2f /* if less than 8 bytes to do */
andi. r0,r6,3 /* get dest word aligned */
mtctr r7
bne 5f
1: lwz r7,4(r4)
lwzu r8,8(r4)
stw r7,4(r6)
stwu r8,8(r6)
bdnz 1b
andi. r5,r5,7
2: cmplwi 0,r5,4
blt 3f
lwzu r0,4(r4)
addi r5,r5,-4
stwu r0,4(r6)
3: cmpwi 0,r5,0
beqlr
mtctr r5
addi r4,r4,3
addi r6,r6,3
4: lbzu r0,1(r4)
stbu r0,1(r6)
bdnz 4b
blr
5: subfic r0,r0,4
mtctr r0
6: lbz r7,4(r4)
addi r4,r4,1
stb r7,4(r6)
addi r6,r6,1
bdnz 6b
subf r5,r0,r5
rlwinm. r7,r5,32-3,3,31
beq 2b
mtctr r7
b 1b
.globl backwards_memcpy
backwards_memcpy:
rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
add r6,r3,r5
add r4,r4,r5
beq 2f
andi. r0,r6,3
mtctr r7
bne 5f
1: lwz r7,-4(r4)
lwzu r8,-8(r4)
stw r7,-4(r6)
stwu r8,-8(r6)
bdnz 1b
andi. r5,r5,7
2: cmplwi 0,r5,4
blt 3f
lwzu r0,-4(r4)
subi r5,r5,4
stwu r0,-4(r6)
3: cmpwi 0,r5,0
beqlr
mtctr r5
4: lbzu r0,-1(r4)
stbu r0,-1(r6)
bdnz 4b
blr
5: mtctr r0
6: lbzu r7,-1(r4)
stbu r7,-1(r6)
bdnz 6b
subf r5,r0,r5
rlwinm. r7,r5,32-3,3,31
beq 2b
mtctr r7
b 1b
.globl memcmp
memcmp:
cmpwi 0,r5,0
blelr
mtctr r5
addi r6,r3,-1
addi r4,r4,-1
1: lbzu r3,1(r6)
lbzu r0,1(r4)
subf. r3,r0,r3
bdnzt 2,1b
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
......@@ -58,6 +58,27 @@ SECTIONS
*(.dynamic)
CONSTRUCTORS
}
. = ALIGN(4096);
_vmlinux_start = .;
.kernel:vmlinux : { *(.kernel:vmlinux) }
_vmlinux_end = .;
. = ALIGN(4096);
_dotconfig_start = .;
.kernel:.config : { *(.kernel:.config) }
_dotconfig_end = .;
. = ALIGN(4096);
_sysmap_start = .;
.kernel:System.map : { *(.kernel:System.map) }
_sysmap_end = .;
. = ALIGN(4096);
_initrd_start = .;
.kernel:initrd : { *(.kernel:initrd) }
_initrd_end = .;
. = ALIGN(4096);
_edata = .;
PROVIDE (edata = .);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment