/* Params are pointed to by u_arg[0], offset is in bytes */ int sys_old_mmap(struct tcb *tcp) { long u_arg[6]; #if defined(IA64) /* * IA64 processes never call this routine, they only use the * new 'sys_mmap' interface. Only IA32 processes come here. */ int i; unsigned narrow_arg[6]; if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1) return 0; for (i = 0; i < 6; i++) u_arg[i] = (unsigned long) narrow_arg[i]; #elif defined(X86_64) /* We are here only in personality 1 (i386) */ int i; unsigned narrow_arg[6]; if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1) return 0; for (i = 0; i < 6; ++i) u_arg[i] = (unsigned long) narrow_arg[i]; #else if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1) return 0; #endif return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]); }
void init_xlat_tables(void) { print_mmap(); init_xlation_table(mmap, 0, l1_xlation_table, 1); tcr_ps_bits = calc_physical_addr_size_bits(max_pa); assert(max_va < ADDR_SPACE_SIZE); }
void init_buddy() { get_mmap(); print_mmap(); // request memory for page descriptors // requested pages for all memory until the last available address -- because I can dt_size = (find_max_available_address() / PAGE_SIZE) * sizeof(page_descr); descr_table = (page_descr*) boot_allocate(dt_size); // initialize dt page_descr* prev = heads + 0; for(unsigned int i = 0; i < dt_size; ++i) { set_page_descr(descr_table + i, i, PAGE_DESCRIPTOR_RESERVED, 0, prev, NULL); } //initialize heads for(int i = 0; i < MAX_SIZE; ++i) { set_page_descr(heads + i, 0, PAGE_DESCRIPTOR_FICT, i, NULL, NULL); } //initialize actually available descriptors activate_available_mem(); //print_pages(); }
/* Params are passed directly, offset is in 4k units */ int sys_mmap_4koff(struct tcb *tcp) { unsigned long long offset; offset = (unsigned long) tcp->u_arg[5]; offset <<= 12; return print_mmap(tcp, tcp->u_arg, offset); }
/* Params are passed directly, offset is in pages */ int sys_mmap_pgoff(struct tcb *tcp) { /* Try test/mmap_offset_decode.c */ unsigned long long offset; offset = (unsigned long) tcp->u_arg[5]; offset *= get_pagesize(); return print_mmap(tcp, tcp->u_arg, offset); }
void init_xlat_tables(void) { unsigned long long max_pa; uintptr_t max_va; print_mmap(); init_xlation_table(0, base_xlation_table, XLAT_TABLE_LEVEL_BASE, &max_va, &max_pa); tcr_ps_bits = calc_physical_addr_size_bits(max_pa); assert(max_va < ADDR_SPACE_SIZE); }
extern "C" bool kinit(uint32_t magic, uint32_t multiboot_ptr) { if(MULTIBOOT2_BOOTLOADER_MAGIC != magic) { klog("Not loaded from a multiboot2-compliant bootloader"); return false; } Allocator::global().add_region(KERNEL_HEAP_START, 0x8000); // We want to stash a few values from the multiboot tags before we // initialize our memory management, as we will likely overwrite // Grub's data structures if we don't. multiboot tags; read_multiboot_tags((uintptr_t)multiboot_ptr, &tags); if (tags.acpi_new) { // TODO: Get XSDT pointer } else if (tags.acpi_old) { // TODO: Get RSDT pointer } else { klog("Could not find ACPI tables."); return false; } size_t elf_header_size = tags.shdr->num * tags.shdr->entsize; uint8_t* elf_section_headers = new uint8_t[elf_header_size]; for (size_t i = 0; i < elf_header_size; i++) elf_section_headers[i] = tags.shdr->sections[i]; if(!initialize_page_allocator(tags, PageAllocator::global())) { return false; } // Below here, we risk clobbering any multiboot data, since we're // allocating pages. // TODO: create our real tables, and reclaim pages occupied by // initial ones. // TODO: setup interrupts/error handling // TODO: initialize userspace // TODO: initialize drivers Allocator::global().dump(); klog("\n"); PageAllocator::global().dump(); klog("\n"); print_mmap(tags); klog("\n"); klog("Kernel command line: \"", tags.cmd_line->string, "\"\n"); return true; }
void init_xlat_tables(void) { unsigned long long max_pa; uintptr_t max_va; print_mmap(); init_xlation_table(0, base_xlation_table, XLAT_TABLE_LEVEL_BASE, &max_va, &max_pa); assert(max_va <= PLAT_VIRT_ADDR_SPACE_SIZE - 1); assert(max_pa <= PLAT_PHY_ADDR_SPACE_SIZE - 1); assert((PLAT_PHY_ADDR_SPACE_SIZE - 1) <= get_max_supported_pa()); tcr_ps_bits = calc_physical_addr_size_bits(max_pa); }
/* Params are passed directly, offset is in bytes */ int sys_mmap(struct tcb *tcp) { unsigned long long offset = (unsigned long) tcp->u_arg[5]; #if defined(LINUX_MIPSN32) || defined(X32) /* Try test/x32_mmap.c */ offset = tcp->ext_arg[5]; #endif /* Example of kernel-side handling of this variety of mmap: * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes, * since the above code converts off to pages. */ return print_mmap(tcp, tcp->u_arg, offset); }
/* Params are pointed to by u_arg[0], offset is in pages */ int sys_old_mmap_pgoff(struct tcb *tcp) { long u_arg[5]; int i; unsigned narrow_arg[6]; unsigned long long offset; if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1) return 0; for (i = 0; i < 5; i++) u_arg[i] = (unsigned long) narrow_arg[i]; offset = narrow_arg[5]; offset *= get_pagesize(); return print_mmap(tcp, u_arg, offset); }
static const char *print_a3(const char *val, const rnode *r) { int machine = r->machine, syscall = r->syscall; const char *sys = audit_syscall_to_name(syscall, machine); if (sys) { if (strcmp(sys, "mmap") == 0) return print_mmap(val); else if (strcmp(sys, "mount") == 0) return print_mount(val); else if (strcmp(sys, "recv") == 0) return print_recv(val); else if (strcmp(sys, "recvfrom") == 0) return print_recv(val); else if (strcmp(sys, "recvmmsg") == 0) return print_recv(val); } return strdup(val); }
void init_xlat_tables(void) { print_mmap(); init_xlation_table(mmap, 0, l1_xlation_table, 1); }
int test_print_mmap(){ print_mmap(); return 0; }
void main(uint32_t magic, struct multiboot_info *mbi, uintptr_t esp, uintptr_t stack_end) { stack_start = esp; stack_size = stack_end - stack_start; vga_driver = vga_init(); com_driver = serial_init(); logging_init(vga_driver, com_driver); assert(magic == MULTIBOOT_MAGIC); assert(mbi->flags & MULTIBOOT_LOADER); kprintf(INFO, "\033\012Toutatis kernel booting from %s\033\017\n", (char *)(mbi->boot_loader_name + (uint32_t)&kernel_voffset)); arch_init(); initrd_init(mbi); assert(mbi->flags & MULTIBOOT_MEMINFO); paging_init((mbi->mem_lower + mbi->mem_upper) * 1024); paging_mark_reserved((uint32_t)mbi - (uint32_t)&kernel_voffset); assert(mbi->flags & MULTIBOOT_MMAP); for (mmap_entry_t *mmap = (mmap_entry_t *)(mbi->mmap_addr + (uint32_t)&kernel_voffset); (uint32_t)mmap < mbi->mmap_addr + (uint32_t)&kernel_voffset + mbi->mmap_length; mmap = (mmap_entry_t *)((uint32_t)mmap + mmap->size + sizeof(mmap->size))) { if (mmap->type == 2) { for (uint64_t i = 0; i < mmap->length; i += FRAME_SIZE) { paging_mark_reserved((mmap->addr + i) & 0xfffff000); } } } paging_finalize(); void *p1 = kmalloc(8); void *p2 = kmalloc(8); *((char *)p1) = 'a'; kprintf(INFO, "p1 @ 0x%x\n", (uint32_t)p1); kprintf(INFO, "p2 @ 0x%x\n", (uint32_t)p2); kfree(p2); kfree(p1); void *p3 = kmalloc(16); kprintf(INFO, "p3 @ 0x%x\n", (uint32_t)p3); uintptr_t phys; void *p4 = kmalloc_ap(0x1a0000, &phys); memset(p4, 0, 0x1a0000); *((char *)p4) = 'z'; kprintf(INFO, "p4 @ 0x%x phys = %x\n", (uint32_t)p4, phys); void *p5 = kmalloc(0x02); kprintf(INFO, "p5 @ 0x%x\n", (uint32_t)p5); kfree(p5); kfree(p4); kfree(p3); print_mmap(mbi); syscall_init(); scheduling_init(); keyboard_init(); process_t *proc1 = create_process("Process 1", 1); process_t *proc2 = create_process("Process 2", 1); process_t *proc3 = create_process("Process 3", 1); process_t *procs[] = { proc1, proc2, proc3 }; unsigned int k = 0; unsigned int off = 0; for (k = 0; k < 10; ++k) { if (!create_thread(procs[k % 3], func2, (void *)(off + 80*2), 1, 0, 0)) { kprintf(INFO, "Oups\n"); stop(); } if (!create_thread(procs[k % 3], func1, (void *)k, 1, 1, 0)) { kprintf(INFO, "Oups\n"); stop(); } off += 2; } //create_thread(proc1, func3, (void *)0, 1, 1, 1); k = 0; unsigned int i = 0; off = 0; for (;;) { uint16_t *video = (uint16_t *)(0xc00b8000 + 80); *video = (uint16_t)alph[i++ % sizeof(alph)] | 0x0f00; if (k % 1 == 0) { //set_pos(0, 23); //vga_print_dec(k); //kprintf(INFO, "mem used: %6x num threads:%3d \n", mem_used(kheap), get_num_threads()); } /* if (!create_thread(proc1, func2, (void *)(off + 80*2), 1, 0, 0)) { kprintf(INFO, "Oups\n"); break; } off += 2; off %= (60 * (25-2)); */ char c = keyboard_lastchar(); if (c == 'u') { create_thread(proc1, func1, (void *)5, 1, 1, 0); } else if (c == 'k') { create_thread(proc1, func2, (void *)off, 1, 0, 0); off += 2; } ++k; } serial_terminate(); stop(); }