Initial commit

This commit is contained in:
Bahadir Balban
2008-01-13 13:53:52 +00:00
commit e2b791a3d8
789 changed files with 95825 additions and 0 deletions

51
loader/SConstruct Normal file
View File

@@ -0,0 +1,51 @@
Import("*")
import os
import glob
from os.path import join
arch = 'arm'
clibvariant = 'baremetal'
# C library information
clibroot = join(os.getcwd(), '../libs/c')
clibpath = join(join(clibroot, 'build'), clibvariant)
cincpath = [join(clibroot, 'include'), join(clibroot,'include/arch/%s' % arch)]
crt0objpath = join(clibroot, 'build/crt/sys-%s/arch-%s/crt0.o' % (clibvariant, arch))
clibname = "c-" + clibvariant
# Elf library information
elflibpath = os.getcwd() + '/../libs/elf'
elfincpath = [elflibpath + '/include']
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding'],
LINKFLAGS = ['-nostdlib', '-Tmylink.lds'],
ENV = {'PATH' : os.environ['PATH']},
PROGSUFFIX = '.axf',
LIBS = ['elf', clibname, 'gcc', clibname], # Note there's a dependency order here.
# Left libs depend on libs on their right.
CPPPATH = ['#'] + cincpath + elfincpath)
env.Append(LIBPATH = [clibpath, elflibpath])
def src_glob(search):
"""Src glob is used to find source files easily e.g: src_glob("src/*.c"),
the reason we can't just use glob is due to the way SCons handles out
of directory builds."""
dir = os.path.dirname(search)
if dir != "":
dir = dir + os.sep
src_path = Dir('.').srcnode().abspath
files = glob.glob(src_path + os.sep + search)
files = map(os.path.basename, files)
ret_files = []
for file in files:
ret_files.append(dir + file)
return ret_files
src = src_glob("*.c")
src += src_glob("*.S")
obj_list = env.Object(src)
loader = env.Program("final", obj_list + [crt0objpath])

108
loader/arch.c Normal file
View File

@@ -0,0 +1,108 @@
/*******************************************************************************
* Filename: src/arch-arm/arch.c *
* Description: Elf-loader - ELF file kernel/application bootstraper, source *
* file defining the architecture specific functions for the Alpha *
* architecture. *
* Authors: Sergio Ruocco <sruocco@cse.unsw.edu.au>. *
********************************************************************************
* *
* Australian Public Licence B (OZPLB) *
* *
* Version 1-0 *
* *
* Copyright (c) 2005 University of New South Wales, Australia *
* *
* All rights reserved. *
* *
* Developed by: Operating Systems, Embedded and *
* Distributed Systems Group (DiSy) *
* University of New South Wales *
* http://www.disy.cse.unsw.edu.au *
* *
* Permission is granted by University of New South Wales, free of charge, to *
* any person obtaining a copy of this software and any associated *
* documentation files (the "Software") to deal with the Software without *
* restriction, including (without limitation) the rights to use, copy, *
* modify, adapt, merge, publish, distribute, communicate to the public, *
* sublicense, and/or sell, lend or rent out copies of the Software, and *
* to permit persons to whom the Software is furnished to do so, subject *
* to the following conditions: *
* *
* * Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimers. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the following *
* disclaimers in the documentation and/or other materials provided *
* with the distribution. *
* *
* * Neither the name of University of New South Wales, nor the names of *
* its contributors, may be used to endorse or promote products derived *
* from this Software without specific prior written permission. *
* *
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT *
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND *
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS, *
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING *
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS *
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE, *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, *
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF *
* ERRORS, WHETHER OR NOT DISCOVERABLE. *
* *
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL *
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL *
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT, *
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER *
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR *
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS *
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR *
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, *
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN *
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER *
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS *
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS, *
* DAMAGES OR OTHER LIABILITY. *
* *
* If applicable legislation implies representations, warranties, or *
* conditions, or imposes obligations or liability on University of New South *
* Wales or one of its contributors in respect of the Software that *
* cannot be wholly or partly excluded, restricted or modified, the *
* liability of University of New South Wales or the contributor is limited, to *
* the full extent permitted by the applicable legislation, at its *
* option, to: *
* a. in the case of goods, any one or more of the following: *
* i. the replacement of the goods or the supply of equivalent goods; *
* ii. the repair of the goods; *
* iii. the payment of the cost of replacing the goods or of acquiring *
* equivalent goods; *
* iv. the payment of the cost of having the goods repaired; or *
* b. in the case of services: *
* i. the supplying of the services again; or *
* ii. the payment of the cost of having the services supplied again. *
* *
* The construction, validity and performance of this licence is governed *
* by the laws in force in New South Wales, Australia. *
* *
*******************************************************************************/
#include "arch.h"
#include <stdio.h>
void
arch_init(void)
{
/** awiggins (2005-05-29): As yet ARM arch doesn't require
* any initialisation.
*/
}
void
arch_start_kernel(void* entry)
{
printf("elf-loader:\tStarting kernel\n\r");
// ((void(*)(uint32_t))entry)(0);
void (*func)(unsigned long) = (void (*)(unsigned long)) (entry);
func(0);
}

