static vm_offset_t init_heap(void) { if ((pmemh = OF_finddevice("/memory")) == (phandle_t)-1) OF_exit(); if (OF_getprop(pmemh, "available", memslices, sizeof(memslices)) <= 0) OF_exit(); /* There is no need for continuous physical heap memory. */ heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32); return heapva; }
void * ofw_alloc_heap(unsigned int size) { phandle_t memoryp; struct ofw_reg available; memoryp = OF_instance_to_package(memory); OF_getprop(memoryp, "available", &available, sizeof(available)); heap_base = OF_claim((void *)available.base, size, sizeof(register_t)); if (heap_base != (void *)-1) { heap_size = size; } return (heap_base); }
/* * The older (those relying on ofwboot v1.8 and earlier) kernels can't handle * ksyms information unless it resides in a dedicated memory allocated from * PROM and aligned on NBPG boundary. This is because the kernels calculate * their ends on their own, they use address of 'end[]' reference which follows * text segment. Ok, allocate some memory from PROM and copy symbol information * over there. */ static void ksyms_copyout(void **ssym, void **esym) { uint8_t *addr; int kssize = (int)(long)((char *)*esym - (char *)*ssym + 1); DPRINTF(("ksyms_copyout(): ssym = %p, esym = %p, kssize = %d\n", *ssym, *esym, kssize)); if ( (addr = OF_claim(0, kssize, NBPG)) == (void *)-1) { panic("ksyms_copyout(): no space for symbol table"); } memcpy(addr, *ssym, kssize); *ssym = addr; *esym = addr + kssize - 1; DPRINTF(("ksyms_copyout(): ssym = %p, esym = %p\n", *ssym, *esym)); }
void mp_init(void) { struct tte *tp; int i; mp_tramp = (vm_offset_t)OF_claim(NULL, PAGE_SIZE, PAGE_SIZE); if (mp_tramp == (vm_offset_t)-1) panic("%s", __func__); bcopy(mp_tramp_code, (void *)mp_tramp, mp_tramp_code_len); *(vm_offset_t *)(mp_tramp + mp_tramp_tlb_slots) = kernel_tlb_slots; *(vm_offset_t *)(mp_tramp + mp_tramp_func) = (vm_offset_t)mp_startup; tp = (struct tte *)(mp_tramp + mp_tramp_code_len); for (i = 0; i < kernel_tlb_slots; i++) { tp[i].tte_vpn = TV_VPN(kernel_tlbs[i].te_va, TS_4M); tp[i].tte_data = TD_V | TD_4M | TD_PA(kernel_tlbs[i].te_pa) | TD_L | TD_CP | TD_CV | TD_P | TD_W; } for (i = 0; i < PAGE_SIZE; i += sizeof(vm_offset_t)) flush(mp_tramp + i); }
int main() { int chosen; /* * Get the boot arguments from Openfirmware */ if ((chosen = OF_finddevice("/chosen")) == -1 || OF_getprop(chosen, "bootpath", bootdev, sizeof bootdev) < 0 || OF_getprop(chosen, "bootargs", bootline, sizeof bootline) < 0) { printf("Invalid Openfirmware environment\n"); exit(); } prom2boot(bootdev); get_alt_bootdev(bootdev, sizeof(bootdev), bootline, sizeof(bootline)); if (bootline[0] != '\0') kernelfile = bootline; OF_claim((void *)0x00100000, CLAIM_LIMIT, 0); /* XXX */ boot(0); return 0; }
void * ofw_alloc_heap(unsigned int size) { phandle_t memoryp, root; cell_t available[4]; cell_t acells; root = OF_finddevice("/"); acells = 1; OF_getprop(root, "#address-cells", &acells, sizeof(acells)); memoryp = OF_instance_to_package(memory); OF_getprop(memoryp, "available", available, sizeof(available)); heap_base = OF_claim((void *)available[acells-1], size, sizeof(register_t)); if (heap_base != (void *)-1) { heap_size = size; } return (heap_base); }
void * alloc(size_t size) { struct ml *f, *bestf; #ifndef ALLOC_FIRST_FIT unsigned bestsize = 0xffffffff; /* greater than any real size */ #endif char *help; int failed; #ifdef ALLOC_TRACE printf("alloc(%zu)", size); #endif /* * Account for overhead now, so that we don't get an * "exact fit" which doesn't have enough space. */ size = ALIGN(size) + OVERHEAD; #ifdef ALLOC_FIRST_FIT /* scan freelist */ for (f = freelist.lh_first; f != NULL && (size_t)f->size < size; f = f->list.le_next) /* noop */ ; bestf = f; failed = (bestf == NULL); #else /* scan freelist */ bestf = NULL; /* XXXGCC: -Wuninitialized */ f = freelist.lh_first; while (f != NULL) { if ((size_t)f->size >= size) { if ((size_t)f->size == size) /* exact match */ goto found; if (f->size < bestsize) { /* keep best fit */ bestf = f; bestsize = f->size; } } f = f->list.le_next; } /* no match in freelist if bestsize unchanged */ failed = (bestsize == 0xffffffff); #endif if (failed) { /* nothing found */ /* * Allocate memory from the OpenFirmware, rounded * to page size, and record the chunk size. */ size = roundup(size, NBPG); help = OF_claim(NULL, (unsigned)size, NBPG); if (help == (char *)-1) panic("alloc: out of memory"); f = (struct ml *)help; f->size = (unsigned)size; #ifdef ALLOC_TRACE printf("=%lx (new chunk size %u)\n", (u_long)(help + OVERHEAD), f->size); #endif goto out; } /* we take the best fit */ f = bestf; #ifndef ALLOC_FIRST_FIT found: #endif /* remove from freelist */ LIST_REMOVE(f, list); help = (char *)f; #ifdef ALLOC_TRACE printf("=%lx (origsize %u)\n", (u_long)(help + OVERHEAD), f->size); #endif out: /* place on allocated list */ LIST_INSERT_HEAD(&allocatedlist, f, list); return (help + OVERHEAD); }
void main(void) { extern char bootprog_name[], bootprog_rev[]; int chosen; char bootline[512]; /* Should check size? */ char *cp, *startbuf, *endbuf; u_long marks[MARK_MAX], size; u_int32_t entry; void *ssym, *esym; printf("\n"); printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev); /* * Get the boot arguments from Openfirmware */ if ((chosen = OF_finddevice("/chosen")) == -1 || OF_getprop(chosen, "bootpath", bootdev, sizeof bootdev) < 0 || OF_getprop(chosen, "bootargs", bootline, sizeof bootline) < 0) { printf("Invalid Openfirmware environment\n"); OF_exit(); } prom2boot(bootdev); parseargs(bootline, &boothowto); DPRINTF("bootline=%s\n", bootline); /* * Per the ARM OpenFirmware bindings, the firmware must * allocate and map at least 6MB of physical memory starting * at VA 0xf0000000. We have been loaded at 0xf0000000, * and the memory after us has been unmapped and freed. * We expect to load the kernel at 0xf0100000, so we will * allocate 5MB of virtual memory starting there, and * unmap/free what we don't use. */ startbuf = OF_claim((void *) 0xf0100000, (5 * 1024 * 1024), 0); if (startbuf != (void *) 0xf0100000) { printf("Unable to claim buffer for kernel\n"); OF_exit(); } endbuf = startbuf + (5 * 1024 * 1024); for (;;) { int i; if (boothowto & RB_ASKNAME) { printf("Boot: "); gets(bootline); parseargs(bootline, &boothowto); } if (bootline[0]) { kernels[0] = bootline; kernels[1] = NULL; } for (i = 0; kernels[i]; i++) { DPRINTF("Trying %s\n", kernels[i]); marks[MARK_START] = 0xf0100000; if (loadfile(kernels[i], marks, LOAD_KERNEL) >= 0) goto loaded; } boothowto |= RB_ASKNAME; } loaded: /* * Okay, kernel is loaded, free the extra memory at the end. * Round to the ARM OpenFirmare page size (4k). */ cp = (char *) ((marks[MARK_END] + 0xfff) & ~0xfff); size = (u_long) (endbuf - cp); if (size) OF_release(cp, size); #ifdef __notyet__ OF_setprop(chosen, "bootpath", opened_name, strlen(opened_name) + 1); cp = bootline; #else strcpy(bootline, opened_name); cp = bootline + strlen(bootline); *cp++ = ' '; #endif *cp = '-'; if (boothowto & RB_ASKNAME) *++cp = 'a'; if (boothowto & RB_SINGLE) *++cp = 's'; if (boothowto & RB_KDB) *++cp = 'd'; if (*cp == '-') #ifdef __notyet__ *cp = 0; #else *--cp = 0; #endif else