summaryrefslogtreecommitdiff
path: root/README
blob: 48a1d975277c909e71ac4a2c6665e9ffc7776f8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
mission
-------

Build a small Linux system with as little resource usage as possible.
Modern kernel, suckless if possible, i486 as target. Trying to
squeeze binaries with NetBSD cruch. Using a floppy boot loader
which uses a USTAR-like format for storing kernel and ramdisk.
Using musl for its ability to produce small static binaries.

requirements
------------

- A native C compiler. gcc/clang is a must for the Linux kernel
- NASM for assembling the floppy boot loader 'uflbbl'
- a make, probably GNU make is required

directory layout
----------------

scripts/   build scripts
lib/       libraries for build scripts
dowloads/  downloaded software (tarballs or git/svn/cvs checkouts)
src/       contains all unpacked sources for building
../stage0  host toolchain building
../stage1  ramdisk first native build
configs/   configurations used during building, e.g. suckless config.h files
build/     the binary artifacts of each stage
../stage0
../stage1
local/     local adaptions and configurations which go into the ramdisk
ramdisk/   the ramdisk being later compressed to ramdisk.img
root/      the root filesystem later being used via NBD or directly as image
tests/     test programs to test sanity of stages
tools/     various tools needed on the host to build the distro

patches
-------

- tcc
  * musl uses 't' and 'u' for i487 stack inline assembly, we try not
    to use floating point anywhere, currently the tcc patch is a
    non-functional stub to make musl compile
  * configure fails completly when used with the stage0 compiler, we
    patch by hand 'configure' and 'Makefile' to build a standalone
    version using stage0 libaries and header files
  * 'config.mak' sets correct pathes and CPU flags for the i386 architecure
- musl
  * tcc doesn't expand macro definitions in inline assembly:
    SYSCALL_INSNS in syscall stubs. Expanded them by hand.
  * tcc has no support for 'Complex', we just define it empty and
    we never use complex numbers
  * replaced 'weak hidden' with
    '__attribute__((weak)) __attribute__((hidden))'
    which is more standard conform
  * 'fabs', 'fmod' have assertions to not be used, they use inline
    assmmbly for i487 stack inline assembly markers
  * '*rint': fistpll to flds, tcc has not everywhere the same opcode
    mnemonics as gcc and clang
  * 'sigsetjmp': replaced 'jecxz 1f' with 'jecxz 1b' and converting the
    far forward jump to a predefied near jump
- ubase
  * 'sys/sysmacros.h' is missing for 'minor' and 'major'
- smdev
  * 'sys/sysmacros.h' is missing for 'minor' and 'major'
- netbsd-curses
  * ignoring 'strong alias' attribute
- vis
  * disabled probing of 'curses/termcap' with 'pkconfig', added them
    directly to 'configure'
- dropbear
  * patched binary locations and pathes in default_options.h
- tinyxlib
  * added a missing stdint.h
  * patched compiler and linker flags
- tinyxserver
  * patched installation
  * patched compiler and linker flags
- xauth
  * disabled IPv6
- xhost
  * disabled IPv6
  * fixed some missing IPv6 conditionals
  * added conditional for FamilyServerInterpreted ("si:")
- image viewer
  - meh
    * disabled external libraries for gif, png, jpeg, imagemagick
    * fixed dependency generator
  - feh as alternative?
- slock
  * fixed for missing setgroups in musl
  * disabled XRandr extension
- lua
  * removed dependency on readline
- wordgrinder
  * TODO: work in progress
- rxvt
  * use the 'fixed' font per default and only that one
- notion
  * disabled XCB for keysum definitions
  * patched for using the stage1 libraries and header files
  * heavily patched Xrandr so at least the lua module builds
    (it cannot possibly work though), made the module return
    some default VGA mode values to at least work as a dummy.
  * linker fix for -rdynamic
  * patches for building statically and doing a lua module preload
  * disabled Xinerama
  
dependencies
------------

- vis
  - libevent
  - libtermcap
  - netbsd-curses
  - optionally lua
- tmux
  - libevent
  - netbsd-curses (compat.h:379: error: incompatible types for redefinition of 'forkpty',
    some non-compiling fallback when there is no curses?)
- mandoc
  - zlib
- lua51
- tinyxserver
  - tinyxlib
  - some basic fonts for default and cursor
  
kernel options
--------------

We just enable things we absolutely need to be running Linux, each config
option below states the main reason we think, it has to be enabled.
The starting point of the Linux kernel configuration is 'make tinyconfig'.

- CONFIG_M486SX=y
  - go to the lowest supported kernel "This kernel requires an i686 CPU"

- CONFIG_TTY=y
  - we need some TTY support for any kind of output

- CONFIG_VT_CONSOLE=y
  CONFIG_VGA_CONSOLE=y
  - usual VGA virtual consoles

- CONFIG_SERIAL_8250=Y
  CONFIG_SERIAL_CORE_CONSOLE=Y
  - serial console without kernel output

- CONFIG_PRINTK=y
  CONFIG_X86_VERBOSE_BOOTUP=y
  CONFIG_EARLY_PRINTK=y
  CONFIG_BUG=y
  CONFIG_DEBUG_BUGVERBOSE=y
  CONFIG_FRAME_POINTER=y
  - enable an early boot console (otherwise we don't see
    any errors anymore)
    "Booting from ROM...
    "early console in setup code"
  - show early boot messages and early console messages
  - enable bug reporting of the kernel
  - frame pointers allow stack strace in case of errors

- CONFIG_MAGIC_SYSRQ=y
  - for debugging
  
