Changeset 171f9a1 in mainline
- Timestamp:
- 2009-04-03T20:39:33Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cb01e1e
- Parents:
- 7a2c479
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
r7a2c479 r171f9a1 54 54 55 55 #define KLOG_SIZE PAGE_SIZE 56 #define KLOG_LENGTH (KLOG_SIZE / sizeof(wchar_t)) 56 57 #define KLOG_LATENCY 8 57 58 58 59 /** Kernel log cyclic buffer */ 59 static wchar_t klog[KLOG_ SIZE] __attribute__ ((aligned (PAGE_SIZE)));60 static wchar_t klog[KLOG_LENGTH] __attribute__ ((aligned (PAGE_SIZE))); 60 61 61 62 /** Kernel log initialized */ … … 258 259 index_t i; 259 260 for (i = klog_len - klog_stored; i < klog_len; i++) 260 stdout->op->write(stdout, klog[(klog_start + i) % KLOG_ SIZE], silent);261 stdout->op->write(stdout, klog[(klog_start + i) % KLOG_LENGTH], silent); 261 262 klog_stored = 0; 262 263 } 263 264 264 265 /* Store character in the cyclic kernel log */ 265 klog[(klog_start + klog_len) % KLOG_ SIZE] = ch;266 if (klog_len < KLOG_ SIZE)266 klog[(klog_start + klog_len) % KLOG_LENGTH] = ch; 267 if (klog_len < KLOG_LENGTH) 267 268 klog_len++; 268 269 else 269 klog_start = (klog_start + 1) % KLOG_ SIZE;270 klog_start = (klog_start + 1) % KLOG_LENGTH; 270 271 271 272 if ((stdout) && (stdout->op->write)) -
uspace/app/klog/klog.c
r7a2c479 r171f9a1 48 48 #define NAME "klog" 49 49 50 #define KLOG_SIZE PAGE_SIZE 50 #define KLOG_SIZE PAGE_SIZE 51 #define KLOG_LENGTH (KLOG_SIZE / sizeof(wchar_t)) 51 52 52 53 /* Pointer to klog area */ 53 static char*klog;54 static wchar_t *klog; 54 55 55 56 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) … … 62 63 size_t i; 63 64 for (i = klog_len - klog_stored; i < klog_len; i++) 64 putchar(klog[(klog_start + i) % KLOG_ SIZE]);65 putchar(klog[(klog_start + i) % KLOG_LENGTH]); 65 66 66 67 async_serialize_end(); -
uspace/lib/libc/generic/console.c
r7a2c479 r171f9a1 62 62 static void cbuffer_flush(void); 63 63 static void cbuffer_drain(void); 64 static void cbuffer_putc(int c);64 static inline void cbuffer_putc(int c); 65 65 66 66 -
uspace/lib/libc/generic/string.c
r7a2c479 r171f9a1 39 39 #include <ctype.h> 40 40 #include <malloc.h> 41 #include <errno.h> 42 #include <string.h> 43 44 /** Byte mask consisting of lowest @n bits (out of 8) */ 45 #define LO_MASK_8(n) ((uint8_t) ((1 << (n)) - 1)) 46 47 /** Byte mask consisting of lowest @n bits (out of 32) */ 48 #define LO_MASK_32(n) ((uint32_t) ((1 << (n)) - 1)) 49 50 /** Byte mask consisting of highest @n bits (out of 8) */ 51 #define HI_MASK_8(n) (~LO_MASK_8(8 - (n))) 52 53 /** Number of data bits in a UTF-8 continuation byte */ 54 #define CONT_BITS 6 55 56 /** Decode a single character from a string. 57 * 58 * Decode a single character from a string of size @a size. Decoding starts 59 * at @a offset and this offset is moved to the beginning of the next 60 * character. In case of decoding error, offset generally advances at least 61 * by one. However, offset is never moved beyond size. 62 * 63 * @param str String (not necessarily NULL-terminated). 64 * @param offset Byte offset in string where to start decoding. 65 * @param size Size of the string (in bytes). 66 * 67 * @return Value of decoded character, U_SPECIAL on decoding error or 68 * NULL if attempt to decode beyond @a size. 69 * 70 */ 71 wchar_t str_decode(const char *str, size_t *offset, size_t size) 72 { 73 if (*offset + 1 > size) 74 return 0; 75 76 /* First byte read from string */ 77 uint8_t b0 = (uint8_t) str[(*offset)++]; 78 79 /* Determine code length */ 80 81 unsigned int b0_bits; /* Data bits in first byte */ 82 unsigned int cbytes; /* Number of continuation bytes */ 83 84 if ((b0 & 0x80) == 0) { 85 /* 0xxxxxxx (Plain ASCII) */ 86 b0_bits = 7; 87 cbytes = 0; 88 } else if ((b0 & 0xe0) == 0xc0) { 89 /* 110xxxxx 10xxxxxx */ 90 b0_bits = 5; 91 cbytes = 1; 92 } else if ((b0 & 0xf0) == 0xe0) { 93 /* 1110xxxx 10xxxxxx 10xxxxxx */ 94 b0_bits = 4; 95 cbytes = 2; 96 } else if ((b0 & 0xf8) == 0xf0) { 97 /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 98 b0_bits = 3; 99 cbytes = 3; 100 } else { 101 /* 10xxxxxx -- unexpected continuation byte */ 102 return U_SPECIAL; 103 } 104 105 if (*offset + cbytes > size) 106 return U_SPECIAL; 107 108 wchar_t ch = b0 & LO_MASK_8(b0_bits); 109 110 /* Decode continuation bytes */ 111 while (cbytes > 0) { 112 uint8_t b = (uint8_t) str[(*offset)++]; 113 114 /* Must be 10xxxxxx */ 115 if ((b & 0xc0) != 0x80) 116 return U_SPECIAL; 117 118 /* Shift data bits to ch */ 119 ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS)); 120 cbytes--; 121 } 122 123 return ch; 124 } 125 126 /** Encode a single character to string representation. 127 * 128 * Encode a single character to string representation (i.e. UTF-8) and store 129 * it into a buffer at @a offset. Encoding starts at @a offset and this offset 130 * is moved to the position where the next character can be written to. 131 * 132 * @param ch Input character. 133 * @param str Output buffer. 134 * @param offset Byte offset where to start writing. 135 * @param size Size of the output buffer (in bytes). 136 * 137 * @return EOK if the character was encoded successfully, EOVERFLOW if there 138 * was not enough space in the output buffer or EINVAL if the character 139 * code was invalid. 140 */ 141 int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size) 142 { 143 if (*offset >= size) 144 return EOVERFLOW; 145 146 if (!chr_check(ch)) 147 return EINVAL; 148 149 /* Unsigned version of ch (bit operations should only be done 150 on unsigned types). */ 151 uint32_t cc = (uint32_t) ch; 152 153 /* Determine how many continuation bytes are needed */ 154 155 unsigned int b0_bits; /* Data bits in first byte */ 156 unsigned int cbytes; /* Number of continuation bytes */ 157 158 if ((cc & ~LO_MASK_32(7)) == 0) { 159 b0_bits = 7; 160 cbytes = 0; 161 } else if ((cc & ~LO_MASK_32(11)) == 0) { 162 b0_bits = 5; 163 cbytes = 1; 164 } else if ((cc & ~LO_MASK_32(16)) == 0) { 165 b0_bits = 4; 166 cbytes = 2; 167 } else if ((cc & ~LO_MASK_32(21)) == 0) { 168 b0_bits = 3; 169 cbytes = 3; 170 } else { 171 /* Codes longer than 21 bits are not supported */ 172 return EINVAL; 173 } 174 175 /* Check for available space in buffer */ 176 if (*offset + cbytes >= size) 177 return EOVERFLOW; 178 179 /* Encode continuation bytes */ 180 unsigned int i; 181 for (i = cbytes; i > 0; i--) { 182 str[*offset + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS)); 183 cc = cc >> CONT_BITS; 184 } 185 186 /* Encode first byte */ 187 str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1); 188 189 /* Advance offset */ 190 *offset += cbytes + 1; 191 192 return EOK; 193 } 194 195 /** Check whether character is valid 196 * 197 * @return True if character is a valid Unicode code point. 198 * 199 */ 200 bool chr_check(const wchar_t ch) 201 { 202 if ((ch >= 0) && (ch <= 1114111)) 203 return true; 204 205 return false; 206 } 41 207 42 208 /** Count the number of characters in the string, not including terminating 0. -
uspace/lib/libc/include/string.h
r7a2c479 r171f9a1 38 38 #include <mem.h> 39 39 #include <sys/types.h> 40 #include <bool.h> 41 42 #define U_SPECIAL '?' 43 44 extern wchar_t str_decode(const char *str, size_t *offset, size_t sz); 45 extern int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz); 46 47 extern bool chr_check(const wchar_t ch); 40 48 41 49 extern int strcmp(const char *, const char *); -
uspace/srv/console/console.c
r7a2c479 r171f9a1 49 49 #include <sys/mman.h> 50 50 #include <stdio.h> 51 #include <string.h> 51 52 #include <sysinfo.h> 52 53 #include <event.h> … … 466 467 { 467 468 ipc_callid_t callid; 468 size_t len; 469 size_t i; 470 471 if (!ipc_data_write_receive(&callid, &len)) { 469 size_t size; 470 wchar_t ch; 471 size_t off; 472 473 if (!ipc_data_write_receive(&callid, &size)) { 472 474 ipc_answer_0(callid, EINVAL); 473 475 ipc_answer_0(rid, EINVAL); 474 476 } 475 477 476 if (len > CWRITE_BUF_SIZE) 477 len = CWRITE_BUF_SIZE; 478 479 (void) ipc_data_write_finalize(callid, cwrite_buf, len); 480 481 for (i = 0; i < len; i++) { 482 write_char(consnum, cwrite_buf[i]); 478 if (size > CWRITE_BUF_SIZE) 479 size = CWRITE_BUF_SIZE; 480 481 (void) ipc_data_write_finalize(callid, cwrite_buf, size); 482 483 off = 0; 484 while (off < size) { 485 ch = str_decode(cwrite_buf, &off, size); 486 write_char(consnum, ch); 483 487 } 484 488 485 489 gcons_notify_char(consnum); 486 ipc_answer_1(rid, EOK, len);490 ipc_answer_1(rid, EOK, size); 487 491 } 488 492 -
uspace/srv/fb/fb.c
r7a2c479 r171f9a1 69 69 #define DEFAULT_FGCOLOR 0x000000 70 70 71 #define GLYPH_UNAVAIL '?' 72 71 73 #define MAX_ANIM_LEN 8 72 74 #define MAX_ANIMATIONS 4 … … 79 81 /** Function to draw a glyph. */ 80 82 typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor, 81 uint8_t *glyphs, uint 8_t glyph, uint32_t fg_color, uint32_t bg_color);83 uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); 82 84 83 85 struct { … … 670 672 /* Check glyph range. */ 671 673 if (glyph >= FONT_GLYPHS) 672 return;674 glyph = GLYPH_UNAVAIL; 673 675 674 676 /* … … 734 736 /* Check glyph range. */ 735 737 if (glyph >= FONT_GLYPHS) 736 return;738 glyph = GLYPH_UNAVAIL; 737 739 738 740 /* Pre-render 1x the foreground and background color pixels. */
Note:
See TracChangeset
for help on using the changeset viewer.