From a2fcf1ced926c7c2bd5b75a2722d677ea93b086a Mon Sep 17 00:00:00 2001 From: rick-masters Date: Wed, 10 May 2023 14:33:42 +0000 Subject: [PATCH 1/7] Complete the kernel bootstrap by adding kexec of Linux from Fiwix. A tiny bootloader bootstrap has been added to compile the builder-hex0 kernel from hex0 source. The boot compiler is builder-hex0-x86-stage1.hex0 and builder-hex0-x86-stage1.bin. The builder-hex0 kernel is now named builder-hex0-x86-stage2.hex0. The inclusion of a binary seed resolves the problem with the previous strategy which used an architecture-specific hex0 compiler. If sysb detects a full disk (i.e. DISK=sda) it now partitions the disk unconditionally because previously fdisk was reporting existing but empty partitions which resulted in no parititions being created. e2fsprogs is now built with --disable-tls because musl was built on Fiwix without full threading support and mkfs.ext4 was crashing without disabling thread local storage. kexec-linux writes the linux kernel and initramfs to a RAM drive on Fiwix which ensure a pre-allocated contiguous memory block. The following is written to the ram drive: a 32-bit number which is the size of the kernel in bytes, a 32-bit number which is the size of the initramfs in bytes, followed by the Linux kernel image, followed by the initramfs. kexec-fiwix invokes a sync syscall to ensure all writes are flushed to the ram drive and then initiates the kexec by shutting down Fiwix with a reboot syscall. Fiwix knows whether and how to perform the kexec based on kernel parameters passed to it. --- kernel-bootstrap/builder-hex0-x86-stage1.bin | Bin 0 -> 200 bytes kernel-bootstrap/builder-hex0-x86-stage1.hex0 | 209 ++++++++ ...-x86.hex0 => builder-hex0-x86-stage2.hex0} | 479 +++++++++--------- rootfs.py | 3 +- sysa.py | 22 +- sysa/SHA256SUMS.pkgs | 2 +- sysa/e2fsprogs-1.45.7/e2fsprogs-1.45.7.sh | 1 + .../fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.checksums | 1 - sysa/fiwix-1.4.0-lb1/sources | 1 - .../fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums | 1 + .../fiwix-1.4.0-lb2.kaem} | 8 +- sysa/fiwix-1.4.0-lb2/sources | 1 + sysa/kexec-fiwix/kexec-fiwix.checksums | 2 +- sysa/kexec-fiwix/src/kexec-fiwix.c | 4 +- sysa/kexec-linux/kexec-linux.checksums | 1 + sysa/kexec-linux/kexec-linux.kaem | 16 + sysa/kexec-linux/src/kexec-linux.c | 91 ++++ .../early-artifacts-needed-after-fiwix.txt | 1 + .../files/make_fiwix_initrd.c | 12 + .../lwext4-1.0.0-lb1.checksums | 2 +- sysa/run.kaem | 8 +- sysa/run2.sh | 31 +- sysb/run.sh | 14 +- 23 files changed, 633 insertions(+), 277 deletions(-) create mode 100644 kernel-bootstrap/builder-hex0-x86-stage1.bin create mode 100644 kernel-bootstrap/builder-hex0-x86-stage1.hex0 rename kernel-bootstrap/{builder-hex0-x86.hex0 => builder-hex0-x86-stage2.hex0} (88%) delete mode 100644 sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.checksums delete mode 100644 sysa/fiwix-1.4.0-lb1/sources create mode 100644 sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums rename sysa/{fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem => fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.kaem} (95%) create mode 100644 sysa/fiwix-1.4.0-lb2/sources create mode 100644 sysa/kexec-linux/kexec-linux.checksums create mode 100755 sysa/kexec-linux/kexec-linux.kaem create mode 100644 sysa/kexec-linux/src/kexec-linux.c diff --git a/kernel-bootstrap/builder-hex0-x86-stage1.bin b/kernel-bootstrap/builder-hex0-x86-stage1.bin new file mode 100644 index 0000000000000000000000000000000000000000..207ce840f719eeb24c7c9a4d2b28f959ae3e5abf GIT binary patch literal 200 zcmV;(05|_Jz>e6Cz>d(o0C)Vq0Ddvsnvr|}0EEDFO*|uXC_FoKBs^w+>pWq61T0tU zBRocb-#kHl1S~h}7d$zC(>ySI&nz(O3!0I9002A+b@%JQgxhrqz~BUk$Nt0Xvk1qC z_^L76>#FJiegFVaQ;GYu0HHZTUg5i00931Q&Cb@ zSG$aSiw}x-0*gljJ^ul813>E!zW{ieY +# SPDX-License-Identifier: MIT +# +# Builder-Hex0 is a small bootable machine image which acts as +# a bootloader using a hex0 compiler. It compiles hex0 code starting +# at sector 2, placing the compiled code at address 0x7E00 and then +# and then jumps to the resulting binary. +# +# hex0 is a "language" for binary encoding in hexadecimal +# with support for comments. + +# Functions: +# _start +# read_sector +# read +# compile + +#------------------------------------------------------------ +# Memory: +# 9FC00 - FFFFF BIOS +# 7C00 - 7E00 MBR/code +# 7A00 - 7BFF sector read buffer +# < 7700 real mode stack +#------------------------------------------------------------ + + +# ------------------------------------------------------------ +# Stub Entry Point +# +# boot drive is in dl +# +#[7C00][15] +#:_start + +# 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 77 # mov sp, 0x7700 +FC # cld ; clear direction flag + +#---------------------------------------- +# Compile hex0 to binary +# compile(dl=boot_drive): +#[7C0C] +BF 00 7E # mov di, 0x7E00 + +# this flag is set after the first digit is seen +31 DB # xor bx,bx + +#:read_loop +9A 91 7C 00 00 # call read +84 C0 # test al, al +74 4D # jz finish + +3C 23 # cmp al, '#' +74 28 # jz skip_comment + +3C 3B # cmp ';' +74 24 # jz skip_comment + +3C 66 # cmp al, 'f' +7F EB # jg 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 23 # jmp maybe_store + +#:maybe_upper +3C 46 # cmp al, 'F' +7F DF # jg 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 17 # jmp maybe_store + +#:maybe_digit +3C 39 # cmp al, '9' +7F D3 # jg read_loop + +3C 30 # cmp al, '0' +7C CF # jl read_loop + +# Handle 0 to 9 +2C 30 # sub al, '0' == x30 +EB 0B # jmp maybe_store + +#:skip_comment +9A 91 7C 00 00 # call read +3C 0A # cmp al, '\n' +75 F7 # jnz skip_comment +EB C0 # jmp 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 B3 # jmp read_loop + +# If on second digit, store and clear state +#:second_digit +08 C7 # or bh, al +88 F8 # mov al, bh +AA # stosb +31 DB # xor bx, bx + +EB AA # jmp read_loop + +#:finish +EA 00 7E 00 00 # ljmp $0000:7E00 ; jump to stage2 + + +#[7C6C][ ] +#:read_sector(di = *dest_addr, cx=cylinder/sector, dh = head, dl=drive) +# +# returns: di - next byte to write to +# cx,dh - next disk sector to read from +# +50 # push ax +53 # push bx + +89 FB # mov bx, di ; int 13 writes to bx + +#:read_one_loop +B4 02 # mov ah, 2 ; rw mode = 02 (read) +B0 01 # mov al, 1 ; num_sectors +CD 13 # int 0x13 +72 F8 # jnc read_one_loop +3C 01 # cmp al, 1 +75 F4 # jnz read_one_loop + +80 F9 3F # cmp cl, 0x3f ; if sector_num == max_sector +74 04 # jz next_head ; goto next_head +FE C1 # inc cl ; else sector_num++; +EB 04 # jmp cleanup + +#next_head: +FE C6 # inc dh ; else head_num++ +B1 01 # mov cl, 1 ; sector = 1 + +5B # pop bx +58 # pop ax +CB # retf + + +#---------------------------------------- +# last_read_location +#[7C8C] +02 00 ; last_cylinder/sector +00 ; last_head +FF 01 ; last_byte + +#[7C91] +#:read() +53 # push bx +51 # push cx +52 # push dx +56 # push si +57 # push di + +# get current position +BB 8C 7C # mov bx, last_read_location +8B 0F # mov cx, [bx] +8A 77 02 # mov dh, [bx+2] +8B 47 03 # mov ax, [bx+3] + +#end of sector? +3D FF 01 # cmp ax, 0x01ff +74 03 # je next sector + +#nextchar: +40 # inc ax +EB 0F # jmp getchar + +#read next sector +BF 00 78 # mov di, 0x7800 +9A 6C 7C 00 00 # call read_sector +# save new location and offset +89 0F # mov [bx], cx +88 77 02 # mov [bx+2], dh +31 C0 # xor ax, ax + +#getchar: +89 47 03 # mov [bx+3], ax +BE 00 78 # mov si, 0x7800 +89 C3 # mov bx, ax +8A 00 # mov al, [si+bx] + +#finish: +5F # pop di +5E # pop si +5A # pop dx +59 # pop cx +5B # pop bx +CB # ret diff --git a/kernel-bootstrap/builder-hex0-x86.hex0 b/kernel-bootstrap/builder-hex0-x86-stage2.hex0 similarity index 88% rename from kernel-bootstrap/builder-hex0-x86.hex0 rename to kernel-bootstrap/builder-hex0-x86-stage2.hex0 index c8eeda1..241295a 100644 --- a/kernel-bootstrap/builder-hex0-x86.hex0 +++ b/kernel-bootstrap/builder-hex0-x86-stage2.hex0 @@ -10,7 +10,7 @@ # 16 bit Functions # ---------------- -# MBR_entry +# stage2_entry # console_putc_16 # console_put_hex_16 # @@ -20,7 +20,7 @@ # write_sectors_16 # # [GDT data] -# MBR_main +# stage2_main # 32 bit Functions # ---------------- @@ -108,13 +108,13 @@ #------------------------------------------------------------ -#[7C00] -#:MBR_entry +#[7E00] +#:stage2_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. +# do that first. We far jump to stage2_main in order to set CS. 31 C0 # xor ax, ax 8E D8 # mov ds, ax 8E C0 # mov es, ax @@ -122,11 +122,11 @@ BC 00 7B # mov sp, 0x7B00 FC # cld ; clear direction flag -EA 26 7D 00 00 # jmp MBR_main +EA 26 7F 00 00 # jmp stage2_main #------------------------ -#[7C11] +#[7E11] #:console_putc_16 # input: # al: char to print @@ -160,7 +160,7 @@ CB # retf #------------------------ -#[7C27] +#[7E27] #:console_put_hex_16 # input: # al: byte to print as hex @@ -180,7 +180,7 @@ EB 02 # jmp print1 04 37 # add al, 0x37 #:print1 -9A 11 7C 00 00 # call console_putc_16 +9A 11 7E 00 00 # call console_putc_16 58 # pop ax ; restore original al 50 # push ax ; @@ -197,7 +197,7 @@ EB 02 # jmp print2 04 37 # add al, 0x37 #:print2 -9A 11 7C 00 00 # call console_putc_16 +9A 11 7E 00 00 # call console_putc_16 58 # pop ax CB # retf @@ -205,23 +205,23 @@ CB # retf #------------- -#[7C51] +#[7E51] #:boot_drive 80 #------------- -#[7C52] +#[7E52] #:max_head 0F #------------- -#[7C53] +#[7E53] #:max_sector 3F #------------------------ -#[7C54] +#[7E54] #:get_drive_geometry # input: # dl: drive @@ -235,9 +235,9 @@ CB # retf B4 08 # mov ah, 8 ; get drive parameters CD 13 # int 0x13 -88 36 52 7C # mov [max_head], dh ; max_head +88 36 52 7E # mov [max_head], dh ; max_head 80 E1 3F # and cl, 0x3f -88 0E 53 7C # mov [max_sector], cl ; num_sectors +88 0E 53 7E # mov [max_sector], cl ; num_sectors 5F # pop di 07 # pop es @@ -245,7 +245,7 @@ CB # retf #------------------------ -#[7C6C] +#[7E6C] #:next_sector # inputs: # cx: cylinder/sector @@ -255,13 +255,13 @@ CB # retf 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 +3A 06 53 7E # 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 +3A 36 52 7E # 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 @@ -289,7 +289,7 @@ CB # retf #------------------------ -#[7CA5] +#[7EA5] #:read_sectors_16 # inputs: # di: dest_addr @@ -309,7 +309,7 @@ CB # retf 89 FB # mov bx, di ; int 13 writes to bx #:read_one_loop -8A 16 51 7C # mov dl, [boot_drive] +8A 16 51 7E # mov dl, [boot_drive] B4 02 # mov ah, 2 ; rw mode = 02 (read) B0 01 # mov al, 1 ; num_sectors CD 13 # int 0x13 @@ -318,7 +318,7 @@ CD 13 # int 0x13 75 F0 # jnz read_one_loop # advance and maybe continue -9A 6C 7C 00 00 # call next_sector +9A 6C 7E 00 00 # call next_sector # we read one sector, advance 81 C3 00 02 # add bx, 0x200 @@ -335,7 +335,7 @@ CB # retf #------------------------ -#[7CCE] +#[7ECE] #:write_sectors_16 # inputs: # si: source_addr @@ -355,7 +355,7 @@ CB # retf 89 F3 # mov bx, si ; int 13 reads from [bx] #:write_one_loop -8A 16 51 7C # mov dl, [boot_drive] +8A 16 51 7E # mov dl, [boot_drive] B4 03 # mov ah, 3 ; rw mode = 03 (write) B0 01 # mov al, 1 ; num_sectors CD 13 # int 0x13 @@ -364,7 +364,7 @@ CD 13 # int 0x13 75 F0 # jnz write_one_loop # advance and maybe continue -9A 6C 7C 00 00 # call next_sector +9A 6C 7E 00 00 # call next_sector # we write one sector, advance 81 C3 00 02 # add bx, 0x200 @@ -386,7 +386,7 @@ CB # retf #--------------------------------------------- # The Global Descriptor Table for 32 bit mode. #--------------------------------------------- -#[7CF8] +#[7EF8] #:GDT_start 00 00 00 00 00 00 00 00 @@ -435,40 +435,43 @@ FF FF # limit 0:15 00 # base 24:31 #------ -#[7D20] +#[7F20] #:GDT_locator 27 00 # length -F8 7C 00 00 # GDT_start +F8 7E 00 00 # GDT_start #------------------------ -#[7D26] -#:MBR_main +#[7F26] +#:stage2_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 +88 16 51 7E # mov [boot_drive], dl +9A 54 7E 00 00 # call get_drive_geometry() +BF 00 80 # mov di, 0x8000 ; 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 + +# XXX disabled - stage1 compiles code +90 90 90 90 90 +#9A A5 7E 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 01 16 20 7F # 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 +EA 59 7F 08 00 # jmp setup_32bit ; sets CS #------ -#[7D59] +#[7F59] #:setup_32bit 66 B8 10 00 # mov ax, 0x0010 ; data descriptor 8E D8 # mov ds, ax @@ -479,45 +482,45 @@ EA 59 7D 08 00 # jmp setup_32bit ; sets CS 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 +9A 7C 7F 00 00 08 00 # call setup_interrupt_handlers +EA A1 8A 00 00 08 00 # jmp internalshell #---------------------------------------- -#[7D7C] +#[7F7C] #: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 03 BC 7F # 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 03 D8 80 # 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 +0F 01 1D BD 7F 00 00 # lidt IDT_locator_32 FB # sti 5B # pop ebx CB # retf #---------------------------------------- -#[7DBC] +#[7FBC] #:stub_interrupt_handler CF # iret #---------------------------------------- -#[7DBD] +#[7FBD] #:IDT_locator_32 FF 07 # length 00 00 01 00 # IDT_start @@ -541,7 +544,7 @@ FF 07 # length # 7B00 <- top of real mode stack #---------------------------------------- -#[7DC5] +#[7FC5] #:enter_16bit_real FA # cli A3 08 7B 00 00 # mov [0x7B08], eax ; preserve so we can use these locally @@ -552,9 +555,9 @@ A3 08 7B 00 00 # mov [0x7B08], eax ; preserve so we can use these locall # 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 +EA DF 7F 00 00 18 00 # jmp 0x18:setup_16bit #------ -#[7DDF] +#[7FDF] #:setup_16bit B8 20 00 # mov eax, 0x0020 8E D0 # mov ss, eax @@ -568,14 +571,14 @@ BC 00 7B # mov sp, 0x7B00 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 +EA 00 80 00 00 # jmp 0000:XXXX real_mode # [7DFE] -# This is the DOS/MBR identifier at offset 510: -55 AA +# Unused +00 00 #------ -#[7E00] +#[8000] #:real_mode B8 00 00 # mov ax, 0x0 8E D8 # mov ds, ax @@ -585,7 +588,7 @@ B8 00 00 # mov ax, 0x0 8E C0 # mov es, ax BC 00 7B # mov sp, 0x7B00 FA # cli -0F 01 1E 22 7E # lidt IDT_locator_16 +0F 01 1E 22 80 # lidt IDT_locator_16 FB # sti # Using retf to set CS comes from here: # https://stackoverflow.com/questions/26448480/bios-interrupts-in-protected-mode @@ -598,27 +601,27 @@ A1 08 7B # mov ax, [0x7B08] ; restore from above CB # retf #------ -#[7E22] +#[8022] #:IDT_locator_16 -FF FF +FF 03 00 00 00 00 #---------------------------------------- -#[7E28] +#[8028] #: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 01 16 20 7F # 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 +EA 46 80 08 00 # jmp restore_32bit #------ -#[7E46] +#[8046] #:restore_32bit B8 10 00 00 00 # mov eax, 0x0010 ; data descriptor 8E D8 # mov ds, eax @@ -627,7 +630,7 @@ B8 10 00 00 00 # mov eax, 0x0010 ; data descriptor 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 +9A 7C 7F 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 @@ -639,26 +642,26 @@ C3 # ret #------------------------ -#[7E6F] +#[806F] #: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 +E8 51 FF FF FF # CALL enter_16bit_real, next=[8074] +9A 11 7E 00 00 # CALL console_putc_16(al) +9A 28 80 00 00 # CALL resume_32bit_mode CB # RETF #------------------------ -#[7E7F] +#[807F] #: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 +E8 41 FF FF FF # CALL enter_16bit_real, next=[8084] +9A 27 7E 00 00 # CALL console_put_hex_16(al) +9A 28 80 00 00 # CALL resume_32bit_mode CB # RETF #------------------------ -#[7E8F] +#[808F] #:console_puts # inputs # ds:si: string to print @@ -668,19 +671,19 @@ CB # RETF 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 +9A 6F 80 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 +9A 6F 80 00 00 08 00 # call console_putc 5E # pop esi 58 # pop eax CB # RETF #------------------------ -#[7EAD] +#[80AD] #:read_sectors # inputs: # di: dest_addr @@ -688,14 +691,14 @@ CB # RETF # 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 +E8 13 FF FF FF # CALL enter_16bit_real, next=[80B2] +9A A5 7E 00 00 # CALL read_sectors_16 +9A 28 80 00 00 # CALL resume_32bit_mode CB # RETF #------------------------ -#[7EBD] +#[80BD] #:write_sectors # inputs: # si: source_addr @@ -703,86 +706,86 @@ CB # RETF # 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 +E8 03 FF FF FF # CALL enter_16bit_real, next=[80C2] +9A CE 7E 00 00 # CALL write_sectors_16 +9A 28 80 00 00 # CALL resume_32bit_mode CB # RETF #------------------------ -#[7ECD] +#[80CD] #:reboot -E8 F3 FE FF FF # call enter_16bit_real, next=[7ED2] +E8 F3 FE FF FF # call enter_16bit_real, next=[80D2] FA # cli EA F0 FF 00 F0 # ljmp $F000:FFF0 ; reboot #------------------------ -#[7ED8] +#[80D8] #:syscall_interrupt_handler # 3C 01 # cmp al, 1 75 08 # jne try next -9A B7 84 00 00 08 00 # call handle_syscall_exit +9A B7 86 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 +9A B0 84 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 +9A 5B 83 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 +9A 3D 84 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 +9A 94 81 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 +9A 5E 82 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 +9A 0B 87 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 +9A 1E 85 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 +9A 60 86 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 +9A 25 87 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 +9A 0E 84 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 +9A 6D 87 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 +9A 83 87 00 00 08 00 # call handle_syscall_mkdir CF # iret # wait4 @@ -794,7 +797,7 @@ CF # iret 3C B7 # cmp al, 0xB7 75 08 # jne syscall_ok -9A 99 85 00 00 08 00 # call handle_syscall_getcwd +9A 99 87 00 00 08 00 # call handle_syscall_getcwd CF # iret #:syscall_ok @@ -804,17 +807,17 @@ CF # iret #------ -#[7F8C] +#[818C] #:next_filenum 04 00 00 00 #------ -#[7F90] +#[8190] #:next_file_address 00 00 00 54 #---------------------------------------- -#[7F94] +#[8194] #:handle_syscall_open # inputs: # ebx: filename @@ -825,7 +828,7 @@ CF # iret 56 # push esi 57 # push edi -9A 76 80 00 00 08 00 # call absolute_path +9A 76 82 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 @@ -857,19 +860,19 @@ FC # cld 89 F7 # mov edi, esi AA # stosb # Lookup directory -9A 13 81 00 00 08 00 # call find_file ; eax=find_file(ebx) +9A 13 83 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 +EA 59 82 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] +A1 8C 81 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 @@ -877,22 +880,22 @@ 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] +A1 8C 81 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] +8B 0D 90 81 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] +A1 8C 81 00 00 # mov eax, [next_filenum] ; return next_filenum +FF 05 8C 81 00 00 # inc [next_filenum] EB 18 # jmp syscall_open_finish #open_read -9A 13 81 00 00 08 00 # call find_file +9A 13 83 00 00 08 00 # call find_file 83 F8 FF # cmp eax, -1 74 34 # je syscall_open_finish_fail @@ -903,7 +906,7 @@ 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] +8B 35 1A 85 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] @@ -925,7 +928,7 @@ EB F4 # jmp find_slot_loop 89 4E 04 # mov [esi+0x4], ecx #-------- -#[8059] +#[8259] #:syscall_open_finish_fail 5F # pop edi @@ -936,13 +939,13 @@ CB # ret #---------------------------------------- -#[805E] +#[825E] #:handle_syscall_close # inputs: # ebx: fd 57 # push edi -8B 3D 1A 83 00 00 # mov edi, [&next_process_num] +8B 3D 1A 85 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 @@ -953,7 +956,7 @@ CB # ret #---------------------------------------- -#[8076] +#[8276] #:absolute_path # inputs: # ebx: path @@ -969,11 +972,11 @@ 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], '/' +80 3B 2F # cmp [ebx], '/' 74 18 # je strcpy_path_arg # get cwd -8B 35 1A 83 00 00 # mov esi, [&next_process_num] +8B 35 1A 85 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 @@ -1089,7 +1092,7 @@ CB #---------------------------------------- -#[8113] +#[8313] #:find_file # inputs: # ebx: file_name @@ -1101,7 +1104,7 @@ CB 56 # push esi 57 # push edi -A1 8C 7F 00 00 # mov eax, [next_filenum] +A1 8C 81 00 00 # mov eax, [next_filenum] 48 # dec eax 89 DE # mov esi, ebx @@ -1111,7 +1114,7 @@ A1 8C 7F 00 00 # mov eax, [next_filenum] 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 +9A C6 87 00 00 08 00 # call strcmp 74 08 # je find_file_finish 48 # dec eax EB E4 # jmp checkfile @@ -1128,14 +1131,14 @@ CB # ret #------------------------------------------------------------ -#[8145] +#[8345] #: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] +8B 3D 1A 85 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 @@ -1145,7 +1148,7 @@ CB # ret #------------------------------------------------------------ -#[815B] +#[835B] #:handle_syscall_read # inputs: # ecx: *return_char @@ -1171,7 +1174,7 @@ BB 00 00 00 01 # mov ebx, 0x01000000 66 8B 43 04 # mov ax, [ebx+4] #end of sector? -66 3D ff 01 # cmp ax, 0x01ff +66 3D FF 01 # cmp ax, 0x01ff 74 04 # je read_next_sector #:nextchar @@ -1181,7 +1184,7 @@ 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 +9A AD 80 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 @@ -1205,7 +1208,7 @@ 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 +9A 45 83 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 @@ -1218,7 +1221,7 @@ C1 E3 04 # shl ebx, 04 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] +8B 35 1A 85 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 @@ -1250,11 +1253,11 @@ CB # ret #------------------------------------------------------------ -#[820E] +#[840E] #:handle_syscall_brk 56 # push esi -A1 1A 83 00 00 # mov eax, [&next_process_num] +A1 1A 85 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] @@ -1289,7 +1292,7 @@ CB # ret #------------------------------------------------------------ -#[823D] +#[843D] #:handle_syscall_write # inputs: # ebx: file @@ -1311,7 +1314,7 @@ CB # ret 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 +9A 6F 80 00 00 08 00 # call console_putc 58 # pop eax ; restore num_written 40 # inc eax ; num_written++ @@ -1323,7 +1326,7 @@ EB EC # jmp std_loop 89 CE # mov esi, ecx # use ecx as pointer to fd current offset -8B 0D 1A 83 00 00 # mov ecx, [&next_process_num] +8B 0D 1A 85 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 @@ -1333,7 +1336,7 @@ C1 E3 03 # shl ebx, 3 5B # pop ebx # lookup global file index from file descriptor -9A 45 81 00 00 08 00 # call fd_to_file_index +9A 45 83 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 @@ -1350,7 +1353,7 @@ FF 01 # inc long [ecx] ; current_offset++ 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] +FF 05 90 81 00 00 # inc long [next_file_address] #:skip_lengthen 58 # pop eax 40 # inc eax ; num_written++ @@ -1366,12 +1369,12 @@ CB # ret #------ -#[82AC] +#[84AC] #:next_save_process_address 00 00 00 30 #---------------------------------------- -#[82B0] +#[84B0] #:handle_syscall_fork 53 # push ebx 51 # push ecx @@ -1380,7 +1383,7 @@ CB # ret 57 # push edi 55 # push ebp -A1 1A 83 00 00 # mov eax, [&next_process_num] +A1 1A 85 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] @@ -1390,15 +1393,15 @@ C1 E0 0C # shl eax, 0x0C 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 +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 +A1 AC 84 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 +01 0D AC 84 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 @@ -1413,7 +1416,7 @@ C1 E0 0C # shl eax, 0x0C 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 +01 0D AC 84 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 @@ -1427,12 +1430,12 @@ CB # ret #------ -#[831A] +#[851A] #:next_process_num 01 00 00 00 #---------------------------------------- -#[831E] +#[851E] #:handle_syscall_execve # inputs: # ebx: program_name @@ -1440,7 +1443,7 @@ CB # ret # edx: env # -A1 1A 83 00 00 # mov eax, [next_process_num] +A1 1A 85 00 00 # mov eax, [next_process_num] 3C 01 # cmp al, 1 75 0A # jne not_first_process @@ -1461,19 +1464,19 @@ C1 E0 0C # shl eax, 0x0C #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] +A1 1A 85 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] +A1 1A 85 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] +8B 3D AC 84 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 @@ -1523,13 +1526,13 @@ F3 A4 # rep movsb 50 # push eax = argc # get current process descriptor -A1 1A 83 00 00 # mov eax, [next_process_num] +A1 1A 85 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 +89 3D AC 84 00 00 # mov [next_save_process_address], edi # copy cwd from current process 05 00 01 00 00 # add eax, 0x100 @@ -1548,8 +1551,8 @@ AA # stosb # 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) +9A 76 82 00 00 08 00 # call absolute_path +9A 13 83 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. @@ -1616,7 +1619,7 @@ F3 AA # rep stosb 74 06 # jz after_new_process # prepare for next process -FF 05 1A 83 00 00 # inc [next_process_num] +FF 05 1A 85 00 00 # inc [next_process_num] #:after_new_process # get entry point and jump @@ -1632,13 +1635,13 @@ C3 # ret #---------------------------------------- -#[8460] +#[8660] #: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 +9A 76 82 00 00 08 00 # call absolute_path +9A 13 83 00 00 08 00 # call find_file 83 F8 FF # cmp eax, -1 74 3F # je chdir_finish @@ -1653,7 +1656,7 @@ EB 2B # jmp chdir_finish #:chdir_ok 89 DE # mov esi, ebx -8B 3D 1A 83 00 00 # mov edi, [&next_process_num] +8B 3D 1A 85 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 @@ -1687,11 +1690,11 @@ CB # retf #---------------------------------------- -#[84B7] +#[86B7] #:handle_syscall_exit -A1 1A 83 00 00 # mov eax, [&next_process_num] +A1 1A 85 00 00 # mov eax, [&next_process_num] 48 # dec eax = current process -A3 1A 83 00 00 # mov [&next_process_num], eax +A3 1A 85 00 00 # mov [&next_process_num], eax 48 # dec eax = parent process 3C 00 # cmp al, 0 @@ -1711,7 +1714,7 @@ C1 E0 0C # shl eax, 0x0C 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 +89 35 AC 84 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 @@ -1734,9 +1737,9 @@ CB # ret ; go back to parent #---------------------------------------- -#[850B] +#[870B] #:handle_syscall_waitpid -8B 35 1A 83 00 00 # mov esi, [&next_process_num] +8B 35 1A 85 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 @@ -1748,7 +1751,7 @@ CB # ret #---------------------------------------- -#[8525] +#[8725] #:handle_syscall_lseek # inputs: # ebx: fd @@ -1759,7 +1762,7 @@ CB # ret # 56 # push esi -8B 35 1A 83 00 00 # mov esi, [&next_process_num] +8B 35 1A 85 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 @@ -1784,7 +1787,7 @@ CB # ret #:seek_end 56 # push esi 53 # push ebx -9A 45 81 00 00 08 00 # call fd_to_file_index +9A 45 83 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 @@ -1800,13 +1803,13 @@ CB # ret #---------------------------------------- -#[856D] +#[876D] #: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 +9A 76 82 00 00 08 00 # call absolute_path +9A 13 83 00 00 08 00 # call find_file 83 F8 FF # cmp eax, -1 74 02 # je access_error_exit 31 C0 # xor eax, eax @@ -1815,14 +1818,14 @@ CB # ret #---------------------------------------- -#[8583] +#[8783] #: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 +9A 94 81 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 @@ -1832,7 +1835,7 @@ CB # ret #---------------------------------------- -#[8599] +#[8799] #:handle_syscall_getcwd #inputs: # ebx: buf @@ -1843,7 +1846,7 @@ CB # ret 57 # push edi 89 DF # mov edi, ebx -8B 35 1A 83 00 00 # mov esi, [&next_process_num] +8B 35 1A 85 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 @@ -1870,7 +1873,7 @@ CB # ret #------------------------------------------------------------ -#[85C6] +#[87C6] #:strcmp # inputs: # esi: string1 @@ -1904,19 +1907,19 @@ CB # ret #------ -#[85E1] +#[87E1] #:io_char 00 00 # free #---------------------------------------- -#[85E3] +#[87E3] #: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 +B9 E1 87 00 00 # mov ecx, &io_char BA 01 00 00 00 # mov edx, 1 CD 80 # int 80 syscall @@ -1925,7 +1928,7 @@ CD 80 # int 80 syscall 74 07 # je read_finish B4 01 # mov ah, 1 -A0 E1 85 00 00 # mov al, &io_char +A0 E1 87 00 00 # mov al, &io_char #:read_finish 5A # pop edx @@ -1935,16 +1938,16 @@ CB # ret #---------------------------------------- -#[8606] +#[8806] #:write 50 # push eax 53 # push ebx 51 # push ecx 52 # push edx -A2 E1 85 00 00 # mov &io_char, al +A2 E1 87 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 +B9 E1 87 00 00 # mov ecx, &io_char BA 01 00 00 00 # mov edx, 1 1 byte characters CD 80 # int 80 syscall @@ -1956,7 +1959,7 @@ CB # ret #------ -#[8625] +#[8825] #:string_src #s r c \0 73 72 63 00 @@ -1970,7 +1973,7 @@ CB # ret # Read a newline. # Then, read N bytes from stdin and write to the new file. #---------------------------------------- -#[8629] +#[8829] #:src 50 # push eax 53 # push ebx @@ -1979,16 +1982,16 @@ CB # ret 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 +BE 25 88 00 00 # mov esi, string_src +9A 8F 80 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 ' ' +9A E3 87 00 00 08 00 # call read 'r' +9A E3 87 00 00 08 00 # call read 'c' +9A E3 87 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 +9A E3 87 00 00 08 00 # call read 3C 20 # cmp al, ' ' 74 0C # je got_count @@ -2016,7 +2019,7 @@ B9 00 08 00 00 # mov ecx, 0x00000800 51 # push ecx B9 00 00 D0 04 # mov ecx, 0x04D00000 #:get_filename_loop -9A E3 85 00 00 08 00 # call read +9A E3 87 00 00 08 00 # call read 3C 0A # cmp al, '\n' 74 05 # je got_filename @@ -2027,7 +2030,7 @@ EB F0 # jmp get_file_name_loop #:got_filename BE 00 00 D0 04 # mov esi, 0x04D00000 -9A 8F 7E 00 00 08 00 # call console_puts +9A 8F 80 00 00 08 00 # call console_puts # open filename for write 51 # push ecx @@ -2047,10 +2050,10 @@ CD 80 # int 80 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 +9A E3 87 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 +9A 06 88 00 00 08 00 # call write 49 # dec ecx ; count-- EB E0 # jmp read_write_loop @@ -2066,25 +2069,25 @@ CB # ret #------ -#[86E1] +#[88E1] #:hex0_str #h e x 0 \0 68 65 78 30 00 #------------------------------------------------------------ -#[86E6] +#[88E6] #: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 +BE E1 88 00 00 # mov esi, hex0_str +9A 8F 80 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 +9A E3 87 00 00 08 00 # call read FE C9 # dec cl 75 F5 # jnz ex0_loop @@ -2100,8 +2103,8 @@ B9 00 08 00 00 # mov ecx, 0x00000800 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 +9A E3 87 00 00 08 00 # call read +9A 6F 80 00 00 08 00 # call console_putc 3C 20 # cmp al, ' ' 74 05 # je got_filename1 88 02 # mov [edx], al @@ -2111,8 +2114,8 @@ 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 +9A E3 87 00 00 08 00 # call read +9A 6F 80 00 00 08 00 # call console_putc 3C 0A # cmp al, '\n' 74 05 # je got_filename2 88 02 # mov [edx], al @@ -2142,14 +2145,14 @@ CD 80 # int 80 #------ -#[8779] +#[8979] #:hex0_read_loop 53 # push ebx 89 CB # mov ebx, ecx -9A E3 85 00 00 08 00 # call read +9A E3 87 00 00 08 00 # call read 5B # pop ebx -84 e4 # test ah, ah +84 E4 # test ah, ah 75 04 # jnz check_command 5F # POP_DI 5E # POP_SI @@ -2199,7 +2202,7 @@ EB 11 # jmp maybe_store #:skip_comment 53 # push ebx 89 CB # mov ebx, ecx -9A E3 85 00 00 08 00 # call read +9A E3 87 00 00 08 00 # call read 5B # pop ebx 3C 0A # cmp al, '\n' 75 F1 # jnz skip_comment @@ -2224,26 +2227,26 @@ EB A3 # jmp hex0_read_loop 53 # push ebx 89 D3 # mov ebx, edx -9A 06 86 00 00 08 00 # call write +9A 06 88 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 +EA 79 89 00 00 08 00 # jmp hex0_read_loop #------ -#[87EE] +#[89EE] #:cmd_args 00 00 D0 04 00 04 D0 04 #------ -#[87F6] +#[89F6] #:cmd_env 00 00 00 00 #------------------------------------------------------------ -#[87FA] +#[89FA] #:handle_other_command 50 # push eax 53 # push ebx @@ -2265,7 +2268,7 @@ B9 FF 07 00 00 # mov ecx, 0x000007FF BA 01 00 D0 04 # mov edx, 0x04D00001 #:get_program_name -9A E3 85 00 00 08 00 # call read +9A E3 87 00 00 08 00 # call read 3C 20 # cmp al, ' ' 74 05 # je got_program_name 88 02 # mov [edx], al @@ -2275,7 +2278,7 @@ 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 +9A E3 87 00 00 08 00 # call read 3C 0A # cmp al, '\n' 74 05 # je got_argument1 88 02 # mov [edx], al @@ -2284,15 +2287,15 @@ 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 +9A 8F 80 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 +9A 8F 80 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 +B9 EE 89 00 00 # mov ecx, cmd_args +BA F6 89 00 00 # mov edx, cmd_env +9A 1E 85 00 00 08 00 # call handle_syscall_execve 5E # pop esi 5A # pop edx @@ -2303,29 +2306,29 @@ CB #------ -#[8872] +#[8A72] #: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] +#[8A82] #: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] +#[8A98] #:str_dev_hda #/ d e v / h d a \0 2F 64 65 76 2F 68 64 61 00 #------------------------------------------------------------ -#[88A1] +#[8AA1] #: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 reading stdin from sector 22, cyl 0, head 2 (i.e. sector 148) +C7 05 00 00 00 01 16 00 02 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 = "/" @@ -2341,7 +2344,7 @@ F3 AA # rep stosb 31 DB # xor ebx, ebx #:process_command -9A E3 85 00 00 08 00 # call read +9A E3 87 00 00 08 00 # call read 3C 00 # cmp al, 0 74 23 # je build_finished @@ -2350,7 +2353,7 @@ F3 AA # rep stosb 75 09 # jne check_hex0_command #:handle_src_command -9A 29 86 00 00 08 00 # call src +9A 29 88 00 00 08 00 # call src EB E8 # jmp process_command #:check_hex0_command @@ -2358,30 +2361,30 @@ EB E8 # jmp process_command 75 09 # jne call_handle_other_command #:handle_hex0_command -9A E6 86 00 00 08 00 # call hex0 +9A E6 88 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 +9A FA 89 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 +BE 72 8A 00 00 # mov esi, str_build_finished +9A 8F 80 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 +BB 98 8A 00 00 # mov ebx, str_dev_hda +9A 13 83 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 +BE 82 8A 00 00 # mov esi, str_error_no_write +9A 8F 80 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 +9A 6F 80 00 00 08 00 # call console_putc EB 62 # jmp shell_reboot #:ok_exit @@ -2396,11 +2399,11 @@ C1 E0 04 # shl eax, 04 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 +9A 7F 80 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 +9A 6F 80 00 00 08 00 # call console_putc # set starting disk location to write 31 C9 # xor ecx, ecx @@ -2419,16 +2422,16 @@ F3 A4 # rep movsb 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 +9A BD 80 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 +9A 6F 80 00 00 08 00 # call console_putc #:shell_reboot -EA CD 7E 00 00 08 00 # jmp reboot +EA CD 80 00 00 08 00 # jmp reboot # sector padding 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 diff --git a/rootfs.py b/rootfs.py index 4e96dbc..5e166d6 100755 --- a/rootfs.py +++ b/rootfs.py @@ -35,11 +35,12 @@ def create_configuration_file(args): config.write(f"CHROOT_ONLY_SYSA={args.bwrap}\n") config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n") config.write(f"JOBS={args.cores}\n") - config.write("DISK=sda1\n") config.write(f"INTERNAL_CI={args.internal_ci}\n") if (args.bare_metal or args.qemu) and not args.kernel: + config.write("DISK=sda\n") config.write("KERNEL_BOOTSTRAP=True\n") else: + config.write("DISK=sda1\n") config.write("KERNEL_BOOTSTRAP=False\n") config.write(f"BUILD_KERNELS={args.update_checksums or args.build_kernels}\n") diff --git a/sysa.py b/sysa.py index ef0d1e6..7b2077d 100755 --- a/sysa.py +++ b/sysa.py @@ -193,12 +193,24 @@ class SysA(SysGeneral): 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) + shutil.copyfile(os.path.join('kernel-bootstrap', 'builder-hex0-x86-stage1.bin'), image_file_name) with open(image_file_name, 'ab') as image_file: + current_size = os.stat(image_file_name).st_size + while current_size != 510: + image_file.write(b'\0') + current_size += 1 + image_file.write(b'\x55') + image_file.write(b'\xAA') + + # Append stage2 hex0 source + with open(os.path.join('kernel-bootstrap', 'builder-hex0-x86-stage2.hex0')) as infile: + image_file.write(infile.read().encode()) + # Pad to next sector + current_size = os.stat(image_file_name).st_size + while current_size % 512 != 0: + image_file.write(b'\0') + current_size += 1 self.append_srcfs(image_file) current_size = os.stat(image_file_name).st_size @@ -213,6 +225,6 @@ class SysA(SysGeneral): # 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: + while current_size < 16384 * megabyte: image_file.write(b'\0' * megabyte) current_size += megabyte diff --git a/sysa/SHA256SUMS.pkgs b/sysa/SHA256SUMS.pkgs index 2298ec8..26eb02b 100644 --- a/sysa/SHA256SUMS.pkgs +++ b/sysa/SHA256SUMS.pkgs @@ -40,7 +40,7 @@ d7d0a5fc9117f9b3ebd287851a48716c96a3c11991365edb8890f0e203d3b810 curl-7.88.1_1. ed1581d1ef5d42c809a7db1c27614e0a900076e7ce08349ea4797944d41c7bc7 dhcpcd-10.0.1_0.tar.bz2 c4008ae6b168aee4120b0f3624a1875f9e413d8f0c637708b8b04a1fb5be173c diffutils-2.7_0.tar.bz2 bda6afcd3a390a34a57443269a4857ccc470129f7a557981778c145fd841cbd1 dist-3.5-236_0.tar.bz2 -c0514138e251062c9ac2ff1e432e01a541777bfd61480c77479ea55f5b75cdd1 e2fsprogs-1.45.7_0.tar.bz2 +5a5923e9dcbec079b032a349471627460f553a430c82bc9b4b6c0bd34ae97547 e2fsprogs-1.45.7_0.tar.bz2 d7b7453ad400eac1ba39f99971afdc392cb8a92c557ef5d6fd9fa2625124de4a ed-1.4_0.tar.bz2 258282c136145d8fba4d66f7e150800e7ca33e024483083a15d0dba3aeb5e86b file-5.44_0.tar.bz2 5984d3f2d5513dd04dc97619e2809d634fc7e3692f36f770e0202a61b6b2921d findutils-4.2.33_0.tar.bz2 diff --git a/sysa/e2fsprogs-1.45.7/e2fsprogs-1.45.7.sh b/sysa/e2fsprogs-1.45.7/e2fsprogs-1.45.7.sh index bba1acd..16618a5 100755 --- a/sysa/e2fsprogs-1.45.7/e2fsprogs-1.45.7.sh +++ b/sysa/e2fsprogs-1.45.7/e2fsprogs-1.45.7.sh @@ -30,6 +30,7 @@ src_prepare() { src_configure() { ./configure --prefix="${PREFIX}" \ --sbindir="${PREFIX}/bin" \ + --disable-tls \ with_udev_rules_dir=no \ with_systemd_unit_dir=no } 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 deleted file mode 100644 index a574f7d..0000000 --- a/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.checksums +++ /dev/null @@ -1 +0,0 @@ -dd9e799311b3c505fa8efe045b969b851c60499ab41db546e5c8b545b3e19ec8 /boot/fiwix diff --git a/sysa/fiwix-1.4.0-lb1/sources b/sysa/fiwix-1.4.0-lb1/sources deleted file mode 100644 index e353a6e..0000000 --- a/sysa/fiwix-1.4.0-lb1/sources +++ /dev/null @@ -1 +0,0 @@ -https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb1/fiwix-1.4.0-lb1.tar.gz ff57d1fbf0547a27dec4d7146eb9c17d01158ca5886de54e5b9bac2bec473ef3 diff --git a/sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums b/sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums new file mode 100644 index 0000000..f1f1aa7 --- /dev/null +++ b/sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums @@ -0,0 +1 @@ +0de298be5c0b00654ddb226c2e657d4fdd2fa0c613ffb3bb32c23c65d2257bf0 /boot/fiwix diff --git a/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem b/sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.kaem similarity index 95% rename from sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem rename to sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.kaem index 35724b4..8cc529a 100755 --- a/sysa/fiwix-1.4.0-lb1/fiwix-1.4.0-lb1.kaem +++ b/sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.kaem @@ -18,9 +18,9 @@ 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 as="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DCONFIG_KEXEC -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-lb2/build/fiwix-1.4.0-lb2/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" +alias cc="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DCONFIG_KEXEC -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-lb2/build/fiwix-1.4.0-lb2/include -O2 -fno-pie -fno-common -ffreestanding -Wall -Wstrict-prototypes" cd kernel as -c -o boot.o boot.S @@ -42,6 +42,7 @@ 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 +cc -c -o kexec.o kexec.c cd syscalls cc -c -o umount.o umount.c @@ -278,6 +279,7 @@ 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 ata_pci.o ata_pci.c cc -c -o atapi.o atapi.c cc -c -o atapi_cd.o atapi_cd.c cc -c -o ramdisk.o ramdisk.c @@ -321,6 +323,7 @@ tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \ kernel/signal.o \ kernel/process.o \ kernel/multiboot.o \ + kernel/kexec.o \ kernel/syscalls/umount.o \ kernel/syscalls/getgid.o \ kernel/syscalls/getppid.o \ @@ -529,6 +532,7 @@ tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \ drivers/block/part.o \ drivers/block/ata.o \ drivers/block/ata_hd.o \ + drivers/block/ata_pci.o \ drivers/block/atapi.o \ drivers/block/atapi_cd.o \ drivers/block/ramdisk.o \ diff --git a/sysa/fiwix-1.4.0-lb2/sources b/sysa/fiwix-1.4.0-lb2/sources new file mode 100644 index 0000000..d4858c5 --- /dev/null +++ b/sysa/fiwix-1.4.0-lb2/sources @@ -0,0 +1 @@ +https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb2/fiwix-1.4.0-lb2.tar.gz 44fb14fb666dcf4f5abf7f49eb3f1d92436b9d7353daa23138ff21e9ec78e30f diff --git a/sysa/kexec-fiwix/kexec-fiwix.checksums b/sysa/kexec-fiwix/kexec-fiwix.checksums index 8a275f2..0103d7a 100644 --- a/sysa/kexec-fiwix/kexec-fiwix.checksums +++ b/sysa/kexec-fiwix/kexec-fiwix.checksums @@ -1 +1 @@ -afb30f2e80adefc979bdffdb525cf2862897f0beefbb0740fbd05ab3246a32c9 /usr/bin/kexec-fiwix +4f78914aef30b569a531102998e52a0514d8836204d57ff42bf0a3324968f247 /usr/bin/kexec-fiwix diff --git a/sysa/kexec-fiwix/src/kexec-fiwix.c b/sysa/kexec-fiwix/src/kexec-fiwix.c index ae6efaa..1995d15 100644 --- a/sysa/kexec-fiwix/src/kexec-fiwix.c +++ b/sysa/kexec-fiwix/src/kexec-fiwix.c @@ -77,10 +77,10 @@ int main() { 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); + sprintf(cmdline, "fiwix console=/dev/ttyS0 root=/dev/ram0 ramdisksize=%d initrd=sysa.ext2 kexec_proto=linux kexec_size=67000 kexec_cmdline=\"init=/init console=ttyS0\"", INITRD_MB * 1024); char * boot_loader_name = "kexec-fiwix"; - unsigned int next_avail_mem = 0x8000; + unsigned int next_avail_mem = 0x9800; multiboot_info_t * pmultiboot_info = (multiboot_info_t *) next_avail_mem; memset(pmultiboot_info, 0, sizeof(multiboot_info_t)); diff --git a/sysa/kexec-linux/kexec-linux.checksums b/sysa/kexec-linux/kexec-linux.checksums new file mode 100644 index 0000000..e546331 --- /dev/null +++ b/sysa/kexec-linux/kexec-linux.checksums @@ -0,0 +1 @@ +c0993adf00bd2c110539a310246f0e50d727e09701ed187827c71c64021431f4 /usr/bin/kexec-linux diff --git a/sysa/kexec-linux/kexec-linux.kaem b/sysa/kexec-linux/kexec-linux.kaem new file mode 100755 index 0000000..6bd66bf --- /dev/null +++ b/sysa/kexec-linux/kexec-linux.kaem @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +cd src +tcc -static -m32 -march=i386 -std=c89 -I../../tcc/tcc-0.9.27/include -o ${bindir}/kexec-linux kexec-linux.c +cd .. + +# Checksums +if match x${UPDATE_CHECKSUMS} xTrue; then + sha256sum /usr/bin/kexec-linux + sha256sum -o ${pkg}.checksums \ + /usr/bin/kexec-linux + + cp ${pkg}.checksums ${srcdir} +else + sha256sum -c ${pkg}.checksums +fi diff --git a/sysa/kexec-linux/src/kexec-linux.c b/sysa/kexec-linux/src/kexec-linux.c new file mode 100644 index 0000000..e4e4ac2 --- /dev/null +++ b/sysa/kexec-linux/src/kexec-linux.c @@ -0,0 +1,91 @@ +/* SPDX-FileCopyrightText: 2023 Richard Masters */ +/* SPDX-License-Identifier: MIT */ +#include +#include +#include +#include +#include + +int append_file(FILE *dst_file, char *src_file_name); + + +int main(int argc, char **argv) { + char *ramdrive_file_name, *kernel_file_name, *initramfs_file_name; + FILE *ramdrive_file; + struct stat stats; + + if (argc < 3) { + puts("Usage: fiwix-kexec-linux "); + exit(1); + } + + ramdrive_file_name = argv[1]; + kernel_file_name = argv[2]; + initramfs_file_name = argv[3]; + + + ramdrive_file = fopen(ramdrive_file_name, "wb"); + + /* Write length of kernel */ + if (stat(kernel_file_name, &stats) == 0) { + fwrite(&stats.st_size, sizeof(stats.st_size), 1, ramdrive_file); + } else { + fprintf(stderr, "Cannot stat kernel file '%s'\n", kernel_file_name); + exit(1); + } + + /* Write length of initramfs */ + if (stat(initramfs_file_name, &stats) == 0) { + fwrite(&stats.st_size, sizeof(stats.st_size), 1, ramdrive_file); + } else { + fprintf(stderr, "Cannot stat initramfs file '%s'\n", initramfs_file_name); + exit(1); + } + + if (append_file(ramdrive_file, kernel_file_name)) { + fprintf(stderr, "Cannot append kernel '%s'\n", kernel_file_name); + exit(1); + } + if (append_file(ramdrive_file, initramfs_file_name)) { + fprintf(stderr, "Cannot append initramfs '%s'\n", initramfs_file_name); + exit(1); + } + fclose(ramdrive_file); + + /* Perform syscall sync */ + __asm__ __volatile__( + "movl $0x00000024, %%eax\n\t" + "int $0x80\n\t" + : /* no output */ + : /* no input */ + ); + + /* Perform syscall reboot to initiate kexec */ + __asm__ __volatile__( + "movl $0x58, %%eax\n\t" + "movl $0xfee1dead, %%ebx\n\t" + "movl $0x28121969, %%ecx\n\t" + "movl $0xcdef0123, %%edx\n\t" + "movl $0x00, %%esi\n\t" + "int $0x80\n\t" + : /* no output */ + : /* no input */ + ); +} + +int append_file(FILE *dst_file, char *src_file_name) { + FILE *src_file; + char buff[BUFSIZ]; + size_t n; + + if (src_file = fopen(src_file_name, "rb")) { + while ((n = fread(buff, 1, BUFSIZ, src_file)) != 0) { + fwrite(buff, 1, n, dst_file ); + } + fclose(src_file); + return 0; + } else { + printf("Cannot open file '%s'\n", src_file_name); + return 1; + } +} 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 index e61d380..a73755e 100644 --- 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 @@ -21,6 +21,7 @@ /usr/bin/checksum-transcriber /usr/bin/tcc /usr/bin/tcc-0.9.26 +/usr/bin/kexec-linux /usr/lib/mes/libc.a /usr/lib/mes/libgetopt.a /usr/lib/mes/crt1.o 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 index 960cc7a..9468981 100644 --- a/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c +++ b/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c @@ -267,6 +267,18 @@ int main(int argc, char **argv) printf("ext4_mknod error: %d \n", err); return EXIT_FAILURE; } + printf("ext4_mknod /mp/dev/ram0\n"); + err = ext4_mknod("/mp/dev/ram0", EXT4_DE_BLKDEV, MKDEV(1, 0)); + if (err != EOK) { + printf("ext4_mknod error: %d \n", err); + return EXIT_FAILURE; + } + printf("ext4_mknod /mp/dev/ram1\n"); + err = ext4_mknod("/mp/dev/ram1", EXT4_DE_BLKDEV, MKDEV(1, 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"); diff --git a/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums b/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums index 9f6e5b1..d518e1c 100644 --- a/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums +++ b/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums @@ -1 +1 @@ -0a3f0012c01cb5aee0643f1674f265e68b5eeadb37596bcc4fe60aad55c9d3d7 /usr/bin/make_fiwix_initrd +4135d55c65ba001b98804425de67907ba92d281a0582dfd8861d728d19da9e7d /usr/bin/make_fiwix_initrd diff --git a/sysa/run.kaem b/sysa/run.kaem index 47fe782..a5bef88 100755 --- a/sysa/run.kaem +++ b/sysa/run.kaem @@ -57,7 +57,7 @@ fi if match x${BUILD_FIWIX} xTrue; then # The Fiwix kernel - pkg="fiwix-1.4.0-lb1" + pkg="fiwix-1.4.0-lb2" cd ${pkg} kaem --verbose --file ${pkg}.kaem cd .. @@ -73,6 +73,12 @@ if match x${BUILD_FIWIX} xTrue; then cd ${pkg} kaem --verbose --file ${pkg}.kaem cd .. + + # Live boot loader for Fiwix to Linux + pkg="kexec-linux" + cd ${pkg} + kaem --verbose --file ${pkg}.kaem + cd .. fi if match x${KERNEL_BOOTSTRAP} xTrue; then diff --git a/sysa/run2.sh b/sysa/run2.sh index 078f487..94bf23e 100755 --- a/sysa/run2.sh +++ b/sysa/run2.sh @@ -25,16 +25,20 @@ create_sysb() { } go_sysb() { - # Mount proc for kexec - mkdir /proc /etc - mount -t proc proc /proc - # kexec time - echo "Loading kernel + sysb initramfs using kexec" - kexec -l "/boot/linux-4.9.10" --console-serial \ - --initrd="/boot/initramfs-sysb.cpio.gz" \ - --append="init=/init console=ttyS0" - echo "kexecing into sysb" - kexec -e + if [ "${KERNEL_BOOTSTRAP}" = True ]; then + kexec-linux "/dev/ram1" "/boot/linux-4.9.10" "/boot/initramfs-sysb.cpio.gz" + else + # Mount proc for kexec + mkdir /proc /etc + mount -t proc proc /proc + # kexec time + echo "Loading kernel + sysb initramfs using kexec" + kexec -l "/boot/linux-4.9.10" --console-serial \ + --initrd="/boot/initramfs-sysb.cpio.gz" \ + --append="init=/init console=ttyS0" + echo "kexecing into sysb" + kexec -e + fi } build automake-1.15.1 @@ -96,12 +100,7 @@ build musl-1.2.3 '' no-patches if [ "${CHROOT}" = False ]; then 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 + go_sysb else # In chroot mode transition directly into System C. SYSC=/sysc_image diff --git a/sysb/run.sh b/sysb/run.sh index c9528bf..8606519 100755 --- a/sysb/run.sh +++ b/sysb/run.sh @@ -65,15 +65,15 @@ if [ -z "${DISK}" ] || ! [ -e "/dev/${DISK}" ]; then echo "DISK=${DISK}" >> /usr/src/bootstrap.cfg fi -# Is it a full disk, and not a partition +# Is it a full disk, and not a partition? # shellcheck disable=SC2012 if [ $(($(ls -l "/dev/${DISK}" | sed "s/.*, *//" | sed "s/ .*//") % 8)) -eq 0 ]; then - if ! fdisk -l "/dev/${DISK}" | grep -qE "${DISK}p?[0-9]" ; then - echo "Creating partition table and partition" - echo ";" | sfdisk "/dev/${DISK}" - mkfs.ext4 "/dev/${DISK}1" - DISK="${DISK}1" - fi + echo "Creating partition table..." + echo ";" | sfdisk "/dev/${DISK}" + fdisk -l "/dev/${DISK}" + echo "Creating ext4 partition..." + mkfs.ext4 "/dev/${DISK}1" + DISK="${DISK}1" fi echo "export DISK=${DISK}" >> /usr/src/bootstrap.cfg From 12026cb1007b305bc328fa464d1310c7100b2c73 Mon Sep 17 00:00:00 2001 From: rick-masters Date: Wed, 10 May 2023 17:21:16 +0000 Subject: [PATCH 2/7] Document the new builder-hex0-x86 boot stages. Describe the kernel bootstrap steps first to avoid confusion because we do not actually start with the stage0-posix binary seeds if the default kernel bootstrap option is used. --- parts.rst | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/parts.rst b/parts.rst index aec4361..8769b0d 100644 --- a/parts.rst +++ b/parts.rst @@ -11,13 +11,15 @@ bootstrap-seeds =============== -This is where it all begins. We start with the two raw binary seeds ``hex0-seed`` and ``kaem-optional-seed``. +This is where it all begins. -First, we use those seeds to rebuild themselves. +A kernel bootstrapping option is used by default at the beginning. The tiny ``builder-hex0-x86-stage1`` binary seed boots, builds and runs the ``builder-hex0-x86-stage2`` kernel. The stage2 kernel has its own built-in shell, the ``hex0`` compiler and the ``src`` tool to load files into its memory file system. In this case the first step is to build the ``hex0-seed`` and ``kaem-optional-seed`` binaries from hex0 source. -Note that all early compilers before ``mes`` are part of `stage0-posix `_. +Note that all early shells and 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. +``builder-hex0-x86-stage2`` runs as the kernel for building the stage0-posix compilers and then ``mes`` and ``tcc``. Then the `Fiwix ` kernel is built and launched. Then Fiwix runs the build until Linux takes over. + +If chroot or bwrap is specified or if a pre-existing kernel is provided for QEMU then we start with the two raw binary seeds ``hex0-seed`` and ``kaem-optional-seed``. We use those seeds to rebuild themselves. hex0 @@ -39,9 +41,16 @@ 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. +builder-hex0-x86-stage1 +======================= + +By default (when kernel bootstrap is enabled), the ``builder-hex0-x86-stage1`` boot loader/compiler boots from a hard drive and loads hex0 source code from disk, compiles, and runs the builder-hex0-x86-stage2 kernel. Builder-hex0-x86-stage1 is written in hex0 and can be compiled with any one of ``hex0-seed``, ``sed``, or the tiny ``builder-hex0-mini`` binary. + + +builder-hex0-x86-stage2 +======================= + +When kernel bootstrap is enabled, the ``builder-hex0-x86-stage2`` kernel 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``. kaem-optional @@ -222,6 +231,12 @@ 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. +kexec-linux +=========== + +If the kernel bootstrap option is enabled then a C program `kexec-linux` is compiled. +This is used as part of the go_sysb step later to launch the Linux kernel. + make 3.82 ========= @@ -686,11 +701,6 @@ 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 =================== @@ -711,6 +721,11 @@ subsequent systems, and we do not have ``modprobe``. Lastly, the initramfs of sysb is generated in this stage, using ``gen_init_cpio`` within the Linux kernel tree. This avoids the compilation of ``cpio`` as well. +musl 1.2.3 +========== +Prior to booting Linux, musl is rebuilt yet again with syscalls +``clone`` and ``set_thread_area`` enabled for Linux thread support. + go_sysb ======= From 68429917c03d5664395410056b3e6b5c2fa7e0e5 Mon Sep 17 00:00:00 2001 From: rick-masters Date: Thu, 18 May 2023 10:58:53 +0000 Subject: [PATCH 3/7] Use code blocks and capitalize consistently and other improvements. --- parts.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parts.rst b/parts.rst index 8769b0d..80a0359 100644 --- a/parts.rst +++ b/parts.rst @@ -13,13 +13,13 @@ bootstrap-seeds This is where it all begins. -A kernel bootstrapping option is used by default at the beginning. The tiny ``builder-hex0-x86-stage1`` binary seed boots, builds and runs the ``builder-hex0-x86-stage2`` kernel. The stage2 kernel has its own built-in shell, the ``hex0`` compiler and the ``src`` tool to load files into its memory file system. In this case the first step is to build the ``hex0-seed`` and ``kaem-optional-seed`` binaries from hex0 source. +A kernel bootstrapping option is used by default at the beginning. The tiny ``builder-hex0-x86-stage1`` binary seed boots, builds and runs the ``builder-hex0-x86-stage2`` kernel. The ``builder-hex0-x86-stage1`` and ``builder-hex0-x86-stage2`` kernels are written in ``hex0``. The stage2 kernel has its own built-in shell, the ``hex0`` compiler and the ``src`` tool to load files into its memory file system. In this case the first step is to build the ``hex0-seed`` and ``kaem-optional-seed`` binaries from ``hex0`` source. Note that all early shells and compilers before ``mes`` are part of `stage0-posix `_. ``builder-hex0-x86-stage2`` runs as the kernel for building the stage0-posix compilers and then ``mes`` and ``tcc``. Then the `Fiwix ` kernel is built and launched. Then Fiwix runs the build until Linux takes over. -If chroot or bwrap is specified or if a pre-existing kernel is provided for QEMU then we start with the two raw binary seeds ``hex0-seed`` and ``kaem-optional-seed``. We use those seeds to rebuild themselves. +If chroot or bwrap is specified or if a pre-existing kernel is provided then we start with the two raw binary seeds ``hex0-seed`` and ``kaem-optional-seed``. We use those seeds to rebuild themselves. hex0 @@ -44,7 +44,7 @@ In the first steps we use initial ``hex0`` binary seed to rebuild ``kaem-optiona builder-hex0-x86-stage1 ======================= -By default (when kernel bootstrap is enabled), the ``builder-hex0-x86-stage1`` boot loader/compiler boots from a hard drive and loads hex0 source code from disk, compiles, and runs the builder-hex0-x86-stage2 kernel. Builder-hex0-x86-stage1 is written in hex0 and can be compiled with any one of ``hex0-seed``, ``sed``, or the tiny ``builder-hex0-mini`` binary. +By default (when kernel bootstrap is enabled), the ``builder-hex0-x86-stage1`` boot loader/compiler boots from a hard drive and loads ``hex0`` source code from disk, compiles, and runs the ``builder-hex0-x86-stage2`` kernel. ``builder-hex0-x86-stage1`` is written in ``hex0`` and can be compiled with any one of ``hex0-seed``, ``sed``, or the tiny ``builder-hex0-mini`` binary. builder-hex0-x86-stage2 From 86048719970fee11ba8990268ccbc0bc3fc242bb Mon Sep 17 00:00:00 2001 From: rick-masters Date: Thu, 18 May 2023 10:59:46 +0000 Subject: [PATCH 4/7] Pull builder-hex0-x86-stage1 from updated stage0-posix and lint fixes. --- kernel-bootstrap/builder-hex0-x86-stage1.bin | Bin 200 -> 0 bytes kernel-bootstrap/builder-hex0-x86-stage1.hex0 | 209 ------------------ sysa.py | 17 +- sysa/stage0-posix/src | 2 +- 4 files changed, 8 insertions(+), 220 deletions(-) delete mode 100644 kernel-bootstrap/builder-hex0-x86-stage1.bin delete mode 100644 kernel-bootstrap/builder-hex0-x86-stage1.hex0 diff --git a/kernel-bootstrap/builder-hex0-x86-stage1.bin b/kernel-bootstrap/builder-hex0-x86-stage1.bin deleted file mode 100644 index 207ce840f719eeb24c7c9a4d2b28f959ae3e5abf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 200 zcmV;(05|_Jz>e6Cz>d(o0C)Vq0Ddvsnvr|}0EEDFO*|uXC_FoKBs^w+>pWq61T0tU zBRocb-#kHl1S~h}7d$zC(>ySI&nz(O3!0I9002A+b@%JQgxhrqz~BUk$Nt0Xvk1qC z_^L76>#FJiegFVaQ;GYu0HHZTUg5i00931Q&Cb@ zSG$aSiw}x-0*gljJ^ul813>E!zW{ieY -# SPDX-License-Identifier: MIT -# -# Builder-Hex0 is a small bootable machine image which acts as -# a bootloader using a hex0 compiler. It compiles hex0 code starting -# at sector 2, placing the compiled code at address 0x7E00 and then -# and then jumps to the resulting binary. -# -# hex0 is a "language" for binary encoding in hexadecimal -# with support for comments. - -# Functions: -# _start -# read_sector -# read -# compile - -#------------------------------------------------------------ -# Memory: -# 9FC00 - FFFFF BIOS -# 7C00 - 7E00 MBR/code -# 7A00 - 7BFF sector read buffer -# < 7700 real mode stack -#------------------------------------------------------------ - - -# ------------------------------------------------------------ -# Stub Entry Point -# -# boot drive is in dl -# -#[7C00][15] -#:_start - -# 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 77 # mov sp, 0x7700 -FC # cld ; clear direction flag - -#---------------------------------------- -# Compile hex0 to binary -# compile(dl=boot_drive): -#[7C0C] -BF 00 7E # mov di, 0x7E00 - -# this flag is set after the first digit is seen -31 DB # xor bx,bx - -#:read_loop -9A 91 7C 00 00 # call read -84 C0 # test al, al -74 4D # jz finish - -3C 23 # cmp al, '#' -74 28 # jz skip_comment - -3C 3B # cmp ';' -74 24 # jz skip_comment - -3C 66 # cmp al, 'f' -7F EB # jg 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 23 # jmp maybe_store - -#:maybe_upper -3C 46 # cmp al, 'F' -7F DF # jg 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 17 # jmp maybe_store - -#:maybe_digit -3C 39 # cmp al, '9' -7F D3 # jg read_loop - -3C 30 # cmp al, '0' -7C CF # jl read_loop - -# Handle 0 to 9 -2C 30 # sub al, '0' == x30 -EB 0B # jmp maybe_store - -#:skip_comment -9A 91 7C 00 00 # call read -3C 0A # cmp al, '\n' -75 F7 # jnz skip_comment -EB C0 # jmp 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 B3 # jmp read_loop - -# If on second digit, store and clear state -#:second_digit -08 C7 # or bh, al -88 F8 # mov al, bh -AA # stosb -31 DB # xor bx, bx - -EB AA # jmp read_loop - -#:finish -EA 00 7E 00 00 # ljmp $0000:7E00 ; jump to stage2 - - -#[7C6C][ ] -#:read_sector(di = *dest_addr, cx=cylinder/sector, dh = head, dl=drive) -# -# returns: di - next byte to write to -# cx,dh - next disk sector to read from -# -50 # push ax -53 # push bx - -89 FB # mov bx, di ; int 13 writes to bx - -#:read_one_loop -B4 02 # mov ah, 2 ; rw mode = 02 (read) -B0 01 # mov al, 1 ; num_sectors -CD 13 # int 0x13 -72 F8 # jnc read_one_loop -3C 01 # cmp al, 1 -75 F4 # jnz read_one_loop - -80 F9 3F # cmp cl, 0x3f ; if sector_num == max_sector -74 04 # jz next_head ; goto next_head -FE C1 # inc cl ; else sector_num++; -EB 04 # jmp cleanup - -#next_head: -FE C6 # inc dh ; else head_num++ -B1 01 # mov cl, 1 ; sector = 1 - -5B # pop bx -58 # pop ax -CB # retf - - -#---------------------------------------- -# last_read_location -#[7C8C] -02 00 ; last_cylinder/sector -00 ; last_head -FF 01 ; last_byte - -#[7C91] -#:read() -53 # push bx -51 # push cx -52 # push dx -56 # push si -57 # push di - -# get current position -BB 8C 7C # mov bx, last_read_location -8B 0F # mov cx, [bx] -8A 77 02 # mov dh, [bx+2] -8B 47 03 # mov ax, [bx+3] - -#end of sector? -3D FF 01 # cmp ax, 0x01ff -74 03 # je next sector - -#nextchar: -40 # inc ax -EB 0F # jmp getchar - -#read next sector -BF 00 78 # mov di, 0x7800 -9A 6C 7C 00 00 # call read_sector -# save new location and offset -89 0F # mov [bx], cx -88 77 02 # mov [bx+2], dh -31 C0 # xor ax, ax - -#getchar: -89 47 03 # mov [bx+3], ax -BE 00 78 # mov si, 0x7800 -89 C3 # mov bx, ax -8A 00 # mov al, [si+bx] - -#finish: -5F # pop di -5E # pop si -5A # pop dx -59 # pop cx -5B # pop bx -CB # ret diff --git a/sysa.py b/sysa.py index 7b2077d..d474109 100755 --- a/sysa.py +++ b/sysa.py @@ -13,7 +13,6 @@ 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 @@ -113,6 +112,8 @@ class SysA(SysGeneral): for root, _, filepaths in os.walk(dirpath): if 'stage0-posix' in root: continue + if root == os.path.join('sysc', 'distfiles'): + 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") @@ -193,18 +194,14 @@ class SysA(SysGeneral): def create_builder_hex0_disk_image(self, image_file_name): """Create builder-hex0 disk image""" - shutil.copyfile(os.path.join('kernel-bootstrap', 'builder-hex0-x86-stage1.bin'), image_file_name) + shutil.copyfile(os.path.join('sysa', 'stage0-posix', 'src', 'bootstrap-seeds', + 'NATIVE', 'x86', 'builder-hex0-x86-stage1.img'), + image_file_name) with open(image_file_name, 'ab') as image_file: - current_size = os.stat(image_file_name).st_size - while current_size != 510: - image_file.write(b'\0') - current_size += 1 - image_file.write(b'\x55') - image_file.write(b'\xAA') - # Append stage2 hex0 source - with open(os.path.join('kernel-bootstrap', 'builder-hex0-x86-stage2.hex0')) as infile: + with open(os.path.join('kernel-bootstrap', 'builder-hex0-x86-stage2.hex0'), + encoding="utf-8") as infile: image_file.write(infile.read().encode()) # Pad to next sector current_size = os.stat(image_file_name).st_size diff --git a/sysa/stage0-posix/src b/sysa/stage0-posix/src index fe529ef..5805bee 160000 --- a/sysa/stage0-posix/src +++ b/sysa/stage0-posix/src @@ -1 +1 @@ -Subproject commit fe529ef2e1053cb0551fb71276f9ced9fe229d87 +Subproject commit 5805beef1754945e280a07f193346710ba2b4d32 From 0d4394aa0d7f9704698dbd98984795c55c2c6332 Mon Sep 17 00:00:00 2001 From: rick-masters Date: Sat, 20 May 2023 15:16:27 +0000 Subject: [PATCH 5/7] Build kexec-linux later as a package for musl lib calls instead of asm. --- sysa/SHA256SUMS.pkgs | 1 + .../files}/kexec-linux.c | 25 +++++-------------- sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh | 15 +++++++++++ sysa/kexec-linux-1.0.0/mk/main.mk | 4 +++ sysa/kexec-linux/kexec-linux.checksums | 1 - sysa/kexec-linux/kexec-linux.kaem | 16 ------------ sysa/run.kaem | 6 ----- sysa/run2.sh | 2 ++ 8 files changed, 28 insertions(+), 42 deletions(-) rename sysa/{kexec-linux/src => kexec-linux-1.0.0/files}/kexec-linux.c (76%) create mode 100755 sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh create mode 100644 sysa/kexec-linux-1.0.0/mk/main.mk delete mode 100644 sysa/kexec-linux/kexec-linux.checksums delete mode 100755 sysa/kexec-linux/kexec-linux.kaem diff --git a/sysa/SHA256SUMS.pkgs b/sysa/SHA256SUMS.pkgs index 26eb02b..65a1dd3 100644 --- a/sysa/SHA256SUMS.pkgs +++ b/sysa/SHA256SUMS.pkgs @@ -62,6 +62,7 @@ d85cff8f9ff76533287891ec2019416fa585815e514743e5b76efd9f17f5ef5c grep-3.7_0.tar b38422d646590600444f0ff12fee6fd738baaf471338aa67899db950d3521127 guile-3.0.9_0.tar.bz2 8d2015b87337abbf287f7a39ee4cf53514120b5d3e90a93fe7d533dcc43f14fa help2man-1.36.4_0.tar.bz2 3f06d1a7f1b1770d4550ff6316c7f06fd26e30bddad7c1b665f1fae80e409c8c kbd-1.15_0.tar.bz2 +6cb8bd6df0472665cd82ef4f4eae8368543a4d04eb90ec5f6cf4f224d1e16e51 kexec-linux-1.0.0_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 diff --git a/sysa/kexec-linux/src/kexec-linux.c b/sysa/kexec-linux-1.0.0/files/kexec-linux.c similarity index 76% rename from sysa/kexec-linux/src/kexec-linux.c rename to sysa/kexec-linux-1.0.0/files/kexec-linux.c index e4e4ac2..51a7573 100644 --- a/sysa/kexec-linux/src/kexec-linux.c +++ b/sysa/kexec-linux-1.0.0/files/kexec-linux.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -28,7 +29,7 @@ int main(int argc, char **argv) { /* Write length of kernel */ if (stat(kernel_file_name, &stats) == 0) { - fwrite(&stats.st_size, sizeof(stats.st_size), 1, ramdrive_file); + fwrite(&stats.st_size, 4, 1, ramdrive_file); } else { fprintf(stderr, "Cannot stat kernel file '%s'\n", kernel_file_name); exit(1); @@ -36,7 +37,7 @@ int main(int argc, char **argv) { /* Write length of initramfs */ if (stat(initramfs_file_name, &stats) == 0) { - fwrite(&stats.st_size, sizeof(stats.st_size), 1, ramdrive_file); + fwrite(&stats.st_size, 4, 1, ramdrive_file); } else { fprintf(stderr, "Cannot stat initramfs file '%s'\n", initramfs_file_name); exit(1); @@ -52,25 +53,11 @@ int main(int argc, char **argv) { } fclose(ramdrive_file); - /* Perform syscall sync */ - __asm__ __volatile__( - "movl $0x00000024, %%eax\n\t" - "int $0x80\n\t" - : /* no output */ - : /* no input */ - ); + /* Flush ram drive writes to device */ + sync(); /* Perform syscall reboot to initiate kexec */ - __asm__ __volatile__( - "movl $0x58, %%eax\n\t" - "movl $0xfee1dead, %%ebx\n\t" - "movl $0x28121969, %%ecx\n\t" - "movl $0xcdef0123, %%edx\n\t" - "movl $0x00, %%esi\n\t" - "int $0x80\n\t" - : /* no output */ - : /* no input */ - ); + reboot(RB_HALT_SYSTEM); } int append_file(FILE *dst_file, char *src_file_name) { diff --git a/sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh b/sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh new file mode 100755 index 0000000..d9dbed8 --- /dev/null +++ b/sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +src_get() { + : +} + +src_unpack() { + dirname=kexec-linux-1.0.0 + mkdir ${dirname} +} + +src_install() { + install -D "kexec-linux" "${DESTDIR}${PREFIX}/bin/kexec-linux" +} diff --git a/sysa/kexec-linux-1.0.0/mk/main.mk b/sysa/kexec-linux-1.0.0/mk/main.mk new file mode 100644 index 0000000..4d42bc6 --- /dev/null +++ b/sysa/kexec-linux-1.0.0/mk/main.mk @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023 Richard Masters +# SPDX-License-Identifier: MIT +kexec-linux: kexec-linux.c + gcc -static -m32 -march=i386 -o $@ $^ diff --git a/sysa/kexec-linux/kexec-linux.checksums b/sysa/kexec-linux/kexec-linux.checksums deleted file mode 100644 index e546331..0000000 --- a/sysa/kexec-linux/kexec-linux.checksums +++ /dev/null @@ -1 +0,0 @@ -c0993adf00bd2c110539a310246f0e50d727e09701ed187827c71c64021431f4 /usr/bin/kexec-linux diff --git a/sysa/kexec-linux/kexec-linux.kaem b/sysa/kexec-linux/kexec-linux.kaem deleted file mode 100755 index 6bd66bf..0000000 --- a/sysa/kexec-linux/kexec-linux.kaem +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Richard Masters -# SPDX-License-Identifier: MIT -cd src -tcc -static -m32 -march=i386 -std=c89 -I../../tcc/tcc-0.9.27/include -o ${bindir}/kexec-linux kexec-linux.c -cd .. - -# Checksums -if match x${UPDATE_CHECKSUMS} xTrue; then - sha256sum /usr/bin/kexec-linux - sha256sum -o ${pkg}.checksums \ - /usr/bin/kexec-linux - - cp ${pkg}.checksums ${srcdir} -else - sha256sum -c ${pkg}.checksums -fi diff --git a/sysa/run.kaem b/sysa/run.kaem index a5bef88..f52d594 100755 --- a/sysa/run.kaem +++ b/sysa/run.kaem @@ -73,12 +73,6 @@ if match x${BUILD_FIWIX} xTrue; then cd ${pkg} kaem --verbose --file ${pkg}.kaem cd .. - - # Live boot loader for Fiwix to Linux - pkg="kexec-linux" - cd ${pkg} - kaem --verbose --file ${pkg}.kaem - cd .. fi if match x${KERNEL_BOOTSTRAP} xTrue; then diff --git a/sysa/run2.sh b/sysa/run2.sh index 94bf23e..6581e62 100755 --- a/sysa/run2.sh +++ b/sysa/run2.sh @@ -91,6 +91,8 @@ grep --no-filename '^build' "${SOURCES}"/run*.sh | grep -v musl-1.2.3 | sed "s/b done if [ "${CHROOT}" = False ] || [ "${BUILD_KERNELS}" = True ]; then + build kexec-linux-1.0.0 + build kexec-tools-2.0.22 build linux-4.9.10 From 1603b81602c60e7e0465610713b701074b2ef1f4 Mon Sep 17 00:00:00 2001 From: rick-masters Date: Sat, 20 May 2023 15:20:01 +0000 Subject: [PATCH 6/7] Fix printf calls and use puts when possible. --- .../files/make_fiwix_initrd.c | 36 +++++++++---------- .../lwext4-1.0.0-lb1.checksums | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) 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 index 9468981..9a05508 100644 --- a/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c +++ b/sysa/lwext4-1.0.0-lb1/files/make_fiwix_initrd.c @@ -71,7 +71,7 @@ static bool open_filedev(void) file_dev_name_set(input_name); bd = file_dev_get(); if (!bd) { - printf("open_filedev: fail\n"); + puts("open_filedev: fail"); return false; } return true; @@ -85,7 +85,7 @@ bool lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache) bd = bdev; if (!bd) { - printf("lwext4_mount: no block device\n"); + puts("lwext4_mount: no block device"); return false; } @@ -155,21 +155,21 @@ bool copy_file(char *src_path, char *dest_path) err = ext4_fopen(&dest_file, dest_path, "wb"); if (err != EOK) { - printf("ext4_open error: %d \n", err); + 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); + 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); + printf("ext4_fclose error: %d\n", err); return EXIT_FAILURE; } @@ -226,7 +226,7 @@ int main(int argc, char **argv) err = ext4_mkfs(&fs, bd, &info, F_SET_EXT2_V0); if (err != EOK) { - printf("ext4_mkfs error: %d \n", err); + printf("ext4_mkfs error: %d\n", err); return EXIT_FAILURE; } @@ -255,44 +255,44 @@ int main(int argc, char **argv) if (!lwext4_mount(bd, bc)) return EXIT_FAILURE; - printf("ext4_dir_mk /mp/dev\n"); + puts("ext4_dir_mk /mp/dev"); err = ext4_dir_mk("/mp/dev"); if (err != EOK) { - printf("ext4_dir_mk error: %d \n", err); + printf("ext4_dir_mk error: %d\n", err); } - printf("ext4_mknod /mp/dev/console\n"); + puts("ext4_mknod /mp/dev/console"); err = ext4_mknod("/mp/dev/console", EXT4_DE_CHRDEV, MKDEV(5, 1)); if (err != EOK) { - printf("ext4_mknod error: %d \n", err); + printf("ext4_mknod error: %d\n", err); return EXIT_FAILURE; } - printf("ext4_mknod /mp/dev/ram0\n"); + puts("ext4_mknod /mp/dev/ram0"); err = ext4_mknod("/mp/dev/ram0", EXT4_DE_BLKDEV, MKDEV(1, 0)); if (err != EOK) { - printf("ext4_mknod error: %d \n", err); + printf("ext4_mknod error: %d\n", err); return EXIT_FAILURE; } - printf("ext4_mknod /mp/dev/ram1\n"); + puts("ext4_mknod /mp/dev/ram1"); err = ext4_mknod("/mp/dev/ram1", EXT4_DE_BLKDEV, MKDEV(1, 1)); if (err != EOK) { - printf("ext4_mknod error: %d \n", err); + 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"); + puts("ext4_dir_mk /mp/tmp"); ext4_dir_mk("/mp/tmp"); - printf("ext4_dir_mk /mp/usr\n"); + puts("ext4_dir_mk /mp/usr"); ext4_dir_mk("/mp/usr"); - printf("ext4_dir_mk /mp/usr/src\n"); + puts("ext4_dir_mk /mp/usr/src"); ext4_dir_mk("/mp/usr/src"); if (!lwext4_umount()) return EXIT_FAILURE; - printf("Fiwix ext2 initrd created successfully.\n"); + puts("Fiwix ext2 initrd created successfully."); return EXIT_SUCCESS; } diff --git a/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums b/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums index d518e1c..735c420 100644 --- a/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums +++ b/sysa/lwext4-1.0.0-lb1/lwext4-1.0.0-lb1.checksums @@ -1 +1 @@ -4135d55c65ba001b98804425de67907ba92d281a0582dfd8861d728d19da9e7d /usr/bin/make_fiwix_initrd +7b65748dd946f1a5266b2e6d0c9cf7143b4722dae0dd4a02b89d6fba9909e2bd /usr/bin/make_fiwix_initrd From ef088914013d8ec73f63bd92044db1064324664d Mon Sep 17 00:00:00 2001 From: rick-masters Date: Sun, 21 May 2023 00:11:37 +0000 Subject: [PATCH 7/7] Convert file size to 32-bit type before writing. --- sysa/SHA256SUMS.pkgs | 2 +- sysa/kexec-linux-1.0.0/files/kexec-linux.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sysa/SHA256SUMS.pkgs b/sysa/SHA256SUMS.pkgs index 65a1dd3..89d79c8 100644 --- a/sysa/SHA256SUMS.pkgs +++ b/sysa/SHA256SUMS.pkgs @@ -62,7 +62,7 @@ d85cff8f9ff76533287891ec2019416fa585815e514743e5b76efd9f17f5ef5c grep-3.7_0.tar b38422d646590600444f0ff12fee6fd738baaf471338aa67899db950d3521127 guile-3.0.9_0.tar.bz2 8d2015b87337abbf287f7a39ee4cf53514120b5d3e90a93fe7d533dcc43f14fa help2man-1.36.4_0.tar.bz2 3f06d1a7f1b1770d4550ff6316c7f06fd26e30bddad7c1b665f1fae80e409c8c kbd-1.15_0.tar.bz2 -6cb8bd6df0472665cd82ef4f4eae8368543a4d04eb90ec5f6cf4f224d1e16e51 kexec-linux-1.0.0_0.tar.bz2 +d23886557310f7ff2c98898eac24b4fe8704b22e88d094e96ff996cf0d2635a4 kexec-linux-1.0.0_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 diff --git a/sysa/kexec-linux-1.0.0/files/kexec-linux.c b/sysa/kexec-linux-1.0.0/files/kexec-linux.c index 51a7573..a43c17c 100644 --- a/sysa/kexec-linux-1.0.0/files/kexec-linux.c +++ b/sysa/kexec-linux-1.0.0/files/kexec-linux.c @@ -2,6 +2,7 @@ /* SPDX-License-Identifier: MIT */ #include #include +#include #include #include #include @@ -14,6 +15,7 @@ int main(int argc, char **argv) { char *ramdrive_file_name, *kernel_file_name, *initramfs_file_name; FILE *ramdrive_file; struct stat stats; + uint32_t size; if (argc < 3) { puts("Usage: fiwix-kexec-linux "); @@ -29,7 +31,8 @@ int main(int argc, char **argv) { /* Write length of kernel */ if (stat(kernel_file_name, &stats) == 0) { - fwrite(&stats.st_size, 4, 1, ramdrive_file); + size = (uint32_t) stats.st_size; + fwrite(&size, sizeof(size), 1, ramdrive_file); } else { fprintf(stderr, "Cannot stat kernel file '%s'\n", kernel_file_name); exit(1); @@ -37,7 +40,8 @@ int main(int argc, char **argv) { /* Write length of initramfs */ if (stat(initramfs_file_name, &stats) == 0) { - fwrite(&stats.st_size, 4, 1, ramdrive_file); + size = (uint32_t) stats.st_size; + fwrite(&size, sizeof(size), 1, ramdrive_file); } else { fprintf(stderr, "Cannot stat initramfs file '%s'\n", initramfs_file_name); exit(1);