aa64: finalise context switch, page fault handler and syscall
[lunaix-os.git] / lunaix-os / arch / aarch64 / includes / asm / hart.h
index 89a2e9ae881574564f2d36e4fa09f44107676f72..52571e67a07664f5aee5379a8834c51e7655ed39 100644 (file)
@@ -6,7 +6,7 @@
 #include <lunaix/bits.h>
 #include <asm/aa64_spsr.h>
 
 #include <lunaix/bits.h>
 #include <asm/aa64_spsr.h>
 
-#define SYNDROME_ETYPE  BITS(63, 56)
+#define SYNDROME_ETYPE  BITFIELD(63, 56)
 
 struct hart_state;
 
 
 struct hart_state;
 
@@ -15,7 +15,7 @@ struct regcontext
     union {
         reg_t x[31];
         struct {
     union {
         reg_t x[31];
         struct {
-            reg_t x[29];
+            reg_t x_[29];
             reg_t fp;
             reg_t lr;
         };
             reg_t fp;
             reg_t lr;
         };
@@ -29,7 +29,7 @@ struct exec_param
     reg_t link;
     struct {
         reg_t sp_el0;
     reg_t link;
     struct {
         reg_t sp_el0;
-        reg_t sp_el1;
+        reg_t rsvd;
     };
     
     reg_t syndrome;
     };
     
     reg_t syndrome;
@@ -43,12 +43,14 @@ struct hart_state
 } compact align(16);
 
 static inline int
 } compact align(16);
 
 static inline int
-hart_vector_stamp(struct hart_state* hstate) {
+hart_vector_stamp(struct hart_state* hstate) 
+{
     return BITS_GET(hstate->execp.syndrome, SYNDROME_ETYPE);
 }
 
 static inline unsigned int
     return BITS_GET(hstate->execp.syndrome, SYNDROME_ETYPE);
 }
 
 static inline unsigned int
-hart_ecause(struct hart_state* hstate) {
+hart_ecause(struct hart_state* hstate) 
+{
     return hstate->execp.syndrome;
 }
 
     return hstate->execp.syndrome;
 }
 
@@ -73,17 +75,16 @@ hart_pc(struct hart_state* hstate)
 static inline ptr_t
 hart_sp(struct hart_state* hstate)
 {
 static inline ptr_t
 hart_sp(struct hart_state* hstate)
 {
-    if (spsr_from_el0(hstate->execp.spsr)) {
-        return hstate->execp.sp_el0;
-    }
-    return hstate->execp.sp_el1;
+    return __ptr(&hstate[-1]);
 }
 
 static inline bool
 kernel_context(struct hart_state* hstate)
 {
 }
 
 static inline bool
 kernel_context(struct hart_state* hstate)
 {
-    // TODO
-    return false;
+    reg_t spsr;
+
+    spsr = hstate->execp.spsr;
+    return !spsr_from_el0(spsr);
 }
 
 static inline ptr_t
 }
 
 static inline ptr_t