double rot(struct place center, struct place zenith) { Xyz cen = ptov(center); Xyz zen = ptov(zenith); if(cen.z > 1-FUZZ) /* center at N pole */ return PI + zenith.wlon.l; if(cen.z < FUZZ-1) /* at S pole */ return -zenith.wlon.l; if(fabs(dot(cen,zen)) > 1-FUZZ) /* at zenith */ return 0; return azimuth(cen, zen); }
/* Initializes the page allocator. At most USER_PAGE_LIMIT pages are put into the user pool. */ void palloc_init (size_t user_page_limit) { /* Free memory starts at 1 MB and runs to the end of RAM. */ uint8_t *free_start = ptov (1024 * 1024); uint8_t *free_end = ptov (init_ram_pages * PGSIZE); size_t free_pages = (free_end - free_start) / PGSIZE; size_t user_pages = free_pages / 2; size_t kernel_pages; if (user_pages > user_page_limit) user_pages = user_page_limit; kernel_pages = free_pages - user_pages; /* Give half of memory to kernel, half to user. */ init_pool (&kernel_pool, free_start, kernel_pages, "kernel pool"); init_pool (&user_pool, free_start + kernel_pages * PGSIZE, user_pages, "user pool"); }
/*! Initializes the VGA text display. */ static void init(void) { /* Already initialized? */ static bool inited; if (!inited) { fb = ptov(0xb8000); find_cursor(&cx, &cy); inited = true; } }
void *fsl_buffer_alloc(u32 pool_id) { struct bm_buffer buf; int ret = bman_acquire(helper_pool[pool_id], &buf, 1, 0); if (ret < 0) { TRACE("bman acquire failure, pool %d, ret %d\n", pool_id, ret); return NULL; } return (void *)ptov(buf.addr); }
int biosread(int dev, int cyl, int head, int sec, int num) { int i; bb.intno = 0x13; sec += 1; // sector numbers start at 1. for (i=0;;) { bb.ecx.r.h = cyl; bb.ecx.r.l = ((cyl & 0x300) >> 2) | (sec & 0x3F); bb.edx.r.h = head; bb.edx.r.l = dev; bb.eax.r.l = num; bb.ebx.rr = OFFSET(ptov(BIOS_ADDR)); bb.es = SEGMENT(ptov(BIOS_ADDR)); bb.eax.r.h = 0x02; bios(&bb); // In case of a successful call, make sure we set AH (return code) to zero. if (bb.flags.cf == 0) { bb.eax.r.h = 0; } // Now we can really check for the return code (AH) value. if ((bb.eax.r.h == 0x00) || (i++ >= 5)) { break; } // Reset disk subsystem and try again. bb.eax.r.h = 0x00; bios(&bb); } return bb.eax.r.h; }
static void startMotion(int x, int y, int but, int time) { if (but == GLUT_LEFT_BUTTON) { mode = MoveView; } else if (but == GLUT_MIDDLE_BUTTON) { mode = MoveTexture; } else { return; } lastTime = time; ptov(x, y, winWidth, winHeight, lastPos); }
void startMotion(int x, int y, int but, int time) { if (but == GLUT_LEFT_BUTTON) { mode = MoveView; } else if (but == GLUT_RIGHT_BUTTON) { mode = MoveTexture; } else { return; } trackingMotion = GL_TRUE; redrawContinuously = GL_FALSE; lastTime = time; ptov(x, y, winWidth, winHeight, lastPos); }
/* Update the frame table entries from the old PTE addresses to the new PTE addresses according to the new PD */ void frame_table_change_pagedir (struct frame_table *ft, uint32_t *pd) { ASSERT (ft != NULL); ASSERT (pd != NULL); size_t i; for (i = 0; i < ft->page_cnt; i++) { if (ft->frames[i].frame != NULL) { uint32_t *old_pte = ft->frames[i].frame; uint32_t paddr = *old_pte & ~PGMASK; uint32_t *new_pte = lookup_page (pd, ptov(paddr), false); ASSERT ((*old_pte & ~PGMASK) == (*new_pte & ~PGMASK)); ft->frames[i].frame = new_pte; } } }
static void *translate_address (uint uva, int align) { Pte *ptep; void *ptr = NULL; ptep = env_va2ptep (curenv, uva); if (ptep) { /* && (*ptep & bits) == bits) { */ ptr = (struct dinode *) (ptov (*ptep & ~PGMASK) + (uva % NBPG)); if ((align) && ((uint)ptr % align)) { ptr = NULL; } } if ((ptr == NULL) && (uva != 0)) { printf ("fsprot: translate_address: bad address supplied (%x, align %d)\n", uva, align); } return (ptr); }
/* Initializes the page allocator. */ void palloc_init (void) { /* End of the kernel as recorded by the linker. See kernel.lds.S. */ extern char _end; /* Free memory. */ uint8_t *free_start = pg_round_up (&_end); uint8_t *free_end = ptov (ram_pages * PGSIZE); size_t free_pages = (free_end - free_start) / PGSIZE; size_t user_pages = free_pages / 2; size_t kernel_pages; if (user_pages > user_page_limit) user_pages = user_page_limit; kernel_pages = free_pages - user_pages; /* Give half of memory to kernel, half to user. */ init_pool (&kernel_pool, free_start, kernel_pages, "kernel pool"); init_pool (&user_pool, free_start + kernel_pages * PGSIZE, user_pages, "user pool"); }
static void trackMotion(int x, int y) { float curPos[3], dx, dy, dz; ptov(x, y, winWidth, winHeight, curPos); dx = curPos[0] - lastPos[0]; dy = curPos[1] - lastPos[1]; dz = curPos[2] - lastPos[2]; angle = 90.0 * sqrt(dx * dx + dy * dy + dz * dz); axis[0] = lastPos[1] * curPos[2] - lastPos[2] * curPos[1]; axis[1] = lastPos[2] * curPos[0] - lastPos[0] * curPos[2]; axis[2] = lastPos[0] * curPos[1] - lastPos[1] * curPos[0]; lastTime = glutGet(GLUT_ELAPSED_TIME); lastPos[0] = curPos[0]; lastPos[1] = curPos[1]; lastPos[2] = curPos[2]; glutPostRedisplay(); }
int ebiosread(int dev, unsigned long long sec, int count) { int i; static struct { unsigned char size; unsigned char reserved; unsigned char numblocks; unsigned char reserved2; unsigned short bufferOffset; unsigned short bufferSegment; unsigned long long startblock; } addrpacket __attribute__((aligned(16))) = {0}; addrpacket.size = sizeof(addrpacket); for (i = 0; ;) { bb.intno = 0x13; bb.eax.r.h = 0x42; bb.edx.r.l = dev; bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket); bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket); addrpacket.reserved = addrpacket.reserved2 = 0; addrpacket.numblocks = count; addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR)); addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR)); addrpacket.startblock = sec; bios(&bb); // In case of a successful call, make sure we set AH (return code) to zero. if (bb.flags.cf == 0) { bb.eax.r.h = 0; } // Now we can really check for the return code (AH) value. if ((bb.eax.r.h == 0x00) || (i++ >= 5)) { break; } // Reset disk subsystem and try again. bb.eax.r.h = 0x00; bios(&bb); } return bb.eax.r.h; } //============================================================================== void putc(int ch) { bb.intno = 0x10; bb.ebx.r.h = 0x00; /* background black */ bb.ebx.r.l = 0x0F; /* foreground white */ bb.eax.r.h = 0x0e; bb.eax.r.l = ch; bios(&bb); }
#include "efi_tables.h" #define BPS 512 // sector size of the device. #define PROBEFS_SIZE BPS * 4 // buffer size for filesystem probe. // #define CD_BPS 2048 // CD-ROM block size. #define N_CACHE_SECS (BIOS_LEN / BPS) // Must be a multiple of 4 for CD-ROMs. // IORound and IOTrunc convenience functions, in the spirit of vm's round_page() and trunc_page(). #define IORound(value, multiple) ((((value) + (multiple) - 1) / (multiple)) * (multiple)) #define IOTrunc(value, multiple) (((value) / (multiple)) * (multiple)); // trackbuf points to the start of the track cache. Biosread() // will store the sectors read from disk to this memory area. static char * const trackbuf = (char *) ptov(BIOS_ADDR); // biosbuf points to a sector within the track cache, and is updated by Biosread(). static char * biosbuf; // Map a disk drive to bootable volumes contained within. struct DiskBVMap { int biosdev; // BIOS device number (unique). BVRef bvr; // Chain of boot volumes on the disk. int bvrcnt; // Number of boot volumes. struct DiskBVMap * next; // Linkage to next mapping. }; static struct DiskBVMap * gDiskBVMap = NULL; static struct disk_blk0 * gBootSector = NULL;
/* A predicate is represented as a sum-of-products, that is (A1 A2 ... ) OR (B1 B2 ...) OR ... where each element in a product (the A?'s and B?'s) are simple predicates like v > 10. Predicates are represented in memory as an array of wk_term's, one term for each immediate, variable, operator, conjunction or disjunction. A single product is considered to be a group of contiguous wk_term's that are not WK_ORs. The whole mess is terminated by a WK_END. */ #include <vcode/vcode.h> #include <xok/wk.h> #include <xok/mmu.h> #include <xok/sys_proto.h> #include <xok/kerrno.h> #include <xok/malloc.h> #include <xok_include/assert.h> #include <xok/printf.h> #ifndef __CAP__ #include <xok/pmapP.h> #else #include <xok/pmap.h> #endif #define WK_MAX_CODE_BYTES 4096 #define OVERRUN_SAFETY 20 #define OVERRUN_CHECK \ { \ if (v_ip > code + WK_MAX_CODE_BYTES - OVERRUN_SAFETY) { \ warn ("wk_compile: out of code space\n"); \ ret = -E_INVAL; \ goto error; \ } \ } static int next_pp; /* outside function so can be used by cleanup code */ static int wk_compile (struct wk_term *t, int sz, char *code, u_int *pred_pages) { int i; v_reg_t r1, r2, z, tag; v_label_t end_of_term; int start_term = 1; int op1 = 1; cap c; struct Ppage *pp; u_int ppn; int ret = 0; next_pp = 0; v_lambda ("", "", NULL, 1, code, WK_MAX_CODE_BYTES); if (!v_getreg (&r1, V_U, V_TEMP) || !v_getreg (&r2, V_U, V_TEMP) || !v_getreg (&z, V_U, V_TEMP) || !v_getreg (&tag, V_U, V_TEMP)) panic ("wk_compile: architecture doesn't have enough registers."); v_setu (tag, -1); v_setu (z, 0); for (i = 0; i < sz; i++) { if (start_term) { end_of_term = v_genlabel (); start_term = 0; } OVERRUN_CHECK; switch (t[i].wk_type) { case WK_VAR: if (next_pp >= WK_MAX_PP-1) { warn ("wk_compile: too many pages in predicate\n"); ret = -E_INVAL; goto error; } if ((ret = env_getcap (curenv, t[i].wk_cap, &c)) < 0) { goto error; } ppn = PGNO((u_int)t[i].wk_var); if (!ppn || ppn >= nppage) { printf ("at index %d\n", i); warn ("wk_compile: invalid physical page\n"); ret = -E_INVAL; goto error; } pp = ppages_get(ppn); switch (Ppage_pp_status_get(pp)) { case PP_USER: if ((ret = ppage_acl_check(pp,&c,PP_ACL_LEN,0)) < 0) { goto error; } ppage_pin (pp); pred_pages[next_pp++] = ppn; break; case PP_KERNRO: /* user can access pages that each env get's mapped r/o */ break; default: printf ("at index %d\n", i); warn ("wk_compile: attempt to reference non PP_KERNRO or PP_USER page\n"); ret = -E_INVAL; goto error; } if (op1) { v_ldui (r1, z, (int )ptov (t[i].wk_var)); op1 = 0; } else { v_ldui (r2, z, (int )ptov (t[i].wk_var)); op1 = 1; } break; case WK_IMM: if (op1) { v_setu (r1, t[i].wk_imm); op1 = 0; } else { v_setu (r2, t[i].wk_imm); op1 = 1; } break; case WK_TAG: { v_setu (tag, t[i].wk_tag); break; } case WK_OP: { switch (t[i].wk_op) { case WK_GT: { v_bleu (r1, r2, end_of_term); break; } case WK_GTE: { v_bltu (r1, r2, end_of_term); break; } case WK_LT: { v_bgeu (r1, r2, end_of_term); break; } case WK_LTE: { v_bgtu (r1, r2, end_of_term); break; } case WK_EQ: { v_bneu (r1, r2, end_of_term); break; } case WK_NEQ: { v_bequ (r1, r2, end_of_term); break; } case WK_OR: { v_retu (tag); v_label (end_of_term); start_term = 1; break; } default: { printf ("at index %d\n", i); warn ("wk_compile: invalid wk-pred instruction\n"); ret = -E_INVAL; goto error; } } break; } default: printf ("at index %d\n", i); warn ("wk_compile: invalid wk-pred type\n"); ret = -E_INVAL; goto error; } } /* end the last term */ OVERRUN_CHECK; v_retu (tag); v_label (end_of_term); v_retui (0); v_end (NULL); error: /* have to do this even on error so that our caller can just call wk_free to clean memory/ref counts up */ pred_pages[next_pp] = 0; curenv->env_pred_pgs = pred_pages; curenv->env_pred = (Spred)code; return ret; }