Changeset c98e6ee in mainline
- 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
- Files:
-
- 39 added
- 50 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/amd64/Makefile.inc
rb7f9087 rc98e6ee 29 29 INIT_TASKS = \ 30 30 $(USPACEDIR)/srv/ns/ns \ 31 $(USPACEDIR)/srv/loader/loader \ 31 32 $(USPACEDIR)/app/init/init \ 32 33 $(USPACEDIR)/srv/devmap/devmap \ 33 34 $(USPACEDIR)/srv/rd/rd \ 34 35 $(USPACEDIR)/srv/vfs/vfs \ 35 $(USPACEDIR)/srv/fs/tmpfs/tmpfs 36 $(USPACEDIR)/srv/fs/tmpfs/tmpfs \ 36 37 37 38 RD_TASKS = \ … … 43 44 $(USPACEDIR)/app/tetris/tetris \ 44 45 $(USPACEDIR)/app/tester/tester \ 45 $(USPACEDIR)/app/klog/klog 46 $(USPACEDIR)/app/klog/klog \ 47 $(USPACEDIR)/app/cli/cli 46 48 47 49 build: $(BASE)/image.iso -
boot/arch/amd64/grub/menu.lst
rb7f9087 rc98e6ee 11 11 module /boot/vfs 12 12 module /boot/tmpfs 13 module /boot/loader 13 14 module /boot/initrd.img -
boot/arch/arm32/loader/Makefile
rb7f9087 rc98e6ee 81 81 $(KERNELDIR)/kernel.bin \ 82 82 $(USPACEDIR)/srv/ns/ns \ 83 $(USPACEDIR)/srv/loader/loader \ 83 84 $(USPACEDIR)/app/init/init \ 84 85 $(USPACEDIR)/srv/devmap/devmap \ … … 94 95 $(USPACEDIR)/app/tetris/tetris \ 95 96 $(USPACEDIR)/app/tester/tester \ 96 $(USPACEDIR)/app/klog/klog 97 $(USPACEDIR)/app/klog/klog \ 98 $(USPACEDIR)/app/cli/cli 97 99 98 100 OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) -
boot/arch/ia32/Makefile.inc
rb7f9087 rc98e6ee 29 29 INIT_TASKS = \ 30 30 $(USPACEDIR)/srv/ns/ns \ 31 $(USPACEDIR)/srv/loader/loader \ 31 32 $(USPACEDIR)/app/init/init \ 32 33 $(USPACEDIR)/srv/devmap/devmap \ … … 43 44 $(USPACEDIR)/app/tetris/tetris \ 44 45 $(USPACEDIR)/app/tester/tester \ 46 $(USPACEDIR)/app/cli/cli \ 45 47 $(USPACEDIR)/app/klog/klog 46 48 -
boot/arch/ia32/grub/menu.lst
rb7f9087 rc98e6ee 11 11 module /boot/vfs 12 12 module /boot/tmpfs 13 module /boot/loader 13 14 module /boot/initrd.img -
boot/arch/ia64/loader/Makefile
rb7f9087 rc98e6ee 87 87 $(KERNELDIR)/kernel.bin \ 88 88 $(USPACEDIR)/srv/ns/ns \ 89 $(USPACEDIR)/srv/loader/loader \ 89 90 $(USPACEDIR)/srv/fb/fb \ 90 91 $(USPACEDIR)/srv/kbd/kbd \ -
boot/arch/mips32/loader/Makefile
rb7f9087 rc98e6ee 81 81 $(KERNELDIR)/kernel.bin \ 82 82 $(USPACEDIR)/srv/ns/ns \ 83 $(USPACEDIR)/srv/loader/loader \ 83 84 $(USPACEDIR)/app/init/init \ 84 85 $(USPACEDIR)/srv/devmap/devmap \ … … 94 95 $(USPACEDIR)/app/tetris/tetris \ 95 96 $(USPACEDIR)/app/tester/tester \ 97 $(USPACEDIR)/app/cli/cli \ 96 98 $(USPACEDIR)/app/klog/klog 99 97 100 98 101 OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) -
boot/arch/ppc32/loader/Makefile
rb7f9087 rc98e6ee 76 76 $(KERNELDIR)/kernel.bin \ 77 77 $(USPACEDIR)/srv/ns/ns \ 78 $(USPACEDIR)/srv/loader/loader \ 78 79 $(USPACEDIR)/app/init/init \ 79 80 $(USPACEDIR)/srv/devmap/devmap \ … … 89 90 $(USPACEDIR)/app/tetris/tetris \ 90 91 $(USPACEDIR)/app/tester/tester \ 91 $(USPACEDIR)/app/klog/klog 92 $(USPACEDIR)/app/klog/klog \ 93 $(USPACEDIR)/app/cli/cli 92 94 93 95 OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) -
boot/arch/sparc64/loader/Makefile
rb7f9087 rc98e6ee 80 80 $(USPACEDIR)/srv/ns/ns \ 81 81 $(USPACEDIR)/app/init/init \ 82 $(USPACEDIR)/srv/loader/loader \ 82 83 $(USPACEDIR)/srv/devmap/devmap \ 83 84 $(USPACEDIR)/srv/rd/rd \ … … 92 93 $(USPACEDIR)/app/tetris/tetris \ 93 94 $(USPACEDIR)/app/tester/tester \ 95 $(USPACEDIR)/app/cli/cli \ 94 96 $(USPACEDIR)/app/klog/klog 95 97 -
kernel/Makefile
rb7f9087 rc98e6ee 233 233 generic/src/main/version.c \ 234 234 generic/src/main/shutdown.c \ 235 generic/src/proc/program.c \ 235 236 generic/src/proc/scheduler.c \ 236 237 generic/src/proc/thread.c \ … … 271 272 generic/src/synch/mutex.c \ 272 273 generic/src/synch/semaphore.c \ 274 generic/src/synch/smc.c \ 273 275 generic/src/synch/waitq.c \ 274 276 generic/src/synch/futex.c \ -
kernel/arch/amd64/src/userspace.c
rb7f9087 rc98e6ee 62 62 "pushq %4\n" 63 63 "movq %5, %%rax\n" 64 /* %rdi is defined to hold pcb_ptr - set it to 0 */ 65 "xorq %%rdi, %%rdi\n" 64 66 "iretq\n" 65 67 : : -
kernel/arch/arm32/src/userspace.c
rb7f9087 rc98e6ee 71 71 ustate.r0 = (uintptr_t) kernel_uarg->uspace_uarg; 72 72 73 /* %r1 is defined to hold pcb_ptr - set it to 0 */ 74 ustate.r1 = 0; 75 73 76 /* clear other registers */ 74 ustate.r 1 = ustate.r2= ustate.r3 = ustate.r4 = ustate.r5 =77 ustate.r2 = ustate.r3 = ustate.r4 = ustate.r5 = 75 78 ustate.r6 = ustate.r7 = ustate.r8 = ustate.r9 = ustate.r10 = 76 79 ustate.r11 = ustate.r12 = ustate.lr = 0; -
kernel/arch/ia32/src/userspace.c
rb7f9087 rc98e6ee 71 71 "pushl %4\n" 72 72 "movl %5, %%eax\n" 73 74 /* %ebx is defined to hold pcb_ptr - set it to 0 */ 75 "xorl %%ebx, %%ebx\n" 76 73 77 "iret\n" 74 78 : -
kernel/arch/ia32xen/src/userspace.c
rb7f9087 rc98e6ee 69 69 "pushl %4\n" 70 70 "movl %5, %%eax\n" 71 72 /* %ebx is defined to hold pcb_ptr - set it to 0 */ 73 "xorl %%ebx, %%ebx\n" 74 71 75 "iret\n" 72 76 : -
kernel/arch/ia64/src/asm.S
rb7f9087 rc98e6ee 164 164 xor r1 = r1, r1 165 165 166 /* r2 is defined to hold pcb_ptr - set it to 0 */ 167 xor r2 = r2, r2 168 166 169 mov loc1 = cr.ifs 167 170 movl loc2 = PFM_MASK ;; -
kernel/arch/mips32/src/start.S
rb7f9087 rc98e6ee 350 350 add $sp, $a0, 0 351 351 add $v0, $a1, 0 352 add $t9, $a2, 0 # Set up correct entry into PIC code 353 eret 352 add $t9, $a2, 0 # Set up correct entry into PIC code 353 xor $a0, $a0, $a0 # $a0 is defined to hold pcb_ptr 354 # set it to 0 355 eret -
kernel/arch/ppc32/src/asm.S
rb7f9087 rc98e6ee 66 66 67 67 mr sp, r4 68 69 # %r3 is defined to hold pcb_ptr - set it to 0 70 71 xor r3, r3, r3 68 72 69 73 # jump to userspace -
kernel/arch/ppc64/src/asm.S
rb7f9087 rc98e6ee 67 67 mr sp, r4 68 68 69 # %r3 is defined to hold pcb_ptr - set it to 0 70 71 xor r3, r3, r3 72 69 73 # jump to userspace 70 74 -
kernel/arch/sparc64/src/asm.S
rb7f9087 rc98e6ee 275 275 276 276 mov %i2, %o0 ! uarg 277 xor %o1, %o1, %o1 ! %o1 is defined to hold pcb_ptr 278 ! set it to 0 277 279 278 280 clr %i2 -
kernel/generic/include/lib/elf.h
rb7f9087 rc98e6ee 115 115 #define EE_INCOMPATIBLE 3 /* ELF image is not compatible with current architecture */ 116 116 #define EE_UNSUPPORTED 4 /* Non-supported ELF (e.g. dynamic ELFs) */ 117 #define EE_IRRECOVERABLE 5 117 #define EE_LOADER 5 /* The image is actually a program loader */ 118 #define EE_IRRECOVERABLE 6 118 119 119 120 /** … … 339 340 extern char *elf_error(unsigned int rc); 340 341 342 /* Interpreter string used to recognize the program loader */ 343 #define ELF_INTERP_ZSTR "kernel" 344 #define ELF_INTERP_ZLEN sizeof(ELF_INTERP_ZSTR) 345 341 346 #endif 342 347 -
kernel/generic/include/mm/as.h
rb7f9087 rc98e6ee 270 270 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size, 271 271 as_t *dst_as, uintptr_t dst_base, int dst_flags_mask); 272 extern int as_area_change_flags(as_t *as, int flags, uintptr_t address); 272 273 273 274 extern int as_area_get_flags(as_area_t *area); … … 300 301 extern mem_backend_t phys_backend; 301 302 302 extern unsigned int elf_load(elf_header_t *header, as_t *as); 303 /** 304 * This flags is passed when running the loader, otherwise elf_load() 305 * would return with a EE_LOADER error code. 306 */ 307 #define ELD_F_NONE 0 308 #define ELD_F_LOADER 1 309 310 extern unsigned int elf_load(elf_header_t *header, as_t *as, int flags); 303 311 304 312 /* Address space area related syscalls. */ 305 313 extern unative_t sys_as_area_create(uintptr_t address, size_t size, int flags); 306 314 extern unative_t sys_as_area_resize(uintptr_t address, size_t size, int flags); 315 extern unative_t sys_as_area_change_flags(uintptr_t address, int flags); 307 316 extern unative_t sys_as_area_destroy(uintptr_t address); 308 317 -
kernel/generic/include/proc/task.h
rb7f9087 rc98e6ee 133 133 134 134 extern unative_t sys_task_get_id(task_id_t *uspace_task_id); 135 extern unative_t sys_task_spawn(void *image, size_t size);136 135 137 136 #endif -
kernel/generic/include/proc/thread.h
rb7f9087 rc98e6ee 249 249 extern bool thread_exists(thread_t *t); 250 250 251 extern thread_t *thread_create_program(void *program_addr, char *name);252 253 251 /** Fpu context slab cache. */ 254 252 extern slab_cache_t *fpu_context_slab; -
kernel/generic/include/syscall/syscall.h
rb7f9087 rc98e6ee 45 45 46 46 SYS_TASK_GET_ID, 47 SYS_ TASK_SPAWN,47 SYS_PROGRAM_SPAWN_LOADER, 48 48 49 49 SYS_FUTEX_SLEEP, 50 50 SYS_FUTEX_WAKEUP, 51 SYS_SMC_COHERENCE, 51 52 52 53 SYS_AS_AREA_CREATE, 53 54 SYS_AS_AREA_RESIZE, 55 SYS_AS_AREA_CHANGE_FLAGS, 54 56 SYS_AS_AREA_DESTROY, 55 57 -
kernel/generic/src/lib/elf.c
rb7f9087 rc98e6ee 58 58 59 59 static int segment_header(elf_segment_header_t *entry, elf_header_t *elf, 60 as_t *as );60 as_t *as, int flags); 61 61 static int section_header(elf_section_header_t *entry, elf_header_t *elf, 62 62 as_t *as); … … 68 68 * @param header Pointer to ELF header in memory 69 69 * @param as Created and properly mapped address space 70 * @param flags A combination of ELD_F_* 70 71 * @return EE_OK on success 71 72 */ 72 unsigned int elf_load(elf_header_t *header, as_t * as )73 unsigned int elf_load(elf_header_t *header, as_t * as, int flags) 73 74 { 74 75 int i, rc; … … 111 112 seghdr = &((elf_segment_header_t *)(((uint8_t *) header) + 112 113 header->e_phoff))[i]; 113 rc = segment_header(seghdr, header, as );114 rc = segment_header(seghdr, header, as, flags); 114 115 if (rc != EE_OK) 115 116 return rc; … … 152 153 */ 153 154 static int segment_header(elf_segment_header_t *entry, elf_header_t *elf, 154 as_t *as) 155 { 155 as_t *as, int flags) 156 { 157 char *interp; 158 156 159 switch (entry->p_type) { 157 160 case PT_NULL: … … 163 166 case PT_DYNAMIC: 164 167 case PT_INTERP: 168 interp = (char *)elf + entry->p_offset; 169 /* FIXME */ 170 /*if (memcmp((uintptr_t)interp, (uintptr_t)ELF_INTERP_ZSTR, 171 ELF_INTERP_ZLEN) != 0) { 172 return EE_UNSUPPORTED; 173 }*/ 174 if ((flags & ELD_F_LOADER) == 0) { 175 return EE_LOADER; 176 } 177 break; 165 178 case PT_SHLIB: 166 179 case PT_NOTE: -
kernel/generic/src/main/kinit.c
rb7f9087 rc98e6ee 48 48 #include <proc/task.h> 49 49 #include <proc/thread.h> 50 #include <proc/program.h> 50 51 #include <panic.h> 51 52 #include <func.h> … … 160 161 */ 161 162 count_t i; 162 thread_t *threads[CONFIG_INIT_TASKS];163 program_t programs[CONFIG_INIT_TASKS]; 163 164 164 165 for (i = 0; i < init.cnt; i++) { … … 168 169 } 169 170 170 threads[i] = thread_create_program((void *) init.tasks[i].addr,171 "uspace");172 173 if ( threads[i]!= NULL) {171 int rc = program_create_from_image((void *) init.tasks[i].addr, 172 &programs[i]); 173 174 if (rc == 0 && programs[i].task != NULL) { 174 175 /* 175 176 * Set capabilities to init userspace tasks. 176 177 */ 177 cap_set( threads[i]->task, CAP_CAP | CAP_MEM_MANAGER |178 cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER | 178 179 CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); 180 179 181 180 182 if (!ipc_phone_0) 181 ipc_phone_0 = &threads[i]->task->answerbox; 183 ipc_phone_0 = &programs[i].task->answerbox; 184 } else if (rc == 0) { 185 /* It was the program loader and was registered */ 182 186 } else { 187 /* RAM disk image */ 183 188 int rd = init_rd((rd_header_t *) init.tasks[i].addr, 184 189 init.tasks[i].size); … … 194 199 */ 195 200 for (i = 0; i < init.cnt; i++) { 196 if ( threads[i]!= NULL) {201 if (programs[i].task != NULL) { 197 202 thread_usleep(50000); 198 thread_ready(threads[i]);203 program_ready(&programs[i]); 199 204 } 200 205 } -
kernel/generic/src/mm/as.c
rb7f9087 rc98e6ee 772 772 } 773 773 774 /** Change adress area flags. 775 * 776 * The idea is to have the same data, but with a different access mode. 777 * This is needed e.g. for writing code into memory and then executing it. 778 * In order for this to work properly, this may copy the data 779 * into private anonymous memory (unless it's already there). 780 * 781 * @param as Address space. 782 * @param flags Flags of the area memory. 783 * @param address Address withing the area to be changed. 784 * 785 * @return Zero on success or a value from @ref errno.h on failure. 786 */ 787 int as_area_change_flags(as_t *as, int flags, uintptr_t address) 788 { 789 as_area_t *area; 790 uintptr_t base; 791 link_t *cur; 792 ipl_t ipl; 793 int page_flags; 794 uintptr_t *old_frame; 795 index_t frame_idx; 796 count_t used_pages; 797 798 /* Flags for the new memory mapping */ 799 page_flags = area_flags_to_page_flags(flags); 800 801 ipl = interrupts_disable(); 802 mutex_lock(&as->lock); 803 804 area = find_area_and_lock(as, address); 805 if (!area) { 806 mutex_unlock(&as->lock); 807 interrupts_restore(ipl); 808 return ENOENT; 809 } 810 811 if (area->sh_info || area->backend != &anon_backend) { 812 /* Copying shared areas not supported yet */ 813 /* Copying non-anonymous memory not supported yet */ 814 mutex_unlock(&area->lock); 815 mutex_unlock(&as->lock); 816 interrupts_restore(ipl); 817 return ENOTSUP; 818 } 819 820 base = area->base; 821 822 /* 823 * Compute total number of used pages in the used_space B+tree 824 */ 825 used_pages = 0; 826 827 for (cur = area->used_space.leaf_head.next; 828 cur != &area->used_space.leaf_head; cur = cur->next) { 829 btree_node_t *node; 830 unsigned int i; 831 832 node = list_get_instance(cur, btree_node_t, leaf_link); 833 for (i = 0; i < node->keys; i++) { 834 used_pages += (count_t) node->value[i]; 835 } 836 } 837 838 /* An array for storing frame numbers */ 839 old_frame = malloc(used_pages * sizeof(uintptr_t), 0); 840 841 /* 842 * Start TLB shootdown sequence. 843 */ 844 tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base, area->pages); 845 846 /* 847 * Remove used pages from page tables and remember their frame 848 * numbers. 849 */ 850 frame_idx = 0; 851 852 for (cur = area->used_space.leaf_head.next; 853 cur != &area->used_space.leaf_head; cur = cur->next) { 854 btree_node_t *node; 855 unsigned int i; 856 857 node = list_get_instance(cur, btree_node_t, leaf_link); 858 for (i = 0; i < node->keys; i++) { 859 uintptr_t b = node->key[i]; 860 count_t j; 861 pte_t *pte; 862 863 for (j = 0; j < (count_t) node->value[i]; j++) { 864 page_table_lock(as, false); 865 pte = page_mapping_find(as, b + j * PAGE_SIZE); 866 ASSERT(pte && PTE_VALID(pte) && 867 PTE_PRESENT(pte)); 868 old_frame[frame_idx++] = PTE_GET_FRAME(pte); 869 870 /* Remove old mapping */ 871 page_mapping_remove(as, b + j * PAGE_SIZE); 872 page_table_unlock(as, false); 873 } 874 } 875 } 876 877 /* 878 * Finish TLB shootdown sequence. 879 */ 880 881 tlb_invalidate_pages(as->asid, area->base, area->pages); 882 /* 883 * Invalidate potential software translation caches (e.g. TSB on 884 * sparc64). 885 */ 886 as_invalidate_translation_cache(as, area->base, area->pages); 887 tlb_shootdown_finalize(); 888 889 /* 890 * Map pages back in with new flags. This step is kept separate 891 * so that there's no instant when the memory area could be 892 * accesed with both the old and the new flags at once. 893 */ 894 frame_idx = 0; 895 896 for (cur = area->used_space.leaf_head.next; 897 cur != &area->used_space.leaf_head; cur = cur->next) { 898 btree_node_t *node; 899 unsigned int i; 900 901 node = list_get_instance(cur, btree_node_t, leaf_link); 902 for (i = 0; i < node->keys; i++) { 903 uintptr_t b = node->key[i]; 904 count_t j; 905 906 for (j = 0; j < (count_t) node->value[i]; j++) { 907 page_table_lock(as, false); 908 909 /* Insert the new mapping */ 910 page_mapping_insert(as, b + j * PAGE_SIZE, 911 old_frame[frame_idx++], page_flags); 912 913 page_table_unlock(as, false); 914 } 915 } 916 } 917 918 free(old_frame); 919 920 mutex_unlock(&area->lock); 921 mutex_unlock(&as->lock); 922 interrupts_restore(ipl); 923 924 return 0; 925 } 926 927 774 928 /** Handle page fault within the current address space. 775 929 * … … 1767 1921 } 1768 1922 1923 /** Wrapper for as_area_change_flags(). */ 1924 unative_t sys_as_area_change_flags(uintptr_t address, int flags) 1925 { 1926 return (unative_t) as_area_change_flags(AS, flags, address); 1927 } 1928 1769 1929 /** Wrapper for as_area_destroy(). */ 1770 1930 unative_t sys_as_area_destroy(uintptr_t address) -
kernel/generic/src/proc/task.c
rb7f9087 rc98e6ee 36 36 */ 37 37 38 #include <main/uinit.h>39 38 #include <proc/thread.h> 40 39 #include <proc/task.h> 41 #include <proc/uarg.h>42 40 #include <mm/as.h> 43 41 #include <mm/slab.h> … … 47 45 #include <arch.h> 48 46 #include <arch/barrier.h> 49 #include <panic.h>50 47 #include <adt/avl.h> 51 48 #include <adt/btree.h> 52 49 #include <adt/list.h> 53 50 #include <ipc/ipc.h> 54 #include <security/cap.h> 55 #include <memstr.h> 51 #include <ipc/ipcrsc.h> 56 52 #include <print.h> 57 #include <lib/elf.h>58 53 #include <errno.h> 59 54 #include <func.h> 60 55 #include <syscall/copy.h> 61 62 #ifndef LOADED_PROG_STACK_PAGES_NO63 #define LOADED_PROG_STACK_PAGES_NO 164 #endif65 56 66 57 /** Spinlock protecting the tasks_tree AVL tree. */ … … 252 243 } 253 244 254 unative_t sys_task_spawn(void *image, size_t size)255 {256 void *kimage = malloc(size, 0);257 if (kimage == NULL)258 return ENOMEM;259 260 int rc = copy_from_uspace(kimage, image, size);261 if (rc != EOK)262 return rc;263 264 /*265 * Not very efficient and it would be better to call it on code only,266 * but this whole function is a temporary hack anyway and one day it267 * will go in favor of the userspace dynamic loader.268 */269 smc_coherence_block(kimage, size);270 271 uspace_arg_t *kernel_uarg;272 kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);273 if (kernel_uarg == NULL) {274 free(kimage);275 return ENOMEM;276 }277 278 kernel_uarg->uspace_entry =279 (void *) ((elf_header_t *) kimage)->e_entry;280 kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS;281 kernel_uarg->uspace_thread_function = NULL;282 kernel_uarg->uspace_thread_arg = NULL;283 kernel_uarg->uspace_uarg = NULL;284 285 as_t *as = as_create(0);286 if (as == NULL) {287 free(kernel_uarg);288 free(kimage);289 return ENOMEM;290 }291 292 unsigned int erc = elf_load((elf_header_t *) kimage, as);293 if (erc != EE_OK) {294 as_destroy(as);295 free(kernel_uarg);296 free(kimage);297 return ENOENT;298 }299 300 as_area_t *area = as_area_create(as,301 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,302 LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS,303 AS_AREA_ATTR_NONE, &anon_backend, NULL);304 if (area == NULL) {305 as_destroy(as);306 free(kernel_uarg);307 free(kimage);308 return ENOMEM;309 }310 311 task_t *task = task_create(as, "app");312 if (task == NULL) {313 as_destroy(as);314 free(kernel_uarg);315 free(kimage);316 return ENOENT;317 }318 319 // FIXME: control the capabilities320 cap_set(task, cap_get(TASK));321 322 thread_t *thread = thread_create(uinit, kernel_uarg, task,323 THREAD_FLAG_USPACE, "user", false);324 if (thread == NULL) {325 task_destroy(task);326 as_destroy(as);327 free(kernel_uarg);328 free(kimage);329 return ENOENT;330 }331 332 thread_ready(thread);333 334 return EOK;335 }336 337 245 /** Find task structure corresponding to task ID. 338 246 * -
kernel/generic/src/proc/thread.c
rb7f9087 rc98e6ee 673 673 } 674 674 675 676 /** Create new user task with 1 thread from image677 *678 * @param program_addr Address of program executable image.679 * @param name Program name.680 *681 * @return Initialized main thread of the task or NULL on error.682 */683 thread_t *thread_create_program(void *program_addr, char *name)684 {685 as_t *as;686 as_area_t *area;687 unsigned int rc;688 task_t *task;689 uspace_arg_t *kernel_uarg;690 691 kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);692 if (kernel_uarg == NULL)693 return NULL;694 695 kernel_uarg->uspace_entry =696 (void *) ((elf_header_t *) program_addr)->e_entry;697 kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS;698 kernel_uarg->uspace_thread_function = NULL;699 kernel_uarg->uspace_thread_arg = NULL;700 kernel_uarg->uspace_uarg = NULL;701 702 as = as_create(0);703 if (as == NULL) {704 free(kernel_uarg);705 return NULL;706 }707 708 rc = elf_load((elf_header_t *) program_addr, as);709 if (rc != EE_OK) {710 free(kernel_uarg);711 as_destroy(as);712 return NULL;713 }714 715 /*716 * Create the data as_area.717 */718 area = as_area_create(as,719 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,720 LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS,721 AS_AREA_ATTR_NONE, &anon_backend, NULL);722 if (area == NULL) {723 free(kernel_uarg);724 as_destroy(as);725 return NULL;726 }727 728 task = task_create(as, name);729 if (task == NULL) {730 free(kernel_uarg);731 as_destroy(as);732 return NULL;733 }734 735 /*736 * Create the main thread.737 */738 return thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE,739 "uinit", false);740 }741 742 743 675 /** Update accounting of current thread. 744 676 * -
kernel/generic/src/syscall/syscall.c
rb7f9087 rc98e6ee 39 39 #include <proc/thread.h> 40 40 #include <proc/task.h> 41 #include <proc/program.h> 41 42 #include <mm/as.h> 42 43 #include <print.h> … … 47 48 #include <ipc/sysipc.h> 48 49 #include <synch/futex.h> 50 #include <synch/smc.h> 49 51 #include <ddi/ddi.h> 50 52 #include <security/cap.h> … … 124 126 125 127 (syshandler_t) sys_task_get_id, 126 (syshandler_t) sys_ task_spawn,128 (syshandler_t) sys_program_spawn_loader, 127 129 128 130 /* Synchronization related syscalls. */ 129 131 (syshandler_t) sys_futex_sleep_timeout, 130 132 (syshandler_t) sys_futex_wakeup, 133 (syshandler_t) sys_smc_coherence, 131 134 132 135 /* Address space related syscalls. */ 133 136 (syshandler_t) sys_as_area_create, 134 137 (syshandler_t) sys_as_area_resize, 138 (syshandler_t) sys_as_area_change_flags, 135 139 (syshandler_t) sys_as_area_destroy, 136 140 -
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.