/trunk/kernel/genarch/include/ofw/ofw_tree.h |
---|
0,0 → 1,56 |
/* |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef KERN_OFW_TREE_H_ |
#define KERN_OFW_TREE_H_ |
#include <arch/types.h> |
#define OFW_TREE_PROPERTY_MAX_NAMELEN 32 |
typedef struct ofw_tree_node ofw_tree_node_t; |
typedef struct ofw_tree_property ofw_tree_property_t; |
/** Memory representation of OpenFirmware device tree node. */ |
struct ofw_tree_node { |
ofw_tree_node_t *parent; |
ofw_tree_node_t *peer; |
ofw_tree_node_t *child; |
unsigned properties; /**< Number of properties. */ |
ofw_tree_property_t *property; |
}; |
/** Memory representation of OpenFirmware device tree node property. */ |
struct ofw_tree_property { |
char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
size_t size; |
void *value; |
}; |
#endif |
/trunk/kernel/genarch/Makefile.inc |
---|
87,3 → 87,10 |
genarch/src/kbd/key.c \ |
genarch/src/kbd/scanc_sun.c |
endif |
## OpenFirmware Device Tree |
ifeq ($(CONFIG_OFW_TREE), y) |
GENARCH_SOURCES += \ |
genarch/src/ofw/ofw_tree,c |
endif |
/trunk/kernel/genarch/src/ofw/ofw_tree.c |
---|
0,0 → 1,39 |
/* |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup ofw |
* @{ |
*/ |
/** |
* @file |
* @brief OpenFirmware device tree navigation. |
* |
*/ |
/** @} |
*/ |
/trunk/kernel/generic/include/config.h |
---|
55,7 → 55,17 |
init_task_t tasks[CONFIG_INIT_TASKS]; |
} init_t; |
/** Boot allocations. |
* |
* Allocatations made by the boot that are meant to be used by the kernel |
* are all recorded in the ballocs_t type. |
*/ |
typedef struct { |
uintptr_t base; |
size_t size; |
} ballocs_t; |
typedef struct { |
count_t cpu_count; /**< Number of processors detected. */ |
volatile count_t cpu_active; /**< Number of processors that are up and running. */ |
69,6 → 79,7 |
extern config_t config; |
extern init_t init; |
extern ballocs_t ballocs; |
#endif |
/trunk/kernel/generic/src/main/main.c |
---|
94,6 → 94,12 |
0 |
}; |
/** Boot allocations. */ |
ballocs_t ballocs = { |
.base = NULL, |
.size = 0 |
}; |
context_t ctx; |
/* |
105,7 → 111,7 |
size_t hardcoded_ktext_size = 0; /**< Size of the kernel code in bytes. */ |
size_t hardcoded_kdata_size = 0; /**< Size of the kernel data in bytes. */ |
uintptr_t stack_safe = 0; /**< Lowest safe stack virtual address */ |
uintptr_t stack_safe = 0; /**< Lowest safe stack virtual address */ |
void main_bsp(void); |
void main_ap(void); |
152,6 → 158,12 |
if (PA_overlaps(config.stack_base, config.stack_size, init.tasks[i].addr, init.tasks[i].size)) |
config.stack_base = ALIGN_UP(init.tasks[i].addr + init.tasks[i].size, config.stack_size); |
} |
/* Avoid placing stack on top of boot allocations. */ |
if (ballocs.size) { |
if (PA_overlaps(config.stack_base, config.stack_size, ballocs.base, ballocs.size)) |
config.stack_base = ALIGN_UP(ballocs.base + ballocs.size, PAGE_SIZE); |
} |
if (config.stack_base < stack_safe) |
config.stack_base = ALIGN_UP(stack_safe, PAGE_SIZE); |
/trunk/kernel/generic/src/mm/frame.c |
---|
1077,6 → 1077,9 |
for (i = 0; i < init.cnt; i++) |
frame_mark_unavailable(ADDR2PFN(KA2PA(init.tasks[i].addr)), SIZE2FRAMES(init.tasks[i].size)); |
if (ballocs.size) |
frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)), SIZE2FRAMES(ballocs.size)); |
/* Black list first frame, as allocating NULL would |
* fail in some places */ |
frame_mark_unavailable(0, 1); |
/trunk/kernel/arch/sparc64/include/boot/boot.h |
---|
35,7 → 35,6 |
#ifndef KERN_sparc64_BOOT_H_ |
#define KERN_sparc64_BOOT_H_ |
#define VMA 0x400000 |
#define LMA VMA |
42,8 → 41,10 |
#ifndef __ASM__ |
#ifndef __LINKER__ |
#include <config.h> |
#include <arch/types.h> |
#include <typedefs.h> |
#include <genarch/ofw/ofw_tree.h> |
#define TASKMAP_MAX_RECORDS 32 |
#define MEMMAP_MAX_RECORDS 32 |
86,6 → 87,10 |
uint32_t clock_frequency; |
} processor_t; |
/** Bootinfo structure. |
* |
* Must be in sync with bootinfo structure used by the boot loader. |
*/ |
typedef struct { |
taskmap_t taskmap; |
memmap_t memmap; |
92,6 → 97,8 |
screen_t screen; |
keyboard_t keyboard; |
processor_t processor; |
ballocs_t ballocs; |
ofw_tree_node_t *ofw_root; |
} bootinfo_t; |
extern bootinfo_t bootinfo; |
/trunk/kernel/arch/sparc64/src/sparc64.c |
---|
51,7 → 51,7 |
void arch_pre_main(void) |
{ |
/* Setup usermode */ |
/* Copy init task info. */ |
init.cnt = bootinfo.taskmap.count; |
uint32_t i; |
60,6 → 60,10 |
init.tasks[i].addr = PA2KA(bootinfo.taskmap.tasks[i].addr); |
init.tasks[i].size = bootinfo.taskmap.tasks[i].size; |
} |
/* Copy boot allocations info. */ |
ballocs.base = bootinfo.ballocs.base; |
ballocs.size = bootinfo.ballocs.size; |
} |
void arch_pre_mm_init(void) |
/trunk/boot/genarch/ofw_tree.h |
---|
37,15 → 37,17 |
typedef struct ofw_tree_node ofw_tree_node_t; |
typedef struct ofw_tree_property ofw_tree_property_t; |
/** Memory representation of OpenFirmware device tree node. */ |
struct ofw_tree_node { |
ofw_tree_node_t *parent; |
ofw_tree_node_t *peer; |
ofw_tree_node_t *child; |
unsigned properties; |
unsigned properties; /**< Number of properties. */ |
ofw_tree_property_t *property; |
}; |
/** Memory representation of OpenFirmware device tree node property. */ |
struct ofw_tree_property { |
char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
size_t size; |
/trunk/boot/genarch/balloc.h |
---|
0,0 → 1,42 |
/* |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef BOOT_BALLOC_H_ |
#define BOOT_BALLOC_H_ |
#include <types.h> |
typedef struct { |
uintptr_t base; |
size_t size; |
} ballocs_t; |
extern void balloc_init(ballocs_t *b, uintptr_t base); |
extern void *balloc(size_t size, size_t alignment); |
#endif |
/trunk/boot/genarch/ofw_tree.c |
---|
30,20 → 30,21 |
#include <ofw.h> |
#include <types.h> |
#include <string.h> |
#include <balloc.h> |
static ofw_tree_node_t *ofw_tree_node_alloc(void) |
{ |
return NULL; |
return balloc(sizeof(ofw_tree_node_t), sizeof(ofw_tree_node_t)); |
} |
static ofw_tree_property_t *ofw_tree_properties_alloc(unsigned count) |
{ |
return NULL; |
return balloc(count * sizeof(ofw_tree_property_t), sizeof(ofw_tree_property_t)); |
} |
static void * ofw_tree_space_alloc(size_t size) |
{ |
return NULL; |
return balloc(size, size); |
} |
/** Transfer information from one OpenFirmware node into its memory representation. |
/trunk/boot/genarch/balloc.c |
---|
0,0 → 1,54 |
/* |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <balloc.h> |
#include <types.h> |
#include <align.h> |
static ballocs_t *ballocs; |
void balloc_init(ballocs_t *b, uintptr_t base) |
{ |
ballocs = b; |
ballocs->base = base; |
ballocs->size = 0; |
} |
void *balloc(size_t size, size_t alignment) |
{ |
uintptr_t addr; |
/* Enforce minimal alignment. */ |
alignment = ALIGN_UP(alignment, 4); |
addr = ballocs->base + ALIGN_UP(ballocs->size, alignment); |
ballocs->size = ALIGN_UP(ballocs->size, alignment) + size; |
return (void *) addr; |
} |
/trunk/boot/arch/sparc64/loader/main.c |
---|
30,7 → 30,9 |
#include <printf.h> |
#include "asm.h" |
#include "_components.h" |
#include <balloc.h> |
#include <ofw.h> |
#include <ofw_tree.h> |
#include "ofwarch.h" |
#include <align.h> |
83,12 → 85,12 |
for (i = 0; i < COMPONENTS; i++) |
printf(" %P: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size); |
void * base = (void *) KERNEL_VIRTUAL_ADDRESS; |
unsigned int top = 0; |
printf("\nCopying components\n"); |
unsigned int top = 0; |
bootinfo.taskmap.count = 0; |
for (i = 0; i < COMPONENTS; i++) { |
void * base = (void *) KERNEL_VIRTUAL_ADDRESS; |
printf(" %s...", components[i].name); |
top = ALIGN_UP(top, PAGE_SIZE); |
memcpy(base + top, components[i].start, components[i].size); |
101,6 → 103,12 |
printf("done.\n"); |
} |
balloc_init(&bootinfo.ballocs, ALIGN_UP(((uintptr_t) base) + top, PAGE_SIZE)); |
printf("\nCanonizing OpenFirmware device tree..."); |
bootinfo.ofw_root = ofw_tree_build(); |
printf("done.\n"); |
printf("\nBooting the kernel...\n"); |
jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, &bootinfo, sizeof(bootinfo)); |
} |
/trunk/boot/arch/sparc64/loader/main.h |
---|
30,6 → 30,8 |
#define BOOT_sparc64_MAIN_H_ |
#include <ofw.h> |
#include <ofw_tree.h> |
#include <balloc.h> |
#include <types.h> |
#define TASKMAP_MAX_RECORDS 32 |
54,6 → 56,8 |
screen_t screen; |
keyboard_t keyboard; |
cpu_t cpu; |
ballocs_t ballocs; |
ofw_tree_node_t *ofw_root; |
} bootinfo_t; |
extern void start(void); |
/trunk/boot/arch/sparc64/loader/Makefile |
---|
52,6 → 52,7 |
main.c \ |
../../../generic/printf.c \ |
../../../generic/string.c \ |
../../../genarch/balloc.c \ |
../../../genarch/ofw.c \ |
../../../genarch/ofw_tree.c \ |
ofwarch.c \ |