void pit_set_timer(uint32_t divisor, uint32_t mode) { if (divisor & 0xffff0000) warn("Divisor too large!"); mode = TIMER_SEL0|TIMER_16BIT|mode; outb(TIMER_MODE, mode); outb(TIMER_CNTR0, divisor & 0xff); outb(TIMER_CNTR0, (divisor >> 8) ); system_timing.pit_mode = SINIT(mode); system_timing.pit_divisor = SINIT(divisor); // cprintf("timer mode set to %d, divisor %d\n",mode, divisor); }
/************** Cache Related Functions *****************/ void cache_init() { // Initialize the caches available on this system. // TODO: Should call out to something reading the acpi tables from // memory, or something similar. For now, just initialize them inline available_caches.l1 = SINIT(&l1); available_caches.l2 = SINIT(&l2); available_caches.l3 = SINIT(&l3); llc_cache = &l3; init_cache_properties(&l1, 32, 8, 64); init_cache_properties(&l2, 256, 8, 64); init_cache_properties(&l3, 8192, 16, 64); printk("Cache init successful\n"); }
/************** Cache Related Functions *****************/ void cache_init() { // Initialize the caches available on this system. // TODO: Should call out to something reading the acpi tables from // memory, or something similar. For now, just initialize them inline available_caches.l1 = SINIT(&l1); available_caches.l2 = SINIT(&l2); available_caches.l3 = SINIT(&l3); llc_cache = &l3; #ifdef __CONFIG_BOXBORO__ /* level (ignoring L1I), size, ways, CL size) */ init_cache_properties(&l1, 32, 8, 64); /* 1 color */ init_cache_properties(&l2, 256, 8, 64); /* 16 colors */ init_cache_properties(&l3, 24576, 24, 64); /* 256 colors */ #else /* Core i7 */ init_cache_properties(&l1, 32, 8, 64); /* 1 color */ init_cache_properties(&l2, 256, 8, 64); /* 16 colors */ init_cache_properties(&l3, 8192, 16, 64); /* 128 colors */ #endif /* __CONFIG_E1000_ON_BOXBORO__ */ printk("Cache init successful\n"); }
// timer init calibrates both tsc timer and lapic timer using PIT void timer_init(void){ uint64_t tscval[2]; long timercount[2]; pit_set_timer(0xffff, TIMER_RATEGEN); // assume tsc exist tscval[0] = read_tsc(); udelay_pit(1000000); tscval[1] = read_tsc(); system_timing.tsc_freq = SINIT(tscval[1] - tscval[0]); cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq); __lapic_set_timer(0xffffffff, LAPIC_TIMER_DEFAULT_VECTOR, FALSE, LAPIC_TIMER_DEFAULT_DIVISOR); // Mask the LAPIC Timer, so we never receive this interrupt (minor race) mask_lapic_lvt(LAPIC_LVT_TIMER); timercount[0] = read_mmreg32(LAPIC_TIMER_CURRENT); udelay_pit(1000000); timercount[1] = read_mmreg32(LAPIC_TIMER_CURRENT); system_timing.bus_freq = SINIT((timercount[0] - timercount[1])*128); cprintf("Bus Frequency: %llu\n", system_timing.bus_freq); }
nserror mimesniff_init(void) { lwc_error lerror; #define SINIT(v, s) \ lerror = lwc_intern_string(s, SLEN(s), &v); \ if (lerror != lwc_error_ok) \ return NSERROR_NOMEM SINIT(unknown_unknown, "unknown/unknown"); SINIT(application_unknown, "application/unknown"); SINIT(any, "*/*"); SINIT(text_xml, "text/xml"); SINIT(application_xml, "application/xml"); SINIT(text_html, "text/html"); SINIT(text_plain, "text/plain"); SINIT(application_octet_stream, "application/octet-stream"); SINIT(image_gif, "image/gif"); SINIT(image_png, "image/png"); SINIT(image_jpeg, "image/jpeg"); SINIT(image_bmp, "image/bmp"); SINIT(image_vnd_microsoft_icon, "image/vnd.microsoft.icon"); SINIT(image_webp, "image/webp"); SINIT(application_rss_xml, "application/rss+xml"); SINIT(application_atom_xml, "application/atom+xml"); SINIT(audio_wave, "audio/wave"); SINIT(application_ogg, "application/ogg"); SINIT(video_webm, "video/webm"); SINIT(application_x_rar_compressed, "application/x-rar-compressed"); SINIT(application_zip, "application/zip"); SINIT(application_x_gzip, "application/x-gzip"); SINIT(application_postscript, "application/postscript"); SINIT(application_pdf, "application/pdf"); SINIT(video_mp4, "video/mp4"); SINIT(image_svg, "image/svg+xml"); #undef SINIT return NSERROR_OK; }