Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2249 → Rev 2250

/trunk/boot/genarch/ofw.h
117,7 → 117,8
extern unsigned int ofw_get_size_cells(const phandle device);
extern void *ofw_translate(const void *virt);
extern int ofw_translate_failed(ofw_arg_t flag);
extern void *ofw_claim(const void *virt, const int len);
extern void *ofw_claim_virt(const void *virt, const int len);
extern void *ofw_claim_phys(const void *virt, const int len);
extern int ofw_map(const void *phys, const void *virt, const int size, const int mode);
extern int ofw_memmap(memmap_t *map);
extern int ofw_screen(screen_t *screen);
/trunk/boot/genarch/balloc.h
31,6 → 31,8
 
#include <types.h>
 
#define BALLOC_MAX_SIZE (1024 * 1024)
 
typedef struct {
uintptr_t base;
size_t size;
/trunk/boot/genarch/ofw.c
38,6 → 38,7
ihandle ofw_stdout;
phandle ofw_root;
ihandle ofw_mmu;
ihandle ofw_memory_prop;
phandle ofw_memory;
phandle ofw_aliases;
 
47,7 → 48,7
if (ofw_chosen == -1)
halt();
if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)
if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)
ofw_stdout = 0;
ofw_root = ofw_find_device("/");
56,10 → 57,14
halt();
}
if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
puts("\r\nError: Unable to get mmu property, halted.\r\n");
halt();
}
if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop, sizeof(ofw_memory_prop)) <= 0) {
puts("\r\nError: Unable to get memory property, halted.\r\n");
halt();
}
 
ofw_memory = ofw_find_device("/memory");
if (ofw_memory == -1) {
200,13 → 205,12
else
shift = 0;
 
return (void *) ((result[2]<<shift)|result[3]);
return (void *) ((result[2] << shift) | result[3]);
}
 
void *ofw_claim(const void *virt, const int len)
void *ofw_claim_virt(const void *virt, const int len)
{
ofw_arg_t retaddr;
int shift;
 
if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) {
puts("Error: MMU method claim() failed, halting.\n");
216,6 → 220,42
return (void *) retaddr;
}
 
void *ofw_claim_phys(const void *phys, const int len)
{
ofw_arg_t retaddr[2];
int shift;
 
if (sizeof(unative_t) == 8) {
shift = 32;
if (ofw_call("call-method", 6, 3, retaddr, "claim",
ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift,
((uintptr_t) phys) & ((uint32_t) -1)) != 0) {
/*
* Note that this will help us to discover
* conflicts between OpenFirmware allocations
* and our use of physical memory.
* It is better to detect collisions here
* than to cope with weird errors later.
*
* So this is really not to make the loader
* more generic; it is here for debugging
* purposes.
*/
puts("Error: memory method claim() failed, halting.\n");
halt();
}
} else {
shift = 0;
/*
* FIXME: the number of arguments is probably different...
*/
puts("Error: 32-bit ofw_claim_phys not implemented.\n");
halt();
}
 
return (void *) ((retaddr[0] << shift) | retaddr[1]);
}
 
int ofw_map(const void *phys, const void *virt, const int size, const int mode)
{
uintptr_t phys_hi, phys_lo;
230,7 → 270,7
}
 
return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt,
phys_hi, phys_lo);
phys_hi, phys_lo);
}
 
/** Save OpenFirmware physical memory map.
252,8 → 292,8
int pos;
map->total = 0;
map->count = 0;
for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count <
MEMMAP_MAX_RECORDS); pos += ac + sc) {
for (pos = 0; (pos < ret / sizeof(uint32_t)) &&
(map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
void * start = (void *) ((uintptr_t) buf[pos + ac - 1]);
unsigned int size = buf[pos + ac + sc - 1];
/trunk/boot/genarch/balloc.c
47,7 → 47,10
alignment = ALIGN_UP(alignment, 4);
addr = ballocs->base + ALIGN_UP(ballocs->size, alignment);
 
if (ALIGN_UP(ballocs->size, alignment) + size > BALLOC_MAX_SIZE)
return NULL;
ballocs->size = ALIGN_UP(ballocs->size, alignment) + size;
return (void *) addr;
/trunk/boot/arch/sparc64/loader/main.c
92,7 → 92,7
unsigned int i;
for (i = 0; i < COMPONENTS; i++)
printf(" %P: %s image (size %d bytes)\n", components[i].start,
components[i].name, components[i].size);
components[i].name, components[i].size);
 
void * base = (void *) KERNEL_VIRTUAL_ADDRESS;
unsigned int top = 0;
102,10 → 102,24
for (i = 0; i < COMPONENTS; i++) {
printf(" %s...", components[i].name);
top = ALIGN_UP(top, PAGE_SIZE);
 
/*
* At this point, we claim the physical memory that we are
* going to use. We should be safe in case of the virtual
* address space because the OpenFirmware, according to its
* SPARC binding, should restrict its use of virtual memory
* to addresses from [0xffd00000; 0xffefffff] and
* [0xfe000000; 0xfeffffff].
*/
(void) ofw_claim_phys(bootinfo.physmem_start + base + top,
ALIGN_UP(components[i].size, PAGE_SIZE));
memcpy(base + top, components[i].start, components[i].size);
if (i > 0) {
bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = base + top;
bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size;
bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr =
base + top;
bootinfo.taskmap.tasks[bootinfo.taskmap.count].size =
components[i].size;
bootinfo.taskmap.count++;
}
top += components[i].size;
112,7 → 126,14
printf("done.\n");
}
 
balloc_init(&bootinfo.ballocs, ALIGN_UP(((uintptr_t) base) + top, PAGE_SIZE));
/*
* Claim the physical memory for the boot allocator.
* Initialize the boot allocator.
*/
(void) ofw_claim_phys(bootinfo.physmem_start +
base + ALIGN_UP(top, PAGE_SIZE), BALLOC_MAX_SIZE);
balloc_init(&bootinfo.ballocs, ALIGN_UP(((uintptr_t) base) + top,
PAGE_SIZE));
 
printf("\nCanonizing OpenFirmware device tree...");
bootinfo.ofw_root = ofw_tree_build();
127,5 → 148,7
 
printf("\nBooting the kernel...\n");
jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS,
bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, sizeof(bootinfo));
bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
sizeof(bootinfo));
}