diff --git a/.reuse/dep5 b/.reuse/dep5 index 31927f7..29efb58 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -9,6 +9,6 @@ Source: https://github.com/fosslinux/live-bootstrap # Copyright: $YEAR $NAME <$CONTACT> # License: ... -Files: sys*/*/sources sys*/SHA256SUMS.sources sysa/checksum-transcriber.SHA256SUM sysa/pre-sha.sha256sums sysa/*/*.checksums sysa/SHA256SUMS.pkgs sysc/musl-1.2.3/ld-musl-i386.path +Files: sys*/*/sources sys*/SHA256SUMS.sources sysa/checksum-transcriber.SHA256SUM sysa/pre-sha.sha256sums sysa/*/*.checksums sysa/SHA256SUMS.pkgs sysc/musl-1.2.3/ld-musl-i386.path sysa/*/simple-patches/* Copyright: none License: MIT diff --git a/DEVEL.md b/DEVEL.md index b9ddef7..7cd866e 100644 --- a/DEVEL.md +++ b/DEVEL.md @@ -23,6 +23,7 @@ sysa ├── somepackage-version │   ├── somepackage-version.kaem (or .sh) │   ├── files +│   ├── simple-patches │   ├── mk │   └── patches └── tmp @@ -47,6 +48,7 @@ Permissible folders/files: - `files`: auxiliary files required for the build distributed by live-bootstrap. - `mk`: makefiles. - `patches`: patches for the source. +- `simple-patches`: patches for the source that use the before/after convention of simple-patch.c - `*.checksums`: files containing the checksums for the resulting binaries and libraries that are compiled and installed. - Up to and including `coreutils-6.10`, `sha256sum` from `stage0-posix` diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/BSD-3-Clause.txt new file mode 100644 index 0000000..b0b8b05 --- /dev/null +++ b/LICENSES/BSD-3-Clause.txt @@ -0,0 +1,11 @@ +Copyright + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/kernel-bootstrap/builder-hex0-x86.hex0 b/kernel-bootstrap/builder-hex0-x86.hex0 new file mode 100644 index 0000000..c8eeda1 --- /dev/null +++ b/kernel-bootstrap/builder-hex0-x86.hex0 @@ -0,0 +1,2439 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +# +# Builder-Hex0 is a small bootable machine image which has +# the ability to compile hex0 code. It is also written in hex0 +# and so it can build itself if provided with its own source code. +# +# hex0 is a "language" for binary encoding in hexadecimal +# with support for comments. + +# 16 bit Functions +# ---------------- +# MBR_entry +# console_putc_16 +# console_put_hex_16 +# +# get_drive_geometry +# next_sector +# read_sectors_16 +# write_sectors_16 +# +# [GDT data] +# MBR_main + +# 32 bit Functions +# ---------------- +# setup_interrupt_handlers +# stub_interrupt_handler +# enter_16bit_real +# resume_32bit_mode +# +# console_putc +# console_put_hex +# console_puts +# read_sectors +# write_sectors +# +# syscall_interrupt_handler +# handle_syscall_open +# handle_syscall_close +# absolute_path +# find_file +# fd_to_file_index +# handle_syscall_read +# handle_syscall_brk +# handle_syscall_write +# handle_syscall_fork +# handle_syscall_execve +# handle_syscall_chdir +# handle_syscall_exit +# handle_syscall_waitpid +# handle_syscall_lseek +# handle_syscall_access +# handle_syscall_mkdir +# handle_syscall_getcwd +# +# strcmp +# +# read +# write +# src +# hex0 +# internalshell + + +#------------------------------------------------------------ +# Memory: +# 54000000 - BFFFFFFF files (~1812MB) +# 30000000 - 53FFFFFF saved processes (~604MB) +# 08048000 - 2FFFFFFF current running process (~670MB) +# 01080000 - 08000000 32 bit stack (117MB) +# 01000010 - 0107FFFF file descriptors (16 bytes each * 32K) +# { unused, address, length, unused } +# 01000000 - 0100000F stdin disk locator +# { cylinder/sector (2 bytes), head (1 byte), unused byte, +# offset (2 bytes), unused } +# 201800 - FFFFFF file names 6..14335 +# 201400 - 2017FF file name 5 +# 201000 - 2013FF file name 4 +# 100000 - 200FF0 unused +# 9FC00 - FFFFF BIOS +# 40200 - 9FBFF scratch buffer +# 40000 - 401FF stdin device buffer +# 20000 - 3FFFF process descriptors ( 16 * 4096 bytes each) +# offset len description +# 0x000 0x004 process address +# 0x004 0x004 brk pointer +# 0x008 0x004 saved stack pointer (first process only) +# 0x00C 0x004 saved stack pointer +# 0x010 0x004 forked? +# 0x014 0x004 saved brk pointer +# 0x018 0x004 child exit code +# 0x01C 0x004 address of saved process memory +# 0x020 0x004 length of process memory +# 0x024 0x004 address of saved process stack +# 0x028 0x004 length of saved process stack +# 0x02C 0x01C unused +# 0x100 0x100 current directory +# 0x200 x0E00 file descriptors 448 * 8 bytes each +# { global_file_index, current_offset } +# 10800 - 1FFFF unused +# 10000 - 107FF interrupt table +# A000 - A1FF sector read buffer - 16bit +# 7C00 - 8600 code +# 7B00 - 7BFF Saved 32 bit registers while in 16 bit mode +# < 7B00 real mode stack +#------------------------------------------------------------ + + +#------------------------------------------------------------ +#[7C00] +#:MBR_entry +# inputs: +# dl: boot drive +# +# We cannot be sure the registers are initialized to zero so we +# do that first. We far jump to MBR_main in order to set CS. +31 C0 # xor ax, ax +8E D8 # mov ds, ax +8E C0 # mov es, ax +8E D0 # mov ss, ax +BC 00 7B # mov sp, 0x7B00 +FC # cld ; clear direction flag + +EA 26 7D 00 00 # jmp MBR_main + + +#------------------------ +#[7C11] +#:console_putc_16 +# input: +# al: char to print +# +# Note: with QEMU+Seabios this does not flush the last character or +# CRLF of a line until the first character is output on the next line +# and that character cannot be another CRLF. +53 # push bx +50 # push ax + +# Prepare to use BIOS tty output interrupt. +# Specify text page 00, 0 black background, 7 light grey text +BB 00 07 # mov bx, 0x0007 +# Specify the `write character` BIOS routine +B4 0E # mov ah, 0x0E + +3C 0A # cmp al, 0x0A +75 06 # jne regular + +# convert LF to CR LF for BIOS output +B0 0D # mov al, 0x0D +CD 10 # int 0x10 +B0 0A # mov al, 0x0A + +#:regular +CD 10 # int 0x10 + +58 # pop ax +5B # pop bx +CB # retf + + +#------------------------ +#[7C27] +#:console_put_hex_16 +# input: +# al: byte to print as hex +# +50 # push ax + +24 F0 # and al, 0xF0 +C0 E8 04 # shr al, 4 +3C 09 # cmp al, 9 +7F 04 # jg alpha1 + +# numeral +04 30 # add al, 0x30 +EB 02 # jmp print1 + +#:alpha1 +04 37 # add al, 0x37 + +#:print1 +9A 11 7C 00 00 # call console_putc_16 + +58 # pop ax ; restore original al +50 # push ax ; + +24 0F # and al, 0x0F +3C 09 # cmp al, 9 +7F 04 # jg alpha2 + +# numeral +04 30 # add al, 0x30 +EB 02 # jmp print2 + +#:alpha2 +04 37 # add al, 0x37 + +#:print2 +9A 11 7C 00 00 # call console_putc_16 + +58 # pop ax +CB # retf + + + +#------------- +#[7C51] +#:boot_drive +80 + +#------------- +#[7C52] +#:max_head +0F + +#------------- +#[7C53] +#:max_sector +3F + + +#------------------------ +#[7C54] +#:get_drive_geometry +# input: +# dl: drive +# +06 # push es +57 # push di + +# https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=08h:_Read_Drive_Parameters +31 FF # xor di, di +8E C7 # mov es, di +B4 08 # mov ah, 8 ; get drive parameters +CD 13 # int 0x13 + +88 36 52 7C # mov [max_head], dh ; max_head +80 E1 3F # and cl, 0x3f +88 0E 53 7C # mov [max_sector], cl ; num_sectors + +5F # pop di +07 # pop es +CB # retf + + +#------------------------ +#[7C6C] +#:next_sector +# inputs: +# cx: cylinder/sector +# dh: head +# +50 # PUSH_AX + +88 C8 # mov al, cl ; get sector number +24 3F # and al, 0x3f +3A 06 53 7C # cmp al, [max_sector]; if sector_num == max_sector +74 04 # je next_head ; goto next_head +FE C1 # inc cl ; else sector_num++; +EB 28 # jmp next_sector_finish + +#:next_head +3A 36 52 7C # cmp dh, [max_head] ; if head_num == max_head +74 09 # je next_cylinder ; goto next_cyclinder +FE C6 # inc dh ; else head_num++ +80 E1 C0 # and cl, 0xc0 ; sector_num = 1 +FE C1 # inc cl ; +EB 19 # jmp next_sector_finish + +#:next_cylinder +80 FD FF # cmp ch, 0xff ; if cylinder_low == 255 +74 0B # je next_cyl_high + +#:next_cyl_low +30 F6 # xor dh, dh ; head_num = 0 +80 E1 C0 # and cl, 0xc0 ; sector_num = 0 +81 C1 01 01 # add cx, 0x0101 ; cylinder_low++, sector_num++ +EB 09 # jmp next_sector_finish + +#:next_cyl_high +30 F6 # xor dh, dh ; head_num = 0 +81 E1 C0 00 # and cx, 0x00C0 ; cylinder_low = 0, sector_num = 0 +80 C1 41 # add cl, 0x41 ; cylinder_high++, sector_num++ + +#:next_sector_finish +58 # pop ax +CB # retf + + +#------------------------ +#[7CA5] +#:read_sectors_16 +# inputs: +# di: dest_addr +# cx: cylinder/sector +# dh: head +# ax: num_sectors +# +# outputs: +# di: next byte to write to +# cx,dh: next disk sector to read from +# +50 # push ax +53 # push bx +56 # push si + +89 C6 # mov si, ax ; si=num_sectors +89 FB # mov bx, di ; int 13 writes to bx + +#:read_one_loop +8A 16 51 7C # mov dl, [boot_drive] +B4 02 # mov ah, 2 ; rw mode = 02 (read) +B0 01 # mov al, 1 ; num_sectors +CD 13 # int 0x13 +72 F4 # jnc read_one_loop +3C 01 # cmp al, 1 +75 F0 # jnz read_one_loop + +# advance and maybe continue +9A 6C 7C 00 00 # call next_sector + +# we read one sector, advance +81 C3 00 02 # add bx, 0x200 + +4E # dec si ; num_sectors-- +75 E4 # jnz read_one_loop + +89 DF # mov di, bx + +5E # pop si +5B # pop bx +58 # pop ax +CB # retf + + +#------------------------ +#[7CCE] +#:write_sectors_16 +# inputs: +# si: source_addr +# cx: cylinder/sector +# dh: head +# ax: num_sectors +# +# outputs: +# si: next byte to read from +# cx,dh: next disk sector to read from +# +50 # push ax +53 # push bx +57 # push di + +89 C7 # mov di, ax ; di=num_sectors +89 F3 # mov bx, si ; int 13 reads from [bx] + +#:write_one_loop +8A 16 51 7C # mov dl, [boot_drive] +B4 03 # mov ah, 3 ; rw mode = 03 (write) +B0 01 # mov al, 1 ; num_sectors +CD 13 # int 0x13 +72 F4 # jnc write_one_loop +3C 01 # cmp al, 1 +75 F0 # jnz write_one_loop + +# advance and maybe continue +9A 6C 7C 00 00 # call next_sector + +# we write one sector, advance +81 C3 00 02 # add bx, 0x200 + +4F # dec di ; num_sectors-- +75 E4 # jnz write_one_loop + +89 DE # mov si, bx + +5F # pop di +5B # pop bx +58 # pop ax +CB # retf + + +#alignment only +00 + +#--------------------------------------------- +# The Global Descriptor Table for 32 bit mode. +#--------------------------------------------- +#[7CF8] +#:GDT_start +00 00 00 00 00 00 00 00 + +#:GDT_code32 +FF FF # limit 0:15 +00 00 # base 0:15 +00 # base 16:23 +9A # access byte 10011010b + # present=1 privilege=00 type=1 + # code=1 conforming=0 readable=1 accessed=0 +CF # 11001111b + # granularity=1 32-bit-default=1 64-bit seg=0 AVL=0 +00 # + +#:GDT_data32 +FF FF # limit 0:15 +00 00 # base 0:15 +00 # base 16:23 +92 # access byte 10010010b + # present=1 privilege=00 type=1 + # code=0 conforming=0 readable=1 accessed=0 +CF # flags, limit 16:19 11001111b + # granularity=1 32-bit-default=1 64-bit seg=0 AVL=0 +00 # base 24:31 + +#:GDT_code16 +FF FF # limit 0:15 +00 00 # base 0:15 +00 # base 16:23 +9A # access byte 10011010b + # present=1 privilege=00 type=1 + # code=1 conforming=0 readable=1 accessed=0 +8F # 10001111b + # granularity=1 32-bit-default=0 64-bit seg=0 AVL=0 +00 # + +#:GDT_data16 +FF FF # limit 0:15 +00 00 # base 0:15 +00 # base 16:23 +92 # access byte 10010010b + # present=1 privilege=00 type=1 + # code=0 conforming=0 readable=1 accessed=0 +8F # flags, limit 16:19 10001111b + # granularity=1 32-bit-default=0 64-bit seg=0 AVL=0 +00 # base 24:31 + +#------ +#[7D20] +#:GDT_locator +27 00 # length +F8 7C 00 00 # GDT_start + + +#------------------------ +#[7D26] +#:MBR_main +# inputs: +# dl: boot_drive +# +# Load the kernel and jump to it +88 16 51 7C # mov [boot_drive], dl +9A 54 7C 00 00 # call get_drive_geometry() +BF 00 7E # mov di, 0x7E00 ; place remaining code after MBR in memory +B8 07 00 # mov ax, 0x0007 ; num_sectors = 7 +B9 02 00 # mov cx, 0x0002 ; cylinder = 0, sector_num = 0x02 +B6 00 # mov dh, 0 ; head = 0 +9A A5 7C 00 00 # call read_sectors_16 + +# start 32bit mode +B8 01 24 # mov ax,2401h # enable A20 line +CD 15 # int 15h + +FA # cli +0F 01 16 20 7D # lgdt GDT_locator +0F 20 C0 # mov eax, cr0 +66 83 C8 01 # or eax, 0x01 +0F 22 C0 # mov cr0, eax +EA 59 7D 08 00 # jmp setup_32bit ; sets CS + +#------ +#[7D59] +#:setup_32bit +66 B8 10 00 # mov ax, 0x0010 ; data descriptor +8E D8 # mov ds, ax +8E D0 # mov ss, ax +8E C0 # mov es, ax +8E E0 # mov fs, ax +8E E8 # mov gs, ax +BD 00 00 00 08 # mov ebp, 0x08000000 +89 EC # mov esp, ebp + +9A 7C 7D 00 00 08 00 # call setup_interrupt_handlers +EA A1 88 00 00 08 00 # jmp internalshell + + +#---------------------------------------- +#[7D7C] +#:setup_interrupt_handlers +53 # push ebx + +# handle the timer interrupt 08 +BB 40 00 01 00 # mov ebx, &interrupt_table[08] +66 C7 03 BC 7D # mov word [ebx + 0], low_address stub_interrupt_handler +66 C7 43 06 00 00 # mov word [ebx + 6], high_address +66 C7 43 02 08 00 # mov word [ebx + 2], code_segment = 0x0800 +C6 43 05 8E # mov byte [ebx + 5], flags = 8E + +# handle int 80 +BB 00 04 01 00 # mov ebx, &interrupt_table[80] +66 C7 03 D8 7E # mov word [ebx + 0], low_address syscall_interrupt_handler +66 C7 43 06 00 00 # mov word [ebx + 6], high_address +66 C7 43 02 08 00 # mov word [ebx + 2], code_segment = 0x0800 +C6 43 05 8E # mov byte [ebx + 5], flags = 8E + +# load the interrupt table +FA # cli +0F 01 1D BD 7D 00 00 # lidt IDT_locator_32 +FB # sti +5B # pop ebx +CB # retf + + +#---------------------------------------- +#[7DBC] +#:stub_interrupt_handler +CF # iret + + +#---------------------------------------- +#[7DBD] +#:IDT_locator_32 +FF 07 # length +00 00 01 00 # IDT_start + +# unused +00 00 + + +#------------------------------------------------------------ +# 32 -> 16 -> 32 bit switching functions +#------------------------------------------------------------ +# When switching between real mode and +# protected, registers are stored here: +# +# 7B14 edx +# 7B10 +# 7B0C +# 7B08 eax +# 7B04 esp +# +# 7B00 <- top of real mode stack + +#---------------------------------------- +#[7DC5] +#:enter_16bit_real +FA # cli +A3 08 7B 00 00 # mov [0x7B08], eax ; preserve so we can use these locally +89 15 14 7B 00 00 # mov [0x7B14], edx ; +5A # pop edx ; capture return address +89 25 04 7B 00 00 # mov [0x7B04], esp ; capture stack + +# The following far jump sets CS to a 16-bit protected mode selector +# and the segment registers are also set to 16-bit protected mode selectors. +# This is done prior to entering real mode. +EA DF 7D 00 00 18 00 # jmp 0x18:setup_16bit +#------ +#[7DDF] +#:setup_16bit +B8 20 00 # mov eax, 0x0020 +8E D0 # mov ss, eax +8E D8 # mov ds, eax +8E C0 # mov es, eax +8E E8 # mov gs, eax +8E E0 # mov fs, eax +BC 00 7B # mov sp, 0x7B00 +0F 20 C0 # mov eax, cr0 +66 83 E0 FE # and eax, 0xfffffffe ; clear protected mode +0F 22 C0 # mov cr0, eax +# The following far jump sets CS to a 16-bit real mode segment +# and the segment registers are also set to real mode segments. +EA 00 7E 00 00 # jmp 0000:XXXX real_mode + +# [7DFE] +# This is the DOS/MBR identifier at offset 510: +55 AA + +#------ +#[7E00] +#:real_mode +B8 00 00 # mov ax, 0x0 +8E D8 # mov ds, ax +8E E0 # mov fs, ax +8E E8 # mov gs, ax +8E D0 # mov ss, ax +8E C0 # mov es, ax +BC 00 7B # mov sp, 0x7B00 +FA # cli +0F 01 1E 22 7E # lidt IDT_locator_16 +FB # sti +# Using retf to set CS comes from here: +# https://stackoverflow.com/questions/26448480/bios-interrupts-in-protected-mode +# This page recommends a far jump followed by sti: +# https://www.sudleyplace.com/pmtorm.html +6A 00 # push 0x0000 (2 bytes!) CS to return to +52 # push dx IP to return to +A1 08 7B # mov ax, [0x7B08] ; restore from above +8B 16 14 7b # mov dx, [0x7B14] +CB # retf + +#------ +#[7E22] +#:IDT_locator_16 +FF FF +00 00 00 00 + + +#---------------------------------------- +#[7E28] +#:resume_32bit_mode +FA # cli +A3 08 7B # mov [0x7B08], ax ; preserve, they might be return values from 16 bit +89 16 14 7b # mov [0x7B14], dx +5A # pop dx ; carry the return IP in dx +58 # pop ax ; CS +0F 01 16 20 7D # lgdt GDT_locator +0F 20 C0 # mov eax, cr0 +66 83 C8 01 # or eax, 0x01 ; enable protected mode +0F 22 C0 # mov cr0, eax +EA 46 7E 08 00 # jmp restore_32bit +#------ +#[7E46] +#:restore_32bit +B8 10 00 00 00 # mov eax, 0x0010 ; data descriptor +8E D8 # mov ds, eax +8E D0 # mov ss, eax +8E C0 # mov es, eax +8E E0 # mov fs, eax +8E E8 # mov gs, eax +8B 25 04 7B 00 00 # mov esp, [0x7B04] ; restore, (saved in enter_16bit_mode) +9A 7C 7D 00 00 08 00 # call setup_interrupt_handlers +52 # push edx ; setup our return location +# These restore the 16 bit portion of these registers, which may be a +# return value from a 16 bit function, and they also restore any previous high +# bits that were stored by enter_16bit_mode so these registers need not be +# saved when going to 16 bit mode and back if you want them left alone. +A1 08 7B 00 00 # mov eax, [0x7B08] ; restore, (saved at top of this function) +8B 15 14 7B 00 00 # mov edx, [0x7B14] +C3 # ret + + +#------------------------ +#[7E6F] +#:console_putc +# +E8 51 FF FF FF # CALL enter_16bit_real, next=[7E74] +9A 11 7C 00 00 # CALL console_putc_16(al) +9A 28 7E 00 00 # CALL resume_32bit_mode +CB # RETF + + +#------------------------ +#[7E7F] +#:console_put_hex +E8 41 FF FF FF # CALL enter_16bit_real, next=[7E84] +9A 27 7C 00 00 # CALL console_put_hex_16(al) +9A 28 7E 00 00 # CALL resume_32bit_mode +CB # RETF + + +#------------------------ +#[7E8F] +#:console_puts +# inputs +# ds:si: string to print +#:puts_loop +50 # push eax +56 # push esi +8A 06 # mov al, [esi] +3C 00 # cmp al, 0 +74 0A # jz end_puts_loop +9A 6F 7E 00 00 08 00 # call console_putc +46 # inc esi +EB F0 # jmp puts_loop +#:end_puts_loop +B0 0A # mov al, 0A +9A 6F 7E 00 00 08 00 # call console_putc +5E # pop esi +58 # pop eax +CB # RETF + + +#------------------------ +#[7EAD] +#:read_sectors +# inputs: +# di: dest_addr +# cx: cylinder/sector +# dh: head +# ax: num_sectors +# +E8 13 FF FF FF # CALL enter_16bit_real, next=[7EB2] +9A A5 7C 00 00 # CALL read_sectors_16 +9A 28 7E 00 00 # CALL resume_32bit_mode +CB # RETF + + +#------------------------ +#[7EBD] +#:write_sectors +# inputs: +# si: source_addr +# cx: cylinder/sector +# dh: head +# ax: num_sectors +# +E8 03 FF FF FF # CALL enter_16bit_real, next=[7EC2] +9A CE 7C 00 00 # CALL write_sectors_16 +9A 28 7E 00 00 # CALL resume_32bit_mode +CB # RETF + +#------------------------ +#[7ECD] +#:reboot +E8 F3 FE FF FF # call enter_16bit_real, next=[7ED2] +FA # cli +EA F0 FF 00 F0 # ljmp $F000:FFF0 ; reboot + + +#------------------------ +#[7ED8] +#:syscall_interrupt_handler +# +3C 01 # cmp al, 1 +75 08 # jne try next +9A B7 84 00 00 08 00 # call handle_syscall_exit +CF # iret + +3C 02 # cmp al, 2 +75 08 # jne try next +9A B0 82 00 00 08 00 # call handle_syscall_fork +CF # iret + +3C 03 # cmp al, 3 +75 08 # jne try next +9A 5B 81 00 00 08 00 # call handle_syscall_read +CF # iret + +3C 04 # cmp al, 4 +75 08 # jne try next +9A 3D 82 00 00 08 00 # call handle_syscall_write +CF # iret + +3C 05 # cmp al, 5 +75 08 # jne try next +9A 94 7F 00 00 08 00 # call handle_syscall_open +CF # iret + +3C 06 # cmp al, 6 +75 08 # jne try next +9A 5E 80 00 00 08 00 # call handle_syscall_close +CF # iret + +3C 07 # cmp eax, 7 +75 08 # jne try next +9A 0B 85 00 00 08 00 # call handle_syscall_waitpid +CF # iret + +3C 0B # cmp eax, B +75 08 # jne try next +9A 1E 83 00 00 08 00 # call handle_syscall_execve +CF # iret + +3C 0C # cmp al, C +75 08 # jne try next +9A 60 84 00 00 08 00 # call handle_syscall_chdir +CF # iret + +3C 13 # cmp al, 0x13 +75 08 # jne try next +9A 25 85 00 00 08 00 # call handle_syscall_lseek +CF # iret + +3C 2D # cmp al, 2D +75 08 # jne try next +9A 0E 82 00 00 08 00 # call handle_syscall_brk +CF # iret + +3C 21 # cmp al, 0x21 +75 08 # jne try next +9A 6D 85 00 00 08 00 # call handle_syscall_access +CF # iret + +3C 27 # cmp al, 0x27 +75 08 # jne syscall_ok +9A 83 85 00 00 08 00 # call handle_syscall_mkdir +CF # iret + +# wait4 +3C 72 # cmp eax, 0x72 +75 05 # jne try next +31 C0 # xor eax, eax +89 01 # mov [ecx], eax +CF # iret + +3C B7 # cmp al, 0xB7 +75 08 # jne syscall_ok +9A 99 85 00 00 08 00 # call handle_syscall_getcwd +CF # iret + +#:syscall_ok +# return success for all unimplemented syscalls +31 C0 # xor eax, eax +CF # iret + + +#------ +#[7F8C] +#:next_filenum +04 00 00 00 + +#------ +#[7F90] +#:next_file_address +00 00 00 54 + +#---------------------------------------- +#[7F94] +#:handle_syscall_open +# inputs: +# ebx: filename +# ecx: flags +# +53 # push ebx +51 # push ecx +56 # push esi +57 # push edi + +9A 76 80 00 00 08 00 # call absolute_path + +F7 C1 40 00 00 00 # test ecx, 0x40 ; 0x40 is O_CREAT +74 72 # jz open_read + +# Create new file + +# Exit with error if directory does not exist + +# Go the end of filename +89 DE # mov esi, ebx +#:end_loop +AC # lodsb +3C 00 # cmp al, 0 +75 FB # jne end_loop +# Look in reverse for last slash +4E # dec esi +FD # std ; go backwards +#:find_slash_loop +AC # lodsb +3C 2F # cmp al, '/' +75 FB # jne find_slash_loop +# If first slash at start, its root, so it exists +FC # cld +46 # inc esi +39 DE # cmp esi, ebx +74 1C # je after_dir_lookup +# Zero out slash +31 C0 # xor eax, eax +89 F7 # mov edi, esi +AA # stosb +# Lookup directory +9A 13 81 00 00 08 00 # call find_file ; eax=find_file(ebx) +# Restore first char +C6 47 FF 2F # mov byte [edi - 1], 0x2f +83 F8 FF # cmp eax, -1 +75 07 # jne after_dir_lookup +EA 59 80 00 00 08 00 # jmp syscall_open_finish_fail + +#:after_dir_lookup + +# copy filename to new slot +89 DE # mov esi, ebx +BF 00 00 20 00 # mov edi, 0x0200000 +A1 8C 7F 00 00 # mov eax, [&next_filenum] +C1 E0 0A # shl eax, 0a +01 C7 # add edi, eax +B9 00 04 00 00 # mov ecx, 0x0000400 +F3 A4 # rep movsb + +# set address of file +BF 00 00 00 01 # mov edi, 0x01000000 ; pfile_descriptor = &file_descriptor[0] +A1 8C 7F 00 00 # mov eax, [&next_filenum] +C1 E0 04 # shl eax, 04 +01 C7 # add edi, eax ; pfile_descriptor += sizeof(file_descriptor) * next_filenum +8B 0D 90 7F 00 00 # mov ecx, [next_file_address] + +89 4F 04 # mov [edi+4], ecx ; pfile_descriptor->file_addr = ecx + +31 C0 # xor eax, eax +89 47 08 # mov [edi+8], eax ; pfile_descriptor->length = 0 + +A1 8C 7F 00 00 # mov eax, [next_filenum] ; return next_filenum +FF 05 8C 7F 00 00 # inc [next_filenum] +EB 18 # jmp syscall_open_finish + +#open_read +9A 13 81 00 00 08 00 # call find_file +83 F8 FF # cmp eax, -1 +74 34 # je syscall_open_finish_fail + +89 C1 # mov ecx, eax +# set read offset to start of file +BE 00 00 00 01 # mov esi, 0x01000000 ; pfile_descriptor = &file_descriptor[0] +C1 E1 04 # shl ecx, 04 +01 CE # add esi, ecx ; pfile_descriptor += sizeof(file_descriptor) * filenum + +#:syscall_open_finish +8B 35 1A 83 00 00 # mov esi, [&next_process_num] +4E # dec esi = current process +C1 E6 0C # shl esi, 0x0C +81 C6 20 02 02 00 # add esi, 0x0020220 ; pproc_descriptor = &pproc_descriptor[current_process_num].open_files[4] + +6A 04 # push 0x04 ; start at fd=4 +59 # pop ecx +#:find_slot_loop +8B 1E # mov ebx, [esi] ; get file number of fd slot +85 DB # test ebx, ebx ; is this fd slot available? +74 06 # jz got_slot +41 # inc ecx ; no, go to next slot +83 C6 08 # add esi, 0x08 +EB F4 # jmp find_slot_loop +#:got_slot +89 06 # mov [esi], eax ; store file number in slot +89 C8 # mov eax, ecx ; return fd + +31 C9 # xor ecx, ecx ; set current file offset to zero +89 4E 04 # mov [esi+0x4], ecx + +#-------- +#[8059] +#:syscall_open_finish_fail + +5F # pop edi +5E # pop esi +59 # pop ecx +5B # pop ebx +CB # ret + + +#---------------------------------------- +#[805E] +#:handle_syscall_close +# inputs: +# ebx: fd + +57 # push edi +8B 3D 1A 83 00 00 # mov edi, [&next_process_num] +4F # dec edi = current process +C1 E7 0C # shl edi, 0x0C +81 C7 00 02 02 00 # add edi, 0x00020200 ; edi = all_procs[current_process_num].open_files +31 C0 # xor eax, eax +89 04 DF # mov [edi+ebx*8], eax ; open_files[fd].global_index = 0 +5F # pop edi +CB # ret + + +#---------------------------------------- +#[8076] +#:absolute_path +# inputs: +# ebx: path +# outputs: +# ebx: absolute path +# +50 # push eax +52 # push edx +56 # push esi +57 # push edi + +BF 00 02 04 00 # mov edi, 0x00040200 ; scratch buffer +57 # push edi + +# if absolute path, skip prefixing current directory +80 3b 2f # cmp [ebx], '/' +74 18 # je strcpy_path_arg + +# get cwd +8B 35 1A 83 00 00 # mov esi, [&next_process_num] +4E # dec esi = current process +C1 E6 0C # shl esi, 0x0C +81 C6 00 01 02 00 # add esi, 0x0020100 ; pproc_descriptor = &pproc_descriptor[current_process_num].current_dir + +#:strcpy_cwd_loop +AC # lodsb +84 C0 # test al, al +74 03 # jz strcpy_path_arg +AA # stosb +EB F8 # jmp strcpy_cwd_loop + +#:strcpy_path_arg +89 DE # mov esi, ebx +# skip leading ./ +66 81 3E 2E 2F # cmp word [esi], 0x2F2E +75 02 # jne strcpy_path +46 # inc esi +46 # inc esi + +#:strcpy_path +31 DB # xor ebx, ebx ; init last_char +#:strcpy_path_loop +AC # lodsb +3C 2F # cmp al, '/' +75 05 # jne ok_path_char +80 FB 2F # cmp bl, '/' +74 01 # je skip_extra_slash +#:ok_path_char +AA # stosb +#:skip_extra_slash +84 C0 # test al, al +74 04 # jz maybe_strip_ending_slash +88 C3 # mov bl, al ; save last_char +EB ED # jmp strcpy_path_loop + +#:maybe_strip_ending_slash +80 FB 2F # cmp bl, '/' +75 05 # jne handle_dots +31 C0 # xor eax, eax +4F # dec edi +4F # dec edi +AA # stosb + +# handle /. and /.. +#:handle_dots +5A # pop edx ; record first parent +52 # push edx + +#:handle_dots_loop +5E # pop esi ; get start location +56 # push esi ; save start location + +## find_slash +AC # lodsb +3C 00 # cmp al, 0 +74 33 # je absolute_path_finish +3C 2F # cmp al, '/' +75 F7 # jne find_slash + +#:found_slash +AC # lodsb +# check for /. or /.. +3C 00 # cmp al, 0 +74 2A # je absolute_path_finish +3C 2E # cmp al, '.' +74 06 # je dot_or_dotdot +89 F2 # mov edx, esi ; record start of parent +4A # dec edx ; go back to slash +4A # dec edx +EB E8 # jmp find_slash +#:dot_or_dotdot +AC # lodsb +3C 2E # cmp al, '.' +75 0A # jne remove_slashdot + +#:remove_parent +89 D7 # mov edi, edx +AC # lodsb +AA # stosb +3C 00 # cmp al, 0 +75 FA # jne copy +EB D7 # jmp handle_dots_loop + +#:remove_slashdot +3C 00 # cmp al, 0 +75 01 # jne not_ending_slashdot +4E # dec esi ; go back to null +#:not_ending_slashdot +89 F7 # mov edi, esi +4F # dec edi +4F # dec edi +#:copy_over_slashdot +AC # lodsb +AA # stosb +3C 00 # cmp al, 0 +75 FA # jne copy_over_slashdot +EB C6 # jmp handle_dots_loop + +#:absolute_path_finish +5B # pop ebx + +# restore / if necessary +80 3B 00 # cmp byte [ebx], 0 +75 05 # jne abs_path_done +66 C7 03 2F 00 # mov word [ebx], 0x002F + +#:abs_path_done +5F # pop edi +5E # pop esi +5A # pop edx +58 # pop eax +CB + + +#---------------------------------------- +#[8113] +#:find_file +# inputs: +# ebx: file_name +# outputs: +# eax: filenum +# +51 # push ecx +52 # push edx +56 # push esi +57 # push edi + +A1 8C 7F 00 00 # mov eax, [next_filenum] +48 # dec eax +89 DE # mov esi, ebx + +#:checkfile +83 F8 03 # cmp eax, 3 +74 17 # je not_found +89 C7 # mov edi, eax +C1 E7 0A # shl edi, 0x0a +81 C7 00 00 20 00 # add edi, 0x0200000 +9A C6 85 00 00 08 00 # call strcmp +74 08 # je find_file_finish +48 # dec eax +EB E4 # jmp checkfile + +#:not_found +B8 FF FF FF FF # mov eax, 0xffffffff + +#:find_file_finish +5F # pop edi +5E # pop esi +5A # pop edx +59 # pop ecx +CB # ret + + +#------------------------------------------------------------ +#[8145] +#:fd_to_file_index +# inputs: +# ebx: file descriptor number +# outputs: +# ebx: global file index +57 # push edi +8B 3D 1A 83 00 00 # mov edi, [&next_process_num] +4F # dec edi = current process +C1 E7 0C # shl edi, 0x0C +81 C7 00 02 02 00 # add edi, 0x00020200 ; edi = all_procs[current_process_num].open_files +8B 1C DF # mov ebx, [edi+ebx*8] +5F # pop edi +CB # ret + + +#------------------------------------------------------------ +#[815B] +#:handle_syscall_read +# inputs: +# ecx: *return_char +# ebx: file +# edx: length +# +53 # push ebx +51 # push ecx +52 # push edx +56 # push esi +57 # push edi + +51 # push ecx ; we need this later to return char +83 FB 00 # cmp ebx, 0 +75 5F # jne read_memfile + +# stdin disk position is stored in fd 0 +# get current position +BB 00 00 00 01 # mov ebx, 0x01000000 +66 8B 0B # mov cx, [ebx] +8A 73 02 # mov dh, [ebx+2] +31 C0 # xor eax, eax +66 8B 43 04 # mov ax, [ebx+4] + +#end of sector? +66 3D ff 01 # cmp ax, 0x01ff +74 04 # je read_next_sector + +#:nextchar +66 40 # inc ax +EB 2A # jmp getchar + +#:read_next_sector +BF 00 A0 00 00 # mov edi, 0x000A000 +B8 01 00 00 00 # mov eax, 0x0001 ; num_sectors = 1 +9A AD 7E 00 00 08 00 # call read_sectors +# save new location and offset +66 89 0b # mov [ebx], cx +88 73 02 # mov [ebx+2], dh +31 C0 # xor eax, eax + +# move block to device buffer +BE 00 A0 00 00 # mov esi, 0x000A000 +BF 00 00 04 00 # mov edi, 0x0040000 +B9 00 02 00 00 # mov ecx, 0x0000200 +F3 A4 # rep movsb + +#:getchar +66 A3 04 00 00 01 # mov [0x01000004], ax +59 # pop ecx +BB 00 00 04 00 # mov ebx, 0x40000 ; device buffer +89 C6 # mov esi, eax ; offset +8A 04 33 # mov al, [ebx+esi+0] +88 01 # mov [ecx], al +B8 01 00 00 00 # mov eax, 1 +EB 43 # jmp syscall_read_finish + +#:read_memfile +89 D8 # mov eax, ebx ; eax = fd +9A 45 81 00 00 08 00 # call fd_to_file_index ; ebx = global file index +# get pointer to global file +BE 00 00 00 01 # mov esi, 0x01000000 ; pfile_descriptor = &file_descriptor[0] +C1 E3 04 # shl ebx, 04 +01 DE # add esi, ebx ; pfile_descriptor += sizeof(file_descriptor) * filenum + +# prepare to read +5F # pop edi ; edi = p_dst +8B 5E 04 # mov ebx, [esi+4] ; ebx = pfile_descriptor->file_address +89 D9 # mov ecx, ebx ; +03 4E 08 # add ecx, [esi+0x08] ; ecx = file_address + length +49 # dec ecx ; ecx = last address to read + +8B 35 1A 83 00 00 # mov esi, [&next_process_num] +4E # dec esi = current process +C1 E6 0C # shl esi, 0x0C +81 C6 04 02 02 00 # add esi, 0x0020204 +C1 E0 03 # shl eax, 3 +01 C6 # add esi, eax ; esi = &all_procs[current_proc_num].files[eax].current_offset + +03 1E # add ebx, [esi] ; ebx = file_addr + current_offset +87 F3 # xchg esi, ebx ; esi = p_src, ebx = &pproc_descriptor->offset +31 C0 # xor eax, eax ; bytes_read = 0 + +#:syscall_read_loop +39 CE # cmp esi, ecx ; past the end? +77 07 # ja syscall_read_finish + +A4 # movsb +40 # inc eax ; bytes_read++ +FF 03 # inc long [ebx] ; (*pcurrent_offset)++ +4A # dec edx ; length_to_read-- +75 F5 # jnz syscall_read_loop + +#:syscall_read_finish +5F # pop edi +5E # pop esi +5A # pop edx +59 # pop ecx +5B # pop ebx +CB # ret + + + +#------------------------------------------------------------ +#[820E] +#:handle_syscall_brk +56 # push esi + +A1 1A 83 00 00 # mov eax, [&next_process_num] +48 # dec eax = current process + +BE 00 00 02 00 # mov esi, 0x0020000 ; pproc_descriptor = &proc_descriptor[0] +C1 E0 0C # shl eax, 0x0C +01 C6 # add esi, eax ; pproc_descriptor += sizeof(proc_descriptor) * procnum + +85 DB # test ebx, ebx ; if ebx == 0, just return the current brk +74 15 # jz get_brk + +# set +# initialize memory to zero +57 # push edi +8B 7E 04 # mov edi, [esi+4] +31 C0 # xor eax, eax +#:init_loop +39 DF # cmp edi, ebx +74 03 # je init_done +AA # stosb +EB F9 # jmp init_loop +#:init_done +5F # pop edi + +89 5E 04 # mov [esi+4], ebx +89 D8 # mov eax, ebx +5E # pop esi +CB # ret + +#:get_brk +8B 46 04 # mov eax, [esi+4] ; pproc_descriptor->brk +5E # pop esi +CB # ret + + +#------------------------------------------------------------ +#[823D] +#:handle_syscall_write +# inputs: +# ebx: file +# ecx: address of char to write +# edx: num bytes to write +51 # push ecx +52 # push edx +56 # push esi +57 # push edi + +31 C0 # xor eax, eax ; bytes_written = 0 + +83 FB 02 # cmp ebx, 02 ; std file? +7F 14 # jg write_memfile + +# stdout,stderr -> console_out +#:std_loop +85 D2 # test edx, edx +74 5B # jz syscall_write_finish +50 # push eax ; save num_written +8A 01 # mov al, [ecx] +9A 6F 7E 00 00 08 00 # call console_putc +58 # pop eax ; restore num_written + +40 # inc eax ; num_written++ +41 # inc ecx ; p_dst++ +4A # dec edx ; count-- +EB EC # jmp std_loop + +#:write_memfile +89 CE # mov esi, ecx + +# use ecx as pointer to fd current offset +8B 0D 1A 83 00 00 # mov ecx, [&next_process_num] +49 # dec ecx = current process +C1 E1 0C # shl ecx, 0x0C +81 C1 04 02 02 00 # add ecx, 0x0020204 +53 # push ebx +C1 E3 03 # shl ebx, 3 +01 D9 # add ecx, ebx ; ecx = &all_procs[current_proc_num].files[ebx].current_offset +5B # pop ebx + +# lookup global file index from file descriptor +9A 45 81 00 00 08 00 # call fd_to_file_index +C1 E3 04 # shl ebx, 04 +81 C3 00 00 00 01 # add ebx, 0x01000000 ; pfile_descriptor += sizeof(file_descriptor) * filenum + +8B 7B 04 # mov edi, [ebx+4] ; edi = pfile_descriptor->file_address +03 39 # add edi, [ecx] ; edi = file_addr + current_offset +#:write_loop +85 D2 # test edx, edx +74 19 # jz syscall_write_finish +A4 # movsb +FF 01 # inc long [ecx] ; current_offset++ +# If current offset is past previous file length, then increase length +50 # push eax +8B 01 # mov eax, [ecx] +3B 43 08 # cmp eax, [ebx+0x8] +7E 09 # jle skip_lengthen +FF 43 08 # inc long [ebx+0x8] ; file_length++ +FF 05 90 7F 00 00 # inc long [next_file_address] +#:skip_lengthen +58 # pop eax +40 # inc eax ; num_written++ +4A # dec edx +EB E3 # jmp write_loop + +#:syscall_write_finish +5F # pop edi +5E # pop esi +5A # pop edx +59 # pop ecx +CB # ret + + +#------ +#[82AC] +#:next_save_process_address +00 00 00 30 + +#---------------------------------------- +#[82B0] +#:handle_syscall_fork +53 # push ebx +51 # push ecx +52 # push edx +56 # push esi +57 # push edi +55 # push ebp + +A1 1A 83 00 00 # mov eax, [&next_process_num] +48 # dec eax = current process +89 C2 # mov edx, eax +BF 00 00 02 00 # mov edi, 0x0020000 ; pproc_descriptor = &proc_descriptor[0] +C1 E0 0C # shl eax, 0x0C +01 C7 # add edi, eax ; pproc_descriptor += sizeof(proc_descriptor) * procnum + +8b 77 04 # mov esi, [edi+0x4] ; save brk pointer +89 77 14 # mov [edi+0x14], esi +89 E6 # mov esi, esp +89 77 0c # mov [edi+0xC], esi ; save stack pointer so we can return again later +FF 47 10 # inc [edi+0x10] ; fork = true + +A1 AC 82 00 00 # mov eax, [next_save_process_address] ; set save stack location +89 47 24 # mov [edi+0x24], eax + +B9 00 00 00 08 # mov ecx, 0x08000000 +29 F1 # sub ecx, esi ; compute save stack length +01 0D AC 82 00 00 # add [next_save_process_address], ecx +89 4F 28 # mov [edi+0x28], ecx +89 C7 # mov edi, eax +F3 A4 # rep movsb ; save stack + +# copy current process image to storage +89 D0 # mov eax, edx ; restore current process num +C1 E0 0C # shl eax, 0x0C +05 00 00 02 00 # add eax, 0x0020000 +8B 30 # mov esi, [eax] ; esi = pproc_descriptor->process_address + +8B 48 14 # mov ecx, [eax+0x14] ; process_length = brk - process_address +29 F1 # sub ecx, esi +89 78 1C # mov [eax+0x1C], edi ; save address of saved process memory +89 48 20 # mov [eax+0x20], ecx ; save length of process memory +01 0D AC 82 00 00 # add [next_save_process_address], ecx +F3 A4 # rep movsb ; copy current process image to storage + +31 C0 # xor eax, eax ; return as child, we'll return again as parent when child exits +5D # pop ebp +5F # pop edi +5E # pop esi +5A # pop edx +59 # pop ecx +5B # pop ebx +CB # ret + + +#------ +#[831A] +#:next_process_num +01 00 00 00 + +#---------------------------------------- +#[831E] +#:handle_syscall_execve +# inputs: +# ebx: program_name +# ecx: char **args +# edx: env +# + +A1 1A 83 00 00 # mov eax, [next_process_num] +3C 01 # cmp al, 1 +75 0A # jne not_first_process + +# first process +BD 00 10 02 00 # mov ebp, 0x00021000 ; ebp = &proc_descriptor[1] +89 65 08 # mov [ebp+0x8], esp ; save original stack pointer before pushing args +EB 23 # jmp prepare_stack + +# not_first_process +# check if current process forked or not. +# if so, create new process, if not overlay current +48 # dec eax ; eax = current_process +C1 E0 0C # shl eax, 0x0C +05 00 00 02 00 # add eax, 0x0020000 ; pproc_descriptor = &proc_descriptor[0] +8B 68 10 # mov ebp, [eax+0x10] ; create_new_process = pproc->forked +85 ED # test ebp, ebp ; did current process fork? +75 0B # jnz forked + +#not_forked +8B 60 0C # mov esp, [eax+0xC] ; no fork so reset initial stack to same as current process +A1 1A 83 00 00 # mov eax, [next_process_num] +48 # dec eax +EB 08 # jump prepare_stack + +#:forked +FF 48 10 # dec [eax+0x10] ; fork handled so reset: fork = false +A1 1A 83 00 00 # mov eax, [next_process_num] + + +#:prepare_stack +# eax=process number to use +# --- env --- +8B 3D AC 82 00 00 # mov edi, [next_save_process_address] +6A 00 # push 0 ; push end of env +#:push_env_loop +# copy env arg to memory for this process +8B 32 # mov esi, [edx] +85 F6 # test esi, esi +74 0F # jz end_env_loop +57 # push edi ; push p_arg +51 # push ecx +B9 00 01 00 00 # mov ecx, 0x00000100 ; memory per arg +F3 A4 # rep movsb ; copy to new memory +59 # pop ecx +83 C2 04 # add edx, 4 +EB EB # jmp push_env_loop + + +#:end_env_loop +# --- args --- +6A 00 # push 0 ; push end of args +# count args +31 C0 # xor eax, eax ; passed_args = 0 +#:countloop +83 39 00 # cmp long [ecx], 0 +74 06 # jz push_args +40 # inc eax +83 C1 04 # add ecx, 4 +EB F5 # jmp countloop + +# push_args +89 C2 # mov edx, eax ; save eax (can't push) +#:push_args_loop +83 E9 04 # sub ecx, 4 + +# copy arg to memory for this process +8B 31 # mov esi, [ecx] + +57 # push edi ; push p_arg + +51 # push ecx +B9 00 01 00 00 # mov ecx, 0x00000100 ; memory per arg +F3 A4 # rep movsb +59 # pop ecx +48 # dec eax +75 EE # jnz push_args_loop + +# finish with argc +89 D0 # mov eax, edx ; restore eax +50 # push eax = argc + +# get current process descriptor +A1 1A 83 00 00 # mov eax, [next_process_num] +48 # dec eax +50 # push eax ; save current process num +C1 E0 0C # shl eax, 0x0C +05 00 00 02 00 # add eax, 0x0020000 ; pproc_descriptor = &proc_descriptor[current_process_num] + +89 3D AC 82 00 00 # mov [next_save_process_address], edi + +# copy cwd from current process +05 00 01 00 00 # add eax, 0x100 +89 C6 # mov esi, eax +05 00 10 00 00 # add eax, 0x1000 +89 C7 # mov edi, eax +#loop +AC # lodsb +AA # stosb +3C 00 # cmp al, 0 +75 FA # jne loop + +58 # pop eax ; restore current process num +40 # inc eax ; eax = new process id + +# prepare process image in memory +50 # push eax ; save new process id +# get file address and length +9A 76 80 00 00 08 00 # call absolute_path +9A 13 81 00 00 08 00 # call find_file ; eax=find_file(ebx) + +# zero process memory. +# Do this after looking up file name because that may come from process memory. +50 # push eax +57 # push edi +31 C0 # xor eax, eax +BF 00 80 04 08 # mov edi, 0x08048000 +B9 00 80 FB 26 # mov ecx, 0x26FB8000 +F3 AA # rep stosb +5F # pop edi +58 # pop eax + +C1 E0 04 # shl eax, 04 ; pfile_descriptor = sizeof(file_descriptor) * filenum +05 00 00 00 01 # add eax, 0x01000000 ; pfile_descriptor += &file_descriptors[0] + +8B 40 04 # mov eax, [eax + 0x4] ; eax = pfile_descriptor->file_address +89 C3 # mov ebx, eax ; save file address +31 C9 # xor ecx, ecx +66 8B 48 2C # mov cx, [eax + 0x2C] ; get number of program headers +8B 50 18 # mov edx, [eax + 0x18] ; get process entry address +03 40 1C # add eax, [eax + 0x1C] ; calc first program header address + +#:program_header_loop +51 # push ecx ; save program header count +8B 70 04 # mov esi, [eax + 4] ; get segment file source offset +01 DE # add esi, ebx ; calc segment file address +8B 78 08 # mov edi, [eax + 8] ; get segment memory destination address +8B 48 10 # mov ecx, [eax + 0x10] ; get segment length +F3 A4 # rep movsb + +83 C0 20 # add eax, 0x20 ; go to next program header +59 # pop ecx ; restore program header count +49 # dec ecx +75 EB # jnz program_header_loop + +58 # pop eax ; restore new process num + +85 ED # test ebp, ebp ; new process (vs overlay)? +75 01 # jnz record_process_address +48 # dec eax ; overlay + +#:record_process_address +C1 E0 0C # shl eax, 0x0C +05 00 00 02 00 # add eax, 0x0020000 ; pproc_descriptor = &pproc_descriptor[current_process_num] + +03 5B 1C # add ebx, [ebx + 0x1C] ; calc first program header address +8B 5B 08 # mov ebx, [ebx + 0x8] ; get first segment memory address +89 18 # mov [eax], ebx ; pproc_descriptor->process_address = first segment address + +# setup brk +81 C7 00 00 02 00 # add edi, 0x00020000 ; brk after last segment plus 0x20000 +89 78 04 # mov [eax + 4], edi ; pproc_descriptor->brk +31 FF # xor edi, edi +89 78 10 # mov [eax + 0x10], edi ; pproc->forked = false + +# clear open file descriptors +89 C7 # mov edi, eax +81 C7 00 02 00 00 # add edi, 0x0000200 +31 C0 # xor eax, eax +B9 00 0E 00 00 # mov ecx, 0x00000E00 +F3 AA # rep stosb + +85 ED # test ebp, ebp ; new process (vs overlay)? +74 06 # jz after_new_process + +# prepare for next process +FF 05 1A 83 00 00 # inc [next_process_num] + +#:after_new_process +# get entry point and jump +52 # push edx +31 C0 # xor eax, eax +31 DB # xor ebx, ebx +31 C9 # xor ecx, ecx +31 D2 # xor edx, edx +31 F6 # xor esi, esi +31 FF # xor edi, edi +31 ED # xor ebp, ebp +C3 # ret + + +#---------------------------------------- +#[8460] +#:handle_syscall_chdir +56 # push esi +57 # push edi + +9A 76 80 00 00 08 00 # call absolute_path +9A 13 81 00 00 08 00 # call find_file +83 F8 FF # cmp eax, -1 +74 3F # je chdir_finish + +C1 E0 04 # shl eax, 04 +05 08 00 00 01 # add eax, 0x01000008 ; eax = &file_descriptor[filenum].file_length +83 38 00 # cmp long [eax], 0 +74 07 # je chdir_ok + +# can't chdir to a file +B8 FF FF FF FF # mov eax, -1 +EB 2B # jmp chdir_finish + +#:chdir_ok +89 DE # mov esi, ebx +8B 3D 1A 83 00 00 # mov edi, [&next_process_num] +4F # dec edi = current process +C1 E7 0C # shl edi, 0x0C +81 C7 00 01 02 00 # add edi, 0x0020100 ; pproc_descriptor = &pproc_descriptor[current_process_num].current_dir + +AC # lodsb ; first slash +AA # stosb +AC # lodsb +AA # stosb +3C 00 # cmp al, 0 +75 04 # jne chdir_loop +31 C0 # xor eax, eax +74 0D # je chdir_finish ; if "/" don't add slash + +#chdir_loop +AC # lodsb +AA # stosb +3C 00 # cmp al, 0 +75 FA # jne chdir_loop +4F # dec edi + +#:add_slash +B0 2F # mov al, '/' +AA # stosb +31 C0 # xor eax, eax +AA # stosb + +#:chdir_finish +5F # pop edi +5E # pop esi +CB # retf + + +#---------------------------------------- +#[84B7] +#:handle_syscall_exit +A1 1A 83 00 00 # mov eax, [&next_process_num] +48 # dec eax = current process +A3 1A 83 00 00 # mov [&next_process_num], eax +48 # dec eax = parent process + +3C 00 # cmp al, 0 +75 07 # jne not_first +#first process +8B 25 08 10 02 00 # mov esp, [0x021008] +CB # ret + +#not_first +C1 E0 0C # shl eax, 0x0C +05 00 00 02 00 # add eax, 0x0020000 ; pproc_descriptor = &proc_descriptor[0] +89 58 18 # mov [eax+0x18], ebx ; save child exit code + +8B 38 # mov edi, [eax] ; edi = pproc_descriptor->process_address +8B 70 1C # mov esi, [eax+0x1C] ; esi = pproc_descriptor->address_of_saved_process_memory +8B 48 20 # mov ecx, [eax+0x20] ; ecx = pproc_descriptor->length_of_process_memory +F3 A4 # rep movsb + +8B 70 24 # mov esi, [eax+0x24] ; deallocate memory for saved process +89 35 AC 82 00 00 # mov [next_save_process_address], esi + +8B 60 0C # mov esp, [eax+0xc] ; restore stack pointer +8B 70 14 # mov esi, [eax+0x14] ; restore brk pointer +89 70 04 # mov [eax+0x4], esi + +8B 70 24 # mov esi, [eax+0x24] ; restore stack +89 E7 # mov edi, esp +8B 48 28 # mov ecx, [eax+0x28] +F3 A4 # rep movsb + +# mimic syscall_fork's finish +B8 01 00 00 00 # mov eax, 0x1 ; process number for fork +5D # pop ebp +5F # pop edi +5E # pop esi +5A # pop edx +59 # pop ecx +5B # pop ebx +CB # ret ; go back to parent + + +#---------------------------------------- +#[850B] +#:handle_syscall_waitpid +8B 35 1A 83 00 00 # mov esi, [&next_process_num] +4E # dec esi = current process +C1 E6 0C # shl esi, 0x0C +81 C6 18 00 02 00 # add esi, 0x00020018 ; pchild_code = &pproc_descriptor[current_process_num].child_exit_code +8B 06 # mov eax, [esi] ; get exit code +C1 E0 08 # shl eax, 0x08 ; +89 01 # mov [ecx], eax ; waitval = ret << 8 +31 C0 # xor eax, eax +CB # ret + + +#---------------------------------------- +#[8525] +#:handle_syscall_lseek +# inputs: +# ebx: fd +# ecx: value +# edx: method (0=SEEK_SET, 1=SEEK_CUR, 2=SEEK_END) +# outputs: +# eax: offset +# +56 # push esi + +8B 35 1A 83 00 00 # mov esi, [&next_process_num] +4E # dec esi = current process +C1 E6 0C # shl esi, 0x0C +81 C6 04 02 02 00 # add esi, 0x0020204 ; pproc_descriptor = &pproc_descriptor[current_process_num].files[0].offset + +83 FA 01 # cmp edx, 1 +7F 13 # jg seek_end +7C 0A # jl seek_set + +#:seek_cur +8B 04 DE # mov eax, [esi+ebx*8] ; get current_offset +01 C8 # add eax, ecx ; current_pos += offset +89 04 DE # mov [esi+ebx*8], eax ; set current_pos +5E # pop esi +CB # ret + +#:seek_set +89 0C DE # mov [esi+ebx*8], ecx ; set current_pos +89 C8 # mov eax, ecx +5E # pop esi +CB # ret + +#:seek_end +56 # push esi +53 # push ebx +9A 45 81 00 00 08 00 # call fd_to_file_index +BE 00 00 00 01 # mov esi, 0x01000000 ; pfile_descriptor = &file_descriptor[0] +C1 E3 04 # shl ebx, 04 +01 DE # add esi, ebx +8B 46 08 # mov eax, [esi+0x8] ; get current_length +01 C8 # add eax, ecx ; current_length += offset +5B # pop ebx +5E # pop esi + +89 04 DE # mov [esi+ebx*8], eax ; set current_offset + +5E # pop esi +CB # ret + + +#---------------------------------------- +#[856D] +#:handle_syscall_access +#inputs: +# ebx: path +# ecx: mode +9A 76 80 00 00 08 00 # call absolute_path +9A 13 81 00 00 08 00 # call find_file +83 F8 FF # cmp eax, -1 +74 02 # je access_error_exit +31 C0 # xor eax, eax +#:access_error_exit +CB # ret + + +#---------------------------------------- +#[8583] +#:handle_syscall_mkdir +#inputs: +# ebx: path +# ecx: mode +51 # push ecx +B9 41 00 00 00 # mov ecx, 0x41 (O_CREAT | O_WRONLY) +9A 94 7F 00 00 08 00 # call handle_syscall_open +83 F8 FF # cmp eax, -1 +74 02 # je open_error_exit +31 C0 # xor eax, eax +#:open_error_exit +59 # pop ecx +CB # ret + + +#---------------------------------------- +#[8599] +#:handle_syscall_getcwd +#inputs: +# ebx: buf +# ecx: buf size +#outputs: +# eax: buf +56 # push esi +57 # push edi + +89 DF # mov edi, ebx +8B 35 1A 83 00 00 # mov esi, [&next_process_num] +4E # dec esi = current process +C1 E6 0C # shl esi, 0x0C +81 C6 00 01 02 00 # add esi, 0x0020100 ; pproc_descriptor = &pproc_descriptor[current_process_num].current_dir + +# Handle root differently because we don't strip trailing slash +66 83 3E 2F # cmp word [esi], $002f ; is cwd == "/" ? +75 04 # jne copy_cwd +66 A5 # movsw ; copy "/" to buffer +EB 0A # jmp cleanup + +# copy_cwd +AC # lodsb +AA # stosb +3C 00 # cmp al, 0 +75 FA # jne copy_cwd +83 EF 02 # sub edi, 2 ; strip trailing slash +AA # stosb + +# cleanup +89 D8 # mov eax, ebx +5F # pop edi +5E # pop esi +CB # ret + + +#------------------------------------------------------------ +#[85C6] +#:strcmp +# inputs: +# esi: string1 +# edi: string2 +# outputs: +# zero flag +# +50 # push eax +53 # push ebx +56 # push esi +57 # push edi + +#:check_byte +8A 06 # mov al, [esi] +8A 1F # mov bl, [edi] +38 D8 # cmp al, bl +75 0A # jne strcmp_finish +46 # inc esi +47 # inc edi +84 C0 # test al, al +75 F2 # jnz check_byte +84 DB # test bl, bl +75 EE # jnz check_byte + +#:strcmp_finish +5F # pop edi +5E # pop esi +5B # pop ebx +58 # pop eax +CB # ret + + +#------ +#[85E1] +#:io_char +00 +00 # free + +#---------------------------------------- +#[85E3] +#:read +53 # push ebx +51 # push ecx +52 # push edx +B8 03 00 00 00 # mov eax, 3 ; syscall=read +B9 E1 85 00 00 # mov ecx, &io_char +BA 01 00 00 00 # mov edx, 1 + +CD 80 # int 80 syscall + +3C 00 # cmp al, 0 +74 07 # je read_finish + +B4 01 # mov ah, 1 +A0 E1 85 00 00 # mov al, &io_char + +#:read_finish +5A # pop edx +59 # pop ecx +5B # pop ebx +CB # ret + + +#---------------------------------------- +#[8606] +#:write +50 # push eax +53 # push ebx +51 # push ecx +52 # push edx + +A2 E1 85 00 00 # mov &io_char, al +B8 04 00 00 00 # mov eax, 4 ; syscall=write +B9 E1 85 00 00 # mov ecx, &io_char +BA 01 00 00 00 # mov edx, 1 1 byte characters +CD 80 # int 80 syscall + +5A # pop edx +59 # pop ecx +5B # pop ebx +58 # pop eax +CB # ret + + +#------ +#[8625] +#:string_src +#s r c \0 +73 72 63 00 + +#---------------------------------------- +# src: create file from stdin +# +# Read an integer, N, in decimal from stdin. +# Read a space. +# Then, read a file name to create. +# Read a newline. +# Then, read N bytes from stdin and write to the new file. +#---------------------------------------- +#[8629] +#:src +50 # push eax +53 # push ebx +51 # push ecx +52 # push edx +56 # push esi +57 # push edi + +BE 25 86 00 00 # mov esi, string_src +9A 8F 7E 00 00 08 00 # call console_puts + +9A E3 85 00 00 08 00 # call read 'r' +9A E3 85 00 00 08 00 # call read 'c' +9A E3 85 00 00 08 00 # call read ' ' + +31 C9 # xor ecx, ecx ; line count=0 +#parse_line_count_loop: +9A E3 85 00 00 08 00 # call read +3C 20 # cmp al, ' ' +74 0C # je got_count + +6B C9 0A # imul ecx, ecx, 10 ; count = count * 10 +2C 30 # sub al, 30 +0F B6 C0 # movzx eax, al +01 C1 # add ecx, eax ; count += digit + +EB E9 # jmp parse_line_count_loop + +#:got_count +# clear arguments +51 # push ecx +31 C0 # xor eax, eax +BA 00 00 D0 04 # mov edx, 0x04D00000 +B9 00 08 00 00 # mov ecx, 0x00000800 + +#:src_args_zeroloop +88 02 # mov [edx], al +42 # inc edx +49 # dec ecx +75 FA # jnz src_args_zeroloop +59 # pop ecx + +51 # push ecx +B9 00 00 D0 04 # mov ecx, 0x04D00000 +#:get_filename_loop +9A E3 85 00 00 08 00 # call read + +3C 0A # cmp al, '\n' +74 05 # je got_filename +88 01 # mov [ecx], al +41 # inc ecx +EB F0 # jmp get_file_name_loop +59 # pop ecx + +#:got_filename +BE 00 00 D0 04 # mov esi, 0x04D00000 +9A 8F 7E 00 00 08 00 # call console_puts + +# open filename for write +51 # push ecx +BB 00 00 D0 04 # mov ebx, 0x04D00000 +B8 05 00 00 00 # mov eax, 5 ; syscall_open +B9 41 02 00 00 # mov ecx, 0x00000241 O_TRUNC (0x200) | O_CREAT (0x40) | O_WRONLY (0x1) +BA 80 01 00 00 # mov edx, 0x00000180 S_IRUSR (0x100) | S_IWUSR (0x80) +CD 80 # int 80 +59 # pop ecx +89 C2 # mov edx, eax + +# edx has the open file number + +#:readwrite_loop +85 C9 # test ecx, ecx +74 1C # jz src_finish +BF 00 02 04 00 # mov edi, 0x00040200 ; scratch buffer +57 # push edi ; save buffer address +31 DB # xor ebx, ebx ; ebx=0=stdin +9A E3 85 00 00 08 00 # call read +89 D3 # mov ebx, edx ; prepare to write +5E # pop esi ; restore buffer address to esi +9A 06 86 00 00 08 00 # call write +49 # dec ecx ; count-- +EB E0 # jmp read_write_loop + +#:src_finish +5F # pop edi +5E # pop esi +5A # pop edx +59 # pop ecx +5B # pop ebx +58 # pop eax +CB # ret + + + +#------ +#[86E1] +#:hex0_str +#h e x 0 \0 +68 65 78 30 00 + +#------------------------------------------------------------ +#[86E6] +#:hex0 +53 # push ebx +56 # push esi +57 # push edi + +BE E1 86 00 00 # mov esi, hex0_str +9A 8F 7E 00 00 08 00 # call console_puts + +# read "ex0 ' +B1 04 # mov cl, 4 +#:ex0_loop +9A E3 85 00 00 08 00 # call read +FE C9 # dec cl +75 F5 # jnz ex0_loop + +# clear arguments +31 C0 # xor eax, eax +BA 00 00 D0 04 # mov edx, 0x04D00000 +B9 00 08 00 00 # mov ecx, 0x00000800 +#:hex0_args_zeroloop +88 02 # mov [edx], al +42 # inc edx +49 # dec ecx +75 FA # jnz hex0_args_zeroloop + +BA 00 00 D0 04 # mov edx, 0x04D00000 +#:get_file_name1_loop +9A E3 85 00 00 08 00 # call read +9A 6F 7E 00 00 08 00 # call console_putc +3C 20 # cmp al, ' ' +74 05 # je got_filename1 +88 02 # mov [edx], al +42 # inc edx +EB E9 # jmp get_file_name1_loop + +#:got_filename1 +BA 00 04 D0 04 # mov edx, 0x04D00400 +#:get_file_name2_loop +9A E3 85 00 00 08 00 # call read +9A 6F 7E 00 00 08 00 # call console_putc +3C 0A # cmp al, '\n' +74 05 # je got_filename2 +88 02 # mov [edx], al +42 # inc edx +EB E9 # jmp get_file_name2_loop + +# open filename1 for read +BB 00 00 D0 04 # mov ebx, 0x04D00000 +B8 05 00 00 00 # mov eax, 5 ; syscall_open +B9 00 00 00 00 # mov ecx, 0x00000000 +CD 80 # int 80 + +50 # push eax ; save read filenum + +# open filename2 for write +BB 00 04 D0 04 # mov ebx, 0x04D00400 +B8 05 00 00 00 # mov eax, 5 ; syscall_open +B9 41 02 00 00 # mov ecx, 0x00000241 O_TRUNC (0x200) | O_CREAT (0x40) | O_WRONLY (0x1) +BA 80 01 00 00 # mov edx, 0x00000180 S_IRUSR (0x100) | S_IWUSR (0x80) +CD 80 # int 80 +89 C2 # mov edx, eax + +59 # pop ecx ; restore read filenum + +# this flag is set after the first digit is seen +31 DB # xor ebx, ebx + + +#------ +#[8779] +#:hex0_read_loop +53 # push ebx +89 CB # mov ebx, ecx +9A E3 85 00 00 08 00 # call read +5B # pop ebx + +84 e4 # test ah, ah +75 04 # jnz check_command +5F # POP_DI +5E # POP_SI +5B # POP_BX +CB # RETF + +#:check_command +3C 23 # cmp al, '#' + +74 28 # jz skip_comment + +3C 3B # cmp ';' +74 24 # jz skip_comment + +3C 66 # cmp al, 'f' +7F D1 # jg hex0_read_loop + +3C 61 # cmp al, 'a' +7C 04 # jl maybe_upper + +# Handle a to f +2C 57 # sub al, 'a'-10 == 87 = 0x57 +EB 29 # jmp maybe_store + +#:maybe_upper +3C 46 # cmp al, 'F' +7F D5 # jg hex0_read_loop + +3C 41 # cmp al, 'A' +7C 04 # jl maybe_digit + +# Handle A to F +2C 37 # sub al, 'A'-10 == 55 = x37 +EB 1D # jmp maybe_store + +#:maybe_digit +3C 39 # cmp al, '9' +7F C9 # jg hex0_read_loop + +3C 30 # cmp al, '0' +7C C5 # jl hex0_read_loop + +# Handle 0 to 9 +2C 30 # sub al, '0' == x30 +EB 11 # jmp maybe_store + +#:skip_comment +53 # push ebx +89 CB # mov ebx, ecx +9A E3 85 00 00 08 00 # call read +5B # pop ebx +3C 0A # cmp al, '\n' +75 F1 # jnz skip_comment +EB B0 # jmp hex0_read_loop + +# only store on second digit +#:maybe_store +84 DB # test bl, bl +75 09 # jnz second_digit + +# If on first digit, record and keep going +#:first_digit +C0 E0 04 # shl al, 4 +88 C7 # mov bh, al +FE C3 # inc bl +EB A3 # jmp hex0_read_loop + +# If on second digit, store and clear state +#:second_digit +08 C7 # or bh, al +88 F8 # mov al, bh + +53 # push ebx +89 D3 # mov ebx, edx +9A 06 86 00 00 08 00 # call write +5B # pop ebx + +31 DB # xor bx, bx +EA 79 87 00 00 08 00 # jmp hex0_read_loop + + +#------ +#[87EE] +#:cmd_args +00 00 D0 04 +00 04 D0 04 + +#------ +#[87F6] +#:cmd_env +00 00 00 00 + +#------------------------------------------------------------ +#[87FA] +#:handle_other_command +50 # push eax +53 # push ebx +51 # push ecx +52 # push edx +56 # push esi + +# clear arguments +BA 00 00 D0 04 # mov edx, 0x04D00000 +88 02 # mov [edx], al +42 # inc edx +31 C0 # xor eax, eax +B9 FF 07 00 00 # mov ecx, 0x000007FF +#other_args_zeroloop +88 02 # mov [edx], al +42 # inc edx +49 # dec ecx +75 FA # jnz other_args_zeroloop + +BA 01 00 D0 04 # mov edx, 0x04D00001 +#:get_program_name +9A E3 85 00 00 08 00 # call read +3C 20 # cmp al, ' ' +74 05 # je got_program_name +88 02 # mov [edx], al +42 # inc edx +EB F0 # jmp get_program_name + +#got_program_name +BA 00 04 D0 04 # mov edx, 0x04D00400 +#get_argument1_loop +9A E3 85 00 00 08 00 # call read +3C 0A # cmp al, '\n' +74 05 # je got_argument1 +88 02 # mov [edx], al +42 # inc edx +EB F0 # jmp get_argument1_loop + +#:got_argument1 +BE 00 00 D0 04 # mov esi, program +9A 8F 7E 00 00 08 00 # call console_puts + +BE 00 04 D0 04 # mov esi, arg1 +9A 8F 7E 00 00 08 00 # call console_puts + +BB 00 00 D0 04 # mov ebx, program_name +B9 EE 87 00 00 # mov ecx, cmd_args +BA F6 87 00 00 # mov edx, cmd_env +9A 1E 83 00 00 08 00 # call handle_syscall_execve + +5E # pop esi +5A # pop edx +59 # pop ecx +5B # pop ebx +58 # pop eax +CB + + +#------ +#[8872] +#:str_build_finished +#B u i l d f i n i s h e d . \0 +42 75 69 6C 64 20 66 69 6E 69 73 68 65 64 2E 00 + +#------ +#[8882] +#:str_error_no_writes +#E R R O R : n o h d a w r i t e s ! \0 +45 52 52 4F 52 3A 20 6E 6F 20 68 64 61 20 77 72 69 74 65 73 21 00 + +#------ +#[8898] +#:str_dev_hda +#/ d e v / h d a \0 +2F 64 65 76 2F 68 64 61 00 + + +#------------------------------------------------------------ +#[88A1] +#:internalshell +# Start reading stdin from sector 8, cyl 0, head 0 +C7 05 00 00 00 01 08 00 00 00 # mov word [0x01000000], 0x00000008 +# start at "end of sector" to trigger an initial sector read +66 C7 05 04 00 00 01 FF 01 # mov word [0x01000004], 0x01FF +66 C7 05 00 01 02 00 2F 00 # mov [0x00020100], 0x002F ; proc[0].cwd = "/" +66 C7 05 00 11 02 00 2F 00 # mov [0x00021100], 0x002F ; proc[1].cwd = "/" + +# clear file descriptors for process 0 +BF 00 02 02 00 # mov edi, 0x00020200 +B9 00 0E 00 00 # mov ecx, 0x00000E00 +31 C0 # xor eax, eax +F3 AA # rep stosb + +# read from stdin +31 DB # xor ebx, ebx + +#:process_command +9A E3 85 00 00 08 00 # call read +3C 00 # cmp al, 0 +74 23 # je build_finished + +#:check_src_command +3C 73 # cmp al, 's' +75 09 # jne check_hex0_command + +#:handle_src_command +9A 29 86 00 00 08 00 # call src +EB E8 # jmp process_command + +#:check_hex0_command +3C 68 # cmp al, 'h' +75 09 # jne call_handle_other_command + +#:handle_hex0_command +9A E6 86 00 00 08 00 # call hex0 +EB DB # jmp process_command + +#:call_handle_other_command +9A FA 87 00 00 08 00 # call handle_other_command +EB D2 # jmp process_command + +#:build_finished +BE 72 88 00 00 # mov esi, str_build_finished +9A 8F 7E 00 00 08 00 # call console_puts + +# copy memory file /dev/hda to the boot disk +BB 98 88 00 00 # mov ebx, str_dev_hda +9A 13 81 00 00 08 00 # call find_file +83 f8 ff # cmp eax, -1 +75 17 # jne ok_exit + +#:error_exit +BE 82 88 00 00 # mov esi, str_error_no_write +9A 8F 7E 00 00 08 00 # call console_puts + +# one space to flush last line +B0 20 # mov al, 20 +9A 6F 7E 00 00 08 00 # call console_putc +EB 62 # jmp shell_reboot + +#:ok_exit +# get file address to read +C1 E0 04 # shl eax, 04 +05 00 00 00 01 # add eax, 0x01000000 +8B 70 04 # mov esi, [eax+4] ; file_address +8B 58 08 # mov ebx, [eax+8] ; bytes_to_write = file_length + +# print length +89 D8 # mov eax, ebx +B9 04 00 00 00 # mov ecx, 4 +#:shift_loop +C1 C8 18 # ror eax, 24 +9A 7F 7E 00 00 08 00 # call console_put_hex +49 # dec ecx +75 F3 # jnz shift_loop +B0 0A # mov al, 0A +9A 6F 7E 00 00 08 00 # call console_putc + +# set starting disk location to write +31 C9 # xor ecx, ecx +41 # inc ecx +B6 00 # mov dh, 0 + +#:sector_loop +# copy 512 bytes from file to 16 bit buffer +51 # push ecx ; save disk location +BF 00 A0 00 00 # mov edi, 0x000A000 +B9 00 02 00 00 # mov ecx, 0x200 +F3 A4 # rep movsb +59 # pop ecx + +# now write from 16 bit buffer +56 # push esi ; save our location in the file +BE 00 A0 00 00 # mov esi, 0x000A000 +B8 01 00 00 00 # mov eax, 0x0001 ; num_sectors = 1 +9A BD 7E 00 00 08 00 # call write_sectors +5E # pop esi +81 EB 00 02 00 00 # sub ebx, 0x200 ; bytes_to_write -= 512 +7F D7 # jg sector_loop + +B0 20 # mov al, 20 +9A 6F 7E 00 00 08 00 # call console_putc + +#:shell_reboot +EA CD 7E 00 00 08 00 # jmp reboot + +# sector padding +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 diff --git a/parts.rst b/parts.rst index 0b99170..fd7cf16 100644 --- a/parts.rst +++ b/parts.rst @@ -7,6 +7,7 @@ .. SPDX-License-Identifier: CC-BY-SA-4.0 + bootstrap-seeds =============== @@ -14,7 +15,10 @@ This is where it all begins. We start with the two raw binary seeds ``hex0-seed` First, we use those seeds to rebuild themselves. -Note that all early steps before ``mes`` are part of `stage0-posix `_. +Note that all early compilers before ``mes`` are part of `stage0-posix `_. + +A kernel bootstrapping option is used by default at the beginning. ``hex0-seed`` can be used to compile the ``builder-hex0`` kernel which has its own built-in shell, the ``hex0`` compiler and the ``src`` tool to load files into its file system. ``builder-hex0`` runs stage0-posix and then builds ``mes`` and ``tcc``. It then builds and launches the `Fiwix ` kernel which runs the build until Linux takes over. + hex0 ==== @@ -34,6 +38,12 @@ In the first steps we use initial ``hex0`` binary seed to rebuild ``kaem-optiona ``hex0`` can be approximated with: ``sed 's/[;#].*$//g' $input_file | xxd -r -p > $output_file`` + +builder-hex0 +============ +By default (when kernel bootstrap is enabled), the ``builder-hex0`` kernel boots from a hard drive and loads an enormous shell script which embeds files (loaded with the ``src`` command) and the initial commands to build ``hex0-seed``, ``kaem-optional-seed``, and the command which launches stage0-posix using ``kaem-optional-seed`` and the stage0-posix launch script ``kaem.x86``. Builder-hex0 is written in hex0 and can be compiled with any one of ``hex0-seed``, ``sed``, the tiny ``builder-hex0-mini`` boot kernel or it can build itself. + + kaem-optional ============= @@ -189,6 +199,29 @@ using older versions compilable by tinycc. Prior to this point, all tools have been adapted significantly for the bootstrap; now, we will be using old tooling instead. +fiwix 1.4.0-lb1 +=============== + +If the kernel bootstrap option is enabled then the Fiwix kernel is built next. +This is a Linux 2.0 clone which is much simpler to understand and build than +Linux. This version of Fiwix is a fork of 1.4.0 that contains many +modifications and enhancements to support live-boostrap. + +lwext4 1.0.0 +============ + +If the kernel bootstrap option is enabled then `lwext4 ` +is built next. This is a library for creating ext2/3/4 file systems from user land. +This is combined with a program called ``make_fiwix_initrd.c`` which creates +and populates an ext2 files system which Fiwix uses for an initial ram drive (initrd). +This file system contains all of the files necessary to build Linux. + +kexec-fiwix +=========== + +If the kernel bootstrap option is enabled then a C program `kexec-fiwix` is compiled +and run which places the Fiwix ram drive in memory and launches the Fiwix kernel. + make 3.82 ========= @@ -597,6 +630,7 @@ musl 1.2.3 GCC can build the latest as of the time of writing musl version. We also don't need any of the TCC patches that we used before. +To accomodate Fiwix, there are patches to avoid syscalls set_thread_area and clone. gcc 4.0.4 ========= @@ -652,6 +686,11 @@ The next step is not a package, but the creation of the sysb rootfs, containing all of the scripts for sysb (which merely move to sysc). Again, this is only done in non-chroot mode, because sysb does not exist in chroot mode. +musl 1.2.3 +========== +Prior to building and booting Linux, musl is rebuilt yet again with syscalls +``clone`` and ``set_thread_area`` enabled for Linux thread support. + Linux kernel 4.9.10 =================== @@ -702,6 +741,16 @@ and is built with GNU readline support so it can be used as a fully-featured interactive shell. ``autoconf-2.69`` is used to regenerate the configure script and ``bison`` is used to recreate some included generated files. +curl 7.83.0 +=========== + +curl is built in sysc because Linux must be running with support for threads +(which is not the case if kernel bootstrapping is being used). curl requires +musl 1.2.3 with thread support, which was built at the end of sysa. +curl is built first in sysc so the rest of the packages can be downloaded. +Note that the tar file for curl itself was copied over from sysa because +curl is not yet available to download it. + xz 5.4.1 ======== diff --git a/rootfs.py b/rootfs.py index 8816b40..1321c34 100755 --- a/rootfs.py +++ b/rootfs.py @@ -34,6 +34,10 @@ def create_configuration_file(args): config.write("CHROOT_ONLY_SYSA=" + str(args.bwrap) + "\n") config.write("UPDATE_CHECKSUMS=" + str(args.update_checksums) + "\n") config.write("DISK=sda1\n") + if (args.bare_metal or args.qemu) and not args.kernel: + config.write("KERNEL_BOOTSTRAP=True\n") + else: + config.write("KERNEL_BOOTSTRAP=False\n") # pylint: disable=too-many-statements def main(): @@ -81,8 +85,7 @@ def main(): default="qemu-system-x86_64") parser.add_argument("-qr", "--qemu-ram", help="Memory (in megabytes) allocated to QEMU VM", default=4096) - parser.add_argument("-qk", "--kernel", help="Kernel to use (default is ./kernel)", - default="kernel") + parser.add_argument("-qk", "--kernel", help="Custom sysa kernel to use") parser.add_argument("-b", "--bare-metal", help="Build images for bare metal", action="store_true") @@ -199,27 +202,42 @@ print(shutil.which('chroot')) '/init') elif args.bare_metal: - system_c.prepare(create_disk_image=True) - system_a.prepare(create_initramfs=True) - - print("Please:") - print(" 1. Take tmp/sysa/initramfs and your kernel, boot using this.") - print(" 2. Take tmp/sysc/disk.img and put this on a writable storage medium.") + if args.kernel: + system_c.prepare(create_disk_image=True) + system_a.prepare(create_initramfs=True) + print("Please:") + print(" 1. Take tmp/sysa/initramfs and your kernel, boot using this.") + print(" 2. Take tmp/sysc/disk.img and put this on a writable storage medium.") + else: + system_a.prepare(create_initramfs=True, kernel_bootstrap=True) + print("Please:") + print(" 1. Take tmp/sysa/sysa.img and write it to a boot drive and then boot it.") else: - system_c.prepare(create_disk_image=True) - system_a.prepare(create_initramfs=True) + if args.kernel: + system_c.prepare(create_disk_image=True) + system_a.prepare(create_initramfs=True) - run(args.qemu_cmd, - '-enable-kvm', - '-m', str(args.qemu_ram) + 'M', - '-no-reboot', - '-hda', tmpdir.get_disk("sysc"), - '-nic', 'user,ipv6=off,model=e1000', - '-kernel', args.kernel, - '-initrd', system_a.initramfs_path, - '-nographic', - '-append', 'console=ttyS0') + run(args.qemu_cmd, + '-enable-kvm', + '-m', str(args.qemu_ram) + 'M', + '-no-reboot', + '-hda', tmpdir.get_disk("sysc"), + '-nic', 'user,ipv6=off,model=e1000', + '-kernel', args.kernel, + '-initrd', system_a.initramfs_path, + '-nographic', + '-append', 'console=ttyS0') + else: + system_a.prepare(create_initramfs=True, kernel_bootstrap=True) + run(args.qemu_cmd, + '-enable-kvm', + '-m', "4G", + '-no-reboot', + '-drive', 'file=' + os.path.join(system_a.tmp_dir, 'sysa.img') + ',format=raw', + '-machine', 'kernel-irqchip=split', + '-nic', 'user,ipv6=off,model=e1000', + '-nographic') if __name__ == "__main__": main() diff --git a/sysa.py b/sysa.py index e495f2a..ef0d1e6 100755 --- a/sysa.py +++ b/sysa.py @@ -13,6 +13,7 @@ import shutil import tarfile from lib.sysgeneral import SysGeneral, stage0_arch_map +from lib.utils import run # pylint: disable=consider-using-with # pylint: disable=too-many-instance-attributes @@ -37,7 +38,7 @@ class SysA(SysGeneral): self.tmp_dir = tmpdir.add_sys("sysa") - def prepare(self, create_initramfs): + def prepare(self, create_initramfs, kernel_bootstrap=False): """ Prepare directory structure for System A. We create an empty tmp directory, unpack stage0-posix. @@ -59,6 +60,11 @@ class SysA(SysGeneral): self.sysc(create_initramfs) + if kernel_bootstrap: + self.create_fiwix_file_list() + self.create_builder_hex0_disk_image(os.path.join(self.tmp_dir, 'sysa.img')) + return + if self.repo_path: repo_dir = os.path.join(self.tmp_dir, 'usr', 'src', 'repo-preseeded') shutil.copytree(self.repo_path, repo_dir) @@ -101,3 +107,112 @@ class SysA(SysGeneral): # stage0-posix hook to continue running live-bootstrap shutil.copy2(os.path.join(self.sys_dir, 'after.kaem'), os.path.join(self.tmp_dir, 'after.kaem')) + + def add_fiwix_files(self, file_list_path, dirpath): + """Add files to the list to populate Fiwix file system""" + for root, _, filepaths in os.walk(dirpath): + if 'stage0-posix' in root: + continue + with open(file_list_path, 'a', encoding="utf-8") as file_list: + for filepath in filepaths: + file_list.write(f"/{os.path.join(root, filepath)}\n") + + def create_fiwix_file_list(self): + """Create a list of files to populate Fiwix file system""" + file_list_path = os.path.join(self.tmp_dir, 'sysa', 'lwext4-1.0.0-lb1', + 'files', 'fiwix-file-list.txt') + shutil.copyfile(os.path.join(self.tmp_dir, 'sysa', 'lwext4-1.0.0-lb1', + 'files', 'early-artifacts-needed-after-fiwix.txt'), + file_list_path) + + save_cwd = os.getcwd() + self.add_fiwix_files(file_list_path, 'sysa') + self.add_fiwix_files(file_list_path, 'sysb') + self.add_fiwix_files(file_list_path, 'sysc') + os.chdir(save_cwd) + + @staticmethod + def output_dir(srcfs_file, dirpath): + """Add a directory to srcfs file system""" + srcline = f"src 0 {dirpath}\n" + srcfs_file.write(srcline.encode()) + + @staticmethod + def output_file(srcfs_file, filepath): + """Add a file to srcfs file system""" + srcline = f"src {os.path.getsize(filepath)} {filepath}\n" + srcfs_file.write(srcline.encode()) + with open(filepath, 'rb') as srcfile: + srcfs_file.write(srcfile.read()) + + def output_tree(self, srcfs_file, treepath): + """Add a tree of files to srcfs file system""" + self.output_dir(srcfs_file, treepath) + for root, dirs, files in os.walk(treepath): + if ".git" in root: + continue + for dirpath in dirs: + if ".git" in dirpath: + continue + self.output_dir(srcfs_file, os.path.join(root, dirpath)) + + for filepath in files: + if ".git" in filepath: + continue + self.output_file(srcfs_file, os.path.join(root, filepath)) + + def append_srcfs(self, image_file): + """Append srcfs file system to sysa disk image""" + save_cwd = os.getcwd() + + os.chdir(os.path.join(self.tmp_dir, 'sysa', 'stage0-posix', 'src')) + self.output_tree(image_file, '.') + + os.chdir(self.tmp_dir) + shutil.move(os.path.join('sysa', 'stage0-posix'), '.') + self.output_tree(image_file, 'sysa') + self.output_tree(image_file, 'sysb') + self.output_tree(image_file, 'sysc') + shutil.move('stage0-posix', 'sysa') + shutil.copyfile(os.path.join('sysa', 'after.kaem'), 'after.kaem') + self.output_file(image_file, 'after.kaem') + + # Add commands to kick off stage0-posix + cmd = ' '.join(['hex0', + './bootstrap-seeds/POSIX/x86/hex0_x86.hex0' + './bootstrap-seeds/POSIX/x86/hex0-seed\n']) + image_file.write(cmd.encode()) + cmd = ' '.join(['hex0', + './bootstrap-seeds/POSIX/x86/kaem-minimal.hex0', + './bootstrap-seeds/POSIX/x86/kaem-optional-seed\n']) + image_file.write(cmd.encode()) + cmd = ' '.join(['./bootstrap-seeds/POSIX/x86/kaem-optional-seed', './kaem.x86\n']) + image_file.write(cmd.encode()) + + os.chdir(save_cwd) + + def create_builder_hex0_disk_image(self, image_file_name): + """Create builder-hex0 disk image""" + run(os.path.join('sysa', 'stage0-posix', 'src', + 'bootstrap-seeds', 'POSIX', 'x86', 'hex0-seed'), + os.path.join('kernel-bootstrap', 'builder-hex0-x86.hex0'), + image_file_name) + + with open(image_file_name, 'ab') as image_file: + self.append_srcfs(image_file) + + current_size = os.stat(image_file_name).st_size + + megabyte = 1024 * 1024 + # fill file with zeros up to next megabyte + extra = current_size % megabyte + round_up = megabyte - extra + with open(image_file_name, 'ab') as image_file: + image_file.write(b'\0' * round_up) + current_size += round_up + + # fill file with zeros up to desired size, one megabyte at a time + with open(image_file_name, 'ab') as image_file: + while current_size < 1008 * megabyte: + image_file.write(b'\0' * megabyte) + current_size += megabyte diff --git a/sysa/SHA256SUMS.pkgs b/sysa/SHA256SUMS.pkgs index 1889f38..6b41e55 100644 --- a/sysa/SHA256SUMS.pkgs +++ b/sysa/SHA256SUMS.pkgs @@ -20,48 +20,47 @@ ef08694bf8e78ffcf56f9c8a63b0f189e301c06f02ab240e15e4c7fe354c2a0d automake-1.7_0 e8ff13753943e43972a8cf1672819f001718ed38e5497cf7b554c21a507ba22b automake-1.7.8_0.tar.bz2 9922651b64ad2e29b944082f26db223008220155048f25d64df1f6d82071ff1c automake-1.8.5_0.tar.bz2 c5807850a377e4bb9aa4121d9781d145bdd80327626a9419630a75ce2c8d9c71 automake-1.9.6_0.tar.bz2 -8bc756e8212ce6fad575f0863ff0bc7f5f125c63affc6d4a6e8d9b841259ff89 bash-2.05b_0.tar.bz2 46282b2a7c2e3d50bac2d3f90fee56629c4a533a962ad61eabac6395a3b676db bash-5.2.15_0.tar.bz2 -438f0b623af8d7a558696d47554554d3a6c9e9a655569d059bfd1e679723d037 bc-1.07.1_0.tar.bz2 -25fc6ea74005ae5677ea790e228a710fb82a80d9a7a56b5a8ddc5789aff4e209 binutils-2.30_0.tar.bz2 +05bcb569640576e53e40c2bfbeea988fd4fc4e0b5b1311668eabd5cdaacd6657 bc-1.07.1_0.tar.bz2 +7b8ea17311f22e987a39b814658c72b46201650c4dfbc707e8fd9eb42bf1ed28 binutils-2.30_0.tar.bz2 a21157791cb5e7ec941de09f275286d90efe1b463dc4302b238af9ba53fae49e binutils-2.38_0.tar.bz2 2e2102a9a41f3ad35683e67f6f9cc09e4edad25b7acb1ae0ca3ad94e19fbbdaf bison-2.3_0.tar.bz2 -b2e45aec68221e6874ea8aa7d5b6a0aab7879a3dbee493536e034b246a884b05 bison-3.4.1_0.tar.bz2 -4b2fa2ddde419e9cc47f68e4aad4e4bd403570664c02a7d0d488417baecafd03 bison-3.4.1_1.tar.bz2 -6a6111b1e8ca906406482053cf0af8c9dea46dc55e4bac9662c8fe47f94221cb bison-3.4.1_2.tar.bz2 +df9539b52384757d927bca5a27b1b58325b6024b23b0470e557f135eb69bae30 bison-3.4.1_0.tar.bz2 +fed9e13409f6378f97e8cef61e6faac992f3b767dfdac22f32453ff57cf29e7b bison-3.4.1_1.tar.bz2 +44d143d9dcb4098138a8b8eee0e29de1c7e282b9582df153f75ae301336c0927 bison-3.4.1_2.tar.bz2 e38ed21c4b4fa514e9a64d2b84bad72f3d242568183b6b84a6a2d0e8c49d0af2 bison-3.4.2_0.tar.bz2 -c6369fcf4ba1fae200a4a67f110563a11d6c51fa8ca80792dbc4630e3dba6f4d bzip2-1.0.8_0.tar.bz2 +80e541fc4d3dfce4451318f26c31ccfe580848139672bd437131cdfd5e3664b2 bzip2-1.0.8_0.tar.bz2 c511d571d24675a141258e0e198c5ed1bcfd4889ddd736ff8e25c0d97b44e2cf ca-certificates-3.88.1_0.tar.bz2 -0d02d37d02d6def11b5f12eab5d97f47dc1e4abd53627deb2d99994e1ab9c6a8 coreutils-5.0_0.tar.bz2 -27d0d3e84794f080f01c7c22547a308d1d781d8ce85d5b3f682c379f17bbeb47 coreutils-6.10_0.tar.bz2 +acd3ba50a33ea0172c3ca59e341a48e4233be48ded26fa031fd2e9417a2dfb31 coreutils-5.0_0.tar.bz2 +09092e187588c5d33c023ac41671b367aef9f7ee967d2c7c03430b33cc03f251 coreutils-6.10_0.tar.bz2 e41aba2caa7514704731d3b7a49f63ff8ffb2d22a64f14afdbaadbd0b24073f0 coreutils-8.32_0.tar.bz2 8df7fe3124243028cc9fd9a00fe8ab55c2143a9b7551426447867d2e1de436b6 curl-7.88.1_0.tar.bz2 d7d0a5fc9117f9b3ebd287851a48716c96a3c11991365edb8890f0e203d3b810 curl-7.88.1_1.tar.bz2 -0b832d3efef962c10b61559052373267e9c85bbff37572b736a6996823e2d5b2 dhcpcd-9.4.1_0.tar.bz2 -f1a17f3d1c65140a6d3043ecb710e5fffe9c019cb3d2eaa982be03706876e534 diffutils-2.7_0.tar.bz2 +ddb6a5292b15cc8925fe3f42ff44e3f2b5bda20a08159c4b3f4ea81730e40178 dhcpcd-9.4.1_0.tar.bz2 +c4008ae6b168aee4120b0f3624a1875f9e413d8f0c637708b8b04a1fb5be173c diffutils-2.7_0.tar.bz2 bda6afcd3a390a34a57443269a4857ccc470129f7a557981778c145fd841cbd1 dist-3.5-236_0.tar.bz2 -47b1954e16d4cafd6ecb3b5751ff3716677c4f509618973d8a2aa0b4126bfd0a e2fsprogs-1.45.7_0.tar.bz2 -a5695b0014c0f0fa8a1cb6ff85b14e578664d8d0da949007dc77fd0243755ec6 ed-1.4_0.tar.bz2 +c0514138e251062c9ac2ff1e432e01a541777bfd61480c77479ea55f5b75cdd1 e2fsprogs-1.45.7_0.tar.bz2 +d7b7453ad400eac1ba39f99971afdc392cb8a92c557ef5d6fd9fa2625124de4a ed-1.4_0.tar.bz2 258282c136145d8fba4d66f7e150800e7ca33e024483083a15d0dba3aeb5e86b file-5.44_0.tar.bz2 -8a0405a66c09c6e1647078c919ae54948f069632214c8430af7adbdb176f62e2 findutils-4.2.33_0.tar.bz2 +5984d3f2d5513dd04dc97619e2809d634fc7e3692f36f770e0202a61b6b2921d findutils-4.2.33_0.tar.bz2 3c85ce52e37c313d699a21cc741d24e808048461b105f58445a645a54ea55436 flex-2.5.11_0.tar.bz2 88d5e3cc92eaeb21f62635d2ca8bfa116d1ccc4067a782b0c3a45488125b358a flex-2.5.33_0.tar.bz2 -3ad2660bff8b84ddb47cc5f9f57f10a7370fab1e1b7f94e8e36d472a4783871c flex-2.6.4_0.tar.bz2 -6e04827921b5f23de5c4d9367509b5644af0162189f007094447bc5f527b17c4 gawk-3.0.4_0.tar.bz2 +408131b1c033a5f8a6845997b049784be0b466cec107a71270e5a04dae2c1e6c flex-2.6.4_0.tar.bz2 +5ff7fbe16b55563719b108260bd6a34ebabab0465d758ca98cba522932532e45 gawk-3.0.4_0.tar.bz2 6de1c1380026ef9948387e665610185b6014f47a80453177a6c81898c95cbbd3 gc-8.0.4_0.tar.bz2 4ed230542823160a4b1a469847cc2cc0ae1985611f2e1b831e13f2a3a7122efb gcc-10.4.0_0.tar.bz2 -72b5ba8ce1f20f0e94a852b04dba147ff2e6232de75628338bc90fea89eaa492 gcc-4.0.4_0.tar.bz2 -bcc8a0549af3542b23005ea666c721a8449007b6b3954abf3eb07dad5a221e76 gcc-4.0.4_1.tar.bz2 +b09580c3972ff4e5f6e624bdc83d5328ce017422e0b92a7c170b51b6f04a47d2 gcc-4.0.4_0.tar.bz2 +58d0d431bb2e96a273965b5e7aa760fb6961a7f7f2fd98ef5fc5a6b7b44bc989 gcc-4.0.4_1.tar.bz2 a2301d8dbbfbfcdd18444f01848e8e4366780281009640acbd3af0fab9b11aea gcc-4.7.4_0.tar.bz2 36610ec18a01c43b5fa9dc032c7c66fc5a812fbc85f48e86b96b67ffd11b7cb5 gettext-0.21_0.tar.bz2 5a98486bccf976d9077f52ce56ab6a1db94d2888d17fdb87ba81ad2140f206f6 gmp-6.2.1_0.tar.bz2 db3f8088a8aa74a7ff300b45c2070397ed7538fe5cc45480ea968014ccf7bc20 gperf-3.1_0.tar.bz2 -c963b667dd0ac1e8cef4b2525fcd5d53237d83d16b6f70855c199472a0dc419f grep-2.4_0.tar.bz2 +67d706423e079a9cd764fd9607027d296c0ff2380c1104006a2230a299eb2c1d grep-2.4_0.tar.bz2 d85cff8f9ff76533287891ec2019416fa585815e514743e5b76efd9f17f5ef5c grep-3.7_0.tar.bz2 adcd3633d004a608cb36e306dd887d96e2ab77bfc5d5b4d6fa93ccc871ae2285 guile-3.0.7_0.tar.bz2 911d2f496ce02e8b95e0f3bf6eb94460b4b083dd13601f81d45f68b896ac9ef4 help2man-1.36.4_0.tar.bz2 -e7f9cecc03f7746b67a74de6ce15f83628dcd08e7896ffbb707990cc575f6c7e kbd-1.15_0.tar.bz2 -bc92c7cc72df7dc5190cbce3439be3ec10f461f9f85d9b0283428e467fa43e7c kexec-tools-2.0.22_0.tar.bz2 +3f06d1a7f1b1770d4550ff6316c7f06fd26e30bddad7c1b665f1fae80e409c8c kbd-1.15_0.tar.bz2 +2a661da13801028f5af98e5d9f6de417c21c90df1bcef4809caf0c2094fdd8f4 kexec-tools-2.0.22_0.tar.bz2 e89e4fc8ba4f917f4f609ba781fc13e43d31479d47a9da2ba3bc7ce5fcbbe6b3 libarchive-3.5.2_0.tar.bz2 36550df491767bb24d2ccab304ce70a3b4956e7c0c0e0c343d922fd57cdafbdd libatomic_ops-7.6.10_0.tar.bz2 b39826742e236890f3562cdf19492e7ef4224b271f3e75ddeab1f07982b03ebe libffi-3.3_0.tar.bz2 @@ -70,46 +69,47 @@ f255cfb75f1764460e60febccfa70fa20bc2ebb7f8ad2629be21fc188fb6dbcd libtool-2.4.7_ 503007bbcddcf4e49d26514c59b4c9501f8b42f0c994a59dfdc388b1ae6b7900 libunistring-0.9.10_0.tar.bz2 1d07aaf7049be45853fd409340cdb52bb3a1b6dfa4dbc8b69358c1ee966cd67f linux-4.9.10_0.tar.bz2 2fd5bec0c086cb89596f14894cbf078b3d1e990d297ba02b6cc4135e7d64996b linux-headers-5.10.41_0.tar.bz2 -a8e75e491322f09b90e0685b9468c589ec38a52529c362e14516cb32e5e57fe3 m4-1.4.7_0.tar.bz2 -128c5247064a9677d1037113707d8d4c92cea51ab21058a1f85c6df566e22162 make-3.82_0.tar.bz2 +3864f2c66516fc4f5086f626f4da2b2a7635e21babca86ba478f866920868e2b m4-1.4.7_0.tar.bz2 +680672991ee527836237c98cb218c050cce73af4aa0a2f35eed72cb9e3b4931b make-3.82_0.tar.bz2 7f08b1f57f55f4a2898454c27538e54902b82f3e8ce7cdbeba824211004f067a make-4.2.1_0.tar.bz2 17cd976bc0f6e897c6fffe43dd7c55d93ce0adadf1b4dc72925b80e2d266519f mpc-1.2.1_0.tar.bz2 6ddf27c49c59e241ad3dadbb5d7ef94b8c24e6de7b9f8717d5643352e46233e2 mpfr-4.1.0_0.tar.bz2 -d06f045be683f7a2cdc3eb79592f75517100d0bcda4fe7924200c065ff52c9f5 musl-1.1.24_0.tar.bz2 -280b05d6c2f7458cf3bde6985c3b2f876e9c361943b0ba3044e389e033d97622 musl-1.1.24_1.tar.bz2 -a12d2442623de67e837c5f42f44bea8e15ecb534d1f23efa182c3603795515d3 musl-1.1.24_2.tar.bz2 -054c6a5f1c07d124b701e590267aa8fb2ba1c88bed9a69a473724f8534cdb728 musl-1.2.3_0.tar.bz2 -3260f0c8bfa1160a2f252c6e0d3ca5f98635ec8f9d9f211a30ef1a0313cac853 musl-1.2.3_1.tar.bz2 +a724c91a43e282c3d338a977e4eeac3b970df241db7872f9d5cf27984b609814 musl-1.1.24_0.tar.bz2 +2a03a3707593997a0e03ce3aa6b2ee647cf2e5bfe1deb028357a2dfab56e33e2 musl-1.1.24_1.tar.bz2 +b79e0f8a39ba8880d43aa27551b72915655c62af39125e1f4ac8f8e69e71aaca musl-1.1.24_2.tar.bz2 +a675ead0f146a96973fca9cc9e4f16081b14c26630ae17405e3ba5e9510ff30d musl-1.2.3_0.tar.bz2 +054c6a5f1c07d124b701e590267aa8fb2ba1c88bed9a69a473724f8534cdb728 musl-1.2.3_1.tar.bz2 +3260f0c8bfa1160a2f252c6e0d3ca5f98635ec8f9d9f211a30ef1a0313cac853 musl-1.2.3_2.tar.bz2 e0c91898e771c65e6a462600243a7858b069db5726680193f86d7dbac3f740ae openssl-1.1.1l_0.tar.bz2 69daf6ffbf26fea500426c6936e5a16e82833f03ad0dc6109697f69a8516b4c7 patch-2.7.6_0.tar.bz2 -8edc149d22a1202938c8ed2c46488115a422fbc44ddfe606727fbe4d362fb07b perl-5.000_0.tar.bz2 -85653922ee1fd39ef6e8ba6f3720d51c9585800767163f4f502296f4a39f4474 perl-5.003_0.tar.bz2 -9bba76361c28da9a0c19054ccaf8432bbf7ce779584151600ad90c439f0baef5 perl5.004-05_0.tar.bz2 -8efe3102f341c232510e6e24ab51337f15a9d1b3a344962f85131fe31bc50516 perl5.005-03_0.tar.bz2 +914a7abf36a64723b6e9f9b0b6ccd19c8e544fa798896a2bb1151dc341890c22 perl-5.000_0.tar.bz2 +887d835562d471653bcda60e652fceb4b3ef58a83321a4eb5af0431dc182781b perl-5.003_0.tar.bz2 +b86fc586d72a6d204d0b9017afe17aa2439529e13f43befc56648b78de17c8f8 perl5.004-05_0.tar.bz2 +451ae6bb6e996a1c857fe92ec379654413fadec180c6477cf5fd4b5d7a079e26 perl5.005-03_0.tar.bz2 a2e1f93eeaa3985c660cc73645930489bad6d68011e4ae6892c6b09c8f02395b perl-5.10.1_0.tar.bz2 8f2730b029a4e62792460ea0448b8f1806d15e5175f3004b31b153d16cb7f4d1 perl-5.32.1_0.tar.bz2 -89ae6fb13483b93623aa42f678eee076b42d9a6e2a80147a14e20807b097f940 perl-5.6.2_0.tar.bz2 +9fa8850897248d77d554caa2b3d52e7890308cbf28750ffc24c09f498aee563c perl-5.6.2_0.tar.bz2 d0c03003eaf21045e13afd2551df952a568e97cea91dec7edb0b829016d434b4 pkg-config-0.29.2_0.tar.bz2 bbe7955df4eec1e4c21ae397545943abc0ef55d1b136d6f30f1550f82cf0cb22 python-2.0.1_0.tar.bz2 281cc79f24007f4667ae5914f89c671be3b2d008fb5296d66b65314d30a7e768 python-2.0.1_1.tar.bz2 66f1571ecc2f00cee322e419f0d53127b2465330bbd8fe01d2fe0af91b9084fc python-2.3.7_0.tar.bz2 7c65497273651adda57d156f7380f07bbeb73dfa96fd6432ed0e3b82a44b7d65 python-2.3.7_1.tar.bz2 203119d5d6bc56f9253abbf6583c9a8bccd00e7b34d2a126b7f4c61294abb0d5 python-2.5.6_0.tar.bz2 -b899fc076277a90eea8d3ffa1fa79d9715d70d51aac85c0f00bfe267e143bbed python-3.11.1_0.tar.bz2 +284ef5e0c44e5e3f2a2e6c3a9dd55ad26a200d6701279383cdbaca0fb2dc831b python-3.11.1_0.tar.bz2 b8e03286ff4aae2a47e61dd7a11d4b272717a181cbcfa8da3fee91e67c007f94 python-3.1.5_0.tar.bz2 4857037c9db993f8feef1de8e4918692a066771713aa25b66e69392b987a0122 python-3.1.5_1.tar.bz2 8bcf91d546333a2af3bfef23aeb0f3e98979715100b48a7c373cd2f22ebb6fb9 python-3.3.7_0.tar.bz2 4568978b5bc0cb501ff6ef5c632c0018ca0c1ed6361b8d18c2fd8bf3d03fc62e python-3.4.10_0.tar.bz2 -a915b7f56d80c1e96f963c49f2e4bba1759124e4974e6415f4784933622f4855 python-3.8.16_0.tar.bz2 -e1eb72972dc5eb4bd0fd1fc6a477026440dd292b71f4ef0052f59d89869ab3e3 sed-4.0.9_0.tar.bz2 +f19dceb161ed1d1d7cdad8ef54d2688a022ab6e26fe73e66d52b2dc362acb3c5 python-3.8.16_0.tar.bz2 +6081832f1fc258df7dd927986821991b49fa78a71b76f4b37b5c34a8ebc9bc86 sed-4.0.9_0.tar.bz2 b3dfb430d6657233cd129c9838c2ab0de3cb02762b15a448b1a82d42fb69ffc5 sed-4.8_0.tar.bz2 edcb2a8665c58c08ca90f4e612c6931fd7a6dc95b3d6f38d1d08c1971d29773c tar-1.34_0.tar.bz2 a07edeebe88d27afe01ae4b9c2fec7d26f54d87928976927f73d9dba5f50782b tcc-0.9.27_0.tar.bz2 -6d2b9b7d7970ab06b56ec59785b7c7246ea1da4835893fa7aa0e80eebefe57ff tcc-0.9.27_1.tar.bz2 -afe30ba8abf45ac3605c09df93ec3b2fec29c242bf5193a2086ef32340c6ebc6 tcc-0.9.27_2.tar.bz2 -90ccfdd7d8ff855183cd873af027262b525c63c65b438e49deeb9e84bef1542c tcc-0.9.27_3.tar.bz2 +41a4b0fbf461dd26ecd31d77b300c979a4decae185c9e2d50c0470bc49d0b893 tcc-0.9.27_1.tar.bz2 +cbfc578c709f677ec3e9792a8620e4e2a88d13d93969fd54aac93e4a29c2604d tcc-0.9.27_2.tar.bz2 +2b503cd31d3326ac1ed0eb9f506ac93c93770da51164e152a812cd248961069c tcc-0.9.27_3.tar.bz2 ff1ccbe06d00d4c16f76640372e5370b6cf87fc5b9ea4f180c988188a3becc0b texinfo-6.7_0.tar.bz2 -11d471567f28e9ef67d9381246f0684d21ab33d27ea2e0d721c82c469f5f2f8b util-linux-2.19.1_0.tar.bz2 +8e5d7ab54f224da30414fc8b53b47003f16a0cfe24850494ff02f25b4dea29ab util-linux-2.19.1_0.tar.bz2 c992ffabed4278588590352c824df2018e6a4492ca83865eba560692765fde11 which-2.21_0.tar.bz2 5ebfb0894b25606432d120eefabe5335abcbf123bbad23fb11871b74acd6a7e5 xz-5.4.1_0.tar.bz2 195c26bb0642eb146c6f113fe3dbbe516a35a514aee7d2fe4bcd15addf1b0f43 zlib-1.2.13_0.tar.bz2 diff --git a/sysa/after2.kaem b/sysa/after2.kaem new file mode 100644 index 0000000..da0a083 --- /dev/null +++ b/sysa/after2.kaem @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT + +prefix=/usr +bindir=${prefix}/bin + +PATH=${bindir} + +cd sysa + +catm run2-after-fiwix.kaem bootstrap.cfg run-after-fiwix.kaem +chmod 755 run2-after-fiwix.kaem + +kaem --file run2-after-fiwix.kaem diff --git a/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.checksums b/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.checksums new file mode 100644 index 0000000..a574f7d --- /dev/null +++ b/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.checksums @@ -0,0 +1 @@ +dd9e799311b3c505fa8efe045b969b851c60499ab41db546e5c8b545b3e19ec8 /boot/fiwix diff --git a/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem b/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem new file mode 100755 index 0000000..35724b4 --- /dev/null +++ b/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem @@ -0,0 +1,556 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT + +set -ex + +# Check tarball checksums +checksum-transcriber sources +sha256sum -c sources.SHA256SUM + +# Extract +mkdir build src +cd src +ungz --file ${distfiles}/${pkg}.tar.gz --output ${pkg}.tar +cd .. + +cd build +untar --file ../src/${pkg}.tar +cd ${pkg} + +alias as="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DNR_PROCS=4096 -DCHILD_MAX=4096 -DOPEN_MAX=1536 -DNR_OPENS=1536 -DINIT_PROGRAM=\"/init\" -DUTS_SYSNAME=\"Linux\" -D__VERSION__=\"tcc\" -traditional -I/sysa/fiwix-1.4.0-lb1/build/fiwix-1.4.0-lb1/include" + +alias cc="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DNR_PROCS=4096 -DCHILD_MAX=4096 -DOPEN_MAX=1536 -DNR_OPENS=1536 -DINIT_PROGRAM=\"/init\" -DUTS_SYSNAME=\"Linux\" -D__VERSION__=\"tcc\" -I/sysa/fiwix-1.4.0-lb1/build/fiwix-1.4.0-lb1/include -O2 -fno-pie -fno-common -ffreestanding -Wall -Wstrict-prototypes" + +cd kernel +as -c -o boot.o boot.S +as -c -o core386.o core386.S +cc -c -o main.o main.c +cc -c -o init.o init.c +cc -c -o gdt.o gdt.c +cc -c -o idt.o idt.c +cc -c -o syscalls.o syscalls.c +cc -c -o pic.o pic.c +cc -c -o pit.o pit.c +cc -c -o irq.o irq.c +cc -c -o traps.o traps.c +cc -c -o cpu.o cpu.c +cc -c -o cmos.o cmos.c +cc -c -o timer.o timer.c +cc -c -o sched.o sched.c +cc -c -o sleep.o sleep.c +cc -c -o signal.o signal.c +cc -c -o process.o process.c +cc -c -o multiboot.o multiboot.c + +cd syscalls +cc -c -o umount.o umount.c +cc -c -o getgid.o getgid.c +cc -c -o getppid.o getppid.c +cc -c -o fstatfs.o fstatfs.c +cc -c -o getgroups.o getgroups.c +cc -c -o fsync.o fsync.c +cc -c -o setreuid.o setreuid.c +cc -c -o newuname.o newuname.c +cc -c -o fork.o fork.c +cc -c -o setitimer.o setitimer.c +cc -c -o fdatasync.o fdatasync.c +cc -c -o chmod.o chmod.c +cc -c -o mmap2.o mmap2.c +cc -c -o msgsnd.o msgsnd.c +cc -c -o madvise.o madvise.c +cc -c -o exit.o exit.c +cc -c -o readlink.o readlink.c +cc -c -o socketcall.o socketcall.c +cc -c -o stat64.o stat64.c +cc -c -o readv.o readv.c +cc -c -o sigaction.o sigaction.c +cc -c -o fstat.o fstat.c +cc -c -o waitpid.o waitpid.c +cc -c -o setfsgid.o setfsgid.c +cc -c -o chown.o chown.c +cc -c -o flock.o flock.c +cc -c -o uname.o uname.c +cc -c -o lseek.o lseek.c +cc -c -o setsid.o setsid.c +cc -c -o settimeofday.o settimeofday.c +cc -c -o unlink.o unlink.c +cc -c -o sigprocmask.o sigprocmask.c +cc -c -o ustat.o ustat.c +cc -c -o open.o open.c +cc -c -o sync.o sync.c +cc -c -o iopl.o iopl.c +cc -c -o msgget.o msgget.c +cc -c -o pipe.o pipe.c +cc -c -o shmdt.o shmdt.c +cc -c -o getsid.o getsid.c +cc -c -o setfsuid.o setfsuid.c +cc -c -o signal.o signal.c +cc -c -o newfstat.o newfstat.c +cc -c -o mkdir.o mkdir.c +cc -c -o getcwd.o getcwd.c +cc -c -o link.o link.c +cc -c -o msgctl.o msgctl.c +cc -c -o sethostname.o sethostname.c +cc -c -o semctl.o semctl.c +cc -c -o sysinfo.o sysinfo.c +cc -c -o setdomainname.o setdomainname.c +cc -c -o getegid.o getegid.c +cc -c -o personality.o personality.c +cc -c -o setregid.o setregid.c +cc -c -o setgid.o setgid.c +cc -c -o lstat.o lstat.c +cc -c -o getuid.o getuid.c +cc -c -o llseek.o llseek.c +cc -c -o select.o select.c +cc -c -o ftruncate.o ftruncate.c +cc -c -o getpgid.o getpgid.c +cc -c -o brk.o brk.c +cc -c -o getrusage.o getrusage.c +cc -c -o sigsuspend.o sigsuspend.c +cc -c -o writev.o writev.c +cc -c -o times.o times.c +cc -c -o ssetmask.o ssetmask.c +cc -c -o stat.o stat.c +cc -c -o fchdir.o fchdir.c +cc -c -o chdir.o chdir.c +cc -c -o setgroups.o setgroups.c +cc -c -o newstat.o newstat.c +cc -c -o creat.o creat.c +cc -c -o getdents64.o getdents64.c +cc -c -o getpid.o getpid.c +cc -c -o read.o read.c +cc -c -o dup.o dup.c +cc -c -o utimes.o utimes.c +cc -c -o semget.o semget.c +cc -c -o mount.o mount.c +cc -c -o rmdir.o rmdir.c +cc -c -o setrlimit.o setrlimit.c +cc -c -o sgetmask.o sgetmask.c +cc -c -o pause.o pause.c +cc -c -o utime.o utime.c +cc -c -o statfs.o statfs.c +cc -c -o ioperm.o ioperm.c +cc -c -o exit_group.o exit_group.c +cc -c -o ftime.o ftime.c +cc -c -o truncate.o truncate.c +cc -c -o pipe2.o pipe2.c +cc -c -o old_mmap.o old_mmap.c +cc -c -o olduname.o olduname.c +cc -c -o kill.o kill.c +cc -c -o gettimeofday.o gettimeofday.c +cc -c -o fchmod.o fchmod.c +cc -c -o fcntl64.o fcntl64.c +cc -c -o mprotect.o mprotect.c +cc -c -o getitimer.o getitimer.c +cc -c -o old_select.o old_select.c +cc -c -o symlink.o symlink.c +cc -c -o mknod.o mknod.c +cc -c -o write.o write.c +cc -c -o rename.o rename.c +cc -c -o shmat.o shmat.c +cc -c -o ipc.o ipc.c +cc -c -o lstat64.o lstat64.c +cc -c -o access.o access.c +cc -c -o getrlimit.o getrlimit.c +cc -c -o sigreturn.o sigreturn.c +cc -c -o ioctl.o ioctl.c +cc -c -o umask.o umask.c +cc -c -o geteuid.o geteuid.c +cc -c -o munmap.o munmap.c +cc -c -o alarm.o alarm.c +cc -c -o nanosleep.o nanosleep.c +cc -c -o close.o close.c +cc -c -o chroot.o chroot.c +cc -c -o ftruncate64.o ftruncate64.c +cc -c -o msgrcv.o msgrcv.c +cc -c -o umount2.o umount2.c +cc -c -o time.o time.c +cc -c -o stime.o stime.c +cc -c -o semop.o semop.c +cc -c -o newlstat.o newlstat.c +cc -c -o sigpending.o sigpending.c +cc -c -o reboot.o reboot.c +cc -c -o setuid.o setuid.c +cc -c -o wait4.o wait4.c +cc -c -o chown32.o chown32.c +cc -c -o fcntl.o fcntl.c +cc -c -o fstat64.o fstat64.c +cc -c -o shmctl.o shmctl.c +cc -c -o dup2.o dup2.c +cc -c -o setpgid.o setpgid.c +cc -c -o getdents.o getdents.c +cc -c -o getpgrp.o getpgrp.c +cc -c -o fchown.o fchown.c +cc -c -o execve.o execve.c +cc -c -o shmget.o shmget.c +cd ../.. + +cd mm +cc -c -o bios_map.o bios_map.c +cc -c -o buddy_low.o buddy_low.c +cc -c -o memory.o memory.c +cc -c -o page.o page.c +cc -c -o alloc.o alloc.c +cc -c -o fault.o fault.c +cc -c -o mmap.o mmap.c +cc -c -o swapper.o swapper.c +cd .. + +cd fs +cc -c -o filesystems.o filesystems.c +cc -c -o devices.o devices.c +cc -c -o buffer.o buffer.c +cc -c -o fd.o fd.c +cc -c -o locks.o locks.c +cc -c -o super.o super.c +cc -c -o inode.o inode.c +cc -c -o namei.o namei.c +cc -c -o elf.o elf.c +cc -c -o script.o script.c + +cd minix +cc -c -o super.o super.c +cc -c -o bitmaps.o bitmaps.c +cc -c -o inode.o inode.c +cc -c -o namei.o namei.c +cc -c -o symlink.o symlink.c +cc -c -o dir.o dir.c +cc -c -o file.o file.c +cc -c -o v1_inode.o v1_inode.c +cc -c -o v2_inode.o v2_inode.c +cd .. + +cd ext2 +cc -c -o inode.o inode.c +cc -c -o super.o super.c +cc -c -o namei.o namei.c +cc -c -o symlink.o symlink.c +cc -c -o dir.o dir.c +cc -c -o file.o file.c +cc -c -o bitmaps.o bitmaps.c +cd .. + +cd pipefs +cc -c -o super.o super.c +cc -c -o fifo.o fifo.c +cc -c -o pipe.o pipe.c +cd .. + +cd iso9660 +cc -c -o inode.o inode.c +cc -c -o super.o super.c +cc -c -o namei.o namei.c +cc -c -o dir.o dir.c +cc -c -o file.o file.c +cc -c -o rrip.o rrip.c +cc -c -o symlink.o symlink.c +cd .. + +cd procfs +cc -c -o super.o super.c +cc -c -o inode.o inode.c +cc -c -o namei.o namei.c +cc -c -o dir.o dir.c +cc -c -o file.o file.c +cc -c -o symlink.o symlink.c +cc -c -o tree.o tree.c +cc -c -o data.o data.c +cd ../.. + +cd drivers/char +cc -c -o console.o console.c +cc -c -o tty.o tty.c +cc -c -o tty_queue.o tty_queue.c +cc -c -o vt.o vt.c +cc -c -o defkeymap.o defkeymap.c +cc -c -o keyboard.o keyboard.c +cc -c -o memdev.o memdev.c +cc -c -o serial.o serial.c +cc -c -o lp.o lp.c +cc -c -o fb.o fb.c +cc -c -o sysrq.o sysrq.c +cd .. + +cd block +cc -c -o dma.o dma.c +cc -c -o floppy.o floppy.c +cc -c -o part.o part.c +cc -c -o ata.o ata.c +cc -c -o ata_hd.o ata_hd.c +cc -c -o atapi.o atapi.c +cc -c -o atapi_cd.o atapi_cd.c +cc -c -o ramdisk.o ramdisk.c +cd .. + +cd pci +cc -c -o pci.o pci.c +cd .. + +cd video +cc -c -o video.o video.c +cc -c -o vgacon.o vgacon.c +cc -c -o fbcon.o fbcon.c +cc -c -o fonts.o fonts.c +cc -c -o bga.o bga.c +cd ../.. + +cd lib +cc -c -o ctype.o ctype.c +cc -c -o strings.o strings.c +cc -c -o printk.o printk.c +cd .. + +mkdir /boot +tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \ + kernel/boot.o \ + kernel/core386.o \ + kernel/main.o kernel/init.o \ + kernel/gdt.o \ + kernel/idt.o \ + kernel/syscalls.o \ + kernel/pic.o \ + kernel/pit.o \ + kernel/irq.o \ + kernel/traps.o \ + kernel/cpu.o \ + kernel/cmos.o \ + kernel/timer.o \ + kernel/sched.o \ + kernel/sleep.o \ + kernel/signal.o \ + kernel/process.o \ + kernel/multiboot.o \ + kernel/syscalls/umount.o \ + kernel/syscalls/getgid.o \ + kernel/syscalls/getppid.o \ + kernel/syscalls/fstatfs.o \ + kernel/syscalls/getgroups.o \ + kernel/syscalls/fsync.o \ + kernel/syscalls/setreuid.o \ + kernel/syscalls/newuname.o \ + kernel/syscalls/fork.o \ + kernel/syscalls/setitimer.o \ + kernel/syscalls/fdatasync.o \ + kernel/syscalls/chmod.o \ + kernel/syscalls/mmap2.o \ + kernel/syscalls/msgsnd.o \ + kernel/syscalls/madvise.o \ + kernel/syscalls/exit.o \ + kernel/syscalls/readlink.o \ + kernel/syscalls/socketcall.o \ + kernel/syscalls/stat64.o \ + kernel/syscalls/readv.o \ + kernel/syscalls/sigaction.o \ + kernel/syscalls/fstat.o \ + kernel/syscalls/waitpid.o \ + kernel/syscalls/setfsgid.o \ + kernel/syscalls/chown.o \ + kernel/syscalls/flock.o \ + kernel/syscalls/uname.o \ + kernel/syscalls/lseek.o \ + kernel/syscalls/setsid.o \ + kernel/syscalls/settimeofday.o \ + kernel/syscalls/unlink.o \ + kernel/syscalls/sigprocmask.o \ + kernel/syscalls/ustat.o \ + kernel/syscalls/open.o \ + kernel/syscalls/sync.o \ + kernel/syscalls/iopl.o \ + kernel/syscalls/msgget.o \ + kernel/syscalls/pipe.o \ + kernel/syscalls/shmdt.o \ + kernel/syscalls/getsid.o \ + kernel/syscalls/setfsuid.o \ + kernel/syscalls/signal.o \ + kernel/syscalls/newfstat.o \ + kernel/syscalls/mkdir.o \ + kernel/syscalls/getcwd.o \ + kernel/syscalls/link.o \ + kernel/syscalls/msgctl.o \ + kernel/syscalls/sethostname.o \ + kernel/syscalls/semctl.o \ + kernel/syscalls/sysinfo.o \ + kernel/syscalls/setdomainname.o \ + kernel/syscalls/getegid.o \ + kernel/syscalls/personality.o \ + kernel/syscalls/setregid.o \ + kernel/syscalls/setgid.o \ + kernel/syscalls/lstat.o \ + kernel/syscalls/getuid.o \ + kernel/syscalls/llseek.o \ + kernel/syscalls/select.o \ + kernel/syscalls/ftruncate.o \ + kernel/syscalls/getpgid.o \ + kernel/syscalls/brk.o \ + kernel/syscalls/getrusage.o \ + kernel/syscalls/sigsuspend.o \ + kernel/syscalls/writev.o \ + kernel/syscalls/times.o \ + kernel/syscalls/ssetmask.o \ + kernel/syscalls/stat.o \ + kernel/syscalls/fchdir.o \ + kernel/syscalls/chdir.o \ + kernel/syscalls/setgroups.o \ + kernel/syscalls/newstat.o \ + kernel/syscalls/creat.o \ + kernel/syscalls/getdents64.o \ + kernel/syscalls/getpid.o \ + kernel/syscalls/read.o \ + kernel/syscalls/dup.o \ + kernel/syscalls/utimes.o \ + kernel/syscalls/semget.o \ + kernel/syscalls/mount.o \ + kernel/syscalls/rmdir.o \ + kernel/syscalls/setrlimit.o \ + kernel/syscalls/sgetmask.o \ + kernel/syscalls/pause.o \ + kernel/syscalls/utime.o \ + kernel/syscalls/statfs.o \ + kernel/syscalls/ioperm.o \ + kernel/syscalls/exit_group.o \ + kernel/syscalls/ftime.o \ + kernel/syscalls/truncate.o \ + kernel/syscalls/pipe2.o \ + kernel/syscalls/old_mmap.o \ + kernel/syscalls/olduname.o \ + kernel/syscalls/kill.o \ + kernel/syscalls/gettimeofday.o \ + kernel/syscalls/fchmod.o \ + kernel/syscalls/fcntl64.o \ + kernel/syscalls/mprotect.o \ + kernel/syscalls/getitimer.o \ + kernel/syscalls/old_select.o \ + kernel/syscalls/symlink.o \ + kernel/syscalls/mknod.o \ + kernel/syscalls/write.o \ + kernel/syscalls/rename.o \ + kernel/syscalls/shmat.o \ + kernel/syscalls/ipc.o \ + kernel/syscalls/lstat64.o \ + kernel/syscalls/access.o \ + kernel/syscalls/getrlimit.o \ + kernel/syscalls/sigreturn.o \ + kernel/syscalls/ioctl.o \ + kernel/syscalls/umask.o \ + kernel/syscalls/geteuid.o \ + kernel/syscalls/munmap.o \ + kernel/syscalls/alarm.o \ + kernel/syscalls/nanosleep.o \ + kernel/syscalls/close.o \ + kernel/syscalls/chroot.o \ + kernel/syscalls/ftruncate64.o \ + kernel/syscalls/msgrcv.o \ + kernel/syscalls/umount2.o \ + kernel/syscalls/time.o \ + kernel/syscalls/stime.o \ + kernel/syscalls/semop.o \ + kernel/syscalls/newlstat.o \ + kernel/syscalls/sigpending.o \ + kernel/syscalls/reboot.o \ + kernel/syscalls/setuid.o \ + kernel/syscalls/wait4.o \ + kernel/syscalls/chown32.o \ + kernel/syscalls/fcntl.o \ + kernel/syscalls/fstat64.o \ + kernel/syscalls/shmctl.o \ + kernel/syscalls/dup2.o \ + kernel/syscalls/setpgid.o \ + kernel/syscalls/getdents.o \ + kernel/syscalls/getpgrp.o \ + kernel/syscalls/fchown.o \ + kernel/syscalls/execve.o \ + kernel/syscalls/shmget.o \ + mm/bios_map.o \ + mm/buddy_low.o \ + mm/memory.o \ + mm/page.o \ + mm/alloc.o \ + mm/fault.o \ + mm/mmap.o \ + mm/swapper.o \ + fs/filesystems.o \ + fs/devices.o \ + fs/buffer.o \ + fs/fd.o \ + fs/locks.o \ + fs/super.o \ + fs/inode.o \ + fs/namei.o \ + fs/elf.o \ + fs/script.o \ + fs/minix/super.o \ + fs/minix/bitmaps.o \ + fs/minix/inode.o \ + fs/minix/namei.o \ + fs/minix/symlink.o \ + fs/minix/dir.o \ + fs/minix/file.o \ + fs/minix/v1_inode.o \ + fs/minix/v2_inode.o \ + fs/ext2/inode.o \ + fs/ext2/super.o \ + fs/ext2/namei.o \ + fs/ext2/symlink.o \ + fs/ext2/dir.o \ + fs/ext2/file.o \ + fs/ext2/bitmaps.o \ + fs/pipefs/super.o \ + fs/pipefs/fifo.o \ + fs/pipefs/pipe.o \ + fs/iso9660/inode.o \ + fs/iso9660/super.o \ + fs/iso9660/namei.o \ + fs/iso9660/dir.o \ + fs/iso9660/file.o \ + fs/iso9660/rrip.o \ + fs/iso9660/symlink.o \ + fs/procfs/super.o \ + fs/procfs/inode.o \ + fs/procfs/namei.o \ + fs/procfs/dir.o \ + fs/procfs/file.o \ + fs/procfs/symlink.o \ + fs/procfs/tree.o \ + fs/procfs/data.o \ + drivers/char/console.o \ + drivers/char/tty.o \ + drivers/char/tty_queue.o \ + drivers/char/vt.o \ + drivers/char/defkeymap.o \ + drivers/char/keyboard.o \ + drivers/char/memdev.o \ + drivers/char/serial.o \ + drivers/char/lp.o \ + drivers/char/fb.o \ + drivers/char/sysrq.o \ + drivers/block/dma.o \ + drivers/block/floppy.o \ + drivers/block/part.o \ + drivers/block/ata.o \ + drivers/block/ata_hd.o \ + drivers/block/atapi.o \ + drivers/block/atapi_cd.o \ + drivers/block/ramdisk.o \ + drivers/pci/pci.o \ + drivers/video/video.o \ + drivers/video/vgacon.o \ + drivers/video/fbcon.o \ + drivers/video/fonts.o \ + drivers/video/bga.o \ + lib/ctype.o \ + lib/strings.o \ + lib/printk.o \ + -o /boot/fiwix + +cd ../.. + +# Checksums +if match x${UPDATE_CHECKSUMS} xTrue; then + sha256sum -o ${pkg}.checksums \ + /boot/fiwix + + cp ${pkg}.checksums ${srcdir} +else + sha256sum -c ${pkg}.checksums +fi diff --git a/sysa/fiwix-1.4.0-lb1/sources b/sysa/fiwix-1.4.0-lb1/sources new file mode 100644 index 0000000..e353a6e --- /dev/null +++ b/sysa/fiwix-1.4.0-lb1/sources @@ -0,0 +1 @@ +https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb1/fiwix-1.4.0-lb1.tar.gz ff57d1fbf0547a27dec4d7146eb9c17d01158ca5886de54e5b9bac2bec473ef3 diff --git a/sysa/kexec-fiwix/kexec-fiwix.kaem b/sysa/kexec-fiwix/kexec-fiwix.kaem new file mode 100755 index 0000000..67017ac --- /dev/null +++ b/sysa/kexec-fiwix/kexec-fiwix.kaem @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +cd src +tcc -m32 -march=i386 -std=c89 -I../../tcc/tcc-0.9.27/include -o ${bindir}/kexec-fiwix kexec-fiwix.c diff --git a/sysa/kexec-fiwix/src/kexec-fiwix.c b/sysa/kexec-fiwix/src/kexec-fiwix.c new file mode 100644 index 0000000..ae6efaa --- /dev/null +++ b/sysa/kexec-fiwix/src/kexec-fiwix.c @@ -0,0 +1,219 @@ +/* SPDX-FileCopyrightText: 2023 Richard Masters */ +/* SPDX-License-Identifier: MIT */ +#include +#include +#include +#include "multiboot1.h" + +#define MULTIBOOT_MAGIC 0x2BADB002 +#define INITRD_MB 1152 + +int main() { + /* Read the kernel */ + + printf("kexec-fiwix: starting...\n\n"); + FILE *fiwix_file = fopen("/boot/fiwix", "r"); + fseek(fiwix_file, 0, SEEK_END); + int fiwix_len = ftell(fiwix_file); + printf("kexec-fiwix: Fiwix kernel file length: %d\n", fiwix_len); + + puts("kexec-fiwix: Reading kernel..."); + fseek(fiwix_file, 0, SEEK_SET); + char * fiwix_mem = malloc(fiwix_len); + int read_len = fread(fiwix_mem, fiwix_len, 1, fiwix_file); + fclose(fiwix_file); + + if (read_len < 1) { + printf("kexec-fiwix: kernel fread error: %d\n", read_len); + return EXIT_FAILURE; + } + + + /* Display info from ELF header */ + + unsigned int e_entry = *((unsigned int *) (&fiwix_mem[0x18])); + printf("ELF virtual entry point : 0x%x\n", e_entry); + + unsigned int e_phoff = *((unsigned int *) (&fiwix_mem[0x1C])); + printf("ELF program header offset : 0x%x\n", e_phoff); + + unsigned int e_phnum = *((unsigned int *) (&fiwix_mem[0x2C])); + e_phnum &= 0xFFFF; + printf("ELF number of program headers: %d\n", e_phnum); + + unsigned int e_phentsize = *((unsigned int *) (&fiwix_mem[0x2A])); + e_phentsize &= 0xFFFF; + printf("ELF size of program headers : %d\n", e_phentsize); + + + /* Load the kernel */ + puts("kexec-fiwix: Placing kernel in memory..."); + + int header_num; + for (header_num = 0; header_num < e_phnum; header_num++) { + char * fiwix_prog_header = &fiwix_mem[e_phoff + header_num * e_phentsize]; + + unsigned int p_offset = *((unsigned int *) (&fiwix_prog_header[0x04])); + unsigned int p_vaddr = *((unsigned int *) (&fiwix_prog_header[0x08])); + unsigned int p_paddr = *((unsigned int *) (&fiwix_prog_header[0x0C])); + unsigned int p_filesz = *((unsigned int *) (&fiwix_prog_header[0x10])); + unsigned int p_memsz = *((unsigned int *) (&fiwix_prog_header[0x14])); + + if (header_num == 0) { + e_entry -= (p_vaddr - p_paddr); + printf("ELF physical entry point : 0x%x\n", e_entry); + } + + printf("header %d:\n", header_num); + printf(" p_offset: 0x%08x\n", p_offset); + printf(" p_paddr : 0x%08x\n", p_paddr); + printf(" p_filesz: 0x%08x\n", p_filesz); + printf(" p_memsz : 0x%08x\n", p_memsz); + + memset((void *)p_paddr, 0, p_memsz + 0x10000); + memcpy((void *)p_paddr, &fiwix_mem[p_offset], p_filesz); + } + + puts("Preparing multiboot info for kernel..."); + + char cmdline[256]; + sprintf(cmdline, "fiwix console=/dev/ttyS0 root=/dev/ram0 ramdisksize=%d initrd=sysa.ext2", INITRD_MB * 1024); + char * boot_loader_name = "kexec-fiwix"; + + unsigned int next_avail_mem = 0x8000; + multiboot_info_t * pmultiboot_info = (multiboot_info_t *) next_avail_mem; + memset(pmultiboot_info, 0, sizeof(multiboot_info_t)); + + pmultiboot_info->flags = MULTIBOOT_INFO_BOOT_LOADER_NAME + | MULTIBOOT_INFO_MEMORY + | MULTIBOOT_INFO_CMDLINE + | MULTIBOOT_INFO_MODS + | MULTIBOOT_INFO_MEM_MAP; + + next_avail_mem += sizeof(multiboot_info_t); + + pmultiboot_info->mem_lower = 0x0000027F; + pmultiboot_info->mem_upper = 0x002FFB80; + + /* Set command line */ + pmultiboot_info->cmdline = next_avail_mem; + strcpy((char *) next_avail_mem, cmdline); + next_avail_mem += (strlen(cmdline) + 1); + + /* Set ramdrive info */ + pmultiboot_info->mods_count = 1; + pmultiboot_info->mods_addr = next_avail_mem; + multiboot_module_t *pmultiboot_module = (multiboot_module_t *) next_avail_mem; + pmultiboot_module->mod_start = 0x1C6000; + pmultiboot_module->mod_end = 0x1C6000 + (INITRD_MB * 1024 * 1024); + next_avail_mem += sizeof(multiboot_module_t); + pmultiboot_module->cmdline = next_avail_mem; + strcpy((char *) next_avail_mem, "sysa.ext2"); + next_avail_mem += (strlen("sysa.ext2") + 1); + + /* Set memory map info */ + pmultiboot_info->mmap_addr = next_avail_mem; + pmultiboot_info->mmap_length = 7 * sizeof(multiboot_memory_map_t); + multiboot_memory_map_t *pmultiboot_memory_map = (multiboot_memory_map_t *) next_avail_mem; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0x00000000; + pmultiboot_memory_map->len = 0x0009FC00; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_AVAILABLE; + pmultiboot_memory_map++; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0x0009FC00; + pmultiboot_memory_map->len = 0x00000400; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED; + pmultiboot_memory_map++; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0x000F0000; + pmultiboot_memory_map->len = 0x00010000; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED; + pmultiboot_memory_map++; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0x00100000; + pmultiboot_memory_map->len = 0xBFEE0000; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_AVAILABLE; + pmultiboot_memory_map++; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0XBFFE0000; + pmultiboot_memory_map->len = 0x00020000; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED; + pmultiboot_memory_map++; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0XFEFFC000; + pmultiboot_memory_map->len = 0x00004000; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED; + pmultiboot_memory_map++; + + pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t); + pmultiboot_memory_map->addr = 0XFFFC0000; + pmultiboot_memory_map->len = 0x00040000; + pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED; + pmultiboot_memory_map++; + + next_avail_mem += pmultiboot_info->mmap_length; + + /* Set boot loader name */ + pmultiboot_info->boot_loader_name = next_avail_mem; + strcpy((char *) next_avail_mem, boot_loader_name); + /* next_avail_mem += (strlen(boot_loader_name) + 1); */ + + /* Jump to kernel entry point */ + unsigned int magic = MULTIBOOT_BOOTLOADER_MAGIC; + unsigned int dummy = 0; + unsigned int multiboot_info_num = (unsigned int) pmultiboot_info; + + int filenum; + unsigned int filename_addr; + for (filenum = 4, filename_addr = 0x201000; filenum <= 14335; filenum++, filename_addr += 1024) { + if (!strcmp((char *) filename_addr, "/boot/sysa.ext2")) { + printf("Found image at filenum %d\n", filenum); + break; + } + } + + unsigned int initrd_src = *((unsigned int *) (0x01000000 + (16 * filenum) + 4)); + unsigned int initrd_len = *((unsigned int *) (0x01000000 + (16 * filenum) + 8)); + printf("initrd_src: 0x%08x\n", initrd_src); + printf("initrd_len: 0x%08x\n", initrd_len); + printf("Preparing trampoline...\n"); + + /* The ramdrive needs to be written to a location that would overwrite this program. + * Therfore, the code that copies the ram drive and jumps to the kernel needs to be + * run from a safe location. So, we put that code into an array variable and + * copy the code (called a "trampoline") to a safe location and then jump to it. + * The 0x00000000 values below are place holders which are set below + */ + char trampoline[] = { + 0xBE, 0x00, 0x00, 0x00, 0x00, /* mov esi, 0x00000000 */ + 0xBF, 0x00, 0x00, 0x00, 0x00, /* mov edi, 0x00000000 */ + 0xB9, 0x00, 0x00, 0x00, 0x00, /* mov ecx, 0x00000000 */ + 0xFC, /* cld */ + 0xF3, 0xA4, /* rep movsb */ + 0xB8, 0x00, 0x00, 0x00, 0x00, /* mov eax, 0x00000000 */ + 0xBB, 0x00, 0x00, 0x00, 0x00, /* mov ebx, 0x00000000 */ + 0xEA, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 /* jmp far 0x0008:0x00000000 */ + }; + + /* Set place holder values */ + *((unsigned int *) &trampoline[1]) = initrd_src; + *((unsigned int *) &trampoline[6]) = 0x001C6000; + *((unsigned int *) &trampoline[11]) = INITRD_MB * 1024 * 1024; + *((unsigned int *) &trampoline[19]) = magic; + *((unsigned int *) &trampoline[24]) = multiboot_info_num; + *((unsigned int *) &trampoline[29]) = e_entry; + + memcpy((void *)0x4000, trampoline, sizeof(trampoline)); + + printf("kexec-fiwix: jumping to trampoline...\n"); + __asm__ __volatile__ ( + "ljmp $0x8, $0x00004000\n\t" + ); +} diff --git a/sysa/kexec-fiwix/src/multiboot1.h b/sysa/kexec-fiwix/src/multiboot1.h new file mode 100644 index 0000000..8b2af72 --- /dev/null +++ b/sysa/kexec-fiwix/src/multiboot1.h @@ -0,0 +1,353 @@ +/* multiboot.h - Multiboot header file. */ +/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY + * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * SPDX-FileCopyrightText: 2010 FSF + * SPDX-License-Identifier: MIT + */ + +#ifndef MULTIBOOT_HEADER +#define MULTIBOOT_HEADER 1 + +/* How many bytes from the start of the file we search for the header. */ +#define MULTIBOOT_SEARCH 8192 +#define MULTIBOOT_HEADER_ALIGN 4 + +/* The magic field should contain this. */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* This should be in %eax. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* Alignment of multiboot modules. */ +#define MULTIBOOT_MOD_ALIGN 0x00001000 + +/* Alignment of the multiboot info structure. */ +#define MULTIBOOT_INFO_ALIGN 0x00000004 + +/* Flags set in the ’flags’ member of the multiboot header. */ + +/* Align all boot modules on i386 page (4KB) boundaries. */ +#define MULTIBOOT_PAGE_ALIGN 0x00000001 + +/* Must pass memory information to OS. */ +#define MULTIBOOT_MEMORY_INFO 0x00000002 + +/* Must pass video information to OS. */ +#define MULTIBOOT_VIDEO_MODE 0x00000004 + +/* This flag indicates the use of the address fields in the header. */ +#define MULTIBOOT_AOUT_KLUDGE 0x00010000 + +/* Flags to be set in the ’flags’ member of the multiboot info structure. */ + +/* is there basic lower/upper memory information? */ +#define MULTIBOOT_INFO_MEMORY 0x00000001 +/* is there a boot device set? */ +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +/* is the command-line defined? */ +#define MULTIBOOT_INFO_CMDLINE 0x00000004 +/* are there modules to do something with? */ +#define MULTIBOOT_INFO_MODS 0x00000008 + +/* These next two are mutually exclusive */ + +/* is there a symbol table loaded? */ +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +/* is there an ELF section header table? */ +#define MULTIBOOT_INFO_ELF_SHDR 0X00000020 + +/* is there a full memory map? */ +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 + +/* Is there drive info? */ +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 + +/* Is there a config table? */ +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 + +/* Is there a boot loader name? */ +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 + +/* Is there a APM table? */ +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 + +/* Is there video information? */ +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 + +#ifndef ASM_FILE + +typedef unsigned char multiboot_uint8_t; +typedef unsigned short multiboot_uint16_t; +typedef unsigned int multiboot_uint32_t; +typedef unsigned long long multiboot_uint64_t; + +struct multiboot_header +{ + /* Must be MULTIBOOT_MAGIC - see above. */ + multiboot_uint32_t magic; + + /* Feature flags. */ + multiboot_uint32_t flags; + + /* The above fields plus this one must equal 0 mod 2^32. */ + multiboot_uint32_t checksum; + + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ + multiboot_uint32_t header_addr; + multiboot_uint32_t load_addr; + multiboot_uint32_t load_end_addr; + multiboot_uint32_t bss_end_addr; + multiboot_uint32_t entry_addr; + + /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ + multiboot_uint32_t mode_type; + multiboot_uint32_t width; + multiboot_uint32_t height; + multiboot_uint32_t depth; +}; + +/* The symbol table for a.out. */ +struct multiboot_aout_symbol_table +{ + multiboot_uint32_t tabsize; + multiboot_uint32_t strsize; + multiboot_uint32_t addr; + multiboot_uint32_t reserved; +}; +typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; + +/* The section header table for ELF. */ +struct multiboot_elf_section_header_table +{ + multiboot_uint32_t num; + multiboot_uint32_t size; + multiboot_uint32_t addr; + multiboot_uint32_t shndx; +}; +typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; + +struct multiboot_info +{ + /* Multiboot info version number */ + multiboot_uint32_t flags; + + /* Available memory from BIOS */ + multiboot_uint32_t mem_lower; + multiboot_uint32_t mem_upper; + + /* "root" partition */ + multiboot_uint32_t boot_device; + + /* Kernel command line */ + multiboot_uint32_t cmdline; + + /* Boot-Module list */ + multiboot_uint32_t mods_count; + multiboot_uint32_t mods_addr; + + union + { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; + + /* Memory Mapping buffer */ + multiboot_uint32_t mmap_length; + multiboot_uint32_t mmap_addr; + + /* Drive Info buffer */ + multiboot_uint32_t drives_length; + multiboot_uint32_t drives_addr; + + /* ROM configuration table */ + multiboot_uint32_t config_table; + + /* Boot Loader Name */ + multiboot_uint32_t boot_loader_name; + + /* APM table */ + multiboot_uint32_t apm_table; + + /* Video */ + multiboot_uint32_t vbe_control_info; + multiboot_uint32_t vbe_mode_info; + multiboot_uint16_t vbe_mode; + multiboot_uint16_t vbe_interface_seg; + multiboot_uint16_t vbe_interface_off; + multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; +}; +typedef struct multiboot_info multiboot_info_t; + +struct multiboot_color +{ + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; +}; + +struct multiboot_mmap_entry +{ + multiboot_uint32_t size; + multiboot_uint64_t addr; + multiboot_uint64_t len; +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 +#define MULTIBOOT_MEMORY_NVS 4 +#define MULTIBOOT_MEMORY_BADRAM 5 + multiboot_uint32_t type; +} __attribute__((packed)); +typedef struct multiboot_mmap_entry multiboot_memory_map_t; + +struct multiboot_mod_list +{ + /* the memory used goes from bytes ’mod_start’ to ’mod_end-1’ inclusive */ + multiboot_uint32_t mod_start; + multiboot_uint32_t mod_end; + + /* Module command line */ + multiboot_uint32_t cmdline; + + /* padding to take it to 16 bytes (must be zero) */ + multiboot_uint32_t pad; +}; +typedef struct multiboot_mod_list multiboot_module_t; + +/* APM BIOS info. */ +struct multiboot_apm_info +{ + multiboot_uint16_t version; + multiboot_uint16_t cseg; + multiboot_uint32_t offset; + multiboot_uint16_t cseg_16; + multiboot_uint16_t dseg; + multiboot_uint16_t flags; + multiboot_uint16_t cseg_len; + multiboot_uint16_t cseg_16_len; + multiboot_uint16_t dseg_len; +}; + +/* VBE controller information. */ +struct vbe_controller +{ + unsigned char signature[4]; + unsigned short version; + unsigned long oem_string; + unsigned long capabilities; + unsigned long video_mode; + unsigned short total_memory; + unsigned short oem_software_rev; + unsigned long oem_vendor_name; + unsigned long oem_product_name; + unsigned long oem_product_rev; + unsigned char reserved[222]; + unsigned char oem_data[256]; +} __attribute__ ((packed)); + +/* VBE mode information. */ +struct vbe_mode +{ + unsigned short mode_attributes; + unsigned char win_a_attributes; + unsigned char win_b_attributes; + unsigned short win_granularity; + unsigned short win_size; + unsigned short win_a_segment; + unsigned short win_b_segment; + unsigned long win_func; + unsigned short bytes_per_scanline; + + /* >=1.2 */ + unsigned short x_resolution; + unsigned short y_resolution; + unsigned char x_char_size; + unsigned char y_char_size; + unsigned char number_of_planes; + unsigned char bits_per_pixel; + unsigned char number_of_banks; + unsigned char memory_model; + unsigned char bank_size; + unsigned char number_of_image_pages; + unsigned char reserved0; + + /* direct color */ + unsigned char red_mask_size; + unsigned char red_field_position; + unsigned char green_mask_size; + unsigned char green_field_position; + unsigned char blue_mask_size; + unsigned char blue_field_position; + unsigned char reserved_mask_size; + unsigned char reserved_field_position; + unsigned char direct_color_mode_info; + + /* >=2.0 */ + unsigned long phys_base; + unsigned long reserved1; + unsigned short reversed2; + + /* >=3.0 */ + unsigned short linear_bytes_per_scanline; + unsigned char banked_number_of_image_pages; + unsigned char linear_number_of_image_pages; + unsigned char linear_red_mask_size; + unsigned char linear_red_field_position; + unsigned char linear_green_mask_size; + unsigned char linear_green_field_position; + unsigned char linear_blue_mask_size; + unsigned char linear_blue_field_position; + unsigned char linear_reserved_mask_size; + unsigned char linear_reserved_field_position; + unsigned long max_pixel_clock; + + unsigned char reserved3[190]; +} __attribute__ ((packed)); + + +#endif /* ! ASM_FILE */ + +#endif /* ! MULTIBOOT_HEADER */ diff --git a/sysa/lwext4-1.0.0-lb1/config/ext4_config.h b/sysa/lwext4-1.0.0-lb1/config/ext4_config.h new file mode 100644 index 0000000..4c04218 --- /dev/null +++ b/sysa/lwext4-1.0.0-lb1/config/ext4_config.h @@ -0,0 +1,18 @@ +/* + SPDX-FileCopyrightText: 2023 Richard Masters + SPDX-License-Identifier: MIT + */ +#define CONFIG_USE_DEFAULT_CONFIG 0 +#define CONFIG_HAVE_OWN_OFLAGS 0 +#define CONFIG_HAVE_OWN_ERRNO 1 +#define CONFIG_HAVE_OWN_ASSERT 0 +#define CONFIG_BLOCK_DEV_CACHE_SIZE 16 +typedef long long unsigned int uint64_t; +typedef long long int int64_t; +#define fseeko fseek +#define ftello ftell +#define PRIu32 "u" +#define PRId32 "d" +#define PRIx32 "x" +#define PRIu16 "hu" + diff --git a/sysa/lwext4-1.0.0-lb1/files/early-artifacts-needed-after-fiwix.txt b/sysa/lwext4-1.0.0-lb1/files/early-artifacts-needed-after-fiwix.txt new file mode 100644 index 0000000..e61d380 --- /dev/null +++ b/sysa/lwext4-1.0.0-lb1/files/early-artifacts-needed-after-fiwix.txt @@ -0,0 +1,93 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +/usr/bin/blood-elf +/usr/bin/catm +/usr/bin/chmod +/usr/bin/get_machine +/usr/bin/hex2 +/usr/bin/kaem +/usr/bin/match +/usr/bin/M1 +/usr/bin/M2-Mesoplanet +/usr/bin/M2-Planet +/usr/bin/mkdir +/usr/bin/sha256sum +/usr/bin/unbz2 +/usr/bin/ungz +/usr/bin/untar +/usr/bin/cp +/usr/bin/replace +/usr/bin/rm +/usr/bin/checksum-transcriber +/usr/bin/tcc +/usr/bin/tcc-0.9.26 +/usr/lib/mes/libc.a +/usr/lib/mes/libgetopt.a +/usr/lib/mes/crt1.o +/usr/lib/mes/crti.o +/usr/lib/mes/crtn.o +/usr/lib/mes/tcc/libtcc1.a +/usr/include/alloca.h +/usr/include/argz.h +/usr/include/ar.h +/usr/include/assert.h +/usr/include/ctype.h +/usr/include/dirent.h +/usr/include/dirstream.h +/usr/include/dlfcn.h +/usr/include/endian.h +/usr/include/errno.h +/usr/include/fcntl.h +/usr/include/features.h +/usr/include/float.h +/usr/include/getopt.h +/usr/include/grp.h +/usr/include/inttypes.h +/usr/include/libgen.h +/usr/include/limits.h +/usr/include/locale.h +/usr/include/math.h +/usr/include/memory.h +/usr/include/pwd.h +/usr/include/setjmp.h +/usr/include/signal.h +/usr/include/stdarg.h +/usr/include/stdbool.h +/usr/include/stddef.h +/usr/include/stdint.h +/usr/include/stdio.h +/usr/include/stdlib.h +/usr/include/stdnoreturn.h +/usr/include/string.h +/usr/include/strings.h +/usr/include/termio.h +/usr/include/time.h +/usr/include/unistd.h +/usr/include/arch/kernel-stat.h +/usr/include/arch/syscall.h +/usr/include/linux/syscall.h +/usr/include/linux/x86/syscall.h +/usr/include/mes/builtins.h +/usr/include/mes/cc.h +/usr/include/mes/config.h +/usr/include/mes/constants.h +/usr/include/mes/lib.h +/usr/include/mes/lib-mini.h +/usr/include/mes/mes.h +/usr/include/mes/symbols.h +/usr/include/sys/cdefs.h +/usr/include/sys/dir.h +/usr/include/sys/file.h +/usr/include/sys/ioctl.h +/usr/include/sys/mman.h +/usr/include/sys/param.h +/usr/include/sys/resource.h +/usr/include/sys/select.h +/usr/include/sys/stat.h +/usr/include/sys/timeb.h +/usr/include/sys/time.h +/usr/include/sys/times.h +/usr/include/sys/types.h +/usr/include/sys/ucontext.h +/usr/include/sys/user.h +/usr/include/sys/wait.h diff --git a/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c b/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c new file mode 100644 index 0000000..960cc7a --- /dev/null +++ b/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c @@ -0,0 +1,286 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com) + * SPDX-License-Identifier: BSD-3-Clause + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modifications: + * SPDX-FileCopyrightText: 2023 Richard Masters + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "../blockdev/linux/file_dev.h" +#include "../blockdev/windows/file_windows.h" + +#define BLOCK_SIZE 1024 +#define FILENAME_LENGTH 256 +#define INITRD_MB 1152 + +const char *input_name = NULL; +/**@brief Block device handle.*/ +static struct ext4_blockdev *bd; +/**@brief Block cache handle.*/ +static struct ext4_bcache *bc; +static struct ext4_fs fs; + + +static struct ext4_mkfs_info info = { + .block_size = BLOCK_SIZE, + .journal = false, + .inode_size = 128, +}; + +#define MKDEV(major, minor) (((major) << 8) | (minor)) + +static bool open_filedev(void) +{ + file_dev_name_set(input_name); + bd = file_dev_get(); + if (!bd) { + printf("open_filedev: fail\n"); + return false; + } + return true; +} + +bool lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache) +{ + int r; + + bc = bcache; + bd = bdev; + + if (!bd) { + printf("lwext4_mount: no block device\n"); + return false; + } + + /* ext4_dmask_set(DEBUG_ALL); */ + + r = ext4_device_register(bd, "ext4_fs"); + if (r != EOK) { + printf("ext4_device_register: rc = %d\n", r); + return false; + } + + r = ext4_mount("ext4_fs", "/mp/", false); + if (r != EOK) { + printf("ext4_mount: rc = %d\n", r); + return false; + } + + r = ext4_recover("/mp/"); + if (r != EOK && r != ENOTSUP) { + printf("ext4_recover: rc = %d\n", r); + return false; + } + + /* ext4_cache_write_back("/mp/", 1); */ + + return true; +} + +bool lwext4_umount(void) +{ + int r; + + /* ext4_cache_write_back("/mp/", 0); */ + + r = ext4_umount("/mp/"); + if (r != EOK) { + printf("ext4_umount: fail %d", r); + return false; + } + return true; +} + + +bool copy_file(char *src_path, char *dest_path) +{ + + printf("copy_file: %s\n", src_path); + ext4_file dest_file; + FILE *src_file = fopen(src_path, "rb"); + if (!src_file) { + printf("fopen '%s' error.\n", src_path); + return EXIT_FAILURE; + } + fseek(src_file, 0, SEEK_END); + int src_len = ftell(src_file); + char * src_mem = malloc(src_len); + int err; + + fseek(src_file, 0, SEEK_SET); + if (src_len > 0) { + int read_len = fread(src_mem, src_len, 1, src_file); + fclose(src_file); + if (read_len < 1) { + printf("src fread error file: '%s' read count: %d\n", src_path, read_len); + } + } + + err = ext4_fopen(&dest_file, dest_path, "wb"); + if (err != EOK) { + printf("ext4_open error: %d \n", err); + return EXIT_FAILURE; + } + + if (src_len > 0) { + err = ext4_fwrite(&dest_file, src_mem, src_len, 0); + if (err != EOK) { + printf("ext4_fwrite error: %d \n", err); + return EXIT_FAILURE; + } + } + + err = ext4_fclose(&dest_file); + if (err != EOK) { + printf("ext4_fclose error: %d \n", err); + return EXIT_FAILURE; + } + + free(src_mem); +} + +bool copy_file_list(char *file_list_path) +{ + char src_filename[FILENAME_LENGTH]; + char dst_filename[FILENAME_LENGTH]; + + FILE *file_list = fopen(file_list_path, "r"); + while(fgets(src_filename, FILENAME_LENGTH, file_list)) { + /* Skip comments */ + if (src_filename[0] == '#') { + continue; + } + src_filename[strlen(src_filename) - 1] = 0; /* strip newline */ + strcpy(dst_filename, "/mp"); + strcat(dst_filename, src_filename); + copy_file(src_filename, dst_filename); + } + fclose(file_list); +} + +int main(int argc, char **argv) +{ + int err; + + char zeros[BLOCK_SIZE]; + + unsigned int next_file_address; + + next_file_address = *((unsigned int *) 0x7F8D); + + printf("Starting sysa.ext2 at addr 0x%08x\n", next_file_address); + + /* Create zeroed out disk image file */ + input_name = "/boot/sysa.ext2"; + + memset(zeros, 0, BLOCK_SIZE); + FILE *ext2file = fopen(input_name, "w"); + int b; + for (b=0; b < (BLOCK_SIZE * INITRD_MB); b++) + fwrite(zeros, BLOCK_SIZE, 1, ext2file); + fclose(ext2file); + + if (!open_filedev()) { + printf("open_filedev error\n"); + return EXIT_FAILURE; + } + + /* ext4_dmask_set(DEBUG_ALL); */ + + err = ext4_mkfs(&fs, bd, &info, F_SET_EXT2_V0); + if (err != EOK) { + printf("ext4_mkfs error: %d \n", err); + return EXIT_FAILURE; + } + + memset(&info, 0, sizeof(struct ext4_mkfs_info)); + err = ext4_mkfs_read_info(bd, &info); + if (err != EOK) { + printf("ext4_mkfs_read_info error: %d\n", err); + return EXIT_FAILURE; + } + + printf("Created filesystem with parameters:\n"); + printf("Size: %"PRIu64"\n", info.len); + printf("Block size: %"PRIu32"\n", info.block_size); + printf("Blocks per group: %"PRIu32"\n", info.blocks_per_group); + printf("Inodes per group: %"PRIu32"\n", info.inodes_per_group); + printf("Inode size: %"PRIu32"\n", info.inode_size); + printf("Inodes: %"PRIu32"\n", info.inodes); + printf("Journal blocks: %"PRIu32"\n", info.journal_blocks); + printf("Features ro_compat: 0x%x\n", info.feat_ro_compat); + printf("Features compat: 0x%x\n", info.feat_compat); + printf("Features incompat: 0x%x\n", info.feat_incompat); + printf("BG desc reserve: %"PRIu32"\n", info.bg_desc_reserve_blocks); + printf("Descriptor size: %"PRIu32"\n",info.dsc_size); + printf("Label: %s\n", info.label); + + if (!lwext4_mount(bd, bc)) + return EXIT_FAILURE; + + printf("ext4_dir_mk /mp/dev\n"); + err = ext4_dir_mk("/mp/dev"); + if (err != EOK) { + printf("ext4_dir_mk error: %d \n", err); + } + + printf("ext4_mknod /mp/dev/console\n"); + err = ext4_mknod("/mp/dev/console", EXT4_DE_CHRDEV, MKDEV(5, 1)); + if (err != EOK) { + printf("ext4_mknod error: %d \n", err); + return EXIT_FAILURE; + } + + copy_file("/usr/bin/kaem", "/mp/init"); + copy_file("/sysa/after2.kaem", "/mp/kaem.run"); + copy_file_list("/sysa/lwext4-1.0.0-lb1/files/fiwix-file-list.txt"); + printf("ext4_dir_mk /mp/tmp\n"); + ext4_dir_mk("/mp/tmp"); + printf("ext4_dir_mk /mp/usr\n"); + ext4_dir_mk("/mp/usr"); + printf("ext4_dir_mk /mp/usr/src\n"); + ext4_dir_mk("/mp/usr/src"); + + if (!lwext4_umount()) + return EXIT_FAILURE; + + printf("Fiwix ext2 initrd created successfully.\n"); + return EXIT_SUCCESS; +} diff --git a/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.kaem b/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.kaem new file mode 100755 index 0000000..bfea081 --- /dev/null +++ b/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.kaem @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT + +mkdir build src +cd src +ungz --file ${distfiles}/${pkg}.tar.gz --output ${pkg}.tar +cd .. + +cd build +untar --file ../src/${pkg}.tar +cd ${pkg} + +mkdir build_generic +mkdir build_generic/include +mkdir build_generic/include/generated +catm build_generic/include/generated/ext4_config.h ../../config/ext4_config.h + +cd blockdev/linux +tcc -m32 -march=i386 -std=c89 -I../../include -I../../build_generic/include -I../../../tcc/tcc-0.9.27/include -DVERSION="\"1.0\"" -c file_dev.c + +cd ../../src +alias cc="tcc -m32 -march=i386 -std=c89 -I../include -I../build_generic/include -I../../tcc/tcc-0.9.27/include" +cc -c ext4.c +cc -c ext4_balloc.c +cc -c ext4_bcache.c +cc -c ext4_bitmap.c +cc -c ext4_block_group.c +cc -c ext4_blockdev.c +cc -c ext4_crc32.c +cc -c ext4_debug.c +cc -c ext4_dir.c +cc -c ext4_dir_idx.c +cc -c ext4_extent.c +cc -c ext4_fs.c +cc -c ext4_hash.c +cc -c ext4_ialloc.c +cc -c ext4_inode.c +cc -c ext4_journal.c +cc -c ext4_mbr.c +cc -c ext4_mkfs.c +cc -c ext4_super.c +cc -c ext4_trans.c +cc -c ext4_xattr.c + +catm make_fiwix_initrd.c ../../../files/make_fiwix_initrd.c +tcc -m32 -march=i386 -std=c89 -I../include -I../build_generic/include -I../../tcc/tcc-0.9.27/include -DVERSION="\"1.0\"" -c make_fiwix_initrd.c + +tcc -m32 -o ${bindir}/make_fiwix_initrd ext4.o ext4_balloc.o ext4_bcache.o ext4_bitmap.o ext4_block_group.o ext4_blockdev.o ext4_crc32.o ext4_debug.o ext4_dir.o ext4_dir_idx.o ext4_extent.o ext4_fs.o ext4_hash.o ext4_ialloc.o ext4_inode.o ext4_journal.o ext4_mbr.o ext4_mkfs.o ext4_super.o ext4_trans.o ext4_xattr.o ../blockdev/linux/file_dev.o make_fiwix_initrd.o diff --git a/sysa/lwext4-1.0.0-lb1/sources b/sysa/lwext4-1.0.0-lb1/sources new file mode 100644 index 0000000..18badcb --- /dev/null +++ b/sysa/lwext4-1.0.0-lb1/sources @@ -0,0 +1 @@ +https://github.com/rick-masters/lwext4/releases/download/v1.0.0-lb1/lwext4-1.0.0-lb1.tar.gz a90526665123d788fc23d14354468d22cc2e3e9e43a6c44ea452fbbec12b8451 diff --git a/sysa/mes-0.24.2/mes-0.24.2.checksums b/sysa/mes-0.24.2/mes-0.24.2.checksums index 8d818d5..fcd3f2e 100644 --- a/sysa/mes-0.24.2/mes-0.24.2.checksums +++ b/sysa/mes-0.24.2/mes-0.24.2.checksums @@ -1,5 +1,5 @@ -93e16eb9264c5123fa7619edff4c2d2b9b0582b327bef4f3d7a339dd488a90c1 /usr/bin/mes -9b2aafd217628f1bef74a7f36b541d1826ef3434235a7c7e1e041e33b95c26aa /usr/bin/mes-m2 +b2a48b2724a7b791df66efc2384a405a91d26579459a6797514dec89c2e76658 /usr/bin/mes +148ce096422535832802494f1128c26b6580cf3b66635e56abb33f7b3fc26043 /usr/bin/mes-m2 17c86665c2f925d88e3c1f827f312bbc7575b9e6006ef57833e895b6e73b8087 /usr/bin/mescc.scm 4feafab424611c976dc4628aa862e37b4e92b5869aebbcf7655e684c3f589041 /usr/lib/x86-mes/crt1.s 69e9ec2ee2ebf065575cdaf878629178b85330257dde0da790a428c0280d1ecb /usr/lib/x86-mes/crt1.o diff --git a/sysa/mes-0.24.2/mes-0.24.2.kaem b/sysa/mes-0.24.2/mes-0.24.2.kaem index 94d05be..b04055e 100755 --- a/sysa/mes-0.24.2/mes-0.24.2.kaem +++ b/sysa/mes-0.24.2/mes-0.24.2.kaem @@ -28,6 +28,8 @@ cd .. cd build untar --file ../src/${NYACC_PKG}.tar untar --non-strict --file ../src/${MES_PKG}.tar # ignore symlinks +mes_run=/sysa/mes-0.24.2/build/mes-0.24.2/kaem.run +replace --file ${mes_run} --output ${mes_run} --match-on 0x1000000 --replace-with 0x8048000 rm ../src/${NYACC_PKG}.tar ../src/${MES_PKG}.tar @@ -250,7 +252,7 @@ mescc src/symbol.c mescc src/vector.c # Link everything into new mes executable -${MES} -e main ${mescc_scm} -- -L ${libdir} -nostdlib -o ${bindir}/mes -L . crt1.o builtins.o cc.o core.o display.o eval-apply.o gc.o globals.o hash.o lib.o math.o mes.o module.o posix.o reader.o stack.o string.o struct.o symbol.o vector.o -lc -lmescc +${MES} -e main ${mescc_scm} -- --base-address 0x08048000 -L ${libdir} -nostdlib -o ${bindir}/mes -L . crt1.o builtins.o cc.o core.o display.o eval-apply.o gc.o globals.o hash.o lib.o math.o mes.o module.o posix.o reader.o stack.o string.o struct.o symbol.o vector.o -lc -lmescc # Make directories mkdir ${prefix}/lib/linux ${incdir}/mes ${incdir}/sys ${incdir}/linux ${incdir}/arch diff --git a/sysa/musl-1.1.24/patches-pass3/avoid_set_thread_area.patch b/sysa/musl-1.1.24/patches-pass3/avoid_set_thread_area.patch new file mode 120000 index 0000000..3f87a3b --- /dev/null +++ b/sysa/musl-1.1.24/patches-pass3/avoid_set_thread_area.patch @@ -0,0 +1 @@ +../patches/avoid_set_thread_area.patch \ No newline at end of file diff --git a/sysa/musl-1.1.24/patches-pass3/avoid_sys_clone.patch b/sysa/musl-1.1.24/patches-pass3/avoid_sys_clone.patch new file mode 120000 index 0000000..ea4b2b8 --- /dev/null +++ b/sysa/musl-1.1.24/patches-pass3/avoid_sys_clone.patch @@ -0,0 +1 @@ +../patches/avoid_sys_clone.patch \ No newline at end of file diff --git a/sysa/musl-1.1.24/patches/avoid_set_thread_area.patch b/sysa/musl-1.1.24/patches/avoid_set_thread_area.patch new file mode 100644 index 0000000..e7706e5 --- /dev/null +++ b/sysa/musl-1.1.24/patches/avoid_set_thread_area.patch @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +diff -r -u musl-1.1.24.orig/arch/i386/pthread_arch.h musl-1.1.24/arch/i386/pthread_arch.h +--- arch/i386/pthread_arch.h 2019-10-13 21:58:27.000000000 +0000 ++++ arch/i386/pthread_arch.h 2023-04-07 11:56:04.649119523 +0000 +@@ -1,8 +1,8 @@ ++extern pthread_t g_pthread; ++ + static inline struct pthread *__pthread_self() + { +- struct pthread *self; +- __asm__ ("movl %%gs:0,%0" : "=r" (self) ); +- return self; ++ return g_pthread; + } + + #define TP_ADJ(p) (p) +diff -r -u musl-1.1.24.orig/src/env/__init_tls.c musl-1.1.24/src/env/__init_tls.c +--- src/env/__init_tls.c 2019-10-13 21:58:27.000000000 +0000 ++++ src/env/__init_tls.c 2023-04-07 11:56:43.565120289 +0000 +@@ -10,20 +10,19 @@ + #include "syscall.h" + + volatile int __thread_list_lock; ++pthread_t g_pthread; + + int __init_tp(void *p) + { + pthread_t td = p; + td->self = td; +- int r = __set_thread_area(TP_ADJ(p)); +- if (r < 0) return -1; +- if (!r) libc.can_do_threads = 1; + td->detach_state = DT_JOINABLE; + td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); + td->locale = &libc.global_locale; + td->robust_list.head = &td->robust_list.head; + td->sysinfo = __sysinfo; + td->next = td->prev = td; ++ g_pthread = td; + return 0; + } + diff --git a/sysa/musl-1.1.24/patches/avoid_sys_clone.patch b/sysa/musl-1.1.24/patches/avoid_sys_clone.patch new file mode 100644 index 0000000..10540d2 --- /dev/null +++ b/sysa/musl-1.1.24/patches/avoid_sys_clone.patch @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +--- src/process/posix_spawn.c 2019-10-13 21:58:27.000000000 +0000 ++++ src/process/posix_spawn.c 2023-04-07 11:50:47.253113271 +0000 +@@ -182,8 +182,11 @@ + args.envp = envp; + pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask); + +- pid = __clone(child, stack+sizeof stack, +- CLONE_VM|CLONE_VFORK|SIGCHLD, &args); ++ pid = fork(); ++ if (pid == 0) { ++ _exit(child(&args)); ++ } ++ + close(args.p[1]); + + if (pid > 0) { diff --git a/sysa/musl-1.2.3/musl-1.2.3.sh b/sysa/musl-1.2.3/musl-1.2.3.sh index 330b75a..0640cf0 100755 --- a/sysa/musl-1.2.3/musl-1.2.3.sh +++ b/sysa/musl-1.2.3/musl-1.2.3.sh @@ -2,6 +2,17 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +src_get() { + # Before the last pass the tar file is moved before + # the linux build removes all distfiles to save space. + if [ -e "../${pkg}.tar.gz" ]; then + mkdir "${DISTFILES}" + mv "../${pkg}.tar.gz" "${DISTFILES}" + else + default + fi +} + src_configure() { CC=gcc ./configure \ --host=i386-unknown-linux-musl \ diff --git a/sysa/musl-1.2.3/patches/avoid_set_thread_area.patch b/sysa/musl-1.2.3/patches/avoid_set_thread_area.patch new file mode 100644 index 0000000..5a71766 --- /dev/null +++ b/sysa/musl-1.2.3/patches/avoid_set_thread_area.patch @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +diff -r -u musl-1.2.3.orig/arch/i386/pthread_arch.h musl-1.2.3/arch/i386/pthread_arch.h +--- arch/i386/pthread_arch.h 2022-04-07 17:12:40.000000000 +0000 ++++ arch/i386/pthread_arch.h 2023-04-07 12:07:07.929132587 +0000 +@@ -1,8 +1,7 @@ ++extern uintptr_t g_pthread; + static inline uintptr_t __get_tp() + { +- uintptr_t tp; +- __asm__ ("movl %%gs:0,%0" : "=r" (tp) ); +- return tp; ++ return g_pthread; + } + + #define MC_PC gregs[REG_EIP] +diff -r -u musl-1.2.3.orig/arch/i386/syscall_arch.h musl-1.2.3/arch/i386/syscall_arch.h +--- arch/i386/syscall_arch.h 2022-04-07 17:12:40.000000000 +0000 ++++ arch/i386/syscall_arch.h 2022-12-20 17:28:21.734839560 +0000 +@@ -1,3 +1,4 @@ ++#define SYSCALL_NO_TLS 1 + #define __SYSCALL_LL_E(x) \ + ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ + ((union { long long ll; long l[2]; }){ .ll = x }).l[1] +diff -r -u musl-1.2.3.orig/src/env/__init_tls.c musl-1.2.3/src/env/__init_tls.c +--- src/env/__init_tls.c 2022-04-07 17:12:40.000000000 +0000 ++++ src/env/__init_tls.c 2023-04-07 12:07:38.677133193 +0000 +@@ -10,20 +10,19 @@ + #include "syscall.h" + + volatile int __thread_list_lock; ++uintptr_t g_pthread; + + int __init_tp(void *p) + { + pthread_t td = p; + td->self = td; +- int r = __set_thread_area(TP_ADJ(p)); +- if (r < 0) return -1; +- if (!r) libc.can_do_threads = 1; + td->detach_state = DT_JOINABLE; + td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); + td->locale = &libc.global_locale; + td->robust_list.head = &td->robust_list.head; + td->sysinfo = __sysinfo; + td->next = td->prev = td; ++ g_pthread = (uintptr_t) td; + return 0; + } + diff --git a/sysa/musl-1.2.3/patches/avoid_sys_clone.patch b/sysa/musl-1.2.3/patches/avoid_sys_clone.patch new file mode 100644 index 0000000..0cc7e5a --- /dev/null +++ b/sysa/musl-1.2.3/patches/avoid_sys_clone.patch @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +--- src/process/posix_spawn.c 2022-04-07 17:12:40.000000000 +0000 ++++ src/process/posix_spawn.c 2023-04-07 12:01:57.217126467 +0000 +@@ -190,8 +190,11 @@ + goto fail; + } + +- pid = __clone(child, stack+sizeof stack, +- CLONE_VM|CLONE_VFORK|SIGCHLD, &args); ++ pid = fork(); ++ if (pid == 0) { ++ _exit(child(&args)); ++ } ++ + close(args.p[1]); + UNLOCK(__abort_lock); + diff --git a/sysa/run-after-fiwix.kaem b/sysa/run-after-fiwix.kaem new file mode 100755 index 0000000..43c3284 --- /dev/null +++ b/sysa/run-after-fiwix.kaem @@ -0,0 +1,90 @@ +#!/bin/sh + +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# SPDX-FileCopyrightText: 2021 Paul Dersey +# SPDX-FileCopyrightText: 2020-2022 fosslinux +# SPDX-FileCopyrightText: 2022 Dor Askayo +# +# SPDX-License-Identifier: GPL-3.0-or-later + +set -ex + +ARCH_DIR="x86" +ARCH="x86" +ARCH_DIR="x86" +M2LIBC="M2libc" +TOOLS="${ARCH_DIR}/bin" +BLOOD_FLAG=" " +BASE_ADDRESS="0x08048000" +ENDIAN_FLAG="--little-endian" +BINDIR="${ARCH_DIR}/bin" +BUILDDIR="${ARCH_DIR}/artifact" + +sysa=/sysa +distfiles=/sysa/distfiles +prefix=/usr +bindir=${prefix}/bin +libdir=${prefix}/lib +incdir=${prefix}/include +srcdir=${prefix}/src +TMPDIR=/tmp # tmpdir is needed for patch to work + +PATH=/usr/bin + +libdir=${libdir}/mes + +# make +pkg="make-3.82" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# gzip +pkg="gzip-1.2.4" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# tar +pkg="tar-1.12" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# sed +pkg="sed-4.0.9" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# patch +pkg="patch-2.5.9" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# bzip2 +pkg="bzip2-1.0.8" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# coreutils +pkg="coreutils-5.0" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# heirloom-devtools +pkg="heirloom-devtools-070527" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +# bash +pkg="bash-2.05b" +cd ${pkg} +kaem --file ${pkg}.kaem +cd .. + +exec bash run.sh diff --git a/sysa/run.kaem b/sysa/run.kaem index f12d3b5..eb5e7bb 100755 --- a/sysa/run.kaem +++ b/sysa/run.kaem @@ -14,6 +14,9 @@ M2LIBC_PATH=/M2libc M2-Mesoplanet --architecture ${ARCH} -f checksum-transcriber.c -o ${bindir}/checksum-transcriber sha256sum -c checksum-transcriber.SHA256SUM +# simple patch tool based on before and after chunks +M2-Mesoplanet --architecture x86 -f simple-patch.c -o /x86/bin/simple-patch + # Environmental variables needed for mes NYACC_PKG=nyacc-1.00.2 MES_VERSION=0.24.2 @@ -42,58 +45,30 @@ cd ${pkg} kaem --file ${pkg}.kaem cd .. -# make -pkg="make-3.82" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. +if match x${KERNEL_BOOTSTRAP} xTrue; then + # The Fiwix kernel + pkg="fiwix-1.4.0-lb1" + cd ${pkg} + kaem --verbose --file ${pkg}.kaem + cd .. -# gzip -pkg="gzip-1.2.4" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. + # ext2 file system library for Fiwix + pkg="lwext4-1.0.0-lb1" + cd ${pkg} + kaem --verbose --file ${pkg}.kaem + cd .. -# tar -pkg="tar-1.12" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. + # Build the ext2 image + make_fiwix_initrd -# sed -pkg="sed-4.0.9" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. + # Live boot loader for Fiwix + pkg="kexec-fiwix" + cd ${pkg} + kaem --verbose --file ${pkg}.kaem + cd .. -# patch -pkg="patch-2.5.9" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. - -# bzip2 -pkg="bzip2-1.0.8" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. - -# coreutils -pkg="coreutils-5.0" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. - -# heirloom-devtools -pkg="heirloom-devtools-070527" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. - -# bash -pkg="bash-2.05b" -cd ${pkg} -kaem --file ${pkg}.kaem -cd .. - -exec bash run.sh + # Boot Fiwix + kexec-fiwix +else + exec kaem --verbose --file run-after-fiwix.kaem +fi diff --git a/sysa/run.sh b/sysa/run.sh index a19b3b2..4fa17fd 100755 --- a/sysa/run.sh +++ b/sysa/run.sh @@ -170,8 +170,6 @@ build autoconf-2.69 build libtool-2.2.4 -build bash-2.05b - cat > .env <<- EOF export PATH=${PATH} PREFIX=${PREFIX} diff --git a/sysa/run2.sh b/sysa/run2.sh index d964d20..8ebb756 100755 --- a/sysa/run2.sh +++ b/sysa/run2.sh @@ -73,11 +73,16 @@ build ed-1.4 build bc-1.07.1 +if [ "${CHROOT}" = False ]; then + # Save because linux deletes all distfiles to save space + cp "${DISTFILES}"/musl-1.2.3.tar.gz "${SOURCES}"/musl-1.2.3 +fi + mkdir -p /sysc/distfiles cp "${DISTFILES}"/curl-7.88.1.tar.bz2 /sysc/distfiles # Clear up some RAM space -grep --no-filename '^build' "${SOURCES}"/run*.sh | sed "s/build //" | sed "s/ .*$//" | while read -r p ; do +grep --no-filename '^build' "${SOURCES}"/run*.sh | grep -v musl-1.2.3 | sed "s/build //" | sed "s/ .*$//" | while read -r p ; do rm -rf "${SOURCES:?}/${p:?}" done @@ -86,13 +91,22 @@ if [ "${CHROOT}" = False ]; then build linux-4.9.10 - create_sysb - go_sysb -fi + build musl-1.2.3 '' no-patches -# In chroot mode transition directly into System C. -SYSC=/sysc_image -sys_transfer "${SYSC}" /sysc gzip patch -if [ "${CHROOT_ONLY_SYSA}" != True ]; then - exec chroot "${SYSC}" /init + create_sysb + if [ "${KERNEL_BOOTSTRAP}" = True ]; then + echo "Kernel bootstrapping successful." + echo "NOTE: Transition to Linux and building remaining packages is under development." + else + go_sysb + fi +else + build musl-1.2.3 '' no-patches + + # In chroot mode transition directly into System C. + SYSC=/sysc_image + sys_transfer "${SYSC}" /sysc gzip patch + if [ "${CHROOT_ONLY_SYSA}" != True ]; then + exec chroot "${SYSC}" /init + fi fi diff --git a/sysa/simple-patch.c b/sysa/simple-patch.c new file mode 100644 index 0000000..ed6faea --- /dev/null +++ b/sysa/simple-patch.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include "M2libc/bootstrappable.h" + +/* +SPDX-FileCopyrightText: 2023 Richard Masters +SPDX-License-Identifier: MIT + +Simple Patch program. + +This program is written in a subset of C called M2, which is from the +stage0-posix bootstrap project. + +Example usage: +./simple-patch file_to_patch before_pattern_file after_pattern_file + +*/ + +// function prototypes +void read_file_or_die(char *file_name, char **buffer, int *file_size); +void patch_buffer_or_die(char *patch_file_before_buffer, int patch_file_before_size, + char *before_pattern_buffer, int before_pattern_size, + char *after_pattern_buffer, int after_pattern_size, + char *patch_file_after_buffer); +void writestr_fd(int fd, char *str); +int memsame(char *search_buffer, int search_size, + char *pattern_buffer, int pattern_size); + + +int main(int argc, char **argv) { + char *patch_file_before_buffer; + int patch_file_before_size; + + char *before_pattern_buffer; + int before_pattern_size; + + char *after_pattern_buffer; + int after_pattern_size; + + int patch_file_after_size; + char *patch_file_after_buffer; + + int patch_file_fd; + + read_file_or_die(argv[1], &patch_file_before_buffer, &patch_file_before_size); + read_file_or_die(argv[2], &before_pattern_buffer, &before_pattern_size); + read_file_or_die(argv[3], &after_pattern_buffer, &after_pattern_size); + + patch_file_after_size = patch_file_before_size - before_pattern_size + after_pattern_size; + patch_file_after_buffer = calloc(patch_file_after_size, sizeof(char)); + + patch_buffer_or_die(patch_file_before_buffer, patch_file_before_size, + before_pattern_buffer, before_pattern_size, + after_pattern_buffer, after_pattern_size, + patch_file_after_buffer); + + patch_file_fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0); + write(patch_file_fd, patch_file_after_buffer, patch_file_after_size); + close(patch_file_fd); + + return EXIT_SUCCESS; +} + + +void read_file_or_die(char *file_name, char **buffer, int *file_size) { + int file_fd; + int num_bytes_read; + + file_fd = open(file_name, O_RDONLY, 0); + if (file_fd == -1) { + writestr_fd(2, "Could not open file: "); + writestr_fd(2, file_name); + writestr_fd(2, "\n"); + exit(1); + } + // determine file size + *file_size = lseek(file_fd, 0, SEEK_END); + // go back to beginning of file + lseek(file_fd, 0, SEEK_SET); + // alloc a buffer to read the entire file + *buffer = calloc(*file_size, sizeof(char)); + + // read the entire patch file + num_bytes_read = read(file_fd, *buffer, *file_size); + if (num_bytes_read != *file_size) { + writestr_fd(2, "Could not read file: "); + writestr_fd(2, file_name); + writestr_fd(2, "\n"); + exit(1); + } + close(file_fd); +} + +void patch_buffer_or_die(char *patch_file_before_buffer, int patch_file_before_size, + char *before_pattern_buffer, int before_pattern_size, + char *after_pattern_buffer, int after_pattern_size, + char *patch_file_after_buffer) { + + char *pos = patch_file_before_buffer; + int prefix_len = 0; + + // look for the pattern at every offset + while (prefix_len < patch_file_before_size) { + // if we find the pattern, replace it and return + if (memsame(pos, patch_file_before_size - prefix_len, before_pattern_buffer, before_pattern_size)) { + memcpy(patch_file_after_buffer, patch_file_before_buffer, prefix_len); + memcpy(patch_file_after_buffer + prefix_len, after_pattern_buffer, after_pattern_size); + memcpy(patch_file_after_buffer + prefix_len + after_pattern_size, + patch_file_before_buffer + prefix_len + before_pattern_size, + patch_file_before_size - (prefix_len + before_pattern_size)); + return; + } + pos = pos + 1; + prefix_len = prefix_len + 1; + } + + /* if we don't find the pattern, something is wrong, so exit with error */ + exit(1); +} + +/* + Write the string to the given file descriptor. +*/ +void writestr_fd(int fd, char *str) { + write(fd, str, strlen(str)); +} + +/* + Is the pattern located at the start of the search buffer + (and not exceeding the length of the search buffer)? +*/ + +int memsame(char *search_buffer, int search_size, + char *pattern_buffer, int pattern_size) { + int check_offset = 0; + + if (pattern_size > search_size) { + return FALSE; + } + while (check_offset < pattern_size) { + if (search_buffer[check_offset] != pattern_buffer[check_offset]) { + return FALSE; + } + check_offset = check_offset + 1; + } + return TRUE; +} diff --git a/sysa/tcc-0.9.26/simple-patches/addback-fileopen.after b/sysa/tcc-0.9.26/simple-patches/addback-fileopen.after new file mode 100644 index 0000000..0e981f0 --- /dev/null +++ b/sysa/tcc-0.9.26/simple-patches/addback-fileopen.after @@ -0,0 +1,7 @@ + if ((fh = fopen(argv[i_lib], "wb")) == NULL) + { + fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); + goto the_end; + } + + // write header diff --git a/sysa/tcc-0.9.26/simple-patches/addback-fileopen.before b/sysa/tcc-0.9.26/simple-patches/addback-fileopen.before new file mode 100644 index 0000000..116b347 --- /dev/null +++ b/sysa/tcc-0.9.26/simple-patches/addback-fileopen.before @@ -0,0 +1 @@ + // write header diff --git a/sysa/tcc-0.9.26/simple-patches/remove-fileopen.after b/sysa/tcc-0.9.26/simple-patches/remove-fileopen.after new file mode 100644 index 0000000..44fb725 --- /dev/null +++ b/sysa/tcc-0.9.26/simple-patches/remove-fileopen.after @@ -0,0 +1,2 @@ + if (ret == 1) + return ar_usage(ret); diff --git a/sysa/tcc-0.9.26/simple-patches/remove-fileopen.before b/sysa/tcc-0.9.26/simple-patches/remove-fileopen.before new file mode 100644 index 0000000..4641e1b --- /dev/null +++ b/sysa/tcc-0.9.26/simple-patches/remove-fileopen.before @@ -0,0 +1,8 @@ + if (ret == 1) + return ar_usage(ret); + + if ((fh = fopen(argv[i_lib], "wb")) == NULL) + { + fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); + goto the_end; + } diff --git a/sysa/tcc-0.9.26/tcc-0.9.26.checksums b/sysa/tcc-0.9.26/tcc-0.9.26.checksums index 748cf4f..51ef9a9 100644 --- a/sysa/tcc-0.9.26/tcc-0.9.26.checksums +++ b/sysa/tcc-0.9.26/tcc-0.9.26.checksums @@ -1,10 +1,10 @@ -2313ba8ce505e08cdb2ce480d3195c3f66a07c0d1a4ce85570e9017f59cc0d4f /usr/bin/mes-tcc -01a56f6ae93d168d8f0122558985b14ab35e36b85934dec8bbf988faabc6db12 /usr/bin/boot0-tcc -07f9ad107c2df7f6131717d3e3de8eeceb25767bb28c7fd2f39a18cf8fbaf016 /usr/bin/boot1-tcc -867e4aafd746de4aea5efeb38b6f878e4cc9440a403c42e4739954d9f85a8cc8 /usr/bin/boot2-tcc -3bb6782f6033946d70d2abb7b4a166ecafe739cbb0201f56e3ae121d003f5e1a /usr/bin/boot3-tcc -bce041b2af0e1bd580f269216e46d7d011ddfccd6dcc464a62eef9da1234b0a5 /usr/bin/boot4-tcc -460211eed1fb086bbb3327a26f56d638029bc2d7b313e06071c26e38fcf06b7f /usr/bin/tcc +7897c2ba182e92765856a9e3ddd2bdfcd69988b3ddc45b3ef932dc3ec041041a /usr/bin/mes-tcc +64bdb36f0048744957454b6ad186d37db4a7fcc392f67bf052b9bc7ec033b963 /usr/bin/boot0-tcc +18af79e0e3c4bfeaced2b0867561bc9fd370cbfcc78860de5a70926374ba7c53 /usr/bin/boot1-tcc +d6fa0c2006f6c8fefb4f3750fade14aa884670637098857d06aef3c7a9bd02d8 /usr/bin/boot2-tcc +93b2c1c567f5938435fbe6c0115276f6073bd46a0a92791b164ca2752180caf5 /usr/bin/boot3-tcc +a40305e6d2acb3dc64dbc80f64952431f4728eeff03f6e7c91c737cbf6e1bdda /usr/bin/boot4-tcc +c56d99e284dfecae047e792b049c0cee022452f13262d6b3c869ec1c9935b276 /usr/bin/tcc 96f93f2d281ee6996767b25fbff4441e8335e7eeaeab060c1d4b698366b277c9 /usr/lib/mes/libc.a 12c07ae103e7e3b390150a79e5c600d88de14e9bb73a066f6342582729ef5a3f /usr/lib/mes/libgetopt.a d1168ee9b528e39f0b40e8d51fb7fa3619c4a5ee928137f7faf6d0879b0916b0 /usr/lib/mes/crt1.o diff --git a/sysa/tcc-0.9.26/tcc-0.9.26.kaem b/sysa/tcc-0.9.26/tcc-0.9.26.kaem index 1077a56..7049879 100755 --- a/sysa/tcc-0.9.26/tcc-0.9.26.kaem +++ b/sysa/tcc-0.9.26/tcc-0.9.26.kaem @@ -31,6 +31,11 @@ cd .. cd build untar --file ../src/${TCC_TAR}.tar +/x86/bin/simple-patch /sysa/tcc-0.9.26/build/tcc-0.9.26-1136-g5bba73cc/tcctools.c \ + /sysa/tcc-0.9.26/simple-patches/remove-fileopen.before /sysa/tcc-0.9.26/simple-patches/remove-fileopen.after +/x86/bin/simple-patch /sysa/tcc-0.9.26/build/tcc-0.9.26-1136-g5bba73cc/tcctools.c \ + /sysa/tcc-0.9.26/simple-patches/addback-fileopen.before /sysa/tcc-0.9.26/simple-patches/addback-fileopen.after + untar --non-strict --file ../src/${MES_PKG}.tar # Create config.h @@ -60,6 +65,7 @@ ${MES} --no-auto-compile -e main ${bindir}/mescc.scm -- \ -D ONE_SOURCE=1 \ tcc.c ${MES} --no-auto-compile -e main ${bindir}/mescc.scm -- \ + --base-address 0x08048000 \ -o mes-tcc \ -L ${libdir} \ tcc.s \ diff --git a/sysa/tcc-0.9.27/simple-patches/addback-fileopen.after b/sysa/tcc-0.9.27/simple-patches/addback-fileopen.after new file mode 100644 index 0000000..0e981f0 --- /dev/null +++ b/sysa/tcc-0.9.27/simple-patches/addback-fileopen.after @@ -0,0 +1,7 @@ + if ((fh = fopen(argv[i_lib], "wb")) == NULL) + { + fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); + goto the_end; + } + + // write header diff --git a/sysa/tcc-0.9.27/simple-patches/addback-fileopen.before b/sysa/tcc-0.9.27/simple-patches/addback-fileopen.before new file mode 100644 index 0000000..116b347 --- /dev/null +++ b/sysa/tcc-0.9.27/simple-patches/addback-fileopen.before @@ -0,0 +1 @@ + // write header diff --git a/sysa/tcc-0.9.27/simple-patches/fiwix-paddr.after b/sysa/tcc-0.9.27/simple-patches/fiwix-paddr.after new file mode 100644 index 0000000..4282496 --- /dev/null +++ b/sysa/tcc-0.9.27/simple-patches/fiwix-paddr.after @@ -0,0 +1,3 @@ + ph->p_paddr = ph->p_vaddr; + if (ph->p_paddr >= 0xC0000000) + ph->p_paddr = ph->p_paddr - 0xC0000000; diff --git a/sysa/tcc-0.9.27/simple-patches/fiwix-paddr.before b/sysa/tcc-0.9.27/simple-patches/fiwix-paddr.before new file mode 100644 index 0000000..316b48f --- /dev/null +++ b/sysa/tcc-0.9.27/simple-patches/fiwix-paddr.before @@ -0,0 +1 @@ + ph->p_paddr = ph->p_vaddr; diff --git a/sysa/tcc-0.9.27/simple-patches/remove-fileopen.after b/sysa/tcc-0.9.27/simple-patches/remove-fileopen.after new file mode 100644 index 0000000..44fb725 --- /dev/null +++ b/sysa/tcc-0.9.27/simple-patches/remove-fileopen.after @@ -0,0 +1,2 @@ + if (ret == 1) + return ar_usage(ret); diff --git a/sysa/tcc-0.9.27/simple-patches/remove-fileopen.before b/sysa/tcc-0.9.27/simple-patches/remove-fileopen.before new file mode 100644 index 0000000..4641e1b --- /dev/null +++ b/sysa/tcc-0.9.27/simple-patches/remove-fileopen.before @@ -0,0 +1,8 @@ + if (ret == 1) + return ar_usage(ret); + + if ((fh = fopen(argv[i_lib], "wb")) == NULL) + { + fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); + goto the_end; + } diff --git a/sysa/tcc-0.9.27/tcc-0.9.27.checksums b/sysa/tcc-0.9.27/tcc-0.9.27.checksums index 2afc9d5..c19c5a0 100644 --- a/sysa/tcc-0.9.27/tcc-0.9.27.checksums +++ b/sysa/tcc-0.9.27/tcc-0.9.27.checksums @@ -1 +1 @@ -c75b7969af5d84c2d6f33674b8372ca3450ec8632ba1523cf8858e124acd667f /usr/bin/tcc +5cd0428fdcb9dc579cdf496a4fd974c4d2a941f76f2ce2049a1c2ff477f64002 /usr/bin/tcc diff --git a/sysa/tcc-0.9.27/tcc-0.9.27.kaem b/sysa/tcc-0.9.27/tcc-0.9.27.kaem index a774950..c857591 100755 --- a/sysa/tcc-0.9.27/tcc-0.9.27.kaem +++ b/sysa/tcc-0.9.27/tcc-0.9.27.kaem @@ -20,6 +20,12 @@ cd .. cd build untar --file ../src/${pkg}.tar +/x86/bin/simple-patch /sysa/tcc-0.9.27/build/tcc-0.9.27/tcctools.c \ + /sysa/tcc-0.9.27/simple-patches/remove-fileopen.before /sysa/tcc-0.9.27/simple-patches/remove-fileopen.after +/x86/bin/simple-patch /sysa/tcc-0.9.27/build/tcc-0.9.27/tcctools.c \ + /sysa/tcc-0.9.27/simple-patches/addback-fileopen.before /sysa/tcc-0.9.27/simple-patches/addback-fileopen.after +/x86/bin/simple-patch /sysa/tcc-0.9.27/build/tcc-0.9.27/tccelf.c \ + /sysa/tcc-0.9.27/simple-patches/fiwix-paddr.before /sysa/tcc-0.9.27/simple-patches/fiwix-paddr.after untar --non-strict --file ../src/${MES_PKG}.tar cd ${pkg} diff --git a/sysc/init b/sysc/init index cffdd6d..b32a0e1 100755 --- a/sysc/init +++ b/sysc/init @@ -55,7 +55,7 @@ install_tar libtool-2.2.4 0 install_tar linux-headers-5.10.41 0 install_tar m4-1.4.7 0 install_tar make-3.82 0 -install_tar musl-1.2.3 0 +install_tar musl-1.2.3 1 install_tar perl-5.6.2 0 install_tar util-linux-2.19.1 0