Changeset 79460ae in mainline
- Timestamp:
- 2006-05-30T10:40:17Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44c6d88d
- Parents:
- f25b73d6
- Files:
-
- 1 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
console/Makefile
rf25b73d6 r79460ae 34 34 include $(LIBC_PREFIX)/Makefile.toolchain 35 35 36 CFLAGS += -I include -I../kbd/include../fb36 CFLAGS += -I. -I../kbd/include -I../fb 37 37 38 38 LIBS = $(LIBC_PREFIX)/libc.a … … 43 43 OUTPUT = console 44 44 GENERIC_SOURCES = \ 45 console.c 45 console.c \ 46 ../kbd/generic/key_buffer.c 46 47 47 48 ARCH_SOURCES = … … 63 64 64 65 $(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) 65 $(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map66 $(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map 66 67 67 68 disasm: -
console/console.c
rf25b73d6 r79460ae 29 29 30 30 #include <kbd.h> 31 #include <fb.h> 31 32 #include <ipc/ipc.h> 33 #include <ipc/fb.h> 32 34 #include <ipc/services.h> 33 #include <stdio.h>34 35 #include <errno.h> 36 #include <key_buffer.h> 37 #include <console.h> 38 39 //#define CONSOLE_COUNT VFB_CONNECTIONS 40 #define CONSOLE_COUNT 6 35 41 36 42 #define NAME "CONSOLE" 43 44 typedef struct { 45 keybuffer_t keybuffer; 46 int client_phone; 47 int vfb_number; /* Not used */ 48 int vfb_phone; 49 int used; 50 } connection_t; 51 52 connection_t connections[CONSOLE_COUNT]; 53 54 static int find_free_connection() 55 { 56 int i = 0; 57 58 while (i < CONSOLE_COUNT) { 59 if (connections[i].used == 0) 60 return i; 61 ++i; 62 } 63 return CONSOLE_COUNT; 64 } 65 66 67 static int find_connection(int client_phone) 68 { 69 int i = 0; 70 71 while (i < CONSOLE_COUNT) { 72 if (connections[i].client_phone == client_phone) 73 return i; 74 ++i; 75 } 76 return CONSOLE_COUNT; 77 } 37 78 38 79 int main(int argc, char *argv[]) … … 41 82 ipc_call_t call; 42 83 ipc_callid_t callid; 43 int phone_kbd, phone_fb;84 int kbd_phone, fb_phone; 44 85 ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; 45 46 printf("Uspace console service started.\n"); 47 86 int i; 87 int active_client = 0; 48 88 49 89 /* Connect to keyboard driver */ 50 90 51 while (( phone_kbd= ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {91 while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { 52 92 }; 53 93 54 if (ipc_connect_to_me(phone_kbd, SERVICE_CONSOLE, 0, &phonead) != 0) { 55 printf("%s: Error: Registering at naming service failed.\n", NAME); 94 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonead) != 0) { 56 95 return -1; 57 96 }; … … 59 98 /* Connect to framebuffer driver */ 60 99 61 while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { 62 }; 100 for (i = 0; i < CONSOLE_COUNT; i++) { 101 connections[i].used = 0; 102 keybuffer_init(&(connections[i].keybuffer)); 103 /* TODO: init key_buffer */ 104 while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { 105 106 ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL); 107 } 108 } 63 109 110 64 111 65 /* Register service at nameserver */66 printf("%s: Registering at naming service.\n", NAME);67 68 112 if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) { 69 printf("%s: Error: Registering at naming service failed.\n", NAME);70 113 return -1; 71 114 }; … … 75 118 switch (IPC_GET_METHOD(call)) { 76 119 case IPC_M_PHONE_HUNGUP: 77 printf("%s: Phone hung up.\n", NAME); 78 retval = 0; 120 /*FIXME: if its fb or kbd then panic! */ 121 /* free connection */ 122 if (i = find_connection(IPC_GET_ARG3(call)) < CONSOLE_COUNT) { 123 connections[i].used = 0; 124 /*TODO: free connection[i].key_buffer; */ 125 /* FIXME: active_connection hungup */ 126 retval = 0; 127 } else { 128 /*FIXME: No such connection */ 129 } 79 130 break; 80 131 case IPC_M_CONNECT_ME_TO: 81 printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); 132 133 /* find first free connection */ 134 135 if ((i = find_free_connection()) == CONSOLE_COUNT) { 136 retval = ELIMIT; 137 break; 138 } 139 140 connections[i].used = 1; 141 connections[i].client_phone = IPC_GET_ARG3(call); 142 82 143 retval = 0; 83 144 break; 84 145 case KBD_PUSHCHAR: 85 printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call)); 146 /* got key from keyboard driver */ 147 /* find active console */ 148 /* if client is awaiting key, send it */ 149 /*FIXME: else store key to its buffer */ 86 150 retval = 0; 151 i = IPC_GET_ARG1(call) & 0xff; 152 /* switch to another virtual console */ 153 if ((i >= KBD_KEY_F1) && (i < KBD_KEY_F1 + CONSOLE_COUNT)) { 154 active_client = i - KBD_KEY_F1; 155 break; 156 } 157 158 keybuffer_push(&(connections[active_client].keybuffer), i); 87 159 88 160 break; 161 case CONSOLE_PUTCHAR: 162 /* find sender client */ 163 /* ??? 164 * if its active client, send it to vfb 165 **/ 166 /*FIXME: check, if its from active client, .... */ 167 168 if ((i = find_connection(IPC_GET_ARG3(call))) == CONSOLE_COUNT) { 169 break; 170 }; 171 172 /* TODO: send message to fb */ 173 ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, IPC_GET_ARG1(call), IPC_GET_ARG2(call), NULL, NULL); 174 175 break; 176 case CONSOLE_GETCHAR: 177 /* FIXME: */ 178 if (!keybuffer_pop(&(connections[active_client].keybuffer), (char *)&arg1)) { 179 /* FIXME: buffer empty -> store request */ 180 arg1 = 'X'; /* Only temporary */ 181 }; 182 //ipc_call_async_2(connections[active_client].vfb_phone, FB_PUTCHAR, ' ', arg1, NULL, (void *)NULL); 183 break; 89 184 default: 90 printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));91 185 retval = ENOENT; 92 186 break; -
fb/fb.c
rf25b73d6 r79460ae 127 127 int vfb = vfb_no++; 128 128 129 if (vfb > 9) {129 if (vfb > VFB_CONNECTIONS) { 130 130 ipc_answer_fast(iid, ELIMIT, 0,0); 131 131 return; … … 536 536 537 537 538 if( (graphics_items[item_new]=malloc(sizeof(framebuffer_descriptor_t))) == NULL)538 if( (graphics_items[item_new]=malloc(sizeof(framebuffer_descriptor_t))) == NULL) 539 539 { 540 540 return EFB; -
fb/fb.h
rf25b73d6 r79460ae 33 33 #include <arch/types.h> 34 34 35 #define VFB_CONNECTIONS 9 36 35 37 //void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan); 36 38 -
kbd/Makefile
rf25b73d6 r79460ae 68 68 69 69 $(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) 70 $(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map70 $(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map 71 71 72 72 disasm: -
kbd/arch/ia32/include/kbd.h
rf25b73d6 r79460ae 30 30 #define __ia32_KBD_H__ 31 31 32 #include <key_buffer.h> 33 32 34 int kbd_arch_init(void); 33 int kbd_arch_process( int scan_code);35 int kbd_arch_process(keybuffer_t *keybuffer, int scan_code); 34 36 35 37 #endif -
kbd/arch/ia32/src/kbd.c
rf25b73d6 r79460ae 29 29 30 30 #include <arch/kbd.h> 31 #include <key_buffer.h>32 31 #include <ipc/ipc.h> 33 32 … … 80 79 ' ', 81 80 SPECIAL, /* 0x3a - CapsLock */ 82 SPECIAL, /* 0x3b - F1 */ 83 SPECIAL, /* 0x3c - F2 */ 84 SPECIAL, /* 0x3d - F3 */ 85 SPECIAL, /* 0x3e - F4 */ 86 SPECIAL, /* 0x3f - F5 */ 87 SPECIAL, /* 0x40 - F6 */ 88 SPECIAL, /* 0x41 - F7 */ 89 SPECIAL, /* 0x42 - F8 */ 90 SPECIAL, /* 0x43 - F9 */ 91 SPECIAL, /* 0x44 - F10 */ 81 0x3b, /* 0x3b - F1 */ 82 // SPECIAL, /* 0x3b - F1 */ 83 0x3c, /* 0x3c - F2 */ 84 // SPECIAL, /* 0x3c - F2 */ 85 0x3d, /* 0x3d - F3 */ 86 // SPECIAL, /* 0x3d - F3 */ 87 0x3e, /* 0x3e - F4 */ 88 // SPECIAL, /* 0x3e - F4 */ 89 // SPECIAL, /* 0x3f - F5 */ 90 0x3f, /* 0x3f - F5 */ 91 // SPECIAL, /* 0x40 - F6 */ 92 0x40, /* 0x40 - F6 */ 93 // SPECIAL, /* 0x41 - F7 */ 94 0x41, /* 0x41 - F7 */ 95 // SPECIAL, /* 0x42 - F8 */ 96 0x42, /* 0x42 - F8 */ 97 // SPECIAL, /* 0x43 - F9 */ 98 0x43, /* 0x43 - F9 */ 99 // SPECIAL, /* 0x44 - F10 */ 100 0x44, /* 0x44 - F10 */ 92 101 SPECIAL, /* 0x45 - NumLock */ 93 102 SPECIAL, /* 0x46 - ScrollLock */ … … 160 169 ' ', 161 170 SPECIAL, /* 0x3a - CapsLock */ 162 SPECIAL, /* 0x3b - F1 */ 163 SPECIAL, /* 0x3c - F2 */ 164 SPECIAL, /* 0x3d - F3 */ 165 SPECIAL, /* 0x3e - F4 */ 166 SPECIAL, /* 0x3f - F5 */ 167 SPECIAL, /* 0x40 - F6 */ 168 SPECIAL, /* 0x41 - F7 */ 169 SPECIAL, /* 0x42 - F8 */ 170 SPECIAL, /* 0x43 - F9 */ 171 SPECIAL, /* 0x44 - F10 */ 171 0x3b, /* 0x3b - F1 */ 172 0x3c, /* 0x3c - F2 */ 173 0x3d, /* 0x3d - F3 */ 174 0x3e, /* 0x3e - F4 */ 175 0x3f, /* 0x3f - F5 */ 176 0x40, /* 0x40 - F6 */ 177 0x41, /* 0x41 - F7 */ 178 0x42, /* 0x42 - F8 */ 179 0x43, /* 0x43 - F9 */ 180 0x44, /* 0x44 - F10 */ 181 // SPECIAL, /* 0x3b - F1 */ 182 // SPECIAL, /* 0x3c - F2 */ 183 // SPECIAL, /* 0x3d - F3 */ 184 // SPECIAL, /* 0x3e - F4 */ 185 // SPECIAL, /* 0x3f - F5 */ 186 // SPECIAL, /* 0x40 - F6 */ 187 // SPECIAL, /* 0x41 - F7 */ 188 // SPECIAL, /* 0x42 - F8 */ 189 // SPECIAL, /* 0x43 - F9 */ 190 // SPECIAL, /* 0x44 - F10 */ 172 191 SPECIAL, /* 0x45 - NumLock */ 173 192 SPECIAL, /* 0x46 - ScrollLock */ … … 231 250 }; 232 251 233 static int key_released( unsigned char key)252 static int key_released(keybuffer_t *keybuffer, unsigned char key) 234 253 { 235 254 switch (key) { … … 250 269 } 251 270 252 static int key_pressed( unsigned char key)271 static int key_pressed(keybuffer_t *keybuffer, unsigned char key) 253 272 { 254 273 char *map = sc_primary_map; … … 268 287 break; 269 288 case SC_LEFTARR: 270 if (key _buffer_available() >= 3) {271 key _buffer_push(0x1b);272 key _buffer_push(0x5b);273 key _buffer_push(0x44);289 if (keybuffer_available(keybuffer) >= 3) { 290 keybuffer_push(keybuffer, 0x1b); 291 keybuffer_push(keybuffer, 0x5b); 292 keybuffer_push(keybuffer, 0x44); 274 293 } 275 294 break; 276 295 case SC_RIGHTARR: 277 if (key _buffer_available() >= 3) {278 key _buffer_push(0x1b);279 key _buffer_push(0x5b);280 key _buffer_push(0x43);296 if (keybuffer_available(keybuffer) >= 3) { 297 keybuffer_push(keybuffer, 0x1b); 298 keybuffer_push(keybuffer, 0x5b); 299 keybuffer_push(keybuffer, 0x43); 281 300 } 282 301 break; 283 302 case SC_UPARR: 284 if (key _buffer_available() >= 3) {285 key _buffer_push(0x1b);286 key _buffer_push(0x5b);287 key _buffer_push(0x41);303 if (keybuffer_available(keybuffer) >= 3) { 304 keybuffer_push(keybuffer, 0x1b); 305 keybuffer_push(keybuffer, 0x5b); 306 keybuffer_push(keybuffer, 0x41); 288 307 } 289 308 break; 290 309 case SC_DOWNARR: 291 if (key _buffer_available() >= 3) {292 key _buffer_push(0x1b);293 key _buffer_push(0x5b);294 key _buffer_push(0x42);310 if (keybuffer_available(keybuffer) >= 3) { 311 keybuffer_push(keybuffer, 0x1b); 312 keybuffer_push(keybuffer, 0x5b); 313 keybuffer_push(keybuffer, 0x42); 295 314 } 296 315 break; 297 316 case SC_HOME: 298 if (key _buffer_available() >= 3) {299 key _buffer_push(0x1b);300 key _buffer_push(0x4f);301 key _buffer_push(0x48);317 if (keybuffer_available(keybuffer) >= 3) { 318 keybuffer_push(keybuffer, 0x1b); 319 keybuffer_push(keybuffer, 0x4f); 320 keybuffer_push(keybuffer, 0x48); 302 321 } 303 322 break; 304 323 case SC_END: 305 if (key _buffer_available() >= 3) {306 key _buffer_push(0x1b);307 key _buffer_push(0x4f);308 key _buffer_push(0x46);324 if (keybuffer_available(keybuffer) >= 3) { 325 keybuffer_push(keybuffer, 0x1b); 326 keybuffer_push(keybuffer, 0x4f); 327 keybuffer_push(keybuffer, 0x46); 309 328 } 310 329 break; 311 330 case SC_DELETE: 312 if (key _buffer_available() >= 4) {313 key _buffer_push(0x1b);314 key _buffer_push(0x5b);315 key _buffer_push(0x33);316 key _buffer_push(0x7e);331 if (keybuffer_available(keybuffer) >= 4) { 332 keybuffer_push(keybuffer, 0x1b); 333 keybuffer_push(keybuffer, 0x5b); 334 keybuffer_push(keybuffer, 0x33); 335 keybuffer_push(keybuffer, 0x7e); 317 336 } 318 337 break; … … 325 344 if (shift) 326 345 map = sc_secondary_map; 327 key _buffer_push(map[key]);346 keybuffer_push(keybuffer, map[key]); 328 347 break; 329 348 } … … 338 357 } 339 358 340 int kbd_arch_process( int scan_code)359 int kbd_arch_process(keybuffer_t *keybuffer, int scan_code) 341 360 { 342 361 if (scan_code != IGNORE_CODE) { 343 362 if (scan_code & KEY_RELEASE) 344 key_released( scan_code ^ KEY_RELEASE);363 key_released(keybuffer, scan_code ^ KEY_RELEASE); 345 364 else 346 key_pressed( scan_code);365 key_pressed(keybuffer, scan_code); 347 366 } 348 367 return 1; -
kbd/arch/mips32/include/kbd.h
rf25b73d6 r79460ae 30 30 #define __mips32_KBD_H__ 31 31 32 #include <key_buffer.h> 33 32 34 int kbd_arch_init(void); 33 int kbd_arch_process( int scan_code);35 int kbd_arch_process(keybuffer_t *keybuffer, int scan_code); 34 36 35 37 #endif -
kbd/arch/mips32/src/kbd.c
rf25b73d6 r79460ae 29 29 #include <arch/kbd.h> 30 30 #include <ipc/ipc.h> 31 #include <key_buffer.h>32 31 33 32 irq_cmd_t msim_cmds[1] = { … … 46 45 } 47 46 48 int kbd_arch_process( int scan_code)47 int kbd_arch_process(keybuffer_t *keybuffer, int scan_code) 49 48 { 50 key _buffer_push(scan_code);49 keybuffer_push(keybuffer, scan_code); 51 50 return 1; 52 51 } -
kbd/generic/kbd.c
rf25b73d6 r79460ae 49 49 int phoneid; 50 50 char connected = 0; 51 51 keybuffer_t keybuffer; 52 52 ipcarg_t retval, arg1, arg2; 53 53 54 printf("Uspace kbd service started.\n");54 // printf("Uspace kbd service started.\n"); 55 55 56 56 /* Initialize arch dependent parts */ 57 57 if (!(res = kbd_arch_init())) { 58 printf("Kbd registration failed with retval %d.\n", res);58 // printf("Kbd registration failed with retval %d.\n", res); 59 59 return -1; 60 60 }; 61 61 62 62 /* Initialize key buffer */ 63 key _buffer_init();63 keybuffer_init(&keybuffer); 64 64 65 65 /* Register service at nameserver */ 66 printf("%s: Registering at naming service.\n", NAME);66 // printf("%s: Registering at naming service.\n", NAME); 67 67 68 68 if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) { 69 printf("%s: Error: Registering at naming service failed.\n", NAME);69 // printf("%s: Error: Registering at naming service failed.\n", NAME); 70 70 return -1; 71 71 }; … … 76 76 switch (IPC_GET_METHOD(call)) { 77 77 case IPC_M_PHONE_HUNGUP: 78 printf("%s: Phone hung up.\n", NAME);78 // printf("%s: Phone hung up.\n", NAME); 79 79 connected = 0; 80 80 retval = 0; … … 98 98 if (connected) { 99 99 /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ 100 kbd_arch_process( IPC_GET_ARG2(call));100 kbd_arch_process(&keybuffer, IPC_GET_ARG2(call)); 101 101 102 102 //printf("%s: GOT INTERRUPT: %c\n", NAME, key); … … 107 107 retval = 0; 108 108 109 while (!key _buffer_empty()) {110 if (!key _buffer_pop((char *)&arg1)) {111 printf("%s: KeyBuffer is empty but it should not be.\n");109 while (!keybuffer_empty(&keybuffer)) { 110 if (!keybuffer_pop(&keybuffer, (char *)&arg1)) { 111 // printf("%s: KeyBuffer is empty but it should not be.\n"); 112 112 break; 113 113 } 114 114 /*FIXME: detection of closed connection */ 115 ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, NULL);115 ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL); 116 116 } 117 117 118 118 } 119 printf("%s: Interrupt processed.\n", NAME);119 // printf("%s: Interrupt processed.\n", NAME); 120 120 break; 121 121 default: 122 printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));122 // printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); 123 123 retval = ENOENT; 124 124 break; -
kbd/generic/key_buffer.c
rf25b73d6 r79460ae 28 28 29 29 #include <key_buffer.h> 30 #include <libadt/fifo.h>31 32 #define KBD_BUFFER_SIZE 128 /**< Size of buffer for pressed keys */33 34 FIFO_INITIALIZE_STATIC(buffer, char, KBD_BUFFER_SIZE); /**< Fifo for storing pressed keys */35 fifo_count_t buffer_items; /**< Counter of used items for prevent fifo overflow */36 30 37 31 /** Clear key buffer. 38 32 */ 39 void key _buffer_free(void)33 void keybuffer_free(keybuffer_t *keybuffer) 40 34 { 41 buffer_items = 0; 42 buffer.head = buffer.tail = 0; 35 36 keybuffer->items = 0; 37 keybuffer->head = keybuffer->tail = keybuffer->items = 0; 43 38 } 44 39 … … 46 41 * 47 42 */ 48 void key _buffer_init(void)43 void keybuffer_init(keybuffer_t *keybuffer) 49 44 { 50 key _buffer_free();45 keybuffer_free(keybuffer); 51 46 } 52 47 … … 56 51 * @return empty buffer space 57 52 */ 58 int key _buffer_available(void)53 int keybuffer_available(keybuffer_t *keybuffer) 59 54 { 60 return K BD_BUFFER_SIZE - buffer_items;55 return KEYBUFFER_SIZE - keybuffer->items; 61 56 } 62 57 … … 64 59 * @return nonzero, if buffer is not empty. 65 60 */ 66 int key _buffer_empty(void)61 int keybuffer_empty(keybuffer_t *keybuffer) 67 62 { 68 return ( buffer_items == 0);63 return (keybuffer->items == 0); 69 64 } 70 65 … … 73 68 * @param key code of stored key 74 69 */ 75 void key _buffer_push(char key)70 void keybuffer_push(keybuffer_t *keybuffer, char key) 76 71 { 77 if ( buffer_items < KBD_BUFFER_SIZE) {78 fifo_push(buffer,key);79 buffer_items++;72 if (keybuffer->items < KEYBUFFER_SIZE) { 73 keybuffer->fifo[keybuffer->tail = (keybuffer->tail + 1) < keybuffer->items ? (keybuffer->tail + 1) : 0] = (key); 74 keybuffer->items++; 80 75 } 81 76 } … … 85 80 * @return zero on empty buffer, nonzero else 86 81 */ 87 int key _buffer_pop(char *c)82 int keybuffer_pop(keybuffer_t *keybuffer, char *c) 88 83 { 89 if ( buffer_items > 0) {90 buffer_items--;91 *c = fifo_pop(buffer);84 if (keybuffer->items > 0) { 85 keybuffer->items--; 86 *c = keybuffer->fifo[keybuffer->head = (keybuffer->head + 1) < keybuffer->items ? (keybuffer->head + 1) : 0]; 92 87 return 1; 93 88 } -
kbd/include/kbd.h
rf25b73d6 r79460ae 32 32 #define KBD_PUSHCHAR 1024 33 33 34 #define KBD_KEY_F1 0x3b 35 #define KBD_KEY_F2 0x3c 36 #define KBD_KEY_F3 0x3d 37 #define KBD_KEY_F4 0x3e 38 #define KBD_KEY_F5 0x3f 39 #define KBD_KEY_F6 0x40 40 #define KBD_KEY_F7 0x41 41 #define KBD_KEY_F8 0x42 42 #define KBD_KEY_F9 0x43 43 #define KBD_KEY_F10 0x44 44 #define KBD_KEY_F11 0x45 45 #define KBD_KEY_F12 0x46 46 34 47 #endif 35 48 -
kbd/include/key_buffer.h
rf25b73d6 r79460ae 32 32 #include <types.h> 33 33 34 void key_buffer_free(void); 35 void key_buffer_init(void); 36 int key_buffer_available(void); 37 int key_buffer_empty(void); 38 void key_buffer_push(char key); 39 int key_buffer_pop(char *c); 34 #define KEYBUFFER_SIZE 128 /**< Size of buffer for pressed keys */ 35 36 typedef struct { 37 char fifo[KEYBUFFER_SIZE]; 38 unsigned long head; 39 unsigned long tail; 40 unsigned long items; 41 } keybuffer_t; 42 43 void keybuffer_free(keybuffer_t *keybuffer); 44 void keybuffer_init(keybuffer_t *keybuffer); 45 int keybuffer_available(keybuffer_t *keybuffer); 46 int keybuffer_empty(keybuffer_t *keybuffer); 47 void keybuffer_push(keybuffer_t *keybuffer, char key); 48 int keybuffer_pop(keybuffer_t *keybuffer, char *c); 40 49 41 50 #endif -
libc/Makefile
rf25b73d6 r79460ae 32 32 LIBC_PREFIX = . 33 33 SOFTINT_PREFIX = ../softint 34 CONSOLE_PREFIX = ../console 34 35 35 36 ## Setup toolchain … … 37 38 38 39 include $(LIBC_PREFIX)/Makefile.toolchain 40 41 CFLAGS += -I$(CONSOLE_PREFIX) 39 42 40 43 ## Sources -
libc/generic/io/stream.c
rf25b73d6 r79460ae 8 8 #include <ipc/fb.h> 9 9 #include <ipc/services.h> 10 #include <console.h> 10 11 11 12 #define FDS 32 … … 17 18 } stream_t; 18 19 19 20 typedef struct vfb_descriptor_t { 21 int phone; 22 int vfb; 23 } vfb_descriptor_t; 24 20 int console_phone = -1; 25 21 26 22 stream_t streams[FDS] = {{0, 0, 0}}; … … 33 29 }*/ 34 30 35 static void vfb_send_char(vfb_descriptor_t *d, char c) 31 static ssize_t write_stderr(void *param, const void *buf, size_t count) 32 { 33 return count; 34 //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count); 35 } 36 37 static char read_stdin(void) 36 38 { 37 39 ipcarg_t r0,r1; 38 ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1); 40 ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1); 41 42 return r0; 43 //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count); 39 44 } 40 41 static ssize_t write_vfb(void *param, const void *buf, size_t count) 45 static ssize_t write_stdout(void *param, const void *buf, size_t count) 42 46 { 43 47 int i; 48 ipcarg_t r0,r1; 49 44 50 for (i = 0; i < count; i++) 45 vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);51 ipc_call_sync_2(console_phone, CONSOLE_PUTCHAR, 0, ((const char *)buf)[i], &r0, &r1); 46 52 47 53 return count; … … 50 56 51 57 52 static ssize_t write_stderr(void *param, const void *buf, size_t count)53 {54 return count;55 //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);56 }57 58 58 59 stream_t open_vfb(void) 59 static stream_t open_stdin(void) 60 60 { 61 61 stream_t stream; 62 vfb_descriptor_t *vfb;63 62 int phoneid; 64 63 int res; 65 ipcarg_t vfb_no;66 64 67 while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { 68 volatile int a; 69 70 for (a = 0; a < 1048576; a++); 65 if (console_phone < 0) { 66 while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { 67 volatile int a; 68 for (a = 0; a < 1048576; a++); 69 } 71 70 } 72 71 73 ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no); 74 vfb = malloc(sizeof(vfb_descriptor_t)); 75 76 vfb->phone = phoneid; 77 vfb->vfb = vfb_no; 78 79 stream.w = write_vfb; 80 stream.param = vfb; 72 stream.r = read_stdin; 73 stream.param = 0; 81 74 return stream; 82 75 } 83 76 77 static stream_t open_stdout(void) 78 { 79 stream_t stream; 80 int res; 81 82 if (console_phone < 0) { 83 while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { 84 volatile int a; 85 for (a = 0; a < 1048576; a++); 86 } 87 } 88 89 stream.w = write_stdout; 90 stream.param = 0; 91 return stream; 92 } 84 93 85 94 fd_t open(const char *fname, int flags) … … 93 102 94 103 if (!strcmp(fname, "stdin")) { 95 streams[c] .r = (preadfn_t)1;104 streams[c] = open_stdin(); 96 105 return c; 97 106 } … … 100 109 //streams[c].w = write_stdout; 101 110 //return c; 102 streams[c] = open_ vfb();111 streams[c] = open_stdout(); 103 112 return c; 104 113 } -
libc/include/io/stream.h
rf25b73d6 r79460ae 8 8 9 9 typedef ssize_t (*pwritefn_t)(void *, const void *, size_t); 10 typedef ssize_t(*preadfn_t)(void);10 typedef char (*preadfn_t)(void); 11 11 12 12 fd_t open(const char *fname, int flags);
Note:
See TracChangeset
for help on using the changeset viewer.