Changes in / [207e208e:bc7d44c] in mainline
- Files:
-
- 6 added
- 62 edited
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
r207e208e rbc7d44c 273 273 274 274 % OpenFirmware tree support 275 ! [PLATFORM=sparc64] CONFIG_OFW_TREE (y) 275 ! [PLATFORM=ppc32|PLATFORM=sparc64] CONFIG_OFW_TREE (y) 276 277 % OpenFirmware PCI bus support 278 ! [PLATFORM=sparc64] CONFIG_OFW_PCI (y) 276 279 277 280 % Multiboot standard support -
boot/arch/arm32/loader/asm.h
r207e208e rbc7d44c 40 40 41 41 42 /** Copies cnt bytes from dst to src.43 *44 * @param dst Destination address.45 * @param src Source address.46 * @param cnt Count of bytes to be copied.47 */48 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))49 50 51 42 /** Called when the CPU is switched on. 52 43 * -
boot/arch/arm32/loader/main.c
r207e208e rbc7d44c 43 43 #include <macros.h> 44 44 #include <string.h> 45 #include <memstr.h> 45 46 46 47 #include "mm.h" -
boot/arch/ia64/loader/asm.h
r207e208e rbc7d44c 34 34 #include "main.h" 35 35 36 #define PAGE_WIDTH 37 #define PAGE_SIZE 36 #define PAGE_WIDTH 14 37 #define PAGE_SIZE (1 << PAGE_WIDTH) 38 38 39 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))39 #define BALLOC_MAX_SIZE (128 * 1024) 40 40 41 41 extern void halt(void); 42 /*extern void jump_to_kernel(void *entry, uint64_t cfg, bootinfo_t *bootinfo,43 unsigned int bootinfo_size) __attribute__((noreturn));*/44 45 42 extern void jump_to_kernel(void *) __attribute__((noreturn)); 46 43 -
boot/arch/ia64/loader/main.h
r207e208e rbc7d44c 34 34 35 35 36 #define CONFIG_INIT_TASKS 32 37 38 36 #define CONFIG_INIT_TASKS 32 39 37 40 38 extern void start(void); -
boot/arch/mips32/loader/asm.h
r207e208e rbc7d44c 33 33 #define PAGE_WIDTH 14 34 34 35 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))36 37 35 void jump_to_kernel(void *entry, void *bootinfo) __attribute__((noreturn)); 38 36 -
boot/arch/mips32/loader/main.c
r207e208e rbc7d44c 27 27 */ 28 28 29 #include "main.h" 29 #include "main.h" 30 30 #include <printf.h> 31 31 #include <align.h> 32 32 #include <macros.h> 33 33 #include <string.h> 34 #include <memstr.h> 34 35 #include "msim.h" 35 36 #include "asm.h" -
boot/arch/ppc32/loader/Makefile
r207e208e rbc7d44c 62 62 SOURCES = \ 63 63 main.c \ 64 ofwarch.c \65 64 _components.c \ 66 ../../../genarch/ofw.c \67 65 ../../../generic/printf.c \ 68 66 ../../../generic/string.c \ 67 ../../../genarch/balloc.c \ 68 ../../../genarch/ofw.c \ 69 ../../../genarch/ofw_tree.c \ 70 ofwarch.c \ 69 71 asm.S \ 70 72 boot.S … … 73 75 $(KERNELDIR)/kernel.bin \ 74 76 $(USPACEDIR)/srv/ns/ns \ 77 $(USPACEDIR)/app/init/init \ 75 78 $(USPACEDIR)/srv/loader/loader \ 76 $(USPACEDIR)/app/init/init \77 79 $(USPACEDIR)/srv/devmap/devmap \ 78 80 $(USPACEDIR)/srv/bd/rd/rd \ … … 99 101 $(USPACEDIR)/app/tester/tester \ 100 102 $(USPACEDIR)/app/trace/trace \ 101 $(USPACEDIR)/app/ klog/klog\102 $(USPACEDIR)/app/ bdsh/bdsh103 $(USPACEDIR)/app/bdsh/bdsh \ 104 $(USPACEDIR)/app/klog/klog 103 105 104 106 OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) -
boot/arch/ppc32/loader/_link.ld.in
r207e208e rbc7d44c 19 19 [[COMPONENTS]] 20 20 } 21 22 /DISCARD/ : { 23 *(.comment); 24 *(.note*); 25 } 21 26 } -
boot/arch/ppc32/loader/asm.S
r207e208e rbc7d44c 29 29 #include "asm.h" 30 30 #include "regname.h" 31 #include "ofwarch.h" 31 32 32 33 .macro SMC_COHERENCY addr … … 45 46 46 47 .macro TLB_FLUSH reg 47 tlbie \reg 48 addi \reg, \reg, 0x1000 48 li \reg, 0 49 sync 50 51 .rept 64 52 tlbie \reg 53 addi \reg, \reg, 0x1000 54 .endr 55 56 eieio 57 tlbsync 58 sync 49 59 .endm 50 60 … … 54 64 .global memcpy 55 65 .global jump_to_kernel 66 .global balloc_base 56 67 57 68 halt: … … 62 73 addi r6, r3, -4 63 74 addi r4, r4, -4 64 beq 75 beq 2f 65 76 66 77 andi. r0, r6, 3 … … 69 80 70 81 1: 71 72 lwz r7, 4(r4) 73 lwzu r8, 8(r4) 74 stw r7, 4(r6) 75 stwu r8, 8(r6) 76 bdnz 1b 77 78 andi. r5, r5, 7 82 lwz r7, 4(r4) 83 lwzu r8, 8(r4) 84 stw r7, 4(r6) 85 stwu r8, 8(r6) 86 bdnz 1b 87 88 andi. r5, r5, 7 79 89 80 90 2: 81 82 cmplwi 0, r5, 4 83 blt 3f 84 85 lwzu r0, 4(r4) 86 addi r5, r5, -4 87 stwu r0, 4(r6) 91 cmplwi 0, r5, 4 92 blt 3f 93 94 lwzu r0, 4(r4) 95 addi r5, r5, -4 96 stwu r0, 4(r6) 88 97 89 98 3: 90 91 cmpwi 0, r5, 0 92 beqlr 93 mtctr r5 94 addi r4, r4, 3 95 addi r6, r6, 3 99 cmpwi 0, r5, 0 100 beqlr 101 mtctr r5 102 addi r4, r4, 3 103 addi r6, r6, 3 96 104 97 105 4: 98 99 lbzu r0, 1(r4) 100 stbu r0, 1(r6) 101 bdnz 4b 102 blr 106 lbzu r0, 1(r4) 107 stbu r0, 1(r6) 108 bdnz 4b 109 blr 103 110 104 111 5: 105 106 subfic r0, r0, 4 107 mtctr r0 112 subfic r0, r0, 4 113 mtctr r0 108 114 109 115 6: 110 111 lbz r7, 4(r4) 112 addi r4, r4, 1 113 stb r7, 4(r6) 114 addi r6, r6, 1 115 bdnz 6b 116 subf r5, r0, r5 117 rlwinm. r7, r5, 32-3, 3, 31 118 beq 2b 119 mtctr r7 120 b 1b 121 116 lbz r7, 4(r4) 117 addi r4, r4, 1 118 stb r7, 4(r6) 119 addi r6, r6, 1 120 bdnz 6b 121 subf r5, r0, r5 122 rlwinm. r7, r5, 32-3, 3, 31 123 beq 2b 124 mtctr r7 125 b 1b 122 126 123 127 jump_to_kernel: … … 128 132 # r6 = bytes to copy 129 133 # r7 = real_mode (pa) 130 # r8 = framebuffer (pa)131 # r9 = scanline132 134 133 135 # disable interrupts … … 153 155 rfi 154 156 157 .align PAGE_WIDTH 158 balloc_base: 159 .fill BALLOC_MAX_SIZE 160 155 161 .section REALMODE, "ax" 162 156 163 .align PAGE_WIDTH 157 164 .global real_mode 158 159 165 real_mode: 160 166 161 167 # copy kernel to proper location 162 168 # 169 # r3 = bootinfo (pa) 170 # r4 = bootinfo_size 163 171 # r5 = trans (pa) 164 172 # r6 = bytes to copy 165 # r8 = framebuffer (pa)166 # r9 = scanline167 173 168 174 li r31, PAGE_SIZE >> 2 … … 343 349 # flush TLB 344 350 345 li r31, 0346 sync347 348 351 TLB_FLUSH r31 349 TLB_FLUSH r31350 TLB_FLUSH r31351 TLB_FLUSH r31352 TLB_FLUSH r31353 TLB_FLUSH r31354 TLB_FLUSH r31355 TLB_FLUSH r31356 357 TLB_FLUSH r31358 TLB_FLUSH r31359 TLB_FLUSH r31360 TLB_FLUSH r31361 TLB_FLUSH r31362 TLB_FLUSH r31363 TLB_FLUSH r31364 TLB_FLUSH r31365 366 TLB_FLUSH r31367 TLB_FLUSH r31368 TLB_FLUSH r31369 TLB_FLUSH r31370 TLB_FLUSH r31371 TLB_FLUSH r31372 TLB_FLUSH r31373 TLB_FLUSH r31374 375 TLB_FLUSH r31376 TLB_FLUSH r31377 TLB_FLUSH r31378 TLB_FLUSH r31379 TLB_FLUSH r31380 TLB_FLUSH r31381 TLB_FLUSH r31382 TLB_FLUSH r31383 384 TLB_FLUSH r31385 TLB_FLUSH r31386 TLB_FLUSH r31387 TLB_FLUSH r31388 TLB_FLUSH r31389 TLB_FLUSH r31390 TLB_FLUSH r31391 TLB_FLUSH r31392 393 TLB_FLUSH r31394 TLB_FLUSH r31395 TLB_FLUSH r31396 TLB_FLUSH r31397 TLB_FLUSH r31398 TLB_FLUSH r31399 TLB_FLUSH r31400 TLB_FLUSH r31401 402 TLB_FLUSH r31403 TLB_FLUSH r31404 TLB_FLUSH r31405 TLB_FLUSH r31406 TLB_FLUSH r31407 TLB_FLUSH r31408 TLB_FLUSH r31409 TLB_FLUSH r31410 411 TLB_FLUSH r31412 TLB_FLUSH r31413 TLB_FLUSH r31414 TLB_FLUSH r31415 TLB_FLUSH r31416 TLB_FLUSH r31417 TLB_FLUSH r31418 TLB_FLUSH r31419 420 eieio421 tlbsync422 sync423 352 424 353 # start the kernel 425 354 # 426 # pc = KERNEL_START_ADDR355 # pc = PA2KA(BOOT_OFFSET) 427 356 # r3 = bootinfo (pa) 428 # sprg0 = KA2PA(KERNEL_START_ADDR)357 # sprg0 = BOOT_OFFSET 429 358 # sprg3 = physical memory size 430 359 # sp = 0 (pa) 431 360 432 lis r31, KERNEL_START_ADDR@ha 433 addi r31, r31, KERNEL_START_ADDR@l 434 361 lis r31, PA2KA(BOOT_OFFSET)@ha 362 addi r31, r31, PA2KA(BOOT_OFFSET)@l 435 363 mtspr srr0, r31 436 364 437 subis r31, r31, 0x8000 365 lis r31, BOOT_OFFSET@ha 366 addi r31, r31, BOOT_OFFSET@l 438 367 mtsprg0 r31 439 368 … … 454 383 .global trans 455 384 trans: 456 .space (TRANS_SIZE * TRANS_ITEM_SIZE) 385 .rept TRANS_SIZE 386 .int 0 387 .endr -
boot/arch/ppc32/loader/asm.h
r207e208e rbc7d44c 30 30 #define BOOT_ppc32_ASM_H_ 31 31 32 #define PAGE_ SIZE 409633 #define PAGE_ WIDTH 1232 #define PAGE_WIDTH 12 33 #define PAGE_SIZE (1 << PAGE_WIDTH) 34 34 35 #define TRANS_SIZE 102436 #define TRANS_ITEM_SIZE 435 #define TRANS_SIZE 1024 36 #define BOOT_OFFSET 0x8000 37 37 38 #define KERNEL_START_ADDR 0x8000800038 #define BALLOC_MAX_SIZE (128 * 1024) 39 39 40 40 #ifndef __ASM__ 41 41 42 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt)) 42 #include "types.h" 43 #include "main.h" 44 #include "ofwarch.h" 43 45 44 extern void *trans[TRANS_SIZE]; 46 #define PA2KA(x) (((uintptr_t) (x)) + 0x80000000) 47 48 extern uint8_t balloc_base[BALLOC_MAX_SIZE]; 49 extern uintptr_t trans[TRANS_SIZE]; 45 50 46 51 extern void halt(); 47 extern void jump_to_kernel(void *bootinfo, unsigned int bootinfo_size, void *trans, unsigned int kernel_size, void *real_mode, void *fb, unsigned int scanline) __attribute__((noreturn)); 52 extern void jump_to_kernel(void *bootinfo, unsigned int bootinfo_size, 53 uintptr_t trans[], unsigned int kernel_size, void *real_mode) __attribute__((noreturn)); 48 54 extern void real_mode(); 55 56 #else 57 58 #define PA2KA(x) ((x) + 0x80000000) 49 59 50 60 #endif -
boot/arch/ppc32/loader/main.c
r207e208e rbc7d44c 27 27 */ 28 28 29 #include "main.h"30 29 #include <printf.h> 31 #include "asm.h"32 #include "_components.h"33 30 #include <ofw.h> 34 31 #include <align.h> 35 32 #include <macros.h> 36 33 #include <string.h> 34 #include "main.h" 35 #include "asm.h" 36 #include "_components.h" 37 37 38 #define HEAP_GAP 1024000 38 static bootinfo_t bootinfo; 39 static component_t components[COMPONENTS]; 40 static char *release = STRING(RELEASE); 39 41 40 bootinfo_t bootinfo; 42 #ifdef REVISION 43 static char *revision = ", revision " STRING(REVISION); 44 #else 45 static char *revision = ""; 46 #endif 41 47 48 #ifdef TIMESTAMP 49 static char *timestamp = "\nBuilt on " STRING(TIMESTAMP); 50 #else 51 static char *timestamp = ""; 52 #endif 53 54 /** Print version information. */ 55 static void version_print(void) 56 { 57 printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\n" 58 "Copyright (c) 2006 HelenOS project\n\n", 59 release, revision, timestamp); 60 } 42 61 43 62 static void check_align(const void *addr, const char *desc) 44 63 { 45 if ((u nsigned int) addr % PAGE_SIZE != 0) {64 if ((uintptr_t) addr % PAGE_SIZE != 0) { 46 65 printf("Error: %s not on page boundary, halting.\n", desc); 47 66 halt(); … … 49 68 } 50 69 51 52 static void fix_overlap(void *va, void **pa, const char *desc, unsigned int *top) 70 static void check_overlap(const void *pa, const char *desc, const uintptr_t top) 53 71 { 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); 72 if ((uintptr_t) pa + PAGE_SIZE < top) { 73 printf("Error: %s overlaps destination physical area\n", desc); 74 halt(); 74 75 } 75 }76 77 char *release = STRING(RELEASE);78 79 #ifdef REVISION80 char *revision = ", revision " STRING(REVISION);81 #else82 char *revision = "";83 #endif84 85 #ifdef TIMESTAMP86 char *timestamp = "\nBuilt on " STRING(TIMESTAMP);87 #else88 char *timestamp = "";89 #endif90 91 /** Print version information. */92 static void version_print(void)93 {94 printf("HelenOS PPC32 Bootloader\nRelease %s%s%s\nCopyright (c) 2006 HelenOS project\n\n", release, revision, timestamp);95 76 } 96 77 … … 98 79 { 99 80 version_print(); 100 101 component_t components[COMPONENTS];102 81 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");110 82 111 83 if (!ofw_memmap(&bootinfo.memmap)) { … … 119 91 } 120 92 121 if (!ofw_screen(&bootinfo.screen)) 122 printf("Warning: Unable to get screen properties.\n"); 93 check_align(&real_mode, "bootstrap trampoline"); 94 check_align(trans, "translation table"); 95 check_align(balloc_base, "boot allocations"); 123 96 124 if (!ofw_macio(&bootinfo.macio)) 125 printf("Warning: Unable to get macio properties.\n"); 97 unsigned int i; 98 for (i = 0; i < COMPONENTS; i++) 99 check_align(components[i].start, components[i].name); 126 100 127 printf("Device statistics\n"); 101 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); 128 105 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); 137 void *bootinfo_pa = ofw_translate(&bootinfo); 138 139 printf("\nMemory statistics (total %d MB)\n", bootinfo.memmap.total >> 20); 106 printf("Memory statistics (total %d MB)\n", bootinfo.memmap.total >> 20); 140 107 printf(" %L: boot info structure (physical %L)\n", &bootinfo, bootinfo_pa); 141 108 printf(" %L: bootstrap trampoline (physical %L)\n", &real_mode, real_mode_pa); 142 printf(" %L: translation table (physical %L)\n", &trans, trans_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); 143 111 for (i = 0; i < COMPONENTS; i++) 144 112 printf(" %L: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size); 145 113 146 u nsigned int top = 0;114 uintptr_t top = 0; 147 115 for (i = 0; i < COMPONENTS; i++) 148 116 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); 149 127 150 128 unsigned int pages = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE) >> PAGE_WIDTH; … … 152 130 for (i = 0; i < pages; i++) { 153 131 void *pa = ofw_translate(KERNEL_START + (i << PAGE_WIDTH)); 154 fix_overlap(KERNEL_START + (i << PAGE_WIDTH), &pa, "kernel", &top);155 trans[i] = pa;132 check_overlap(pa, "kernel", top); 133 trans[i] = (uintptr_t) pa; 156 134 } 157 135 158 136 bootinfo.taskmap.count = 0; 159 137 for (i = 1; i < COMPONENTS; i++) { 138 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { 139 printf("\nSkipping superfluous components.\n"); 140 break; 141 } 142 160 143 unsigned int component_pages = ALIGN_UP(components[i].size, PAGE_SIZE) >> PAGE_WIDTH; 161 144 unsigned int j; … … 163 146 for (j = 0; j < component_pages; j++) { 164 147 void *pa = ofw_translate(components[i].start + (j << PAGE_WIDTH)); 165 fix_overlap(components[i].start + (j << PAGE_WIDTH), &pa, components[i].name, &top);166 trans[pages + j] = pa;148 check_overlap(pa, components[i].name, top); 149 trans[pages + j] = (uintptr_t) pa; 167 150 if (j == 0) { 168 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) (pages << PAGE_WIDTH); 151 152 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) PA2KA(pages << PAGE_WIDTH); 169 153 bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size; 170 154 strncpy(bootinfo.taskmap.tasks[bootinfo.taskmap.count].name, 171 155 components[i].name, BOOTINFO_TASK_NAME_BUFLEN); 172 156 173 157 bootinfo.taskmap.count++; 174 158 } … … 178 162 } 179 163 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); 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"); 183 178 184 179 ofw_setup_palette(); 185 180 186 181 printf("\nBooting the kernel...\n"); 187 jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa , (void *) bootinfo.screen.addr, bootinfo.screen.scanline);182 jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa); 188 183 } -
boot/arch/ppc32/loader/main.h
r207e208e rbc7d44c 30 30 #define BOOT_ppc32_MAIN_H_ 31 31 32 #include "ofw.h" 32 #include <ofw.h> 33 #include <ofw_tree.h> 34 #include <balloc.h> 35 #include <types.h> 33 36 34 #define TASKMAP_MAX_RECORDS 3237 #define TASKMAP_MAX_RECORDS 32 35 38 36 39 /** Size of buffer for storing task name in task_t. */ 37 #define BOOTINFO_TASK_NAME_BUFLEN 3240 #define BOOTINFO_TASK_NAME_BUFLEN 32 38 41 39 /** Struct holding information about single loaded task. */40 42 typedef struct { 41 /** Address where the task was placed. */42 43 void *addr; 43 /** Size of the task's binary. */ 44 unsigned int size; 45 /** Task name. */ 44 uint32_t size; 46 45 char name[BOOTINFO_TASK_NAME_BUFLEN]; 47 46 } task_t; 48 47 49 48 typedef struct { 50 u nsigned int count;49 uint32_t count; 51 50 task_t tasks[TASKMAP_MAX_RECORDS]; 52 51 } taskmap_t; … … 55 54 memmap_t memmap; 56 55 taskmap_t taskmap; 57 screen_t screen;58 macio_t macio;56 ballocs_t ballocs; 57 ofw_tree_node_t *ofw_root; 59 58 } bootinfo_t; 60 59 … … 62 61 extern void bootstrap(void); 63 62 64 extern memmap_t memmap;65 66 63 #endif -
boot/arch/ppc32/loader/ofwarch.c
r207e208e rbc7d44c 31 31 #include <printf.h> 32 32 33 typedef int (* 33 typedef int (*ofw_entry_t)(ofw_args_t *args); 34 34 35 35 int ofw(ofw_args_t *args) … … 49 49 } 50 50 51 int ofw_macio(macio_t *macio)52 {53 char device_name[BUF_SIZE];54 55 if ((ofw_get_property(ofw_aliases, "macio", device_name, sizeof(device_name)) <= 0)56 && (ofw_get_property(ofw_aliases, "mac-io", device_name, sizeof(device_name)) <= 0))57 return false;58 59 phandle device = ofw_find_device(device_name);60 if (device == -1)61 return false;62 63 pci_reg_t pci_reg;64 if (ofw_get_property(device, "assigned-addresses", &pci_reg, sizeof(pci_reg)) <= 0)65 return false;66 67 macio->addr = (void *) pci_reg.addr.addr_lo;68 macio->size = pci_reg.size_lo;69 70 return true;71 }72 73 51 int ofw_translate_failed(ofw_arg_t flag) 74 52 { 53 /* PearPC returns buggy flag */ 75 54 return 0; 76 55 } -
boot/arch/ppc32/loader/ofwarch.h
r207e208e rbc7d44c 30 30 #define BOOT_ppc32_OFWARCH_H_ 31 31 32 #define OFW_ADDRESS_CELLS 33 #define OFW_SIZE_CELLS 32 #define OFW_ADDRESS_CELLS 1 33 #define OFW_SIZE_CELLS 1 34 34 35 35 #endif -
boot/arch/ppc32/loader/regname.h
r207e208e rbc7d44c 31 31 32 32 /* Condition Register Bit Fields */ 33 #define cr0034 #define cr1135 #define cr2236 #define cr3337 #define cr4438 #define cr5539 #define cr6640 #define cr7733 #define cr0 0 34 #define cr1 1 35 #define cr2 2 36 #define cr3 3 37 #define cr4 4 38 #define cr5 5 39 #define cr6 6 40 #define cr7 7 41 41 42 42 /* General Purpose Registers (GPRs) */ 43 #define r0044 #define r1145 #define r2246 #define r3347 #define r4448 #define r5549 #define r6650 #define r7751 #define r8852 #define r9953 #define r101054 #define r111155 #define r121256 #define r131357 #define r141458 #define r151559 #define r161660 #define r171761 #define r181862 #define r191963 #define r202064 #define r212165 #define r222266 #define r232367 #define r242468 #define r252569 #define r262670 #define r272771 #define r282872 #define r292973 #define r303074 #define r313143 #define r0 0 44 #define r1 1 45 #define r2 2 46 #define r3 3 47 #define r4 4 48 #define r5 5 49 #define r6 6 50 #define r7 7 51 #define r8 8 52 #define r9 9 53 #define r10 10 54 #define r11 11 55 #define r12 12 56 #define r13 13 57 #define r14 14 58 #define r15 15 59 #define r16 16 60 #define r17 17 61 #define r18 18 62 #define r19 19 63 #define r20 20 64 #define r21 21 65 #define r22 22 66 #define r23 23 67 #define r24 24 68 #define r25 25 69 #define r26 26 70 #define r27 27 71 #define r28 28 72 #define r29 29 73 #define r30 30 74 #define r31 31 75 75 76 76 /* GPR Aliases */ 77 #define sp177 #define sp 1 78 78 79 79 /* Floating Point Registers (FPRs) */ 80 #define fr0081 #define fr1182 #define fr2283 #define fr3384 #define fr4485 #define fr5586 #define fr6687 #define fr7788 #define fr8889 #define fr9990 #define fr101091 #define fr111192 #define fr121293 #define fr131394 #define fr141495 #define fr151596 #define fr161697 #define fr171798 #define fr181899 #define fr1919100 #define fr2020101 #define fr2121102 #define fr2222103 #define fr2323104 #define fr2424105 #define fr2525106 #define fr2626107 #define fr2727108 #define fr2828109 #define fr2929110 #define fr3030111 #define fr3131112 113 #define vr00114 #define vr11115 #define vr22116 #define vr33117 #define vr44118 #define vr55119 #define vr66120 #define vr77121 #define vr88122 #define vr99123 #define vr1010124 #define vr1111125 #define vr1212126 #define vr1313127 #define vr1414128 #define vr1515129 #define vr1616130 #define vr1717131 #define vr1818132 #define vr1919133 #define vr2020134 #define vr2121135 #define vr2222136 #define vr2323137 #define vr2424138 #define vr2525139 #define vr2626140 #define vr2727141 #define vr2828142 #define vr2929143 #define vr3030144 #define vr3131145 146 #define evr00147 #define evr11148 #define evr22149 #define evr33150 #define evr44151 #define evr55152 #define evr66153 #define evr77154 #define evr88155 #define evr99156 #define evr1010157 #define evr1111158 #define evr1212159 #define evr1313160 #define evr1414161 #define evr1515162 #define evr1616163 #define evr1717164 #define evr1818165 #define evr1919166 #define evr2020167 #define evr2121168 #define evr2222169 #define evr2323170 #define evr2424171 #define evr2525172 #define evr2626173 #define evr2727174 #define evr2828175 #define evr2929176 #define evr3030177 #define evr313180 #define fr0 0 81 #define fr1 1 82 #define fr2 2 83 #define fr3 3 84 #define fr4 4 85 #define fr5 5 86 #define fr6 6 87 #define fr7 7 88 #define fr8 8 89 #define fr9 9 90 #define fr10 10 91 #define fr11 11 92 #define fr12 12 93 #define fr13 13 94 #define fr14 14 95 #define fr15 15 96 #define fr16 16 97 #define fr17 17 98 #define fr18 18 99 #define fr19 19 100 #define fr20 20 101 #define fr21 21 102 #define fr22 22 103 #define fr23 23 104 #define fr24 24 105 #define fr25 25 106 #define fr26 26 107 #define fr27 27 108 #define fr28 28 109 #define fr29 29 110 #define fr30 30 111 #define fr31 31 112 113 #define vr0 0 114 #define vr1 1 115 #define vr2 2 116 #define vr3 3 117 #define vr4 4 118 #define vr5 5 119 #define vr6 6 120 #define vr7 7 121 #define vr8 8 122 #define vr9 9 123 #define vr10 10 124 #define vr11 11 125 #define vr12 12 126 #define vr13 13 127 #define vr14 14 128 #define vr15 15 129 #define vr16 16 130 #define vr17 17 131 #define vr18 18 132 #define vr19 19 133 #define vr20 20 134 #define vr21 21 135 #define vr22 22 136 #define vr23 23 137 #define vr24 24 138 #define vr25 25 139 #define vr26 26 140 #define vr27 27 141 #define vr28 28 142 #define vr29 29 143 #define vr30 30 144 #define vr31 31 145 146 #define evr0 0 147 #define evr1 1 148 #define evr2 2 149 #define evr3 3 150 #define evr4 4 151 #define evr5 5 152 #define evr6 6 153 #define evr7 7 154 #define evr8 8 155 #define evr9 9 156 #define evr10 10 157 #define evr11 11 158 #define evr12 12 159 #define evr13 13 160 #define evr14 14 161 #define evr15 15 162 #define evr16 16 163 #define evr17 17 164 #define evr18 18 165 #define evr19 19 166 #define evr20 20 167 #define evr21 21 168 #define evr22 22 169 #define evr23 23 170 #define evr24 24 171 #define evr25 25 172 #define evr26 26 173 #define evr27 27 174 #define evr28 28 175 #define evr29 29 176 #define evr30 30 177 #define evr31 31 178 178 179 179 /* Special Purpose Registers (SPRs) */ 180 #define xer 1 181 #define lr 8 182 #define ctr 9 183 #define dec 22 184 #define sdr1 25 185 #define srr0 26 186 #define srr1 27 187 #define sprg0 272 188 #define sprg1 273 189 #define sprg2 274 190 #define sprg3 275 191 #define prv 287 192 #define ibat0u 528 193 #define ibat0l 529 194 #define ibat1u 530 195 #define ibat1l 531 196 #define ibat2u 532 197 #define ibat2l 533 198 #define ibat3u 534 199 #define ibat3l 535 200 #define dbat0u 536 201 #define dbat0l 537 202 #define dbat1u 538 203 #define dbat1l 539 204 #define dbat2u 540 205 #define dbat2l 541 206 #define dbat3u 542 207 #define dbat3l 543 208 #define hid0 1008 180 #define xer 1 181 #define lr 8 182 #define ctr 9 183 #define dec 22 184 #define sdr1 25 185 #define srr0 26 186 #define srr1 27 187 #define sprg0 272 188 #define sprg1 273 189 #define sprg2 274 190 #define sprg3 275 191 #define prv 287 192 #define ibat0u 528 193 #define ibat0l 529 194 #define ibat1u 530 195 #define ibat1l 531 196 #define ibat2u 532 197 #define ibat2l 533 198 #define ibat3u 534 199 #define ibat3l 535 200 #define dbat0u 536 201 #define dbat0l 537 202 #define dbat1u 538 203 #define dbat1l 539 204 #define dbat2u 540 205 #define dbat2l 541 206 #define dbat3u 542 207 #define dbat3l 543 208 #define tlbmiss 980 209 #define ptehi 981 210 #define ptelo 982 211 #define hid0 1008 209 212 210 213 /* MSR bits */ 211 #define msr_dr 212 #define msr_ir 213 #define msr_pr 214 #define msr_ee 214 #define msr_dr (1 << 4) 215 #define msr_ir (1 << 5) 216 #define msr_pr (1 << 14) 217 #define msr_ee (1 << 15) 215 218 216 219 /* HID0 bits */ 217 #define hid0_sten 218 #define hid0_ice 219 #define hid0_dce 220 #define hid0_icfi 221 #define hid0_dci 220 #define hid0_sten (1 << 24) 221 #define hid0_ice (1 << 15) 222 #define hid0_dce (1 << 14) 223 #define hid0_icfi (1 << 11) 224 #define hid0_dci (1 << 10) 222 225 223 226 #endif -
boot/arch/sparc64/loader/asm.S
r207e208e rbc7d44c 31 31 #include <register.h> 32 32 33 .register 34 .register 33 .register %g2, #scratch 34 .register %g3, #scratch 35 35 36 36 .text … … 43 43 ba %xcc, halt 44 44 nop 45 46 memcpy: 47 mov %o0, %o3 ! save dst 48 add %o1, 7, %g1 49 and %g1, -8, %g1 50 cmp %o1, %g1 51 be,pn %xcc, 3f 52 add %o0, 7, %g1 53 mov 0, %g3 45 54 46 memcpy: 47 mov %o0, %o3 ! save dst 48 add %o1, 7, %g1 49 and %g1, -8, %g1 50 cmp %o1, %g1 51 be,pn %xcc, 3f 52 add %o0, 7, %g1 53 mov 0, %g3 54 0: 55 brz,pn %o2, 2f 56 mov 0, %g2 57 1: 58 ldub [%g3 + %o1], %g1 59 add %g2, 1, %g2 60 cmp %o2, %g2 61 stb %g1, [%g3 + %o0] 62 bne,pt %xcc, 1b 63 mov %g2, %g3 64 2: 65 jmp %o7 + 8 ! exit point 66 mov %o3, %o0 67 3: 68 and %g1, -8, %g1 69 cmp %o0, %g1 70 bne,pt %xcc, 0b 71 mov 0, %g3 72 srlx %o2, 3, %g4 73 brz,pn %g4, 5f 74 mov 0, %g5 75 4: 76 sllx %g3, 3, %g2 77 add %g5, 1, %g3 78 ldx [%o1 + %g2], %g1 79 mov %g3, %g5 80 cmp %g4, %g3 81 bne,pt %xcc, 4b 82 stx %g1, [%o0 + %g2] 83 5: 84 and %o2, 7, %o2 85 brz,pn %o2, 2b 86 sllx %g4, 3, %g1 87 mov 0, %g2 88 add %g1, %o0, %o0 89 add %g1, %o1, %g4 90 mov 0, %g3 91 6: 92 ldub [%g2 + %g4], %g1 93 stb %g1, [%g2 + %o0] 94 add %g3, 1, %g2 95 cmp %o2, %g2 96 bne,pt %xcc, 6b 97 mov %g2, %g3 98 99 jmp %o7 + 8 ! exit point 100 mov %o3, %o0 55 0: 56 brz,pn %o2, 2f 57 mov 0, %g2 58 59 1: 60 ldub [%g3 + %o1], %g1 61 add %g2, 1, %g2 62 cmp %o2, %g2 63 stb %g1, [%g3 + %o0] 64 bne,pt %xcc, 1b 65 mov %g2, %g3 66 67 2: 68 jmp %o7 + 8 ! exit point 69 mov %o3, %o0 70 71 3: 72 and %g1, -8, %g1 73 cmp %o0, %g1 74 bne,pt %xcc, 0b 75 mov 0, %g3 76 srlx %o2, 3, %g4 77 brz,pn %g4, 5f 78 mov 0, %g5 79 80 4: 81 sllx %g3, 3, %g2 82 add %g5, 1, %g3 83 ldx [%o1 + %g2], %g1 84 mov %g3, %g5 85 cmp %g4, %g3 86 bne,pt %xcc, 4b 87 stx %g1, [%o0 + %g2] 88 89 5: 90 and %o2, 7, %o2 91 brz,pn %o2, 2b 92 sllx %g4, 3, %g1 93 mov 0, %g2 94 add %g1, %o0, %o0 95 add %g1, %o1, %g4 96 mov 0, %g3 97 98 6: 99 ldub [%g2 + %g4], %g1 100 stb %g1, [%g2 + %o0] 101 add %g3, 1, %g2 102 cmp %o2, %g2 103 bne,pt %xcc, 6b 104 mov %g2, %g3 105 106 jmp %o7 + 8 ! exit point 107 mov %o3, %o0 101 108 102 109 jump_to_kernel: … … 107 114 * 3. Flush instruction pipeline. 108 115 */ 109 116 110 117 /* 111 118 * US3 processors have a write-invalidate cache, so explicitly 112 119 * invalidating it is not required. Whether to invalidate I-cache 113 * or not is decided according to the value of the global114 * "subarchitecture" variable (set in the bootstrap).120 * or not is decided according to the value of the 5th argument 121 * (subarchitecture). 115 122 */ 116 set subarchitecture, %g2 117 ldub [%g2], %g2 118 cmp %g2, 3 123 cmp %i4, 3 119 124 be %xcc, 1f 120 125 nop 121 0: 122 call icache_flush 123 nop 124 1: 125 membar #StoreStore 126 127 0: 128 call icache_flush 129 nop 130 131 1: 132 membar #StoreStore 126 133 127 134 /* 128 135 * Flush the instruction pipeline. 129 136 */ 130 flush 131 137 flush %i7 138 132 139 mov %o0, %l1 133 140 mov %o1, %o0 134 141 mov %o2, %o1 135 142 mov %o3, %o2 136 jmp %l1 143 jmp %l1 ! jump to kernel 137 144 nop 138 145 139 #define ICACHE_SIZE 140 #define ICACHE_LINE_SIZE 141 #define ICACHE_SET_BIT 142 #define ASI_ICACHE_TAG 146 #define ICACHE_SIZE 8192 147 #define ICACHE_LINE_SIZE 32 148 #define ICACHE_SET_BIT (1 << 13) 149 #define ASI_ICACHE_TAG 0x67 143 150 144 151 # Flush I-cache 145 152 icache_flush: 146 set ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1 147 stxa %g0, [%g1] ASI_ICACHE_TAG 148 0: membar #Sync 149 subcc %g1, ICACHE_LINE_SIZE, %g1 150 bnz,pt %xcc, 0b 151 stxa %g0, [%g1] ASI_ICACHE_TAG 152 membar #Sync 153 set ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1 154 stxa %g0, [%g1] ASI_ICACHE_TAG 155 156 0: 157 membar #Sync 158 subcc %g1, ICACHE_LINE_SIZE, %g1 159 bnz,pt %xcc, 0b 160 161 stxa %g0, [%g1] ASI_ICACHE_TAG 162 membar #Sync 153 163 retl 154 164 ! SF Erratum #51 155 165 nop 166 156 167 .global ofw 157 168 ofw: … … 159 170 set ofw_cif, %l0 160 171 ldx [%l0], %l0 161 172 162 173 rdpr %pstate, %l1 163 174 and %l1, ~PSTATE_AM_BIT, %l2 164 175 wrpr %l2, 0, %pstate 165 176 166 177 jmpl %l0, %o7 167 178 mov %i0, %o0 168 179 169 180 wrpr %l1, 0, %pstate 170 181 171 182 ret 172 183 restore %o0, 0, %o0 -
boot/arch/sparc64/loader/asm.h
r207e208e rbc7d44c 34 34 #include "main.h" 35 35 36 #define PAGE_WIDTH 37 #define PAGE_SIZE 36 #define PAGE_WIDTH 14 37 #define PAGE_SIZE (1 << PAGE_WIDTH) 38 38 39 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))39 #define BALLOC_MAX_SIZE (128 * 1024) 40 40 41 41 extern void halt(void); 42 42 extern void jump_to_kernel(void *entry, uint64_t cfg, bootinfo_t *bootinfo, 43 unsigned int bootinfo_size) __attribute__((noreturn));43 unsigned int bootinfo_size, uint8_t subarchitecture) __attribute__((noreturn)); 44 44 45 45 #endif -
boot/arch/sparc64/loader/boot.S
r207e208e rbc7d44c 31 31 #include <register.h> 32 32 33 #define INITIAL_STACK_SIZE 33 #define INITIAL_STACK_SIZE 8192 34 34 35 #define NWINDOWS 35 #define NWINDOWS 8 36 36 37 37 .register %g2, #scratch … … 57 57 .half 0 58 58 .half 0 59 59 60 .global silo_ramdisk_image 60 61 silo_ramdisk_image: 61 62 .word 0 63 62 64 .global silo_ramdisk_size 63 65 silo_ramdisk_size: … … 65 67 66 68 .align 8 67 1: 69 1: 68 70 /* 69 71 * Disable interrupts and disable address masking. … … 71 73 wrpr %g0, PSTATE_PRIV_BIT, %pstate 72 74 73 wrpr %g0, NWINDOWS - 2, %cansave 74 wrpr %g0, 0, %canrestore 75 wrpr %g0, 0, %otherwin 76 wrpr %g0, NWINDOWS - 1, %cleanwin 77 75 wrpr %g0, NWINDOWS - 2, %cansave ! set maximum saveable windows 76 wrpr %g0, 0, %canrestore ! get rid of windows we will never need again 77 wrpr %g0, 0, %otherwin ! make sure the window state is consistent 78 wrpr %g0, NWINDOWS - 1, %cleanwin ! prevent needless clean_window traps for kernel 79 78 80 set initial_stack_top, %sp 79 81 add %sp, -STACK_BIAS, %sp 80 82 81 83 set ofw_cif, %l0 82 83 call ofw_init 84 85 call ofw_init ! initialize OpenFirmware 84 86 stx %o4, [%l0] 85 87 … … 90 92 initial_stack: 91 93 .space INITIAL_STACK_SIZE 94 92 95 initial_stack_top: 93 96 .space STACK_WINDOW_SAVE_AREA_SIZE -
boot/arch/sparc64/loader/main.c
r207e208e rbc7d44c 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2006 Jakub Jermar 4 4 * All rights reserved. 5 5 * … … 28 28 */ 29 29 30 #include "main.h" 30 #include "main.h" 31 31 #include <printf.h> 32 32 #include "asm.h" … … 39 39 #include <macros.h> 40 40 #include <string.h> 41 42 bootinfo_t bootinfo; 43 44 component_t components[COMPONENTS]; 45 46 char *release = STRING(RELEASE); 41 #include <memstr.h> 42 43 static bootinfo_t bootinfo; 44 static component_t components[COMPONENTS]; 45 static char *release = STRING(RELEASE); 47 46 48 47 #ifdef REVISION 49 char *revision = ", revision " STRING(REVISION);48 static char *revision = ", revision " STRING(REVISION); 50 49 #else 51 char *revision = "";50 static char *revision = ""; 52 51 #endif 53 52 54 53 #ifdef TIMESTAMP 55 char *timestamp = "\nBuilt on " STRING(TIMESTAMP);54 static char *timestamp = "\nBuilt on " STRING(TIMESTAMP); 56 55 #else 57 char *timestamp = "";56 static char *timestamp = ""; 58 57 #endif 59 58 60 59 /** UltraSPARC subarchitecture - 1 for US, 3 for US3 */ 61 uint8_t subarchitecture;60 static uint8_t subarchitecture; 62 61 63 62 /** … … 65 64 * MID_SHIFT bits to the right 66 65 */ 67 uint16_t mid_mask;66 static uint16_t mid_mask; 68 67 69 68 /** Print version information. */ … … 76 75 77 76 /* the lowest ID (read from the VER register) of some US3 CPU model */ 78 #define FIRST_US3_CPU 77 #define FIRST_US3_CPU 0x14 79 78 80 79 /* the greatest ID (read from the VER register) of some US3 CPU model */ 81 #define LAST_US3_CPU 80 #define LAST_US3_CPU 0x19 82 81 83 82 /* UltraSPARC IIIi processor implementation code */ 84 #define US_IIIi_CODE 83 #define US_IIIi_CODE 0x15 85 84 86 85 /** … … 91 90 { 92 91 uint64_t v; 93 asm volatile ("rdpr %%ver, %0\n" : "=r" (v)); 92 asm volatile ( 93 "rdpr %%ver, %0\n" 94 : "=r" (v) 95 ); 94 96 95 97 v = (v << 16) >> 48; … … 103 105 subarchitecture = SUBARCH_US; 104 106 mid_mask = (1 << 5) - 1; 105 } else {107 } else 106 108 printf("\nThis CPU is not supported by HelenOS."); 107 }108 109 } 109 110 … … 113 114 void *balloc_base; 114 115 unsigned int top = 0; 115 int i, j; 116 116 unsigned int i; 117 unsigned int j; 118 117 119 version_print(); 118 120 119 121 detect_subarchitecture(); 120 122 init_components(components); 121 123 122 124 if (!ofw_get_physmem_start(&bootinfo.physmem_start)) { 123 125 printf("Error: unable to get start of physical memory.\n"); 124 126 halt(); 125 127 } 126 128 127 129 if (!ofw_memmap(&bootinfo.memmap)) { 128 130 printf("Error: unable to get memory map, halting.\n"); 129 131 halt(); 130 132 } 131 133 132 134 if (bootinfo.memmap.total == 0) { 133 135 printf("Error: no memory detected, halting.\n"); 134 136 halt(); 135 137 } 136 138 137 139 /* 138 140 * SILO for some reason adds 0x400000 and subtracts … … 143 145 silo_ramdisk_image += bootinfo.physmem_start; 144 146 silo_ramdisk_image -= 0x400000; 145 /* Install 1:1 mapping for the ramdisk. */ 146 if (ofw_map((void *)((uintptr_t) silo_ramdisk_image), 147 (void *)((uintptr_t) silo_ramdisk_image), 147 148 /* Install 1:1 mapping for the RAM disk. */ 149 if (ofw_map((void *) ((uintptr_t) silo_ramdisk_image), 150 (void *) ((uintptr_t) silo_ramdisk_image), 148 151 silo_ramdisk_size, -1) != 0) { 149 printf("Failed to map ramdisk.\n");152 printf("Failed to map RAM disk.\n"); 150 153 halt(); 151 154 } 152 155 } 153 156 154 printf("\nSystem info\n"); 155 printf(" memory: %dM starting at %P\n", 157 printf("\nMemory statistics (total %d MB, starting at %P)\n", 156 158 bootinfo.memmap.total >> 20, bootinfo.physmem_start); 157 158 printf("\nMemory statistics\n"); 159 printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS); 159 printf(" %P: kernel entry point\n", KERNEL_VIRTUAL_ADDRESS); 160 160 printf(" %P: boot info structure\n", &bootinfo); 161 161 … … 176 176 break; 177 177 } 178 178 179 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = 179 180 base + top; … … 187 188 top += components[i].size; 188 189 } 189 190 j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */ 191 190 191 /* Do not consider RAM disk */ 192 j = bootinfo.taskmap.count - 1; 193 192 194 if (silo_ramdisk_image) { 193 /* Treat the ramdisk as the last bootinfo task. */195 /* Treat the RAM disk as the last bootinfo task. */ 194 196 if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { 195 printf("Skipping ramdisk.\n");197 printf("Skipping RAM disk.\n"); 196 198 goto skip_ramdisk; 197 199 } 200 198 201 top = ALIGN_UP(top, PAGE_SIZE); 199 202 bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = … … 202 205 silo_ramdisk_size; 203 206 bootinfo.taskmap.count++; 204 printf("\nCopying ramdisk..."); 207 printf("\nCopying RAM disk..."); 208 205 209 /* 206 210 * Claim and map the whole ramdisk as it may exceed the area … … 210 214 (void) ofw_map(bootinfo.physmem_start + base + top, base + top, 211 215 silo_ramdisk_size, -1); 212 memmove(base + top, (void *) ((uintptr_t)silo_ramdisk_image),216 memmove(base + top, (void *) ((uintptr_t) silo_ramdisk_image), 213 217 silo_ramdisk_size); 218 214 219 printf("done.\n"); 215 220 top += silo_ramdisk_size; 216 221 } 217 222 skip_ramdisk: 218 223 219 224 /* 220 225 * Now we can proceed to copy the components. We do it in reverse order … … 222 227 * with base. 223 228 */ 224 printf("\nCopying bootinfo tasks\n");229 printf("\nCopying tasks..."); 225 230 for (i = COMPONENTS - 1; i > 0; i--, j--) { 226 printf(" %s...", components[i].name);227 231 printf("%s ", components[i].name); 232 228 233 /* 229 234 * At this point, we claim the physical memory that we are … … 240 245 bootinfo.taskmap.tasks[j].addr, 241 246 ALIGN_UP(components[i].size, PAGE_SIZE)); 242 243 memcpy((void *) bootinfo.taskmap.tasks[j].addr,247 248 memcpy((void *) bootinfo.taskmap.tasks[j].addr, 244 249 components[i].start, components[i].size); 245 printf("done.\n"); 246 } 247 250 251 } 252 printf(".\n"); 253 248 254 printf("\nCopying kernel..."); 249 255 (void) ofw_claim_phys(bootinfo.physmem_start + base, … … 251 257 memcpy(base, components[0].start, components[0].size); 252 258 printf("done.\n"); 253 259 254 260 /* 255 261 * Claim and map the physical memory for the boot allocator. … … 261 267 (void) ofw_map(bootinfo.physmem_start + balloc_base, balloc_base, 262 268 BALLOC_MAX_SIZE, -1); 263 balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base); 264 269 balloc_init(&bootinfo.ballocs, (uintptr_t) balloc_base, 270 (uintptr_t) balloc_base); 271 265 272 printf("\nCanonizing OpenFirmware device tree..."); 266 273 bootinfo.ofw_root = ofw_tree_build(); 267 274 printf("done.\n"); 268 275 269 276 #ifdef CONFIG_AP 270 277 printf("\nChecking for secondary processors..."); 271 if (!ofw_cpu( ))278 if (!ofw_cpu(mid_mask, bootinfo.physmem_start)) 272 279 printf("Error: unable to get CPU properties\n"); 273 280 printf("done.\n"); 274 281 #endif 275 282 276 283 ofw_setup_palette(); 277 284 278 285 printf("\nBooting the kernel...\n"); 279 286 jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, 280 287 bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, 281 sizeof(bootinfo) );288 sizeof(bootinfo), subarchitecture); 282 289 } -
boot/arch/sparc64/loader/main.h
r207e208e rbc7d44c 35 35 #include <types.h> 36 36 37 #define KERNEL_VIRTUAL_ADDRESS 0x40000037 #define KERNEL_VIRTUAL_ADDRESS 0x400000 38 38 39 #define TASKMAP_MAX_RECORDS 3239 #define TASKMAP_MAX_RECORDS 32 40 40 41 41 /** Size of buffer for storing task name in task_t. */ 42 #define BOOTINFO_TASK_NAME_BUFLEN 3242 #define BOOTINFO_TASK_NAME_BUFLEN 32 43 43 44 #define BSP_PROCESSOR 45 #define AP_PROCESSOR 44 #define BSP_PROCESSOR 1 45 #define AP_PROCESSOR 0 46 46 47 #define SUBARCH_US 48 #define SUBARCH_US3 47 #define SUBARCH_US 1 48 #define SUBARCH_US3 3 49 49 50 50 typedef struct { … … 70 70 extern uint32_t silo_ramdisk_size; 71 71 72 extern bootinfo_t bootinfo;73 74 72 extern void start(void); 75 73 extern void bootstrap(void); -
boot/arch/sparc64/loader/ofwarch.c
r207e208e rbc7d44c 30 30 /** 31 31 * @file 32 * @brief 32 * @brief Architecture dependent parts of OpenFirmware interface. 33 33 */ 34 34 … … 40 40 #include "main.h" 41 41 #include "asm.h" 42 43 /* these tho variables will be set by the detect_subarchitecture function */44 extern uint8_t subarchitecture;45 extern uint16_t mid_mask;46 42 47 43 void write(const char *str, const int len) … … 65 61 * except for the current CPU. 66 62 * 67 * @param child The first child of the OFW tree node whose children 68 * represent CPUs to be woken up. 69 * @param current_mid MID of the current CPU, the current CPU will 70 * (of course) not be woken up. 71 * @return Number of CPUs which have the same parent node as 72 * "child". 63 * @param child The first child of the OFW tree node whose children 64 * represent CPUs to be woken up. 65 * @param current_mid MID of the current CPU, the current CPU will 66 * (of course) not be woken up. 67 * @param physmem_start Starting address of the physical memory. 68 * 69 * @return Number of CPUs which have the same parent node as 70 * "child". 71 * 73 72 */ 74 static int wake_cpus_in_node(phandle child, uint64_t current_mid) 73 static int wake_cpus_in_node(phandle child, uint64_t current_mid, 74 uintptr_t physmem_start) 75 75 { 76 76 int cpus; 77 char type_name[BUF_SIZE];78 77 79 for (cpus = 0; child != 0 && child != -1;78 for (cpus = 0; (child != 0) && (child != -1); 80 79 child = ofw_get_peer_node(child), cpus++) { 80 char type_name[BUF_SIZE]; 81 81 82 if (ofw_get_property(child, "device_type", type_name, 82 83 sizeof(type_name)) > 0) { … … 88 89 * "cpuid" for US-IV 89 90 */ 90 if (ofw_get_property( 91 child, "upa-portid", 92 &mid, sizeof(mid)) <= 0 93 && ofw_get_property(child, "portid", 94 &mid, sizeof(mid)) <= 0 95 && ofw_get_property(child, "cpuid", 96 &mid, sizeof(mid)) <= 0) 91 if ((ofw_get_property(child, "upa-portid", &mid, sizeof(mid)) <= 0) 92 && (ofw_get_property(child, "portid", &mid, sizeof(mid)) <= 0) 93 && (ofw_get_property(child, "cpuid", &mid, sizeof(mid)) <= 0)) 97 94 continue; 98 95 99 96 if (current_mid != mid) { 100 97 /* … … 103 100 (void) ofw_call("SUNW,start-cpu", 3, 1, 104 101 NULL, child, KERNEL_VIRTUAL_ADDRESS, 105 bootinfo.physmem_start | 106 AP_PROCESSOR); 102 physmem_start | AP_PROCESSOR); 107 103 } 108 104 } 109 105 } 110 106 } 111 107 112 108 return cpus; 113 109 } … … 116 112 * Finds out the current CPU's MID and wakes up all AP processors. 117 113 */ 118 int ofw_cpu( void)114 int ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start) 119 115 { 120 int cpus; 121 phandle node; 122 phandle subnode; 123 phandle cpus_parent; 124 phandle cmp; 125 char name[BUF_SIZE]; 126 127 /* get the current CPU MID */ 116 /* Get the current CPU MID */ 128 117 uint64_t current_mid; 129 118 130 asm volatile ("ldxa [%1] %2, %0\n" 131 : "=r" (current_mid) 132 : "r" (0), "i" (ASI_ICBUS_CONFIG)); 119 asm volatile ( 120 "ldxa [%1] %2, %0\n" 121 : "=r" (current_mid) 122 : "r" (0), "i" (ASI_ICBUS_CONFIG) 123 ); 124 133 125 current_mid >>= ICBUS_CONFIG_MID_SHIFT; 134 135 126 current_mid &= mid_mask; 136 137 /* wake up CPUs */138 127 139 cpus_parent = ofw_find_device("/ssm@0,0"); 140 if (cpus_parent == 0 || cpus_parent == -1) { 128 /* Wake up the CPUs */ 129 130 phandle cpus_parent = ofw_find_device("/ssm@0,0"); 131 if ((cpus_parent == 0) || (cpus_parent == -1)) 141 132 cpus_parent = ofw_find_device("/"); 142 } 143 144 node = ofw_get_child_node(cpus_parent); 145 cpus = wake_cpus_in_node(node, current_mid); 146 while (node != 0 && node != -1) { 133 134 phandle node = ofw_get_child_node(cpus_parent); 135 int cpus = wake_cpus_in_node(node, current_mid, physmem_start); 136 while ((node != 0) && (node != -1)) { 137 char name[BUF_SIZE]; 138 147 139 if (ofw_get_property(node, "name", name, 148 140 sizeof(name)) > 0) { 149 141 if (strcmp(name, "cmp") == 0) { 150 subnode = ofw_get_child_node(node);142 phandle subnode = ofw_get_child_node(node); 151 143 cpus += wake_cpus_in_node(subnode, 152 current_mid );144 current_mid, physmem_start); 153 145 } 154 146 } … … 157 149 158 150 return cpus; 159 160 151 } 161 152 162 153 /** Get physical memory starting address. 163 154 * 164 * @param start 165 * 155 * @param start Pointer to variable where the physical memory starting 156 * address will be stored. 166 157 * 167 * @return Non-zero on succes, zero on failure. 158 * @return Non-zero on succes, zero on failure. 159 * 168 160 */ 169 161 int ofw_get_physmem_start(uintptr_t *start) 170 162 { 171 163 uint32_t memreg[4]; 172 173 164 if (ofw_get_property(ofw_memory, "reg", &memreg, sizeof(memreg)) <= 0) 174 165 return 0; 175 166 176 167 *start = (((uint64_t) memreg[0]) << 32) | memreg[1]; 177 168 return 1; 178 169 } 179 -
boot/arch/sparc64/loader/ofwarch.h
r207e208e rbc7d44c 33 33 #include "types.h" 34 34 35 #define OFW_ADDRESS_CELLS 36 #define OFW_SIZE_CELLS 35 #define OFW_ADDRESS_CELLS 2 36 #define OFW_SIZE_CELLS 2 37 37 38 extern int ofw_cpu( void);39 extern int ofw_get_physmem_start(uintptr_t *start); 38 extern int ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start); 39 extern int ofw_get_physmem_start(uintptr_t *start); 40 40 41 41 #endif -
boot/arch/sparc64/loader/register.h
r207e208e rbc7d44c 30 30 #define BOOT_sparc64_REGISTER_H_ 31 31 32 #define PSTATE_IE_BIT 233 #define PSTATE_PRIV_BIT 34 #define PSTATE_AM_BIT 832 #define PSTATE_IE_BIT 2 33 #define PSTATE_PRIV_BIT 4 34 #define PSTATE_AM_BIT 8 35 35 36 #define ASI_ICBUS_CONFIG 37 #define ICBUS_CONFIG_MID_SHIFT 36 #define ASI_ICBUS_CONFIG 0x4a 37 #define ICBUS_CONFIG_MID_SHIFT 17 38 38 39 39 #endif -
boot/arch/sparc64/loader/stack.h
r207e208e rbc7d44c 30 30 #define BOOT_sparc64_STACK_H_ 31 31 32 #define STACK_ALIGNMENT 33 #define STACK_BIAS 34 #define STACK_WINDOW_SAVE_AREA_SIZE (16*8)32 #define STACK_ALIGNMENT 16 33 #define STACK_BIAS 2047 34 #define STACK_WINDOW_SAVE_AREA_SIZE (16 * 8) 35 35 36 36 #endif -
boot/genarch/balloc.c
r207e208e rbc7d44c 28 28 29 29 #include <balloc.h> 30 #include <asm.h> 30 31 #include <types.h> 31 32 #include <align.h> 32 33 33 34 static ballocs_t *ballocs; 35 static uintptr_t phys_base; 34 36 35 void balloc_init(ballocs_t *b , uintptr_tbase)37 void balloc_init(ballocs_t *ball, uintptr_t base, uintptr_t kernel_base) 36 38 { 37 ballocs = b; 38 ballocs->base = base; 39 ballocs = ball; 40 phys_base = base; 41 ballocs->base = kernel_base; 39 42 ballocs->size = 0; 40 43 } … … 42 45 void *balloc(size_t size, size_t alignment) 43 46 { 44 uintptr_t addr;45 46 47 /* Enforce minimal alignment. */ 47 48 alignment = ALIGN_UP(alignment, 4); 48 49 49 addr = ballocs->base + ALIGN_UP(ballocs->size, alignment);50 50 uintptr_t addr = phys_base + ALIGN_UP(ballocs->size, alignment); 51 51 52 if (ALIGN_UP(ballocs->size, alignment) + size > BALLOC_MAX_SIZE) 52 53 return NULL; 53 54 54 55 ballocs->size = ALIGN_UP(ballocs->size, alignment) + size; 55 56 56 57 return (void *) addr; 57 58 } 59 60 void *balloc_rebase(void *ptr) 61 { 62 return (void *) ((uintptr_t) ptr - phys_base + ballocs->base); 63 } -
boot/genarch/balloc.h
r207e208e rbc7d44c 32 32 #include <types.h> 33 33 34 #define BALLOC_MAX_SIZE (128 * 1024)35 36 34 typedef struct { 37 35 uintptr_t base; … … 39 37 } ballocs_t; 40 38 41 extern void balloc_init(ballocs_t *b , uintptr_tbase);39 extern void balloc_init(ballocs_t *ball, uintptr_t base, uintptr_t kernel_base); 42 40 extern void *balloc(size_t size, size_t alignment); 41 extern void *balloc_rebase(void *ptr); 43 42 44 43 #endif -
boot/genarch/ofw.c
r207e208e rbc7d44c 33 33 #include <types.h> 34 34 35 #define RED(i) (((i) >> 5) & ((1 << 3) - 1)) 36 #define GREEN(i) (((i) >> 3) & ((1 << 2) - 1)) 37 #define BLUE(i) ((i) & ((1 << 3) - 1)) 38 #define CLIP(i) ((i) <= 255 ? (i) : 255) 39 35 40 uintptr_t ofw_cif; 36 41 … … 85 90 /** Perform a call to OpenFirmware client interface. 86 91 * 87 * @param service String identifying the service requested. 88 * @param nargs Number of input arguments. 89 * @param nret Number of output arguments. This includes the return 90 * value. 91 * @param rets Buffer for output arguments or NULL. The buffer must 92 * accommodate nret - 1 items. 93 * 94 * @return Return value returned by the client interface. 92 * @param service String identifying the service requested. 93 * @param nargs Number of input arguments. 94 * @param nret Number of output arguments. This includes the return 95 * value. 96 * @param rets Buffer for output arguments or NULL. The buffer must 97 * accommodate nret - 1 items. 98 * 99 * @return Return value returned by the client interface. 100 * 95 101 */ 96 102 unsigned long … … 221 227 } 222 228 223 void *ofw_claim_virt(const void *virt, const int len)229 void *ofw_claim_virt(const void *virt, const unsigned int len) 224 230 { 225 231 ofw_arg_t retaddr; … … 234 240 } 235 241 236 void *ofw_claim_phys(const void *phys, const int len) 237 { 238 ofw_arg_t retaddr[2]; 239 int shift; 240 242 static void *ofw_claim_phys_internal(const void *phys, const unsigned int len, const unsigned int alignment) 243 { 244 /* 245 * Note that the return value check will help 246 * us to discover conflicts between OpenFirmware 247 * allocations and our use of physical memory. 248 * It is better to detect collisions here 249 * than to cope with weird errors later. 250 * 251 * So this is really not to make the loader 252 * more generic; it is here for debugging 253 * purposes. 254 */ 255 241 256 if (sizeof(unative_t) == 8) { 242 shift = 32; 257 ofw_arg_t retaddr[2]; 258 int shift = 32; 259 243 260 if (ofw_call("call-method", 6, 3, retaddr, "claim", 244 ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift,261 ofw_memory_prop, alignment, len, ((uintptr_t) phys) >> shift, 245 262 ((uintptr_t) phys) & ((uint32_t) -1)) != 0) { 246 /*247 * Note that this will help us to discover248 * conflicts between OpenFirmware allocations249 * and our use of physical memory.250 * It is better to detect collisions here251 * than to cope with weird errors later.252 *253 * So this is really not to make the loader254 * more generic; it is here for debugging255 * purposes.256 */257 263 puts("Error: memory method claim() failed, halting.\n"); 258 264 halt(); 259 265 } 266 267 return (void *) ((retaddr[0] << shift) | retaddr[1]); 260 268 } else { 261 shift = 0; 262 /* 263 * FIXME: the number of arguments is probably different... 264 */ 265 puts("Error: 32-bit ofw_claim_phys not implemented.\n"); 266 halt(); 267 } 268 269 return (void *) ((retaddr[0] << shift) | retaddr[1]); 270 } 271 272 int ofw_map(const void *phys, const void *virt, const int size, const int mode) 269 ofw_arg_t retaddr[1]; 270 271 if (ofw_call("call-method", 5, 2, retaddr, "claim", 272 ofw_memory_prop, alignment, len, (uintptr_t) phys) != 0) { 273 puts("Error: memory method claim() failed, halting.\n"); 274 halt(); 275 } 276 277 return (void *) retaddr[0]; 278 } 279 } 280 281 void *ofw_claim_phys(const void *phys, const unsigned int len) 282 { 283 return ofw_claim_phys_internal(phys, len, 0); 284 } 285 286 void *ofw_claim_phys_any(const unsigned int len, const unsigned int alignment) 287 { 288 return ofw_claim_phys_internal(NULL, len, alignment); 289 } 290 291 int ofw_map(const void *phys, const void *virt, const unsigned int size, const int mode) 273 292 { 274 293 uintptr_t phys_hi, phys_lo; … … 314 333 315 334 /* 316 317 318 319 320 335 * This is a hot fix of the issue which occurs on machines 336 * where there are holes in the physical memory (such as 337 * SunBlade 1500). Should we detect a hole in the physical 338 * memory, we will ignore any memory detected behind 339 * the hole and pretend the hole does not exist. 321 340 */ 322 341 if ((map->count > 0) && (map->zones[map->count - 1].start + … … 335 354 } 336 355 337 int ofw_screen(screen_t *screen)338 {339 char device_name[BUF_SIZE];340 uint32_t virtaddr;341 342 if (ofw_get_property(ofw_aliases, "screen", device_name,343 sizeof(device_name)) <= 0)344 return false;345 346 phandle device = ofw_find_device(device_name);347 if (device == -1)348 return false;349 350 if (ofw_get_property(device, "address", &virtaddr,351 sizeof(virtaddr)) <= 0)352 return false;353 354 screen->addr = (void *) ((uintptr_t) virtaddr);355 356 if (ofw_get_property(device, "width", &screen->width,357 sizeof(screen->width)) <= 0)358 return false;359 360 if (ofw_get_property(device, "height", &screen->height,361 sizeof(screen->height)) <= 0)362 return false;363 364 if (ofw_get_property(device, "depth", &screen->bpp,365 sizeof(screen->bpp)) <= 0)366 return false;367 368 if (ofw_get_property(device, "linebytes", &screen->scanline,369 sizeof(screen->scanline)) <= 0)370 return false;371 372 return true;373 }374 375 #define RED(i) (((i) >> 5) & ((1 << 3) - 1))376 #define GREEN(i) (((i) >> 3) & ((1 << 2) - 1))377 #define BLUE(i) ((i) & ((1 << 3) - 1))378 #define CLIP(i) ((i) <= 255 ? (i) : 255)379 380 381 356 /** 382 357 * Sets up the palette for the 8-bit color depth configuration so that the … … 392 367 char device_name[BUF_SIZE]; 393 368 394 /* resolve alias */369 /* Resolve alias */ 395 370 if (ofw_get_property(ofw_aliases, "screen", device_name, 396 371 sizeof(device_name)) <= 0) 397 372 return false; 398 373 399 /* for depth greater than 8 it makes no sense to set up the palette */374 /* For depth greater than 8 it makes no sense to set up the palette */ 400 375 uint32_t depth; 401 376 phandle device = ofw_find_device(device_name); … … 407 382 return false; 408 383 409 /* required in order to be able to make a method call */384 /* Required in order to be able to make a method call */ 410 385 ihandle screen = ofw_open(device_name); 411 386 if (screen == -1) 412 387 return false; 413 388 414 /* setup the palette so that the (inverted) 3:2:3 scheme is usable */389 /* Setup the palette so that the (inverted) 3:2:3 scheme is usable */ 415 390 unsigned int i; 416 391 for (i = 0; i < 256; i++) -
boot/genarch/ofw.h
r207e208e rbc7d44c 33 33 #include <stdarg.h> 34 34 35 #define BUF_SIZE 35 #define BUF_SIZE 1024 36 36 37 #define MEMMAP_MAX_RECORDS 37 #define MEMMAP_MAX_RECORDS 32 38 38 39 #define MAX_OFW_ARGS 39 #define MAX_OFW_ARGS 12 40 40 41 41 typedef unative_t ofw_arg_t; … … 47 47 */ 48 48 typedef struct { 49 ofw_arg_t service; 50 ofw_arg_t nargs; 51 ofw_arg_t nret; 52 ofw_arg_t args[MAX_OFW_ARGS]; 49 ofw_arg_t service; /**< Command name. */ 50 ofw_arg_t nargs; /**< Number of in arguments. */ 51 ofw_arg_t nret; /**< Number of out arguments. */ 52 ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments. */ 53 53 } ofw_args_t; 54 54 … … 63 63 memzone_t zones[MEMMAP_MAX_RECORDS]; 64 64 } memmap_t; 65 66 typedef struct {67 void *addr;68 uint32_t width;69 uint32_t height;70 uint32_t bpp;71 uint32_t scanline;72 } screen_t;73 74 typedef struct {75 void *addr;76 uint32_t size;77 } macio_t;78 65 79 66 typedef struct { … … 118 105 extern void *ofw_translate(const void *virt); 119 106 extern int ofw_translate_failed(ofw_arg_t flag); 120 extern void *ofw_claim_virt(const void *virt, const int len); 121 extern void *ofw_claim_phys(const void *virt, const int len); 122 extern int ofw_map(const void *phys, const void *virt, const int size, const int mode); 107 extern void *ofw_claim_virt(const void *virt, const unsigned int len); 108 extern void *ofw_claim_phys(const void *virt, const unsigned int len); 109 extern void *ofw_claim_phys_any(const unsigned int len, const unsigned int alignment); 110 extern int ofw_map(const void *phys, const void *virt, const unsigned int size, const int mode); 123 111 extern int ofw_memmap(memmap_t *map); 124 extern int ofw_screen(screen_t *screen);125 extern int ofw_macio(macio_t *macio);126 112 extern int ofw_setup_palette(void); 127 113 extern void ofw_quiesce(void); -
boot/genarch/ofw_tree.c
r207e208e rbc7d44c 29 29 #include <ofw_tree.h> 30 30 #include <ofw.h> 31 #include <ofwarch.h> 31 32 #include <types.h> 32 33 #include <string.h> 33 34 #include <balloc.h> 34 35 #include <asm.h> 35 36 #define MAX_PATH_LEN 256 36 #include <memstr.h> 37 38 #define MAX_PATH_LEN 256 37 39 38 40 static ofw_tree_node_t *ofw_tree_node_alloc(void) … … 49 51 static void *ofw_tree_space_alloc(size_t size) 50 52 { 51 char *addr;52 53 53 /* 54 54 * What we do here is a nasty hack :-) … … 61 61 * behind the requested memory. 62 62 */ 63 addr = balloc(size + 1, size);63 char *addr = balloc(size + 1, size); 64 64 if (addr) 65 65 addr[size] = '\0'; 66 66 67 return addr; 67 68 } … … 75 76 * order to prevent stack from overflowing. 76 77 * 77 * @param current_node Pointer to uninitialized ofw_tree_node structure that 78 * will become the memory represenation of 'current'. 79 * @param parent_node Parent ofw_tree_node structure or NULL in case of root 80 * node. 81 * @param current OpenFirmware phandle to the current device tree node. 78 * @param current_node Pointer to uninitialized ofw_tree_node structure that 79 * will become the memory represenation of 'current'. 80 * @param parent_node Parent ofw_tree_node structure or NULL in case of root 81 * node. 82 * @param current OpenFirmware phandle to the current device tree node. 83 * 82 84 */ 83 85 static void ofw_tree_node_process(ofw_tree_node_t *current_node, 84 86 ofw_tree_node_t *parent_node, phandle current) 85 87 { 86 static char path[MAX_PATH_LEN + 1];87 static char name[OFW_TREE_PROPERTY_MAX_NAMELEN];88 static char name2[OFW_TREE_PROPERTY_MAX_NAMELEN];89 phandle peer;90 phandle child;91 size_t len;92 int i;93 94 88 while (current_node) { 95 89 /* 96 90 * Initialize node. 97 91 */ 98 current_node->parent = parent_node;92 current_node->parent = (ofw_tree_node_t *) balloc_rebase(parent_node); 99 93 current_node->peer = NULL; 100 94 current_node->child = NULL; … … 103 97 current_node->property = NULL; 104 98 current_node->device = NULL; 105 99 106 100 /* 107 101 * Get the disambigued name. 108 102 */ 109 len = ofw_package_to_path(current, path, MAX_PATH_LEN); 103 static char path[MAX_PATH_LEN + 1]; 104 size_t len = ofw_package_to_path(current, path, MAX_PATH_LEN); 110 105 if (len == -1) 111 106 return; 112 107 113 108 path[len] = '\0'; 114 for (i = len - 1; i >= 0 && path[i] != '/'; i--) 115 ; 116 i++; /* do not include '/' */ 117 109 110 /* Find last slash */ 111 int i; 112 for (i = len - 1; (i >= 0) && (path[i] != '/'); i--); 113 114 /* Do not include the slash */ 115 i++; 118 116 len -= i; 119 120 /* add space for trailing '\0' */ 121 current_node->da_name = ofw_tree_space_alloc(len + 1); 122 if (!current_node->da_name) 123 return; 124 125 memcpy(current_node->da_name, &path[i], len); 126 current_node->da_name[len] = '\0'; 127 117 118 /* Add space for trailing '\0' */ 119 char *da_name = ofw_tree_space_alloc(len + 1); 120 if (!da_name) 121 return; 122 123 memcpy(da_name, &path[i], len); 124 da_name[len] = '\0'; 125 current_node->da_name = (char *) balloc_rebase(da_name); 126 128 127 /* 129 128 * Recursively process the potential child node. 130 129 */ 131 child = ofw_get_child_node(current); 132 if (child != 0 && child != -1) { 133 ofw_tree_node_t *child_node; 134 135 child_node = ofw_tree_node_alloc(); 130 phandle child = ofw_get_child_node(current); 131 if ((child != 0) && (child != -1)) { 132 ofw_tree_node_t *child_node = ofw_tree_node_alloc(); 136 133 if (child_node) { 137 134 ofw_tree_node_process(child_node, current_node, 138 135 child); 139 current_node->child = child_node; 136 current_node->child = 137 (ofw_tree_node_t *) balloc_rebase(child_node); 140 138 } 141 139 } 142 140 143 141 /* 144 142 * Count properties. 145 143 */ 144 static char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; 145 static char name2[OFW_TREE_PROPERTY_MAX_NAMELEN]; 146 146 name[0] = '\0'; 147 147 while (ofw_next_property(current, name, name2) == 1) { … … 149 149 memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN); 150 150 } 151 151 152 152 if (!current_node->properties) 153 153 return; 154 154 155 155 /* 156 156 * Copy properties. 157 157 */ 158 current_node->property =158 ofw_tree_property_t *property = 159 159 ofw_tree_properties_alloc(current_node->properties); 160 if (! current_node->property)160 if (!property) 161 161 return; 162 162 163 163 name[0] = '\0'; 164 164 for (i = 0; ofw_next_property(current, name, name2) == 1; i++) { 165 size_t size;166 167 165 if (i == current_node->properties) 168 166 break; 169 167 170 168 memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN); 171 memcpy(current_node->property[i].name, name, 172 OFW_TREE_PROPERTY_MAX_NAMELEN); 173 current_node->property[i].name[ 174 OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0'; 175 176 size = ofw_get_proplen(current, name); 177 current_node->property[i].size = size; 169 memcpy(property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN); 170 property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0'; 171 172 size_t size = ofw_get_proplen(current, name); 173 property[i].size = size; 174 178 175 if (size) { 179 void *buf; 180 181 buf = ofw_tree_space_alloc(size); 182 if (current_node->property[i].value = buf) { 176 void *buf = ofw_tree_space_alloc(size); 177 if (buf) { 183 178 /* 184 179 * Copy property value to memory node. 185 180 */ 186 (void) ofw_get_property(current, name, 187 buf, size);181 (void) ofw_get_property(current, name, buf, size); 182 property[i].value = balloc_rebase(buf); 188 183 } 189 } else { 190 current_node->property[i].value = NULL; 191 } 192 } 193 184 } else 185 property[i].value = NULL; 186 } 187 194 188 /* Just in case we ran out of memory. */ 195 189 current_node->properties = i; 196 190 current_node->property = (ofw_tree_property_t *) balloc_rebase(property); 191 192 197 193 /* 198 194 * Iteratively process the next peer node. … … 202 198 * risk of overflowing the stack is too real. 203 199 */ 204 peer = ofw_get_peer_node(current); 205 if (peer != 0 && peer != -1) { 206 ofw_tree_node_t *peer_node; 207 208 peer_node = ofw_tree_node_alloc(); 209 if (peer_node) { 210 current_node->peer = peer_node; 200 phandle peer = ofw_get_peer_node(current); 201 if ((peer != 0) && (peer != -1)) { 202 ofw_tree_node_t *peer_node = ofw_tree_node_alloc(); 203 if (peer_node) { 204 current_node->peer = (ofw_tree_node_t *) balloc_rebase(peer_node); 211 205 current_node = peer_node; 212 206 current = peer; … … 217 211 } 218 212 } 213 219 214 /* 220 215 * No more peers on this level. … … 226 221 /** Construct memory representation of OpenFirmware device tree. 227 222 * 228 * @return NULL on failure or pointer to the root node. 223 * @return NULL on failure or kernel pointer to the root node. 224 * 229 225 */ 230 226 ofw_tree_node_t *ofw_tree_build(void) 231 227 { 232 ofw_tree_node_t *root; 233 phandle ssm_node; 234 ofw_tree_node_t *ssm; 235 236 root = ofw_tree_node_alloc(); 228 ofw_tree_node_t *root = ofw_tree_node_alloc(); 237 229 if (root) 238 230 ofw_tree_node_process(root, NULL, ofw_root); 239 231 240 232 /* 241 233 * The firmware client interface does not automatically include the … … 243 235 * solution is to explicitly stick "ssm" to the OFW tree. 244 236 */ 245 ssm_node = ofw_find_device("/ssm@0,0");237 phandle ssm_node = ofw_find_device("/ssm@0,0"); 246 238 if (ssm_node != -1) { 247 ssm = ofw_tree_node_alloc();239 ofw_tree_node_t *ssm = ofw_tree_node_alloc(); 248 240 if (ssm) { 249 241 ofw_tree_node_process(ssm, root, 250 242 ofw_find_device("/ssm@0,0")); 251 243 ssm->peer = root->child; 252 root->child = ssm;244 root->child = (ofw_tree_node_t *) balloc_rebase(ssm); 253 245 } 254 246 } 255 247 256 return root;257 } 248 return (ofw_tree_node_t *) balloc_rebase(root); 249 } -
boot/genarch/ofw_tree.h
r207e208e rbc7d44c 33 33 #include <ofw.h> 34 34 35 #define OFW_TREE_PROPERTY_MAX_NAMELEN 32 36 37 typedef struct ofw_tree_node ofw_tree_node_t; 38 typedef struct ofw_tree_property ofw_tree_property_t; 39 40 /** Memory representation of OpenFirmware device tree node. */ 41 struct ofw_tree_node { 42 ofw_tree_node_t *parent; 43 ofw_tree_node_t *peer; 44 ofw_tree_node_t *child; 45 46 uint32_t node_handle; /**< Old OpenFirmware node handle. */ 47 48 char *da_name; /**< Disambigued name. */ 49 50 unsigned properties; /**< Number of properties. */ 51 ofw_tree_property_t *property; 52 53 void *device; /**< Member used solely by the kernel. */ 54 }; 35 #define OFW_TREE_PROPERTY_MAX_NAMELEN 32 55 36 56 37 /** Memory representation of OpenFirmware device tree node property. */ 57 struct ofw_tree_property{38 typedef struct { 58 39 char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; 59 40 size_t size; 60 41 void *value; 61 }; 42 } ofw_tree_property_t; 43 44 /** Memory representation of OpenFirmware device tree node. */ 45 typedef struct ofw_tree_node { 46 struct ofw_tree_node *parent; 47 struct ofw_tree_node *peer; 48 struct ofw_tree_node *child; 49 50 uint32_t node_handle; /**< Old OpenFirmware node handle. */ 51 52 char *da_name; /**< Disambigued name. */ 53 54 unsigned int properties; /**< Number of properties. */ 55 ofw_tree_property_t *property; 56 57 void *device; /**< Member used solely by the kernel. */ 58 } ofw_tree_node_t; 62 59 63 60 extern ofw_tree_node_t *ofw_tree_build(void); -
boot/generic/printf.c
r207e208e rbc7d44c 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ -
boot/generic/printf.h
r207e208e rbc7d44c 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ -
boot/generic/stdarg.h
r207e208e rbc7d44c 38 38 typedef __builtin_va_list va_list; 39 39 40 #define va_start(ap, last) 41 #define va_arg(ap, type) 42 #define va_end(ap) 40 #define va_start(ap, last) __builtin_va_start(ap, last) 41 #define va_arg(ap, type) __builtin_va_arg(ap, type) 42 #define va_end(ap) __builtin_va_end(ap) 43 43 44 44 #endif -
kernel/arch/ia64/src/drivers/ski.c
r207e208e rbc7d44c 129 129 130 130 outdev_initialize("skiout", &skiout, &skiout_ops); 131 stdout = &skiout;131 stdout_wire(&skiout); 132 132 133 133 sysinfo_set_item_val("fb", NULL, false); -
kernel/arch/ppc32/include/asm/regname.h
r207e208e rbc7d44c 27 27 */ 28 28 29 /** @addtogroup ppc32 29 /** @addtogroup ppc32 30 30 * @{ 31 31 */ … … 37 37 38 38 /* Condition Register Bit Fields */ 39 #define cr0040 #define cr1141 #define cr2242 #define cr3343 #define cr4444 #define cr5545 #define cr6646 #define cr7739 #define cr0 0 40 #define cr1 1 41 #define cr2 2 42 #define cr3 3 43 #define cr4 4 44 #define cr5 5 45 #define cr6 6 46 #define cr7 7 47 47 48 48 /* General Purpose Registers (GPRs) */ 49 #define r0050 #define r1151 #define r2252 #define r3353 #define r4454 #define r5555 #define r6656 #define r7757 #define r8858 #define r9959 #define r101060 #define r111161 #define r121262 #define r131363 #define r141464 #define r151565 #define r161666 #define r171767 #define r181868 #define r191969 #define r202070 #define r212171 #define r222272 #define r232373 #define r242474 #define r252575 #define r262676 #define r272777 #define r282878 #define r292979 #define r303080 #define r313149 #define r0 0 50 #define r1 1 51 #define r2 2 52 #define r3 3 53 #define r4 4 54 #define r5 5 55 #define r6 6 56 #define r7 7 57 #define r8 8 58 #define r9 9 59 #define r10 10 60 #define r11 11 61 #define r12 12 62 #define r13 13 63 #define r14 14 64 #define r15 15 65 #define r16 16 66 #define r17 17 67 #define r18 18 68 #define r19 19 69 #define r20 20 70 #define r21 21 71 #define r22 22 72 #define r23 23 73 #define r24 24 74 #define r25 25 75 #define r26 26 76 #define r27 27 77 #define r28 28 78 #define r29 29 79 #define r30 30 80 #define r31 31 81 81 82 82 /* GPR Aliases */ 83 #define sp183 #define sp 1 84 84 85 85 /* Floating Point Registers (FPRs) */ 86 #define fr0087 #define fr1188 #define fr2289 #define fr3390 #define fr4491 #define fr5592 #define fr6693 #define fr7794 #define fr8895 #define fr9996 #define fr101097 #define fr111198 #define fr121299 #define fr1313100 #define fr1414101 #define fr1515102 #define fr1616103 #define fr1717104 #define fr1818105 #define fr1919106 #define fr2020107 #define fr2121108 #define fr2222109 #define fr2323110 #define fr2424111 #define fr2525112 #define fr2626113 #define fr2727114 #define fr2828115 #define fr2929116 #define fr3030117 #define fr3131118 119 #define vr00120 #define vr11121 #define vr22122 #define vr33123 #define vr44124 #define vr55125 #define vr66126 #define vr77127 #define vr88128 #define vr99129 #define vr1010130 #define vr1111131 #define vr1212132 #define vr1313133 #define vr1414134 #define vr1515135 #define vr1616136 #define vr1717137 #define vr1818138 #define vr1919139 #define vr2020140 #define vr2121141 #define vr2222142 #define vr2323143 #define vr2424144 #define vr2525145 #define vr2626146 #define vr2727147 #define vr2828148 #define vr2929149 #define vr3030150 #define vr3131151 152 #define evr00153 #define evr11154 #define evr22155 #define evr33156 #define evr44157 #define evr55158 #define evr66159 #define evr77160 #define evr88161 #define evr99162 #define evr1010163 #define evr1111164 #define evr1212165 #define evr1313166 #define evr1414167 #define evr1515168 #define evr1616169 #define evr1717170 #define evr1818171 #define evr1919172 #define evr2020173 #define evr2121174 #define evr2222175 #define evr2323176 #define evr2424177 #define evr2525178 #define evr2626179 #define evr2727180 #define evr2828181 #define evr2929182 #define evr3030183 #define evr313186 #define fr0 0 87 #define fr1 1 88 #define fr2 2 89 #define fr3 3 90 #define fr4 4 91 #define fr5 5 92 #define fr6 6 93 #define fr7 7 94 #define fr8 8 95 #define fr9 9 96 #define fr10 10 97 #define fr11 11 98 #define fr12 12 99 #define fr13 13 100 #define fr14 14 101 #define fr15 15 102 #define fr16 16 103 #define fr17 17 104 #define fr18 18 105 #define fr19 19 106 #define fr20 20 107 #define fr21 21 108 #define fr22 22 109 #define fr23 23 110 #define fr24 24 111 #define fr25 25 112 #define fr26 26 113 #define fr27 27 114 #define fr28 28 115 #define fr29 29 116 #define fr30 30 117 #define fr31 31 118 119 #define vr0 0 120 #define vr1 1 121 #define vr2 2 122 #define vr3 3 123 #define vr4 4 124 #define vr5 5 125 #define vr6 6 126 #define vr7 7 127 #define vr8 8 128 #define vr9 9 129 #define vr10 10 130 #define vr11 11 131 #define vr12 12 132 #define vr13 13 133 #define vr14 14 134 #define vr15 15 135 #define vr16 16 136 #define vr17 17 137 #define vr18 18 138 #define vr19 19 139 #define vr20 20 140 #define vr21 21 141 #define vr22 22 142 #define vr23 23 143 #define vr24 24 144 #define vr25 25 145 #define vr26 26 146 #define vr27 27 147 #define vr28 28 148 #define vr29 29 149 #define vr30 30 150 #define vr31 31 151 152 #define evr0 0 153 #define evr1 1 154 #define evr2 2 155 #define evr3 3 156 #define evr4 4 157 #define evr5 5 158 #define evr6 6 159 #define evr7 7 160 #define evr8 8 161 #define evr9 9 162 #define evr10 10 163 #define evr11 11 164 #define evr12 12 165 #define evr13 13 166 #define evr14 14 167 #define evr15 15 168 #define evr16 16 169 #define evr17 17 170 #define evr18 18 171 #define evr19 19 172 #define evr20 20 173 #define evr21 21 174 #define evr22 22 175 #define evr23 23 176 #define evr24 24 177 #define evr25 25 178 #define evr26 26 179 #define evr27 27 180 #define evr28 28 181 #define evr29 29 182 #define evr30 30 183 #define evr31 31 184 184 185 185 /* Special Purpose Registers (SPRs) */ 186 #define xer1187 #define lr 188 #define ctr 189 #define dec22190 #define sdr125191 #define srr026192 #define srr1 193 #define sprg0272194 #define sprg1273195 #define sprg2274196 #define sprg3275197 #define prv287198 #define ibat0u 199 #define ibat0l 200 #define ibat1u 201 #define ibat1l 202 #define ibat2u 203 #define ibat2l 204 #define ibat3u 205 #define ibat3l 206 #define dbat0u 207 #define dbat0l 208 #define dbat1u 209 #define dbat1l 210 #define dbat2u 211 #define dbat2l 212 #define dbat3u 213 #define dbat3l 214 #define tlbmiss 215 #define ptehi 216 #define ptelo 217 #define hid0 186 #define xer 1 187 #define lr 8 188 #define ctr 9 189 #define dec 22 190 #define sdr1 25 191 #define srr0 26 192 #define srr1 27 193 #define sprg0 272 194 #define sprg1 273 195 #define sprg2 274 196 #define sprg3 275 197 #define prv 287 198 #define ibat0u 528 199 #define ibat0l 529 200 #define ibat1u 530 201 #define ibat1l 531 202 #define ibat2u 532 203 #define ibat2l 533 204 #define ibat3u 534 205 #define ibat3l 535 206 #define dbat0u 536 207 #define dbat0l 537 208 #define dbat1u 538 209 #define dbat1l 539 210 #define dbat2u 540 211 #define dbat2l 541 212 #define dbat3u 542 213 #define dbat3l 543 214 #define tlbmiss 980 215 #define ptehi 981 216 #define ptelo 982 217 #define hid0 1008 218 218 219 219 /* MSR bits */ 220 #define msr_dr 221 #define msr_ir 222 #define msr_pr 223 #define msr_ee 220 #define msr_dr (1 << 4) 221 #define msr_ir (1 << 5) 222 #define msr_pr (1 << 14) 223 #define msr_ee (1 << 15) 224 224 225 225 /* HID0 bits */ 226 #define hid0_sten 227 #define hid0_ice 228 #define hid0_dce 229 #define hid0_icfi 230 #define hid0_dci 226 #define hid0_sten (1 << 24) 227 #define hid0_ice (1 << 15) 228 #define hid0_dce (1 << 14) 229 #define hid0_icfi (1 << 11) 230 #define hid0_dci (1 << 10) 231 231 232 232 #endif -
kernel/arch/ppc32/include/boot/boot.h
r207e208e rbc7d44c 41 41 #define TEMP_STACK_SIZE 0x1000 42 42 43 #define TASKMAP_MAX_RECORDS 32 44 #define MEMMAP_MAX_RECORDS 32 43 #define TASKMAP_MAX_RECORDS 32 44 #define MEMMAP_MAX_RECORDS 32 45 #define BOOTINFO_TASK_NAME_BUFLEN 32 45 46 46 47 #ifndef __ASM__ 47 48 48 #define BOOTINFO_TASK_NAME_BUFLEN 3249 50 49 #include <arch/types.h> 50 #include <config.h> 51 #include <genarch/ofw/ofw_tree.h> 51 52 52 53 typedef struct { … … 73 74 74 75 typedef struct { 75 uintptr_t addr;76 unsigned int width;77 unsigned int height;78 unsigned int bpp;79 unsigned int scanline;80 } screen_t;81 82 typedef struct {83 uintptr_t addr;84 unsigned int size;85 } macio_t;86 87 typedef struct {88 76 memmap_t memmap; 89 77 taskmap_t taskmap; 90 screen_t screen;91 macio_t macio;78 ballocs_t ballocs; 79 ofw_tree_node_t *ofw_root; 92 80 } bootinfo_t; 93 81 -
kernel/arch/ppc32/src/mm/tlb.c
r207e208e rbc7d44c 45 45 static unsigned int seed = 10; 46 46 static unsigned int seed_real __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42; 47 48 49 #define TLB_FLUSH \50 "tlbie %0\n" \51 "addi %0, %0, 0x1000\n"52 47 53 48 … … 451 446 "sync\n" 452 447 453 TLB_FLUSH 454 TLB_FLUSH 455 TLB_FLUSH 456 TLB_FLUSH 457 TLB_FLUSH 458 TLB_FLUSH 459 TLB_FLUSH 460 TLB_FLUSH 461 462 TLB_FLUSH 463 TLB_FLUSH 464 TLB_FLUSH 465 TLB_FLUSH 466 TLB_FLUSH 467 TLB_FLUSH 468 TLB_FLUSH 469 TLB_FLUSH 470 471 TLB_FLUSH 472 TLB_FLUSH 473 TLB_FLUSH 474 TLB_FLUSH 475 TLB_FLUSH 476 TLB_FLUSH 477 TLB_FLUSH 478 TLB_FLUSH 479 480 TLB_FLUSH 481 TLB_FLUSH 482 TLB_FLUSH 483 TLB_FLUSH 484 TLB_FLUSH 485 TLB_FLUSH 486 TLB_FLUSH 487 TLB_FLUSH 488 489 TLB_FLUSH 490 TLB_FLUSH 491 TLB_FLUSH 492 TLB_FLUSH 493 TLB_FLUSH 494 TLB_FLUSH 495 TLB_FLUSH 496 TLB_FLUSH 497 498 TLB_FLUSH 499 TLB_FLUSH 500 TLB_FLUSH 501 TLB_FLUSH 502 TLB_FLUSH 503 TLB_FLUSH 504 TLB_FLUSH 505 TLB_FLUSH 506 507 TLB_FLUSH 508 TLB_FLUSH 509 TLB_FLUSH 510 TLB_FLUSH 511 TLB_FLUSH 512 TLB_FLUSH 513 TLB_FLUSH 514 TLB_FLUSH 515 516 TLB_FLUSH 517 TLB_FLUSH 518 TLB_FLUSH 519 TLB_FLUSH 520 TLB_FLUSH 521 TLB_FLUSH 522 TLB_FLUSH 523 TLB_FLUSH 448 ".rept 64\n" 449 "tlbie %0\n" 450 "addi %0, %0, 0x1000\n" 451 ".endr\n" 524 452 525 453 "eieio\n" -
kernel/arch/ppc32/src/ppc32.c
r207e208e rbc7d44c 41 41 #include <genarch/fb/fb.h> 42 42 #include <genarch/fb/visuals.h> 43 #include <genarch/ofw/ofw_tree.h> 44 #include <genarch/ofw/pci.h> 43 45 #include <userspace.h> 44 46 #include <proc/uarg.h> … … 49 51 #include <macros.h> 50 52 #include <string.h> 53 #include <print.h> 51 54 52 55 #define IRQ_COUNT 64 … … 63 66 64 67 for (i = 0; i < min3(bootinfo.taskmap.count, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) { 65 init.tasks[i].addr = PA2KA(bootinfo.taskmap.tasks[i].addr);68 init.tasks[i].addr = bootinfo.taskmap.tasks[i].addr; 66 69 init.tasks[i].size = bootinfo.taskmap.tasks[i].size; 67 70 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN, 68 71 bootinfo.taskmap.tasks[i].name); 69 72 } 73 74 /* Copy boot allocations info. */ 75 ballocs.base = bootinfo.ballocs.base; 76 ballocs.size = bootinfo.ballocs.size; 77 78 ofw_tree_init(bootinfo.ofw_root); 70 79 } 71 80 … … 74 83 /* Initialize dispatch table */ 75 84 interrupt_init(); 76 85 77 86 /* Start decrementer */ 78 87 start_decrementer(); 79 88 } 80 89 90 static bool display_register(ofw_tree_node_t *node, void *arg) 91 { 92 uintptr_t fb_addr = 0; 93 uint32_t fb_width = 0; 94 uint32_t fb_height = 0; 95 uint32_t fb_scanline = 0; 96 unsigned int visual = VISUAL_UNKNOWN; 97 98 ofw_tree_property_t *prop = ofw_tree_getprop(node, "address"); 99 if ((prop) && (prop->value)) 100 fb_addr = *((uintptr_t *) prop->value); 101 102 prop = ofw_tree_getprop(node, "width"); 103 if ((prop) && (prop->value)) 104 fb_width = *((uint32_t *) prop->value); 105 106 prop = ofw_tree_getprop(node, "height"); 107 if ((prop) && (prop->value)) 108 fb_height = *((uint32_t *) prop->value); 109 110 prop = ofw_tree_getprop(node, "depth"); 111 if ((prop) && (prop->value)) { 112 uint32_t fb_bpp = *((uint32_t *) prop->value); 113 switch (fb_bpp) { 114 case 8: 115 visual = VISUAL_INDIRECT_8; 116 break; 117 case 16: 118 visual = VISUAL_RGB_5_5_5_BE; 119 break; 120 case 24: 121 visual = VISUAL_BGR_8_8_8; 122 break; 123 case 32: 124 visual = VISUAL_RGB_0_8_8_8; 125 break; 126 default: 127 visual = VISUAL_UNKNOWN; 128 } 129 } 130 131 prop = ofw_tree_getprop(node, "linebytes"); 132 if ((prop) && (prop->value)) 133 fb_scanline = *((uint32_t *) prop->value); 134 135 if ((fb_addr) && (fb_width > 0) && (fb_height > 0) 136 && (fb_scanline > 0) && (visual != VISUAL_UNKNOWN)) { 137 fb_properties_t fb_prop = { 138 .addr = fb_addr, 139 .offset = 0, 140 .x = fb_width, 141 .y = fb_height, 142 .scan = fb_scanline, 143 .visual = visual, 144 }; 145 fb_init(&fb_prop); 146 } 147 148 /* Consider only a single device for now */ 149 return false; 150 } 151 81 152 void arch_post_mm_init(void) 82 153 { 83 154 if (config.cpu_active == 1) { 84 85 155 #ifdef CONFIG_FB 86 /* Initialize framebuffer */ 87 if (bootinfo.screen.addr) { 88 unsigned int visual; 89 90 switch (bootinfo.screen.bpp) { 91 case 8: 92 visual = VISUAL_INDIRECT_8; 93 break; 94 case 16: 95 visual = VISUAL_RGB_5_5_5_BE; 96 break; 97 case 24: 98 visual = VISUAL_BGR_8_8_8; 99 break; 100 case 32: 101 visual = VISUAL_RGB_0_8_8_8; 102 break; 103 default: 104 panic("Unsupported bits per pixel."); 105 } 106 fb_properties_t prop = { 107 .addr = bootinfo.screen.addr, 108 .offset = 0, 109 .x = bootinfo.screen.width, 110 .y = bootinfo.screen.height, 111 .scan = bootinfo.screen.scanline, 112 .visual = visual, 113 }; 114 fb_init(&prop); 115 } 156 ofw_tree_walk_by_device_type("display", display_register, NULL); 116 157 #endif 117 158 … … 132 173 } 133 174 134 void arch_post_smp_init(void) 135 { 136 if (bootinfo.macio.addr) { 175 static bool macio_register(ofw_tree_node_t *node, void *arg) 176 { 177 ofw_pci_reg_t *assigned_address = NULL; 178 179 ofw_tree_property_t *prop = ofw_tree_getprop(node, "assigned-addresses"); 180 if ((prop) && (prop->value)) 181 assigned_address = ((ofw_pci_reg_t *) prop->value); 182 183 if (assigned_address) { 137 184 /* Initialize PIC */ 138 185 cir_t cir; 139 186 void *cir_arg; 140 pic_init( bootinfo.macio.addr, PAGE_SIZE, &cir, &cir_arg);141 187 pic_init(assigned_address[0].addr, PAGE_SIZE, &cir, &cir_arg); 188 142 189 #ifdef CONFIG_MAC_KBD 143 uintptr_t pa = bootinfo.macio.addr + 0x16000;190 uintptr_t pa = assigned_address[0].addr + 0x16000; 144 191 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE); 145 192 size_t offset = pa - aligned_addr; 146 193 size_t size = 2 * PAGE_SIZE; 147 194 148 195 cuda_t *cuda = (cuda_t *) 149 196 (hw_map(aligned_addr, offset + size) + offset); 150 197 151 198 /* Initialize I/O controller */ 152 199 cuda_instance_t *cuda_instance = … … 163 210 #endif 164 211 } 212 213 /* Consider only a single device for now */ 214 return false; 215 } 216 217 void arch_post_smp_init(void) 218 { 219 ofw_tree_walk_by_device_type("mac-io", macio_register, NULL); 165 220 } 166 221 -
kernel/arch/sparc64/include/drivers/fhc.h
r207e208e rbc7d44c 27 27 */ 28 28 29 /** @addtogroup sparc64 29 /** @addtogroup sparc64 30 30 * @{ 31 31 */ -
kernel/arch/sparc64/src/drivers/fhc.c
r207e208e rbc7d44c 46 46 #include <arch/types.h> 47 47 #include <genarch/ofw/ofw_tree.h> 48 #include <genarch/ofw/fhc.h> 48 49 #include <sysinfo/sysinfo.h> 49 50 -
kernel/arch/sparc64/src/drivers/kbd.c
r207e208e rbc7d44c 35 35 #include <arch/drivers/kbd.h> 36 36 #include <genarch/ofw/ofw_tree.h> 37 38 #ifdef CONFIG_SUN_KBD 39 #include <genarch/kbrd/kbrd.h> 40 #endif 41 #ifdef CONFIG_Z8530 42 #include <genarch/drivers/z8530/z8530.h> 43 #endif 44 #ifdef CONFIG_NS16550 45 #include <genarch/drivers/ns16550/ns16550.h> 46 #endif 47 37 #include <genarch/ofw/fhc.h> 38 #include <genarch/ofw/ebus.h> 48 39 #include <console/console.h> 49 40 #include <ddi/irq.h> … … 56 47 57 48 #ifdef CONFIG_SUN_KBD 49 #include <genarch/kbrd/kbrd.h> 50 #endif 51 52 #ifdef CONFIG_Z8530 53 #include <genarch/drivers/z8530/z8530.h> 54 #endif 55 56 #ifdef CONFIG_NS16550 57 #include <genarch/drivers/ns16550/ns16550.h> 58 #endif 59 60 #ifdef CONFIG_SUN_KBD 58 61 59 62 #ifdef CONFIG_Z8530 -
kernel/arch/sparc64/src/drivers/pci.c
r207e208e rbc7d44c 37 37 #include <arch/drivers/pci.h> 38 38 #include <genarch/ofw/ofw_tree.h> 39 #include <genarch/ofw/upa.h> 39 40 #include <arch/trap/interrupt.h> 40 41 #include <mm/page.h> -
kernel/arch/sparc64/src/drivers/scr.c
r207e208e rbc7d44c 35 35 #include <arch/drivers/scr.h> 36 36 #include <genarch/ofw/ofw_tree.h> 37 #include <genarch/ofw/pci.h> 38 #include <genarch/ofw/sbus.h> 39 #include <genarch/ofw/upa.h> 37 40 #include <genarch/fb/fb.h> 38 41 #include <genarch/fb/visuals.h> -
kernel/arch/sparc64/src/drivers/sgcn.c
r207e208e rbc7d44c 380 380 sysinfo_set_item_val("fb.kind", NULL, 4); 381 381 382 outdev_initialize("sgcnout", &sgcnout, &sgcnout_ops); 383 stdout = &sgcnout;382 outdev_initialize("sgcnout", &sgcnout, &sgcnout_ops); 383 stdout_wire(&sgcnout); 384 384 } 385 385 -
kernel/genarch/Makefile.inc
r207e208e rbc7d44c 130 130 ifeq ($(CONFIG_OFW_TREE),y) 131 131 GENARCH_SOURCES += \ 132 genarch/src/ofw/ofw_tree.c \ 132 genarch/src/ofw/ofw_tree.c 133 endif 134 135 ifeq ($(CONFIG_OFW_PCI),y) 136 GENARCH_SOURCES += \ 133 137 genarch/src/ofw/ebus.c \ 134 138 genarch/src/ofw/fhc.c \ 135 139 genarch/src/ofw/pci.c \ 136 140 genarch/src/ofw/sbus.c \ 137 genarch/src/ofw/upa.c 141 genarch/src/ofw/upa.c 138 142 endif 139 143 -
kernel/genarch/include/fb/fb.h
r207e208e rbc7d44c 68 68 69 69 void fb_redraw(void); 70 voidfb_init(fb_properties_t *props);70 bool fb_init(fb_properties_t *props); 71 71 72 72 #endif -
kernel/genarch/include/fb/visuals.h
r207e208e rbc7d44c 37 37 38 38 typedef enum { 39 VISUAL_UNKNOWN = 0, 39 40 VISUAL_INDIRECT_8, 40 41 VISUAL_RGB_5_5_5_LE, -
kernel/genarch/include/ofw/ofw_tree.h
r207e208e rbc7d44c 31 31 32 32 #include <arch/types.h> 33 #include <ddi/irq.h>34 33 #include <typedefs.h> 35 34 36 #define OFW_TREE_PROPERTY_MAX_NAMELEN 35 #define OFW_TREE_PROPERTY_MAX_NAMELEN 32 37 36 38 typedef struct ofw_tree_node ofw_tree_node_t; 39 typedef struct ofw_tree_property ofw_tree_property_t; 37 /** Memory representation of OpenFirmware device tree node property. */ 38 typedef struct { 39 char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; 40 size_t size; 41 void *value; 42 } ofw_tree_property_t; 40 43 41 44 /** Memory representation of OpenFirmware device tree node. */ 42 struct ofw_tree_node {43 ofw_tree_node_t*parent;44 ofw_tree_node_t*peer;45 ofw_tree_node_t*child;46 47 uint32_t node_handle; 48 49 char *da_name; 50 51 unsigned properties;/**< Number of properties. */45 typedef struct ofw_tree_node { 46 struct ofw_tree_node *parent; 47 struct ofw_tree_node *peer; 48 struct ofw_tree_node *child; 49 50 uint32_t node_handle; /**< Old OpenFirmware node handle. */ 51 52 char *da_name; /**< Disambigued name. */ 53 54 unsigned int properties; /**< Number of properties. */ 52 55 ofw_tree_property_t *property; 53 56 … … 57 60 */ 58 61 void *device; 59 } ;62 } ofw_tree_node_t; 60 63 61 /** Memory representation of OpenFirmware device tree node property. */ 62 struct ofw_tree_property { 63 char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; 64 size_t size; 65 void *value; 66 }; 67 68 /* 69 * Definition of 'reg' and 'ranges' properties for various buses. 70 */ 71 72 struct ofw_fhc_reg { 73 uint64_t addr; 74 uint32_t size; 75 } __attribute__ ((packed)); 76 typedef struct ofw_fhc_reg ofw_fhc_reg_t; 77 78 struct ofw_fhc_range { 79 uint64_t child_base; 80 uint64_t parent_base; 81 uint32_t size; 82 } __attribute__ ((packed)); 83 typedef struct ofw_fhc_range ofw_fhc_range_t; 84 85 struct ofw_central_reg { 86 uint64_t addr; 87 uint32_t size; 88 } __attribute__ ((packed)); 89 typedef struct ofw_central_reg ofw_central_reg_t; 90 91 struct ofw_central_range { 92 uint64_t child_base; 93 uint64_t parent_base; 94 uint32_t size; 95 } __attribute__ ((packed)); 96 typedef struct ofw_central_range ofw_central_range_t; 97 98 struct ofw_ebus_reg { 99 uint32_t space; 100 uint32_t addr; 101 uint32_t size; 102 } __attribute__ ((packed)); 103 typedef struct ofw_ebus_reg ofw_ebus_reg_t; 104 105 struct ofw_ebus_range { 106 uint32_t child_space; 107 uint32_t child_base; 108 uint32_t parent_space; 109 uint64_t parent_base; /* group phys.mid and phys.lo together */ 110 uint32_t size; 111 } __attribute__ ((packed)); 112 typedef struct ofw_ebus_range ofw_ebus_range_t; 113 114 struct ofw_ebus_intr_map { 115 uint32_t space; 116 uint32_t addr; 117 uint32_t intr; 118 uint32_t controller_handle; 119 uint32_t controller_ino; 120 } __attribute__ ((packed)); 121 typedef struct ofw_ebus_intr_map ofw_ebus_intr_map_t; 122 123 struct ofw_ebus_intr_mask { 124 uint32_t space_mask; 125 uint32_t addr_mask; 126 uint32_t intr_mask; 127 } __attribute__ ((packed)); 128 typedef struct ofw_ebus_intr_mask ofw_ebus_intr_mask_t; 129 130 struct ofw_pci_reg { 131 uint32_t space; /* needs to be masked to obtain pure space id */ 132 uint64_t addr; /* group phys.mid and phys.lo together */ 133 uint64_t size; 134 } __attribute__ ((packed)); 135 typedef struct ofw_pci_reg ofw_pci_reg_t; 136 137 struct ofw_pci_range { 138 uint32_t space; 139 uint64_t child_base; /* group phys.mid and phys.lo together */ 140 uint64_t parent_base; 141 uint64_t size; 142 } __attribute__ ((packed)); 143 typedef struct ofw_pci_range ofw_pci_range_t; 144 145 struct ofw_sbus_reg { 146 uint64_t addr; 147 uint32_t size; 148 } __attribute__ ((packed)); 149 typedef struct ofw_sbus_reg ofw_sbus_reg_t; 150 151 struct ofw_sbus_range { 152 uint64_t child_base; 153 uint64_t parent_base; 154 uint32_t size; 155 } __attribute__ ((packed)); 156 typedef struct ofw_sbus_range ofw_sbus_range_t; 157 158 struct ofw_upa_reg { 159 uint64_t addr; 160 uint64_t size; 161 } __attribute__ ((packed)); 162 typedef struct ofw_upa_reg ofw_upa_reg_t; 64 /* Walker for visiting OpenFirmware device tree nodes. */ 65 typedef bool (* ofw_tree_walker_t)(ofw_tree_node_t *, void *); 163 66 164 67 extern void ofw_tree_init(ofw_tree_node_t *); 165 68 extern void ofw_tree_print(void); 69 166 70 extern const char *ofw_tree_node_name(const ofw_tree_node_t *); 167 71 extern ofw_tree_node_t *ofw_tree_lookup(const char *); 168 72 extern ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *, 169 73 const char *); 74 extern void ofw_tree_walk_by_device_type(const char *, ofw_tree_walker_t, 75 void *); 76 170 77 extern ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *, const char *); 171 78 extern ofw_tree_node_t *ofw_tree_find_child_by_device_type(ofw_tree_node_t *, 172 79 const char *); 80 173 81 extern ofw_tree_node_t *ofw_tree_find_peer_by_device_type(ofw_tree_node_t *, 174 82 const char *); 175 extern ofw_tree_node_t *ofw_tree_find_peer_by_name(ofw_tree_node_t * node,176 const char * name);83 extern ofw_tree_node_t *ofw_tree_find_peer_by_name(ofw_tree_node_t *, 84 const char *); 177 85 extern ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *, 178 86 uint32_t); 179 87 180 extern bool ofw_fhc_apply_ranges(ofw_tree_node_t *, ofw_fhc_reg_t *,181 uintptr_t *);182 extern bool ofw_central_apply_ranges(ofw_tree_node_t *, ofw_central_reg_t *,183 uintptr_t *);184 extern bool ofw_ebus_apply_ranges(ofw_tree_node_t *, ofw_ebus_reg_t *,185 uintptr_t *);186 extern bool ofw_pci_apply_ranges(ofw_tree_node_t *, ofw_pci_reg_t *,187 uintptr_t *);188 extern bool ofw_sbus_apply_ranges(ofw_tree_node_t *, ofw_sbus_reg_t *,189 uintptr_t *);190 extern bool ofw_upa_apply_ranges(ofw_tree_node_t *, ofw_upa_reg_t *,191 uintptr_t *);192 193 extern bool ofw_pci_reg_absolutize(ofw_tree_node_t *, ofw_pci_reg_t *,194 ofw_pci_reg_t *);195 196 extern bool ofw_fhc_map_interrupt(ofw_tree_node_t *, ofw_fhc_reg_t *,197 uint32_t, int *, cir_t *, void **);198 extern bool ofw_ebus_map_interrupt(ofw_tree_node_t *, ofw_ebus_reg_t *,199 uint32_t, int *, cir_t *, void **);200 extern bool ofw_pci_map_interrupt(ofw_tree_node_t *, ofw_pci_reg_t *,201 int, int *, cir_t *, void **);202 203 88 #endif -
kernel/genarch/src/drivers/dsrln/dsrlnout.c
r207e208e rbc7d44c 66 66 67 67 outdev_initialize("dsrlnout", &dsrlnout_console, &dsrlnout_ops); 68 stdout = &dsrlnout_console;68 stdout_wire(&dsrlnout_console); 69 69 70 70 sysinfo_set_item_val("fb", NULL, true); -
kernel/genarch/src/drivers/ega/ega.c
r207e208e rbc7d44c 567 567 568 568 outdev_initialize("ega", &ega_console, &ega_ops); 569 stdout = &ega_console;569 stdout_wire(&ega_console); 570 570 571 571 sysinfo_set_item_val("fb", NULL, true); -
kernel/genarch/src/fb/fb.c
r207e208e rbc7d44c 458 458 * 459 459 */ 460 void fb_init(fb_properties_t *props) 461 { 460 bool fb_init(fb_properties_t *props) 461 { 462 ASSERT(props); 463 ASSERT(props->x > 0); 464 ASSERT(props->y > 0); 465 ASSERT(props->scan > 0); 466 462 467 switch (props->visual) { 463 468 case VISUAL_INDIRECT_8: … … 506 511 break; 507 512 default: 508 panic("Unsupported visual."); 513 LOG("Unsupported visual."); 514 return false; 509 515 } 510 516 … … 536 542 size_t glyphsize = FONT_GLYPHS * glyphbytes; 537 543 544 fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); 545 if (!fb_addr) { 546 LOG("Unable to map framebuffer."); 547 return false; 548 } 549 538 550 backbuf = (uint16_t *) malloc(bbsize, 0); 539 if (!backbuf) 540 panic("Unable to allocate backbuffer."); 551 if (!backbuf) { 552 LOG("Unable to allocate backbuffer."); 553 return false; 554 } 541 555 542 556 glyphs = (uint8_t *) malloc(glyphsize, 0); 543 if (!glyphs) 544 panic("Unable to allocate glyphs."); 557 if (!glyphs) { 558 free(backbuf); 559 LOG("Unable to allocate glyphs."); 560 return false; 561 } 545 562 546 563 bgscan = malloc(bgscanbytes, 0); 547 if (!bgscan) 548 panic("Unable to allocate background pixel."); 564 if (!bgscan) { 565 free(glyphs); 566 free(backbuf); 567 LOG("Unable to allocate background pixel."); 568 return false; 569 } 549 570 550 571 memsetw(backbuf, cols * rows, 0); 551 552 572 glyphs_render(); 553 554 fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);555 573 556 574 sysinfo_set_item_val("fb", NULL, true); … … 565 583 566 584 outdev_initialize("fb", &fb_console, &fb_ops); 567 stdout = &fb_console; 585 stdout_wire(&fb_console); 586 587 return true; 568 588 } 569 589 -
kernel/genarch/src/ofw/ebus.c
r207e208e rbc7d44c 37 37 38 38 #include <genarch/ofw/ofw_tree.h> 39 #include <genarch/ofw/ebus.h> 40 #include <genarch/ofw/pci.h> 39 41 #include <arch/memstr.h> 40 #include <arch/trap/interrupt.h>41 42 #include <string.h> 42 43 #include <panic.h> -
kernel/genarch/src/ofw/fhc.c
r207e208e rbc7d44c 37 37 38 38 #include <genarch/ofw/ofw_tree.h> 39 #include <genarch/ofw/fhc.h> 39 40 #include <arch/drivers/fhc.h> 40 41 #include <arch/memstr.h> -
kernel/genarch/src/ofw/ofw_tree.c
r207e208e rbc7d44c 32 32 /** 33 33 * @file 34 * @brief 34 * @brief OpenFirmware device tree navigation. 35 35 * 36 36 */ … … 40 40 #include <mm/slab.h> 41 41 #include <string.h> 42 #include <panic.h> 42 43 #include <print.h> 43 #include <panic.h> 44 45 #define PATH_MAX_LEN 80 46 #define NAME_BUF_LEN 50 44 45 #define PATH_MAX_LEN 256 46 #define NAME_BUF_LEN 50 47 47 48 48 static ofw_tree_node_t *ofw_root; … … 55 55 /** Get OpenFirmware node property. 56 56 * 57 * @param node Node in which to lookup the property. 58 * @param name Name of the property. 59 * 60 * @return Pointer to the property structure or NULL if no such 61 * property. 62 */ 63 ofw_tree_property_t * 64 ofw_tree_getprop(const ofw_tree_node_t *node, const char *name) 57 * @param node Node in which to lookup the property. 58 * @param name Name of the property. 59 * 60 * @return Pointer to the property structure or NULL if no such 61 * property. 62 * 63 */ 64 ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, 65 const char *name) 65 66 { 66 67 unsigned int i; … … 70 71 return &node->property[i]; 71 72 } 72 73 73 74 return NULL; 74 75 } … … 76 77 /** Return value of the 'name' property. 77 78 * 78 * @param node Node of interest. 79 * 80 * @return Value of the 'name' property belonging to the node. 79 * @param node Node of interest. 80 * 81 * @return Value of the 'name' property belonging to the node 82 * or NULL if the property is invalid. 83 * 81 84 */ 82 85 const char *ofw_tree_node_name(const ofw_tree_node_t *node) 83 86 { 84 ofw_tree_property_t *prop; 85 86 prop = ofw_tree_getprop(node, "name"); 87 if (!prop) 88 panic("Node without name property."); 89 90 if (prop->size < 2) 91 panic("Invalid name property."); 87 ofw_tree_property_t *prop = ofw_tree_getprop(node, "name"); 88 if ((!prop) || (prop->size < 2)) 89 return NULL; 92 90 93 91 return prop->value; … … 96 94 /** Lookup child of given name. 97 95 * 98 * @param node Node whose child is being looked up. 99 * @param name Name of the child being looked up. 100 * 101 * @return NULL if there is no such child or pointer to the 102 * matching child node. 103 */ 104 ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *name) 96 * @param node Node whose child is being looked up. 97 * @param name Name of the child being looked up. 98 * 99 * @return NULL if there is no such child or pointer to the 100 * matching child node. 101 * 102 */ 103 ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, 104 const char *name) 105 105 { 106 106 ofw_tree_node_t *cur; … … 125 125 return cur; 126 126 } 127 127 128 128 return NULL; 129 129 } … … 131 131 /** Lookup first child of given device type. 132 132 * 133 * @param node 134 * @param nameDevice type of the child being looked up.135 * 136 * @return 137 * 138 * /139 ofw_tree_node_t * 140 ofw_tree_ find_child_by_device_type(ofw_tree_node_t *node, const char *name)141 { 142 ofw_tree_node_t *cur; 143 ofw_tree_ property_t *prop;133 * @param node Node whose child is being looked up. 134 * @param dtype Device type of the child being looked up. 135 * 136 * @return NULL if there is no such child or pointer to the 137 * matching child node. 138 * 139 */ 140 ofw_tree_node_t *ofw_tree_find_child_by_device_type(ofw_tree_node_t *node, 141 const char *dtype) 142 { 143 ofw_tree_node_t *cur; 144 144 145 145 for (cur = node->child; cur; cur = cur->peer) { 146 prop = ofw_tree_getprop(cur, "device_type"); 147 if (!prop || !prop->value) 146 ofw_tree_property_t *prop = 147 ofw_tree_getprop(cur, "device_type"); 148 149 if ((!prop) || (!prop->value)) 148 150 continue; 149 if (str_cmp(prop->value, name) == 0) 150 return cur; 151 } 152 151 152 if (str_cmp(prop->value, dtype) == 0) 153 return cur; 154 } 155 153 156 return NULL; 154 157 } … … 159 162 * are looked up iteratively to avoid stack overflow. 160 163 * 161 * @param root Root of the searched subtree. 162 * @param handle OpenFirmware handle. 163 * 164 * @return NULL if there is no such node or pointer to the matching 165 * node. 166 */ 167 ofw_tree_node_t * 168 ofw_tree_find_node_by_handle(ofw_tree_node_t *root, uint32_t handle) 169 { 170 ofw_tree_node_t *cur; 171 172 for (cur = root; cur; cur = cur->peer) { 164 * @param root Root of the searched subtree. 165 * @param handle OpenFirmware handle. 166 * 167 * @return NULL if there is no such node or pointer to the matching 168 * node. 169 * 170 */ 171 ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *root, 172 uint32_t handle) 173 { 174 ofw_tree_node_t *cur; 175 176 for (cur = root; cur; cur = cur->peer) { 173 177 if (cur->node_handle == handle) 174 178 return cur; 175 179 176 180 if (cur->child) { 177 ofw_tree_node_t *node; 178 179 node = ofw_tree_find_node_by_handle(cur->child, handle); 181 ofw_tree_node_t *node 182 = ofw_tree_find_node_by_handle(cur->child, handle); 180 183 if (node) 181 184 return node; … … 183 186 } 184 187 185 return NULL; 188 return NULL; 186 189 } 187 190 188 191 /** Lookup first peer of given device type. 189 192 * 190 * @param node 191 * @param nameDevice type of the child being looked up.192 * 193 * @return 194 * 195 * /196 ofw_tree_node_t * 197 ofw_tree_ find_peer_by_device_type(ofw_tree_node_t *node, const char *name)198 { 199 ofw_tree_node_t *cur; 200 ofw_tree_ property_t *prop;193 * @param node Node whose peer is being looked up. 194 * @param dtype Device type of the child being looked up. 195 * 196 * @return NULL if there is no such child or pointer to the 197 * matching child node. 198 * 199 */ 200 ofw_tree_node_t *ofw_tree_find_peer_by_device_type(ofw_tree_node_t *node, 201 const char *dtype) 202 { 203 ofw_tree_node_t *cur; 201 204 202 205 for (cur = node->peer; cur; cur = cur->peer) { 203 prop = ofw_tree_getprop(cur, "device_type"); 204 if (!prop || !prop->value) 206 ofw_tree_property_t *prop = 207 ofw_tree_getprop(cur, "device_type"); 208 209 if ((!prop) || (!prop->value)) 205 210 continue; 211 212 if (str_cmp(prop->value, dtype) == 0) 213 return cur; 214 } 215 216 return NULL; 217 } 218 219 /** Lookup first peer of given name. 220 * 221 * @param node Node whose peer is being looked up. 222 * @param name Name of the child being looked up. 223 * 224 * @return NULL if there is no such peer or pointer to the matching 225 * peer node. 226 * 227 */ 228 ofw_tree_node_t *ofw_tree_find_peer_by_name(ofw_tree_node_t *node, 229 const char *name) 230 { 231 ofw_tree_node_t *cur; 232 233 for (cur = node->peer; cur; cur = cur->peer) { 234 ofw_tree_property_t *prop 235 = ofw_tree_getprop(cur, "name"); 236 237 if ((!prop) || (!prop->value)) 238 continue; 239 206 240 if (str_cmp(prop->value, name) == 0) 207 241 return cur; 208 242 } 209 210 return NULL; 211 } 212 213 214 /** Lookup first peer of given name. 215 * 216 * @param node Node whose peer is being looked up. 217 * @param name Name of the child being looked up. 218 * 219 * @return NULL if there is no such peer or pointer to the matching 220 * peer node. 221 */ 222 ofw_tree_node_t * 223 ofw_tree_find_peer_by_name(ofw_tree_node_t *node, const char *name) 224 { 225 ofw_tree_node_t *cur; 226 ofw_tree_property_t *prop; 227 228 for (cur = node->peer; cur; cur = cur->peer) { 229 prop = ofw_tree_getprop(cur, "name"); 230 if (!prop || !prop->value) 231 continue; 232 if (str_cmp(prop->value, name) == 0) 233 return cur; 234 } 235 243 236 244 return NULL; 237 245 } … … 239 247 /** Lookup OpenFirmware node by its path. 240 248 * 241 * @param path Path to the node. 242 * 243 * @return NULL if there is no such node or pointer to the leaf 244 * node. 249 * @param path Path to the node. 250 * 251 * @return NULL if there is no such node or pointer to the leaf 252 * node. 253 * 245 254 */ 246 255 ofw_tree_node_t *ofw_tree_lookup(const char *path) 247 256 { 248 char buf[NAME_BUF_LEN + 1]; 257 if (path[0] != '/') 258 return NULL; 259 249 260 ofw_tree_node_t *node = ofw_root; 250 261 size_t i; 251 262 size_t j; 252 263 253 if (path[0] != '/')254 return NULL;255 256 264 for (i = 1; (i < str_size(path)) && (node); i = j + 1) { 257 265 for (j = i; (j < str_size(path)) && (path[j] != '/'); j++); … … 261 269 continue; 262 270 271 char buf[NAME_BUF_LEN + 1]; 263 272 memcpy(buf, &path[i], j - i); 264 273 buf[j - i] = 0; … … 269 278 } 270 279 271 /** PrintOpenFirmware device subtree rooted in a node.280 /** Walk the OpenFirmware device subtree rooted in a node. 272 281 * 273 282 * Child nodes are processed recursively and peer nodes are processed 274 283 * iteratively in order to avoid stack overflow. 275 284 * 276 * @param node Root of the subtree. 277 * @param path Current path, NULL for the very root of the entire tree. 278 */ 279 static void ofw_tree_node_print(const ofw_tree_node_t *node, const char *path) 280 { 281 char *p; 282 const ofw_tree_node_t *cur; 283 284 p = (char *) malloc(PATH_MAX_LEN, 0); 285 285 * @param node Root of the subtree. 286 * @param dtype Device type to look for. 287 * @param walker Routine to be invoked on found device. 288 * @param arg User argument to the walker. 289 * 290 * @return True if the walk should continue. 291 * 292 */ 293 static bool ofw_tree_walk_by_device_type_internal(ofw_tree_node_t *node, 294 const char *dtype, ofw_tree_walker_t walker, void *arg) 295 { 296 ofw_tree_node_t *cur; 297 286 298 for (cur = node; cur; cur = cur->peer) { 287 if (cur->parent) { 288 snprintf(p, PATH_MAX_LEN, "%s/%s", path, cur->da_name); 289 printf("%s\n", p); 299 ofw_tree_property_t *prop = 300 ofw_tree_getprop(cur, "device_type"); 301 302 if ((prop) && (prop->value) && (str_cmp(prop->value, dtype) == 0)) { 303 bool ret = walker(cur, arg); 304 if (!ret) 305 return false; 306 } 307 308 if (cur->child) { 309 bool ret = 310 ofw_tree_walk_by_device_type_internal(cur->child, dtype, walker, arg); 311 if (!ret) 312 return false; 313 } 314 } 315 316 return true; 317 } 318 319 /** Walk the OpenFirmware device tree and find devices by type. 320 * 321 * Walk the whole OpenFirmware device tree and if any node has 322 * the property "device_type" equal to dtype, run a walker on it. 323 * If the walker returns false, the walk does not continue. 324 * 325 * @param dtype Device type to look for. 326 * @param walker Routine to be invoked on found device. 327 * @param arg User argument to the walker. 328 * 329 */ 330 void ofw_tree_walk_by_device_type(const char *dtype, ofw_tree_walker_t walker, 331 void *arg) 332 { 333 (void) ofw_tree_walk_by_device_type_internal(ofw_root, dtype, walker, arg); 334 } 335 336 /** Print OpenFirmware device subtree rooted in a node. 337 * 338 * Child nodes are processed recursively and peer nodes are processed 339 * iteratively in order to avoid stack overflow. 340 * 341 * @param node Root of the subtree. 342 * @param path Current path, NULL for the very root of the entire tree. 343 * 344 */ 345 static void ofw_tree_node_print(ofw_tree_node_t *node, const char *path) 346 { 347 char *cur_path = (char *) malloc(PATH_MAX_LEN, 0); 348 ofw_tree_node_t *cur; 349 350 for (cur = node; cur; cur = cur->peer) { 351 if ((cur->parent) && (path)) { 352 snprintf(cur_path, PATH_MAX_LEN, "%s/%s", path, cur->da_name); 353 printf("%s\n", cur_path); 290 354 } else { 291 snprintf( p, PATH_MAX_LEN, "%s", cur->da_name);355 snprintf(cur_path, PATH_MAX_LEN, "%s", cur->da_name); 292 356 printf("/\n"); 293 357 } 294 358 295 359 if (cur->child) 296 ofw_tree_node_print(cur->child, p);297 } 298 299 free( p);360 ofw_tree_node_print(cur->child, cur_path); 361 } 362 363 free(cur_path); 300 364 } 301 365 -
kernel/genarch/src/ofw/pci.c
r207e208e rbc7d44c 37 37 38 38 #include <genarch/ofw/ofw_tree.h> 39 #include <genarch/ofw/pci.h> 39 40 #include <arch/drivers/pci.h> 40 41 #include <arch/trap/interrupt.h> -
kernel/genarch/src/ofw/sbus.c
r207e208e rbc7d44c 37 37 38 38 #include <genarch/ofw/ofw_tree.h> 39 #include <genarch/ofw/sbus.h> 39 40 #include <macros.h> 40 41 -
kernel/genarch/src/ofw/upa.c
r207e208e rbc7d44c 37 37 38 38 #include <genarch/ofw/ofw_tree.h> 39 #include <genarch/ofw/upa.h> 39 40 #include <arch/memstr.h> 40 41 #include <func.h> -
kernel/generic/include/console/chardev.h
r207e208e rbc7d44c 36 36 #define KERN_CHARDEV_H_ 37 37 38 #include <adt/list.h> 38 39 #include <arch/types.h> 39 40 #include <synch/waitq.h> … … 75 76 } outdev_operations_t; 76 77 77 /** Character input device. */78 /** Character output device. */ 78 79 typedef struct outdev { 79 80 char *name; … … 81 82 /** Protects everything below. */ 82 83 SPINLOCK_DECLARE(lock); 84 85 /** Fields suitable for multiplexing. */ 86 link_t link; 87 link_t list; 83 88 84 89 /** Implementation of outdev operations. */ -
kernel/generic/include/console/console.h
r207e208e rbc7d44c 44 44 45 45 extern indev_t *stdin_wire(void); 46 extern void stdout_wire(outdev_t *outdev); 46 47 extern void console_init(void); 47 48 -
kernel/generic/src/console/chardev.c
r207e208e rbc7d44c 33 33 */ 34 34 35 #include <adt/list.h> 35 36 #include <console/chardev.h> 36 37 #include <synch/waitq.h> … … 134 135 outdev->name = name; 135 136 spinlock_initialize(&outdev->lock, "outdev"); 137 link_initialize(&outdev->link); 138 list_initialize(&outdev->list); 136 139 outdev->op = op; 137 140 } -
kernel/generic/src/console/console.c
r207e208e rbc7d44c 76 76 static parea_t klog_parea; 77 77 78 static indev_t stdin_sink; 79 static outdev_t stdout_source; 80 78 81 static indev_operations_t stdin_ops = { 79 82 .poll = NULL 80 83 }; 81 84 85 static void stdout_write(outdev_t *dev, wchar_t ch, bool silent); 86 87 static outdev_operations_t stdout_ops = { 88 .write = stdout_write 89 }; 90 82 91 /** Silence output */ 83 92 bool silent = false; … … 90 99 { 91 100 if (stdin == NULL) { 92 stdin = malloc(sizeof(indev_t), FRAME_ATOMIC); 93 if (stdin != NULL) 94 indev_initialize("stdin", stdin, &stdin_ops); 101 indev_initialize("stdin", &stdin_sink, &stdin_ops); 102 stdin = &stdin_sink; 95 103 } 96 104 97 105 return stdin; 106 } 107 108 void stdout_wire(outdev_t *outdev) 109 { 110 if (stdout == NULL) { 111 outdev_initialize("stdout", &stdout_source, &stdout_ops); 112 stdout = &stdout_source; 113 } 114 115 list_append(&outdev->link, &stdout->list); 116 } 117 118 static void stdout_write(outdev_t *dev, wchar_t ch, bool silent) 119 { 120 link_t *cur; 121 122 for (cur = dev->list.next; cur != &dev->list; cur = cur->next) { 123 outdev_t *sink = list_get_instance(cur, outdev_t, link); 124 sink->op->write(sink, ch, silent); 125 } 98 126 } 99 127
Note:
See TracChangeset
for help on using the changeset viewer.