- CONFIG_LOG_BUF_SHIFT=16
  CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=12
  - trying to make some buffers smaller, the effect might not be that
    big

- CONFIG_BLK_DEV_INITRD=y
  CONFIG_RD_XZ=y
  - allow an XZ compressed ramdisk

- CONFIG_ELF_CORE=y
  CONFIG_BINFMT_ELF=y
  - "Run /bin/sinit as init process
     Failed to execute /bin/sinit (error -2)"

- MODIFY_LDT_SYSCALL
  - "Run /bin/sinit as init process
     process '/bin/sinit' started with executable stack
     traps: sinit[1] general protection fault ip:804b0e8 sp:bfa84c10 error:0 in sinit[8049000+5000]"
     => this is the error we get
  - musl
    (https://stackoverflow.com/questions/30377020/on-linux-is-tls-set-up-by-the-kernel-or-by-libc-or-other-language-runtime)
    "I haven't looked at glibc yet, but I just checked musl. It initializes
    the TLS on startup (as you said), but then also uses a set_thread_area
    syscall to make an entry in the process' LDT which points to the space
    allocated for TLS. Then libc sets the %gs register so that it refers to
    the LDT entry for TLS. (This is on x86-32 -- x86-64 uses a different
    segment register.)" – –  Alex D May 28, 2015 at 6:48

- CONFIG_POSIX_TIMERS=y
  - "Run /bin/sinit as init process
     process '/bin/sinit' started with executable stack
     process 1 (sinit) attempted a POSIX timer syscall while CONFIG_POSIX_TIMERS is not set"

- CONFIG_BINFMT_SCRIPT=y
  - "Run /bin/sinit as init process
     ...
    "execvp: Exec format error"
    => we try to execute a shell script

- CONFIG_DEVTMPFS=y
  DEVTMPFS_MOUNT=y
  - one visible effect is that getty cannot spawn a login session (and
    on the serial console you see tons of errors about /dev/ttyX not
    being available)
  - TODO: do we still need that if we have smdev?

- CONFIG_PROC_FS=y
  - "login: ttyname: No such file or directory"

- CONFIG_MULTIUSER=y
  CONFIG_NET=y
  - "login: initgroups: Function not implemented"
  - musl (in getpwnam)
    - nscd query code which calls 'socket' and then only falls back
      to using files, this is a problem in musl.

- CONFIG_PROC_SYSCTL=y
  (CONFIG_PROC_PAGE_MONITOR=y ?)
  CONFIG_SYSFS=y
  => we want to have /proc and /sys
  => not quite sure, but either CONFIG_PROC_FS or CONFIG_SYSFS is needed)

- CONFIG_UNIX98_PTYS
  "mount: mount: devpts: No such device"

- CONFIG_COMPAT_32BIT_TIME
  - for 32-bit time parameter as in pselect (this of course made the
    whole thing non-2038-safe)
    "vis: mainloop function not implemented", needs 'pselect'
    "pselect, function not implemented SYS_pselect6_time64"

- CONFIG_MSDOS_PARTITION
  - for fdisk

- CONFIG_MODULES
  - modules support, for everything which doesn't has to be in the
    kernel, we can have a module and load it in rc.init.

- CONFIG_UNIX (networking options, as module), unix domain sockets
  - tmux

- CONFIG_PCI_QUIRKS=y
  "8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
   8139cp 0000:00:03.0: found PCI INT A -> IRQ 11
   8139cp: probe of 0000:00:03.0 failed with error -22"
  22 is EINVAL, this is a nasty one to find
  
- CONFIG_VGA_ARB
  => might be needed for PCI not to choke on VGA cards

- CONFIG_BLK_DEV_FD=m
  => we might want to use floppies for confugration or files
  
- CONFIG_BLK_DEV_NBD=m
  => NBD support for root filesystem on network block device

- CONFIG_EXT4_FS=m, CONFIG_EXT4_USE_FOR_EXT2=y
  => mount ext4 filesystems (for instance the root.img)

Debugging:

- CONFIG_KALLSYMS=y
  CONFIG_KGDB=y
  CONFIG_UNWINDER_FRAME_POINTER=y
  CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
  CONFIG_FRAME_POINTER=y
  CONFIG_UNWINDER_FRAME_POINTER=y

Memory optimization:

- CONFIG_PHYSICAL_START=0x1000000 16M
  CONFIG_PHYSICAL_ALIGN=0x2000 8K
  CONFIG_RELOCATABLE=n
  boot.asm: set ramdisk and linux addresses correctly

tinyx/framebuffer:

- CONFIG_FB=y
  => generic framebuffer support

- CONFIG_FRAMEBUFFER_CONSOLE=y
  => console on framebuffer

- CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION=y
- CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y

- CONFIG_FONTS
  => do we need them, at least fk.ko complains about font functions otherwise

- CONFIG_FB_VESA=y
  => only selectable if framebuffer support is NOT built as modules
  => this also means we can only start x framebuffer X in the most generic
     SVGA case when using no modules for the framebuffer modules
  => works only if a vga=XXX parameter is passed on boot?


TODO: CONFIG_FB_VGA16=m
  => for lowest VGA mode
  => never got that one working
  => not sure if that one is needed when choosing VGA in framebuffer

TODO: looks optional for a simple running system
- CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION=y
  => we use fbdev low-level drivers for Cirrus, Alix, etc.

- CONFIG_FB_CIRRUS=y
  => for the Unisys 486 machine, also for qemu?

- CONFIG_FB_GEODE_LX=y
  => for the Alix 1.E

