Changeset db3341e in mainline


Ignore:
Timestamp:
2005-09-01T14:28:00Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
623ba26c
Parents:
1dde3b61
Message:

Fixed typo in 'outb' instruction.
Paging basically working.

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/include/asm.h

    r1dde3b61 rdb3341e  
    3737void asm_fake_loop(__u32 t);
    3838
    39 /* TODO: implement the real stuff */
    4039static inline __address get_stack_base(void)
    4140{
    42         return NULL;
     41        __address v;
     42       
     43        __asm__ volatile ("andq %%rsp, %0\n" : "=r" (v) : "0" (~((__u64)STACK_SIZE-1)));
     44       
     45        return v;
    4346}
    4447
     
    5255
    5356        asm (
    54                 "mov %0, %%dx;"
     57                "mov %1, %%dx;"
    5558                "inb %%dx,%%al;"
    56                 "mov %%al, %1;"
     59                "mov %%al, %0;"
    5760                :"=m"(out)
    5861                :"m"(port)
  • arch/amd64/include/mm/page.h

    r1dde3b61 rdb3341e  
    3939
    4040#ifndef __ASM__
    41 # define KA2PA(x)       (((__address) (x)) + 0x80000000)
    42 # define PA2KA(x)       (((__address) (x)) - 0x80000000)
     41# define KA2PA(x)      (((__address) (x)) + 0x80000000)
     42# define PA2KA(x)      (((__address) (x)) - 0x80000000)
    4343#else
    44 # define KA2PA(x)       ((x) + 0x80000000)
    45 # define PA2KA(x)       ((x)) - 0x80000000)
     44# define KA2PA(x)      ((x) + 0x80000000)
     45//# define PA2KA(x)      ((x)) - 0x80000000)
    4646#endif
    4747
    48 #define PTL0_INDEX_ARCH(vaddr)          0
    49 #define PTL1_INDEX_ARCH(vaddr)          0
    50 #define PTL2_INDEX_ARCH(vaddr)          0
    51 #define PTL3_INDEX_ARCH(vaddr)          0
     48#define PTL0_INDEX_ARCH(vaddr)  (((vaddr)>>39)&0x1ff)
     49#define PTL1_INDEX_ARCH(vaddr)  (((vaddr)>>30)&0x1ff)
     50#define PTL2_INDEX_ARCH(vaddr)  (((vaddr)>>21)&0x1ff)
     51#define PTL3_INDEX_ARCH(vaddr)  (((vaddr)>>12)&0x1ff)
    5252
    53 #define GET_PTL0_ADDRESS_ARCH()         0
    54 #define SET_PTL0_ADDRESS_ARCH(ptl0)
     53#define GET_PTL0_ADDRESS_ARCH()                 ((pte_t *) read_cr3())
     54#define GET_PTL1_ADDRESS_ARCH(ptl0, i)          ((pte_t *) ((((__u64) ((pte_t *)(ptl0))[(i)].addr_12_31)<<12) | (((__u64) ((pte_t *)(ptl0))[(i)].addr_32_51)<<32 )))
     55#define GET_PTL2_ADDRESS_ARCH(ptl1, i)          ((pte_t *) ((((__u64) ((pte_t *)(ptl1))[(i)].addr_12_31)<<12) | (((__u64) ((pte_t *)(ptl1))[(i)].addr_32_51)<<32 )))
     56#define GET_PTL3_ADDRESS_ARCH(ptl2, i)          ((pte_t *) ((((__u64) ((pte_t *)(ptl2))[(i)].addr_12_31)<<12) | (((__u64) ((pte_t *)(ptl2))[(i)].addr_32_51)<<32 )))
     57#define GET_FRAME_ADDRESS_ARCH(ptl3, i)         ((__address *) ((((__u64) ((pte_t *)(ptl3))[(i)].addr_12_31)<<12) | (((__u64) ((pte_t *)(ptl3))[(i)].addr_32_51)<<32 )))
    5558
    56 #define GET_PTL1_ADDRESS_ARCH(ptl0, i)          ((pte_t *) 0)
    57 #define GET_PTL2_ADDRESS_ARCH(ptl1, i)          ((pte_t *) 0)
    58 #define GET_PTL3_ADDRESS_ARCH(ptl2, i)          ((pte_t *) 0)
    59 #define GET_FRAME_ADDRESS_ARCH(ptl3, i)         ((pte_t *) 0)
     59#define SET_PTL0_ADDRESS_ARCH(ptl0)             (write_cr3((__address) (ptl0)))
     60#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)       set_pt_addr((pte_t *)(ptl0), (index_t)(i), a)
     61#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)       set_pt_addr((pte_t *)(ptl1), (index_t)(i), a)
     62#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)       set_pt_addr((pte_t *)(ptl2), (index_t)(i), a)
     63#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)      set_pt_addr((pte_t *)(ptl3), (index_t)(i), a)
    6064
    61 #define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)
    62 #define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
    63 #define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
    64 #define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)
     65#define GET_PTL1_FLAGS_ARCH(ptl0, i)            get_pt_flags((pte_t *)(ptl0), (index_t)(i))
     66#define GET_PTL2_FLAGS_ARCH(ptl1, i)            get_pt_flags((pte_t *)(ptl1), (index_t)(i))
     67#define GET_PTL3_FLAGS_ARCH(ptl2, i)            get_pt_flags((pte_t *)(ptl2), (index_t)(i))
     68#define GET_FRAME_FLAGS_ARCH(ptl3, i)           get_pt_flags((pte_t *)(ptl3), (index_t)(i))
    6569
    66 #define GET_PTL1_FLAGS_ARCH(ptl0, i)            0
    67 #define GET_PTL2_FLAGS_ARCH(ptl1, i)            0
    68 #define GET_PTL3_FLAGS_ARCH(ptl2, i)            0
    69 #define GET_FRAME_FLAGS_ARCH(ptl3, i)           0
    70 
    71 #define SET_PTL1_FLAGS_ARCH(ptl0, i, x)
    72 #define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
    73 #define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
    74 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x)
     70#define SET_PTL1_FLAGS_ARCH(ptl0, i, x)         set_pt_flags((pte_t *)(ptl0), (index_t)(i), (x))
     71#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)         set_pt_flags((pte_t *)(ptl1), (index_t)(i), (x))
     72#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)         set_pt_flags((pte_t *)(ptl2), (index_t)(i), (x))
     73#define SET_FRAME_FLAGS_ARCH(ptl3, i, x)        set_pt_flags((pte_t *)(ptl3), (index_t)(i), (x))
    7574
    7675#ifndef __ASM__
     76
     77typedef struct page_specifier pte_t;
     78
     79struct page_specifier {
     80        unsigned present : 1;
     81        unsigned writeable : 1;
     82        unsigned uaccessible : 1;
     83        unsigned page_write_through : 1;
     84        unsigned page_cache_disable : 1;
     85        unsigned accessed : 1;
     86        unsigned dirty : 1;
     87        unsigned unused: 1;
     88        unsigned global : 1;
     89        unsigned avl : 3;
     90        unsigned addr_12_31 : 30;
     91        unsigned addr_32_51 : 21;
     92        unsigned no_execute : 1;
     93} __attribute__ ((packed));
     94
     95static inline int get_pt_flags(pte_t *pt, index_t i)
     96{
     97        pte_t *p = &pt[i];
     98       
     99        return (
     100                (!p->page_cache_disable)<<PAGE_CACHEABLE_SHIFT |
     101                (!p->present)<<PAGE_PRESENT_SHIFT |
     102                p->uaccessible<<PAGE_USER_SHIFT |
     103                1<<PAGE_READ_SHIFT |
     104                p->writeable<<PAGE_WRITE_SHIFT |
     105                (!p->no_execute)<<PAGE_EXEC_SHIFT
     106        );
     107}
     108
     109static inline void set_pt_addr(pte_t *pt, index_t i, __address a)
     110{
     111        pte_t *p = &pt[i];
     112
     113        p->addr_12_31 = (a >> 12) & 0xfffff;
     114        p->addr_32_51 = a >> 32;
     115}
     116
     117static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
     118{
     119        pte_t *p = &pt[i];
     120       
     121        p->page_cache_disable = !(flags & PAGE_CACHEABLE);
     122        p->present = !(flags & PAGE_NOT_PRESENT);
     123        p->uaccessible = (flags & PAGE_USER) != 0;
     124        p->writeable = (flags & PAGE_WRITE) != 0;
     125        p->no_execute = (flags & PAGE_EXEC) == 0;
     126}
     127
    77128extern void page_arch_init(void);
    78129
    79 typedef __u64 pte_t;
    80130#endif
    81131
  • arch/amd64/src/mm/page.c

    r1dde3b61 rdb3341e  
    2828
    2929#include <mm/page.h>
     30#include <mm/frame.h>
    3031#include <arch/mm/page.h>
     32#include <arch/interrupt.h>
     33#include <arch/asm.h>
     34#include <config.h>
     35
     36#include <memstr.h>
     37
     38
     39__address bootstrap_dba;
    3140
    3241void page_arch_init(void)
    3342{
     43        __address dba;
     44        count_t i;
     45
     46        if (config.cpu_active == 1) {
     47                dba = frame_alloc(FRAME_KA | FRAME_PANIC);
     48                memsetb(dba, PAGE_SIZE, 0);
     49
     50                bootstrap_dba = dba;
     51
     52                /*
     53                 * Identity mapping for all frames.
     54                 * PA2KA(identity) mapping for all frames.
     55                 */
     56                for (i = 0; i < frames; i++) {
     57                        map_page_to_frame(i * PAGE_SIZE, i * PAGE_SIZE, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
     58                        map_page_to_frame(PA2KA(i * PAGE_SIZE), i * PAGE_SIZE, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
     59                }
     60
     61                trap_register(14, page_fault);
     62                write_cr3(KA2PA(dba));
     63        }
     64        else {
     65                /*
     66                 * Application processors need to create their own view of the
     67                 * virtual address space. Because of that, each AP copies
     68                 * already-initialized paging information from the bootstrap
     69                 * processor and adjusts it to fulfill its needs.
     70                 */
     71
     72                dba = frame_alloc(FRAME_KA | FRAME_PANIC);
     73                memcpy((void *)dba, (void *)bootstrap_dba , PAGE_SIZE);
     74                write_cr3(KA2PA(dba));
     75        }
    3476}
  • src/build.amd64

    r1dde3b61 rdb3341e  
    55(cd ../arch/amd64/src;make gencontext;./gencontext)
    66# Create links to ia32 architecture
    7 for a in drivers bios interrupt.c; do
     7for a in drivers bios; do
    88  ln -sf ../../ia32/src/$a ../arch/amd64/src/
    99done
  • src/mm/page.c

    r1dde3b61 rdb3341e  
    3737
    3838void page_init(void)
    39 {       
     39{
    4040        page_arch_init();
    4141        map_page_to_frame(0x0, 0x0, PAGE_NOT_PRESENT, 0);
     
    5555        int i, cnt, length;
    5656
    57         /* TODO: implement portable way of computing page address from address */
    58         length = size + (s - (s & 0xfffff000));
     57        length = size + (s - (s & ~(PAGE_SIZE-1)));
    5958        cnt = length/PAGE_SIZE + (length%PAGE_SIZE>0);
    6059
Note: See TracChangeset for help on using the changeset viewer.