hexed: add jump cmd, refactor transfer
authornotaz <notasas@gmail.com>
Mon, 16 May 2011 20:18:23 +0000 (23:18 +0300)
committernotaz <notasas@gmail.com>
Mon, 16 May 2011 20:18:23 +0000 (23:18 +0300)
hexed/hexed.s
hexed/pc_transfer.c
hexed/transfer.S
hexed/transfer.h

index 010346d..3746191 100644 (file)
@@ -443,6 +443,7 @@ no_auto_transfer:
        lea             (jumptab,pc,d0),a0
        jmp             (a0)
 jumptab:
+       /* branch insns here because we want to be position independent */
        bra             mode_main
        bra             mode_val_input
        bra             mode_edit_val   /* edit val in editor */
index 309c383..9e2681a 100644 (file)
@@ -157,7 +157,8 @@ static void usage(const char *argv0)
 {
        fprintf(stderr, "usage:\n%s <cmd> [args]\n"
                "\tsend <file> <addr> [size]\n"
-               "\trecv <file> <addr> <size>\n", argv0);
+               "\trecv <file> <addr> <size>\n"
+               "\tjump <addr>\n", argv0);
        exit(1);
 }
 
@@ -235,6 +236,13 @@ int main(int argc, char *argv[])
 
                memset(data, 0, size);
        }
+       else if (strcmp(argv[1], "jump") == 0)
+       {
+               if (argc != 3)
+                       usage(argv[0]);
+
+               addr = atoi_or_die(argv[2]);
+       }
        else
                usage(argv[0]);
 
@@ -253,13 +261,12 @@ int main(int argc, char *argv[])
        if (inb(PORT_STATUS) & 0x40)
                printf("waiting for TH low..\n");
        while (inb(PORT_STATUS) & 0x40)
-               sleep(1);
+               usleep(100000);
 
        outb(0xe0, PORT_CONTROL);
 
        if (strcmp(argv[1], "send") == 0)
        {
-               printf("send %06x %06x\n", addr, size);
                send_cmd(CMD_MD_SEND);
                send_byte((addr >> 16) & 0xff);
                send_byte((addr >>  8) & 0xff);
@@ -303,9 +310,19 @@ int main(int argc, char *argv[])
 
                fwrite(data, 1, size, file);
        }
-       printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
-       printf("%06x/%06x\n", i, size);
-       fclose(file);
+       else if (strcmp(argv[1], "jump") == 0)
+       {
+               send_cmd(CMD_JUMP);
+               send_byte((addr >> 16) & 0xff);
+               send_byte((addr >>  8) & 0xff);
+               send_byte((addr >>  0) & 0xff);
+       }
+
+       if (file != NULL) {
+               printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
+               printf("%06x/%06x\n", i, size);
+               fclose(file);
+       }
 
        /* switch TL back to high, disable outputs */
        outb(0xe0, PORT_CONTROL);
index e4d5a2b..4ab3aff 100644 (file)
@@ -88,6 +88,7 @@
 .endm
 
 recv_byte:
+       moveq.l         #0,d0
        recv_one_byte 1
        rts
 
@@ -118,14 +119,23 @@ do_transfer:
        bne             return
 
        bsr             recv_byte
-       cmp.b           #CMD_MD_SEND,d0         /* sent to us */
-       beq             transfer_recv
-       cmp.b           #CMD_MD_RECV,d0         /* recv from us */
-       beq             transfer_send
-       bra             return
-
-
-transfer_recv:
+       cmp.b           #CMD_FIRST,d0
+       bcs             return
+       cmp.b           #CMD_LAST+1,d0
+       bcc             return
+       sub.b           #CMD_FIRST,d0
+
+       lsl.w           #2,d0
+       lea             (jumptab,pc,d0),a0
+       jmp             (a0)
+jumptab:
+       bra             pcc_transfer_recv       /* sent to us */
+       bra             pcc_transfer_send       /* recv from us */
+       bra             pcc_jump
+       bra             pcc_test_code
+
+
+pcc_transfer_recv:
        bsr             recv_ad
        move.l          d0,a0
        bsr             recv_ad
@@ -135,10 +145,11 @@ tr_recv_loop:
        recv_one_byte
        move.b          d0,(a0)+
        subq.l          #1,d3
-       bne             tr_recv_loop
+       bgt             tr_recv_loop
        bra             return
 
-transfer_send:
+
+pcc_transfer_send:
        bsr             recv_ad
        move.l          d0,a0
        bsr             recv_ad
@@ -156,7 +167,17 @@ tr_send_loop:
        move.b          (a0)+,d0
        send_one_byte
        subq.l          #1,d3
-       bne             tr_send_loop
+       bgt             tr_send_loop
+       bra             return
+
+
+pcc_jump:
+       bsr             recv_ad
+       move.l          d0,a0
+       jmp             (a0)
+
+
+pcc_test_code:
        bra             return
 
 
index 0fcda0c..b1aa7cd 100644 (file)
@@ -1,4 +1,8 @@
 #define CMD_PREFIX     0x5a
 #define CMD_MD_SEND    0xc1    /* send to MD:   addr[3], len[3], data[] */
 #define CMD_MD_RECV    0xc2    /* recv from MD: addr[3], len[3], data[] */
+#define CMD_JUMP       0xc3    /* jump to addr: addr[3] */
+#define CMD_TEST       0xc4    /* test code */
 
+#define CMD_FIRST      CMD_MD_SEND
+#define CMD_LAST       CMD_TEST