Changeset 2f57690 in mainline
- Timestamp:
- 2009-03-03T12:41:39Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- deca67b
- Parents:
- 561db3f
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/boot/cboot.c
r561db3f r2f57690 47 47 /** Extract command name from the multiboot module command line. 48 48 * 49 * @param buf Destination buffer (will always null-terminate). 50 * @param n Size of destination buffer. 51 * @param cmd_line Input string (the command line). 49 * @param buf Destination buffer (will always null-terminate). 50 * @param n Size of destination buffer. 51 * @param cmd_line Input string (the command line). 52 * 52 53 */ 53 54 static void extract_command(char *buf, size_t n, const char *cmd_line) … … 55 56 const char *start, *end, *cp; 56 57 size_t max_len; 57 58 58 59 /* Find the first space. */ 59 60 end = strchr(cmd_line, ' '); 60 if (end == NULL) end = cmd_line + strlen(cmd_line); 61 61 if (end == NULL) 62 end = cmd_line + strlen(cmd_line); 63 62 64 /* 63 65 * Find last occurence of '/' before 'end'. If found, place start at … … 73 75 --cp; 74 76 } 75 77 76 78 /* Copy the command and null-terminate the string. */ 77 79 max_len = min(n - 1, (size_t) (end - start)); … … 81 83 82 84 /** C part of ia32 boot sequence. 83 * @param signature Should contain the multiboot signature. 84 * @param mi Pointer to the multiboot information structure. 85 * 86 * @param signature Should contain the multiboot signature. 87 * @param mi Pointer to the multiboot information structure. 85 88 */ 86 89 void ia32_cboot(uint32_t signature, const mb_info_t *mi) … … 89 92 mb_mod_t *mods; 90 93 uint32_t i; 91 92 if (signature == MULTIBOOT_LOADER_MAGIC) {94 95 if (signature == MULTIBOOT_LOADER_MAGIC) 93 96 flags = mi->flags; 94 }else {97 else { 95 98 /* No multiboot info available. */ 96 99 flags = 0; 97 100 } 98 101 99 102 /* Copy module information. */ 100 103 101 104 if ((flags & MBINFO_FLAGS_MODS) != 0) { 102 105 init.cnt = mi->mods_count; 103 106 mods = mi->mods_addr; 104 107 105 108 for (i = 0; i < init.cnt; i++) { 106 109 init.tasks[i].addr = mods[i].start + 0x80000000; 107 110 init.tasks[i].size = mods[i].end - mods[i].start; 108 111 109 112 /* Copy command line, if available. */ 110 113 if (mods[i].string) { … … 112 115 CONFIG_TASK_NAME_BUFLEN, 113 116 mods[i].string); 114 } else {117 } else 115 118 init.tasks[i].name[0] = '\0'; 116 }117 119 } 118 } else {120 } else 119 121 init.cnt = 0; 120 } 121 122 122 123 /* Copy memory map. */ 123 124 124 125 int32_t mmap_length; 125 126 mb_mmap_t *mme; 126 127 uint32_t size; 127 128 128 129 if ((flags & MBINFO_FLAGS_MMAP) != 0) { 129 130 mmap_length = mi->mmap_length; 130 131 mme = mi->mmap_addr; 131 132 e820counter = 0; 132 133 133 134 i = 0; 134 135 while (mmap_length > 0) { 135 136 e820table[i++] = mme->mm_info; 136 137 137 138 /* Compute address of next structure. */ 138 139 size = sizeof(mme->size) + mme->size; … … 140 141 mmap_length -= size; 141 142 } 142 143 143 144 e820counter = i; 144 } else {145 } else 145 146 e820counter = 0; 146 } 147 147 148 148 #ifdef CONFIG_SMP 149 149 /* Copy AP bootstrap routines below 1 MB. */ … … 151 151 (size_t) &_hardcoded_unmapped_size); 152 152 #endif 153 153 154 154 main_bsp(); 155 155 } -
kernel/generic/include/string.h
r561db3f r2f57690 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ -
kernel/generic/src/lib/string.c
r561db3f r2f57690 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Miscellaneous functions. 36 36 */ 37 37 … … 48 48 * 49 49 * @return Number of characters in str. 50 * 50 51 */ 51 52 size_t strlen(const char *str) … … 53 54 int i; 54 55 55 for (i = 0; str[i]; i++) 56 ; 56 for (i = 0; str[i]; i++); 57 57 58 58 return i; … … 81 81 if (*src == *dst) 82 82 return 0; 83 83 84 if (!*src) 84 85 return -1; 86 85 87 return 1; 86 88 } … … 108 110 if (*src < *dst) 109 111 return -1; 112 110 113 if (*src > *dst) 111 114 return 1; 112 115 } 116 113 117 if (i == len || *src == *dst) 114 118 return 0; 119 115 120 if (!*src) 116 121 return -1; 122 117 123 return 1; 118 124 } … … 126 132 * last copied character. 127 133 * 128 * @param src Source string.134 * @param src Source string. 129 135 * @param dest Destination buffer. 130 * @param len Size of destination buffer. 136 * @param len Size of destination buffer. 137 * 131 138 */ 132 139 void strncpy(char *dest, const char *src, size_t len) 133 140 { 134 141 unsigned int i; 135 142 136 143 for (i = 0; i < len; i++) { 137 144 if (!(dest[i] = src[i])) 138 145 return; 139 146 } 140 147 141 148 dest[i - 1] = '\0'; 142 149 } … … 144 151 /** Find first occurence of character in string. 145 152 * 146 * @param s 147 * @param i 153 * @param s String to search. 154 * @param i Character to look for. 148 155 * 149 * @return 156 * @return Pointer to character in @a s or NULL if not found. 150 157 */ 151 158 extern char *strchr(const char *s, int i) 152 159 { 153 160 while (*s != '\0') { 154 if (*s == i) return (char *) s; 161 if (*s == i) 162 return (char *) s; 155 163 ++s; 156 164 } 157 165 158 166 return NULL; 159 167 } -
kernel/generic/src/main/kinit.c
r561db3f r2f57690 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Kernel initialization thread. 36 36 * 37 37 * This file contains kinit kernel thread which carries out … … 81 81 #endif 82 82 83 #define BOOT_PREFIX 84 #define BOOT_PREFIX_LEN 83 #define BOOT_PREFIX "boot:" 84 #define BOOT_PREFIX_LEN 5 85 85 86 86 /** Kernel initialization thread. … … 98 98 thread_t *thread; 99 99 #endif 100 100 101 101 /* 102 102 * Detach kinit as nobody will call thread_join_timeout() on it. 103 103 */ 104 104 thread_detach(THREAD); 105 105 106 106 interrupts_disable(); 107 108 #ifdef CONFIG_SMP 107 108 #ifdef CONFIG_SMP 109 109 if (config.cpu_count > 1) { 110 110 waitq_initialize(&ap_completion_wq); … … 126 126 thread_detach(thread); 127 127 } 128 #endif /* CONFIG_SMP */ 129 130 #ifdef CONFIG_SMP 128 131 129 if (config.cpu_count > 1) { 132 130 count_t i; … … 144 142 } else 145 143 printf("Unable to create kcpulb thread for cpu" PRIc "\n", i); 146 147 144 } 148 145 } … … 153 150 */ 154 151 arch_post_smp_init(); 155 152 156 153 #ifdef CONFIG_KCONSOLE 157 154 if (stdin) { … … 180 177 continue; 181 178 } 182 179 183 180 /* 184 181 * Construct task name from the 'boot:' prefix and the 185 182 * name stored in the init structure (if any). 186 183 */ 187 188 char namebuf[TASK_NAME_BUFLEN], *name; 189 184 185 char namebuf[TASK_NAME_BUFLEN]; 186 char *name; 187 190 188 name = init.tasks[i].name; 191 if (name[0] == '\0') name = "<unknown>"; 192 189 if (name[0] == '\0') 190 name = "<unknown>"; 191 193 192 ASSERT(TASK_NAME_BUFLEN >= BOOT_PREFIX_LEN); 194 193 strncpy(namebuf, BOOT_PREFIX, TASK_NAME_BUFLEN); … … 234 233 } 235 234 } 236 235 237 236 #ifdef CONFIG_KCONSOLE 238 237 if (!stdin) { -
uspace/srv/loader/main.c
r561db3f r2f57690 28 28 29 29 /** @addtogroup loader 30 * @brief 30 * @brief Loads and runs programs from VFS. 31 31 * @{ 32 */ 32 */ 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Loads and runs programs from VFS. 36 36 * 37 37 * The program loader is a special init binary. Its image is used … … 89 89 task_id_t task_id; 90 90 size_t len; 91 91 92 92 task_id = task_get_id(); 93 93 94 94 if (!ipc_data_read_receive(&callid, &len)) { 95 95 ipc_answer_0(callid, EINVAL); … … 97 97 return; 98 98 } 99 100 if (len > sizeof(task_id)) len = sizeof(task_id); 101 99 100 if (len > sizeof(task_id)) 101 len = sizeof(task_id); 102 102 103 ipc_data_read_finalize(callid, &task_id, len); 103 104 ipc_answer_0(rid, EOK); … … 115 116 size_t len; 116 117 char *name_buf; 117 118 118 119 if (!ipc_data_write_receive(&callid, &len)) { 119 120 ipc_answer_0(callid, EINVAL); … … 121 122 return; 122 123 } 123 124 124 125 name_buf = malloc(len + 1); 125 126 if (!name_buf) { … … 128 129 return; 129 130 } 130 131 131 132 ipc_data_write_finalize(callid, name_buf, len); 132 133 ipc_answer_0(rid, EOK); 133 134 134 135 if (pathname != NULL) { 135 136 free(pathname); 136 137 pathname = NULL; 137 138 } 138 139 139 140 name_buf[len] = '\0'; 140 141 pathname = name_buf; … … 152 153 char *p; 153 154 int n; 154 155 155 156 if (!ipc_data_write_receive(&callid, &buf_len)) { 156 157 ipc_answer_0(callid, EINVAL); … … 158 159 return; 159 160 } 160 161 161 162 if (arg_buf != NULL) { 162 163 free(arg_buf); 163 164 arg_buf = NULL; 164 165 } 165 166 166 167 if (argv != NULL) { 167 168 free(argv); 168 169 argv = NULL; 169 170 } 170 171 171 172 arg_buf = malloc(buf_len + 1); 172 173 if (!arg_buf) { … … 175 176 return; 176 177 } 177 178 178 179 ipc_data_write_finalize(callid, arg_buf, buf_len); 179 180 ipc_answer_0(rid, EOK); 180 181 181 182 arg_buf[buf_len] = '\0'; 182 183 183 184 /* 184 185 * Count number of arguments … … 191 192 ++n; 192 193 } 193 194 194 195 /* Allocate argv */ 195 196 argv = malloc((n + 1) * sizeof(char *)); 196 197 197 198 if (argv == NULL) { 198 199 free(arg_buf); … … 201 202 return; 202 203 } 203 204 204 205 /* 205 206 * Fill argv with argument pointers … … 209 210 while (p < arg_buf + buf_len) { 210 211 argv[n] = p; 211 212 212 213 arg_len = strlen(p); 213 214 p = p + arg_len + 1; 214 215 ++n; 215 216 } 216 217 217 218 argc = n; 218 219 argv[n] = NULL; … … 228 229 { 229 230 int rc; 230 231 231 232 rc = elf_load_file(pathname, 0, &prog_info); 232 233 if (rc < 0) { … … 235 236 return 1; 236 237 } 237 238 238 239 elf_create_pcb(&prog_info, &pcb); 239 240 240 241 pcb.argc = argc; 241 242 pcb.argv = argv; 242 243 243 244 if (prog_info.interp == NULL) { 244 245 /* Statically linked program */ … … 247 248 return 0; 248 249 } 249 250 250 251 rc = elf_load_file(prog_info.interp, 0, &interp_info); 251 252 if (rc < 0) { … … 255 256 return 1; 256 257 } 257 258 258 259 is_dyn_linked = true; 259 260 ipc_answer_0(rid, EOK); 260 261 261 262 return 0; 262 263 } … … 272 273 { 273 274 const char *cp; 274 275 275 276 /* Set the task name. */ 276 277 cp = strrchr(pathname, '/'); 277 278 cp = (cp == NULL) ? pathname : (cp + 1); 278 279 task_set_name(cp); 279 280 280 281 if (is_dyn_linked == true) { 281 282 /* Dynamically linked program */ … … 283 284 DPRINTF("Entry point: 0x%lx\n", interp_info.entry); 284 285 close_console(); 285 286 286 287 ipc_answer_0(rid, EOK); 287 288 elf_run(&interp_info, &pcb); 288 289 289 } else { 290 290 /* Statically linked program */ … … 307 307 ipc_call_t call; 308 308 int retval; 309 309 310 310 /* Already have a connection? */ 311 311 if (connected) { … … 313 313 return; 314 314 } 315 315 316 316 connected = true; 317 317 318 318 /* Accept the connection */ 319 319 ipc_answer_0(iid, EOK); 320 320 321 321 /* Ignore parameters, the connection is already open */ 322 (void)iid; (void)icall; 323 322 (void) iid; 323 (void) icall; 324 324 325 while (1) { 325 326 callid = async_get_call(&call); 326 327 327 328 switch (IPC_GET_METHOD(call)) { 328 329 case IPC_M_PHONE_HUNGUP: … … 361 362 { 362 363 ipcarg_t phonead; 363 364 364 365 connected = false; 365 366 366 367 /* Set a handler of incomming connections. */ 367 368 async_set_client_connection(loader_connection); 368 369 369 370 /* Register at naming service. */ 370 371 if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, &phonead) != 0) … … 372 373 373 374 async_manager(); 374 375 375 376 /* Never reached */ 376 377 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.