Skip to contentSkip to conversation

m68k: implement movep instruction

PATCH In review Pavel Dovgalyuk 3 participants 5 messages Feb 6, 2018 – Feb 7, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 m68k: implement movep instruction

This patch implements movep instruction. It moves data between a data register and alternate bytes within the address space starting at the location specified and incrementing by two.

It was designed for the original 68000 and used in firmwares for interfacing the 8-bit peripherals through the 16-bit data bus. Without this patch opcode for this instruction is recognized as some bitop.

--

v4: - fixed offset calculation misprint

v3: - simplified movep function code
- joined movep masks

v2: - disabled movep for Coldfire
- fixed gen_store/load usage

---
 target/m68k/cpu.c       |    2 ++
 target/m68k/cpu.h       |    1 +
 target/m68k/translate.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+)
target/m68k/cpu.c +2 -0
index 98919b3..461db85 100644
@@ -113,6 +113,7 @@ static void m68000_cpu_initfn(Object *obj)
     m68k_set_feature(env, M68K_FEATURE_M68000);
     m68k_set_feature(env, M68K_FEATURE_USP);
     m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
+    m68k_set_feature(env, M68K_FEATURE_MOVEP);
 }
 
 static void m68020_cpu_initfn(Object *obj)
@@ -135,6 +136,7 @@ static void m68020_cpu_initfn(Object *obj)
     m68k_set_feature(env, M68K_FEATURE_BKPT);
     m68k_set_feature(env, M68K_FEATURE_RTD);
     m68k_set_feature(env, M68K_FEATURE_CHK2);
+    m68k_set_feature(env, M68K_FEATURE_MOVEP);
 }
 #define m68030_cpu_initfn m68020_cpu_initfn
 
target/m68k/cpu.h +1 -0
index 627fb78..1d79885 100644
@@ -492,6 +492,7 @@ enum m68k_features {
     M68K_FEATURE_RTD,
     M68K_FEATURE_CHK2,
     M68K_FEATURE_M68040, /* instructions specific to MC68040 */
+    M68K_FEATURE_MOVEP,
 };
 
 static inline int m68k_feature(CPUM68KState *env, int feature)
target/m68k/translate.c +46 -0

58 lines not on this page · raw message

Tested-by Reviewed-by on v4 1/1
#1 lore raw

Le 06/02/2018 à 13:44, Pavel Dovgalyuk a écrit :

Quoted 6 lines

This patch implements movep instruction. It moves data between a data register and alternate bytes within the address space starting at the location specified and incrementing by two.

It was designed for the original 68000 and used in firmwares for interfacing the 8-bit peripherals through the 16-bit data bus.

Did you test this change with some kind of firmware?

Quoted 12 lines

Without this patch opcode for this instruction is recognized as some bitop.

--

v4: - fixed offset calculation misprint

v3: - simplified movep function code
- joined movep masks

Quoted 7 lines

v2: - disabled movep for Coldfire
- fixed gen_store/load usage

---
 target/m68k/cpu.c       |    2 ++
 target/m68k/cpu.h       |    1 +
 target/m68k/translate.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+)

I've checked we have the same result on a real 68040

Thanks,
Laurent

#2 lore raw
Quoted 10 lines

From: Laurent Vivier [mailto:[email protected]]

Quoted 6 lines · Pavel Dovgalyuk

This patch implements movep instruction. It moves data between a data register and alternate bytes within the address space starting at the location specified and incrementing by two.

It was designed for the original 68000 and used in firmwares for interfacing the 8-bit peripherals through the 16-bit data bus.

Did you test this change with some kind of firmware?

Yes, we implemented this instruction when tried to emulate Macintosh-128k on Qemu.

Quoted 20 lines
Quoted 12 lines

Without this patch opcode for this instruction is recognized as some bitop.

--

v4: - fixed offset calculation misprint

v3: - simplified movep function code
- joined movep masks

Quoted 7 lines

v2: - disabled movep for Coldfire
- fixed gen_store/load usage

---
 target/m68k/cpu.c       |    2 ++
 target/m68k/cpu.h       |    1 +
 target/m68k/translate.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+)
Quoted 5 lines

I've checked we have the same result on a real 68040

Thanks!

By the way, we also handled reset interrupt, but it is not compatible with other m68k platforms:

@@ -66,8 +66,9 @@ static void m68k_cpu_reset(CPUState *s)

     cpu_m68k_set_fpcr(env, 0);
     env->fpsr = 0;
-    /* TODO: We should set PC from the interrupt vector.  */
-    env->pc = 0;
+    env->vbr = 0;
+    /* PC and SP (for m68k) will be initialized by the reset handler */
+    s->exception_index = EXCP_RESET;

}

@@ -378,6 +380,8 @@ static void m68k_interrupt_all(CPUM68KState *env, int is_hw)

         cpu_m68k_set_sr(env, sr &= ~SR_M);
         sp = env->aregs[7] & ~1;
         do_stack_frame(env, &sp, 1, oldsr, 0, retaddr);
+    } else if (cs->exception_index == EXCP_RESET) {
+        sp = cpu_ldl_kernel(env, env->vbr + vector - 4);
     } else {
         do_stack_frame(env, &sp, 0, oldsr, 0, retaddr);
     }

