- Timestamp:
- 2008-07-08T16:05:45Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f93f168
- Parents:
- b7f9087
- Location:
- uspace
- Files:
-
- 35 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
rb7f9087 rc98e6ee 38 38 lib/softfloat \ 39 39 srv/ns \ 40 srv/loader \ 40 41 srv/fb \ 41 42 srv/kbd \ … … 48 49 app/tetris \ 49 50 app/tester \ 51 app/cli \ 50 52 app/klog \ 51 53 app/init -
uspace/app/init/init.c
rb7f9087 rc98e6ee 46 46 #include "version.h" 47 47 48 #define BUF_SIZE 15000049 50 static char *buf;51 52 48 static void console_wait(void) 53 49 { … … 83 79 static void spawn(char *fname) 84 80 { 81 char *argv[2]; 82 85 83 printf(NAME ": Spawning %s\n", fname); 86 87 int fd = open(fname, O_RDONLY); 88 if (fd >= 0) { 89 90 ssize_t rd; 91 size_t len = 0; 92 93 // FIXME: cannot do long reads yet 94 do { 95 rd = read(fd, buf + len, 1024); 96 if (rd > 0) 97 len += rd; 98 99 } while (rd > 0); 100 101 if (len > 0) { 102 task_spawn(buf, len); 103 sleep(1); // FIXME 104 } 105 106 close(fd); 84 85 argv[0] = fname; 86 argv[1] = NULL; 87 88 if (task_spawn(fname, argv) != 0) { 89 /* Success */ 90 sleep(1); 107 91 } 108 92 } … … 118 102 } 119 103 120 buf = malloc(BUF_SIZE);121 122 104 // FIXME: spawn("/sbin/pci"); 123 105 spawn("/sbin/fb"); … … 130 112 spawn("/sbin/fat"); 131 113 spawn("/sbin/tetris"); 114 spawn("/sbin/cli"); 132 115 // FIXME: spawn("/sbin/tester"); 133 116 spawn("/sbin/klog"); 134 117 135 free(buf);136 118 return 0; 137 119 } -
uspace/app/tester/tester.c
rb7f9087 rc98e6ee 108 108 } 109 109 110 int main( void)110 int main(int argc, char **argv) 111 111 { 112 printf("Number of arguments: %d\n", argc); 113 if (argv) { 114 printf("Arguments:"); 115 while (*argv) { 116 printf(" '%s'", *argv++); 117 } 118 printf("\n"); 119 } 120 112 121 while (1) { 113 122 char c; -
uspace/lib/libc/Makefile
rb7f9087 rc98e6ee 52 52 generic/string.c \ 53 53 generic/fibril.c \ 54 generic/pcb.c \ 55 generic/smc.c \ 54 56 generic/thread.c \ 55 57 generic/tls.c \ -
uspace/lib/libc/arch/amd64/src/entry.s
rb7f9087 rc98e6ee 35 35 ## User-space task entry point 36 36 # 37 # %rdi contains the PCB pointer 37 38 # 38 39 __entry: 40 # %rdi was deliberately chosen as the first argument is also in %rdi 41 # Pass PCB pointer to __main (no operation) 39 42 call __main 40 call main 43 41 44 call __exit -
uspace/lib/libc/arch/arm32/src/entry.s
rb7f9087 rc98e6ee 35 35 ## User-space task entry point 36 36 # 37 # r1 contains the PCB pointer 37 38 # 38 39 __entry: 40 # Pass pcb_ptr to __main as the first argument (in r0) 41 mov r0, r1 39 42 bl __main 40 bl main 43 41 44 bl __exit -
uspace/lib/libc/arch/ia32/src/entry.s
rb7f9087 rc98e6ee 35 35 ## User-space task entry point 36 36 # 37 # %ebx contains the PCB pointer 37 38 # 38 39 __entry: … … 42 43 mov %ax, %fs 43 44 # Do not set %gs, it contains descriptor that can see TLS 44 45 46 # Pass the PCB pointer to __main as the first argument 47 pushl %ebx 45 48 call __main 46 call main 49 47 50 call __exit -
uspace/lib/libc/arch/ia64/src/entry.s
rb7f9087 rc98e6ee 35 35 ## User-space task entry point 36 36 # 37 # r2 contains the PCB pointer 37 38 # 38 39 __entry: 39 40 alloc loc0 = ar.pfs, 0, 1, 2, 0 40 mov r1 = _gp 41 mov r1 = _gp 42 43 # Pass PCB pointer as the first argument to __main 44 mov out0 = r2 41 45 br.call.sptk.many b0 = __main 42 46 0: 43 br.call.sptk.many b0 = main44 1:45 47 br.call.sptk.many b0 = __exit -
uspace/lib/libc/arch/mips32/src/entry.s
rb7f9087 rc98e6ee 36 36 ## User-space task entry point 37 37 # 38 # $a0 ($4) contains the PCB pointer 38 39 # 39 40 .ent __entry … … 41 42 .frame $sp, 32, $31 42 43 .cpload $25 43 44 44 45 45 # Mips o32 may store its arguments on stack, make space (16 bytes), 46 46 # so that it could work with -O0 … … 49 49 addiu $sp, -32 50 50 .cprestore 16 # Allow PIC code 51 51 52 # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already 53 # in $a0. As the first argument is passed in $a0, no operation 54 # is needed. 55 52 56 jal __main 53 nop54 55 jal main56 57 nop 57 58 -
uspace/lib/libc/arch/ppc32/src/entry.s
rb7f9087 rc98e6ee 35 35 ## User-space task entry point 36 36 # 37 # r3 contains the PCB pointer 37 38 # 38 39 __entry: 40 # Pass the PCB pointer to __main() as the first argument. 41 # Since the first argument is passed in r3, no operation is needed. 39 42 bl __main 40 bl main 43 41 44 bl __exit -
uspace/lib/libc/arch/ppc64/src/entry.s
rb7f9087 rc98e6ee 32 32 33 33 .globl __entry 34 .globl __entry_driver35 34 36 35 ## User-space task entry point … … 39 38 __entry: 40 39 bl __main 41 bl __io_init42 bl main43 40 bl __exit 44 45 __entry_driver:46 bl __main47 bl main48 bl __exit -
uspace/lib/libc/arch/sparc64/src/entry.s
rb7f9087 rc98e6ee 35 35 ## User-space task entry point 36 36 # 37 # %o0 contains uarg 38 # %o1 contains pcb_ptr 37 39 # 38 40 __entry: 41 # Pass pcb_ptr as the first argument to __main() 42 mov %o1, %o0 39 43 sethi %hi(_gp), %l7 40 44 call __main 41 45 or %l7, %lo(_gp), %l7 42 call main 43 nop 46 44 47 call __exit 45 48 nop -
uspace/lib/libc/generic/as.c
rb7f9087 rc98e6ee 84 84 { 85 85 return __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t ) address); 86 } 87 88 /** Change address-space area flags. 89 * 90 * @param address Virtual address pointing into the address space area being 91 * modified. 92 * @param flags New flags describing type of the area. 93 * 94 * @return Zero on success or a code from @ref errno.h on failure. 95 */ 96 int as_area_change_flags(void *address, int flags) 97 { 98 return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address, 99 (sysarg_t) flags); 86 100 } 87 101 -
uspace/lib/libc/generic/io/stream.c
rb7f9087 rc98e6ee 97 97 } 98 98 99 void close_console(void) 100 { 101 if (console_phone >= 0) { 102 if (ipc_hangup(console_phone) == 0) { 103 console_phone = -1; 104 } 105 } 106 } 107 99 108 void klog_update(void) 100 109 { -
uspace/lib/libc/generic/libc.c
rb7f9087 rc98e6ee 49 49 #include <async.h> 50 50 #include <as.h> 51 #include <loader/pcb.h> 51 52 52 53 extern char _heap; 54 extern int main(int argc, char *argv[]); 53 55 54 56 void _exit(int status) … … 57 59 } 58 60 59 void __main(void )61 void __main(void *pcb_ptr) 60 62 { 61 63 fibril_t *f; 64 int argc; 65 char **argv; 62 66 63 67 (void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ); … … 67 71 68 72 open_console(); 73 74 /* Save the PCB pointer */ 75 __pcb = (pcb_t *)pcb_ptr; 76 77 if (__pcb == NULL) { 78 argc = 0; 79 argv = NULL; 80 } else { 81 argc = __pcb->argc; 82 argv = __pcb->argv; 83 } 84 85 main(argc, argv); 69 86 } 70 87 -
uspace/lib/libc/generic/task.c
rb7f9087 rc98e6ee 1 1 /* 2 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2008 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 34 35 35 36 #include <task.h> 37 #include <ipc/ipc.h> 38 #include <ipc/loader.h> 36 39 #include <libc.h> 40 #include <string.h> 41 #include <stdlib.h> 42 #include <async.h> 43 #include <errno.h> 37 44 38 45 task_id_t task_get_id(void) … … 45 52 } 46 53 47 int task_spawn(void *image, size_t size)54 static int task_spawn_loader(void) 48 55 { 49 return __SYSCALL2(SYS_TASK_SPAWN, (sysarg_t) image, (sysarg_t) size); 56 int phone_id, rc; 57 58 rc = __SYSCALL1(SYS_PROGRAM_SPAWN_LOADER, (sysarg_t) &phone_id); 59 if (rc != 0) 60 return rc; 61 62 return phone_id; 63 } 64 65 static int loader_set_args(int phone_id, const char *argv[]) 66 { 67 aid_t req; 68 ipc_call_t answer; 69 ipcarg_t rc; 70 71 const char **ap; 72 char *dp; 73 char *arg_buf; 74 size_t buffer_size; 75 size_t len; 76 77 /* 78 * Serialize the arguments into a single array. First 79 * compute size of the buffer needed. 80 */ 81 ap = argv; 82 buffer_size = 0; 83 while (*ap != NULL) { 84 buffer_size += strlen(*ap) + 1; 85 ++ap; 86 } 87 88 arg_buf = malloc(buffer_size); 89 if (arg_buf == NULL) return ENOMEM; 90 91 /* Now fill the buffer with null-terminated argument strings */ 92 ap = argv; 93 dp = arg_buf; 94 while (*ap != NULL) { 95 strcpy(dp, *ap); 96 dp += strlen(*ap) + 1; 97 98 ++ap; 99 } 100 101 /* Send serialized arguments to the loader */ 102 103 req = async_send_0(phone_id, LOADER_SET_ARGS, &answer); 104 rc = ipc_data_write_start(phone_id, (void *)arg_buf, buffer_size); 105 if (rc != EOK) { 106 async_wait_for(req, NULL); 107 return rc; 108 } 109 110 async_wait_for(req, &rc); 111 if (rc != EOK) return rc; 112 113 /* Free temporary buffer */ 114 free(arg_buf); 115 116 return EOK; 117 } 118 119 /** Create a new task by running an executable from VFS. 120 * 121 * @param path pathname of the binary to execute 122 * @param argv command-line arguments 123 * @return ID of the newly created task or zero on error. 124 */ 125 task_id_t task_spawn(const char *path, const char *argv[]) 126 { 127 int phone_id; 128 ipc_call_t answer; 129 aid_t req; 130 int rc; 131 ipcarg_t retval; 132 133 /* Spawn a program loader */ 134 phone_id = task_spawn_loader(); 135 if (phone_id < 0) return 0; 136 137 /* 138 * Say hello so that the loader knows the incoming connection's 139 * phone hash. 140 */ 141 rc = async_req_0_0(phone_id, LOADER_HELLO); 142 if (rc != EOK) return 0; 143 144 /* Send program pathname */ 145 req = async_send_0(phone_id, LOADER_SET_PATHNAME, &answer); 146 rc = ipc_data_write_start(phone_id, (void *)path, strlen(path)); 147 if (rc != EOK) { 148 async_wait_for(req, NULL); 149 return 1; 150 } 151 152 async_wait_for(req, &retval); 153 if (retval != EOK) goto error; 154 155 /* Send arguments */ 156 rc = loader_set_args(phone_id, argv); 157 if (rc != EOK) goto error; 158 159 /* Request loader to start the program */ 160 rc = async_req_0_0(phone_id, LOADER_RUN); 161 if (rc != EOK) goto error; 162 163 /* Success */ 164 ipc_hangup(phone_id); 165 return 1; 166 167 /* Error exit */ 168 error: 169 ipc_hangup(phone_id); 170 return 0; 50 171 } 51 172 -
uspace/lib/libc/include/as.h
rb7f9087 rc98e6ee 43 43 extern void *as_area_create(void *address, size_t size, int flags); 44 44 extern int as_area_resize(void *address, size_t size, int flags); 45 extern int as_area_change_flags(void *address, int flags); 45 46 extern int as_area_destroy(void *address); 46 47 extern void *set_maxheapsize(size_t mhs); -
uspace/lib/libc/include/io/stream.h
rb7f9087 rc98e6ee 41 41 42 42 extern void open_console(void); 43 extern void close_console(void); 43 44 extern void klog_update(void); 44 45 -
uspace/lib/libc/include/libc.h
rb7f9087 rc98e6ee 49 49 __syscall(p1, p2, p3, p4, p5, p6,id) 50 50 51 extern void __main(void );51 extern void __main(void *pcb_ptr); 52 52 extern void __exit(void); 53 53 -
uspace/lib/libc/include/task.h
rb7f9087 rc98e6ee 41 41 42 42 extern task_id_t task_get_id(void); 43 extern int task_spawn(void *image, size_t size);43 extern task_id_t task_spawn(const char *path, const char *argv[]); 44 44 45 45 #endif
Note:
See TracChangeset
for help on using the changeset viewer.