Usermode/libc++ - Implement map::insert and map::erase
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / udi_lib / physio / pio.c
index c2c229c..dc45d25 100644 (file)
@@ -54,7 +54,7 @@ void udi_pio_map(udi_pio_map_call_t *callback, udi_cb_t *gcb,
 {
        LOG("gcb=%p,regset_idx=%i,base_offset=0x%x,length=0x%x,trans_list=%p,list_length=%i,...",
                gcb, regset_idx, base_offset, length, trans_list, list_length);
-       char bus_type[16];
+       char bus_type[16] = {0};
        udi_instance_attr_type_t        type;
        type = udi_instance_attr_get_internal(gcb, "bus_type", 0, bus_type, sizeof(bus_type), NULL);
        if(type != UDI_ATTR_STRING) {
@@ -71,6 +71,7 @@ void udi_pio_map(udi_pio_map_call_t *callback, udi_cb_t *gcb,
        }
        else {
                // Oops, unknown
+               Log_Warning("UDI", "Unknown bus type %s", bus_type);
                callback(gcb, UDI_NULL_PIO_HANDLE);
                return ;
        }
@@ -293,13 +294,17 @@ static inline int _read_mem(udi_cb_t *gcb, udi_buf_t *buf, void *mem_ptr,
        case UDI_PIO_SCRATCH:
                ASSERTCR( (ofs & (size-1)), ==, 0, 1);
                memcpy(val, gcb->scratch + ofs, size);
+               //LOG("scr %p+%i => %i %x,...", gcb->scratch, ofs, size, val->words[0]);
                break;
        case UDI_PIO_BUF:
+               ASSERT(buf);
                udi_buf_read(buf, ofs, size, val);
+               //LOG("buf %p+%i => %i %x,...", buf, ofs, size, val->words[0]);
                break;
        case UDI_PIO_MEM:
                ASSERTCR( (ofs & (size-1)), ==, 0, 1 );
                memcpy(val, mem_ptr + ofs, size);
+               //LOG("mem %p+%i => %i %x,...", mem_ptr, ofs, size, val->words[0]);
                break;
        }
        return 0;
@@ -314,18 +319,23 @@ static inline int _write_mem(udi_cb_t *gcb, udi_buf_t *buf, void *mem_ptr,
        switch(op)
        {
        case UDI_PIO_DIRECT:
+               //LOG("reg %p = %i %x,...", reg, size, val->words[0]);
                memcpy(reg, val, size);
                _zero_upper(sizelog2, reg);
                break;
        case UDI_PIO_SCRATCH:
                ASSERTCR( (ofs & (size-1)), ==, 0, 1);
+               //LOG("scr %p+%i = %i %x,...", gcb->scratch, ofs, size, val->words[0]);
                memcpy(gcb->scratch + ofs, val, size);
                break;
        case UDI_PIO_BUF:
+               ASSERT(buf);
+               //LOG("buf %p+%i = %i %x,...", buf, ofs, size, val->words[0]);
                udi_buf_write(NULL,NULL, val, size, buf, ofs, size, UDI_NULL_BUF_PATH);
                break;
        case UDI_PIO_MEM:
                ASSERTCR( (ofs & (size-1)), ==, 0, 1);
+               //LOG("mem %p+%i = %i %x,...", mem_ptr, ofs, size, val->words[0]);
                memcpy(mem_ptr + ofs, val, size);
                break;
        }
@@ -365,18 +375,22 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                        case UDI_PIO_IN:
                                pio_handle->IOFunc(pio_handle->ChildID, pio_handle->RegSet,
                                        operand, tran_size, &tmpval, false);
+                               LOG("IN %x = %i %x", operand, tran_size, tmpval.words[0]);
                                _write_mem(gcb, buf, mem_ptr, (pio_op&0x18), tran_size, reg, &tmpval);
                                break;
                        case UDI_PIO_OUT:
                                _read_mem(gcb, buf, mem_ptr, (pio_op&0x18), tran_size, reg, &tmpval);
+                               LOG("OUT %x = %i %x", operand, tran_size, tmpval.words[0]);
                                pio_handle->IOFunc(pio_handle->ChildID, pio_handle->RegSet,
                                        operand, tran_size, &tmpval, true);
                                break;
                        case UDI_PIO_LOAD:
                                _read_mem(gcb, buf, mem_ptr, (pio_op&0x18), tran_size, reg, &registers[operand]);
+                               LOG("LOAD R%x = %i %x", operand, tran_size, registers[operand].words[0]);
                                _zero_upper(tran_size, &registers[operand]);
                                break;
                        case UDI_PIO_STORE:
+                               LOG("STORE R%x (%i %x)", operand, tran_size, registers[operand].words[0]);
                                _write_mem(gcb, buf, mem_ptr, (pio_op&0x18), tran_size, reg, &registers[operand]);
                                break;
                        }
@@ -414,6 +428,7 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                        reg->words[0] = operand;
                                        break;
                                }
+                               LOG("LOAD IMM ");
                                _zero_upper(tran_size, reg);
                                ip += (1<<tran_size)/2-1;
                                break;
@@ -422,32 +437,35 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                switch(operand)
                                {
                                case UDI_PIO_NZ:
-                                       LOG("CSKIP NZ R%i", reg_num);
+                                       LOG("CSKIP NZ R%i (%i %x)", reg_num, tran_size, reg->words[0]);
                                        if( !(cnd & 1) )
                                                ip ++;
                                        break;
                                case UDI_PIO_Z:
-                                       LOG("CSKIP Z R%i", reg_num);
+                                       LOG("CSKIP Z R%i (%i %x)", reg_num, tran_size, reg->words[0]);
                                        if( cnd & 1 )
                                                ip ++;
                                        break;
                                case UDI_PIO_NNEG:
-                                       LOG("CSKIP NNEG R%i", reg_num);
+                                       LOG("CSKIP NNEG R%i (%i %x)", reg_num, tran_size, reg->words[0]);
                                        if( !(cnd & 2) )
                                                ip ++;
+                                       break;
                                case UDI_PIO_NEG:
-                                       LOG("CSKIP NEG R%i", reg_num);
+                                       LOG("CSKIP NEG R%i (%i %x)", reg_num, tran_size, reg->words[0]);
                                        if( cnd & 2 )
                                                ip ++;
                                        break;
                                }
                                break; }
                        case UDI_PIO_IN_IND:
+                               LOG("IN IND");
                                pio_handle->IOFunc(pio_handle->ChildID, pio_handle->RegSet,
                                        registers[operand].words[0], tran_size, reg, false);
                                _zero_upper(tran_size, reg);
                                break;
                        case UDI_PIO_OUT_IND:
+                               LOG("OUT IND");
                                pio_handle->IOFunc(pio_handle->ChildID, pio_handle->RegSet,
                                        registers[operand].words[0], tran_size, reg, true);
                                break;
@@ -461,6 +479,7 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                _operation_and(tran_size, reg, &registers[operand]);
                                break;
                        case UDI_PIO_AND_IMM:
+                               LOG("AND_IMM R%i &= 0x%x", reg_num, operand);
                                tmpval.words[0] = operand;
                                _zero_upper(UDI_PIO_2BYTE, &tmpval);
                                _operation_and(tran_size, reg, &tmpval);
@@ -469,6 +488,7 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                _operation_or(tran_size, reg, &registers[operand]);
                                break;
                        case UDI_PIO_OR_IMM:
+                               LOG("OR_IMM R%i |= 0x%x", reg_num, operand);
                                tmpval.words[0] = operand;
                                _zero_upper(UDI_PIO_4BYTE, &tmpval);
                                _operation_or(tran_size, reg, &tmpval);
@@ -477,6 +497,8 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                _operation_xor(tran_size, reg, &registers[operand]);
                                break;
                        case UDI_PIO_ADD:
+                               LOG("ADD R%i += R%i", reg_num, operand);
+                               ASSERTC(operand, <, 8);
                                _operation_add(tran_size, reg, &registers[operand]);
                                break;
                        case UDI_PIO_ADD_IMM:
@@ -488,9 +510,12 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                else {
                                        _zero_upper(UDI_PIO_4BYTE, &tmpval);
                                }
+                               LOG("ADD R%i += 0x%x", reg_num, tmpval.words[0]);
                                _operation_add(tran_size, reg, &tmpval);
                                break;
                        case UDI_PIO_SUB:
+                               LOG("SUB R%i -= R%i", reg_num, operand);
+                               ASSERTC(operand, <, 8);
                                _operation_sub(tran_size, reg, &registers[operand]);
                                break;
                        default:
@@ -505,10 +530,12 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                        switch(pio_op)
                        {
                        case UDI_PIO_BRANCH:
+                               LOG("BRANCH %i", operand);
                                ip = _get_label(pio_handle, operand);
                                break;
                        case UDI_PIO_LABEL:
                                // nop
+                               LOG("LABEL %i", operand);
                                break;
                        case UDI_PIO_REP_IN_IND:
                        case UDI_PIO_REP_OUT_IND: {
@@ -540,7 +567,7 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                        pio_handle->IOFunc(pio_handle->ChildID, pio_handle->RegSet,
                                                pio_ofs, tran_size, &tmpval, dir_is_out);
                                        if( !dir_is_out )
-                                               _read_mem(gcb,buf,mem_ptr, mode, tran_size,
+                                               _write_mem(gcb,buf,mem_ptr, mode, tran_size,
                                                        mem_reg, &tmpval);
                                        pio_ofs += pio_stride;
                                        if( mode != UDI_PIO_DIRECT )
@@ -577,8 +604,10 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                                        ret_status = registers[operand].words[0] & 0xFFFF;
                                else
                                        ret_status = registers[operand].words[0] & 0xFF;
+                               LOG("END R%i 0x%x", operand, ret_status);
                                goto end;
                        case UDI_PIO_END_IMM:
+                               LOG("END IMM 0x%x", operand);
                                ASSERTC(tran_size, ==, UDI_PIO_2BYTE);
                                ret_status = operand;
                                goto end;
@@ -595,10 +624,10 @@ void udi_pio_trans(udi_pio_trans_call_t *callback, udi_cb_t *gcb,
                        ops);
        }
 end:
-       callback(gcb, NULL, UDI_OK, ret_status);
+       callback(gcb, buf, UDI_OK, ret_status);
        return ;
 error:
-       callback(gcb, NULL, UDI_STAT_HW_PROBLEM, 0);
+       callback(gcb, buf, UDI_STAT_HW_PROBLEM, 0);
 }
 
 void udi_pio_probe(udi_pio_probe_call_t *callback, udi_cb_t *gcb,

UCC git Repository :: git.ucc.asn.au