Pavel Dovgalyuk

#3 lore raw

Le 06/02/2018 à 14:30, Pavel Dovgalyuk a écrit :

Quoted 55 lines
Quoted 10 lines

From: Laurent Vivier [mailto:[email protected]]

Quoted 6 lines · Pavel Dovgalyuk

This patch implements movep instruction. It moves data between a data register and alternate bytes within the address space starting at the location specified and incrementing by two.

It was designed for the original 68000 and used in firmwares for interfacing the 8-bit peripherals through the 16-bit data bus.

Did you test this change with some kind of firmware?

Yes, we implemented this instruction when tried to emulate Macintosh-128k on Qemu.

Quoted 20 lines
Quoted 12 lines

Without this patch opcode for this instruction is recognized as some bitop.

--

v4: - fixed offset calculation misprint

v3: - simplified movep function code
- joined movep masks

Quoted 7 lines

v2: - disabled movep for Coldfire
- fixed gen_store/load usage

---
 target/m68k/cpu.c       |    2 ++
 target/m68k/cpu.h       |    1 +
 target/m68k/translate.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+)
Quoted 5 lines

I've checked we have the same result on a real 68040

Thanks!

By the way, we also handled reset interrupt, but it is not compatible with other m68k platforms:

(quoted diff) +3 -2
@@ -66,8 +66,9 @@ static void m68k_cpu_reset(CPUState *s)
     cpu_m68k_set_fpcr(env, 0);
     env->fpsr = 0;
 
-    /* TODO: We should set PC from the interrupt vector.  */
-    env->pc = 0;
+    env->vbr = 0;
+    /* PC and SP (for m68k) will be initialized by the reset handler */
+    s->exception_index = EXCP_RESET;
 }
 

Review static void m68k_interrupt_all(CPUM68KState *env, int is_hw) · line 387

Quoted 8 lines
(quoted diff) +2 -0
@@ -378,6 +380,8 @@ static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
         cpu_m68k_set_sr(env, sr &= ~SR_M);
         sp = env->aregs[7] & ~1;
         do_stack_frame(env, &sp, 1, oldsr, 0, retaddr);
+    } else if (cs->exception_index == EXCP_RESET) {
+        sp = cpu_ldl_kernel(env, env->vbr + vector - 4);
     } else {
         do_stack_frame(env, &sp, 0, oldsr, 0, retaddr);
     }

It looks better of what I have already coded :)

Do you work using code in
https://github.com/vivier/qemu-m68k , branch q800-dev ?

I'm already emulating a Quadra 800, it can help for Macintosh-128k

Thanks,
Laurent

#4 lore raw
Quoted 31 lines

From: Laurent Vivier [mailto:[email protected]]

Quoted 4 lines · Pavel Dovgalyuk
Quoted 1 line

From: Laurent Vivier [mailto:[email protected]]

Thanks!

By the way, we also handled reset interrupt, but it is not compatible with other m68k

platforms:

Quoted 13 lines
(quoted diff) +3 -2
@@ -66,8 +66,9 @@ static void m68k_cpu_reset(CPUState *s)
     cpu_m68k_set_fpcr(env, 0);
     env->fpsr = 0;
 
-    /* TODO: We should set PC from the interrupt vector.  */
-    env->pc = 0;
+    env->vbr = 0;
+    /* PC and SP (for m68k) will be initialized by the reset handler */
+    s->exception_index = EXCP_RESET;
 }
 

Review static void m68k_interrupt_all(CPUM68KState *env, int is_hw) · line 387

Quoted 8 lines
(quoted diff) +2 -0
@@ -378,6 +380,8 @@ static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
         cpu_m68k_set_sr(env, sr &= ~SR_M);
         sp = env->aregs[7] & ~1;
         do_stack_frame(env, &sp, 1, oldsr, 0, retaddr);
+    } else if (cs->exception_index == EXCP_RESET) {
+        sp = cpu_ldl_kernel(env, env->vbr + vector - 4);
     } else {
         do_stack_frame(env, &sp, 0, oldsr, 0, retaddr);
     }

It looks better of what I have already coded :)

Quoted 2 lines

Do you work using code in
https://github.com/vivier/qemu-m68k , branch q800-dev ?

No, it was a project for our students couple of years ago. We used Qemu 2.3 with not-yet-included patches for 68000.
I believe that someday we'll port our peripherals onto the new version.

There were some fixes for processing the interrupts. As I can see, all of them are not needed for the mainline Qemu.

We didn't find a solution for 24-bit address bus of 68000. Macintosh stores 32-bit values in address registers and uses them to access the memory. We just duplicated the memory layout, but I believe that there is a better solution.

Quoted 1 line

I'm already emulating a Quadra 800, it can help for Macintosh-128k

Here is the repository with Mac-128: https://github.com/Dovgalyuk/qemu
We didn't finally fix all the bugs, but it can boot the OS, using some hacks. One of the hack is related to IWM. We couldn't emulate all timings for that. CPU controls disk rotation speed through controlling the strobe signal. It was hard to synchronize this, because icount wasn't fully working and we used semihosting - we intercepted the file operation system calls and didn't execute ROM code, emulating them in Qemu instead.

Pavel Dovgalyuk