libc: сплит «1 функция = 1 модуль» — вся библиотека, wildcard-сборка

- bios/conio/env/errno/gfx/io/mem/mouse/stdio/stdlib/string/sys/time/
  video разложены по модулям: общие статики и helpers — в internal
  _-модулях (_conio.h/_mouse.h/_gfx.h/_palette.h/_atexit.h/_time.h)
- lib/Makefile: LIBC_C = wildcard libc/*/*.c — гранулярность файлов
  = гранулярность DCE линкера
- эффект _CODE: gfx_text 6986→2568 Б, gfx_mous −1745, gfx_demo/d16
  −542; ранее timedir −3270, ls −3098, stattest −2995
- комментарии оставшихся модулей переведены на русский; puts: убран
  мёртвый pchars; videomode_raw разложен на get/set
- docs/libc-split-asm-cases.md — правила asm-связок между модулями;
  docs/libc-roadmap.md — план этапа
- восстановлен examples/mdview/SAMPLE.MD (нужен make floppy)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 16:08:58 +03:00
parent 46553f4e07
commit 4a081501d8
237 changed files with 4830 additions and 3933 deletions
+9 -45
View File
@@ -1,57 +1,21 @@
/*
* atexit + exit + _exit.
* atexit — зарегистрировать функцию, вызываемую при нормальном
* завершении (exit()), максимум 8, порядок LIFO. Возвращает 0 или -1
* при переполнении стека хендлеров.
*
* atexit(fn) — register fn to be called at normal termination (max 8).
* exit(code) — run the atexit chain in LIFO, then ESTEX EXIT.
* _exit(code) — POSIX raw exit: skip the chain, go straight to ESTEX.
*
* These functions own termination entirely; crt0.s only does inline RST
* 10h #41 when main returns without an explicit exit(). That path skips
* the atexit chain — programs that need handlers should call exit() at
* the bottom of main (or return through a wrapper).
* Внимание: возврат из main() без явного exit() уходит в inline RST
* 10h #41 в crt0.s и цепочку atexit НЕ выполняет — программам с
* хендлерами нужно завершаться через exit().
*/
#include <stdlib.h>
#include <sprinter_exit.h>
#define ATEXIT_MAX 8
static void (*atexit_stack[ATEXIT_MAX])(void);
static int atexit_top = 0;
#include "_atexit.h"
int atexit(void (*fn)(void))
{
if (atexit_top >= ATEXIT_MAX) {
if (_atexit_top >= ATEXIT_MAX) {
return -1;
}
atexit_stack[atexit_top++] = fn;
_atexit_stack[_atexit_top++] = fn;
return 0;
}
/* exit() — runs the chain, then performs the raw ESTEX EXIT. */
void exit(int code)
{
while (atexit_top > 0) {
void (*fn)(void) = atexit_stack[--atexit_top];
if (fn) {
fn();
}
}
_exit(code); /* falls into the inline-asm raw exit below */
}
/* _exit() — POSIX raw termination, no atexit chain. */
void _exit(int code) __naked
{
(void)code;
__asm
;; HL = code (single int arg).
ld a, l
ld b, a
ld c, #0x41 ; ESTEX EXIT
rst #0x10
;; Should not return.
1$: halt
jr 1$
__endasm;
}