TODO: needed? and for which cards?
- CONFIG_FB_SIMPLE=y

- CONFIG_FB_DEVICE=y
  => to get a /dev/fb*
  => TODO: check if XF86fbdev need that

TODO: which one of the hardware acceleration options are needed for
which cards and have performace benefits (Cirrus for instance should
have BtBlt functions)
- CONFIG_FB_TILEBLITTING=y

TODO: what happens when we have multiple framebuffer drivers, which one
takes precedence (for instance SVGA over VGA16 over CIRRUS?).
  
- CONFIG_MOUSE_PS2=m
- CONFIG_INPUT_MOUSEDEV=m
  CONFIG_INPUT_MOUSEDEV_PSAUX=y
  
- CONFIG_INPUT_EVDEV=m
  => /dev/input/eventX

- CONFIG_SYSFB_SIMPLEFB=y
  => so we get output after the vga= mode is set, so the output
     continues on the VGA text console
     
TODO: CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
TODO: FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y
  
TODO FROM HERE:

TODO: preemption better for 1 CPU systems, Desktop?

BLOCK_LEGACY_AUTOLOAD?? needed for /dev/ram0?
are we doing pivot_root ?
  
- CONFIG_LEGACY_PTYS=y
  CONFIG_LEGACY_PTY_COUNT=16

- CONFIG_TIMERFD
  - for sdhcp

cd ../linux

#TODO
[*]   Multiple users, groups and capabilities support
[*]   Legacy autoloading support
[*] Enable core dump support
[*]   RAM block device support
[*]   AT keyboard (NEW)   
[*]   PS/2 mouse (NEW)

bugs
----

- getpass in login needs legacy BSD ttys?
- tcc cannot compile the linux kernel. Most likely this will remain
  a bug forever.. so we must use gcc toolchain for building the kernel,
  tcc doesn't work since a long time (since tccboot) or only in non-public
  experimental tcc/linux branches
- Having i486tcc-linux self-hosting might not be feasable as we
  have too many funny build tools around and we don't want to get
  into the busybox/tinderbox trap, where everything has to be
  emulated. We rather reimplement software to use less build
  tools (at most tcc and samurai and maybe some confiure-like
  new tool).
- 'joe' is quite slow in startup. For now we resort to 'vis' with
  somewhat better performance. It's not clear whether the software is
  so slow or because we use 'tcc'.
- build only the i386 (or choosen cross-compiler), especially the native
  one for stage1. The stage0 can be a full or a partial cross-compiler
  ideally. For now both stages are building a full cross-compiler and
  then superflous architectures are removed. Fixing this likely needs
  some rewrite of the tcc Makefiles.
- The native compiler in stage1 doesn't set pathes correctly:
    # tcc -o test test.c
    tcc: error: file 'crt1.o' not found
    tcc: error: file 'crti.o' not found
    test.c:1: error: include file 'stdio.h' not found
  Does recompiling it help?
  It's just search pathes presumably still being hard-coded to root/stage1,
  this works for now (as workaround):
    i386-tcc -vv -static -L/lib -I/include -nostdlib -c  -o test.o test.c
    i386-tcc -vv -static -L/lib -I/include -nostdlib -o test /lib/crt1.o test.o /lib/libc.a
  so recompiling it inside the chroot might work (though it needs patching
  again and a stage2 probably, as it has to run inside the chroot and eventually
  even inside a qemu emulation).
- currently we bundle too many things in the initial ramdisk:
  - all kernel modules (instead of just the essential or/and the ones
    fitting to the hardware)
- kernel modules should remain uncompressed when added to the ramdisk and
  compressed as *.ko.xz when living in a normal filesystem on a floppy
  or hard disk.
- binaries are not crunched. sbase/ubase/abase create Xbase-box crunched
  binaries by hand, doesn't work across packages. NetBSD crunch approach
  could help.
- vis has no lua interpreter support build-in currently (needed?)
- gave up on ex, is not really working:
  memory management issues, always results in "Out of memory - too many lines in file"
  This editor is a little bit too low level to use anyway.
- a lot of stuff is copy-pasted between sbase/ubase/abase/smdev, etc. for
  instance parts of libutil
