-
-
Notifications
You must be signed in to change notification settings - Fork 638
/
ape.S
1847 lines (1752 loc) · 77.1 KB
/
ape.S
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
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 nofixeol :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice & this permission notice appear in all copies │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL │
│ THE AUTHOR BE LIABLE FOR ANY SPECIAL DIRECT INDIRECT, OR EVEN │
│ CONSEQUENTIAL DAMAGE OR ANY DAMAGES WHATSOEVER RESULTING FROM │
│ LOSS OF USE, DATA OR PROFITS WHETHER IN AN ACTION OF CONTRACT │
│ NEGLIGENCE OR OTHER TORTIOUS ACTION, THAT ARISE OUT OF, OR IN │
│ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. │
╠──────────────────────────────────────────────────────────────────────────────╣
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░█▀█░█▀█░▀█▀░█░█░█▀█░█░░░█░░░█░█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░█▀█░█░▄░░█░░█░█░█▀█░█░░░█░░░▀█▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░▀░▀░▀▀▀░░▀░░▀▀▀░▀░▀░▀▀▀░▀▀▀░░▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░█▀█░█▀█░█▀█░▀█▀░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░█▀▀░█ █░██▀░░█░░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░▀░░░▀▀▀░▀░▀░░▀░░▀░▀░▀▀▀░▀▀▀░▀▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
│░░░░░░░█▀▀░█░█░█▀▀░█▀█░█░█░▀█▀░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░▄▄░░░▐█░░│
│░░░░░░░█▀▀░▄▀▄░█▀▀░█░▄░█░█░░█░░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░▄▄▄░░░▄██▄░░█▀░░░█░▄░│
│░░░░░░░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░░▀░░▀░▀░▀▀▀░▀▀░▀▀▀░░░░░░░░░░▄██▀█▌░██▄▄░░▐█▀▄░▐█▀░░│
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▐█▀▀▌░░░▄▀▌░▌░█░▌░░▌░▌░░│
╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│
│ αcτµαlly pδrταblε εxεcµταblε § program header │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "ape/macros.internal.h"
#include "ape/relocations.h"
#include "libc/calls/metalfile.internal.h"
#include "libc/dce.h"
#include "libc/elf/def.h"
#include "libc/macho.h"
#include "libc/nexgen32e/uart.internal.h"
#include "libc/nt/pedef.internal.h"
#include "libc/runtime/pc.internal.h"
#include "ape/ape.internal.h"
#include "libc/thread/tls.h"
#include "ape/ape.h"
#include "libc/sysv/consts/prot.h"
#define USE_SYMBOL_HACK 1
.section .text,"ax",@progbits
.balign __SIZEOF_POINTER__
.previous
.section .rodata,"a",@progbits
.balign __SIZEOF_POINTER__
__ro: .endobj __ro,globl,hidden // ←for gdb readability
.previous
.section .data,"aw",@progbits
.balign __SIZEOF_POINTER__
.previous
.section .bss,"aw",@nobits
.balign __SIZEOF_POINTER__
.previous
.section .rodata.str1.1,"a",@progbits
cstr: .endobj cstr,globl,hidden // ←for gdb readability
.previous
.section .head,"ax",@progbits
/* ████████ ████████ ███████████
██░░░░▒▒██ ██░░░░▒▒██ ████░░░░░░░░░▒▒████
██░░░░░░██ ██░░░░▒▒██ ██░░░░▒▒███████░░░░▒▒██
██░░░░░░▒▒██ ░██░░░░░░▒▒██ ██░░▒▒██ ██░░▒▒██
██░░▒▒░░░░██ ░██░░░░░░▒▒██ ██░░▒▒██ ████████
██░░▒▒▒▒░░▒▒██ ██▓░░░░▒▒░░▒▒██ ██░░▒▒▒▒███████
██░░▒▒██░░░░██ ██▓░░░░██░░▒▒██ ████░░░░░░░▒▒████
██░░▒▒████░░▒▒██░░░░░████░░▒▒██ ███████░░░░▒▒██
██░░▒▒████░░░░██░░░░░████░░▒▒██ ██████ ██░░░░▒▒██
██░░▒▒██ ██░░▒▒░░▒██ ██░░▒▒██ ██░░░░██ ██░░▒▒██
██░░▒▒██ ██░░░░░░▒██ ██░░▒▒██ ██░░░░█████████░░░░▒▒██
██░░▒▒██ ▓▓▒▒░░▒▒▒▓▓ ██░░▒▒██ ▓▓▒▒░░▓▓▓▓▓▓▓▓▓░░░░▓▓▓▓
██░░▒▒██ ██░░██▓ ██░░▒▒██ ██░░░░░░░░░░░░░▒▒██
████████████████████▓ ██████████████ ███████████████
██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓░░▓▓░░▓▓░░████░░░░░░░░░░░░░░░████
██▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓░░▓▓░░▓▓░░████░░░░░░░░░░░░░░░░░░░░░██
██▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓▒░░▓▓░░▓▓░░▓▓██░░░░░░░░░░░░░░░░░░░░░░░░░██
██▓▓▓▓▓▓██████████░░▒▓▓▓▓██████▓▓██░░░░░░███████████▓▓░░░░▓▓██
██▓▓▓▓▓▓████████░░▓▓▓▓▓██▓▓▓▓██████░░░░████░░▒▓▓██ ██▓▓▓▓▓▓██
██▓▓▓▓▓▓████████▓▓░░▒████▓▓▓▓██████░░░░██▓▓▓▓▒░░██ ██████
██▓▓▓▓▓▓██ ██░░▓▓▓▓▓██▓▓▓▓██ ██▓▓░░████░░▒▓▓██████
██▓▓▓▓▓▓██ ██▓▓░░▒████▓▓▓▓██ ██▓▓██▓▓▓▓▒░░██░░░░████
██▓▓▓▓▓▓██ ██░░▓▓▓▓▓██▓▓▓▓██ ██████░░▒▓▓██░░░░░░░░██
██▓▓▓▓▓▓██ ██▓▓░░▒████▓▓▓▓██ ██▓▓▓▓▒░░██▓▓░░░░░░░░██
██▓▓▓▓▓▓██ ██░░▓▓▓████▓▓▓▓██ ████████░░▒▓▓████▓▓░░░░░░██
██▓▓▓▓▓▓██ ██░░▒██▓▓▓▓████ ██░░░░░░██▓▓███ ██░░░░░░██
██▓▓▓▓▓▓█████████████▓▓▓▓██████████▓▓░░░░░░█████████░░░░░░░░██
██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓░░██▓▓░░░░░░░░░░░░░░░░░░░░░▓▓██
██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓░░▓▓██▓▓▓▓░░░░░░░░░░░░░░░░░▓▓▓▓██
██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓░░▓▓░░▓▓██▓▓▓▓▓▓░░░░░░░░░░░▓▓▓▓▓▓██
██▓▓█████████████████████▓▓██▓▓██▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██
███████████████████████████▓▓██▓▓██▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓████
██████████████████▓ ██████████████ █████████████
╔──────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § the old technology │
╚─────────────────────────────────────────────────────────────────────────────*/
#if SupportsWindows() || SupportsMetal() || SupportsXnu()
// MZ Literally Executable Header
//
// This is the beginning of the program file and it can serve as an
// entrypoint too. It shouldn't matter if the program is running on
// Linux, Windows, etc. Please note if the underlying machine isn't
// a machine, this header may need to morph itself to say the magic
// words, e.g. ⌂ELF, which also works fine as a generic entrypoint.
//
// @param dl is drive number
// @noreturn
ape_mz:
#if SupportsWindows() || SupportsMetal()
.asciz "MZqFpD='\n" // Mark 'Zibo' Joseph Zbikowski
// # in real mode
// dec %bp
// pop %dx
// jno 0x4a
// jo 0x4a
//
// # in legacy mode
// push %ebp
// pop %edx
// jno 0x4a
// jo 0x4a
//
// # 64-bit mode
// rex.WRB
// pop %r10
// jno 0x4a
// jo 0x4a
#else
// Avoid virus scanner reputation damage when targeting System Five.
.asciz "jartsr='\n" // Justine Alexandra Roberts Tunney
// push $0x61
// jb 0x78
// jae 0x78
#endif
.short 0x1000 // MZ: lowers upper bound load / 16
.short 0xf800 // MZ: roll greed on bss
.short 0 // MZ: lower bound on stack segment
.short 0 // MZ: initialize stack pointer
.short 0 // MZ: ∑bₙ checksum don't bother
.short 0x0100 // MZ: initial ip value
.short 0x0800 // MZ: increases cs load lower bound
.short 0x0040 // MZ: reloc table offset
.short 0 // MZ: overlay number
.org 0x24 // MZ: bytes reserved for you
.ascii "JT" // MZ: OEM identifier
.short 0 // MZ: OEM information
.ascii "' <<'@'\n"
.org 0x40-4 // MZ: bytes reserved for you
#if SupportsWindows() || SupportsMetal()
.long RVA(ape_pe) // PE: the new technology
#else
.long 0
.org 0x78
pop %rax
jmp _start
#endif
.endfn ape_mz,globl,hidden
#else /* !(SupportsWindows() || SupportsMetal() || SupportsXnu()) */
// ELF Literally Executable Header
//
// If we don't need to support Microsoft or Apple then we can
// produce a conventional executable without the shell script
//
// @param dl is drive number
// @noreturn
.ascii "\177ELF" // 0x0: ⌂ELF
.byte ELFCLASS64 // 4: long mode
.byte ELFDATA2LSB // 5: little endian
.byte 1 // 6: elf v1.o
.byte ELFOSABI_FREEBSD // 7: FreeBSD
.byte 0 // 8: os/abi ver.
.balign 8,0 // 9: padding
.short ET_EXEC // 10: εxεcµταblε
#ifdef __x86_64__
.short EM_NEXGEN32E // 12: amd
#elif __aarch64__
.short EM_AARCH64 // 12: arm
#elif __powerpc64__
.short EM_PPC64 // 12: open power
#elif __riscv
.short EM_RISCV // 12: risc five
#endif
.long 1 // 14: elf v1.o
.quad ape_elf_entry // 18: e_entry
.quad ape_elf_phoff // 20: e_phoff
.quad ape_elf_shoff // 28: e_shoff
.long 0x101ca75 // 30: ape e_flags
.short 64 // 34: e_ehsize
.short 56 // 36: e_phentsize
.short ape_elf_phnum // 38: e_phnum
.short 0 // 3a: e_shentsize
.short ape_elf_shnum // 3c: e_shnum
.short ape_elf_shstrndx // 3e: e_shstrndx
#endif /* SupportsWindows() || SupportsMetal() || SupportsXnu() */
#if SupportsMetal()
// Disk Operating System Stub
//
// @param dl is drive number
// @noreturn
.org 0x40 // mz/elf header length
stub: mov $0x40,%dl // *literally* dos
jmp 1f // good bios skips here
1: jmp pc // thus avoiding heroics
nop // system five bootpoint
.org 0x48,0x90 // note ⌂ELF means JG 47
jmp 3f // MZ also means pop r10
2: sub $8,%rsp // a.k.a. dec %ax sub %sp
xor %edx,%edx // MZ ate BIOS drive code
3: .byte 0xbd,0,0 // a.k.a. mov imm,%bp
jmp pc // real mode, is real
jmp _start // surprise it's unix
.endfn stub,globl
/*─────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § ibm personal computer │
╚──────────────────────────────────────────────────────────────────────────────┘
IBM designed BIOS to run programs by handing over the computer
to a program as soon as its first sector is loaded. That gives
us control over user-facing latency, even though the next step
will generally be asking the BIOS to load more.
The process is trivial enough that this entrypoint can support
handoffs from alternative program-loaders e.g. Grub and MS-DOS
so long as they either load our full program, or implement the
PC BIOS disk service API.
Since so many different implementations of these APIs have been
built the last forty years these routines also canonicalize the
cpu and program state, as it is written in the System V ABI. */
// Initializes program and jumps to real mode loader.
//
// @param dl drive number (use 0x40 to skip bios disk load)
// @mode real
// @noreturn
pc: cld
.code16
#if USE_SYMBOL_HACK
.byte 0x0f,0x1f,0207 // nop rdi binbase
.short (0x7c00-IMAGE_BASE_VIRTUAL)/512
#endif
mov $0x70000>>4,%di // we need a stack
xor %cx,%cx // 0x7f000-0x80000
mov %cx,%es
rlstack %di,%cx
push %cs // determine load address
pop %ds // and relocate this code
call 1f // to a way lower address
1: pop %si // and we'll make cs zero
sub $RVA(1b),%si
mov $IMAGE_BASE_REAL>>4,%ax
push %ax // save IMAGE_BASE_REAL>>4
push %ax
pop %es
xor %di,%di
mov $512,%cx
rep movsb
#if USE_SYMBOL_HACK
.byte 0x0f,0x1f,0207 // nop rdi binbase
.short (IMAGE_BASE_REAL-0x7c00)/512
#endif
ljmp $0,$REAL(1f)
1: mov %cx,%ds
.set mm,0x0500 // struct mman
mov $IMAGE_BASE_REAL-mm,%cx // clears bss
mov $mm>>4,%ax
mov %ax,%es
xor %ax,%ax
xor %di,%di
rep stosb
cmp $0x40,%dl
je 6f
call dsknfo
pop %es // restore IMAGE_BASE_REAL>>4
mov $1,%al // current sector
xor %cx,%cx // current cylinder
xor %dh,%dh // current head
mov $v_ape_realsectors,%di // total sectors
3: call pcread
mov %es,%si // addr += 512
add $512>>4,%si
mov %si,%es
dec %di
jnz 3b
6: ljmp $0,$REAL(realmodeloader)
.endfn pc
// Determines disk geometry.
//
// We use imperial measurements for storage systems so the software
// can have an understanding of physical locality, which deeply
// impacts the latency of operations.
//
// - 160KB: 40 cylinders × 1 head × 8 sectors × 512 = 163,840
// - 180KB: 40 cylinders × 1 head × 9 sectors × 512 = 184,320
// - 320KB: 40 cylinders × 2 heads × 8 sectors × 512 = 327,680
// - 360KB: 40 cylinders × 2 heads × 9 sectors × 512 = 368,640
// - 720KB: 80 cylinders × 2 heads × 9 sectors × 512 = 737,280
// - 1.2MB: 80 cylinders × 2 heads × 15 sectors × 512 = 1,228,800
// - 1.44MB: 80 cylinders × 2 heads × 18 sectors × 512 = 1,474,560
//
// Terminology
//
// - Heads are also known as Tracks
//
// Disk Base Table
//
// 0: specify byte 1, step-rate time, head unload time
// 1: specify byte 2, head load time, DMA mode
// 2: timer ticks to wait before disk motor shutoff
// 3: bytes per sector code
// 0: 128 bytes 2: 512 bytes
// 1: 256 bytes 3: 1024 bytes
// 4: sectors per track (last sector number)
// 5: inter-block gap length/gap between sectors
// 6: data length, if sector length not specified
// 7: gap length between sectors for format
// 8: fill byte for formatted sectors
// 9: head settle time in milliseconds
// 10: motor startup time in eighths of a second
//
// @param dl drive number
// @return dl = pc_drive (corrected if clobbered by header)
// pc_drive
// pc_drive_type
// pc_drive_heads
// pc_drive_last_cylinder
// pc_drive_last_sector
// @clob ax, cx, dx, di, si, es, flags
// @since IBM Personal Computer XT
dsknfo: push %bx
1: push %dx
mov $0x16,%ah // make sure there is disk in drive,
int $0x13 // by querying change-line status
jnc 2f
xor %ax,%ax // if error or change line active,
int $0x13 // do a reset...
jc 9f
mov $0x0201,%ax // ...then do a read, to confirm that
mov $0x0001,%cx // there is disk in drive
mov $0,%dh // (verify (%ah = 4) does not work
mov $IMAGE_BASE_REAL>>4,%bx // under QEMU, which always returns
mov %bx,%es // success)
xor %bx,%bx
int $0x13
jc 9f
2: mov $0x08,%ah // get disk params
int $0x13
jc 9f
mov %cl,%bh
and $0b00111111,%bh
and $0b11000000,%cl
rol %cl
rol %cl
xchg %cl,%ch
push %ds // disk base table in es:di
movpp %es,%ds
xor %si,%si
mov %si,%es
mov $mm+"struct mman::pc_drive_base_table",%si
xchg %si,%di
movsw //→ headunloadtime, headloadtime
movsw //→ shutofftime, bytespersector
movsw //→ sectorspertrack, sectorgap
movsw //→ datalength, formatgap
movsw //→ formatfill, settletime
movsb //→ startuptime
pop %ds
xchg %bx,%ax
stosw //→ pc_drive_type, pc_drive_last_sector
scasb
xchg %cx,%ax
stosw //→ pc_drive_last_cylinder
xchg %dx,%ax
stosw //→ pc_drives_attached, pc_drive_last_head
pop %ax
stosb //→ pc_drive
xchg %ax,%dx
pop %bx
ret
9: pop %dx
8: xor $0x80,%dl // try cycling drive a/c
xor %ax,%ax // reset disk
int $0x13
jc 8b
jmp 1b
.endfn dsknfo
// Reads disk sector via BIOS.
//
// @param al sector number
// @param es destination memory address >> 4
// @param cx cylinder number
// @param dh head number
// @param dl drive number
// @return number of sectors actually read
pcread: push %ax
push %cx
xchg %cl,%ch
ror %cl
ror %cl
or %al,%cl
xor %bx,%bx // es:bx is destination addr
mov $1,%al // read only one disk sector
mov $2,%ah // read disk sectors ordinal
int $0x13
pop %cx
pop %ax
jc 9f
inc %al // ++sector
cmp mm+"struct mman::pc_drive_last_sector",%al
jbe 2f
mov $1,%al
inc %dh // ++head
cmp mm+"struct mman::pc_drive_last_head",%dh
jbe 2f
xor %dh,%dh
inc %cx // ++cylinder
2: ret
9: push %ax
xor %ax,%ax // try disk reset on error
int $0x13
pop %ax
jmp pcread
.endfn pcread
// Video put string.
//
// @param di is the string
// @clob bp,bx
// @mode real
rvputs: mov %di,%si
0: lodsb
test %al,%al
je 1f
mov $7,%bx // normal mda/cga style page zero
mov $0x0e,%ah // teletype output al cp437
int $0x10 // vidya service
jmp 0b
1: ret
.endfn rvputs
// Abnormally halts startup.
//
// @param di message
// @mode real
// @noreturn
rldie: push %di
mov $REAL(str.error),%di
call rvputs
pop %di
call rvputs
mov $REAL(str.crlf),%di
call rvputs
0: rep nop
jmp 0b
.endfn rldie
// Initializes present PC serial lines.
sinit4: mov $4,%cx
mov $0x400,%si // BDA.COM1
0: lodsw
test %ax,%ax
jz 1f
push %cx
push %si
xchg %ax,%di
mov $REAL(sconf),%si
call sinit
pop %si
pop %cx
1: loop 0b
ret
.endfn sinit4,global,hidden
// Initializes Serial Line Communications 8250 UART 16550A
//
// @param word di tty port
// @param char (*{es:,e,r}si)[4] register initial values
// @mode long,legacy,real
// @see www.lammertbies.nl/comm/info/serial-uart.html
sinit: mov %di,%dx
test %dx,%dx
jz 2f
push %dx
push %si
xor %cx,%cx
mov $UART_LCR,%cl
add %cx,%dx
lodsb %ds:(%si),%al
pop %si
or $UART_DLAB,%al
out %al,%dx
pop %dx
1: lodsb %ds:(%si),%al
out %al,%dx
inc %dx
dec %cx
jns 1b
2: ret
.endfn sinit,global,hidden
/*───────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § partition table ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
// Partition Table.
ape.mbrpad:
.org 0x1b4
.endobj ape.mbrpad
ape_disk:
.stub ape.diskid,quad
.org 0x1be,0x00
.macro .partn x:req sta h0 s0 c0 fs h9 s9 c9 lba0 nsec
.stub ape.part\x\().status,byte,\sta // 0=non-boot / 0x80=active
.stub ape.part\x\().first.head,byte,\h0
.stub ape.part\x\().first.sector,byte,\s0 # in low 6 bits
.stub ape.part\x\().first.cylinder,byte,\c0
.stub ape.part\x\().filesystem,byte,\fs
.stub ape.part\x\().last.head,byte,\h9
.stub ape.part\x\().last.sector,byte,\s9
.stub ape.part\x\().last.cylinder,byte,\c9
.stub ape.part\x\().lba,long,\lba0 // c₀*Cₙ + h₀*Hₙ + s₀*Sₙ
.stub ape.part\x\().sector.count,long,\nsec # sectors are 512 bytes
.endm
.partn 1,0x80,0,1,0,0x7f,0xff,0xff,0xff,0,0xffffffff
.partn 2
.partn 3
.partn 4
.org 0x1fe
.short BOOTSIG
.endobj ape_disk
#endif /* SupportsMetal() */
/* ▄▄▄
▄▄▄ ▀▓▓▒▄
▄▓▒▒░ ▀▓▒▒▒▄
▄▓▓▓▒▀ ▄▄▄▄ ▒▓▒▒░▒▄
▄▓▓▓▒▓ ▄▄▓██▓▓▓▓▒▒▒▒▓▓▄▄▓▓▒▒▒░░▒
▓▓▓▓▒▒▒▄▄ ░▒█▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓▒░░▒░
██▓▓▓▒▒░░▒▒▒▒▓▓▓▓▓▓▒▓▒░▒▒░▀▒▒▒▒░▀░▒▒▒░▒
▓▓▓▓▓▓▓▒▒▒▒▒▒▓▓▒▓▓▒▒▒░▒▒░░ ░▒▒░ ░▒▒▒▒
▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░▒░░ ░▒▒ ░ ▀▒▒
▀▓▓█▓▓▓▓▓▓▓▓▓▓▒▒░░▒▒░░ ░░░▓░ ▓░░░▒
▀▀█▓███▓▓▓▓▓▒▒░░░▒░░ ░█▓░█▓░█▓▓▄▒░
░▓██▓▓▓▓▓▒▒░░░▒░░ ░████▓▒▓█▓▀░▀▄
░▓██▓▓▓▓▓▒▒▒░░░▒░░ ▒██▓▒▒▒▒▒▒░░░▒
████▓▓▓▓▓▒▒▒▒▒▒▒▒▒░░▒▓▓▒░░░░▒░░░▒░ ░░░░░
░▓███▓▓▓▓▓▒▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒░░░ ░░░░░ ░
▓███▓▓▓▓▓▒▓▒▒▒▒░░░░░░░░░▒▓▒▒░▀ ░░░ ░░░░░
▀▒██▓▓▓▓▒▒▒▓▓▓▓▒▒▒▒▒▒▒▓▀▀░ ░░░░░░░░░ ░
▓▓▓▓▓▓▓▒▓▒▒▒▒▓▓▓▒▀░ ░░░░░▄░░░ ░░░ ░░░░░░
▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓ █▓▒░░▒░░░░ ░░░░░░░░
▄▓▓▓▒▒▒▒▒░░░░░░░▒▄▄▄░▒▓▓▒▒░▀░
░▓█▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒░░░▒ besiyata
▓▓█▓▓▒▓▓▓▒▒▒░░░░░░▒▓▓▓▓▒▒▒▒▒░ dishmaya
▓▓█▓▓▓▓▓▓▒▒▒░░░░░░░▒▓▓▒▀▀▀
▓▓██▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▀
█▓▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀
▒▓▓▓▓▀░░▒▓▓▓▓▓▓▓▓▒▒░░▒
▄▓▓▀░░░▄▓▓▓▓▒▒▒▒▒░░░░▄░
▄███▄▄▓▓▓▓▓▓▓▒▒▒▒▒░░▒▒░
▄▓▓▓█▓█▓▓███▓▓▓▓▓▓▓▓▓▓▓░
▄░▓▓▓▓▓▓▀▒▓▓▓▒▒▓▒░░░▒▓▒░░░▓
▄▄▄░▒▓▓▓▓▓▓░▀▀ ▓▓▒░▓▒▒▒▒▒▒▒▒▒▒▄░░▀▀░░ ▄▄▄▄
▄▄▄▒▒▓▓█▓▓▓▓▓▀▀▀▀▀ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▀░░▀░░▒▒▒░░░ ░░░░░
▄▓▓▓▒▀▀ ▓▒▓▓▓▓▓▒▒▒▒▒▒▒▒▓░░░ ▒▒▒░░░░░░░░▒
█▓▓▒ ▄▄▄ ▀▓▒▓▒▒▒▓▓▓▓▓▓▒▒▒░░░░░░░░░▒▒░░░░░░░
▀▓▓▓▓▒▄▄▒▒▒▒▒▒▄▄ ▀▀▀▀░░▒▒▒▒░░░░░░
▀▀▀▓▓▓▓▒▒▒▒▒▓▓▄▄
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § bell system five ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
the bourne executable & linkable format */
#ifdef APE_IS_SHELL_SCRIPT
apesh: .ascii "\n@\n#'\"\n" // sixth edition shebang
.ascii "m=$(uname -m 2>/dev/null) || m=x86_64\n"
.ascii "if [ \"$m\" = x86_64 ] || [ \"$m\" = amd64 ]; then\n"
// Until all operating systems can be updated to support APE,
// we have a beautiful, yet imperfect workaround, which is to
// modify the binary to follow the local system's convention.
// There isn't a one-size-fits-all approach for this, thus we
// present two choices.
.ascii "o=\"$(command -v \"$0\")\"\n"
// Try to use system-wide APE loader.
.ascii "[ x\"$1\" != x--assimilate ] && "
.ascii "type ape >/dev/null 2>&1 && "
.ascii "exec ape \"$o\" \"$@\"\n"
#ifdef APE_LOADER
// There is no system-wide APE loader, but there is one
// embedded inside the APE. So if the system is not MacOs,
// extract the loader into a temp folder, and use it to
// load the APE without modifying it.
.ascii "[ x\"$1\" != x--assimilate ] && {\n"
.ascii "t=\"${TMPDIR:-${HOME:-.}}/.ape-"
.ascii APE_VERSION_STR
.ascii "\"\n"
.ascii "[ -x \"$t\" ] || {\n"
.ascii "mkdir -p \"${t%/*}\" &&\n"
.ascii "dd if=\"$o\" of=\"$t.$$\" skip="
.shstub ape_loader_dd_skip,2
.ascii " count="
.shstub ape_loader_dd_count,2
.ascii " bs=64 2>/dev/null\n"
#if SupportsXnu()
.ascii "[ -d /Applications ] && "
.ascii "dd if=\"$t.$$\""
.ascii " of=\"$t.$$\""
.ascii " skip=5"
.ascii " count=8"
.ascii " bs=64"
.ascii " conv=notrunc"
.ascii " 2>/dev/null\n"
#endif /* SupportsXnu() */
.ascii "chmod 755 \"$t.$$\"\n"
.ascii "mv -f \"$t.$$\" \"$t\"\n"
.ascii "}\n"
.ascii "exec \"$t\" \"$o\" \"$@\"\n"
.ascii "}\n"
#endif /* APE_LOADER */
#ifndef APE_NO_MODIFY_SELF
// The default behavior is: to overwrite the header in place.
// We prefer this because it's a tiny constant one time cost.
// We simply printf a 64-byte header and call execve() again.
#else
// The alternative behavior is to copy to $TMPDIR or $HOME or
// the current directory. We like TMPDIR because it's part of
// the IEEE POSIX standard whereas alternatives (XDG) aren't.
.ascii "t=\"${TMPDIR:-${HOME:-.}}/$0\"\n"
.ascii "[ x\"$1\" != x--assimilate ] || [ ! -e \"$t\" ] && {\n"
.ascii "[ x\"$1\" != x--assimilate ] && {\n"
.ascii "mkdir -p \"${t%/*}\" 2>/dev/null\n"
.ascii "cp -f \"$o\" \"$t.$$\" &&\n"
.ascii "mv -f \"$t.$$\" \"$t\" || exit 120\n"
.ascii "o=\"$t\"\n"
.ascii "}\n"
#endif /* APE_NO_MODIFY_SELF */
.ascii "exec 7<> \"$o\" || exit 121\n"
.ascii "printf '"
.ascii "\\177ELF" // 0x0: ⌂ELF
.ascii "\\2" // 4: long mode
.ascii "\\1" // 5: little endian
.ascii "\\1" // 6: elf v1.o
.ascii "\\011" // 7: FreeBSD
.ascii "\\0" // 8: os/abi ver.
.ascii "\\0\\0\\0" // 9: padding 3/7
.ascii "\\0\\0\\0\\0" // padding 4/7
.ascii "\\2\\0" // 10: εxεcµταblε
.ascii "\\076\\0" // 12: NexGen32e
.ascii "\\1\\0\\0\\0" // 14: elf v1.o
.shstub ape_elf_entry,8 // 18: e_entry
.shstub ape_elf_phoff,8 // 20: e_phoff
.shstub ape_elf_shoff,8 // 28: e_shoff
.ascii "\\165\\312\\1\\1" // 30: ape e_flags
.ascii "\\100\\0" // 34: e_ehsize
.ascii "\\070\\0" // 36: e_phentsize
.shstub ape_elf_phnum,2 // 38: e_phnum
.ascii "\\0\\0" // 3a: e_shentsize
.shstub ape_elf_shnum,2 // 3c: e_shnum
.shstub ape_elf_shstrndx,2 // 3e: e_shstrndx
.ascii "' >&7\n"
.ascii "exec 7<&-\n"
#if SupportsXnu()
.ascii "[ -d /Applications ] && "
.ascii "dd if=\"$o\""
.ascii " of=\"$o\""
.ascii " bs=8"
.ascii " skip="
.shstub ape_macho_dd_skip,2
.ascii " count="
.shstub ape_macho_dd_count,2
.ascii " conv=notrunc 2>/dev/null\n"
#endif /* XNU */
.ascii "[ x\"$1\" = x--assimilate ] && exit 0\n"
#ifndef APE_NO_MODIFY_SELF
.ascii "exec \"$0\" \"$@\"\n" // try to preserve argv[0]
#else
.ascii "}\n"
.ascii "o=\"$t\"\n"
.ascii "exec \"$o\" \"$@\"\n"
#endif /* APE_NO_MODIFY_SELF */
.ascii "exit $?\n"
.ascii "fi\n" // x86_64
.ascii "echo error: this ape binary only supports x86_64 >&2\n"
.ascii "exit 1\n"
.endobj apesh
#ifdef APE_LOADER
.section .ape.loader,"a",@progbits
.balign 64
ape_loader:
.incbin APE_LOADER
.endobj ape_loader,globl
.balign 64
ape_loader_end:
nop
.endobj ape_loader_end,globl
.previous
#endif /* APE_LOADER */
#endif /* APE_IS_SHELL_SCRIPT */
#if SupportsSystemv() || SupportsMetal()
.section .elf.phdrs,"a",@progbits
.globl ape_phdrs
ape_phdrs:
.long PT_LOAD
.long PF_R|PF_X
.stub ape_cod_offset,quad
.stub ape_cod_vaddr,quad
.stub ape_cod_paddr,quad
.stub ape_cod_filesz,quad
.stub ape_cod_memsz,quad
.stub ape_cod_align,quad
.long PT_LOAD
.long PF_R
.stub ape_rom_offset,quad
.stub ape_rom_vaddr,quad
.stub ape_rom_paddr,quad
.stub ape_rom_filesz,quad
.stub ape_rom_memsz,quad
.stub ape_rom_align,quad
.long PT_LOAD
.long PF_R|PF_W
.stub ape_ram_offset,quad
.stub ape_ram_vaddr,quad
.stub ape_ram_paddr,quad
.stub ape_ram_filesz,quad
.stub ape_ram_memsz,quad
.stub ape_ram_align,quad
// These values are left empty because some UNIX OSes give p_filesz
// priority over `ulimit -s` a.k.a. RLIMIT_STACK which is preferred
// because we use an 8mb stack by default so that decadent software
// doesn't unexpectedly crash, but putting that here meant NetBSD's
// rusage accounting (which is the best) always reported 6mb of RSS
.long PT_GNU_STACK
.stub ape_stack_pf,long
.quad 0
.quad 0
.quad 0
.quad 0
.quad 0
.quad 16
#if SupportsOpenbsd() || SupportsNetbsd()
.long PT_NOTE
.long PF_R
.stub ape_note_offset,quad
.quad 0
.quad 0
.stub ape_note_filesz,quad
.stub ape_note_memsz,quad
.quad 4
#endif
.previous
#endif /* SupportsSystemv() || SupportsMetal() */
.section .note.ape.ident,"a",@progbits
.balign 4
ape.ident:
.long 2f-1f
.long 4f-3f
.long 1
1: .asciz "APE"
2: .balign 4
3: .long APE_VERSION_NOTE
4: .size ape.ident,.-ape.ident
.type ape.ident,@object
.previous
#if SupportsOpenbsd()
.section .note.openbsd.ident,"a",@progbits
.balign 4
openbsd.ident:
.long 2f-1f
.long 4f-3f
.long 1
1: .asciz "OpenBSD"
2: .balign 4
3: .long 0
4: .size openbsd.ident,.-openbsd.ident
.type openbsd.ident,@object
.previous
#endif /* SupportsOpenbsd() */
#if SupportsNetbsd()
.section .note.netbsd.ident,"a",@progbits
.balign 4
netbsd.ident:
.long 2f-1f
.long 4f-3f
.long 1
1: .asciz "NetBSD"
2: .balign 4
3: .long 901000000
4: .size netbsd.ident,.-netbsd.ident
.type netbsd.ident,@object
.previous
#endif /* SupportsNetbsd() */
/* ▄▄███▄
▄▄████████▄
▄█████████████▄
▄▄███▓▓▓▓▓▓▓▓▓▓▓███▄
▄▄█████▓▓▓█████████▓▓▓██▄
▄▄████████▓▓▓███████▓▓▓▓▓████▄
▄█████░░░████▓▓█████▓▓▓▓█████████▄
▄▄█████████░░░███▓▓█▓▓▓▓▒███████▓▓▒███▄
▄██████████████░░░██▓▓▓▓███████████▓▓█████▄
██████████████████░░░██▓▓▓█████████▓▓▓███████▄
███░░░░░░█████████▓░░███▓▓▓▓▓▓▓▓▓▓▓█████▒▒▒██▄
█░███░░░██░░░░░░░░░██░░██████████████▒▒▒▒██████▄
███████░░░█████████░░░░░░█████████▒▒▒▒▒██████████▄
█████ ██░░░███████████████████▒▒▒▒▒██░▒▒██████████▄
██████ ██░░░██████████████░███▒████████▒▒██████████▄
████████ ███░░█████████████░░████████████▒▒███████████
█████████ ███░░███████████░░██████████████▒▒███████████
▄██████████ ██████████████ ░░███████████████▒▒███████████
████████████ ███░░░░░█████░░█████████████████▒▒██████ █
█████████████ ██████░░░░░░░▒█████████████████████ ████▀
█████████████ ██████████░░░░░░░░░███████████ ████████
█████████████ ████████░░███████░░░██████ ▓██████████
█████████████ ██████░░░████████████ █████████████
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § nexstep carnegie melon mach object format ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
@note hey xnu before we get upx'd email feedback jtunney@gmail.com
@see OS X ABI Mach-O File Format Reference, Apple Inc. 2009-02-04
@see System V Application Binary Interface NexGen32e Architecture
Processor Supplement, Version 1.0, December 5th, 2018 */
#if SupportsXnu()
.section .macho,"a",@progbits
.balign __SIZEOF_POINTER__
ape_macho:
.long 0xFEEDFACE+1
.long MAC_CPU_NEXGEN32E
.long MAC_CPU_NEXGEN32E_ALL
.long MAC_EXECUTE
.long 6 // number of load commands
.long 70f-10f // size of all load commands
.long MAC_NOUNDEFS // flags
.long 0 // reserved
10: .long MAC_LC_SEGMENT_64
.long 20f-10b // unmaps first page dir
.ascin "__PAGEZERO",16 // consistent with linux
.quad 0,0x200000,0,0 // which forbids mem <2m
.long 0,0,0,0
20: .long MAC_LC_SEGMENT_64
.long 30f-20b
.ascin "__TEXT",16
.stub ape_cod_vaddr,quad
.stub ape_cod_memsz,quad
.stub ape_cod_offset,quad
.stub ape_cod_filesz,quad
.long PROT_EXEC|PROT_READ|PROT_WRITE // maxprot
.long PROT_EXEC|PROT_READ // initprot
.long 0 // segment section count
.long 0 // flags
30: .long MAC_LC_SEGMENT_64
.long 40f-30b
.ascin "__RODATA",16
.stub ape_rom_vaddr,quad
.stub ape_rom_memsz,quad
.stub ape_rom_offset,quad
.stub ape_rom_filesz,quad
.long PROT_EXEC|PROT_READ|PROT_WRITE // maxprot
.long PROT_READ // initprot
.long 0 // segment section count
.long 0 // flags
40: .long MAC_LC_SEGMENT_64
.long 50f-40b
.ascin "__DATA",16
.stub ape_ram_vaddr,quad
.stub ape_ram_memsz,quad
.stub ape_ram_offset,quad
.stub ape_ram_filesz,quad
.long PROT_EXEC|PROT_READ|PROT_WRITE // maxprot
.long PROT_READ|PROT_WRITE // initprot
.long 0 // segment section count
.long 0 // flags
50: .long MAC_LC_UUID
.long 60f-50b
.stub ape_uuid1,quad
.stub ape_uuid2,quad
60: .long MAC_LC_UNIXTHREAD
.long 70f-60b // cmdsize
.long MAC_THREAD_NEXGEN32E // flavaflav
.long (620f-610f)/4 // count
610: .quad 0 // rax
.quad 0 // rbx
.quad 0 // rcx
.quad 0 // rdx
.quad 0 // rdi
.quad 0 // rsi
.quad 0 // rbp
.quad 0 // rsp
.quad 0 // r8
.quad 0 // r9
.quad 0 // r10
.quad 0 // r11
.quad 0 // r12
.quad 0 // r13
.quad 0 // r14
.quad 0 // r15
.quad _apple // rip
.quad 0 // rflags
.quad 0 // cs
.quad 0 // fs
.quad 0 // gs
620:
70:
.endobj ape_macho,globl,hidden
.previous /* .macho */
#endif /* SupportsXnu() */
#if SupportsWindows() || SupportsMetal()
/* ░░░░
▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓░
▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▒ ▒▒▒▓▓█
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
▒▒▒▒▓▓ ▓▒▒▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
▒▓ ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
░░░░░░░░░░░▒▒▒▒ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
░▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓░ ░▓███▓
▒▒░░░░░░░░░░▒▒▒▒▒▓▓░ ▒▓▓▓▒▒▒ ░▒▒▒▓ ████████████
▒▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░ ░███
▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ███
▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ▓██
▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓ ▓██
▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ███
░▒▓ ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ▓██
╔─────────────────────────────────────────────────────────────────▀▀▀────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § the new technology ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
The Portable Executable Format
@see https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format
@see "The Portable Executable File Format from Top to Bottom",
Randy Kath, Microsoft Developer Network Technology Group. */
// ┌14:Uniprocessor Machine ┌─────────────────────────┐
// │┌13:DLL │ PE File Characteristics │
// ││┌12:System ├─────────────────────────┤
// │││┌11:If Net Run From Swap │ r │ reserved │
// ││││┌10:If Removable Run From Swap │ d │ deprecated │
// │││││┌9:Debug Stripped │ D │ deprecated with │
// ││││││┌8:32bit Machine │ │ extreme prejudice │
// │││││││ ┌5:Large Address Aware └───┴─────────────────────┘
// │││││││ │ ┌1:Executable
// │││││││ │ │┌0:Relocs Stripped
// d│││││││dr│Ddd││
PEEXE = 0b00000001000100011
// ┌15:TERMINAL_SERVER_AWARE ┌─────────────────────────┐
// │┌14:GUARD_CF │ PE DLL Characteristics │
// ││┌13:WDM_DRIVER ├─────────────────────────┤
// │││┌12:APPCONTAINER │ r │ reserved │
// ││││┌11:NO_BIND └───┴─────────────────────┘
// │││││┌10:NO_SEH
// ││││││┌9:NO_ISOLATION
// │││││││┌8:NX_COMPAT
// ││││││││┌7:FORCE_INTEGRITY
// │││││││││┌6:DYNAMIC_BASE
// ││││││││││┌5:HIGH_ENTROPY_VA
// │││││││││││rrrrr
DLLSTD = 0b0000000100100000
DLLPIE = 0b0000000001100000
DLLEXE = DLLSTD
// ┌31:Writeable ┌─────────────────────────┐