diff --git a/arch/x86_64/include/arch/paging.h b/arch/x86_64/include/arch/paging.h index 7335e31..d3fd4e0 100644 --- a/arch/x86_64/include/arch/paging.h +++ b/arch/x86_64/include/arch/paging.h @@ -50,5 +50,6 @@ typedef enum page_size { /* returns 1 if gigabyte pages are supported by the CPU, 0 otherwise. defined in pmap_ctrl.S */ extern int gigabyte_pages(void); +extern int enable_nx(void); #endif diff --git a/arch/x86_64/pmap.c b/arch/x86_64/pmap.c index 6f93c48..f1636ea 100644 --- a/arch/x86_64/pmap.c +++ b/arch/x86_64/pmap.c @@ -226,6 +226,8 @@ void pmap_bootstrap(void) { can_use_gbpages = gigabyte_pages(); printk("pmap: gigabyte pages %sabled", can_use_gbpages == 1 ? "en" : "dis"); + enable_nx(); + printk("pmap: NX protection enabled"); page_size_t hugepage = PS_2M; if (can_use_gbpages) { diff --git a/arch/x86_64/pmap_ctrl.S b/arch/x86_64/pmap_ctrl.S index 28c9b67..a8416f2 100644 --- a/arch/x86_64/pmap_ctrl.S +++ b/arch/x86_64/pmap_ctrl.S @@ -29,3 +29,14 @@ gigabyte_pages: 3: pop %rbx pop %rbp ret + + .global enable_nx + .type enable_nx, @function + +enable_nx: + mov $0xC0000080, %ecx + rdmsr + or $0x800, %eax + wrmsr + + ret