27 */ 28 29#include "opt_syscons.h" 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/malloc.h> 34#include <sys/consio.h> 35#include <sys/fbio.h> 36 37#include <machine/md_var.h> 38 39#include <dev/fb/fbreg.h> 40#include <dev/syscons/syscons.h> 41 42#define ATTR_OFFSET_FB 0x2000 43#define attr_offset(vtb) ((vtb)->vtb_size*sizeof(u_int16_t)) 44 45#define vtb_pointer(vtb, at) \ 46 ((vtb)->vtb_buffer + sizeof(u_int16_t)*(at)) 47 48#define vtb_wrap(vtb, at, offset) \ 49 (((at) + (offset) + (vtb)->vtb_size)%(vtb)->vtb_size) 50 51static u_int8_t ibmpc_to_pc98[256] = { 52 0x01, 0x21, 0x81, 0xa1, 0x41, 0x61, 0xc1, 0xe1, 53 0x09, 0x29, 0x89, 0xa9, 0x49, 0x69, 0xc9, 0xe9, 54 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 55 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 56 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 57 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 58 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 59 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 60 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 61 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 62 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 63 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 64 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 65 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 66 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 67 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 68 69 0x03, 0x23, 0x83, 0xa3, 0x43, 0x63, 0xc3, 0xe3, 70 0x0b, 0x2b, 0x8b, 0xab, 0x4b, 0x6b, 0xcb, 0xeb, 71 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 72 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 73 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 74 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 75 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 76 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 77 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 78 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 79 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 80 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 81 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 82 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 83 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 84 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 85}; 86#define at2pc98(attr) ((attr) | ibmpc_to_pc98[(unsigned)(attr) >> 8]) 87 88void 89sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows, void *buf, int wait) 90{ 91 vtb->vtb_flags = 0; 92 vtb->vtb_type = type; 93 vtb->vtb_cols = cols; 94 vtb->vtb_rows = rows; 95 vtb->vtb_size = cols*rows; 96 vtb->vtb_buffer = 0; 97 vtb->vtb_tail = 0; 98 99 switch (type) { 100 case VTB_MEMORY: 101 case VTB_RINGBUFFER: 102 if ((buf == NULL) && (cols*rows != 0)) { 103 vtb->vtb_buffer = 104 (vm_offset_t)malloc(cols*rows*sizeof(u_int16_t)*2, 105 M_DEVBUF,
| 27 */ 28 29#include "opt_syscons.h" 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/malloc.h> 34#include <sys/consio.h> 35#include <sys/fbio.h> 36 37#include <machine/md_var.h> 38 39#include <dev/fb/fbreg.h> 40#include <dev/syscons/syscons.h> 41 42#define ATTR_OFFSET_FB 0x2000 43#define attr_offset(vtb) ((vtb)->vtb_size*sizeof(u_int16_t)) 44 45#define vtb_pointer(vtb, at) \ 46 ((vtb)->vtb_buffer + sizeof(u_int16_t)*(at)) 47 48#define vtb_wrap(vtb, at, offset) \ 49 (((at) + (offset) + (vtb)->vtb_size)%(vtb)->vtb_size) 50 51static u_int8_t ibmpc_to_pc98[256] = { 52 0x01, 0x21, 0x81, 0xa1, 0x41, 0x61, 0xc1, 0xe1, 53 0x09, 0x29, 0x89, 0xa9, 0x49, 0x69, 0xc9, 0xe9, 54 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 55 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 56 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 57 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 58 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 59 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 60 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 61 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 62 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 63 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 64 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 65 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 66 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 67 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 68 69 0x03, 0x23, 0x83, 0xa3, 0x43, 0x63, 0xc3, 0xe3, 70 0x0b, 0x2b, 0x8b, 0xab, 0x4b, 0x6b, 0xcb, 0xeb, 71 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 72 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 73 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 74 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 75 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 76 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 77 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 78 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 79 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 80 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 81 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 82 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 83 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 84 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 85}; 86#define at2pc98(attr) ((attr) | ibmpc_to_pc98[(unsigned)(attr) >> 8]) 87 88void 89sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows, void *buf, int wait) 90{ 91 vtb->vtb_flags = 0; 92 vtb->vtb_type = type; 93 vtb->vtb_cols = cols; 94 vtb->vtb_rows = rows; 95 vtb->vtb_size = cols*rows; 96 vtb->vtb_buffer = 0; 97 vtb->vtb_tail = 0; 98 99 switch (type) { 100 case VTB_MEMORY: 101 case VTB_RINGBUFFER: 102 if ((buf == NULL) && (cols*rows != 0)) { 103 vtb->vtb_buffer = 104 (vm_offset_t)malloc(cols*rows*sizeof(u_int16_t)*2, 105 M_DEVBUF,
|
107 if (vtb->vtb_buffer != 0) { 108 vtb->vtb_flags |= VTB_ALLOCED; 109 } 110 } else { 111 vtb->vtb_buffer = (vm_offset_t)buf; 112 } 113 vtb->vtb_flags |= VTB_VALID; 114 break; 115 case VTB_FRAMEBUFFER: 116 vtb->vtb_buffer = (vm_offset_t)buf; 117 vtb->vtb_flags |= VTB_VALID; 118 break; 119 default: 120 break; 121 } 122} 123 124void 125sc_vtb_destroy(sc_vtb_t *vtb) 126{ 127 vm_offset_t p; 128 129 vtb->vtb_cols = 0; 130 vtb->vtb_rows = 0; 131 vtb->vtb_size = 0; 132 vtb->vtb_tail = 0; 133 134 p = vtb->vtb_buffer; 135 vtb->vtb_buffer = 0; 136 switch (vtb->vtb_type) { 137 case VTB_MEMORY: 138 case VTB_RINGBUFFER: 139 if ((vtb->vtb_flags & VTB_ALLOCED) && (p != 0)) 140 free((void *)p, M_DEVBUF); 141 break; 142 default: 143 break; 144 } 145 vtb->vtb_flags = 0; 146 vtb->vtb_type = VTB_INVALID; 147} 148 149size_t 150sc_vtb_size(int cols, int rows) 151{ 152 return (size_t)(cols*rows*sizeof(u_int16_t)*2); 153} 154 155int 156sc_vtb_getc(sc_vtb_t *vtb, int at) 157{ 158 vm_offset_t p = vtb_pointer(vtb, at); 159 160 if (vtb->vtb_type == VTB_FRAMEBUFFER) 161 return (readw(p) & 0x00ff); 162 else 163 return (*(u_int16_t *)p & 0x00ff); 164} 165 166int 167sc_vtb_geta(sc_vtb_t *vtb, int at) 168{ 169 vm_offset_t p = vtb_pointer(vtb, at); 170 171 if (vtb->vtb_type == VTB_FRAMEBUFFER) 172 return (readw(p + ATTR_OFFSET_FB) & 0xff00); 173 else 174 return (*(u_int16_t *)(p + attr_offset(vtb)) & 0xff00); 175} 176 177__inline static void 178vtb_putc(sc_vtb_t *vtb, vm_offset_t p, int c, int a) 179{ 180 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 181 writew(p, c); 182 writew(p + ATTR_OFFSET_FB, at2pc98(a)); 183 } else { 184 *(u_int16_t *)p = c; 185 *(u_int16_t *)(p + attr_offset(vtb)) = at2pc98(a); 186 } 187} 188 189void 190sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a) 191{ 192 vtb_putc(vtb, vtb_pointer(vtb, at), c, a); 193} 194 195vm_offset_t 196sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a) 197{ 198 vtb_putc(vtb, p, c, a); 199 return (p + sizeof(u_int16_t)); 200} 201 202vm_offset_t 203sc_vtb_pointer(sc_vtb_t *vtb, int at) 204{ 205 return (vtb_pointer(vtb, at)); 206} 207 208int 209sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset) 210{ 211 return ((pos + offset + vtb->vtb_size)%vtb->vtb_size); 212} 213 214void 215sc_vtb_clear(sc_vtb_t *vtb, int c, int attr) 216{ 217 vm_offset_t p = vtb_pointer(vtb, 0); 218 219 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 220 fillw_io(c, p, vtb->vtb_size); 221 fillw_io(at2pc98(attr), p + ATTR_OFFSET_FB, vtb->vtb_size); 222 } else { 223 fillw(c, (void *)p, vtb->vtb_size); 224 fillw(at2pc98(attr), (void *)(p + attr_offset(vtb)), 225 vtb->vtb_size); 226 } 227} 228 229void 230sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to, int count) 231{ 232 vm_offset_t p1, p2; 233 234 p1 = vtb_pointer(vtb1, from); 235 p2 = vtb_pointer(vtb2, to); 236 if (vtb2->vtb_type == VTB_FRAMEBUFFER) { 237 bcopy_toio(p1, p2, count*sizeof(u_int16_t)); 238 bcopy_toio(p1 + attr_offset(vtb1), 239 p2 + ATTR_OFFSET_FB, 240 count*sizeof(u_int16_t)); 241 } else if (vtb1->vtb_type == VTB_FRAMEBUFFER) { 242 bcopy_fromio(p1, p2, count*sizeof(u_int16_t)); 243 bcopy_fromio(p1 + ATTR_OFFSET_FB, 244 p2 + attr_offset(vtb2), 245 count*sizeof(u_int16_t)); 246 } else { 247 bcopy((void *)p1, (void *)p2, count*sizeof(u_int16_t)); 248 bcopy((void *)(p1 + attr_offset(vtb1)), 249 (void *)(p2 + attr_offset(vtb2)), 250 count*sizeof(u_int16_t)); 251 } 252} 253 254void 255sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int count) 256{ 257 int len; 258 vm_offset_t p1, p2; 259 260 if (vtb2->vtb_type != VTB_RINGBUFFER) 261 return; 262 263 while (count > 0) { 264 p1 = vtb_pointer(vtb1, from); 265 p2 = vtb_pointer(vtb2, vtb2->vtb_tail); 266 len = imin(count, vtb2->vtb_size - vtb2->vtb_tail); 267 if (vtb1->vtb_type == VTB_FRAMEBUFFER) { 268 bcopy_fromio(p1, p2, len*sizeof(u_int16_t)); 269 bcopy_fromio(p1 + ATTR_OFFSET_FB, 270 p2 + attr_offset(vtb2), 271 len*sizeof(u_int16_t)); 272 } else { 273 bcopy((void *)p1, (void *)p2, len*sizeof(u_int16_t)); 274 bcopy((void *)(p1 + attr_offset(vtb1)), 275 (void *)(p2 + attr_offset(vtb2)), 276 len*sizeof(u_int16_t)); 277 } 278 from += len; 279 count -= len; 280 vtb2->vtb_tail = vtb_wrap(vtb2, vtb2->vtb_tail, len); 281 } 282} 283 284void 285sc_vtb_seek(sc_vtb_t *vtb, int pos) 286{ 287 vtb->vtb_tail = pos%vtb->vtb_size; 288} 289 290void 291sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr) 292{ 293 vm_offset_t p; 294 295 if (at + count > vtb->vtb_size) 296 count = vtb->vtb_size - at; 297 p = vtb_pointer(vtb, at); 298 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 299 fillw_io(c, p, count); 300 fillw_io(at2pc98(attr), p + ATTR_OFFSET_FB, count); 301 } else { 302 fillw(c, (void *)p, count); 303 fillw(at2pc98(attr), (void *)(p + attr_offset(vtb)), count); 304 } 305} 306 307void 308sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count) 309{ 310 vm_offset_t p1, p2; 311 312 if (from + count > vtb->vtb_size) 313 count = vtb->vtb_size - from; 314 if (to + count > vtb->vtb_size) 315 count = vtb->vtb_size - to; 316 if (count <= 0) 317 return; 318 319 p1 = vtb_pointer(vtb, from); 320 p2 = vtb_pointer(vtb, to); 321 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 322 bcopy_io(p1, p2, count*sizeof(u_int16_t)); 323 bcopy_io(p1 + ATTR_OFFSET_FB, 324 p2 + ATTR_OFFSET_FB, count*sizeof(u_int16_t)); 325 } else { 326 bcopy((void *)p1, (void *)p2, count*sizeof(u_int16_t)); 327 bcopy((void *)(p1 + attr_offset(vtb)), 328 (void *)(p2 + attr_offset(vtb)), count*sizeof(u_int16_t)); 329 } 330} 331 332void 333sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr) 334{ 335 int len; 336 vm_offset_t p1, p2; 337 338 if (at + count > vtb->vtb_size) 339 count = vtb->vtb_size - at; 340 len = vtb->vtb_size - at - count; 341 if (len > 0) { 342 p1 = vtb_pointer(vtb, at + count); 343 p2 = vtb_pointer(vtb, at); 344 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 345 bcopy_io(p1, p2, len*sizeof(u_int16_t)); 346 bcopy_io(p1 + ATTR_OFFSET_FB, 347 p2 + ATTR_OFFSET_FB, 348 len*sizeof(u_int16_t)); 349 } else { 350 bcopy((void *)p1, (void *)p2, len*sizeof(u_int16_t)); 351 bcopy((void *)(p1 + attr_offset(vtb)), 352 (void *)(p2 + attr_offset(vtb)), 353 len*sizeof(u_int16_t)); 354 } 355 } 356 p1 = vtb_pointer(vtb, at + len); 357 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 358 fillw_io(c, p1, vtb->vtb_size - at - len); 359 fillw_io(at2pc98(attr), p1 + ATTR_OFFSET_FB, 360 vtb->vtb_size - at - len); 361 } else { 362 fillw(c, (void *)p1, vtb->vtb_size - at - len); 363 fillw(at2pc98(attr), (void *)(p1 + attr_offset(vtb)), 364 vtb->vtb_size - at - len); 365 } 366} 367 368void 369sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr) 370{ 371 vm_offset_t p1, p2; 372 373 p1 = vtb_pointer(vtb, at); 374 if (at + count > vtb->vtb_size) { 375 count = vtb->vtb_size - at; 376 } else { 377 p2 = vtb_pointer(vtb, at + count); 378 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 379 bcopy_io(p1, p2, 380 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 381 bcopy_io(p1 + ATTR_OFFSET_FB, 382 p2 + ATTR_OFFSET_FB, 383 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 384 } else { 385 bcopy((void *)p1, (void *)p2, 386 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 387 bcopy((void *)(p1 + attr_offset(vtb)), 388 (void *)(p2 + attr_offset(vtb)), 389 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 390 } 391 } 392 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 393 fillw_io(c, p1, count); 394 fillw_io(at2pc98(attr), p1 + ATTR_OFFSET_FB, count); 395 } else { 396 fillw(c, (void *)p1, count); 397 fillw(at2pc98(attr), (void *)(p1 + attr_offset(vtb)), count); 398 } 399}
| 107 if (vtb->vtb_buffer != 0) { 108 vtb->vtb_flags |= VTB_ALLOCED; 109 } 110 } else { 111 vtb->vtb_buffer = (vm_offset_t)buf; 112 } 113 vtb->vtb_flags |= VTB_VALID; 114 break; 115 case VTB_FRAMEBUFFER: 116 vtb->vtb_buffer = (vm_offset_t)buf; 117 vtb->vtb_flags |= VTB_VALID; 118 break; 119 default: 120 break; 121 } 122} 123 124void 125sc_vtb_destroy(sc_vtb_t *vtb) 126{ 127 vm_offset_t p; 128 129 vtb->vtb_cols = 0; 130 vtb->vtb_rows = 0; 131 vtb->vtb_size = 0; 132 vtb->vtb_tail = 0; 133 134 p = vtb->vtb_buffer; 135 vtb->vtb_buffer = 0; 136 switch (vtb->vtb_type) { 137 case VTB_MEMORY: 138 case VTB_RINGBUFFER: 139 if ((vtb->vtb_flags & VTB_ALLOCED) && (p != 0)) 140 free((void *)p, M_DEVBUF); 141 break; 142 default: 143 break; 144 } 145 vtb->vtb_flags = 0; 146 vtb->vtb_type = VTB_INVALID; 147} 148 149size_t 150sc_vtb_size(int cols, int rows) 151{ 152 return (size_t)(cols*rows*sizeof(u_int16_t)*2); 153} 154 155int 156sc_vtb_getc(sc_vtb_t *vtb, int at) 157{ 158 vm_offset_t p = vtb_pointer(vtb, at); 159 160 if (vtb->vtb_type == VTB_FRAMEBUFFER) 161 return (readw(p) & 0x00ff); 162 else 163 return (*(u_int16_t *)p & 0x00ff); 164} 165 166int 167sc_vtb_geta(sc_vtb_t *vtb, int at) 168{ 169 vm_offset_t p = vtb_pointer(vtb, at); 170 171 if (vtb->vtb_type == VTB_FRAMEBUFFER) 172 return (readw(p + ATTR_OFFSET_FB) & 0xff00); 173 else 174 return (*(u_int16_t *)(p + attr_offset(vtb)) & 0xff00); 175} 176 177__inline static void 178vtb_putc(sc_vtb_t *vtb, vm_offset_t p, int c, int a) 179{ 180 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 181 writew(p, c); 182 writew(p + ATTR_OFFSET_FB, at2pc98(a)); 183 } else { 184 *(u_int16_t *)p = c; 185 *(u_int16_t *)(p + attr_offset(vtb)) = at2pc98(a); 186 } 187} 188 189void 190sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a) 191{ 192 vtb_putc(vtb, vtb_pointer(vtb, at), c, a); 193} 194 195vm_offset_t 196sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a) 197{ 198 vtb_putc(vtb, p, c, a); 199 return (p + sizeof(u_int16_t)); 200} 201 202vm_offset_t 203sc_vtb_pointer(sc_vtb_t *vtb, int at) 204{ 205 return (vtb_pointer(vtb, at)); 206} 207 208int 209sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset) 210{ 211 return ((pos + offset + vtb->vtb_size)%vtb->vtb_size); 212} 213 214void 215sc_vtb_clear(sc_vtb_t *vtb, int c, int attr) 216{ 217 vm_offset_t p = vtb_pointer(vtb, 0); 218 219 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 220 fillw_io(c, p, vtb->vtb_size); 221 fillw_io(at2pc98(attr), p + ATTR_OFFSET_FB, vtb->vtb_size); 222 } else { 223 fillw(c, (void *)p, vtb->vtb_size); 224 fillw(at2pc98(attr), (void *)(p + attr_offset(vtb)), 225 vtb->vtb_size); 226 } 227} 228 229void 230sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to, int count) 231{ 232 vm_offset_t p1, p2; 233 234 p1 = vtb_pointer(vtb1, from); 235 p2 = vtb_pointer(vtb2, to); 236 if (vtb2->vtb_type == VTB_FRAMEBUFFER) { 237 bcopy_toio(p1, p2, count*sizeof(u_int16_t)); 238 bcopy_toio(p1 + attr_offset(vtb1), 239 p2 + ATTR_OFFSET_FB, 240 count*sizeof(u_int16_t)); 241 } else if (vtb1->vtb_type == VTB_FRAMEBUFFER) { 242 bcopy_fromio(p1, p2, count*sizeof(u_int16_t)); 243 bcopy_fromio(p1 + ATTR_OFFSET_FB, 244 p2 + attr_offset(vtb2), 245 count*sizeof(u_int16_t)); 246 } else { 247 bcopy((void *)p1, (void *)p2, count*sizeof(u_int16_t)); 248 bcopy((void *)(p1 + attr_offset(vtb1)), 249 (void *)(p2 + attr_offset(vtb2)), 250 count*sizeof(u_int16_t)); 251 } 252} 253 254void 255sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int count) 256{ 257 int len; 258 vm_offset_t p1, p2; 259 260 if (vtb2->vtb_type != VTB_RINGBUFFER) 261 return; 262 263 while (count > 0) { 264 p1 = vtb_pointer(vtb1, from); 265 p2 = vtb_pointer(vtb2, vtb2->vtb_tail); 266 len = imin(count, vtb2->vtb_size - vtb2->vtb_tail); 267 if (vtb1->vtb_type == VTB_FRAMEBUFFER) { 268 bcopy_fromio(p1, p2, len*sizeof(u_int16_t)); 269 bcopy_fromio(p1 + ATTR_OFFSET_FB, 270 p2 + attr_offset(vtb2), 271 len*sizeof(u_int16_t)); 272 } else { 273 bcopy((void *)p1, (void *)p2, len*sizeof(u_int16_t)); 274 bcopy((void *)(p1 + attr_offset(vtb1)), 275 (void *)(p2 + attr_offset(vtb2)), 276 len*sizeof(u_int16_t)); 277 } 278 from += len; 279 count -= len; 280 vtb2->vtb_tail = vtb_wrap(vtb2, vtb2->vtb_tail, len); 281 } 282} 283 284void 285sc_vtb_seek(sc_vtb_t *vtb, int pos) 286{ 287 vtb->vtb_tail = pos%vtb->vtb_size; 288} 289 290void 291sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr) 292{ 293 vm_offset_t p; 294 295 if (at + count > vtb->vtb_size) 296 count = vtb->vtb_size - at; 297 p = vtb_pointer(vtb, at); 298 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 299 fillw_io(c, p, count); 300 fillw_io(at2pc98(attr), p + ATTR_OFFSET_FB, count); 301 } else { 302 fillw(c, (void *)p, count); 303 fillw(at2pc98(attr), (void *)(p + attr_offset(vtb)), count); 304 } 305} 306 307void 308sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count) 309{ 310 vm_offset_t p1, p2; 311 312 if (from + count > vtb->vtb_size) 313 count = vtb->vtb_size - from; 314 if (to + count > vtb->vtb_size) 315 count = vtb->vtb_size - to; 316 if (count <= 0) 317 return; 318 319 p1 = vtb_pointer(vtb, from); 320 p2 = vtb_pointer(vtb, to); 321 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 322 bcopy_io(p1, p2, count*sizeof(u_int16_t)); 323 bcopy_io(p1 + ATTR_OFFSET_FB, 324 p2 + ATTR_OFFSET_FB, count*sizeof(u_int16_t)); 325 } else { 326 bcopy((void *)p1, (void *)p2, count*sizeof(u_int16_t)); 327 bcopy((void *)(p1 + attr_offset(vtb)), 328 (void *)(p2 + attr_offset(vtb)), count*sizeof(u_int16_t)); 329 } 330} 331 332void 333sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr) 334{ 335 int len; 336 vm_offset_t p1, p2; 337 338 if (at + count > vtb->vtb_size) 339 count = vtb->vtb_size - at; 340 len = vtb->vtb_size - at - count; 341 if (len > 0) { 342 p1 = vtb_pointer(vtb, at + count); 343 p2 = vtb_pointer(vtb, at); 344 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 345 bcopy_io(p1, p2, len*sizeof(u_int16_t)); 346 bcopy_io(p1 + ATTR_OFFSET_FB, 347 p2 + ATTR_OFFSET_FB, 348 len*sizeof(u_int16_t)); 349 } else { 350 bcopy((void *)p1, (void *)p2, len*sizeof(u_int16_t)); 351 bcopy((void *)(p1 + attr_offset(vtb)), 352 (void *)(p2 + attr_offset(vtb)), 353 len*sizeof(u_int16_t)); 354 } 355 } 356 p1 = vtb_pointer(vtb, at + len); 357 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 358 fillw_io(c, p1, vtb->vtb_size - at - len); 359 fillw_io(at2pc98(attr), p1 + ATTR_OFFSET_FB, 360 vtb->vtb_size - at - len); 361 } else { 362 fillw(c, (void *)p1, vtb->vtb_size - at - len); 363 fillw(at2pc98(attr), (void *)(p1 + attr_offset(vtb)), 364 vtb->vtb_size - at - len); 365 } 366} 367 368void 369sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr) 370{ 371 vm_offset_t p1, p2; 372 373 p1 = vtb_pointer(vtb, at); 374 if (at + count > vtb->vtb_size) { 375 count = vtb->vtb_size - at; 376 } else { 377 p2 = vtb_pointer(vtb, at + count); 378 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 379 bcopy_io(p1, p2, 380 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 381 bcopy_io(p1 + ATTR_OFFSET_FB, 382 p2 + ATTR_OFFSET_FB, 383 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 384 } else { 385 bcopy((void *)p1, (void *)p2, 386 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 387 bcopy((void *)(p1 + attr_offset(vtb)), 388 (void *)(p2 + attr_offset(vtb)), 389 (vtb->vtb_size - at - count)*sizeof(u_int16_t)); 390 } 391 } 392 if (vtb->vtb_type == VTB_FRAMEBUFFER) { 393 fillw_io(c, p1, count); 394 fillw_io(at2pc98(attr), p1 + ATTR_OFFSET_FB, count); 395 } else { 396 fillw(c, (void *)p1, count); 397 fillw(at2pc98(attr), (void *)(p1 + attr_offset(vtb)), count); 398 } 399}
|