Write with me. Operating System (v)-Allocating physical memory

Source: Internet
Author: User

Reprint Annotated Source: http://www.cnblogs.com/lucasysfeng/p/4847662.html

Previous address: http://www.cnblogs.com/lucasysfeng/p/5059767.html

Project Address: Https://github.com/lucasysfeng/lucasOS

  

The last one tells us how to allocate physical memory to the physical memory. To simplify the problem, instead of using the partner memory allocation algorithm, we put the available memory on the page to the stack, and each allocation is taken from the stack.

The main code in this lecture is in Lib/pmm.c, and some of the code is given below. The content of this talk is not many, readers see the code can.

void init_pmm () {mmap_entry_t *mmap_start_addr = (mmap_entry_t *) glb_mboot_ptr->mmap_addr;mmap_entry_t *mmap_end_ Addr = (mmap_entry_t *) glb_mboot_ptr->mmap_addr+ glb_mboot_ptr->mmap_length;mmap_entry_t *map_entry;for (map_ Entry = MMAP_START_ADDR; Map_entry < mmap_end_addr; map_entry++) {//Type 1 indicates available memory, other means reserved area, refer to previous multiboot_t structure if (Map_entry->type = = 1 && map_entry->base_ Addr_low = = 0x100000) {//free memory to subtract the memory occupied by the kernel itself uint32_t page_addr = map_entry->base_addr_low+ (uint32_t) (kern_end-kern_ start); uint32_t length = Map_entry->base_addr_low + map_entry->length_low;while (page_addr < length && Page_addr <= pmm_max_size) {pmm_free_page (page_addr);p age_addr + = pmm_page_size;phy_page_count++;}}}

  

void Pmm_free_page (uint32_t p) {assert (Pmm_stack_top! = Page_max_size, "Out of Pmm_stack stack\n");p mm_stack[++pmm_ Stack_top] = p;}

  

Code acquisition

This series of GitHub addresses Https://github.com/lucasysfeng/lucasOS, the code of this lecture is CODE/CHAPTER5.

Write with me. Operating System (v)-Allocating physical memory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.