uintptr_t mcall_clear_ipi(void) { // only clear SSIP if no other events are pending if (HLS()->device_response_queue_head == NULL) { clear_csr(mip, MIP_SSIP); mb(); } return atomic_swap(&HLS()->ipi_pending, 0); }
uintptr_t mcall_dev_req(sbi_device_message *m) { if ((m->dev > 0xFFU) | (m->cmd > 0xFFU) | (m->data > 0x0000FFFFFFFFFFFFU)) return -EINVAL; while (swap_csr(mtohost, TOHOST_CMD(m->dev, m->cmd, m->data)) != 0); m->sbi_private_data = (uintptr_t)HLS()->device_request_queue_head; HLS()->device_request_queue_head = m; HLS()->device_request_queue_size++; return 0; }
void stage_entry(int hart_id, void *fdt) { /* * Save the FDT pointer before entering ramstage, because mscratch * might be overwritten in the trap handler, and there is code in * ramstage that generates misaligned access faults. */ HLS()->hart_id = hart_id; HLS()->fdt = fdt; smp_pause(CONFIG_RISCV_WORKING_HARTID); main(); }
HLSCOLOR RGB2HLS (COLORREF rgb) { unsigned char minval = min(GetRValue(rgb), min(GetGValue(rgb), GetBValue(rgb))); unsigned char maxval = max(GetRValue(rgb), max(GetGValue(rgb), GetBValue(rgb))); float mdiff = float(maxval) - float(minval); float msum = float(maxval) + float(minval); float luminance = msum / 510.0f; float saturation = 0.0f; float hue = 0.0f; if ( maxval != minval ) { float rnorm = (maxval - GetRValue(rgb) ) / mdiff; float gnorm = (maxval - GetGValue(rgb)) / mdiff; float bnorm = (maxval - GetBValue(rgb) ) / mdiff; saturation = (luminance <= 0.5f) ? (mdiff / msum) : (mdiff / (510.0f - msum)); if (GetRValue(rgb) == maxval) hue = 60.0f * (6.0f + bnorm - gnorm); if (GetGValue(rgb) == maxval) hue = 60.0f * (2.0f + rnorm - bnorm); if (GetBValue(rgb) == maxval) hue = 60.0f * (4.0f + gnorm - rnorm); if (hue > 360.0f) hue = hue - 360.0f; } return HLS ((hue*255)/360, luminance*255, saturation*255); }
COLORREF HLS_TRANSFORM (COLORREF rgb, int percent_L, int percent_S) { HLSCOLOR hls = RGB2HLS (rgb); BYTE h = HLS_H(hls); BYTE l = HLS_L(hls); BYTE s = HLS_S(hls); if ( percent_L > 0 ) { l = BYTE(l + ((255 - l) * percent_L) / 100); } else if ( percent_L < 0 ) { l = BYTE((l * (100+percent_L)) / 100); } if ( percent_S > 0 ) { s = BYTE(s + ((255 - s) * percent_S) / 100); } else if ( percent_S < 0 ) { s = BYTE((s * (100+percent_S)) / 100); } return HLS2RGB (HLS(h, l, s)); }
void OperaColors::EnlightenFlood(const COLORREF& clr, COLORREF& a, COLORREF& b) { HLSCOLOR hls_a = ::RGB2HLS(clr); HLSCOLOR hls_b = hls_a; BYTE buf = HLS_L(hls_a); if (buf < 38) buf = 0; else buf -= 38; a = ::HLS2RGB(HLS(HLS_H(hls_a), buf, HLS_S(hls_a))); buf = HLS_L(hls_b); if (buf > 217) buf = 255; else buf += 38; b = ::HLS2RGB(HLS(HLS_H(hls_b), buf, HLS_S(hls_b))); }
uintptr_t htif_interrupt(uintptr_t mcause, uintptr_t* regs) { uintptr_t fromhost = swap_csr(mfromhost, 0); if (!fromhost) return 0; uintptr_t dev = FROMHOST_DEV(fromhost); uintptr_t cmd = FROMHOST_CMD(fromhost); uintptr_t data = FROMHOST_DATA(fromhost); sbi_device_message* m = HLS()->device_request_queue_head; sbi_device_message* prev = 0x0; unsigned long i, n; for (i = 0, n = HLS()->device_request_queue_size; i < n; i++) { /* if (!supervisor_paddr_valid(m, sizeof(*m)) && EXTRACT_FIELD(read_csr(mstatus), MSTATUS_PRV1) != PRV_M) panic("htif: page fault"); */ sbi_device_message* next = (void*)m->sbi_private_data; if (m->dev == dev && m->cmd == cmd) { m->data = data; // dequeue from request queue if (prev) prev->sbi_private_data = (uintptr_t)next; else HLS()->device_request_queue_head = next; HLS()->device_request_queue_size = n-1; m->sbi_private_data = 0; // enqueue to response queue if (HLS()->device_response_queue_tail) { HLS()->device_response_queue_tail->sbi_private_data = (uintptr_t)m; } else { HLS()->device_response_queue_head = m; } HLS()->device_response_queue_tail = m; // signal software interrupt set_csr(mip, MIP_SSIP); return 0; } prev = m; m = (void*)atomic_read(&m->sbi_private_data); } //HLT(); return 0; //panic("htif: no record"); }
uintptr_t mcall_dev_resp(void) { htif_interrupt(0, 0); sbi_device_message* m = HLS()->device_response_queue_head; if (m) { //printm("resp %p\n", m); sbi_device_message* next = (void*)atomic_read(&m->sbi_private_data); HLS()->device_response_queue_head = next; if (!next) { HLS()->device_response_queue_tail = 0; // only clear SSIP if no other events are pending clear_csr(mip, MIP_SSIP); mb(); if (HLS()->ipi_pending) set_csr(mip, MIP_SSIP); } } return (uintptr_t)m; }
static void init_other_hart() { // wait until virtual memory is enabled while (root_page_table == NULL) asm volatile ("" ::: "memory"); mb(); write_csr(sptbr, root_page_table); // then make sure we're in bounds if (HLS()->hart_id >= num_harts) { while (1) wfi(); } boot_other_hart(); }
void CColorSpectrum::OnMouseMove(CPoint point, UINT nFlags) { CRect rcPos = m_rcPos; point.x -= rcPos.left; point.y -= rcPos.top; if (m_dragging) { COLORREF rgb; if (point.x > rcPos.Width()-20) { if (point.y < rcPos.Height()/2) { rgb = RGB(255, 255, 255); } else { rgb = RGB(0, 0, 0); } } else { int h = point.x * 255 / rcPos.Width(); int l = (rcPos.Height()-point.y)*255 / rcPos.Height(); int s = (rcPos.Height()-point.y)*255 / rcPos.Height(); if (h < 0) h = 0; else if (h > 255) h = 255; if (l < 0) l = 0; else if (l > 255) l = 255; if (s < 0) s = 0; else if (s > 255) s = 255; rgb = HLStoRGB(HLS(h, l, s)); } Fire_SetColorRGB(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); } }
void hls_init(uint32_t hart_id) { memset(HLS(), 0, sizeof(*HLS())); HLS()->hart_id = hart_id; }
void timer_monotonic_get(struct mono_time *mt) { if (HLS()->time == NULL) die("time not set in HLS"); mono_time_set_usecs(mt, (long)read64((void *)(HLS()->time))); }
HRESULT CColorSpectrum::OnDraw(ATL_DRAWINFO& di) { CRect& rc = *(CRect*)di.prcBounds; HDC hDC = di.hdcDraw; if (m_bEnabled) { #define ROWBYTES(width,bitcount) ((((width)*(bitcount)+31) >> 3) & 0xfffc) int width = rc.Width()-20; int height = rc.Height(); FillSolidRect(hDC, rc.left+width, rc.top, 20, height/2, RGB(255, 255, 255)); FillSolidRect(hDC, rc.left+width, rc.top+height/2, 20, rc.Height()-height/2, RGB(0, 0, 0)); int bytesPerRow = ROWBYTES(width, 24); BITMAPINFOHEADER bmi; ZeroMemory(&bmi, sizeof(bmi)); bmi.biSize = sizeof(BITMAPINFOHEADER); bmi.biWidth = width; bmi.biHeight = height; bmi.biPlanes = 1; bmi.biBitCount = 24; bmi.biCompression = BI_RGB; bmi.biSizeImage = bytesPerRow*height; LPBYTE bits = (LPBYTE)GlobalAlloc(0, bmi.biSizeImage); if (bits) { for (int y = 0; y < height; y++) { RGBTRIPLE* dest = (RGBTRIPLE*)(bits + (height-y-1)*bytesPerRow); for (int x = 0; x < width; x++) { int h = (x * 255)/width; int l = ((height-y-1) * 255)/height; int s = ((height-y-1) * 255)/height; //int s = 127;//(x * width)/255; COLORREF clr = HLStoRGB(HLS(h, l, s)); dest->rgbtRed = GetRValue(clr); dest->rgbtGreen = GetGValue(clr); dest->rgbtBlue = GetBValue(clr); dest++; } } SetDIBitsToDevice(hDC, rc.left, rc.top, width, height, 0, 0, 0, height, bits, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS); GlobalFree(bits); } } return S_OK; }
uintptr_t mcall_hart_id(void) { return HLS()->hart_id; }