zx128: Fix stubs from common to do a bank restore
authorAlan Cox <alan@linux.intel.com>
Fri, 13 Feb 2015 21:09:50 +0000 (21:09 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 13 Feb 2015 21:09:50 +0000 (21:09 +0000)
Turns out this is needed

Kernel/platform-zx128/zx128.s
Kernel/tools/binmunge.c

index 26a5477..8403058 100644 (file)
@@ -357,37 +357,36 @@ __bank_3_2:
        jr bankina3
 
 ;
-;      Stubs from common are the easy case and use HL
-;
-;      FIXME: if we ever stub a function that is in discard/common and
-;      which calls into code that bank switches then returns this will
-;      break. If that happens then these will need munging into the
-;      method used in __bank_0_x (ick)
+;      Stubs need some stack munging and use DE
 ;
+
 __stub_0_1:
        xor a
+__stub_0_a:
+       pop hl          ; the return
+       ex (sp), hl     ; write it over the discard
+       ld bc, (current_map)
        call switch_bank
-       jp (hl)
-
+       ld a, c
+       or a
+       jr z, __stub_1_ret
+       dec a
+       jr z, __stub_2_ret
+       jr __stub_3_ret
 __stub_0_2:
-       ld a,#1
-       call switch_bank
-       jp (hl)
-
+       ld a, #1
+       jr __stub_0_a
 __stub_0_3:
-       ld a,#7
-       call switch_bank
-       jp (hl)
+       ld a, #7
+       jr __stub_0_a
 
-;
-;      Other stubs need some stack munging and use DE 
-;
 __stub_1_2:
        ld a, #1
 __stub_1_a:
        pop hl          ; the return
        ex (sp), hl     ; write it over the discad
        call switch_bank
+__stub_1_ret:
        ex de, hl
        call callhl
        xor a
@@ -406,6 +405,7 @@ __stub_2_a:
        pop hl          ; the return
        ex (sp), hl     ; write it over the discad
        call switch_bank
+__stub_2_ret:
        ex de, hl       ; DE is our target
        call callhl
        ld a,#1
@@ -424,6 +424,7 @@ __stub_3_a:
        pop hl          ; the return
        ex (sp), hl     ; write it over the discad
        call switch_bank
+__stub_3_ret:
        ex de, hl
        call callhl
        ld a,#7
index 8295b58..006a0b3 100644 (file)
@@ -124,11 +124,8 @@ int stubmap(uint16_t v, int sbank, int dbank)
   /* FIXME: we could have per bank stubs in ROM and not waste precious
      common memory here */
   da = get_stub_function(sbank, dbank);
-  if (sbank) /* LD DE */
-    buf[0][nextfix++] = 0x11;
-  else /* LD HL */
-    buf[0][nextfix++] = 0x21;
   /* LD DE, targetaddr */
+  buf[0][nextfix++] = 0x11;
   buf[0][nextfix++] = v & 0xFF;
   buf[0][nextfix++] = v >> 8;
   /* JP */