*
*/
#define ILOG2(x) \
- __builtin_constant_p(x) ? ((x) == 0 ? 0 \
- : ((x) & (1ul << 31)) ? 31 \
- : ((x) & (1ul << 30)) ? 30 \
- : ((x) & (1ul << 29)) ? 29 \
- : ((x) & (1ul << 28)) ? 28 \
- : ((x) & (1ul << 27)) ? 27 \
- : ((x) & (1ul << 26)) ? 26 \
- : ((x) & (1ul << 25)) ? 25 \
- : ((x) & (1ul << 24)) ? 24 \
- : ((x) & (1ul << 23)) ? 23 \
- : ((x) & (1ul << 22)) ? 22 \
- : ((x) & (1ul << 21)) ? 21 \
- : ((x) & (1ul << 20)) ? 20 \
- : ((x) & (1ul << 19)) ? 19 \
- : ((x) & (1ul << 18)) ? 18 \
- : ((x) & (1ul << 17)) ? 17 \
- : ((x) & (1ul << 16)) ? 16 \
- : ((x) & (1ul << 15)) ? 15 \
- : ((x) & (1ul << 14)) ? 14 \
- : ((x) & (1ul << 13)) ? 13 \
- : ((x) & (1ul << 12)) ? 12 \
- : ((x) & (1ul << 11)) ? 11 \
- : ((x) & (1ul << 10)) ? 10 \
- : ((x) & (1ul << 9)) ? 9 \
- : ((x) & (1ul << 8)) ? 8 \
- : ((x) & (1ul << 7)) ? 7 \
- : ((x) & (1ul << 6)) ? 6 \
- : ((x) & (1ul << 5)) ? 5 \
- : ((x) & (1ul << 4)) ? 4 \
- : ((x) & (1ul << 3)) ? 3 \
- : ((x) & (1ul << 2)) ? 2 \
- : ((x) & (1ul << 1)) ? 1 \
- : 0) \
- : (31 - __builtin_clz(x))
+ (__builtin_constant_p(x) ? ((x) == 0 ? 0 \
+ : ((x) & (1ul << 31)) ? 31 \
+ : ((x) & (1ul << 30)) ? 30 \
+ : ((x) & (1ul << 29)) ? 29 \
+ : ((x) & (1ul << 28)) ? 28 \
+ : ((x) & (1ul << 27)) ? 27 \
+ : ((x) & (1ul << 26)) ? 26 \
+ : ((x) & (1ul << 25)) ? 25 \
+ : ((x) & (1ul << 24)) ? 24 \
+ : ((x) & (1ul << 23)) ? 23 \
+ : ((x) & (1ul << 22)) ? 22 \
+ : ((x) & (1ul << 21)) ? 21 \
+ : ((x) & (1ul << 20)) ? 20 \
+ : ((x) & (1ul << 19)) ? 19 \
+ : ((x) & (1ul << 18)) ? 18 \
+ : ((x) & (1ul << 17)) ? 17 \
+ : ((x) & (1ul << 16)) ? 16 \
+ : ((x) & (1ul << 15)) ? 15 \
+ : ((x) & (1ul << 14)) ? 14 \
+ : ((x) & (1ul << 13)) ? 13 \
+ : ((x) & (1ul << 12)) ? 12 \
+ : ((x) & (1ul << 11)) ? 11 \
+ : ((x) & (1ul << 10)) ? 10 \
+ : ((x) & (1ul << 9)) ? 9 \
+ : ((x) & (1ul << 8)) ? 8 \
+ : ((x) & (1ul << 7)) ? 7 \
+ : ((x) & (1ul << 6)) ? 6 \
+ : ((x) & (1ul << 5)) ? 5 \
+ : ((x) & (1ul << 4)) ? 4 \
+ : ((x) & (1ul << 3)) ? 3 \
+ : ((x) & (1ul << 2)) ? 2 \
+ : ((x) & (1ul << 1)) ? 1 \
+ : 0) \
+ : (31 - __builtin_clz(x)))
#define __USER__ __attribute__((section(".usrtext")))
if (hit_region->mfile && !PG_IS_PRESENT(*pte)) {
struct v_file* file = hit_region->mfile;
u32_t offset =
- (ptr - hit_region->start) & (PG_SIZE - 1) + hit_region->foff;
+ ((ptr - hit_region->start) & (PG_SIZE - 1)) + hit_region->foff;
uintptr_t pa = pmm_alloc_page(__current->pid, 0);
if (!pa) {
#include <lunaix/spike.h>
int
-__elf_populate_mapped(struct mm_region* region, void* pg, off_t offset)
+__elf_populate_mapped(struct mm_region* region, void* pg, off_t segfoff)
{
size_t segsz = region->flen;
- size_t segoff = offset - region->foff;
+ size_t segmoff = segfoff - region->foff;
- if (segoff >= segsz) {
+ if (segmoff >= segsz) {
return 0;
}
struct v_file* file = region->mfile;
- size_t rdlen = MIN(segsz - segoff, PG_SIZE);
+ size_t rdlen = MIN(segsz - segmoff, PG_SIZE);
if (rdlen == PG_SIZE) {
// This is because we want to exploit any optimization on read_page
- return file->ops->read_page(file->inode, pg, PG_SIZE, offset);
+ return file->ops->read_page(file->inode, pg, PG_SIZE, segfoff);
} else {
- return file->ops->read(file->inode, pg, rdlen, offset);
+ // we don't want to over-read the segment!
+ return file->ops->read(file->inode, pg, rdlen, segfoff);
}
}
}
tbl_sz = 1 << ILOG2(tbl_sz);
- phdrs = elfile->ops->read(elfile->inode, phdrs, tbl_sz, ehdr->e_phoff);
+ status = elfile->ops->read(elfile->inode, phdrs, tbl_sz, ehdr->e_phoff);
+
+ if (status < 0) {
+ goto done;
+ }
if (PG_ALIGN(phdrs[0].p_va) != USER_START) {
status = ENOEXEC;
struct elf32_ehdr* ehdr = valloc(SIZE_EHDR);
int status = elfile->ops->read(elfile->inode, ehdr, SIZE_EHDR, 0);
- if (status) {
+ if (status < 0) {
goto done;
}
heap->region_copied = __heap_copied;
mm_index((void**)&pvms->heap, heap);
+
+ return status;
}
int
if (envp)
memcpy(arg_start + sz_argv, (void*)envp, sz_envp);
- struct usr_exec_param* param = mapped;
- *param = (struct usr_exec_param){ .argc = argv_len,
- .argv = arg_start,
- .envc = envp_len,
- .envp = arg_start + sz_argv,
- .info = param->info };
ptr_t* ustack = (ptr_t*)USTACK_TOP;
+ struct usr_exec_param* exec_param = mapped;
+
ustack[-1] = (ptr_t)mapped;
param->info.stack_top = &ustack[-1];
+
+ *exec_param = (struct usr_exec_param){ .argc = argv_len,
+ .argv = arg_start,
+ .envc = envp_len,
+ .envp = arg_start + sz_argv,
+ .info = param->info };
} else {
// TODO need to find a way to inject argv and envp remotely
fail("not implemented");
{
int errno = 0;
struct ld_param param;
- char filename[] = "/mnt/lunaix-os/usr/initd";
+ char filename[] = "/mnt/lunaix-os/usr/init";
ld_create_param(¶m, __current, VMS_SELF);
}
mapped->region_copied = __stack_copied;
- mm_index((void**)&pcb->mm.heap, mapped);
+ mm_index((void**)&pcb->mm.stack, mapped);
// TODO other uspace initialization stuff
{
int errno = 0;
- if ((errno = open("/dev/tty", 0))) {
+ if ((errno = open("/dev/tty", 0)) < 0) {
syslog(2, "fail to open tty (%d)\n", errno);
return 0;
}
- if ((errno = dup(errno))) {
+ if ((errno = dup(errno)) < 0) {
syslog(2, "fail to setup tty i/o (%d)\n", errno);
return 0;
}
- syslog(0, "user space!\n");
+ syslog(0, "(%p) user space!\n", main);
return 0;
}
\ No newline at end of file
.section .text
.global _u_start
_u_start:
+ movl $2, %eax
call usr_pre_init
jnz 1f