z80: add different includes for CMOS/NMOS Z80
authorAlan Cox <alan@etchedpixels.co.uk>
Sun, 30 Nov 2014 15:08:04 +0000 (15:08 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Sun, 30 Nov 2014 15:08:04 +0000 (15:08 +0000)
Kernel/lowlevel-z80-cmos.s [new file with mode: 0644]
Kernel/lowlevel-z80-nmos.s [new file with mode: 0644]
Kernel/lowlevel-z80.s

diff --git a/Kernel/lowlevel-z80-cmos.s b/Kernel/lowlevel-z80-cmos.s
new file mode 100644 (file)
index 0000000..4e39204
--- /dev/null
@@ -0,0 +1,20 @@
+               .area _COMMONMEM
+
+               ; IRQ helpers, in common as they may get used by common C
+               ; code (and are tiny)
+
+_di:           ld a, i
+               push af
+               pop hl
+               di
+               ret
+
+_irqrestore:   pop hl          ; sdcc needs to get register arg passing
+               pop af          ; so badly
+               jp po, was_di
+               ei
+               jr irqres_out
+was_di:                di
+irqres_out:    push af
+               jp (hl)
+
diff --git a/Kernel/lowlevel-z80-nmos.s b/Kernel/lowlevel-z80-nmos.s
new file mode 100644 (file)
index 0000000..715a7a5
--- /dev/null
@@ -0,0 +1,26 @@
+               .area _COMMONMEM
+
+_di:           xor a           ; NMOS Z80 bug work around as per CPU manual
+               push af
+               pop af          ; clear byte on stack below our usage
+               ld a, i
+               jp pe, was_ei   ; P is now IFF2, if irqs on return is safe
+               dec sp          ; the CPU may have lied due to an erratum
+               dec sp
+               pop af          ; see if anyone pushed a return address
+               and a
+               jr nz, was_ei   ; someone did - IRQs were enabled then
+               scf             ; disabled
+was_ei:                push af
+               pop hl
+               ret
+
+_irqrestore:   pop hl
+               pop af
+               jr c, was_di
+               ei
+               jr irqres_out
+was_di:                di
+irqres_out:    push af
+               jp (hl)
+
index b90593a..2893fe0 100644 (file)
@@ -430,29 +430,6 @@ nmi_handler:
 
 
        .area _COMMONMEM
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
-               ; IRQ helpers, in common as they may get used by common C
-               ; code (and are tiny)
-
-_di:           ld a, i
-               push af
-               pop hl
-               di
-               ret
-
-_irqrestore:   pop hl          ; sdcc needs to get register arg passing
-               pop af          ; so badly
-               jp po, was_di
-               ei
-               jr irqres_out
-was_di:                di
-irqres_out:    push af
-               jp (hl)
-
-
-
 
 ; outstring: Print the string at (HL) until 0 byte is found
 ; destroys: AF HL
@@ -530,3 +507,12 @@ numeral:add a, #0x30 ; start at '0' (0x30='0')
         call outchar
         ret
 
+;
+;      Pull in the CPU specific workarounds
+;
+
+       .if NMOS_Z80
+       .include "lowlevel-z80-nmos.s"
+       .else
+       .include "lowlevel-z80-cmos.s"
+       .endif