Skip to content

Commit

Permalink
(crt) Rename exit stack variables
Browse files Browse the repository at this point in the history
  • Loading branch information
suborb committed Mar 12, 2024
1 parent cd92276 commit cb80d8b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/crt/classic/crt_exit_atexit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

PUBLIC __clib_exit_stack_size

ld hl,(exitsp)
ld hl,(__exit_atexit_funcs)
IF __clib_exit_stack_size > 0
ld de, +(__clib_exit_stack_size * 2)
add hl,de
Expand Down
8 changes: 4 additions & 4 deletions lib/crt/classic/crt_init_atexit.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PUBLIC __clib_exit_stack_size
EXTERN exitsp
EXTERN __exit_atexit_funcs

IF __clib_exit_stack_size > 0
ld hl, -(__clib_exit_stack_size * 2)
Expand All @@ -11,16 +11,16 @@ IF __CPU_GBZ80__
ld hl,sp+0
ld d,h
ld e,l
ld hl,exitsp
ld hl,__exit_atexit_funcs
ld a,l
ld (hl+),a
ld a,h
ld (hl+),a
ELIF __CPU_INTEL__
ld hl,0
add hl,sp
ld (exitsp),hl
ld (__exit_atexit_funcs),hl
ELSE
ld (exitsp),sp
ld (__exit_atexit_funcs),sp
ENDIF

2 changes: 0 additions & 2 deletions lib/target/z88/classic/z88s5_crt0.asm
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ __restore_sp_onexit
; Install the error handler
;-----------
doerrhan:
xor a
ld (exitcount),a
ld b,0
ld hl,errhand
call_oz(os_erh)
Expand Down
2 changes: 0 additions & 2 deletions lib/target/z88/classic/z88s_crt0.asm
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ __restore_sp_onexit ld sp,0 ;Restore stack to entry value
; Install the error handler
;-----------
doerrhan:
xor a
ld (exitcount),a
ld b,0
ld hl,errhand
call_oz(os_erh)
Expand Down
8 changes: 4 additions & 4 deletions libsrc/stdlib/atexit.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PUBLIC _atexit_fastcall

EXTERN __clib_exit_stack_size
EXTERN exitsp, exitcount
EXTERN __exit_atexit_funcs, __exit_atexit_count


atexit:
Expand All @@ -39,7 +39,7 @@ _atexit_fastcall:

ex de, hl ; de = function to register

ld hl, exitcount
ld hl, __exit_atexit_count
ld a, (hl)
cp __clib_exit_stack_size ; can only hold 32 levels..
ret nc ; if full returns with hl!=0
Expand All @@ -49,12 +49,12 @@ _atexit_fastcall:
ld c, a
ld b, 0
IF __CPU_GBZ80__
ld hl, exitsp
ld hl, __exit_atexit_funcs
ld a, (hl+)
ld h, (hl)
ld l, a
ELSE
ld hl, (exitsp)
ld hl, (__exit_atexit_funcs)
ENDIF
add hl, bc
ld (hl), e ; write atexit function
Expand Down
8 changes: 4 additions & 4 deletions libsrc/stdlib/exit.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PUBLIC exit_fastcall
PUBLIC _exit_fastcall

EXTERN __Exit, exitsp, exitcount
EXTERN __Exit, __exit_atexit_funcs, __exit_atexit_count

EXTERN l_jphl

Expand All @@ -44,7 +44,7 @@ asm_exit:

push hl ; save exit value

ld a, (exitcount)
ld a, (__exit_atexit_count)
or a
jr z, end

Expand All @@ -53,12 +53,12 @@ asm_exit:
ld e, a
ld d, 0
IF __CPU_GBZ80__
ld hl, exitsp
ld hl, __exit_atexit_funcs
ld a, (hl+)
ld h, (hl)
ld l, a
ELSE
ld hl, (exitsp) ; hl = & atexit stack
ld hl, (__exit_atexit_funcs) ; hl = & atexit stack
ENDIF
add hl, de ; hl = & last function in exit stack + 2b

Expand Down
8 changes: 4 additions & 4 deletions libsrc/stdlib/exit_vars.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

SECTION bss_clib

PUBLIC exitcount
PUBLIC exitsp
PUBLIC __exit_atexit_count
PUBLIC __exit_atexit_funcs

exitcount: defb 0
exitsp: defw 0
__exit_atexit_count: defb 0
__exit_atexit_funcs: defw 0

0 comments on commit cb80d8b

Please sign in to comment.