112
loader/arch.h Normal file
View File

@@ -0,0 +1,112 @@
/*******************************************************************************
* Filename: src/main.c *
* Description: Elf-loader - ELF file kernel/application bootstraper, header *
* file defining the architecture specific functions required. *
* Authors: Adam 'WeirdArms' Wiggins <awiggins@cse.unsw.edu.au>. *
* Created: 2004-12-01 *
********************************************************************************
* *
* Australian Public Licence B (OZPLB) *
* *
* Version 1-0 *
* *
* Copyright (c) 2004 - 2005 University of New South Wales, Australia *
* *
* All rights reserved. *
* *
* Developed by: Operating Systems, Embedded and *
* Distributed Systems Group (DiSy) *
* University of New South Wales *
* http://www.disy.cse.unsw.edu.au *
* *
* Permission is granted by University of New South Wales, free of charge, to *
* any person obtaining a copy of this software and any associated *
* documentation files (the "Software") to deal with the Software without *
* restriction, including (without limitation) the rights to use, copy, *
* modify, adapt, merge, publish, distribute, communicate to the public, *
* sublicense, and/or sell, lend or rent out copies of the Software, and *
* to permit persons to whom the Software is furnished to do so, subject *
* to the following conditions: *
* *
* * Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimers. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the following *
* disclaimers in the documentation and/or other materials provided *
* with the distribution. *
* *
* * Neither the name of University of New South Wales, nor the names of *
* its contributors, may be used to endorse or promote products derived *
* from this Software without specific prior written permission. *
* *
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT *
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND *
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS, *
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING *
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS *
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE, *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, *
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF *
* ERRORS, WHETHER OR NOT DISCOVERABLE. *
* *
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL *
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL *
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT, *
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER *
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR *
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS *
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR *
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, *
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN *
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER *
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS *
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS, *
* DAMAGES OR OTHER LIABILITY. *
* *
* If applicable legislation implies representations, warranties, or *
* conditions, or imposes obligations or liability on University of New South *
* Wales or one of its contributors in respect of the Software that *
* cannot be wholly or partly excluded, restricted or modified, the *
* liability of University of New South Wales or the contributor is limited, to *
* the full extent permitted by the applicable legislation, at its *
* option, to: *
* a. in the case of goods, any one or more of the following: *
* i. the replacement of the goods or the supply of equivalent goods; *
* ii. the repair of the goods; *
* iii. the payment of the cost of replacing the goods or of acquiring *
* equivalent goods; *
* iv. the payment of the cost of having the goods repaired; or *
* b. in the case of services: *
* i. the supplying of the services again; or *
* ii. the payment of the cost of having the services supplied again. *
* *
* The construction, validity and performance of this licence is governed *
* by the laws in force in New South Wales, Australia. *
* *
*******************************************************************************/
/** It is assumed that the either the boot loader or the baremetal
* crt0.S has initialised the whatever console provides printf based
* output.
*/
/** arch_init() This function conducts architecture specific
* initialisation of the machine to prep it for loading of the kernel
* and application images from the dite generated elf file.
*/
void arch_init(void);
/** arch_start_kernel() This function carries out any architecture
* specific post-image-loading initialisation and jumps to the
* kernel's entry point.
*
* entry - The entry point of the kernel,
*/
void arch_start_kernel(void* entry);
#ifdef __PPC64__
#include <elf/elf.h>
int arch_claim_memory(struct Elf32_Header*);
#endif

