void init_kernel(uint32_t* modulep, void* kernmem, void* physbase, void* physfree) { printf("Booting Deep-OS\n"); printf("Initializing interrupt handler\n"); if(ENABLE_INTR) { init_pics(); idtStart(); } printf("Initializing memory manager\n"); init_mem_mgmt(modulep, kernmem, physbase, physfree); if (DEBUG) printf("Kernmem virt: %x\n", kernmem); if (DEBUG) printf("Kernmem before: %x\n", get_phy_addr((uint64_t)kernmem, kern_pml4e_virt)); printf("Initializing process manager\n"); initialize_tasking(); printf("Creating deep shell\n"); create_shell(); if (DEBUG) printf("Back after a simple switch. Current PID %d\n", getpid()); while(1); }
/** * \brief Program main function. * * \param argc number of arguments * \param *argv[] array with the arguments * * \return 0 OK <BR> * -1 error */ int main(int argc, char *argv[]) { cs_device_t *dev; char *file = CS_PATH_DEV(0); cs_space_t *lb_ep[NUM_LB_EP]; cs_space_t *mi32tobm; uint32_t *lb_ep_mem[NUM_LB_EP]; uint32_t offset = 0; uint32_t value[MAX_DATA_SIZE/4]; bool randomize_offset = true, randomize_data = true, randomize_index = true; int c, index, mem_size, size; int cmd = -1; char buffer[MAX_DATA_SIZE]; uint32_t phy_addr; uint32_t lb_ep_base_addr[10]; uint32_t data; char *command = NULL; long ltemp; /*!< getopt */ uint32_t loops = 1, cycle; uint32_t data_size = 4; char *data_file = NULL; int ret = 0; bool test_local, test_global; uint32_t i; debug = -1; size = LB_ENDPOINT_WIDTH/4; for(i=0; i < NUM_LB_EP; i++){ if(i >= BRAM_FROM_INDEX) { size = LB_ENDPOINT_BRAM_WIDTH/4; } lb_ep_mem[i] = (uint32_t *) malloc(sizeof(uint32_t) * size); if(lb_ep_mem[i] == 0){ errx(1, "cannot allocate memory"); } memset(lb_ep_mem[i], 0, sizeof(uint32_t) * size); } while ((c = getopt(argc, argv, ARGUMENTS)) != -1) { switch (c) { case 'd': /* Set device file path */ file = optarg; break; case 'c': /* Decode command */ command = optarg; break; #ifdef DEBUG case 'D': /* debug level */ if( (cl_strtol(optarg, <emp)) || (ltemp > 2) || (ltemp < 0) ) { errx(1, "wrong value of -D attribute"); } debug = ltemp; break; #endif case 'f': randomize_data = false; data_file = optarg; break; case 'h': /* program usage */ usage(c_commands); return 0; case 'l': if( (cl_strtol(optarg, <emp)) || (ltemp > LOOPS_MAX) || (ltemp < 1) ) { errx(1, "wrong value of -l attribute. Minimum is 1, maximum %d", LOOPS_MAX); } loops = ltemp; break; case 's': if( (cl_strtol(optarg, <emp)) || (ltemp > MAX_DATA_SIZE) || (ltemp < 1)) { errx(1, "wrong value of -s attribute. Minimum is 1, maximum %d", MAX_DATA_SIZE); } data_size = ltemp; if(data_size % 4) errx(1, "Size not aligned to 4"); break; case 'o': if( (cl_strtol(optarg, <emp)) || (ltemp > MAX_OFFSET)) { errx(1, "wrong value of -o attribute. Minimum is 0, maximum %d", MAX_OFFSET); } randomize_offset = false; offset = ltemp; if(offset % 4) warnx("offset not aligned to 4"); break; default: errx(1, "unknown argument -%c", optopt); } } argc -= optind; argv += optind; if (argc != 0) { errx(1, "stray arguments"); } /* load data pattern */ if(!cl_file_read_hex((char *)value, data_file, data_size)) errx(1, "Can't load data from file"); /* attach device */ if (cs_attach_noex(&dev, file) != 0){ cs_detach(&dev); errx(1, "cs_attach_noex failed"); } /* ------------ Component space mapping ------------ */ /* LB_ENDPOINT */ MSG(CL_VERBOSE_BASIC, "Mapping memory 0 at %08x", LB_ENDPOINT_0_BASE); if (cs_space_map(dev, &lb_ep[0], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \ LB_ENDPOINT_0_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_0"); } lb_ep_base_addr[0] = LB_ENDPOINT_0_BASE; #ifndef GICS /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[1], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \ LB_ENDPOINT_1_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_1"); } lb_ep_base_addr[1] = LB_ENDPOINT_1_BASE; /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[2], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \ LB_ENDPOINT_2_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_2"); } lb_ep_base_addr[2] = LB_ENDPOINT_2_BASE; /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[3], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \ LB_ENDPOINT_3_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_3"); } lb_ep_base_addr[3] = LB_ENDPOINT_3_BASE; /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[4], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \ LB_ENDPOINT_4_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_4"); } lb_ep_base_addr[4] = LB_ENDPOINT_4_BASE; #endif /* MI32 TO BM */ MSG(CL_VERBOSE_BASIC, "Mapping MI32 TO BM at %08x", LB_EP_MI32TOBM_BASE); if (cs_space_map(dev, &mi32tobm, CS_SPACE_FPGA, LB_EP_MI32TOBM_WIDTH, \ LB_EP_MI32TOBM_BASE, 0) != 0) { errx(1, "cs_space_map failed to map MI32TOBM"); } #ifndef GICS /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[5], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\ LB_ENDPOINT_5_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_5"); } lb_ep_base_addr[5] = LB_ENDPOINT_5_BASE; /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[6], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\ LB_ENDPOINT_6_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_6"); } lb_ep_base_addr[6] = LB_ENDPOINT_6_BASE; /* LB_ENDPOINT */ if (cs_space_map(dev, &lb_ep[7], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\ LB_ENDPOINT_7_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_7"); } lb_ep_base_addr[7] = LB_ENDPOINT_7_BASE; /* LB_ENDPOINT_BM */ if (cs_space_map(dev, &lb_ep[8], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\ LB_ENDPOINT_BM_BASE, 0) != 0) { errx(1, "cs_space_map failed to map LB_ENDPOINT_BM"); } lb_ep_base_addr[8] = LB_ENDPOINT_BM_BASE; #endif /* Clear all memory of all LB_EPs - zeros like in SW buffers */ for(i=0; i<NUM_LB_EP; i++) { mem_size = get_lb_ep_mem_size(i); ics_clear_mem(dev,lb_ep[i], mem_size); } srand((unsigned int) clock()); if (command != NULL){ if( (cmd = decode_choice(c_commands, command, NUM_CMD)) == -1){ MSG(CL_VERBOSE_BASIC, "Unknown command %s", command); return -1; } } if(cmd == -1){ usage(c_commands); return 0; } for(cycle=0; cycle<loops; cycle++) { test_local = false; test_global = false; /* get needed data for operations */ if(randomize_index) index = rand_index(); if(randomize_offset) offset = rand_offset(index); if(randomize_data) rand_data((u_char *)value, data_size); MSG(CL_VERBOSE_BASIC, "index %d", index); MSG(CL_VERBOSE_BASIC, "offset 0x%08x", offset); MSG(CL_VERBOSE_BASIC, "data_size 0x%08x", data_size); MSG(CL_VERBOSE_BASIC, "loops %d", loops); MSG(CL_VERBOSE_BASIC, "data"); for(i = 0; i < data_size; i++) { MSG_NONL(CL_VERBOSE_BASIC, "%02x ", *((u_char *)value + i)); } MSG_NONL(CL_VERBOSE_BASIC, "\n"); switch(cmd){ case CMD_WRITE_IN: /* test write-in to LB_EPs */ MSG(CL_VERBOSE_BASIC, "WRITE_IN"); ics_write(dev, lb_ep[index], offset, value, \ lb_ep_mem[index], data_size); test_local = true; break; case CMD_G2LR: /*************************************************************/ /* BM - G2L READ - TEST */ write_to_phy_addr((char *)value, data_size); /* written data to physical address - verification */ read_from_phy_addr(buffer, data_size); /* store data from phy. mem to SW copy of LB_EP mems */ memcpy(lb_ep_mem[index], buffer, data_size); /* get physical address - here was just written */ if( (phy_addr = get_phy_addr()) == 0) { printf("Unable to get physical address to memory\n"); exit(-1); } /* BM operation - from physical address to unit */ ics_bm_g2lread(dev, mi32tobm, phy_addr, \ lb_ep_base_addr[index]+(offset), data_size); /* wait for operation to finish */ usleep(1000); test_local = true; break; case CMD_L2GW: /************************************************************/ /* BM - L2G WRITE - TEST*/ if( (phy_addr = get_phy_addr()) == 0) { printf("Unable to get physical address to memory\n"); exit(-1); } ics_write(dev, lb_ep[index], offset, value, \ lb_ep_mem[index], data_size); ics_bm_l2gwrite(dev, mi32tobm, phy_addr, offset, data_size); /* wait till BM operation end */ usleep(100); read_from_phy_addr(buffer, data_size); test_global = true; break; } if(test_local) { /* diff FPGA and lb_ep_mem */ ret = ics_test_lb_ep_mem(dev, lb_ep[index], data_size, (u_char *)lb_ep_mem[index], offset); } else if(test_global) { /* global stored in buffer - diff buffer and lb_ep_mem */ ret = ics_test_lb_ep_mem_global(buffer, data_size, (u_char *)lb_ep_mem[index], offset); } /* print results */ if(!ret) { printf("memory verification for lb_ep %d was " \ "successfull\n", index); } else { printf("memory verification for lb_ep %d failed!!\n", \ index); } } /* FOR */ cs_detach(&dev); return 0; }
int load_exe(task_struct *task, void *exe_start) { mm_struct *mm = task->mm; /* ELF header */ elfHeader *ehdr = (elfHeader *)exe_start; /* program header */ progHeader *phdr = (progHeader *)((uint64_t)ehdr + ehdr->e_phoff); int count = 0; /* new task entry point */ task->rip = ehdr->e_entry; task->mm->mmap = NULL; for(; count < ehdr->e_phnum; count++) { /* loadable section */ if(phdr->p_type == 1) { vma_struct *vma = (vma_struct *)kmalloc(); if(mm->mmap == NULL) { mm->mmap = vma; } else { mm->current->next = vma; } mm->current = vma; vma->mm = mm; vma->start = phdr->p_vaddr; vma->end = phdr->p_vaddr + phdr->p_memsz; /* copy the exe contents to the binary's virtual address */ uint64_t size = (((vma->end/0x1000)*0x1000 + 0x1000)-((vma->start/0x1000)*0x1000)); uint64_t itr = size/0x1000; uint64_t start = (phdr->p_vaddr/0x1000)*0x1000; while(itr) { uint64_t page = (uint64_t)allocate_page(); map_process(start, page); itr--; start += 0x1000; } vma->flags = phdr->p_flags; vma->file = NULL; vma->next = NULL; vma->type = NOTYPE; if((phdr->p_flags == (PERM_R | PERM_X)) || (phdr->p_flags == (PERM_R | PERM_W))){ task->mm->start_code = phdr->p_vaddr; task->mm->end_code = phdr->p_vaddr + phdr->p_memsz; vma->file = (struct file *)kmalloc(); vma->file->start = (uint64_t)ehdr; vma->file->pgoff = phdr->p_offset; vma->file->size = phdr->p_filesz; memcpy((void*)vma->start, (void*)((uint64_t)ehdr + phdr->p_offset), phdr->p_filesz); if(phdr->p_flags == (PERM_R | PERM_X)) { vma->file->bss_size = 0; vma->type = TEXT; } else { vma->file->bss_size = phdr->p_memsz - phdr->p_filesz; vma->type = DATA; } } } phdr++; } /* Allocate HEAP */ vma_struct *vma_heap = (vma_struct *)kmalloc(); if(mm->mmap == NULL) mm->mmap = vma_heap; else mm->current->next = vma_heap; mm->current = vma_heap; vma_heap->mm = mm; // if(!mm->end_data) // return 1; vma_heap->start = HEAP_START; mm->brk = HEAP_START; vma_heap->end = HEAP_START + PAGE_SIZE; vma_heap->flags = (PERM_R | PERM_W); vma_heap->type = HEAP; vma_heap->file = NULL; vma_heap->next = NULL; get_phy_addr(HEAP_START); /* Allocate STACK */ vma_struct *vma_stack = (vma_struct *)kmalloc(); if(mm->mmap == NULL) { mm->mmap = vma_stack; } else { mm->current->next = vma_stack; } mm->current = vma_stack; uint64_t *stack = (uint64_t *)get_phy_addr(USER_STACK_TOP); vma_stack->start = (uint64_t)stack + PAGE_SIZE; vma_stack->end = (uint64_t)stack; vma_stack->flags = (PERM_R | PERM_W); vma_stack->type = STACK; vma_stack->file = NULL; vma_stack->next = NULL; task->rsp = (uint64_t)((uint64_t)stack + 4096 - 16); return 0; }