/trunk/kernel/generic/include/string.h |
---|
26,7 → 26,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
/trunk/kernel/generic/src/main/kinit.c |
---|
32,7 → 32,7 |
/** |
* @file |
* @brief Kernel initialization thread. |
* @brief Kernel initialization thread. |
* |
* This file contains kinit kernel thread which carries out |
* high level system initialization. |
80,8 → 80,8 |
static char alive[ALIVE_CHARS] = "-\\|/"; |
#endif |
#define BOOT_PREFIX "boot:" |
#define BOOT_PREFIX_LEN 5 |
#define BOOT_PREFIX "boot:" |
#define BOOT_PREFIX_LEN 5 |
/** Kernel initialization thread. |
* |
97,15 → 97,15 |
#if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE) |
thread_t *thread; |
#endif |
/* |
* Detach kinit as nobody will call thread_join_timeout() on it. |
*/ |
thread_detach(THREAD); |
interrupts_disable(); |
#ifdef CONFIG_SMP |
#ifdef CONFIG_SMP |
if (config.cpu_count > 1) { |
waitq_initialize(&ap_completion_wq); |
/* |
125,9 → 125,7 |
thread_join(thread); |
thread_detach(thread); |
} |
#endif /* CONFIG_SMP */ |
#ifdef CONFIG_SMP |
if (config.cpu_count > 1) { |
count_t i; |
143,7 → 141,6 |
thread_ready(thread); |
} else |
printf("Unable to create kcpulb thread for cpu" PRIc "\n", i); |
} |
} |
#endif /* CONFIG_SMP */ |
152,7 → 149,7 |
* At this point SMP, if present, is configured. |
*/ |
arch_post_smp_init(); |
#ifdef CONFIG_KCONSOLE |
if (stdin) { |
/* |
179,17 → 176,19 |
printf("init[%" PRIc "].addr is not frame aligned\n", i); |
continue; |
} |
/* |
* Construct task name from the 'boot:' prefix and the |
* name stored in the init structure (if any). |
*/ |
char namebuf[TASK_NAME_BUFLEN], *name; |
char namebuf[TASK_NAME_BUFLEN]; |
char *name; |
name = init.tasks[i].name; |
if (name[0] == '\0') name = "<unknown>"; |
if (name[0] == '\0') |
name = "<unknown>"; |
ASSERT(TASK_NAME_BUFLEN >= BOOT_PREFIX_LEN); |
strncpy(namebuf, BOOT_PREFIX, TASK_NAME_BUFLEN); |
strncpy(namebuf + BOOT_PREFIX_LEN, name, |
233,7 → 232,7 |
thread_usleep(10000); |
} |
} |
#ifdef CONFIG_KCONSOLE |
if (!stdin) { |
thread_sleep(10); |
/trunk/kernel/generic/src/lib/string.c |
---|
26,13 → 26,13 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
/** @addtogroup generic |
* @{ |
*/ |
/** |
* @file |
* @brief Miscellaneous functions. |
* @brief Miscellaneous functions. |
*/ |
#include <string.h> |
47,13 → 47,13 |
* @param str NULL terminated string. |
* |
* @return Number of characters in str. |
* |
*/ |
size_t strlen(const char *str) |
{ |
int i; |
for (i = 0; str[i]; i++) |
; |
for (i = 0; str[i]; i++); |
return i; |
} |
80,8 → 80,10 |
} |
if (*src == *dst) |
return 0; |
if (!*src) |
return -1; |
return 1; |
} |
107,13 → 109,17 |
for (i = 0; (*src) && (*dst) && (i < len); src++, dst++, i++) { |
if (*src < *dst) |
return -1; |
if (*src > *dst) |
return 1; |
} |
if (i == len || *src == *dst) |
return 0; |
if (!*src) |
return -1; |
return 1; |
} |
125,36 → 131,38 |
* If 'src' is shorter than 'len', '\0' is inserted behind the |
* last copied character. |
* |
* @param src Source string. |
* @param src Source string. |
* @param dest Destination buffer. |
* @param len Size of destination buffer. |
* @param len Size of destination buffer. |
* |
*/ |
void strncpy(char *dest, const char *src, size_t len) |
{ |
unsigned int i; |
for (i = 0; i < len; i++) { |
if (!(dest[i] = src[i])) |
return; |
} |
dest[i - 1] = '\0'; |
} |
/** Find first occurence of character in string. |
* |
* @param s String to search. |
* @param i Character to look for. |
* @param s String to search. |
* @param i Character to look for. |
* |
* @return Pointer to character in @a s or NULL if not found. |
* @return Pointer to character in @a s or NULL if not found. |
*/ |
extern char *strchr(const char *s, int i) |
{ |
while (*s != '\0') { |
if (*s == i) return (char *) s; |
if (*s == i) |
return (char *) s; |
++s; |
} |
return NULL; |
} |
/trunk/kernel/arch/ia32/src/boot/cboot.c |
---|
46,19 → 46,21 |
/** Extract command name from the multiboot module command line. |
* |
* @param buf Destination buffer (will always null-terminate). |
* @param n Size of destination buffer. |
* @param cmd_line Input string (the command line). |
* @param buf Destination buffer (will always null-terminate). |
* @param n Size of destination buffer. |
* @param cmd_line Input string (the command line). |
* |
*/ |
static void extract_command(char *buf, size_t n, const char *cmd_line) |
{ |
const char *start, *end, *cp; |
size_t max_len; |
/* Find the first space. */ |
end = strchr(cmd_line, ' '); |
if (end == NULL) end = cmd_line + strlen(cmd_line); |
if (end == NULL) |
end = cmd_line + strlen(cmd_line); |
/* |
* Find last occurence of '/' before 'end'. If found, place start at |
* next character. Otherwise, place start at beginning of buffer. |
72,7 → 74,7 |
} |
--cp; |
} |
/* Copy the command and null-terminate the string. */ |
max_len = min(n - 1, (size_t) (end - start)); |
strncpy(buf, start, max_len + 1); |
80,8 → 82,9 |
} |
/** C part of ia32 boot sequence. |
* @param signature Should contain the multiboot signature. |
* @param mi Pointer to the multiboot information structure. |
* |
* @param signature Should contain the multiboot signature. |
* @param mi Pointer to the multiboot information structure. |
*/ |
void ia32_cboot(uint32_t signature, const mb_info_t *mi) |
{ |
88,69 → 91,66 |
uint32_t flags; |
mb_mod_t *mods; |
uint32_t i; |
if (signature == MULTIBOOT_LOADER_MAGIC) { |
if (signature == MULTIBOOT_LOADER_MAGIC) |
flags = mi->flags; |
} else { |
else { |
/* No multiboot info available. */ |
flags = 0; |
} |
/* Copy module information. */ |
if ((flags & MBINFO_FLAGS_MODS) != 0) { |
init.cnt = mi->mods_count; |
mods = mi->mods_addr; |
for (i = 0; i < init.cnt; i++) { |
init.tasks[i].addr = mods[i].start + 0x80000000; |
init.tasks[i].size = mods[i].end - mods[i].start; |
/* Copy command line, if available. */ |
if (mods[i].string) { |
extract_command(init.tasks[i].name, |
CONFIG_TASK_NAME_BUFLEN, |
mods[i].string); |
} else { |
} else |
init.tasks[i].name[0] = '\0'; |
} |
} |
} else { |
} else |
init.cnt = 0; |
} |
/* Copy memory map. */ |
int32_t mmap_length; |
mb_mmap_t *mme; |
uint32_t size; |
if ((flags & MBINFO_FLAGS_MMAP) != 0) { |
mmap_length = mi->mmap_length; |
mme = mi->mmap_addr; |
e820counter = 0; |
i = 0; |
while (mmap_length > 0) { |
e820table[i++] = mme->mm_info; |
/* Compute address of next structure. */ |
size = sizeof(mme->size) + mme->size; |
mme = ((void *) mme) + size; |
mmap_length -= size; |
} |
e820counter = i; |
} else { |
} else |
e820counter = 0; |
} |
#ifdef CONFIG_SMP |
/* Copy AP bootstrap routines below 1 MB. */ |
memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET, |
(size_t) &_hardcoded_unmapped_size); |
#endif |
main_bsp(); |
} |
/trunk/uspace/srv/loader/main.c |
---|
27,12 → 27,12 |
*/ |
/** @addtogroup loader |
* @brief Loads and runs programs from VFS. |
* @brief Loads and runs programs from VFS. |
* @{ |
*/ |
*/ |
/** |
* @file |
* @brief Loads and runs programs from VFS. |
* @brief Loads and runs programs from VFS. |
* |
* The program loader is a special init binary. Its image is used |
* to create a new task upon a @c task_spawn syscall. The syscall |
88,17 → 88,18 |
ipc_callid_t callid; |
task_id_t task_id; |
size_t len; |
task_id = task_get_id(); |
if (!ipc_data_read_receive(&callid, &len)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
} |
if (len > sizeof(task_id)) len = sizeof(task_id); |
if (len > sizeof(task_id)) |
len = sizeof(task_id); |
ipc_data_read_finalize(callid, &task_id, len); |
ipc_answer_0(rid, EOK); |
} |
114,13 → 115,13 |
ipc_callid_t callid; |
size_t len; |
char *name_buf; |
if (!ipc_data_write_receive(&callid, &len)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
} |
name_buf = malloc(len + 1); |
if (!name_buf) { |
ipc_answer_0(callid, ENOMEM); |
127,15 → 128,15 |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
ipc_data_write_finalize(callid, name_buf, len); |
ipc_answer_0(rid, EOK); |
if (pathname != NULL) { |
free(pathname); |
pathname = NULL; |
} |
name_buf[len] = '\0'; |
pathname = name_buf; |
} |
151,23 → 152,23 |
size_t buf_len, arg_len; |
char *p; |
int n; |
if (!ipc_data_write_receive(&callid, &buf_len)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
} |
if (arg_buf != NULL) { |
free(arg_buf); |
arg_buf = NULL; |
} |
if (argv != NULL) { |
free(argv); |
argv = NULL; |
} |
arg_buf = malloc(buf_len + 1); |
if (!arg_buf) { |
ipc_answer_0(callid, ENOMEM); |
174,12 → 175,12 |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
ipc_data_write_finalize(callid, arg_buf, buf_len); |
ipc_answer_0(rid, EOK); |
arg_buf[buf_len] = '\0'; |
/* |
* Count number of arguments |
*/ |
190,10 → 191,10 |
p = p + arg_len + 1; |
++n; |
} |
/* Allocate argv */ |
argv = malloc((n + 1) * sizeof(char *)); |
if (argv == NULL) { |
free(arg_buf); |
ipc_answer_0(callid, ENOMEM); |
200,7 → 201,7 |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
/* |
* Fill argv with argument pointers |
*/ |
208,12 → 209,12 |
n = 0; |
while (p < arg_buf + buf_len) { |
argv[n] = p; |
arg_len = strlen(p); |
p = p + arg_len + 1; |
++n; |
} |
argc = n; |
argv[n] = NULL; |
} |
227,7 → 228,7 |
static int loader_load(ipc_callid_t rid, ipc_call_t *request) |
{ |
int rc; |
rc = elf_load_file(pathname, 0, &prog_info); |
if (rc < 0) { |
DPRINTF("Failed to load executable '%s'.\n", pathname); |
234,12 → 235,12 |
ipc_answer_0(rid, EINVAL); |
return 1; |
} |
elf_create_pcb(&prog_info, &pcb); |
pcb.argc = argc; |
pcb.argv = argv; |
if (prog_info.interp == NULL) { |
/* Statically linked program */ |
is_dyn_linked = false; |
246,7 → 247,7 |
ipc_answer_0(rid, EOK); |
return 0; |
} |
rc = elf_load_file(prog_info.interp, 0, &interp_info); |
if (rc < 0) { |
DPRINTF("Failed to load interpreter '%s.'\n", |
254,10 → 255,10 |
ipc_answer_0(rid, EINVAL); |
return 1; |
} |
is_dyn_linked = true; |
ipc_answer_0(rid, EOK); |
return 0; |
} |
271,21 → 272,20 |
static void loader_run(ipc_callid_t rid, ipc_call_t *request) |
{ |
const char *cp; |
/* Set the task name. */ |
cp = strrchr(pathname, '/'); |
cp = (cp == NULL) ? pathname : (cp + 1); |
task_set_name(cp); |
if (is_dyn_linked == true) { |
/* Dynamically linked program */ |
DPRINTF("Run ELF interpreter.\n"); |
DPRINTF("Entry point: 0x%lx\n", interp_info.entry); |
close_console(); |
ipc_answer_0(rid, EOK); |
elf_run(&interp_info, &pcb); |
} else { |
/* Statically linked program */ |
close_console(); |
306,24 → 306,25 |
ipc_callid_t callid; |
ipc_call_t call; |
int retval; |
/* Already have a connection? */ |
if (connected) { |
ipc_answer_0(iid, ELIMIT); |
return; |
} |
connected = true; |
/* Accept the connection */ |
ipc_answer_0(iid, EOK); |
/* Ignore parameters, the connection is already open */ |
(void)iid; (void)icall; |
(void) iid; |
(void) icall; |
while (1) { |
callid = async_get_call(&call); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
exit(0); |
360,18 → 361,18 |
int main(int argc, char *argv[]) |
{ |
ipcarg_t phonead; |
connected = false; |
/* Set a handler of incomming connections. */ |
async_set_client_connection(loader_connection); |
/* Register at naming service. */ |
if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, &phonead) != 0) |
return -1; |
async_manager(); |
/* Never reached */ |
return 0; |
} |