Changeset 94d211e in mainline


Ignore:
Timestamp:
2018-03-21T19:32:48Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
1c7a170
Parents:
973be387
Message:

Change the way page flags work. TODO description

Location:
kernel
Files:
48 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/abs32le/include/arch/mm/page.h

    r973be387 r94d211e  
    9292        get_pt_flags((pte_t *) (ptl0), (size_t) (i))
    9393#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
    94         PAGE_PRESENT
     94        PAGE_NEXT_LEVEL_PT
    9595#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
    96         PAGE_PRESENT
     96        PAGE_NEXT_LEVEL_PT
    9797#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
    9898        get_pt_flags((pte_t *) (ptl3), (size_t) (i))
     
    121121#define PTE_GET_FRAME_ARCH(p) \
    122122        ((p)->frame_address << FRAME_WIDTH)
     123#define PTE_READABLE_ARCH(p) \
     124        1
    123125#define PTE_WRITABLE_ARCH(p) \
    124126        ((p)->writeable != 0)
    125 #define PTE_EXECUTABLE_ARCH(p)  1
     127#define PTE_EXECUTABLE_ARCH(p) \
     128        1
    126129
    127130#include <mm/mm.h>
     
    154157        return (
    155158            ((unsigned int) (!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT) |
    156             ((unsigned int) (!p->present) << PAGE_PRESENT_SHIFT) |
     159            ((unsigned int) (!p->present) << PAGE_NOT_PRESENT_SHIFT) |
    157160            ((unsigned int) p->uaccessible << PAGE_USER_SHIFT) |
    158161            (1 << PAGE_READ_SHIFT) |
     
    172175        p->present = !(flags & PAGE_NOT_PRESENT);
    173176        p->uaccessible = (flags & PAGE_USER) != 0;
    174         p->writeable = (flags & PAGE_WRITE) != 0;
     177        p->writeable = (flags & _PAGE_WRITE) != 0;
    175178        p->global = (flags & PAGE_GLOBAL) != 0;
    176179
  • kernel/arch/amd64/include/arch/mm/page.h

    r973be387 r94d211e  
    157157        ((((uintptr_t) (p)->addr_12_31) << 12) | \
    158158            ((uintptr_t) (p)->addr_32_51 << 32))
     159#define PTE_READABLE_ARCH(p) \
     160        1
    159161#define PTE_WRITABLE_ARCH(p) \
    160162        ((p)->writeable != 0)
     
    211213        pte_t *p = &pt[i];
    212214
    213         return ((!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT |
    214             (!p->present) << PAGE_PRESENT_SHIFT |
    215             p->uaccessible << PAGE_USER_SHIFT |
     215        return ((p->page_cache_disable ? PAGE_NOT_CACHEABLE : PAGE_CACHEABLE) |
     216            (!p->present) << PAGE_NOT_PRESENT_SHIFT |
     217            (!p->uaccessible)  << PAGE_KERNEL_SHIFT |
    216218            1 << PAGE_READ_SHIFT |
    217219            p->writeable << PAGE_WRITE_SHIFT |
     
    234236        p->page_cache_disable = !(flags & PAGE_CACHEABLE);
    235237        p->present = !(flags & PAGE_NOT_PRESENT);
    236         p->uaccessible = (flags & PAGE_USER) != 0;
    237         p->writeable = (flags & PAGE_WRITE) != 0;
    238         p->no_execute = (flags & PAGE_EXEC) == 0;
     238        p->uaccessible = !(flags & PAGE_KERNEL);
     239        p->writeable = (flags & _PAGE_WRITE) != 0;
     240        p->no_execute = (flags & _PAGE_EXEC) == 0;
    239241        p->global = (flags & PAGE_GLOBAL) != 0;
    240242
  • kernel/arch/amd64/src/mm/page.c

    r973be387 r94d211e  
    5555
    5656        uintptr_t cur;
    57         unsigned int identity_flags =
    58             PAGE_GLOBAL | PAGE_CACHEABLE | PAGE_EXEC | PAGE_WRITE | PAGE_READ;
     57        unsigned int identity_flags = PAGE_READ_WRITE_EXECUTE |
     58            PAGE_CACHEABLE | PAGE_KERNEL | PAGE_GLOBAL;
    5959
    6060        page_mapping_operations = &pt_mapping_operations;
  • kernel/arch/amd64/src/vreg.c

    r973be387 r94d211e  
    6767
    6868        page = (uint64_t *) km_map(frame, PAGE_SIZE,
    69             PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE);
     69            PAGE_READ_WRITE | PAGE_USER | PAGE_CACHEABLE);
    7070
    7171        write_msr(AMD_MSR_FS, (uintptr_t) page);
  • kernel/arch/arm32/include/arch/mm/page.h

    r973be387 r94d211e  
    108108        get_pt_level0_flags((pte_t *) (ptl0), (size_t) (i))
    109109#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
    110         PAGE_PRESENT
     110        PAGE_NEXT_LEVEL_PT
    111111#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
    112         PAGE_PRESENT
     112        PAGE_NEXT_LEVEL_PT
    113113#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
    114114        get_pt_level1_flags((pte_t *) (ptl3), (size_t) (i))
  • kernel/arch/arm32/include/arch/mm/page_armv4.h

    r973be387 r94d211e  
    4949#define PTE_GET_FRAME_ARCH(pte) \
    5050        (((uintptr_t) ((pte_t *) (pte))->l1.frame_base_addr) << FRAME_WIDTH)
     51#define PTE_READABLE_ARCH(pte) \
     52        1
    5153#define PTE_WRITABLE_ARCH(pte) \
    5254        (((pte_t *) (pte))->l1.access_permission_0 == PTE_AP_USER_RW_KERNEL_RW)
     
    138140        int np = (p->descriptor_type == PTE_DESCRIPTOR_NOT_PRESENT);
    139141
    140         return (np << PAGE_PRESENT_SHIFT) | (1 << PAGE_USER_SHIFT) |
    141             (1 << PAGE_READ_SHIFT) | (1 << PAGE_WRITE_SHIFT) |
    142             (1 << PAGE_EXEC_SHIFT) | (1 << PAGE_CACHEABLE_SHIFT);
     142        return (np << PAGE_NOT_PRESENT_SHIFT) | PAGE_NEXT_LEVEL_PT;
    143143}
    144144
     
    156156        int ap = p->access_permission_0;
    157157
    158         return ((dt == PTE_DESCRIPTOR_NOT_PRESENT) << PAGE_PRESENT_SHIFT) |
     158        return ((dt == PTE_DESCRIPTOR_NOT_PRESENT) << PAGE_NOT_PRESENT_SHIFT) |
    159159            ((ap == PTE_AP_USER_RO_KERNEL_RW) << PAGE_READ_SHIFT) |
    160160            ((ap == PTE_AP_USER_RW_KERNEL_RW) << PAGE_READ_SHIFT) |
     
    164164            ((ap == PTE_AP_USER_NO_KERNEL_RW) << PAGE_WRITE_SHIFT) |
    165165            (1 << PAGE_EXEC_SHIFT) |
    166             (p->bufferable << PAGE_CACHEABLE);
     166            (p->bufferable ? PAGE_CACHEABLE : PAGE_NOT_CACHEABLE);
    167167}
    168168
     
    220220
    221221        if (flags & PAGE_USER)  {
    222                 if (flags & PAGE_READ) {
     222                if (flags & _PAGE_READ) {
    223223                        p->access_permission_0 = p->access_permission_1 =
    224224                            p->access_permission_2 = p->access_permission_3 =
    225225                            PTE_AP_USER_RO_KERNEL_RW;
    226226                }
    227                 if (flags & PAGE_WRITE) {
     227                if (flags & _PAGE_WRITE) {
    228228                        p->access_permission_0 = p->access_permission_1 =
    229229                            p->access_permission_2 = p->access_permission_3 =
  • kernel/arch/arm32/include/arch/mm/page_armv6.h

    r973be387 r94d211e  
    4949#define PTE_GET_FRAME_ARCH(pte) \
    5050        (((uintptr_t) ((pte_t *) (pte))->l1.frame_base_addr) << FRAME_WIDTH)
     51#define PTE_READABLE_ARCH(pte) \
     52        1
    5153#define PTE_WRITABLE_ARCH(pte) \
    5254        (((pte_t *) (pte))->l1.access_permission_1 != PTE_AP1_RO)
     
    171173        const unsigned np = (p->descriptor_type == PTE_DESCRIPTOR_NOT_PRESENT);
    172174
    173         return (np << PAGE_PRESENT_SHIFT) | (1 << PAGE_USER_SHIFT) |
    174             (1 << PAGE_READ_SHIFT) | (1 << PAGE_WRITE_SHIFT) |
    175             (1 << PAGE_EXEC_SHIFT) | (1 << PAGE_CACHEABLE_SHIFT);
     175        return (np << PAGE_NOT_PRESENT_SHIFT) | PAGE_NEXT_LEVEL_PT;
    176176}
    177177
     
    190190        const unsigned ap1 = p->access_permission_1;
    191191
    192         return ((dt == PTE_DESCRIPTOR_NOT_PRESENT) << PAGE_PRESENT_SHIFT) |
     192        return ((dt == PTE_DESCRIPTOR_NOT_PRESENT) << PAGE_NOT_PRESENT_SHIFT) |
    193193            ((dt != PTE_DESCRIPTOR_SMALL_PAGE_NX) << PAGE_EXEC_SHIFT) |
    194194            ((ap0 == PTE_AP0_USER_LIMITED_KERNEL_FULL) << PAGE_READ_SHIFT) |
     
    198198            (((ap1 != PTE_AP1_RO) && (ap0 == PTE_AP0_USER_FULL_KERNEL_FULL)) << PAGE_WRITE_SHIFT) |
    199199            (((ap1 != PTE_AP1_RO) && (ap0 == PTE_AP0_USER_NO_KERNEL_FULL)) << PAGE_WRITE_SHIFT) |
    200             (p->bufferable << PAGE_CACHEABLE);
     200            (p->bufferable ? PAGE_CACHEABLE : PAGE_NOT_CACHEABLE);
    201201}
    202202
     
    249249                p->descriptor_type = PTE_DESCRIPTOR_NOT_PRESENT;
    250250        } else {
    251                 if (flags & PAGE_EXEC)
     251                if (flags & _PAGE_EXEC)
    252252                        p->descriptor_type = PTE_DESCRIPTOR_SMALL_PAGE;
    253253                else
     
    288288        p->access_permission_0 = PTE_AP0_USER_NO_KERNEL_FULL;
    289289
    290         if (flags & PAGE_USER) {
     290        if (flags & PAGE_USER)
    291291                p->access_permission_0 = PTE_AP0_USER_FULL_KERNEL_FULL;
    292                 // TODO Fix kernel to use PAGE_WRITE flag properly and
    293                 // apply this for kernel pages as well.
    294                 if (!(flags & PAGE_WRITE))
    295                         p->access_permission_1 = PTE_AP1_RO;
    296         }
     292
     293        if (!(flags & _PAGE_WRITE))
     294                p->access_permission_1 = PTE_AP1_RO;
     295
    297296        pt_coherence(p);
    298297}
  • kernel/arch/arm32/src/mach/beagleboardxm/beagleboardxm.c

    r973be387 r94d211e  
    101101        beagleboard.irc_addr =
    102102            (void *) km_map(AMDM37x_IRC_BASE_ADDRESS, AMDM37x_IRC_SIZE,
    103             PAGE_NOT_CACHEABLE);
     103            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    104104        assert(beagleboard.irc_addr);
    105105        omap_irc_init(beagleboard.irc_addr);
  • kernel/arch/arm32/src/mach/beaglebone/beaglebone.c

    r973be387 r94d211e  
    8787{
    8888        bbone.irc_addr = (void *) km_map(AM335x_IRC_BASE_ADDRESS,
    89             AM335x_IRC_SIZE, PAGE_NOT_CACHEABLE);
     89            AM335x_IRC_SIZE,
     90            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9091
    9192        bbone.cm_per_addr = (void *) km_map(AM335x_CM_PER_BASE_ADDRESS,
    92             AM335x_CM_PER_SIZE, PAGE_NOT_CACHEABLE);
     93            AM335x_CM_PER_SIZE,
     94            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9395
    9496        bbone.cm_dpll_addr = (void *) km_map(AM335x_CM_DPLL_BASE_ADDRESS,
    95             AM335x_CM_DPLL_SIZE, PAGE_NOT_CACHEABLE);
     97            AM335x_CM_DPLL_SIZE,
     98            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9699
    97100        bbone.ctrl_module = (void *) km_map(AM335x_CTRL_MODULE_BASE_ADDRESS,
    98             AM335x_CTRL_MODULE_SIZE, PAGE_NOT_CACHEABLE);
     101            AM335x_CTRL_MODULE_SIZE,
     102            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    99103
    100104        assert(bbone.irc_addr != NULL);
  • kernel/arch/arm32/src/mach/gta02/gta02.c

    r973be387 r94d211e  
    103103
    104104        gta02_timer = (void *) km_map(S3C24XX_TIMER_ADDRESS, PAGE_SIZE,
    105             PAGE_NOT_CACHEABLE);
     105            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    106106        irqc_regs = (void *) km_map(S3C24XX_IRQC_ADDRESS, PAGE_SIZE,
    107             PAGE_NOT_CACHEABLE);
     107            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    108108
    109109        /* Initialize interrupt controller. */
  • kernel/arch/arm32/src/mach/integratorcp/integratorcp.c

    r973be387 r94d211e  
    135135{
    136136        icp.hw_map.uart = km_map(ICP_UART, PAGE_SIZE,
    137             PAGE_WRITE | PAGE_NOT_CACHEABLE);
    138         icp.hw_map.kbd_ctrl = km_map(ICP_KBD, PAGE_SIZE, PAGE_NOT_CACHEABLE);
     137            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     138        icp.hw_map.kbd_ctrl = km_map(ICP_KBD, PAGE_SIZE,
     139            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    139140        icp.hw_map.kbd_stat = icp.hw_map.kbd_ctrl + ICP_KBD_STAT;
    140141        icp.hw_map.kbd_data = icp.hw_map.kbd_ctrl + ICP_KBD_DATA;
    141142        icp.hw_map.kbd_intstat = icp.hw_map.kbd_ctrl + ICP_KBD_INTR_STAT;
    142143        icp.hw_map.rtc = km_map(ICP_RTC, PAGE_SIZE,
    143             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     144            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    144145        icp.hw_map.rtc1_load = icp.hw_map.rtc + ICP_RTC1_LOAD_OFFSET;
    145146        icp.hw_map.rtc1_read = icp.hw_map.rtc + ICP_RTC1_READ_OFFSET;
     
    150151
    151152        icp.hw_map.irqc = km_map(ICP_IRQC, PAGE_SIZE,
    152             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     153            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    153154        icp.hw_map.irqc_mask = icp.hw_map.irqc + ICP_IRQC_MASK_OFFSET;
    154155        icp.hw_map.irqc_unmask = icp.hw_map.irqc + ICP_IRQC_UNMASK_OFFSET;
    155156        icp.hw_map.cmcr = km_map(ICP_CMCR, PAGE_SIZE,
    156             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     157            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    157158        icp.hw_map.sdramcr = icp.hw_map.cmcr + ICP_SDRAMCR_OFFSET;
    158159        icp.hw_map.vga = km_map(ICP_VGA, PAGE_SIZE,
    159             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     160            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    160161
    161162        hw_map_init_called = true;
  • kernel/arch/arm32/src/mach/raspberrypi/raspberrypi.c

    r973be387 r94d211e  
    102102        /* Initialize interrupt controller */
    103103        raspi.irc = (void *) km_map(BCM2835_IRC_ADDR, sizeof(bcm2835_irc_t),
    104                                     PAGE_NOT_CACHEABLE);
     104            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    105105        assert(raspi.irc);
    106106        bcm2835_irc_init(raspi.irc);
     
    108108        /* Initialize system timer */
    109109        raspi.timer = (void *) km_map(BCM2835_TIMER_ADDR,
    110                                       sizeof(bcm2835_timer_t),
    111                                       PAGE_NOT_CACHEABLE);
     110              sizeof(bcm2835_timer_t),
     111              PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    112112}
    113113
  • kernel/arch/arm32/src/mm/page.c

    r973be387 r94d211e  
    5252void page_arch_init(void)
    5353{
    54         int flags = PAGE_CACHEABLE | PAGE_EXEC;
     54        int flags = PAGE_READ_WRITE_EXECUTE | PAGE_KERNEL | PAGE_CACHEABLE;
    5555        page_mapping_operations = &pt_mapping_operations;
    5656
  • kernel/arch/arm32/src/ras.c

    r973be387 r94d211e  
    5757
    5858        ras_page = (uintptr_t *) km_map(frame,
    59             PAGE_SIZE, PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE);
     59            PAGE_SIZE, PAGE_READ_WRITE | PAGE_USER | PAGE_CACHEABLE);
    6060
    6161        memsetb(ras_page, PAGE_SIZE, 0);
  • kernel/arch/ia32/include/arch/mm/page.h

    r973be387 r94d211e  
    109109        get_pt_flags((pte_t *) (ptl0), (size_t) (i))
    110110#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
    111         PAGE_PRESENT
     111        PAGE_NEXT_LEVEL_PT
    112112#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
    113         PAGE_PRESENT
     113        PAGE_NEXT_LEVEL_PT
    114114#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
    115115        get_pt_flags((pte_t *) (ptl3), (size_t) (i))
     
    138138#define PTE_GET_FRAME_ARCH(p) \
    139139        ((p)->frame_address << FRAME_WIDTH)
     140#define PTE_READABLE_ARCH(p) \
     141        1
    140142#define PTE_WRITABLE_ARCH(p) \
    141143        ((p)->writeable != 0)
    142 #define PTE_EXECUTABLE_ARCH(p)  1
     144#define PTE_EXECUTABLE_ARCH(p) \
     145        1
    143146
    144147#ifndef __ASSEMBLER__
     
    184187        pte_t *p = &pt[i];
    185188
    186         return ((!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT |
    187             (!p->present) << PAGE_PRESENT_SHIFT |
    188             p->uaccessible << PAGE_USER_SHIFT |
    189             1 << PAGE_READ_SHIFT |
     189        return ((p->page_cache_disable ? PAGE_NOT_CACHEABLE : PAGE_CACHEABLE) |
     190            (!p->present) << PAGE_NOT_PRESENT_SHIFT |
     191            (p->uaccessible ? PAGE_USER : PAGE_KERNEL) |
     192            _PAGE_READ |
    190193            p->writeable << PAGE_WRITE_SHIFT |
    191             1 << PAGE_EXEC_SHIFT |
     194            _PAGE_EXEC |
    192195            p->global << PAGE_GLOBAL_SHIFT);
    193196}
     
    199202        p->page_cache_disable = !(flags & PAGE_CACHEABLE);
    200203        p->present = !(flags & PAGE_NOT_PRESENT);
    201         p->uaccessible = (flags & PAGE_USER) != 0;
    202         p->writeable = (flags & PAGE_WRITE) != 0;
     204        p->uaccessible = !(flags & PAGE_KERNEL);
     205        p->writeable = (flags & _PAGE_WRITE) != 0;
    203206        p->global = (flags & PAGE_GLOBAL) != 0;
    204207
  • kernel/arch/ia32/src/mm/page.c

    r973be387 r94d211e  
    7070        for (cur = 0; cur < min(config.identity_size, config.physmem_end);
    7171            cur += FRAME_SIZE) {
    72                 flags = PAGE_GLOBAL | PAGE_CACHEABLE | PAGE_WRITE | PAGE_READ;
     72                flags = PAGE_READ_WRITE | PAGE_KERNEL | PAGE_GLOBAL | PAGE_CACHEABLE;
    7373                page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
    7474        }
  • kernel/arch/ia32/src/smp/smp.c

    r973be387 r94d211e  
    7575
    7676        if (config.cpu_count > 1) {
    77                 l_apic = (uint32_t *) km_map((uintptr_t) l_apic, PAGE_SIZE,
    78                     PAGE_WRITE | PAGE_NOT_CACHEABLE);
    79                 io_apic = (uint32_t *) km_map((uintptr_t) io_apic, PAGE_SIZE,
    80                     PAGE_WRITE | PAGE_NOT_CACHEABLE);
     77                l_apic = (uint32_t *) km_map((uintptr_t) l_apic,
     78                    PAGE_SIZE,
     79                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     80                io_apic = (uint32_t *) km_map((uintptr_t) io_apic,
     81                    PAGE_SIZE,
     82                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    8183        }
    8284}
  • kernel/arch/ia32/src/vreg.c

    r973be387 r94d211e  
    6868
    6969        page = (uint32_t *) km_map(frame, PAGE_SIZE,
    70             PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE);
     70            PAGE_READ_WRITE | PAGE_USER | PAGE_CACHEABLE);
    7171
    7272        gdt_setbase(&gdt_p[VREG_DES], (uintptr_t) page);
  • kernel/arch/ia64/src/ia64.c

    r973be387 r94d211e  
    106106{
    107107        uintptr_t IOSAPIC = km_map(iosapic_base, PAGE_SIZE,
    108             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     108            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    109109        int i;
    110110
     
    135135                /* Map the page with legacy I/O. */
    136136                legacyio_virt_base = km_map(LEGACYIO_PHYS_BASE, LEGACYIO_SIZE,
    137                     PAGE_WRITE | PAGE_NOT_CACHEABLE);
     137                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    138138
    139139                iosapic_init();
  • kernel/arch/ia64/src/mm/page.c

    r973be387 r94d211e  
    246246        v->present.d = false;  /* not dirty */
    247247        v->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL;
    248         v->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ;
    249         v->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0;
     248        v->present.ar = (flags & _PAGE_WRITE) ? AR_WRITE : AR_READ;
     249        v->present.ar |= (flags & _PAGE_EXEC) ? AR_EXECUTE : 0;
    250250        v->present.ppn = frame >> PPN_SHIFT;
    251251        v->present.ed = false;  /* exception not deffered */
  • kernel/arch/mips32/include/arch/mm/page.h

    r973be387 r94d211e  
    114114        get_pt_flags((pte_t *) (ptl0), (size_t) (i))
    115115#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
    116         PAGE_PRESENT
     116        PAGE_NEXT_LEVEL_PT
    117117#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
    118         PAGE_PRESENT
     118        PAGE_NEXT_LEVEL_PT
    119119#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
    120120        get_pt_flags((pte_t *) (ptl3), (size_t) (i))
     
    140140#define PTE_PRESENT_ARCH(pte)           ((pte)->p != 0)
    141141#define PTE_GET_FRAME_ARCH(pte)         ((pte)->pfn << 12)
     142#define PTE_READABLE_ARCH(pte)          1
    142143#define PTE_WRITABLE_ARCH(pte)          ((pte)->w != 0)
    143144#define PTE_EXECUTABLE_ARCH(pte)        1
     
    147148#include <mm/mm.h>
    148149#include <arch/exception.h>
     150
     151// FIXME: PAGE_USER / PAGE_KERNEL handling?
    149152
    150153/** Page Table Entry. */
     
    167170
    168171        return ((p->cacheable << PAGE_CACHEABLE_SHIFT) |
    169             ((!p->p) << PAGE_PRESENT_SHIFT) |
     172            ((!p->p) << PAGE_NOT_PRESENT_SHIFT) |
    170173            (1 << PAGE_USER_SHIFT) |
    171174            (1 << PAGE_READ_SHIFT) |
     
    182185        p->p = !(flags & PAGE_NOT_PRESENT);
    183186        p->g = (flags & PAGE_GLOBAL) != 0;
    184         p->w = (flags & PAGE_WRITE) != 0;
     187        p->w = (flags & _PAGE_WRITE) != 0;
    185188
    186189        /*
  • kernel/arch/ppc32/include/arch/mm/page.h

    r973be387 r94d211e  
    111111
    112112#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
    113         PAGE_PRESENT
     113        PAGE_NEXT_LEVEL_PT
    114114
    115115#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
    116         PAGE_PRESENT
     116        PAGE_NEXT_LEVEL_PT
    117117
    118118#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
     
    143143#define PTE_PRESENT_ARCH(pte)     ((pte)->present != 0)
    144144#define PTE_GET_FRAME_ARCH(pte)   ((pte)->pfn << 12)
     145#define PTE_READABLE_ARCH(pte)    1
    145146#define PTE_WRITABLE_ARCH(pte)    1
    146147#define PTE_EXECUTABLE_ARCH(pte)  1
     
    167168
    168169        return (((!entry->page_cache_disable) << PAGE_CACHEABLE_SHIFT) |
    169             ((!entry->present) << PAGE_PRESENT_SHIFT) |
     170            ((!entry->present) << PAGE_NOT_PRESENT_SHIFT) |
    170171            (1 << PAGE_USER_SHIFT) |
    171172            (1 << PAGE_READ_SHIFT) |
  • kernel/arch/ppc32/src/drivers/pic.c

    r973be387 r94d211e  
    4242void pic_init(uintptr_t base, size_t size, cir_t *cir, void **cir_arg)
    4343{
    44         pic = (uint32_t *) km_map(base, size, PAGE_WRITE | PAGE_NOT_CACHEABLE);
     44        pic = (uint32_t *) km_map(base, size,
     45            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    4546        *cir = pic_ack_interrupt;
    4647        *cir_arg = NULL;
  • kernel/arch/ppc32/src/ppc32.c

    r973be387 r94d211e  
    242242
    243243                cuda_t *cuda = (cuda_t *) (km_map(aligned_addr, offset + size,
    244                     PAGE_WRITE | PAGE_NOT_CACHEABLE) + offset);
     244                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE) + offset);
    245245
    246246                /* Initialize I/O controller */
  • kernel/arch/riscv64/include/arch/mm/page.h

    r973be387 r94d211e  
    8282
    8383/* Flags mask for non-leaf page table entries */
    84 #define NON_LEAF_MASK  (~(PAGE_READ | PAGE_WRITE | PAGE_EXEC))
     84#define NON_LEAF_MASK  (~(_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC))
    8585
    8686/* Get PTE address accessors for each level. */
     
    156156#define PTE_PRESENT_ARCH(pte)     ((pte)->valid != 0)
    157157#define PTE_GET_FRAME_ARCH(pte)   ((uintptr_t) (pte)->pfn << 12)
     158#define PTE_READABLE_ARCH(pte)    ((pte)->readable != 0)
    158159#define PTE_WRITABLE_ARCH(pte)    ((pte)->writable != 0)
    159160#define PTE_EXECUTABLE_ARCH(pte)  ((pte)->executable != 0)
     
    183184        pte_t *entry = &pt[i];
    184185
    185         return (((!entry->valid) << PAGE_PRESENT_SHIFT) |
     186        return (((!entry->valid) << PAGE_NOT_PRESENT_SHIFT) |
    186187            (entry->user << PAGE_USER_SHIFT) |
    187188            (entry->readable << PAGE_READ_SHIFT) |
     
    196197
    197198        entry->valid = !(flags & PAGE_NOT_PRESENT);
    198         entry->readable = (flags & PAGE_READ) != 0;
    199         entry->writable = (flags & PAGE_WRITE) != 0;
    200         entry->executable = (flags & PAGE_EXEC) != 0;
     199        entry->readable = (flags & _PAGE_READ) != 0;
     200        entry->writable = (flags & _PAGE_WRITE) != 0;
     201        entry->executable = (flags & _PAGE_EXEC) != 0;
    201202        entry->user = (flags & PAGE_USER) != 0;
    202203        entry->global = (flags & PAGE_GLOBAL) != 0;
  • kernel/arch/riscv64/src/mm/page.c

    r973be387 r94d211e  
    6363                    cur += FRAME_SIZE)
    6464                        page_mapping_insert(AS_KERNEL, PA2KA(cur), cur,
    65                             PAGE_GLOBAL | PAGE_CACHEABLE | PAGE_EXEC | PAGE_WRITE | PAGE_READ);
     65                            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_GLOBAL | PAGE_CACHEABLE);
    6666
    6767                page_table_unlock(AS_KERNEL, true);
  • kernel/arch/sparc64/src/drivers/kbd.c

    r973be387 r94d211e  
    119119
    120120        ioport8_t *ns16550 = (ioport8_t *) (km_map(aligned_addr, offset + size,
    121             PAGE_WRITE | PAGE_NOT_CACHEABLE) + offset);
     121            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE) + offset);
    122122
    123123        ns16550_instance_t *ns16550_instance = ns16550_init(ns16550, 0, inr, cir,
  • kernel/arch/sparc64/src/drivers/pci.c

    r973be387 r94d211e  
    110110        pci->op = &pci_sabre_ops;
    111111        pci->reg = (uint64_t *) km_map(paddr, reg[SABRE_INTERNAL_REG].size,
    112             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     112            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    113113
    114114        return pci;
     
    152152        pci->op = &pci_psycho_ops;
    153153        pci->reg = (uint64_t *) km_map(paddr, reg[PSYCHO_INTERNAL_REG].size,
    154             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     154            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    155155
    156156        return pci;
  • kernel/genarch/include/genarch/drivers/amdm37x/gpt.h

    r973be387 r94d211e  
    208208        // TODO find a nicer way to setup 32kHz clock source for timer1
    209209        // reg 0x48004C40 is CM_CLKSEL_WKUP see page 485 of the manual
    210         ioport32_t *clksel = (void*) km_map(0x48004C40, 4, PAGE_NOT_CACHEABLE);
     210        ioport32_t *clksel = (void*) km_map(0x48004C40, 4,
     211            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    211212        *clksel &= ~1;
    212213        km_unmap((uintptr_t)clksel, 4);
     
    214215        assert(timer);
    215216        /* Map control register */
    216         timer->regs = (void*) km_map(ioregs, iosize, PAGE_NOT_CACHEABLE);
     217        timer->regs = (void*) km_map(ioregs, iosize,
     218            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    217219
    218220        /* Reset the timer */
  • kernel/genarch/include/genarch/mm/page_pt.h

    r973be387 r94d211e  
    136136#define PTE_PRESENT(p)     PTE_PRESENT_ARCH((p))
    137137#define PTE_GET_FRAME(p)   PTE_GET_FRAME_ARCH((p))
    138 #define PTE_READABLE(p)    1
     138#define PTE_READABLE(p)    PTE_READABLE_ARCH((p))
    139139#define PTE_WRITABLE(p)    PTE_WRITABLE_ARCH((p))
    140140#define PTE_EXECUTABLE(p)  PTE_EXECUTABLE_ARCH((p))
  • kernel/genarch/src/acpi/acpi.c

    r973be387 r94d211e  
    104104        /* Start with mapping the header only. */
    105105        vhdr = (struct acpi_sdt_header *) km_map((uintptr_t) psdt,
    106             sizeof(struct acpi_sdt_header), PAGE_READ | PAGE_NOT_CACHEABLE);
     106            sizeof(struct acpi_sdt_header),
     107            PAGE_READ_ONLY | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    107108
    108109        /* Now we can map the entire structure. */
    109110        vsdt = (struct acpi_sdt_header *) km_map((uintptr_t) psdt,
    110             vhdr->length, PAGE_WRITE | PAGE_NOT_CACHEABLE);
     111            vhdr->length,
     112            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    111113
    112114        // TODO: do not leak vtmp
  • kernel/genarch/src/drivers/am335x/timer.c

    r973be387 r94d211e  
    100100        size = regs_map[id].size;
    101101
    102         timer->regs = (void *) km_map(base_addr, size, PAGE_NOT_CACHEABLE);
     102        timer->regs = (void *) km_map(base_addr, size,
     103            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    103104        assert(timer->regs != NULL);
    104105
  • kernel/genarch/src/drivers/bcm2835/mbox.c

    r973be387 r94d211e  
    9191
    9292        fb_mbox = (void *) km_map(BCM2835_MBOX0_ADDR, sizeof(bcm2835_mbox_t),
    93                                   PAGE_NOT_CACHEABLE);
     93            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9494
    9595        fb_desc->width = 640;
  • kernel/genarch/src/drivers/ega/ega.c

    r973be387 r94d211e  
    601601        instance->base = base;
    602602        instance->addr = (uint8_t *) km_map(addr, EGA_VRAM_SIZE,
    603             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     603            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    604604        if (!instance->addr) {
    605605                LOG("Unable to EGA video memory.");
  • kernel/genarch/src/drivers/omap/uart.c

    r973be387 r94d211e  
    8787{
    8888        assert(uart);
    89         uart->regs = (void *)km_map(addr, size, PAGE_NOT_CACHEABLE);
     89        uart->regs = (void *)km_map(addr, size,
     90            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9091
    9192        assert(uart->regs);
  • kernel/genarch/src/drivers/pl011/pl011.c

    r973be387 r94d211e  
    100100        assert(uart);
    101101        uart->regs = (void*)km_map(addr, sizeof(pl011_uart_regs_t),
    102                                   PAGE_NOT_CACHEABLE);
     102            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    103103        assert(uart->regs);
    104104
  • kernel/genarch/src/drivers/s3c24xx/uart.c

    r973be387 r94d211e  
    117117
    118118        uart->io = (s3c24xx_uart_io_t *) km_map(paddr, PAGE_SIZE,
    119             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     119            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    120120        uart->indev = NULL;
    121121
  • kernel/genarch/src/fb/fb.c

    r973be387 r94d211e  
    610610
    611611        instance->addr = (uint8_t *) km_map((uintptr_t) props->addr, fbsize,
    612             PAGE_WRITE | PAGE_NOT_CACHEABLE);
     612            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    613613        if (!instance->addr) {
    614614                LOG("Unable to map framebuffer.");
  • kernel/genarch/src/mm/page_ht.c

    r973be387 r94d211e  
    6161static void ht_mapping_remove(as_t *, uintptr_t);
    6262static bool ht_mapping_find(as_t *, uintptr_t, bool, pte_t *);
    63 static void ht_mapping_update(as_t *, uintptr_t, bool, pte_t *);
     63static void ht_mapping_update(as_t *, uintptr_t, bool, const pte_t *);
    6464static void ht_mapping_make_global(uintptr_t, size_t);
    6565
     
    168168
    169169                pte->g = (flags & PAGE_GLOBAL) != 0;
    170                 pte->x = (flags & PAGE_EXEC) != 0;
    171                 pte->w = (flags & PAGE_WRITE) != 0;
     170                pte->x = (flags & _PAGE_EXEC) != 0;
     171                pte->w = (flags & _PAGE_WRITE) != 0;
    172172                pte->k = !(flags & PAGE_USER);
    173173                pte->c = (flags & PAGE_CACHEABLE) != 0;
     
    268268 * @param pte      New PTE.
    269269 */
    270 void ht_mapping_update(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
     270void ht_mapping_update(as_t *as, uintptr_t page, bool nolock, const pte_t *pte)
    271271{
    272272        irq_spinlock_lock(&page_ht_lock, true);
  • kernel/genarch/src/mm/page_pt.c

    r973be387 r94d211e  
    5555static void pt_mapping_remove(as_t *, uintptr_t);
    5656static bool pt_mapping_find(as_t *, uintptr_t, bool, pte_t *pte);
    57 static void pt_mapping_update(as_t *, uintptr_t, bool, pte_t *pte);
     57static void pt_mapping_update(as_t *, uintptr_t, bool, const pte_t *pte);
    5858static void pt_mapping_make_global(uintptr_t, size_t);
    5959
     
    9090                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
    9191                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page),
    92                     PAGE_NOT_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    93                     PAGE_WRITE);
     92                    PAGE_NOT_PRESENT | PAGE_NEXT_LEVEL_PT);
    9493                /*
    9594                 * Make sure that a concurrent hardware page table walk or
     
    109108                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
    110109                SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page),
    111                     PAGE_NOT_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    112                     PAGE_WRITE);
     110                    PAGE_NOT_PRESENT | PAGE_NEXT_LEVEL_PT);
    113111                /*
    114112                 * Make the new PTL2 visible only after it is fully initialized.
     
    126124                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
    127125                SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page),
    128                     PAGE_NOT_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    129                     PAGE_WRITE);
     126                    PAGE_NOT_PRESENT | PAGE_NEXT_LEVEL_PT);
    130127                /*
    131128                 * Make the new PTL3 visible only after it is fully initialized.
     
    353350 * @param[in] pte  New PTE.
    354351 */
    355 void pt_mapping_update(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
     352void pt_mapping_update(as_t *as, uintptr_t page, bool nolock, const pte_t *pte)
    356353{
    357354        pte_t *t = pt_mapping_find_internal(as, page, nolock);
     
    431428                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(addr), KA2PA(l1));
    432429                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(addr),
    433                     PAGE_PRESENT | PAGE_USER | PAGE_CACHEABLE |
    434                     PAGE_EXEC | PAGE_WRITE | PAGE_READ);
     430                    PAGE_NEXT_LEVEL_PT);
    435431        }
    436432}
  • kernel/generic/include/mm/mm.h

    r973be387 r94d211e  
    3636#define KERN_MM_H_
    3737
    38 #define PAGE_CACHEABLE_SHIFT            0
    39 #define PAGE_NOT_CACHEABLE_SHIFT        PAGE_CACHEABLE_SHIFT
    40 #define PAGE_PRESENT_SHIFT              1
    41 #define PAGE_NOT_PRESENT_SHIFT          PAGE_PRESENT_SHIFT
    42 #define PAGE_USER_SHIFT                 2
    43 #define PAGE_KERNEL_SHIFT               PAGE_USER_SHIFT
     38#include <assert.h>
     39#include <stdbool.h>
     40
     41#define PAGE_NOT_CACHEABLE_SHIFT        0
     42#define PAGE_CACHEABLE_SHIFT            1
     43#define PAGE_NOT_PRESENT_SHIFT          2
    4444#define PAGE_READ_SHIFT                 3
    4545#define PAGE_WRITE_SHIFT                4
    4646#define PAGE_EXEC_SHIFT                 5
    4747#define PAGE_GLOBAL_SHIFT               6
     48#define PAGE_USER_SHIFT                 7
     49#define PAGE_KERNEL_SHIFT               8
    4850
    49 #define PAGE_NOT_CACHEABLE              (0 << PAGE_CACHEABLE_SHIFT)
     51/* Cacheability.
     52 * Platform-independent code should always use PAGE_CACHEABLE for normal memory,
     53 * and PAGE_NOT_CACHEABLE for I/O memory.
     54 * In particular, setting PAGE_NOT_CACHEABLE on normal memory does not prevent
     55 * caching on all platforms. You have been warned.
     56 * Exactly one must be present for leaf pages.
     57 * None may be present for non-leaf entries.
     58 */
     59
     60#define PAGE_NOT_CACHEABLE              (1 << PAGE_NOT_CACHEABLE_SHIFT)
    5061#define PAGE_CACHEABLE                  (1 << PAGE_CACHEABLE_SHIFT)
    5162
    52 #define PAGE_PRESENT                    (0 << PAGE_PRESENT_SHIFT)
    53 #define PAGE_NOT_PRESENT                (1 << PAGE_PRESENT_SHIFT)
    5463
    55 #define PAGE_USER                       (1 << PAGE_USER_SHIFT)
    56 #define PAGE_KERNEL                     (0 << PAGE_USER_SHIFT)
     64/* Discriminant, exactly one of the following seven must be set for
     65 * the flags to be valid. Furthermore, the first two are only legal
     66 * for setting individual page table entries. Setting an entry
     67 * to PAGE_NOT_PRESENT renders the entry eligible for removal.
     68 * In an earlier iteration of this interface, page could be not
     69 * present but valid, preventing removal. This has been changed, and
     70 * if future iterations allow kernel to hide data (e.g. swap identifiers)
     71 * in page tables, it should be achieved by adding a separate discriminant.
     72 */
     73#define PAGE_NOT_PRESENT          (1 << PAGE_NOT_PRESENT_SHIFT)
    5774
    58 #define PAGE_READ                       (1 << PAGE_READ_SHIFT)
    59 #define PAGE_WRITE                      (1 << PAGE_WRITE_SHIFT)
    60 #define PAGE_EXEC                       (1 << PAGE_EXEC_SHIFT)
     75// TODO: This will be a separate flag.
     76#define PAGE_NEXT_LEVEL_PT        (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC | PAGE_USER | PAGE_CACHEABLE)
    6177
    62 #define PAGE_GLOBAL                     (1 << PAGE_GLOBAL_SHIFT)
     78#define PAGE_READ_ONLY            (_PAGE_READ)
     79#define PAGE_READ_EXECUTE         (_PAGE_READ | _PAGE_EXEC)
     80#define PAGE_READ_WRITE           (_PAGE_READ | _PAGE_WRITE)
     81#define PAGE_READ_WRITE_EXECUTE   (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)
     82#define PAGE_EXECUTE_ONLY         (_PAGE_EXEC)
     83
     84/* Individual permissions.
     85 * Only used when the flags are tested or translated from other
     86 * format. In constant flags, use one of the combinations above.
     87 */
     88#define _PAGE_READ                (1 << PAGE_READ_SHIFT)
     89#define _PAGE_WRITE               (1 << PAGE_WRITE_SHIFT)
     90#define _PAGE_EXEC                (1 << PAGE_EXEC_SHIFT)
     91
     92/* Global page. Can be combined with anything except PAGE_NOT_PRESENT.
     93 * PAGE_GLOBAL on non-leaf entry means all the leaf entries under it are global,
     94 * even if they don't have the PAGE_GLOBAL flag themselves.
     95 */
     96#define PAGE_GLOBAL               (1 << PAGE_GLOBAL_SHIFT)
     97
     98/* Protection.
     99 * PAGE_USER for memory accessible to userspace programs, PAGE_KERNEL for
     100 * memory accessible only to the kernel. Note that on some platforms,
     101 * PAGE_USER pages are accessible to kernel, while on others, they are not.
     102 * For non-leaf entries, PAGE_USER means that all of the lower-level pages
     103 * are PAGE_USER, likewise with PAGE_KERNEL. Exactly one of these two must be
     104 * used for leaf entries, but it may be omitted for non-leaf entries.
     105 */
     106#define PAGE_USER                 (1 << PAGE_USER_SHIFT)
     107#define PAGE_KERNEL               (1 << PAGE_KERNEL_SHIFT)
     108
     109
     110
     111static inline bool PAGE_FLAGS_VALID(unsigned flags) {
     112        // TODO
     113
     114        /* Empty entry supports no flags. */
     115        if (flags & PAGE_NOT_PRESENT)
     116                return flags == PAGE_NOT_PRESENT;
     117
     118        /* PAGE_USER and PAGE_KERNEL are mutually exclusive. */
     119        if ((flags & PAGE_USER) && (flags & PAGE_KERNEL))
     120                return false;
     121
     122        /* Check allowed flags for non-leaf entry. */
     123        if (flags & PAGE_NEXT_LEVEL_PT)
     124                return flags == (flags & (PAGE_NEXT_LEVEL_PT | PAGE_GLOBAL | PAGE_USER | PAGE_KERNEL));
     125
     126        /* Leaf entries only. */
     127
     128        /* Check that at least one permission is set. */
     129        if (!(flags & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)))
     130                return false;
     131
     132        /* Check that write implies read. */
     133        if ((flags & _PAGE_WRITE) && !(flags & _PAGE_READ))
     134                return false;
     135
     136        /* One of PAGE_USER and PAGE_KERNEL must be used. */
     137        if (!(flags & (PAGE_USER | PAGE_KERNEL)))
     138                return false;
     139
     140        /* One of PAGE_CACHEABLE and PAGE_NOT_CACHEABLE must be used. */
     141        if ((flags & PAGE_CACHEABLE) && (flags & PAGE_NOT_CACHEABLE))
     142                return false;
     143        if (!(flags & (PAGE_CACHEABLE | PAGE_NOT_CACHEABLE)))
     144                return false;
     145
     146        return true;
     147}
    63148
    64149#endif
  • kernel/generic/include/mm/page.h

    r973be387 r94d211e  
    4949        void (*mapping_remove)(as_t *, uintptr_t);
    5050        bool (*mapping_find)(as_t *, uintptr_t, bool, pte_t *);
    51         void (*mapping_update)(as_t *, uintptr_t, bool, pte_t *);
     51        void (*mapping_update)(as_t *, uintptr_t, bool, const pte_t *);
    5252        void (*mapping_make_global)(uintptr_t, size_t);
    5353} page_mapping_operations_t;
  • kernel/generic/src/console/cmd.c

    r973be387 r94d211e  
    727727        else
    728728#endif
    729                 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
    730                     PAGE_NOT_CACHEABLE);
     729                ptr = (uint8_t *) km_map(
     730                    argv[0].intval, sizeof(uint8_t),
     731                    PAGE_READ_ONLY | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    731732
    732733        const uint8_t val = pio_read_8(ptr);
     
    749750 */
    750751static int cmd_pio_read_16(cmd_arg_t *argv)
     752{
     753        uint16_t *ptr = NULL;
     754
     755#ifdef IO_SPACE_BOUNDARY
     756        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     757                ptr = (void *) argv[0].intval;
     758        else
     759#endif
     760                ptr = (uint16_t *) km_map(
     761                    argv[0].intval, sizeof(uint16_t),
     762                    PAGE_READ_ONLY | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     763
     764        const uint16_t val = pio_read_16(ptr);
     765        printf("read %" PRIxn ": %" PRIx16 "\n", argv[0].intval, val);
     766
     767#ifdef IO_SPACE_BOUNDARY
     768        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     769                return 1;
     770#endif
     771
     772        km_unmap((uintptr_t) ptr, sizeof(uint16_t));
     773        return 1;
     774}
     775
     776/** Read 4 bytes from phys memory or io port.
     777 *
     778 * @param argv Argument vector.
     779 *
     780 * @return 0 on failure, 1 on success.
     781 */
     782static int cmd_pio_read_32(cmd_arg_t *argv)
     783{
     784        uint32_t *ptr = NULL;
     785
     786#ifdef IO_SPACE_BOUNDARY
     787        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     788                ptr = (void *) argv[0].intval;
     789        else
     790#endif
     791                ptr = (uint32_t *) km_map(
     792                    argv[0].intval, sizeof(uint32_t),
     793                    PAGE_READ_ONLY | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     794
     795        const uint32_t val = pio_read_32(ptr);
     796        printf("read %" PRIxn ": %" PRIx32 "\n", argv[0].intval, val);
     797
     798#ifdef IO_SPACE_BOUNDARY
     799        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     800                return 1;
     801#endif
     802
     803        km_unmap((uintptr_t) ptr, sizeof(uint32_t));
     804        return 1;
     805}
     806
     807/** Write 1 byte to phys memory or io port.
     808 *
     809 * @param argv Argument vector.
     810 *
     811 * @return 0 on failure, 1 on success.
     812 */
     813static int cmd_pio_write_8(cmd_arg_t *argv)
     814{
     815        uint8_t *ptr = NULL;
     816
     817#ifdef IO_SPACE_BOUNDARY
     818        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     819                ptr = (void *) argv[0].intval;
     820        else
     821#endif
     822                ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
     823                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     824
     825        printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval,
     826            (uint8_t) argv[1].intval);
     827        pio_write_8(ptr, (uint8_t) argv[1].intval);
     828
     829#ifdef IO_SPACE_BOUNDARY
     830        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     831                return 1;
     832#endif
     833
     834        km_unmap((uintptr_t) ptr, sizeof(uint8_t));
     835        return 1;
     836}
     837
     838/** Write 2 bytes to phys memory or io port.
     839 *
     840 * @param argv Argument vector.
     841 *
     842 * @return 0 on failure, 1 on success.
     843 */
     844static int cmd_pio_write_16(cmd_arg_t *argv)
    751845{
    752846        uint16_t *ptr = NULL;
     
    758852#endif
    759853                ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
    760                     PAGE_NOT_CACHEABLE);
    761 
    762         const uint16_t val = pio_read_16(ptr);
    763         printf("read %" PRIxn ": %" PRIx16 "\n", argv[0].intval, val);
     854                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     855
     856        printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval,
     857            (uint16_t) argv[1].intval);
     858        pio_write_16(ptr, (uint16_t) argv[1].intval);
    764859
    765860#ifdef IO_SPACE_BOUNDARY
     
    772867}
    773868
    774 /** Read 4 bytes from phys memory or io port.
     869/** Write 4 bytes to phys memory or io port.
    775870 *
    776871 * @param argv Argument vector.
     
    778873 * @return 0 on failure, 1 on success.
    779874 */
    780 static int cmd_pio_read_32(cmd_arg_t *argv)
     875static int cmd_pio_write_32(cmd_arg_t *argv)
    781876{
    782877        uint32_t *ptr = NULL;
     
    788883#endif
    789884                ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
    790                     PAGE_NOT_CACHEABLE);
    791 
    792         const uint32_t val = pio_read_32(ptr);
    793         printf("read %" PRIxn ": %" PRIx32 "\n", argv[0].intval, val);
    794 
    795 #ifdef IO_SPACE_BOUNDARY
    796         if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    797                 return 1;
    798 #endif
    799 
    800         km_unmap((uintptr_t) ptr, sizeof(uint32_t));
    801         return 1;
    802 }
    803 
    804 /** Write 1 byte to phys memory or io port.
    805  *
    806  * @param argv Argument vector.
    807  *
    808  * @return 0 on failure, 1 on success.
    809  */
    810 static int cmd_pio_write_8(cmd_arg_t *argv)
    811 {
    812         uint8_t *ptr = NULL;
    813 
    814 #ifdef IO_SPACE_BOUNDARY
    815         if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    816                 ptr = (void *) argv[0].intval;
    817         else
    818 #endif
    819                 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
    820                     PAGE_NOT_CACHEABLE);
    821 
    822         printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval,
    823             (uint8_t) argv[1].intval);
    824         pio_write_8(ptr, (uint8_t) argv[1].intval);
    825 
    826 #ifdef IO_SPACE_BOUNDARY
    827         if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    828                 return 1;
    829 #endif
    830 
    831         km_unmap((uintptr_t) ptr, sizeof(uint8_t));
    832         return 1;
    833 }
    834 
    835 /** Write 2 bytes to phys memory or io port.
    836  *
    837  * @param argv Argument vector.
    838  *
    839  * @return 0 on failure, 1 on success.
    840  */
    841 static int cmd_pio_write_16(cmd_arg_t *argv)
    842 {
    843         uint16_t *ptr = NULL;
    844 
    845 #ifdef IO_SPACE_BOUNDARY
    846         if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    847                 ptr = (void *) argv[0].intval;
    848         else
    849 #endif
    850                 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
    851                     PAGE_NOT_CACHEABLE);
    852 
    853         printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval,
    854             (uint16_t) argv[1].intval);
    855         pio_write_16(ptr, (uint16_t) argv[1].intval);
    856 
    857 #ifdef IO_SPACE_BOUNDARY
    858         if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    859                 return 1;
    860 #endif
    861 
    862         km_unmap((uintptr_t) ptr, sizeof(uint16_t));
    863         return 1;
    864 }
    865 
    866 /** Write 4 bytes to phys memory or io port.
    867  *
    868  * @param argv Argument vector.
    869  *
    870  * @return 0 on failure, 1 on success.
    871  */
    872 static int cmd_pio_write_32(cmd_arg_t *argv)
    873 {
    874         uint32_t *ptr = NULL;
    875 
    876 #ifdef IO_SPACE_BOUNDARY
    877         if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    878                 ptr = (void *) argv[0].intval;
    879         else
    880 #endif
    881                 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
    882                     PAGE_NOT_CACHEABLE);
     885                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    883886
    884887        printf("write %" PRIxn ": %" PRIx32 "\n", argv[0].intval,
  • kernel/generic/src/ipc/irq.c

    r973be387 r94d211e  
    9393#endif
    9494                ranges[i].base = km_map(pbase[i], ranges[i].size,
    95                     PAGE_READ | PAGE_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
     95                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9696                if (!ranges[i].base) {
    9797                        ranges_unmap(ranges, i);
  • kernel/generic/src/main/kinit.c

    r973be387 r94d211e  
    250250                uintptr_t page = km_map(init.tasks[i].paddr,
    251251                    init.tasks[i].size,
    252                     PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
     252                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_CACHEABLE);
    253253                assert(page);
    254254
  • kernel/generic/src/mm/as.c

    r973be387 r94d211e  
    12171217NO_TRACE static unsigned int area_flags_to_page_flags(unsigned int aflags)
    12181218{
    1219         unsigned int flags = PAGE_USER | PAGE_PRESENT;
     1219        unsigned int flags = PAGE_USER;
    12201220
    12211221        if (aflags & AS_AREA_READ)
    1222                 flags |= PAGE_READ;
     1222                flags |= _PAGE_READ;
    12231223
    12241224        if (aflags & AS_AREA_WRITE)
    1225                 flags |= PAGE_WRITE;
     1225                flags |= _PAGE_WRITE;
    12261226
    12271227        if (aflags & AS_AREA_EXEC)
    1228                 flags |= PAGE_EXEC;
     1228                flags |= _PAGE_EXEC;
    12291229
    12301230        if (aflags & AS_AREA_CACHEABLE)
    12311231                flags |= PAGE_CACHEABLE;
     1232        else
     1233                flags |= PAGE_NOT_CACHEABLE;
    12321234
    12331235        return flags;
  • kernel/generic/src/mm/km.c

    r973be387 r94d211e  
    257257        if (frame) {
    258258                page = km_map(frame, PAGE_SIZE,
    259                     PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
     259                    PAGE_READ_WRITE | PAGE_KERNEL | PAGE_CACHEABLE);
    260260                if (!page) {
    261261                        frame_free(frame, 1);
  • kernel/test/mm/mapping1.c

    r973be387 r94d211e  
    4444
    4545        uintptr_t page0 = km_map(frame, FRAME_SIZE,
    46             PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
     46            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_CACHEABLE);
    4747        TPRINTF("Virtual address %p mapped to physical address %p.\n",
    4848            (void *) page0, (void *) frame);
    4949
    5050        uintptr_t page1 = km_map(frame, FRAME_SIZE,
    51             PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
     51            PAGE_READ_WRITE | PAGE_KERNEL | PAGE_CACHEABLE);
    5252        TPRINTF("Virtual address %p mapped to physical address %p.\n",
    5353            (void *) page1, (void *) frame);
Note: See TracChangeset for help on using the changeset viewer.