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
+13
View File
@@ -0,0 +1,13 @@
/*
* _atexit.h — внутренний стек atexit-хендлеров, общий для atexit() и
* exit(). НЕ публичный заголовок; данные живут в _atexit_state.c.
*/
#ifndef _ATEXIT_INTERNAL_H
#define _ATEXIT_INTERNAL_H
#define ATEXIT_MAX 8
extern void (*_atexit_stack[ATEXIT_MAX])(void);
extern int _atexit_top;
#endif
+10
View File
@@ -0,0 +1,10 @@
/*
* _atexit_state — стек зарегистрированных atexit-хендлеров (LIFO,
* максимум 8) и его вершина. Модуль только с данными; пишет atexit(),
* читает/сматывает exit().
*/
#include "_atexit.h"
void (*_atexit_stack[ATEXIT_MAX])(void);
int _atexit_top;
+21
View File
@@ -0,0 +1,21 @@
/*
* _exit — POSIX-сырое завершение: без цепочки atexit, сразу ESTEX EXIT
* ($41, B = код возврата). Не возвращается.
*/
#include <sprinter_exit.h>
void _exit(int code) __naked
{
(void)code;
__asm
;; HL = code (единственный int-аргумент).
ld a, l
ld b, a
ld c, #0x41 ; ESTEX EXIT
rst #0x10
;; Возврата быть не должно.
1$: halt
jr 1$
__endasm;
}
+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;
}
+19
View File
@@ -0,0 +1,19 @@
/*
* exit — нормальное завершение: смотать цепочку atexit-хендлеров
* (LIFO), затем сырое завершение _exit() (ESTEX EXIT).
*/
#include <stdlib.h>
#include <sprinter_exit.h>
#include "_atexit.h"
void exit(int code)
{
while (_atexit_top > 0) {
void (*fn)(void) = _atexit_stack[--_atexit_top];
if (fn) {
fn();
}
}
_exit(code);
}