25
loader/kernel.S Normal file
View File

@@ -0,0 +1,25 @@
/* This file defines kernel symbols extracted from the kernel image in their physical address */
.include "start.axf.S"
.section .kernel
.incbin "start.axf"
.align 4
.section .mm0
.incbin "mm0.axf"
.align 4
.section .bootdesc
.incbin "bootdesc.axf"
.section .fs0
.incbin "fs0.axf"
.align 4
.section .test0
.incbin "test0.axf"
.align 4

191
loader/main.c Normal file
View File

@@ -0,0 +1,191 @@
/*******************************************************************************
* Filename: src/main.c *
* Description: Elf-loader - ELF file kernel/application bootstraper, main *
* source file. *
* Authors: Adam 'WeirdArms' Wiggins <awiggins@cse.unsw.edu.au>. *
* Created: 2004-12-01 *
********************************************************************************
* *
* Australian Public Licence B (OZPLB) *
* *
* Version 1-0 *
* *
* Copyright (c) 2004 - 2005 University of New South Wales, Australia *
* *
* All rights reserved. *
* *
* Developed by: Operating Systems, Embedded and *
* Distributed Systems Group (DiSy) *
* University of New South Wales *
* http://www.disy.cse.unsw.edu.au *
* *
* Permission is granted by University of New South Wales, free of charge, to *
* any person obtaining a copy of this software and any associated *
* documentation files (the "Software") to deal with the Software without *
* restriction, including (without limitation) the rights to use, copy, *
* modify, adapt, merge, publish, distribute, communicate to the public, *
* sublicense, and/or sell, lend or rent out copies of the Software, and *
* to permit persons to whom the Software is furnished to do so, subject *
* to the following conditions: *
* *
* * Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimers. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the following *
* disclaimers in the documentation and/or other materials provided *
* with the distribution. *
* *
* * Neither the name of University of New South Wales, nor the names of *
* its contributors, may be used to endorse or promote products derived *
* from this Software without specific prior written permission. *
* *
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT *
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND *
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS, *
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING *
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS *
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE, *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, *
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF *
* ERRORS, WHETHER OR NOT DISCOVERABLE. *
* *
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL *
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL *
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT, *
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER *
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR *
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS *
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR *
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, *
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN *
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER *
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS *
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS, *
* DAMAGES OR OTHER LIABILITY. *
* *
* If applicable legislation implies representations, warranties, or *
* conditions, or imposes obligations or liability on University of New South *
* Wales or one of its contributors in respect of the Software that *
* cannot be wholly or partly excluded, restricted or modified, the *
* liability of University of New South Wales or the contributor is limited, to *
* the full extent permitted by the applicable legislation, at its *
* option, to: *
* a. in the case of goods, any one or more of the following: *
* i. the replacement of the goods or the supply of equivalent goods; *
* ii. the repair of the goods; *
* iii. the payment of the cost of replacing the goods or of acquiring *
* equivalent goods; *
* iv. the payment of the cost of having the goods repaired; or *
* b. in the case of services: *
* i. the supplying of the services again; or *
* ii. the payment of the cost of having the services supplied again. *
* *
* The construction, validity and performance of this licence is governed *
* by the laws in force in New South Wales, Australia. *
* *
*******************************************************************************/
#include <elf/elf.h>
#include <stdio.h>
#include <stdlib.h>
#include "arch.h"
/*****************
* Extern symbols *
*****************/
/* These symbols are defined by the linker scripts. */
extern char _start_kernel[];
extern char _end_kernel[];
extern char _start_mm0[];
extern char _end_mm0[];
extern char _start_fs0[];
extern char _end_fs0[];
extern char _start_test0[];
extern char _end_test0[];
extern char _start_bootdesc[];
extern char _end_bootdesc[];
/* This is a kernel symbol exported to loader's linker script from kernel build */
extern char bkpt_phys_to_virt[];
/*****************************
* Local function prototypes. *
*****************************/
static void load_image(void **entry, char *start, char *end);
int
main(void)
{
void *kernel_entry = NULL;
void *mm0_entry = NULL;
void *fs0_entry = NULL;
void *test0_entry = NULL;
void *bootdesc_entry = NULL;
arch_init();
printf("elf-loader:\tStarted\n");
printf("Loading the kernel...\n");
load_image(&kernel_entry, _start_kernel, _end_kernel);
printf("Loading the inittask\n");
load_image(&mm0_entry, _start_mm0, _end_mm0);
printf("Loading the roottask\n");
load_image(&fs0_entry, _start_fs0, _end_fs0);
printf("Loading the testtask\n");
load_image(&test0_entry, _start_test0, _end_test0);
printf("Loading the bootdesc\n");
load_image(&bootdesc_entry, _start_bootdesc, _end_bootdesc);
printf("elf-loader:\tkernel entry point is %p\n", kernel_entry);
arch_start_kernel(kernel_entry);
printf("elf-loader:\tKernel start failed!\n");
return -1;
}
/*******************
* Local functions. *
*******************/
static void
load_image(void** entry, char *start, char *end)
{
if(start == end) {
printf("elf-loader: error, dite image is empty!\n");
return;
}
/* awiggins (2004-12-21): Should probably add an alignment check? */
/** awiggins (2005-05-29): Probably should add checks to see
* the correct kind of elf file is being loaded for the platform,
* or does the elf library do that somewhere?.
*/
if(!elf32_checkFile((struct Elf32_Header*)start)) {
// printf("32-bit elf image detected.\n");
*entry = (void*)(uintptr_t)
elf32_getEntryPoint((struct Elf32_Header*)start);
printf("Entry point: %p\n", *entry);
} else if(!elf64_checkFile((struct Elf64_Header*)start)) {
*entry =
(void*)(uintptr_t)elf64_getEntryPoint((struct Elf64_Header*)start);
} else {
printf("elf-loader: error, dite image not a valid elf file!\n");
return;
}
#ifdef __PPC64__
if (arch_claim_memory((struct Elf32_Header*)start)) {
printf("could not claim memory for elf file!\n");
return;
}
#endif
//printf("Start: %p\n", start);
//printf("End: %p\n", end);
if(!elf_loadFile(start, true)) {
printf("elf-loader: error, unable to load dite image!\n");
return;
}
}

