Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/ppc32/loader/main.c

    re731b0d r5e9de3a  
    2727 */
    2828
     29#include "main.h"
    2930#include <printf.h>
     31#include "asm.h"
     32#include "_components.h"
    3033#include <ofw.h>
    3134#include <align.h>
    3235#include <macros.h>
    3336#include <string.h>
    34 #include "main.h"
    35 #include "asm.h"
    36 #include "_components.h"
    3737
    38 static bootinfo_t bootinfo;
    39 static component_t components[COMPONENTS];
    40 static char *release = STRING(RELEASE);
     38#define HEAP_GAP 1024000
     39
     40bootinfo_t bootinfo;
     41
     42
     43static void check_align(const void *addr, const char *desc)
     44{
     45        if ((unsigned int) addr % PAGE_SIZE != 0) {
     46                printf("Error: %s not on page boundary, halting.\n", desc);
     47                halt();
     48        }
     49}
     50
     51
     52static void fix_overlap(void *va, void **pa, const char *desc, unsigned int *top)
     53{
     54        if ((unsigned int) *pa + PAGE_SIZE < *top) {
     55                printf("Warning: %s overlaps kernel physical area\n", desc);
     56               
     57                void *new_va = (void *) (ALIGN_UP((unsigned int) KERNEL_END + HEAP_GAP, PAGE_SIZE) + *top);
     58                void *new_pa = (void *) (HEAP_GAP + *top);
     59                *top += PAGE_SIZE;
     60               
     61                if (ofw_map(new_pa, new_va, PAGE_SIZE, 0) != 0) {
     62                        printf("Error: Unable to map page aligned memory at %L (physical %L), halting.\n", new_va, new_pa);
     63                        halt();
     64                }
     65               
     66                if ((unsigned int) new_pa + PAGE_SIZE < KERNEL_SIZE) {
     67                        printf("Error: %s cannot be relocated, halting.\n", desc);
     68                        halt();
     69                }
     70               
     71                printf("Relocating %L -> %L (physical %L -> %L)\n", va, new_va, *pa, new_pa);
     72                *pa = new_pa;
     73                memcpy(new_va, va, PAGE_SIZE);
     74        }
     75}
     76
     77char *release = STRING(RELEASE);
    4178
    4279#ifdef REVISION
    43         static char *revision = ", revision " STRING(REVISION);
     80        char *revision = ", revision " STRING(REVISION);
    4481#else
    45         static char *revision = "";
     82        char *revision = "";
    4683#endif
    4784
    4885#ifdef TIMESTAMP
    49         static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
     86        char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
    5087#else
    51         static char *timestamp = "";
     88        char *timestamp = "";
    5289#endif
    5390
     
    5592static void version_print(void)
    5693{
    57         printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\n"
    58             "Copyright (c) 2006 HelenOS project\n\n",
    59             release, revision, timestamp);
    60 }
    61 
    62 static void check_align(const void *addr, const char *desc)
    63 {
    64         if ((uintptr_t) addr % PAGE_SIZE != 0) {
    65                 printf("Error: %s not on page boundary, halting.\n", desc);
    66                 halt();
    67         }
    68 }
    69 
    70 static void check_overlap(const void *pa, const char *desc, const uintptr_t top)
    71 {
    72         if ((uintptr_t) pa + PAGE_SIZE < top) {
    73                 printf("Error: %s overlaps destination physical area\n", desc);
    74                 halt();
    75         }
     94        printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\nCopyright (c) 2006 HelenOS project\n\n", release, revision, timestamp);
    7695}
    7796
     
    7998{
    8099        version_print();
     100       
     101        component_t components[COMPONENTS];
    81102        init_components(components);
     103               
     104        unsigned int i;
     105        for (i = 0; i < COMPONENTS; i++)
     106                check_align(components[i].start, components[i].name);
     107       
     108        check_align(&real_mode, "bootstrap trampoline");
     109        check_align(&trans, "translation table");
    82110       
    83111        if (!ofw_memmap(&bootinfo.memmap)) {
     
    91119        }
    92120       
    93         check_align(&real_mode, "bootstrap trampoline");
    94         check_align(trans, "translation table");
    95         check_align(balloc_base, "boot allocations");
     121        if (!ofw_screen(&bootinfo.screen))
     122                printf("Warning: Unable to get screen properties.\n");
    96123       
    97         unsigned int i;
    98         for (i = 0; i < COMPONENTS; i++)
    99                 check_align(components[i].start, components[i].name);
     124        if (!ofw_macio(&bootinfo.macio))
     125                printf("Warning: Unable to get macio properties.\n");
    100126       
     127        printf("Device statistics\n");
     128       
     129        if (bootinfo.screen.addr)
     130                printf(" screen at %L, resolution %dx%d, %d bpp (scanline %d bytes)\n", bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height, bootinfo.screen.bpp, bootinfo.screen.scanline);
     131       
     132        if (bootinfo.macio.addr)
     133                printf(" macio at %L (size %d bytes)\n", bootinfo.macio.addr, bootinfo.macio.size);
     134       
     135        void *real_mode_pa = ofw_translate(&real_mode);
     136        void *trans_pa = ofw_translate(&trans);
    101137        void *bootinfo_pa = ofw_translate(&bootinfo);
    102         void *real_mode_pa = ofw_translate(&real_mode);
    103         void *trans_pa = ofw_translate(trans);
    104         void *balloc_base_pa = ofw_translate(balloc_base);
    105138       
    106         printf("Memory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
     139        printf("\nMemory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
    107140        printf(" %L: boot info structure (physical %L)\n", &bootinfo, bootinfo_pa);
    108141        printf(" %L: bootstrap trampoline (physical %L)\n", &real_mode, real_mode_pa);
    109         printf(" %L: translation table (physical %L)\n", trans, trans_pa);
    110         printf(" %L: boot allocations (physical %L)\n", balloc_base, balloc_base_pa);
     142        printf(" %L: translation table (physical %L)\n", &trans, trans_pa);
    111143        for (i = 0; i < COMPONENTS; i++)
    112144                printf(" %L: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size);
    113145       
    114         uintptr_t top = 0;
     146        unsigned int top = 0;
    115147        for (i = 0; i < COMPONENTS; i++)
    116148                top += ALIGN_UP(components[i].size, PAGE_SIZE);
    117         top += ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE);
    118        
    119         if (top >= TRANS_SIZE * PAGE_SIZE) {
    120                 printf("Error: boot image is too large\n");
    121                 halt();
    122         }
    123        
    124         check_overlap(bootinfo_pa, "boot info", top);
    125         check_overlap(real_mode_pa, "bootstrap trampoline", top);
    126         check_overlap(trans_pa, "translation table", top);
    127149       
    128150        unsigned int pages = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
     
    130152        for (i = 0; i < pages; i++) {
    131153                void *pa = ofw_translate(KERNEL_START + (i << PAGE_WIDTH));
    132                 check_overlap(pa, "kernel", top);
    133                 trans[i] = (uintptr_t) pa;
     154                fix_overlap(KERNEL_START + (i << PAGE_WIDTH), &pa, "kernel", &top);
     155                trans[i] = pa;
    134156        }
    135157       
    136158        bootinfo.taskmap.count = 0;
    137159        for (i = 1; i < COMPONENTS; i++) {
    138                 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) {
    139                         printf("\nSkipping superfluous components.\n");
    140                         break;
    141                 }
    142                
    143160                unsigned int component_pages = ALIGN_UP(components[i].size, PAGE_SIZE) >> PAGE_WIDTH;
    144161                unsigned int j;
     
    146163                for (j = 0; j < component_pages; j++) {
    147164                        void *pa = ofw_translate(components[i].start + (j << PAGE_WIDTH));
    148                         check_overlap(pa, components[i].name, top);
    149                         trans[pages + j] = (uintptr_t) pa;
     165                        fix_overlap(components[i].start + (j << PAGE_WIDTH), &pa, components[i].name, &top);
     166                        trans[pages + j] = pa;
    150167                        if (j == 0) {
    151                                
    152                                 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) PA2KA(pages << PAGE_WIDTH);
     168                                bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) (pages << PAGE_WIDTH);
    153169                                bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size;
    154170                                strncpy(bootinfo.taskmap.tasks[bootinfo.taskmap.count].name,
    155171                                    components[i].name, BOOTINFO_TASK_NAME_BUFLEN);
    156                                
     172
    157173                                bootinfo.taskmap.count++;
    158174                        }
     
    162178        }
    163179       
    164         uintptr_t balloc_kernel_base = PA2KA(pages << PAGE_WIDTH);
    165         unsigned int balloc_pages = ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
    166         for (i = 0; i < balloc_pages; i++) {
    167                 void *pa = ofw_translate(balloc_base + (i << PAGE_WIDTH));
    168                 check_overlap(pa, "boot allocations", top);
    169                 trans[pages + i] = (uintptr_t) pa;
    170         }
    171        
    172         pages += balloc_pages;
    173        
    174         balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base, balloc_kernel_base);
    175         printf("\nCanonizing OpenFirmware device tree...");
    176         bootinfo.ofw_root = ofw_tree_build();
    177         printf("done.\n");
     180        fix_overlap(&real_mode, &real_mode_pa, "bootstrap trampoline", &top);
     181        fix_overlap(&trans, &trans_pa, "translation table", &top);
     182        fix_overlap(&bootinfo, &bootinfo_pa, "boot info", &top);
    178183       
    179184        ofw_setup_palette();
    180185       
    181186        printf("\nBooting the kernel...\n");
    182         jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa);
     187        jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa, (void *) bootinfo.screen.addr, bootinfo.screen.scanline);
    183188}
Note: See TracChangeset for help on using the changeset viewer.