/** Create PTL0. * * PTL0 of 4-level page table will be created for each address space. * * @param flags Flags can specify whether ptl0 is for the kernel address space. * * @return New PTL0. * */ pte_t *ptl0_create(unsigned int flags) { pte_t *dst_ptl0 = (pte_t *) PA2KA(frame_alloc(PTL0_FRAMES, FRAME_LOWMEM, PTL0_SIZE - 1)); if (flags & FLAG_AS_KERNEL) memsetb(dst_ptl0, PTL0_SIZE, 0); else { /* * Copy the kernel address space portion to new PTL0. */ mutex_lock(&AS_KERNEL->lock); pte_t *src_ptl0 = (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table); uintptr_t src = (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; uintptr_t dst = (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; memsetb(dst_ptl0, PTL0_SIZE, 0); memcpy((void *) dst, (void *) src, PTL0_SIZE - (src - (uintptr_t) src_ptl0)); mutex_unlock(&AS_KERNEL->lock); } return (pte_t *) KA2PA((uintptr_t) dst_ptl0); }
/** Initialize a call structure. * * @param call Call structure to be initialized. * */ static void _ipc_call_init(call_t *call) { memsetb(call, sizeof(*call), 0); spinlock_initialize(&call->forget_lock, "forget_lock"); call->active = false; call->forget = false; call->sender = NULL; call->buffer = NULL; }
/** Initialize one IRQ structure. * * @param irq Pointer to the IRQ structure to be initialized. * */ void irq_initialize(irq_t *irq) { memsetb(irq, sizeof(irq_t), 0); link_initialize(&irq->link); irq_spinlock_initialize(&irq->lock, "irq.lock"); irq->inr = -1; irq->devno = -1; irq_initialize_arch(irq); }
void ras_init(void) { uintptr_t frame = frame_alloc(1, FRAME_ATOMIC | FRAME_HIGHMEM, 0); if (!frame) frame = frame_alloc(1, FRAME_LOWMEM, 0); ras_page = (uintptr_t *) km_map(frame, PAGE_SIZE, PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE); memsetb(ras_page, PAGE_SIZE, 0); ras_page[RAS_START] = 0; ras_page[RAS_END] = 0xffffffff; }
/** Initialize CPUs * * Initialize kernel CPUs support. * */ void cpu_init(void) { #ifdef CONFIG_SMP if (config.cpu_active == 1) { #endif /* CONFIG_SMP */ cpus = (cpu_t *) malloc(sizeof(cpu_t) * config.cpu_count, FRAME_ATOMIC); if (!cpus) panic("Cannot allocate CPU structures."); /* Initialize everything */ memsetb(cpus, sizeof(cpu_t) * config.cpu_count, 0); size_t i; for (i = 0; i < config.cpu_count; i++) { cpus[i].stack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_LOWMEM | FRAME_KA | FRAME_ATOMIC); cpus[i].id = i; irq_spinlock_initialize(&cpus[i].lock, "cpus[].lock"); unsigned int j; for (j = 0; j < RQ_COUNT; j++) { irq_spinlock_initialize(&cpus[i].rq[j].lock, "cpus[].rq[].lock"); list_initialize(&cpus[i].rq[j].rq); } } #ifdef CONFIG_SMP } #endif /* CONFIG_SMP */ CPU = &cpus[config.cpu_active - 1]; CPU->active = true; CPU->tlb_active = true; CPU->idle = false; CPU->last_cycle = get_cycle(); CPU->idle_cycles = 0; CPU->busy_cycles = 0; cpu_identify(); cpu_arch_init(); }
int as_constructor_arch(as_t *as, unsigned int flags) { #ifdef CONFIG_TSB uintptr_t tsb_phys = frame_alloc(SIZE2FRAMES((ITSB_ENTRY_COUNT + DTSB_ENTRY_COUNT) * sizeof(tsb_entry_t)), flags, 0); if (!tsb_phys) return -1; tsb_entry_t *tsb = (tsb_entry_t *) PA2KA(tsb_phys); as->arch.itsb = tsb; as->arch.dtsb = tsb + ITSB_ENTRY_COUNT; memsetb(as->arch.itsb, (ITSB_ENTRY_COUNT + DTSB_ENTRY_COUNT) * sizeof(tsb_entry_t), 0); #endif return 0; }
void tss_initialize(tss_t *t) { memsetb(t, sizeof(tss_t), 0); }
/** Function 01h - Return VBE Mode Information * * Input: * AX = 4F01h * CX = Mode Number * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure * Output: * AX = VBE Return Status * */ void vbe_biosfn_return_mode_information(uint16_t STACK_BASED *AX, uint16_t CX, uint16_t ES, uint16_t DI) { uint16_t result = 0x0100; #ifdef VBE_NEW_DYN_LIST uint16_t cur_info_ofs; #else ModeInfoListItem *cur_info; #endif Boolean using_lfb; uint8_t win_attr; #ifdef VGA_DEBUG printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX); #endif using_lfb = ((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER); CX = (CX & 0x1ff); #ifdef VBE_NEW_DYN_LIST cur_info_ofs = mode_info_find_mode(CX, using_lfb); if (cur_info_ofs) { uint16_t i; #else cur_info = mode_info_find_mode(CX, using_lfb); if (cur_info != 0) { #endif #ifdef VGA_DEBUG printf("VBE found mode %x\n",CX); #endif memsetb(ES, DI, 0, 256); // The mode info size is fixed #ifdef VBE_NEW_DYN_LIST for (i = 0; i < sizeof(ModeInfoBlockCompact); i++) { uint8_t b; b = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info) + i/*(char *)(&(cur_info->info)) + i*/); write_byte(ES, DI + i, b); } #else memcpyb(ES, DI, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact)); #endif win_attr = read_byte(ES, DI + offsetof(ModeInfoBlock, WinAAttributes)); if (win_attr & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) { write_word(ES, DI + offsetof(ModeInfoBlock, WinFuncPtr), (uint16_t)(dispi_set_bank_farcall)); // If BIOS not at 0xC000 -> boom write_word(ES, DI + offsetof(ModeInfoBlock, WinFuncPtr) + 2, 0xC000); } // Update the LFB physical address which may change at runtime out_w(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_FB_BASE_HI); write_word(ES, DI + offsetof(ModeInfoBlock, PhysBasePtr) + 2, in_w(VBE_DISPI_IOPORT_DATA)); result = 0x4f; } else { #ifdef VGA_DEBUG printf("VBE *NOT* found mode %x\n",CX); #endif result = 0x100; } *AX = result; } /** Function 02h - Set VBE Mode * * Input: * AX = 4F02h * BX = Desired Mode to set * ES:DI = Pointer to CRTCInfoBlock structure * Output: * AX = VBE Return Status * */ void vbe_biosfn_set_mode(uint16_t STACK_BASED *AX, uint16_t BX, uint16_t ES, uint16_t DI) { uint16_t result; #ifdef VBE_NEW_DYN_LIST uint16_t cur_info_ofs; #else ModeInfoListItem *cur_info; #endif Boolean using_lfb; uint8_t no_clear; uint8_t lfb_flag; using_lfb = ((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER); lfb_flag = using_lfb ? VBE_DISPI_LFB_ENABLED : 0; no_clear = ((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY) ? VBE_DISPI_NOCLEARMEM : 0; BX = (BX & 0x1ff); // check for non vesa mode if (BX < VBE_MODE_VESA_DEFINED) { uint8_t mode; dispi_set_enable(VBE_DISPI_DISABLED); // call the vgabios in order to set the video mode // this allows for going back to textmode with a VBE call (some applications expect that to work) mode = (BX & 0xff); biosfn_set_video_mode(mode); result = 0x4f; goto leave; } #ifdef VBE_NEW_DYN_LIST cur_info_ofs = mode_info_find_mode(BX, using_lfb); if (cur_info_ofs != 0) { uint16_t xres, yres; uint8_t bpp; xres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.XResolution) /*&cur_info->info.XResolution*/); yres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.YResolution) /*&cur_info->info.YResolution*/); bpp = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.BitsPerPixel) /*&cur_info->info.BitsPerPixel*/); #ifdef VGA_DEBUG printf("VBE found mode %x, setting:\n", BX); printf("\txres%x yres%x bpp%x\n", xres, yres, bpp); #endif #else cur_info = mode_info_find_mode(BX, using_lfb); if (cur_info != 0) { #ifdef VGA_DEBUG printf("VBE found mode %x, setting:\n", BX); printf("\txres%x yres%x bpp%x\n", cur_info->info.XResolution, cur_info->info.YResolution, cur_info->info.BitsPerPixel); #endif #endif // VBE_NEW_DYN_LIST // first disable current mode (when switching between vesa modi) dispi_set_enable(VBE_DISPI_DISABLED); #ifdef VBE_NEW_DYN_LIST if (bpp == 4) #else if (cur_info->info.BitsPerPixel == 4) #endif { biosfn_set_video_mode(0x6a); } #ifdef VBE_NEW_DYN_LIST dispi_set_bpp(bpp); dispi_set_xres(xres); dispi_set_yres(yres); #else dispi_set_bpp(cur_info->info.BitsPerPixel); dispi_set_xres(cur_info->info.XResolution); dispi_set_yres(cur_info->info.YResolution); #endif dispi_set_bank(0); dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag); vga_compat_setup(); write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX); write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear)); result = 0x4f; } else { #ifdef VGA_DEBUG printf("VBE *NOT* found mode %x\n" , BX); #endif result = 0x100; } leave: *AX = result; } uint16_t vbe_biosfn_read_video_state_size(void) { return 9 * 2; } void vbe_biosfn_save_video_state(uint16_t ES, uint16_t BX) { uint16_t enable, i; outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE); enable = inw(VBE_DISPI_IOPORT_DATA); write_word(ES, BX, enable); BX += 2; if (!(enable & VBE_DISPI_ENABLED)) return; for(i = VBE_DISPI_INDEX_XRES; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) { if (i != VBE_DISPI_INDEX_ENABLE) { outw(VBE_DISPI_IOPORT_INDEX, i); write_word(ES, BX, inw(VBE_DISPI_IOPORT_DATA)); BX += 2; } } }
void vhpt_invalidate_all() { memsetb(vhpt_base, VHPT_SIZE, 0); }
int __attribute__ ((visibility ("internal"))) decompress8 (FILE *module, void *dst, int len, char it215) { sbyte *destbuf; /* the destination buffer which will be returned */ word blklen; /* length of compressed data block in samples */ word blkpos; /* position in block */ byte width; /* actual "bit width" */ word value; /* value read from file to be processed */ sbyte d1, d2; /* integrator buffers (d2 for it2.15) */ sbyte *destpos; destbuf = (sbyte *)dst; if (!destbuf) return 0; memsetb(destbuf,0,len); destpos=destbuf; /* position in output buffer */ /* now unpack data till the dest buffer is full */ while (len) { /* read a new block of compressed data and reset variables */ if (!readblock(module)) return 0; blklen=(len<0x8000)?len:0x8000; blkpos=0; width=9; /* start with width of 9 bits */ d1=d2=0; /* reset integrator buffers */ /* now uncompress the data block */ while (blkpos<blklen) { sbyte v; value = readbits(width); /* read bits */ if (width<7) /* method 1 (1-6 bits) */ { if (value==(1<<(width-1))) /* check for "100..." */ { value = readbits(3)+1; /* yes -> read new width; */ width = (value<width)?value:value+1; /* and expand it */ continue; /* ... next value */ } } else if (width<9) /* method 2 (7-8 bits) */ { byte border = (0xFF>>(9-width)) - 4; /* lower border for width chg */ if (value>border && value <=(border+8)) { value-=border; /* convert width to 1-8 */ width = (value<width)?value:value+1; /* and expand it */ continue; /* ... next value */ } } else if (width==9) /* method 3 (9 bits) */ { if (value & 0x100) /* bit 8 set? */ { width=(value+1)&0xff; /* new width... */ continue; /* ... and next value */ } } else { /* illegal width, abort */ freeblock(); return 0; } /* now expand value to signed byte */ /* sbyte v; // sample value */ if (width<8) { byte shift=8-width; v = (value<<shift); v>>=shift; } else