- we heavily use tools from the host (perl, python, make, m4, etc.) from
  the host (but we don't want those tools inside our system also). So
  self-hosting will be tricky.
- mandoc needs zlib unconditionally, if we don't have compressed man pages,
  we need to patch this and add a NO_COMPRESSION flag to 'configure.local'.
- a poweroff sending SIGUSR1 to sinit would be nice, also shutdown fails
  by leaving users logged in (stuck in shell, getty is killed, but there
  is no message on the screen or so) and it doesn't unmount /.
  (umount2 / error), there is also no 'wall'
- minimal binary seed: not that important that we have a small enough requirement
  list to start with, currently:
  - host C compiler
  - host C library to link against first tcc
  - tons of tools which are not really binary seed 
    (they are just used to produce binaries)
- can we use ccache and distcc with tcc?
- nbd-client gets killed before calling killall5, we cannot mark it
  to be started by 'init' presumably (as systemd does), we can also not
  umount it otherwise we don't have killall5. There is the option of
  having a shutdown ramdisk (as others do)..
- maybe we need a shutdown ramdisk (generated on the fly or using
  pivot_root and not switch_root and reuse the init ramdisk - but
  loosing the memory while running and pivot_root is a deprecated
  syscall. And we have a new ramarchive initrd and not a traditional
  ramdisk. The shutdown ramdisk is not so much a ramdisk but a tmpfs
  you are not unmounting with the rest of the file systems. And you
  populate it with killall5 and unmount, etc.
- qemu: Slirp: Failed to send packet, ret: -1
  => seems to be a qemu network thingy..
- vis sometimes looses first line of text or shows strange artefacts
  when exiting it
- If building on x86_64, you need lib32 glibc and gcc-libs for tcc
  to link a standalone version between stage0 and stage1
- does the ramdisk get correctly unmounted? I see a /mnt busy message
  when doing the switch_root
- man pages are not compressed on the root partition, mandoc can deal
  with compressed pages (as it requires zlib)
- low memory support
  low ram: 0 - 011e0000
  -> 011E0000 = 18MB
  RAMDISK: [mem 0x00580000-0x0062bfff]
  62BFFF-580000 704511
  -> ramdisk.img is 704152 compressed, where does it get unpacked to
  Memory: 12984K/17912K available (1990K kernel code, 446K rwdata, 532K rodata, 204K init, 148K bss, 4928K reserved, 0K cma-reserved)
  -> roughly 6 MB of kernel space
  Unpacking initramfs...
  -> right, where to, or does it live in the cache only?
  Freeing initrd memory: 688K
  -> is this our ramdisk? we didn't to switch_root yet
- tcc is almost usable inside the i486 system, just some pathes are
  wrong, this small example works fine:
  mkdir -p /home/abaumann/projects/i486tcc-linux/build/stage1
  /home/abaumann/projects/i486tcc-linux/build/stage1
  ln -s /include .
  ln -s /lib .
  cat test.c <<EOF
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main( int argc, char *argv[] )
{
    puts( "hello" );
    
    exit( EXIT_SUCCESS );
}
EOF
  i386-tcc -c -o test.o test.c
  i386-tcc -static -o test test.o
  => recompilation of tcc inside the 486 system might be a problem because
     of the build system
- modern Xorg ist out of reach (and old devices DO have good framebuffer support!),
  Xvesa from tinyx doesn't build because of missin vm86 stuff (presumable for mode
  timing), this might be because we use musl?
  Xfbdev builds, vesafb only works when started at boot time (not as module) which is
  annoying.
- minimize fonts
- Xfbdev :0 -fp /share/X11/fonts
- "Could not init font path element ../share/X11/fonts/, removing from list"
  https://www.x.org/releases/X11R7.5/doc/libXfont/fontlib.html
  => the pathes must be absolute and no errors in any file whatsover!
     Only BCF, PCF are supported
- font handling when installing, currently in local/share/fonts/X11, we
  should generate them from BCF files
- rxvt: can't load font "7x14"
- we need to set the video mode for the floppy loading mode with rdev,
  vga=? seems not to be used when booting via Linux real mode boot mode
  (qemu_direct works fine with vga=?)
- notion: keyboard XCB missing in tinyxlib? tcc: error: undefined symbol 'XkbKeycodeToKeysym'
- notion: some dummy Xrandr implementation, but as long as we don't use
  the mod_xrandr module, we should be fine (tinyxlib has some Xrandr function
  stubs for a possible extention - similar like XCB - but the implementation
  is somehow missing) 
- notion: default font contains all glyphs and not only the ISO-8859-1 ones
- notion: more fonts (for status bar? menues?):
2023-07-29 21:14:41 WARN  /notion/../font.c:184: de_load_font: Could not load font "-*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*", trying "fixed"
2023-07-29 21:14:41 WARN  /notion/../font.c:184: de_load_font: Could not load font "-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*", trying "fixed"
2023-07-29 21:14:41 WARN  /notion/../font.c:184: de_load_font: Could not load font "-*-helvetica-medium-r-normal-*-17-*-*-*-*-*-*-*", trying "fixed"
  => de/font.c if(ioncore_g.use_mb), if not use_mb, then is should use fixed
  => this depends on the LANG setting supposedly
- notion:
notion: XSupportsLocale() failed.
notion: Reverting locale settings to "C".
2023-07-29 21:14:40 INFO  /notion/../ioncore.c:613: ioncore_startup: Starting Notion
notion: Failed to open input method.
>> mod_xrandr: Unable to initialise module.
>> Stack trace:
   0 [C]: in 'load_module'
   1 mod_xrandr.lua:5
     [Skipping unnamed C functions.]
   4 [C]: in 'dopath'
   5 /etc/notion/cfg_defaults.lua:15
     [Skipping unnamed C functions.]
   8 [C]: in 'dopath'
   9 /etc/notion/cfg_notion.lua:115
     [Skipping unnamed C functions.]
sh: xmessage: not found
notion: Caught signal 2. Dying.
Segmentation fault 
=> xrandr is a dummy module (but the shared library should be loaded by lua?)
=> xmessage: do we really want to install that Xorg app?
- wordgrinder: segfaults in luapeg on first script, probably a static linking
  issue or a tcc issue?
- rxvt: 2.7.10 doesn't link statically and has a rxvt-2.7.10 additionally to
  rxvt.
  TODO: we use rxvt-2.6.4, why exactly?
- real hardware (Unisys): softirq kernel panic
Starting network via DHCP..                                                                              
ne ne.0 (unnamed net_device) (uninitialized): NE*000 ethercard probe at 0x300:                           
00:00:e8:cd:05:88                                                                                        
ne ne.0 eth0: NE2000 found at 0x300, using IRQ 10.                                                       
random: crng init done                                                                                   
------------[ cut here ]------------                                                                     
NETDEV WATCHDOG: eth0 (ne): transmit queue 0 timed out 444 ms                                            
WARNING: CPU: 0 PID: 0 at net/sched/sch_generic.c:525 0xc02921bb                                         
Modules linked in: ne 8390p                                                                              
CPU: 0 PID: 0 Comm: swapper Not tainted 6.4.7 #1                                                         
EIP: 0xc02921bb                                                                                          
Code: 3f c0 00 75 2a 89 45 e8 c6 05 1f 2f 3f c0 01 8b 45 ec e8 a7 e9 fd ff 8b 55 e8 52 56 50 ff 75 ec 68b
EAX: 0000003d EBX: c112d234 ECX: 00000066 EDX: 00000000                                                  
ESI: 00000000 EDI: c13fd680 EBP: c0811f60 ESP: c0811f34                                                  
DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068 EFLAGS: 00210282                                            
CR0: 80050033 CR2: b7fe1080 CR3: 008b8000 CR4: 00000000                                                  
Call Trace:                                                                                              
 <SOFTIRQ>                                                                                               
- also real hardware (Unisys): no graphic VESA, only text-VESA modes, missing
  => cirrus framebuffer drivers at boot time (cannot be a module)?
  => same behaviour with cirrus in qemu and 86box, enabling a PCI bus suddently
     gives us cirrusfb messages and a working /dev/fb* (not more modes though)
- ${BASE} and @@BASE@@ with sed are both used to pass the build pathes to
  builds in patches. ${BASE} sounds like it is working more by accident..
- 'cd DIR' used everywhere without 'cd DIR || exit 1'
- can we do a crunch binary for X apps, they get 400k when linked statically
  with X libraries1
- depth 16 -> 24 on Xfbdev?
- meh segfaults with the test.qoi image from the meh branch in qemu, works
  on the host
- slock runs but cannot unlock the screen (shadow issue?), also we need
  a hard-coded nobody and nogroup user and group
- qemu on Arch fails to find a vgabios.bin in the local directory?
  => cp /usr/share/qemu/vgabios-isavga.bin vgabios.bin
- some man pages are in /man, some in /share/man
- non-English pages notion.1 in cs
- we have a non-empty sbin
- building for the first time blocks root.img in losetup, doens't create
  ramdisk.img, etc. races? missing trap in build.sh?
- makewhatis /share/man not called on installation of root.img,
  results in warnings when issuing 'man xxx'
- too big 6x13-ISO8859-1.pcf.gz: 4k on host, 64k in root.img. Most likely we
  package too many charset variants
- "Linux as a Boot Loader - Peter Chubb", kernel assumes to have space after
  it for decompression in address space and overwrites the ramdisk, explains
  our fiddling with loading addresses and random crashes till they no longer
  overlap sessions.
- suckless:
  - sup: not really suckless, sha256 summing and listing, daemonizing should be
    separate binaries in Unix sense
  - sandy: not really stable and maintained, it seems
  - static: minial cgit version with static pages

tools
-----

- util-linux, version 2.17: rdev, for setting the video mode in real mode
  load mode
- bdftopcf 1.1: for converting BDF to PCF

missing things
--------------

We miss some things currently, must see where to get them from somwhere
or whether we add them to existing minimal packages (or temporarily
to abase).

- abase (we already started to add some small tools)
  - more
  - hexdump
- sbase
  - domainname (hostname exists)
- ubase
  - fdisk
  - wall
- ibase (this is a hypothetical thing, internet base tools, we will
  put them into abase for now)
  - ip
  - ping
- obase:
  - chio (BSD I/O), stty
  - csh and ksh (we have oksh)
  - mt (tape management)
  - pax (archives, we have tar)
  - rcp/rsh (old, insecure)
  - systrace (as truss or strace are not really nice to build)
   => could be tricky to build, we don't want bmake too
   The comments say:
   "At least the ALIGN-macro is defined only meaningfully for x86_64."
- 9base
  - ascii
  - awk
  - bc and dc
  - diff
  - mk (instead of samu)
  - yacc
  - troff
- others
  - byacc
  - bison
- minimal languages
  - lua: is already minimal and easy to build, luajit would be nice to
    have for lua 5.1
  - microperl/miniperl
    https://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0003.html
    seems not really be working anymore after perl 5.20
    microperl 5.20 segfaults
  - micropython: https://github.com/micropython/micropython
    Their definition of micro is quite different from mine in terms of
    size and library dependencies)
    I also doubt it works with tcc, needs python3 on the host to build

