Changeset 32

Show
Ignore:
Timestamp:
10/12/08 23:43:39
Author:
root
Message:

Finished the init_as() function. We now create a virtual address space for the kernel.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build.sh

    r28 r32  
    268268$RUN 
    269269 
     270INPUT_FILE="\.\/src\/arch\/intel\/as\.c" 
     271OUTPUT_FILE="\.\/bin\/kernel\/as\.o" 
     272RUN=`echo $COMPILER | sed "s/input/$INPUT_FILE/g"` 
     273RUN=`echo $RUN | sed "s/output/$OUTPUT_FILE/g"` 
     274RUN=`echo $RUN | sed "s/flags/$FLAGS/g"` 
     275$RUN 
     276 
    270277# Link all the files together... 
    271278 
  • trunk/src/arch/intel/as.c

    r31 r32  
    88 
    99as_t * 
    10 create_as() 
     10init_as() 
    1111{ 
    1212 
    13         as_t *as = kmem_alloc(sizeof(as_t) * (4096 / (PAGE_SIZE * 1024))); 
     13        as_t *tmp; 
     14        int i, j; 
     15 
     16        #ifdef DEBUG 
     17                kprintf("init_as(): setting up kernel address space...\n"); 
     18        #endif 
     19 
     20        tmp = kmem_alloc(sizeof(as_t)); 
     21        for ( i = 0 ; i < 1024 ; i++ ) { 
     22                 
     23                /* Mark the page as present, kernel level, 
     24                 * read/write and disable caching.  
     25                 */ 
     26                tmp->pd[i].data = 0; 
     27                tmp->pd[i].data |= PAGE_PRESENT; 
     28                tmp->pd[i].data |= PAGE_RW; 
     29                tmp->pd[i].data |= PAGE_CACHEDISABLED; 
     30 
     31                /* Apply our PAGE_MASK to all addresses so 
     32                 * that we only get the first 20 bytes of the 
     33                 * full 32bit address of the page table. 
     34                 */              
     35                tmp->pd[i].data |= (PAGE_MASK & tmp->pt[i].pte[i].data); 
     36 
     37                for ( j = 0 ; j < 1024 ; j++ ) { 
     38 
     39                        /* Again mark the pages as present, kernel level, 
     40                         * read/write and disable caching. 
     41                         */ 
     42                        tmp->pt[i].pte[j].data = 0; 
     43                        tmp->pt[i].pte[j].data |= PAGE_PRESENT; 
     44                        tmp->pt[i].pte[j].data |= PAGE_RW; 
     45                        tmp->pt[i].pte[j].data |= PAGE_CACHEDISABLED; 
     46 
     47                        /* Apply the PAGE_MASK to all addresses so 
     48                         * that we only get the first 20 bytes of the 
     49                         * full 32bit address of the page base. 
     50                         *  
     51                         * The last 10 bits are included in the offset. 
     52                         */ 
     53                        tmp->pt[i].pte[j].data |= (PAGE_MASK & (PAGE_SIZE * 1024 * j)); 
     54 
     55                } 
     56         
     57        } 
     58 
     59 
     60        #ifdef DEBUG 
     61                kprintf("init_as(): kernel address space completed..\n"); 
     62                kprintf("init_as(): enabling pageing...\n"); 
     63        #endif 
     64 
     65        // TODO: Now enable paging. We must do this with asm by 
     66        //       setting BIT32 of CR0 to 1 and then pushing 
     67        //       the address of pde_t into CR3. 
     68         
     69        return tmp; 
    1470 
    1571} 
    16  
  • trunk/src/include/sys/pageing.h

    r31 r32  
    11/* MouthOS (wombat) Kernel 
     2 * 
     3 * #define PAGE_MASK               0xFFFFF000 
    24 * (C) Copyright 2008. Michael F Clarke. All Rights Reserved. 
    35 */ 
     
    8082 */ 
    8183typedef struct pt { 
    82         pte_t[1024] pte
     84        pte_t pte[1024]
    8385} pt_t; 
    8486 
     
    119121typedef struct as { 
    120122 
    121         pde_t[1024] pd
    122         pt_t[1024] pt
     123        pde_t pd[1024]
     124        pt_t pt[1024]
    123125 
    124126} as_t; 
     
    185187#define PAGE_NOT_FREE              4  
    186188 
     189#define PAGE_PRESENT               0x1 
     190#define PAGE_RW                    0x2 
     191#define PAGE_USER                  0x4 
     192#define PAGE_WRITETHROUGH          0x8 
     193#define PAGE_CACHEDISABLED         0x10 
     194#define PAGE_ACCESSED              0x20 
     195#define PAGE_DIRTY                 0x40 
     196#define PAGE_LARGEPAGES            0x80 
     197#define PAGE_GLOBAL                0x100 
     198 
     199#define PAGE_MASK                  0xFFFFF000 
     200 
    187201void init_memory(kinfo_t *kernel_info); 
    188202void *kmem_alloc(int size); 
     
    190204void kmem_free(void *start_addr); 
    191205 
     206as_t *init_as(); 
  • trunk/src/kernel.c

    r28 r32  
    3939        void *tmp; 
    4040 
     41        as_t *kas; 
     42 
    4143        /*  
    4244         * Populate the kernel_info structure with as much information as 
     
    5355        init_memory(&kernel_info); 
    5456        init_sched(); 
     57        kas = init_as(); 
    5558 
    5659        /*  
     
    5861         */ 
    5962        kprintf("Loading MouthOS Kernel...\n"); 
     63        kas = kmem_alloc(sizeof(as_t)); 
    6064        kprintf("Kernel loaded at: 0x%x, Kernel size: %dK\n", 
    6165                 kernel_info.entry_addr, kernel_info.size/1024);