35
loader/mylink.lds Normal file
View File

@@ -0,0 +1,35 @@
/*
* Simple linker script for userspace or svc tasks.
*
* Copyright (C) 2007 Bahadir Balban
*/
ENTRY(_start)
SECTIONS
{
. = 0x8000;
.text : { *(.text) }
.rodata : { *(.rodata) }
.rodata1 : { *(.rodata1) }
.data :
{
_start_kernel = .;
*(.kernel)
_end_kernel = .;
_start_mm0 = .;
*(.mm0)
_end_mm0 = .;
_start_fs0 = .;
*(.fs0)
_end_fs0 = .;
_start_test0 = .;
*(.test0)
_end_test0 = .;
_start_bootdesc = .;
*(.bootdesc)
_end_bootdesc = .;
*(.data)
}
.got : { *(.got) *(.got.plt) }
.bss : { *(.bss) }
}

16
loader/start.axf.S Normal file
View File

@@ -0,0 +1,16 @@
/*
* loader/start.axf.S autogenerated from build/start.axf
*
* This file is included by the loader sources so that any
* kernel symbol address can be known in advance and stopped
* at by debuggers before virtual memory is enabled.
*/
.section .text
.align 4
.global bkpt_phys_to_virt;
.type bkpt_phys_to_virt, function;
.equ bkpt_phys_to_virt, 0x107118

8
loader/todo.txt Normal file
View File

@@ -0,0 +1,8 @@
TODO:
1) The build system could auto-copy all images to here,
then autogenerate kernel.S from these images.
Then autogenerate a function that loads all given images in main.c
This would allow you to, say, build a custom combination of images
and not worry about how they will be loaded.