reword redraft mvendorid-marchid idea
[libreriscv.git] / isa_conflict_resolution / ioctl.mdwn
index 7acd97bd5b8224be660fbec92a66a7bff5962789..cacf082861356ad5f3aa8fbdf4d807833f92f33c 100644 (file)
@@ -9,7 +9,7 @@ local interface cookie in rs1. Based on the cookie, the CPU routes the
 "overloaded" instructions to a "device" on or off the CPU that implements
 the actual semantics.
 
-The cookie is "opened" with an additional r-type instruction ext_open that
+The cookie is "opened" with an additional R-type instruction ext_open that
 takes a 20 bit identifier and "closed" with an  ext_close instruction. The
 implementing hardware device can use the cookie to reference internal
 state. Thus, interfaces may be statefull.
@@ -74,25 +74,29 @@ The "open handle" opcode takes a GUID (globally-unique identifier)
 and an ioctl number, and stores the UUID in a table indexed by the
 ioctl number:
 
-    handle_global_state[8] # stores UUID or index of same
+    char handle_global_state[8][20] # stores UUID or index of same
 
-    def open_handle(uuid, ioctl_num):
+    void open_handle(char[20] uuid, byte ioctl_num):
           handle_global_state[ioctl_num] = uuid
 
-    def close_handle(ioctl_num):
+    void close_handle(byte ioctl_num):
           handle_global_state[ioctl_num] = -1 # clear table entry
 
-
 "Ioctls" (arbitrarily 8 separate R-type opcodes) then perform a redirect
 based on what the global state for that numbered "ioctl" has been set to:
 
-    def ioctl_fn0(*rargs): # star means "take all arguments as a tuple"
-        if handle_global_state[0] == CUSTOMEXT1UUID:
-           CUSTOMEXT1_FN0(*rargs) # apply all arguments to function
-        elif handle_global_state[0] == CUSTOMEXT2UUID:
-           CUSTOMEXT2_FN0(*rargs) # apply all arguments to function
-        else:
+    ioctl_fn0(funct7, rs2, rs1, funct3, rd): # all r-type bits
+    {
+        if (handle_global_state[0] == CUSTOMEXT1UUID)
+           CUSTEXT1_FN0(funct7, rs2, rs1, funct3, rd); # all r-type bits
+        else if (handle_global_state[0] == CUSTOMEXT2UUID)
+           CUSTEXT2_FN0(funct7, rs2, rs1, funct3, rd, opcode); # all r-type bits
+        else
             raise Exception("undefined opcode")
+    }
+
+Note that the "ioctl" receives all R-type bits (31:7) with the exception of the
+opcode (6:0).
 
 === RB ==
 
@@ -153,7 +157,8 @@ not quite I think. It is more like
             raise Exception("No such interface")
 
         handleId = new_unused_handle_id()
-        cpu_open_handles[handleId] = (interface, CurrentVirtualMemoryAddressSpace)
+        cpu_open_handles[handleId] = (interface,
+                                      CurrentVirtualMemoryAddressSpace)
 
         cookie = A_init(data)                      # Here device takes over
 
@@ -187,7 +192,10 @@ not quite I think. It is more like
 
         (interface, VMA) = intf_VMA
         if VMA != CurrentVirtualMemoryAddressSpace:
-             raise Exception("No such interface")  #Disclosing that the interface exists in different address is security hole
+             raise Exception("No such interface")  # Disclosing that the
+                                                   # interface exists in 
+                                                   # different address is 
+                                                   # security hole
 
         assert(interface != NIL)
         ctl0 = interface["ctl0"]