From: Alan Cox Date: Fri, 13 Feb 2015 21:09:50 +0000 (+0000) Subject: zx128: Fix stubs from common to do a bank restore X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=bdc511b5a98e674129c01d827f93baf540fff7b4;p=FUZIX.git zx128: Fix stubs from common to do a bank restore Turns out this is needed --- diff --git a/Kernel/platform-zx128/zx128.s b/Kernel/platform-zx128/zx128.s index 26a54773..84030586 100644 --- a/Kernel/platform-zx128/zx128.s +++ b/Kernel/platform-zx128/zx128.s @@ -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 diff --git a/Kernel/tools/binmunge.c b/Kernel/tools/binmunge.c index 8295b589..006a0b37 100644 --- a/Kernel/tools/binmunge.c +++ b/Kernel/tools/binmunge.c @@ -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 */