Changeset 80d301ab in mainline


Ignore:
Timestamp:
2011-11-17T12:45:37Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9d4e170
Parents:
ce940da
Message:

Add amd64 and ia32 support for frame_low/high_arch_init().

Location:
kernel/arch
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/mm/page.c

    rce940da r80d301ab  
    4646#include <panic.h>
    4747#include <align.h>
     48#include <macros.h>
    4849
    4950void page_arch_init(void)
    5051{
    51         if (config.cpu_active == 1) {
    52                 uintptr_t cur;
    53                 unsigned int identity_flags =
    54                     PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE;
     52        if (config.cpu_active > 1) {
     53                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
     54                return;
     55        }
     56
     57        uintptr_t cur;
     58        unsigned int identity_flags =
     59            PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE;
    5560               
    56                 page_mapping_operations = &pt_mapping_operations;
     61        page_mapping_operations = &pt_mapping_operations;
    5762               
    58                 page_table_lock(AS_KERNEL, true);
     63        page_table_lock(AS_KERNEL, true);
    5964               
    60                 /*
    61                  * PA2KA(identity) mapping for all frames.
    62                  */
    63                 for (cur = 0; cur < last_frame; cur += FRAME_SIZE)
    64                         page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, identity_flags);
     65        /*
     66         * PA2KA(identity) mapping for all frames.
     67         */
     68        for (cur = 0; cur < min(config.identity_size, last_frame);
     69            cur += FRAME_SIZE)
     70                page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, identity_flags);
    6571               
    66                 page_table_unlock(AS_KERNEL, true);
     72        page_table_unlock(AS_KERNEL, true);
    6773               
    68                 exc_register(14, "page_fault", true, (iroutine_t) page_fault);
    69                 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    70         } else
    71                 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
     74        exc_register(14, "page_fault", true, (iroutine_t) page_fault);
     75        write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    7276}
    7377
  • kernel/arch/ia32/src/mm/frame.c

    rce940da r80d301ab  
    4646#include <print.h>
    4747
    48 #define PHYSMEM_LIMIT32  UINT64_C(0x07c000000)
    49 #define PHYSMEM_LIMIT64  UINT64_C(0x200000000)
    50 
    5148size_t hardcoded_unmapped_ktext_size = 0;
    5249size_t hardcoded_unmapped_kdata_size = 0;
    5350
     51// XXX: remove me
    5452uintptr_t last_frame = 0;
    5553
    56 static void init_e820_memory(pfn_t minconf)
     54static void init_e820_memory(pfn_t minconf, bool low)
    5755{
    5856        unsigned int i;
     
    6159                uint64_t base = e820table[i].base_address;
    6260                uint64_t size = e820table[i].size;
     61                uintptr_t limit = config.identity_size;
    6362               
    64 #ifdef __32_BITS__
    65                 /*
    66                  * XXX FIXME:
    67                  *
    68                  * Ignore zones which start above PHYSMEM_LIMIT32
    69                  * or clip zones which go beyond PHYSMEM_LIMIT32.
    70                  *
    71                  * The PHYSMEM_LIMIT32 (2 GB - 64 MB) is a rather
    72                  * arbitrary constant which allows to have at
    73                  * least 64 MB in the kernel address space to
    74                  * map hardware resources.
    75                  *
    76                  * The kernel uses fixed 1:1 identity mapping
    77                  * of the physical memory with 2:2 GB split.
    78                  * This is a severe limitation of the current
    79                  * kernel memory management.
    80                  *
    81                  */
    82                
    83                 if (base > PHYSMEM_LIMIT32)
    84                         continue;
    85                
    86                 if (base + size > PHYSMEM_LIMIT32)
    87                         size = PHYSMEM_LIMIT32 - base;
    88 #endif
    89                
    90 #ifdef __64_BITS__
    91                 /*
    92                  * XXX FIXME:
    93                  *
    94                  * Ignore zones which start above PHYSMEM_LIMIT64
    95                  * or clip zones which go beyond PHYSMEM_LIMIT64.
    96                  *
    97                  * The PHYSMEM_LIMIT64 (8 GB) is the size of the
    98                  * fixed 1:1 identically mapped physical memory
    99                  * accessible during the bootstrap process.
    100                  * This is a severe limitation of the current
    101                  * kernel memory management.
    102                  *
    103                  */
    104                
    105                 if (base > PHYSMEM_LIMIT64)
    106                         continue;
    107                
    108                 if (base + size > PHYSMEM_LIMIT64)
    109                         size = PHYSMEM_LIMIT64 - base;
    110 #endif
     63                if (low) {
     64                        if (base > limit)
     65                                continue;
     66                        if (base + size > limit)
     67                                size = limit - base;
     68                } else {
     69                        if (base + size <= limit)
     70                                continue;
     71                        if (base <= limit) {
     72                                size -= limit - base;
     73                                base = limit;
     74                        }
     75                }
    11176               
    11277                if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
     
    11681                            FRAME_SIZE);
    11782                       
     83                        size_t count = SIZE2FRAMES(new_size);
    11884                        pfn_t pfn = ADDR2PFN(new_base);
    119                         size_t count = SIZE2FRAMES(new_size);
     85                        pfn_t conf;
    12086                       
    121                         pfn_t conf;
    122                         if ((minconf < pfn) || (minconf >= pfn + count))
    123                                 conf = pfn;
    124                         else
    125                                 conf = minconf;
     87                        if (low) {
     88                                if ((minconf < pfn) || (minconf >= pfn + count))
     89                                        conf = pfn;
     90                                else
     91                                        conf = minconf;
     92                                zone_create(pfn, count, conf,
     93                                    ZONE_AVAILABLE | ZONE_LOWMEM);
     94                        } else {
     95                                printf("count=%lld\n", (long long int) count);
     96                                conf = zone_external_conf_alloc(count);
     97                                zone_create(pfn, count, conf,
     98                                    ZONE_AVAILABLE | ZONE_HIGHMEM);
     99                        }
    126100                       
    127                         zone_create(pfn, count, conf, ZONE_AVAILABLE);
    128                        
    129                         // XXX this has to be removed
    130                         if (last_frame < ALIGN_UP(new_base + new_size, FRAME_SIZE))
    131                                 last_frame = ALIGN_UP(new_base + new_size, FRAME_SIZE);
     101                        // XXX: remove me
     102                        if (last_frame < new_base + new_size)
     103                                last_frame = new_base + new_size;
    132104                } else if ((e820table[i].type == MEMMAP_MEMORY_ACPI) ||
    133105                    (e820table[i].type == MEMMAP_MEMORY_NVS)) {
     
    192164#endif
    193165               
    194                 init_e820_memory(minconf);
     166                init_e820_memory(minconf, true);
    195167               
    196168                /* Reserve frame 0 (BIOS data) */
     
    208180void frame_high_arch_init(void)
    209181{
     182        if (config.cpu_active == 1)
     183                init_e820_memory(0, false);
    210184}
    211185
  • kernel/arch/ia32/src/mm/page.c

    rce940da r80d301ab  
    4949#include <print.h>
    5050#include <interrupt.h>
     51#include <macros.h>
    5152
    5253void page_arch_init(void)
     
    5556        int flags;
    5657       
    57         if (config.cpu_active == 1) {
    58                 page_mapping_operations = &pt_mapping_operations;
     58        if (config.cpu_active > 1) {
     59                /* Fast path for non-boot CPUs */
     60                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
     61                paging_on();
     62                return;
     63        }
     64
     65        page_mapping_operations = &pt_mapping_operations;
    5966       
    60                 /*
    61                  * PA2KA(identity) mapping for all frames until last_frame.
    62                  */
    63                 page_table_lock(AS_KERNEL, true);
    64                 for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
    65                         flags = PAGE_CACHEABLE | PAGE_WRITE;
    66                         if ((PA2KA(cur) >= config.base) && (PA2KA(cur) < config.base + config.kernel_size))
    67                                 flags |= PAGE_GLOBAL;
    68                         page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
    69                 }
    70                 page_table_unlock(AS_KERNEL, true);
     67        /*
     68         * PA2KA(identity) mapping for all frames until last_frame.
     69         */
     70        page_table_lock(AS_KERNEL, true);
     71        for (cur = 0; cur < min(config.identity_size, last_frame);
     72            cur += FRAME_SIZE) {
     73                flags = PAGE_CACHEABLE | PAGE_WRITE;
     74                if ((PA2KA(cur) >= config.base) && (PA2KA(cur) <
     75                    config.base + config.kernel_size))
     76                        flags |= PAGE_GLOBAL;
     77                page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
     78        }
     79        page_table_unlock(AS_KERNEL, true);
    7180               
    72                 exc_register(14, "page_fault", true, (iroutine_t) page_fault);
    73                 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    74         } else
    75                 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
     81        exc_register(14, "page_fault", true, (iroutine_t) page_fault);
     82        write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    7683       
    7784        paging_on();
Note: See TracChangeset for help on using the changeset viewer.