Changeset 2408969 in mainline
- Timestamp:
- 2006-06-02T19:37:21Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 86029498
- Parents:
- 53daee3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
init/init.c
r53daee3 r2408969 28 28 29 29 #include "version.h" 30 #include <ipc/ipc.h>31 #include <ipc/services.h>32 #include <ipc/ns.h>33 30 #include <stdio.h> 34 #include <unistd.h>35 #include <stdlib.h>36 #include <thread.h>37 #include <task.h>38 #include <psthread.h>39 #include <futex.h>40 #include <as.h>41 #include <ddi.h>42 #include <string.h>43 #include <errno.h>44 #include <kbd.h>45 #include <ipc/fb.h>46 #include <async.h>47 #include <sys/time.h>48 49 int a;50 atomic_t ftx;51 52 int __thread stage;53 54 extern void utest(void *arg);55 void utest(void *arg)56 {57 printf("Uspace thread started.\n");58 if (futex_down(&ftx) < 0)59 printf("Futex failed.\n");60 if (futex_up(&ftx) < 0)61 printf("Futex failed.\n");62 63 printf("%s in good condition.\n", __FUNCTION__);64 65 for (;;)66 ;67 }68 69 /* test different parameters types and modifiers */70 static void test_printf(void)71 {72 printf("Simple text.\n");73 printf("Now insert '%s' string.\n","this");74 printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);75 printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);76 printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);77 printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);78 printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);79 printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);80 printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);81 printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );82 printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );83 84 printf("Thats all, folks!\n");85 }86 87 /* test width and precision modifiers */88 static void test_printf2(void)89 {90 printf(" text 10.8s %*.*s \n", 5, 3, "text");91 printf(" very long text 10.8s %10.8s \n", "very long text");92 printf(" text 8.10s %8.10s \n", "text");93 printf(" very long text 8.10s %8.10s \n", "very long text");94 95 printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' );96 printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 );97 printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 );98 printf(" 0xint: x '%x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 );99 100 }101 102 extern char _heap;103 static void test_mremap(void)104 {105 printf("Writing to good memory\n");106 as_area_resize(&_heap, 120000, 0);107 printf("%P\n", ((char *)&_heap));108 printf("%P\n", ((char *)&_heap) + 80000);109 *(((char *)&_heap) + 80000) = 10;110 printf("Making small\n");111 as_area_resize(&_heap, 16000, 0);112 printf("Failing..\n");113 *((&_heap) + 80000) = 10;114 115 printf("memory done\n");116 }117 /*118 static void test_sbrk(void)119 {120 printf("Writing to good memory\n");121 printf("Got: %P\n", sbrk(120000));122 printf("%P\n", ((char *)&_heap));123 printf("%P\n", ((char *)&_heap) + 80000);124 *(((char *)&_heap) + 80000) = 10;125 printf("Making small, got: %P\n",sbrk(-120000));126 printf("Testing access to heap\n");127 _heap = 10;128 printf("Failing..\n");129 *((&_heap) + 80000) = 10;130 131 printf("memory done\n");132 }133 */134 /*135 static void test_malloc(void)136 {137 char *data;138 139 data = malloc(10);140 printf("Heap: %P, data: %P\n", &_heap, data);141 data[0] = 'a';142 free(data);143 }144 */145 146 147 static void test_ping(void)148 {149 ipcarg_t result;150 int retval;151 152 printf("Pinging\n");153 retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);154 printf("Retval: %d - received: %P\n", retval, result);155 }156 157 static void got_answer(void *private, int retval, ipc_call_t *data)158 {159 printf("Retval: %d...%s...%zX, %zX\n", retval, private,160 IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));161 }162 163 164 static void got_answer_2(void *private, int retval, ipc_call_t *data)165 {166 printf("Pong\n");167 }168 169 static void test_connection_ipc(void)170 {171 int res;172 ipcarg_t result;173 int phoneid;174 175 printf("Starting connect...\n");176 res = ipc_connect_me_to(PHONE_NS, 10, 20);177 printf("Connected: %d\n", res);178 printf("pinging.\n");179 res = ipc_call_sync(res, NS_PING, 0xbeef,&result);180 printf("Retval: %d - received: %X\n", res, result);181 182 }183 184 static int ptest(void *arg)185 {186 stage = 1;187 printf("Pseudo thread stage%d.\n", stage);188 stage++;189 psthread_schedule_next();190 printf("Pseudo thread stage%d.\n", stage);191 stage++;192 psthread_schedule_next();193 printf("Pseudo thread stage%d.\n", stage);194 psthread_schedule_next();195 stage++;196 printf("Pseudo thread stage%d.\n", stage);197 psthread_schedule_next();198 printf("Pseudo thread exiting.\n");199 return 0;200 }201 202 static void test_kbd()203 {204 int res;205 ipcarg_t result;206 int phoneid;207 208 printf("Test: Starting connect...\n");209 while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {210 };211 212 printf("Test: Connected: %d\n", res);213 printf("Test: pinging.\n");214 /* while (1) {215 216 res = ipc_call_sync(phoneid, KBD_GETCHAR, 0xbeef,&result);217 // printf("Test: Retval: %d - received: %c\n", res, result);218 printf("%c", result);219 }220 */221 printf("Test: Hangin up\n");222 ipc_hangup(phoneid);223 }224 225 static void test_async_kbd()226 {227 int res;228 ipcarg_t result;229 ipc_call_t kbddata;230 int phoneid;231 aid_t aid;232 233 printf("Test: Starting connect...\n");234 while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {235 };236 237 printf("Test: Connected: %d\n", res);238 printf("Test: pinging.\n");239 240 241 while (1) {242 }243 244 printf("Test: Hangin up\n");245 ipc_hangup(phoneid);246 }247 248 static void test_pci()249 {250 int phone;251 while ((phone = ipc_connect_me_to(PHONE_NS, SERVICE_PCI, 0)) < 0)252 ;253 printf("Connected to PCI service through phone %d.\n", phone);254 }255 256 static int test_as_area_send()257 {258 char *as_area;259 int retval;260 ipcarg_t result;261 262 as_area = as_area_create((void *)(1024*1024), 16384, AS_AREA_READ | AS_AREA_WRITE);263 if (!as_area) {264 printf("Error creating as_area.\n");265 return 0;266 }267 268 memcpy(as_area, "Hello world.\n", 14);269 270 retval = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_SEND, (sysarg_t) as_area, 0, AS_AREA_READ,271 NULL, NULL, NULL);272 if (retval) {273 printf("AS_AREA_SEND failed.\n");274 return 0;275 }276 printf("Done\n");277 }278 279 static void test_fb()280 {281 int res;282 ipcarg_t result;283 int phoneid;284 int vp;285 286 // printf("Test: Starting connect...\n");287 288 while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {289 volatile int a;290 for(a=0;a<1048576;a++);291 };292 293 usleep(100000);294 vp = ipc_call_sync_3(phoneid, FB_VIEWPORT_CREATE, (200 << 16) | 300, (200 << 16) | 150,0,NULL,NULL,NULL);295 if (! ipc_call_sync(phoneid, FB_VIEWPORT_SWITCH, vp, NULL)) {296 ipc_call_sync_2(phoneid, FB_SET_STYLE, 0, 0xffffff, NULL, NULL);297 ipc_call_sync(phoneid, FB_CLEAR, 0, NULL);298 ipc_call_sync_3(phoneid, FB_PUTCHAR, 'X', 0,0, NULL, NULL, NULL);299 }300 301 ipc_hangup(phoneid);302 }303 304 static void test_time(void)305 {306 int rc;307 struct timeval tv;308 struct timezone tz;309 310 while (1) {311 rc = gettimeofday(&tv, &tz);312 printf("Rc: %d, Secs: %d, Usecs: %d\n", rc, tv.tv_sec,313 tv.tv_usec);314 }315 }316 31 317 32 static void test_console(void) … … 323 38 } 324 39 325 326 40 int main(int argc, char *argv[]) 327 41 { 328 pstid_t ptid; 329 int tid; 330 331 // version_print(); 42 version_print(); 332 43 333 44 printf("Hello\nThis is Init\n"); 334 45 335 // test_printf();336 // test_printf2();337 // test_ping();338 // test_async_ipc();339 // test_advanced_ipc();340 // test_connection_ipc();341 // test_hangup();342 // test_slam();343 // test_as_area_send();344 // test_pci();345 // test_kbd();346 // test_time();347 // test_async_kbd();348 // test_fb();349 46 test_console(); 350 47 351 48 printf("\nBye.\n"); 352 49 353 /*354 printf("Userspace task, taskid=%llX\n", task_get_id());355 356 futex_initialize(&ftx, 1);357 if (futex_down(&ftx) < 0)358 printf("Futex failed.\n");359 if (futex_up(&ftx) < 0)360 printf("Futex failed.\n");361 362 if (futex_down(&ftx) < 0)363 printf("Futex failed.\n");364 365 if ((tid = thread_create(utest, NULL, "utest")) != -1) {366 printf("Created thread tid=%d\n", tid);367 }368 369 if ((tid = thread_create(utest, NULL, "utest")) != -1) {370 printf("Created thread tid=%d\n", tid);371 }372 373 int i;374 375 for (i = 0; i < 50000000; i++)376 ;377 378 if (futex_up(&ftx) < 0)379 printf("Futex failed.\n");380 381 382 printf("Creating pseudo thread.\n");383 stage = 1;384 ptid = psthread_create(ptest, NULL);385 printf("Main thread stage%d.\n", stage);386 stage++;387 psthread_schedule_next();;388 printf("Main thread stage%d.\n", stage);389 stage++;390 psthread_schedule_next();;391 printf("Main thread stage%d.\n", stage);392 393 psthread_join(ptid);394 395 printf("Main thread exiting.\n");396 */397 398 50 return 0; 399 51 } -
libc/include/ipc/ns.h
r53daee3 r2408969 30 30 #define __LIBIPC__NS_H__ 31 31 32 #define NS_PING 102433 #define NS_PING_SVC 102534 #define NS_HANGUP 102635 36 32 #endif -
libc/include/ipc/services.h
r53daee3 r2408969 36 36 37 37 #define SERVICE_PCI 1 38 #define SERVICE_FRAME_BUFFER 2 39 #define SERVICE_KEYBOARD 3 40 #define SERVICE_VIDEO 4 41 #define SERVICE_CONSOLE 5 38 #define SERVICE_KEYBOARD 2 39 #define SERVICE_VIDEO 3 40 #define SERVICE_CONSOLE 4 42 41 43 42 /* Memory area to be received from NS */ -
ns/ns.c
r53daee3 r2408969 102 102 ipcarg_t retval, arg1, arg2; 103 103 104 // printf("%s: Naming service started.\n", NAME);105 106 104 if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3, &ns_hash_table_ops)) { 107 // printf("%s: cannot create hash table\n", NAME);108 105 return ENOMEM; 109 106 } … … 111 108 while (1) { 112 109 callid = ipc_wait_for_call(&call); 113 // printf("NS: Call in_phone_hash=%lX...", call.in_phone_hash);114 110 switch (IPC_GET_METHOD(call)) { 115 case IPC_M_AS_AREA_SEND:116 as_area = (char *)IPC_GET_ARG1(call);117 // printf("Received as_area: %P, size:%d\n", as_area, IPC_GET_ARG2(call));118 retval = ipc_answer_fast(callid, 0,(sysarg_t)(1024*1024), 0);119 if (!retval) {120 // printf("Reading shared memory...");121 // printf("Text: %s", as_area);122 } else123 // printf("Failed answer: %d\n", retval);124 continue;125 111 case IPC_M_AS_AREA_RECV: 126 112 get_realtime_as(callid, &call); 127 113 continue; 128 case IPC_M_INTERRUPT:129 break;130 114 case IPC_M_PHONE_HUNGUP: 131 115 retval = 0; … … 136 120 */ 137 121 retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG3(call), &call); 138 ping_phone = IPC_GET_ARG3(call);139 122 break; 140 123 case IPC_M_CONNECT_ME_TO: … … 144 127 retval = connect_to_service(IPC_GET_ARG1(call), &call, callid); 145 128 break; 146 case NS_HANGUP:147 // printf("Closing connection.\n");148 retval = EHANGUP;149 break;150 case NS_PING:151 // printf("Ping...%P %P\n", IPC_GET_ARG1(call),152 // IPC_GET_ARG2(call));153 retval = 0;154 arg1 = 0xdead;155 arg2 = 0xbeef;156 break;157 case NS_PING_SVC:158 // printf("NS:Pinging service %d\n", ping_phone);159 ipc_call_sync(ping_phone, NS_PING, 0xbeef, 0);160 // printf("NS:Got pong\n");161 break;162 129 default: 163 // printf("Unknown method: %zd\n", IPC_GET_METHOD(call));164 130 retval = ENOENT; 165 131 break; 166 132 } 167 133 if (! (callid & IPC_CALLID_NOTIFICATION)) { 168 // printf("Answering.\n");169 134 ipc_answer_fast(callid, retval, arg1, arg2); 170 135 } … … 185 150 hashed_service_t *hs; 186 151 187 // printf("Registering service %d on phone %d...", service, phone);188 189 152 if (hash_table_find(&ns_hash_table, keys)) { 190 // printf("Service %d already registered.\n", service);191 153 return EEXISTS; 192 154 } … … 194 156 hs = (hashed_service_t *) malloc(sizeof(hashed_service_t)); 195 157 if (!hs) { 196 // printf("Failed to register service %d.\n", service);197 158 return ENOMEM; 198 159 } … … 223 184 hlp = hash_table_find(&ns_hash_table, keys); 224 185 if (!hlp) { 225 // printf("Service %d not registered.\n", service);226 186 return ENOENT; 227 187 } 228 188 hs = hash_table_get_instance(hlp, hashed_service_t, link); 229 // printf("Connecting in_phone_hash=%lX to service at phone %d...", call->in_phone_hash, hs->phone);230 189 return ipc_forward_fast(callid, hs->phone, 0, 0); 231 190 }
Note:
See TracChangeset
for help on using the changeset viewer.