From: uz Date: Sun, 22 Feb 2009 18:10:01 +0000 (+0000) Subject: Fixed problems with the startup code (Greg King): Interrupts must be hooked X-Git-Tag: V2.13.0rc1~304 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d28ba06f79df0d6f2ebb7c5ae8a0a61616dd830f;p=cc65 Fixed problems with the startup code (Greg King): Interrupts must be hooked before calling initlib because initlib calls contructors and may install drivers, which enable hardware interrupts. Similar for donelib. See also R3897 where this change was done for other platforms. git-svn-id: svn://svn.cc65.org/cc65/trunk@3951 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index 1d5641a7c..1e63617c2 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -70,10 +70,6 @@ L1: lda sp,x lda MEMSIZE+1 sta sp+1 ; Set argument stack ptr -; Call module constructors - - jsr initlib - ; If we have IRQ functions, chain our stub into the IRQ vector lda #<__INTERRUPTOR_COUNT__ @@ -89,13 +85,21 @@ L1: lda sp,x stx IRQVec+1 cli +; Call module constructors + +NoIRQ1: jsr initlib + ; Push arguments and call main() -NoIRQ1: jsr callmain + jsr callmain ; Call module destructors. This is also the _exit entry. -_exit: pha ; Save the return code on stack +_exit: pha ; Save the return code on stack + jsr donelib + +; Reset the IRQ vector if we chained it. + lda #<__INTERRUPTOR_COUNT__ beq NoIRQ2 lda IRQInd+1 @@ -105,13 +109,9 @@ _exit: pha ; Save the return code on stack stx IRQVec+1 cli -; Run module destructors - -NoIRQ2: jsr donelib ; Run module destructors - ; Copy back the zero page stuff - ldx #zpspace-1 +NoIRQ2: ldx #zpspace-1 L2: lda zpsave,x sta sp,x dex diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index 42833b87a..c5ce0c7a1 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -80,16 +80,16 @@ L1: lda sp,x jsr zerobss -; Call module constructors - - jsr initlib - ; Initialize irqcount, which means that from now own custom linked in IRQ ; handlers (via condes) will be called. lda #.lobyte(__INTERRUPTOR_COUNT__*2) sta irqcount +; Call module constructors + + jsr initlib + ; Push arguments and call main() jsr callmain @@ -97,9 +97,12 @@ L1: lda sp,x ; Back from main (this is also the _exit entry). Run module destructors. _exit: pha ; Save the return code + jsr donelib ; Run module destructors + +; Disable chained IRQ handlers + lda #0 sta irqcount ; Disable custom IRQ handlers - jsr donelib ; Run module destructors ; Copy back the zero page stuff