linux-mips
[Top] [All Lists]

Re: Moving kernel_entry to LOADADDR

To: Gerald Champagne <gerald.champagne@esstech.com>
Subject: Re: Moving kernel_entry to LOADADDR
From: Florian Lohoff <flo@rfc822.org>
Date: Wed, 24 Oct 2001 13:16:11 +0200
Cc: "linux-mips@oss.sgi.com" <linux-mips@oss.sgi.com>
In-reply-to: <3BCF7AD2.2000000@esstech.com>
Organization: rfc822 - pure communication
References: <3BCF7AD2.2000000@esstech.com>
Sender: owner-linux-mips@oss.sgi.com
User-agent: Mutt/1.3.23i
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

Attachment: pgptQg8YwS6F0.pgp
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>