Re: Moving kernel_entry to LOADADDR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 18, 2001 at 07:58:58PM -0500, Gerald Champagne wrote:
> I'm planning to work with a very minimal boot loader, and I'd like
> to hard-code a jump to kernel_entry in my boot loader.  I got tired
> of having kernel_entry moving around, so I just moved it to the top
> of head.S, just afte the ".fill 0x280".  That places kernel_entry at
> the same place every time.  It's always at LOADADDR+0x280.

Dont do this - Its easy to decode the elf stuff:

Basically this is the code needed to relocate the elf chunks
and return the entry point. I might have corrupted it a bit due to stripping
unneeded bits but you will get the point. This code even clears bss
chunk which the kernel will do itself again.


	Elf32_Ehdr	*fhdr = fb;
	Elf32_Shdr	*shdr;	
	int		i;

	if (fhdr->e_machine != EM_MIPS) {
		printf("No Mips ELF\n");
		return(0);	
	}

	fhdr=(void *) KSEG1ADDR(fb);

	shdr=fb + fhdr->e_shoff;

	for(i=0;i<fhdr->e_shnum;i++,shdr++) {

		if (shdr->sh_size <= 0) 
			continue;

		if (shdr->sh_type == SHT_PROGBITS) {
			memcpy((void *) KSEG1ADDR(shdr->sh_addr),
				KSEG1ADDR(fb + shdr->sh_offset),
				shdr->sh_size);
		} else if (shdr->sh_type == SHT_NOBITS) {
			memset((void *) KSEG1ADDR(shdr->sh_addr), 0x0, shdr->sh_size);
		}
	}
	return((void *) fhdr->e_entry);

-- 
Florian Lohoff                  flo@rfc822.org             +49-5201-669912
Nine nineth on september the 9th              Welcome to the new billenium

PGP signature


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux