Patchwork [2/2,RFC] ARMv7: Support for simplified access permissions checking

login
register
mail settings
Submitter Bahadir Balban
Date Jan. 25, 2010, 7:38 a.m.
Message ID <1264405128-2332-2-git-send-email-bbalban@b-labs.co.uk>
Download mbox | patch
Permalink /patch/43614/
State New
Headers show

Comments

Bahadir Balban - Jan. 25, 2010, 7:38 a.m.
ARMv7 has a simplified access permissions model that is enabled
by setting the AFE bit of the SCTLR. This patch adds checking
for permission values for when this mode is selected.

Signed-off-by: Bahadir Balban <bbalban@b-labs.co.uk>
---
 target-arm/helper.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 48 insertions(+), 2 deletions(-)
Paul Brook - March 1, 2010, 2:40 p.m.
> ARMv7 has a simplified access permissions model that is enabled
> by setting the AFE bit of the SCTLR. This patch adds checking
> for permission values for when this mode is selected.

This is already implemented.

Paul

Patch

diff --git a/target-arm/helper.c b/target-arm/helper.c
index 334832d..732d142 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -837,11 +837,48 @@  void do_interrupt(CPUARMState *env)
     env->interrupt_request |= CPU_INTERRUPT_EXITTB;
 }
 
+
+/*
+ * Simplified access permissions:
+ * AP[2:1] has below meanings:
+ * User/None Kern/RW    0
+ * User/RW   Kern/RW    1
+ * User/None Kern/RO    2
+ * User/RO   Kern/RO    3
+ */
+#define AP_SIMPLE_USER_NONE_KERN_RW		0
+#define AP_SIMPLE_USER_RW_KERN_RW		1
+#define AP_SIMPLE_USER_NONE_KERN_RO		2
+#define AP_SIMPLE_USER_RO_KERN_RO		3
+
+static int check_ap_simplified(CPUState *env, int ap, int domain,
+                               int access_type, int is_user)
+{
+    switch(ap) {
+    case AP_SIMPLE_USER_NONE_KERN_RW:
+	if (is_user)
+            return 0;
+	else
+            return PAGE_READ | PAGE_WRITE;
+    case AP_SIMPLE_USER_RW_KERN_RW:
+	return PAGE_READ | PAGE_WRITE;
+    case AP_SIMPLE_USER_NONE_KERN_RO:
+	if (is_user)
+	    return 0;
+        else
+            return PAGE_READ;
+    case AP_SIMPLE_USER_RO_KERN_RO:
+	return PAGE_READ;
+    default:
+	return 0;
+    }
+}
+
 /* Check section/page access permissions.
    Returns the page protection flags, or zero if the access is not
    permitted.  */
-static inline int check_ap(CPUState *env, int ap, int domain, int access_type,
-                           int is_user)
+static inline int check_ap_normal(CPUState *env, int ap, int domain,
+                                  int access_type, int is_user)
 {
   int prot_ro;
 
@@ -889,6 +926,15 @@  static inline int check_ap(CPUState *env, int ap, int domain, int access_type,
   }
 }
 
+static inline int check_ap(CPUState *env, int ap, int domain,
+                           int access_type, int is_user)
+{
+    if (env->cp15.c1_sys & (1 << 29))
+        return check_ap_simplified(env, ap, domain, access_type, is_user);
+    else
+        return check_ap_normal(env, ap, domain, access_type, is_user);
+}
+
 static uint32_t get_level1_table_address(CPUState *env, uint32_t address)
 {
     uint32_t table;