Changeset a2cd194 in mainline
- Timestamp:
- 2006-05-22T11:14:25Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8bc924e
- Parents:
- 6862338
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fb/fb.c
r6862338 ra2cd194 1 1 /* 2 2 * Copyright (C) 2006 Jakub Vana 3 * All rights reserved.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions7 * are met:8 *9 * - Redistributions of source code must retain the above copyright10 * notice, this list of conditions and the following disclaimer.11 * - Redistributions in binary form must reproduce the above copyright12 * notice, this list of conditions and the following disclaimer in the13 * documentation and/or other materials provided with the distribution.14 * - The name of the author may not be used to endorse or promote products15 * derived from this software without specific prior written permission.16 *17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 */28 29 #include <stdio.h>30 #include <ddi.h>31 #include <task.h>32 #include <stdlib.h>33 #include <ddi.h>34 #include <sysinfo.h>35 #include <align.h>36 #include <as.h>37 #include <ipc/fb.h>38 39 40 #include <ipc/ipc.h>41 #include <ipc/services.h>42 #include <unistd.h>43 #include <stdlib.h>44 #include <ipc/ns.h>45 46 #include <kernel/errno.h>47 #include <async.h>48 49 #include "fb.h"50 51 #define EFB (-1)52 53 #define DEFAULT_BGCOLOR 0x00008054 #define DEFAULT_FGCOLOR 0xffff0055 #define DEFAULT_LOGOCOLOR 0x0000ff56 57 #define MAIN_BGCOLOR 0x40400058 #define MAIN_FGCOLOR 0x00000059 #define MAIN_LOGOCOLOR 0x40400060 61 #define SPACING (2)62 63 #define H_NO_VFBS 364 #define V_NO_VFBS 365 66 67 static void fb_putchar(int item,char ch);68 int create_window(int item,unsigned int x, unsigned int y,unsigned int x_size, unsigned int y_size,69 unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);70 void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan,71 unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);72 73 74 unsigned int mod_col(unsigned int col,int mod);75 76 77 78 static int init_fb(void)79 {80 __address fb_ph_addr;81 unsigned int fb_width;82 unsigned int fb_height;83 unsigned int fb_bpp;84 unsigned int fb_scanline;85 __address fb_addr;86 int a=0;87 int i,j,k;88 int w;89 char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB ";90 91 fb_ph_addr=sysinfo_value("fb.address.physical");92 fb_width=sysinfo_value("fb.width");93 fb_height=sysinfo_value("fb.height");94 fb_bpp=sysinfo_value("fb.bpp");95 fb_scanline=sysinfo_value("fb.scanline");96 97 fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);98 99 100 101 map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr,102 (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,1);103 104 fb_init(0,fb_addr, fb_width, fb_height, fb_bpp, fb_scanline,105 MAIN_BGCOLOR,MAIN_FGCOLOR,MAIN_LOGOCOLOR);106 107 fb_putchar(0,'\n');108 fb_putchar(0,' ');109 110 for(i=0;i<H_NO_VFBS;i++)111 for(j=0;j<V_NO_VFBS;j++) {112 w = create_window(0,(fb_width/H_NO_VFBS)*i+SPACING,113 (fb_height/V_NO_VFBS)*j+SPACING,(fb_width/H_NO_VFBS)-2*SPACING ,114 (fb_height/V_NO_VFBS)-2*SPACING,mod_col(DEFAULT_BGCOLOR,/*i+j*H_NO_VFBS*/0),115 mod_col(DEFAULT_FGCOLOR,/*i+j*H_NO_VFBS*/0),116 mod_col(DEFAULT_LOGOCOLOR,/*i+j*H_NO_VFBS)*/0));117 118 if( w== EFB)119 return -1;120 121 for(k=0;text[k];k++)122 fb_putchar(w,text[k]);123 fb_putchar(w,w+'0');124 fb_putchar(w,'\n');125 }126 return 0;127 }128 129 int vfb_no = 1;130 void client_connection(ipc_callid_t iid, ipc_call_t *icall)131 {132 ipc_callid_t callid;133 ipc_call_t call;134 int vfb = vfb_no++;135 136 if (vfb > 9) {137 ipc_answer_fast(iid, ELIMIT, 0,0);138 return;139 }140 ipc_answer_fast(iid, 0, 0, 0);141 142 while (1) {143 callid = async_get_call(&call);144 switch (IPC_GET_METHOD(call)) {145 case IPC_M_PHONE_HUNGUP:146 ipc_answer_fast(callid,0,0,0);147 return; /* Exit thread */148 149 case FB_PUTCHAR:150 ipc_answer_fast(callid,0,0,0);151 fb_putchar(vfb,IPC_GET_ARG2(call));152 break;153 default:154 ipc_answer_fast(callid,ENOENT,0,0);155 }156 }157 }158 159 int main(int argc, char *argv[])160 {161 ipc_call_t call;162 ipc_callid_t callid;163 char connected = 0;164 int res;165 int c;166 ipcarg_t phonead;167 168 ipcarg_t retval, arg1, arg2;169 170 if(!sysinfo_value("fb")) return -1;171 172 173 if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0)174 return -1;175 176 init_fb();177 178 async_manager();179 /* Never reached */180 return 0;181 }182 /*183 3 * Copyright (C) 2006 Ondrej Palkovsky 184 4 * All rights reserved. … … 208 28 */ 209 29 30 #include <stdio.h> 31 #include <ddi.h> 32 #include <task.h> 33 #include <stdlib.h> 34 #include <ddi.h> 35 #include <sysinfo.h> 36 #include <align.h> 37 #include <as.h> 38 #include <ipc/fb.h> 39 40 41 #include <ipc/ipc.h> 42 #include <ipc/services.h> 43 #include <unistd.h> 44 #include <stdlib.h> 45 #include <ipc/ns.h> 46 47 #include <kernel/errno.h> 48 #include <async.h> 49 50 210 51 #include "font-8x16.h" 211 52 #include <string.h> 212 53 213 54 #include "helenos.xbm" 214 215 216 217 55 #include "fb.h" 56 57 #define EFB (-1) 58 59 #define DEFAULT_BGCOLOR 0x000080 60 #define DEFAULT_FGCOLOR 0xffff00 61 #define DEFAULT_LOGOCOLOR 0x0000ff 62 63 #define MAIN_BGCOLOR 0x404000 64 #define MAIN_FGCOLOR 0x000000 65 #define MAIN_LOGOCOLOR 0x404000 66 67 #define SPACING (2) 68 69 #define H_NO_VFBS 3 70 #define V_NO_VFBS 3 71 72 73 static void fb_putchar(int item,char ch); 74 int create_window(int item,unsigned int x, unsigned int y,unsigned int x_size, unsigned int y_size, 75 unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR); 76 void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan, 77 unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR); 78 79 80 unsigned int mod_col(unsigned int col,int mod); 81 82 83 84 static int init_fb(void) 85 { 86 __address fb_ph_addr; 87 unsigned int fb_width; 88 unsigned int fb_height; 89 unsigned int fb_bpp; 90 unsigned int fb_scanline; 91 __address fb_addr; 92 int a=0; 93 int i,j,k; 94 int w; 95 char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB "; 96 97 fb_ph_addr=sysinfo_value("fb.address.physical"); 98 fb_width=sysinfo_value("fb.width"); 99 fb_height=sysinfo_value("fb.height"); 100 fb_bpp=sysinfo_value("fb.bpp"); 101 fb_scanline=sysinfo_value("fb.scanline"); 102 103 fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE); 104 105 106 107 map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr, 108 (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,1); 109 110 fb_init(0,fb_addr, fb_width, fb_height, fb_bpp, fb_scanline, 111 MAIN_BGCOLOR,MAIN_FGCOLOR,MAIN_LOGOCOLOR); 112 113 fb_putchar(0,'\n'); 114 fb_putchar(0,' '); 115 116 for(i=0;i<H_NO_VFBS;i++) 117 for(j=0;j<V_NO_VFBS;j++) { 118 w = create_window(0,(fb_width/H_NO_VFBS)*i+SPACING, 119 (fb_height/V_NO_VFBS)*j+SPACING,(fb_width/H_NO_VFBS)-2*SPACING , 120 (fb_height/V_NO_VFBS)-2*SPACING,mod_col(DEFAULT_BGCOLOR,/*i+j*H_NO_VFBS*/0), 121 mod_col(DEFAULT_FGCOLOR,/*i+j*H_NO_VFBS*/0), 122 mod_col(DEFAULT_LOGOCOLOR,/*i+j*H_NO_VFBS)*/0)); 123 124 if( w== EFB) 125 return -1; 126 127 for(k=0;text[k];k++) 128 fb_putchar(w,text[k]); 129 fb_putchar(w,w+'0'); 130 fb_putchar(w,'\n'); 131 } 132 return 0; 133 } 134 135 int vfb_no = 1; 136 void client_connection(ipc_callid_t iid, ipc_call_t *icall) 137 { 138 ipc_callid_t callid; 139 ipc_call_t call; 140 int vfb = vfb_no++; 141 142 if (vfb > 9) { 143 ipc_answer_fast(iid, ELIMIT, 0,0); 144 return; 145 } 146 ipc_answer_fast(iid, 0, 0, 0); 147 148 while (1) { 149 callid = async_get_call(&call); 150 switch (IPC_GET_METHOD(call)) { 151 case IPC_M_PHONE_HUNGUP: 152 ipc_answer_fast(callid,0,0,0); 153 return; /* Exit thread */ 154 155 case FB_PUTCHAR: 156 ipc_answer_fast(callid,0,0,0); 157 fb_putchar(vfb,IPC_GET_ARG2(call)); 158 break; 159 default: 160 ipc_answer_fast(callid,ENOENT,0,0); 161 } 162 } 163 } 164 165 int main(int argc, char *argv[]) 166 { 167 ipc_call_t call; 168 ipc_callid_t callid; 169 char connected = 0; 170 int res; 171 int c; 172 ipcarg_t phonead; 173 174 ipcarg_t retval, arg1, arg2; 175 176 if(!sysinfo_value("fb")) return -1; 177 178 179 if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0) 180 return -1; 181 182 init_fb(); 183 184 async_manager(); 185 /* Never reached */ 186 return 0; 187 } 218 188 219 189 -
libc/generic/async.c
r6862338 ra2cd194 74 74 * .... 75 75 * } 76 * 77 * TODO: Detaching/joining dead psthreads? */ 76 78 */ 77 79 #include <futex.h> … … 100 102 pstid_t ptid; /**< Thread associated with this connection */ 101 103 int active; /**< If this thread is currently active */ 102 int opened; /* If the connection was accepted */103 104 /* Structures for connection opening packet */ 104 105 ipc_callid_t callid; … … 110 111 /* Hash table functions */ 111 112 112 #define ASYNC_HASH_TABLE_CHAINS 32113 #define CONN_HASH_TABLE_CHAINS 32 113 114 114 115 static hash_index_t conn_hash(unsigned long *key) 115 116 { 116 117 assert(key); 117 return ((*key) >> 4) % ASYNC_HASH_TABLE_CHAINS;118 return ((*key) >> 4) % CONN_HASH_TABLE_CHAINS; 118 119 } 119 120 … … 175 176 } 176 177 178 /** Return new incoming message for current(thread-local) connection */ 177 179 ipc_callid_t async_get_call(ipc_call_t *call) 178 180 { … … 200 202 } 201 203 204 /** Thread function that gets created on new connection 205 * 206 * This function is defined as a weak symbol - to be redefined in 207 * user code. 208 */ 202 209 void client_connection(ipc_callid_t callid, ipc_call_t *call) 203 210 { 204 printf("Got connection - no handler.\n"); 205 _exit(1); 206 } 207 211 ipc_answer_fast(callid, ENOENT, 0, 0); 212 } 213 214 /** Wrapper for client connection thread 215 * 216 * When new connection arrives, thread with this function is created. 217 * It calls client_connection and does final cleanup. 218 * 219 * @parameter arg Connection structure pointer 220 */ 208 221 static int connection_thread(void *arg) 209 222 { 223 unsigned long key; 224 msg_t *msg; 225 210 226 /* Setup thread local connection pointer */ 211 227 PS_connection = (connection_t *)arg; 212 228 client_connection(PS_connection->callid, &PS_connection->call); 213 229 230 /* Remove myself from connection hash table */ 214 231 futex_down(&conn_futex); 215 /* TODO: remove myself from connection hash table */ 232 key = PS_connection->in_phone_hash; 233 hash_table_remove(&conn_hash_table, &key, 1); 216 234 futex_up(&conn_futex); 217 /* TODO: answer all unanswered messages in queue with 218 * EHANGUP */ 235 /* Answer all remaining messages with ehangup */ 236 while (!list_empty(&PS_connection->msg_queue)) { 237 msg = list_get_instance(PS_connection->msg_queue.next, msg_t, link); 238 list_remove(&msg->link); 239 ipc_answer_fast(msg->callid, EHANGUP, 0, 0); 240 free(msg); 241 } 219 242 } 220 243 … … 239 262 conn->in_phone_hash = IPC_GET_ARG3(*call); 240 263 list_initialize(&conn->msg_queue); 241 conn->opened = 0;242 264 conn->ptid = psthread_create(connection_thread, conn); 243 265 conn->callid = callid; … … 298 320 } 299 321 322 /** Function to start async_manager as a standalone thread 323 * 324 * When more kernel threads are used, one async manager should 325 * exist per thread. The particular implementation may change, 326 * currently one async_manager is started automatically per kernel 327 * thread except main thread. 328 */ 300 329 static int async_manager_thread(void *arg) 301 330 { … … 323 352 int _async_init(void) 324 353 { 325 if (!hash_table_create(&conn_hash_table, ASYNC_HASH_TABLE_CHAINS, 1, &conn_hash_table_ops)) {354 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1, &conn_hash_table_ops)) { 326 355 printf("%s: cannot create hash table\n", "async"); 327 356 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.