Some todos to sort out
----------------------

- zlib
  - use libz or zlib-ng
- st/rxvt
  - https://opensource.com/article/19/10/why-use-rxvt-terminal
- tmux/screen
- joe/vis
- vesa/frambuffer
     
other approaches
----------------

linux-486
---------

nice ideas, preinit decompresses lzma compressed files, uses the
chromium Linux syscall wrapper to be a standalone binary (as
the C library is compressed too).

preinit/init.c
preinit/linux_syscall_support.h

no ramdisk, decompresses directly into / (which is the boot root without
an initial change_root?), so is this in RAM?

Uses buildroot for the toolchain.
Boot loader is LILO.
C-library is uclibc.
There are 486-related kernel patches, but it runs without issues on 6.x on
a real machine, so why?

I really like the shell scripts to build the system, they are extremely
simple.

gray486linux
------------

Maybe the final system is nice, but the Nix build system is not..

0001-WIP-patch-kernel-to-skip-endbr32-instruction-on-real.patch
interesting approach to ignore endbr32 without the help of fixing
gcc/binutils (we should check again, why we got it inside busybox,
musl and tinycc don't to this kind of stuff).

Using dropbear could be a good idea.

aboriginal
----------

miniconfig.sh
hush as init shell
highly portable
lots of patches, we must see if those are still relevant
the comments in patches and comments are really funny and helpfull.
also nice autoamitzation, smoke tests using qemu and report generation
Firmware Linux, Rob Landley, "the 7 packages to build whole of LFS on top".
The idea of making just 7 packages cross-compile and compile the rest
inside the emulation. "we cross-compile for you so you don't have to".
'mkroot' is the successor. 'toybox' is the modern variant for minimal
user land.

oasis
-----

by Michael Forney, author of cproc
statically linked, the Lua build thing is weird.
He also rewrote ninja as samurai in C (which is nice).
Also with QBE and cproc the user land can be built with a small C
compiler. QBE is currently lacking IA-32 support, so we can not just
rebuild oasis for our purpose (though we could write a IA-32 QBE
code generator).
The idea of using git for installation feels strange to me.
Also lua scripting for all this software introduces high maintaince costs.

the package list was more or less an inspiration for our list of packages:

musl instead of glibc
sbase instead of coreutils
ubase instead of util-linux
oksh instead of bash
sdhcp instead of dhclient or dhcpcd
vis instead of vim or emacs
netbsd-curses instead of ncurses
mandoc instead of man-db
samurai instead of ninja

those packages we are still considering:

pigz instead of gzip
bearssl instead of openssl
byacc instead of bison
perp and sinit instead of sysvinit or systemd
netsurf instead of chromium or firefox

embutils for our abase version of:

domainname
install

morpheus
--------

statically linked
Plan 9 mk build system
x86_64 and i486 builds
quite old (kernel 3.10.32)
git://git.2f30.org/hbase (Heirloom as alternative base for some Unix tools)
text-based tools like abduco and dvtm for easy text console multiplexing
and window manager, no X
tinyalsa sounds interesting too

how is id prefering tools over other tools?

stali
-----

uses suckless tools
everything statically linked

sabotage
--------

They use an old gcc without a lot of depenendencies (C++, libraries, etc.)
to build the toolchain for stage 0. This is similar to us using tcc.
This is the first distro based on musl which made musl much more suitable
to build a Linux userspace upon. Since alpine linux switched to musl,
sabotage seems to be not heavily developed anymore.

Minimal Linux Live
------------------

No toolchain, so we depend on the hosts toolchain, this breaks when building
too easily. Kernel 5.18 no longer compiles with newer gcc versions.

links
-----

- Other similar distributions or projects
  - Linux-i486
    - https://github.com/tcsullivan/linux-486
  - Aboriginal Linux/Mkroot/miniconfig:
    - https://github.com/landley/aboriginal
    - https://github.com/landley/mkroot
    - https://landley.net/aboriginal/documentation.html
    - http://landley.net/aboriginal/history.html
  - Morpheus
    - https://git.2f30.org/morpheus/
  - Oasis
    - https://git.sr.ht/~mcf/oasis
    - https://github.com/oasislinux/oasis
  - Stali
    - https://sta.li
    - https://pub.nethence.com/xen/guest-stali
  - Graylinux
    - https://github.com/marmolak/gray386linux
    - https://github.com/marmolak/gray486linux
    - https://linuxnews.de/alte-schaetzchen-linux-optimiert-fuer-386-und-486/
  - Sabotage Linux:
    - http://sabo.xyz/
    - https://sabotage-linux.neocities.org/
    - https://sabotage-linux.neocities.org/blog/11/
    - https://github.com/scanlime/avc-edge-linux (disappeared)
  - others minimal linux:
    - https://www.glaucuslinux.org/
    - https://github.com/ZilchOS/bootstrap-from-tcc: this is more for having
      a minimal tcc-based binary core for bootstrapping
    - https://github.com/GataOS/musl-tcc.git: especially interesting to
      have a look at the patches for making musl build with tcc (we sort
      of yoloed the complex and floating point stuff)
    - https://github.com/oriansj
    - https://bellard.org/tcc/tccboot.html
    - https://github.com/michaelforney/
    - https://ella-0.github.io/
    - https://github.com/landley/mkroot
    - https://github.com/richfelker/musl-cross-make.git
    - https://github.com/OSPreservProject/oskit
    - https://github.com/oriansj/M2-Planet.git
    - https://github.com/MiguelVis/mescc.git
    - https://gitlab.com/janneke/mes.git
    - https://www.youtube.com/watch?v=iU0Z0vBKrtQ
      (Michael Matz, tintycc contributor, tccboot revived, tcc hacked did it on kernel 4.6, not published)
    - https://git.mills.io/prologic/ulinux
    - https://www.plop.at/en/ploplinux/downloads/full.html
    - https://git.savannah.nongnu.org/git/stage0.git
    - https://github.com/firasuke/awesome
    - https://github.com/firasuke/mussel (Firas Khalil Khana)
    - https://github.com/pikhq/bootstrap-linux
    - https://www.glendix.org/: Plan9-like distro
    - https://github.com/ivandavidov/minimal: Minimal Linux Live
    - https://github.com/yeokm1/gentoo-on-486
    - https://distr1.org/: Michael Stapelberg, alternative package management for Linux
    - https://kisslinux.org/
    - https://git.sdf.org/midfavila/musl-tcc
  - other minimal floppy system
    - https://github.com/gotoco/PE_Bootloader_x86
    - https://github.com/fysnet/FYSOS/ (smallc, boot loader in C for unreal mode)
    - https://github.com/alexfru/BootProg
    - http://dc0d32.blogspot.com/2010/06/real-mode-in-c-with-gcc-writing.html
    - https://wiki.osdev.org/Disk_access_using_the_BIOS_(INT_13h)
    - https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=08h:_Read_Drive_Parameters
    - https://stanislavs.org/helppc/dbt.html
    - http://vitaly_filatov.tripod.com/ng/asm/asm_024.9.html
    - https://web.archive.org/web/20160619063203/http://www.ctyme.com/intr/rb-0621.htm
    - https://students.mimuw.edu.pl/SO/Linux/Kod/arch/i386/boot/bootsect.S.html
  - other minimal toolchains
    - https://github.com/pts/pts-tcc
- C Compilers
  - https://repo.or.cz/w/tinycc.git
  - https://blog.stephencleary.com/2010/10/implementing-gccs-builtin-functions.html: on __builtin_clz
- C Libraries
  - https://www.fefe.de/dietlibc
    (https://www.monperrus.net/martin/compiling-tcc-with-dietlibc: sadly
    has issues and was never designed to use tcc in the first place)
- tinycc and musl
  - https://wiki.musl-libc.org/design-concepts.html
  - https://www.mail-archive.com/tinycc-devel@nongnu.org/msg08533.html
  - https://lists.gnu.org/archive/html/tinycc-devel/2015-01/msg00135.html
  - https://www.mail-archive.com/tinycc-devel@nongnu.org/msg10201.html
  - https://www.mail-archive.com/tinycc-devel@nongnu.org/msg10196.html
- Terminal stuff
  - https://github.com/sabotage-linux/netbsd-curses/
  - https://www.leonerd.org.uk/code/libtermkey/
  - http://git.musl-libc.org/cgit/uuterm/tree/README
- Editors
  - https://github.com/martanne/vis
  - https://joe-editor.sourceforge.io/
  - https://ex-vi.sourceforge.net/
  - https://git.sdf.org/midfavila/mse
- Kernel
  - Tinification
    - https://weeraman.com/building-a-tiny-linux-kernel-8c07579ae79d
    - https://tiny.wiki.kernel.org/
    - http://events17.linuxfoundation.org/sites/events/files/slides/tiny.pdf
    - https://z49x2vmq.github.io/2020/12/24/linux-tiny-qemu/
    - http://elinux.org/Kernel_Size_Reduction_Work
    - https://stackoverflow.com/questions/27941775/what-is-the-minimum-amount-of-ram-required-to-run-linux-kernel-on-an-embedded-de    
- Boot process
  - ramdisks
    - https://linuxlink.timesys.com/docs/startup_overview
    - https://people.freedesktop.org/~narmstrong/meson_drm_doc/admin-guide/initrd.html
    - https://firasuke.github.io/DOTSLASHLINUX/post/booting-the-linux-kernel-without-an-initrd-initramfs/
    - https://docs.kernel.org/admin-guide/initrd.html
    - https://landley.net/writing/rootfs-programming.html
    - https://github.com/chris-se/tiny-initramfs
  - device management
    - https://git.suckless.org/smdev
  - init systems
    - git://git.suckless.org/sinit
    - https://github.com/bbenne10/rc
    - https://github.com/hut/minirc
    - https://omaera.org/wlog/tech/runit_init
    - https://forums.gentoo.org/viewtopic-t-1000292-start-0.html
    - https://busybox.busybox.narkive.com/PBeyeZOM/custom-initrd-using
    - https://github.com/shiftypenguin/uinit
  - service/daemon management
    - http://r-36.net/scm/svc/log.html
- minimal userland
  - shells
     - POSIX compliant
      - https://github.com/ibara/oksh: good compromise of good and small
        code base and functionality
      - https://yash.osdn.jp/index.html.en
      - dash: something bothered be there in the build process (TODO: what?)
    - minimalistic to the extreme:
      - https://github.com/hacheigriega/sshell.git: very minimal, more an
        education project
      - the 'S' shell
  - suckless
    - git://git.suckless.org/sbase
    - git://git.suckless.org/ubase
  - https://git.andreasbaumann.cc/cgit/abase/
  - other minimal user lands (we don't use for now)
    - https://busybox.net/
    - https://landley.net/toybox/
    - https://tools.suckless.org/9base/
    - https://github.com/leahneukirchen/obase
    - https://beastiebox.sourceforge.net/
    - https://www.fefe.de/embutils/
    - https://heirloom.sourceforge.net/
  - gopher://bitreich.org
  - https://git.2f30.org/hbase/log.html: Heirlom
  - https://www.glendix.org/: we could also go into the direction of using
    plan 9 things (as they tend to be more minimalistic):
    - git://git.9front.org/plan9front/plan9front
    - git://git.suckless.org/9base
  - https://github.com/ecki/net-tools.git
  - https://www.reddit.com/r/suckless/comments/n14xnq/can_sbase_replace_busybox/
  - https://exactcode.com/opensource/minised/ (Eroc S. Raymond, maintained by Rene Rebe)
  - https://stackoverflow.com/questions/4327942/non-buffering-stdin-reading
- minimalism
  - https://wiki.installgentoo.com/wiki/Software_minimalism
  - https://suckless.org/philosophy
  - https://github.com/173duprot/harm-less
- Link collections of interesting software
  - https://suckless.org/rocks/
  - https://suckless.org/other_projects/
  - https://github.com/firasuke/awesome
  - https://wiki.musl-libc.org/alternatives.html
  - http://bashismal.blogspot.com/2011/10/unbloated-resources-in-c.html
- cruching binaries
  - https://github.com/ryao/crunch
  - http://www.bsdnewsletter.com/2003/09/Features102.html
- TTY stuff
  - controlling terminals: /dev/console on serial and tty0 has no tty!
  - https://debianforum.de/forum/viewtopic.php?t=169622&start=15
  - https://www.linuxquestions.org/questions/linux-from-scratch-13/%5Bsolved%5D-failing-to-open-dev-tty-4175685290/
  - https://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty
- historical stuff
  - https://www.elinux.org/Busybox_replacement_project
- qemu
  - https://en.wikibooks.org/wiki/QEMU/Devices/Network
  - https://virtuallyfun.com/2020/07/31/using-qemu-in-2020/
- nbd
  - https://patchwork.kernel.org/project/linux-block/patch_20190612163144.18486-2/roman.stratiienko@globallogic.com/
  - http://patraulea.com/nbd-http/
  - https://github.com/NetworkBlockDevice/nbd/
  - https://patchwork.kernel.org/project/linux-block/patch/20190612163144.18486-2-roman.stratiienko@globallogic.com/
- debugging
  - https://www.kernel.org/doc/html/v4.15/dev-tools/kgdb.html
  - https://ja.nsommer.dk/articles/linux-and-tiny-c-compiler-in-the-browser-part-one.html
- X
  - tiny X
    - https://github.com/idunham/tinyxserver and
      https://github.com/idunham/tinyxlib (puppy linux): has nice simple
      makefiles
    - https://github.com/tinycorelinux/tinyx, is newer, but requires autoconf
      to build
    - alternatives:
      - https://github.com/michaelforney/velox, https://github.com/michaelforney/swc: but
        this is wayland
      - http://www.microwindows.org/
      - KDrive (Tiny X, TinyX): Keith Packard
      - https://www.pps.jussieu.fr/~jch/software/kdrive.html
      - https://github.com/Earnestly/sx: alternative xinit/startx
      - http://www.microwindows.org/
    - http://forum.tinycorelinux.net/index.php?topic=16299.0: fork of tinyx for tinycorelinux
  - X terminal
    - xterm: bloat
    - st, requires Xft, requiring fontconfig, freetype2, etc. can eventually
      be redone to use old font library?
    - rxvt: simple and uses normal bitmap fonts (old font library)
  - X fonts
    - https://www.x.org/archive/X11R6.8.0/doc/fonts2.html
    - https://www.x.org/archive/X11R7.5/doc/man/man1/mkfontdir.1.html
    - https://www.x.org/archive//individual/font
  - X apps and stuff
    - https://www.x.org/archive/individual/app/
- terminal multiplexing
  - tmux: newer
  - screen: looks a little bit aged, might habe more features but also more code
- window manager
  - dwm/dmenu or notion3
  - notion3/notion: uses lua, loadable modules, etc. has xinerama/xrandr support,
    this is all a little bit too much
  - ion1: more suckless, maybe patchable to do what we want
    https://github.com/apenwarr/ion1
- debugging
  - automatic serial without getty
    - https://github.com/Angstrom-distribution/meta-linaro/blob/master/recipes-core/auto-serial-console/auto-serial-console/auto-getty
- suspend/hibernate
  - https://docs.kernel.org/power/s2ram.html
- philosophical stuff
  - 1983 Rob Pike made a presentation titled ‘UNIX Style, or cat -v Considered Harmful’ 
  - http://harmful.cat-v.org/cat-v/
- hardware-specific stuff
  - Unisys CWD-4002
    - http://www.dosdays.co.uk/topics/Manufacturers/cirrus_logic.php: graphic chip
- graphic programming
  - https://www.svgalib.org/
  - https://benpfaff.org/projects.html: BOGL graphics library for framebuffers

performance
-----------

Building i486tcc-linux

5 minutes userland including cross-toolchain
15 minutes kernel
1 minute ramdisk/floppy creation

framebuffer
-----------

insmod /lib/modules/drivers/video/fbdev/core/cfbcopyarea.ko
insmod /lib/modules/drivers/video/fbdev/core/cfbfillrect.ko
insmod /lib/modules/drivers/video/fbdev/core/cfbimgblt.ko
insmod /lib/modules/arch/x86/video/fbdev.ko
insmod /lib/modules/lib/fonts/font.ko
insmod /lib/modules/drivers/video/fbdev/core/fb.ko
insmod /lib/modules/drivers/video/fbdev/cirrusfb.ko

insmod /lib/modules/drivers/video/vgastate.ko
insmod /lib/modules/lib/fonts/font.ko
insmod /lib/modules/drivers/video/fbdev/vga16fb.ko

mknod /dev/fb0 c 29 0
cat /sys/class/graphics/fb0/name 

Unsorted links
--------------

- framebuffer
  - https://higfxback.github.io/
  - https://github.com/rothgar/awesome-tuis
  - https://dev1galaxy.org/viewtopic.php?id=5400
  - https://directfb2.github.io/
  - https://github.com/directfb2/DirectFB2
  - https://github.com/8l/fbui
  - https://manpages.ubuntu.com/manpages/xenial/man1/fbi.1.html
  - https://kevinboone.me/linuxfbc.html?i=1
  - https://benpfaff.org/projects.html: vga16fb
- fonts
  - https://github.com/ntwk/vga-font

Real hardware
-------------

Unisys CDW-4002
---------------

cd lib/modules/drivers/net/ethernet/8390
insmod 8390p.ko
insmod ne.ko io=0x300 irq=10
ifconfig eth0 up
sdhcp