From 97877001e22c64b3dcf5558454b28b896a0c50cf Mon Sep 17 00:00:00 2001
From: Jedian <jmb15@c3sl.ufpr.br>
Date: Wed, 25 May 2016 10:03:52 -0300
Subject: [PATCH] Probleminhas do jedi

Signed-off-by: Jedian <jmb15@c3sl.ufpr.br>
---
 cMIPS/tests/handlerUARTjedi.s  | 20 +++++------
 cMIPS/tests/handlerUARTjedi2.s | 66 ++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 10 deletions(-)
 create mode 100644 cMIPS/tests/handlerUARTjedi2.s

diff --git a/cMIPS/tests/handlerUARTjedi.s b/cMIPS/tests/handlerUARTjedi.s
index 8f2915d..2c9b689 100644
--- a/cMIPS/tests/handlerUARTjedi.s
+++ b/cMIPS/tests/handlerUARTjedi.s
@@ -5,7 +5,7 @@
     #k0 = _uart_buff
 
     andi  $a1, $k1, UART_rx_irq # Is this reception?
-    beq   $a1, $zero, UARTinterr2   #   no, maybe transmission?
+    beq   $a1, $zero, UARTret   #   no, maybe transmission?
     nop
 
     #handle reception
@@ -29,7 +29,7 @@
 
     lw    $7, 0($5)
 
-    #### stores on queue on calculated new head
+    #### stores on queue on head
     lui   $6, %hi(rx_q)         # get queue address
     ori   $6, $6, %lo(rx_q)
 
@@ -39,24 +39,24 @@
     nop
     sw    $7, 0($6)             # and store it!
 
-    #### process rx_hd
+    #### process rx_hd -- updates head
     lw    $7, 0($5)
+    nop
     addiu $7, $7, 1             # increment in 1 the head of the circular queue
-    li    $6, 16                # calculate mod 16
-    div   $7, $6
-    mfhi  $7
+    andi  $7, $7, 0xf           # % 16
     sw    $7, 0($5)
 
+#FIZ TUDO ERRADO, ERA NO TAIL QUE EU TINHA QUE MUDAR, EXEMPLO NA APOSTILA PAG 142
 
     # loading back used registers
     lw    $5, 9*4($k0)
     lw    $6, 10*4($k0)
     lw    $7, 11*4($k0)
 
-UARTinterr2:
-    andi  $a1, $k1, UART_tx_irq # Is this transmission?
-    beq   $a1, $zero, UARTret   # no, ignore it and return
-    nop
+#UARTinterr2:
+#    andi  $a1, $k1, UART_tx_irq # Is this transmission?
+#    beq   $a1, $zero, UARTret   # no, ignore it and return
+#    nop
 
     #handle transmission
     # ... TODO
diff --git a/cMIPS/tests/handlerUARTjedi2.s b/cMIPS/tests/handlerUARTjedi2.s
new file mode 100644
index 0000000..2c9b689
--- /dev/null
+++ b/cMIPS/tests/handlerUARTjedi2.s
@@ -0,0 +1,66 @@
+#UARTinterr:
+    # There is space on _uart_buff
+    # _uart_buff[0]=UARTstatus, [1]=UARTcontrol, [2]=data_inp, [3]=new,
+    #           [4]=$ra, [5]=$a0, [6]=$a1, [7]=$a2, [8]=$a3
+    #k0 = _uart_buff
+
+    andi  $a1, $k1, UART_rx_irq # Is this reception?
+    beq   $a1, $zero, UARTret   #   no, maybe transmission?
+    nop
+
+    #handle reception
+    lw    $a1, 4($a0)           # Read data from device
+    nop                         #   and store it to UART's buffer
+    sw    $a1, 2*4($k0)         #   and return from interrupt
+    addiu $a1, $zero, 1
+    sw    $a1, 3*4($k0)         # Signal new arrival
+                                # Jedian: when a new char is on the UART's buffer, 
+                                #         i have to enqueue it and update nrx.
+
+    #ACHO QUE ELE NAO TA RESETANDO O INTERRUPTION REQUEST, AI FICA TRAVADAO
+    # saving used registers on _uart_buff
+    sw    $5, 9*4($k0)
+    sw    $6, 10*4($k0)
+    sw    $7, 11*4($k0)
+    
+    # enqueue
+    lui   $5, %hi(rx_hd)        # get rx head address
+    ori   $5, $5, %lo(rx_hd)    
+
+    lw    $7, 0($5)
+
+    #### stores on queue on head
+    lui   $6, %hi(rx_q)         # get queue address
+    ori   $6, $6, %lo(rx_q)
+
+    sll   $7, $7, 2             # multiply by 4
+    addu  $6, $7, $6            # calculate address to move new char
+    lw    $7, 2*4($k0)          # get char to be stored
+    nop
+    sw    $7, 0($6)             # and store it!
+
+    #### process rx_hd -- updates head
+    lw    $7, 0($5)
+    nop
+    addiu $7, $7, 1             # increment in 1 the head of the circular queue
+    andi  $7, $7, 0xf           # % 16
+    sw    $7, 0($5)
+
+#FIZ TUDO ERRADO, ERA NO TAIL QUE EU TINHA QUE MUDAR, EXEMPLO NA APOSTILA PAG 142
+
+    # loading back used registers
+    lw    $5, 9*4($k0)
+    lw    $6, 10*4($k0)
+    lw    $7, 11*4($k0)
+
+#UARTinterr2:
+#    andi  $a1, $k1, UART_tx_irq # Is this transmission?
+#    beq   $a1, $zero, UARTret   # no, ignore it and return
+#    nop
+
+    #handle transmission
+    # ... TODO
+
+    # Lembrar de inicializar os hd e tl com 0 no comeco do main
+
+#UARTret: 
-- 
GitLab