Compare commits

...

9 Commits

Author SHA1 Message Date
8b3a1e658a Added builder 2024-12-19 12:13:17 -08:00
d42db82558 More fixes 2024-12-16 22:53:13 -08:00
3207a2c7ee Add tools 2024-12-16 20:57:17 -08:00
fbb975674f Fix initfs build 2024-12-16 20:50:34 -08:00
a6f7d459d1 Build kernel 2024-12-16 20:50:27 -08:00
0f42691db8 Initfs makefile 2024-12-15 21:27:29 -08:00
b156510422 Added component makefiles 2024-12-15 21:06:44 -08:00
067992221f Add components 2024-12-15 20:26:24 -08:00
786af6f2e6 Gitignore 2024-12-15 20:26:16 -08:00
3746 changed files with 2075882 additions and 300 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/build
**/target
*.ignore

30
.gitmodules vendored Normal file
View File

@ -0,0 +1,30 @@
[submodule "components/sources/bootstrap"]
path = components/sources/bootstrap
url = https://gitlab.redox-os.org/redox-os/bootstrap.git
[submodule "components/sources/drivers"]
path = components/sources/drivers
url = https://gitlab.redox-os.org/redox-os/drivers
[submodule "components/sources/init"]
path = components/sources/init
url = https://gitlab.redox-os.org/redox-os/init
[submodule "components/sources/logd"]
path = components/sources/logd
url = https://gitlab.redox-os.org/redox-os/logd
[submodule "components/sources/ramfs"]
path = components/sources/ramfs
url = https://gitlab.redox-os.org/redox-os/ramfs
[submodule "components/sources/randd"]
path = components/sources/randd
url = https://gitlab.redox-os.org/redox-os/randd
[submodule "components/sources/redoxfs"]
path = components/sources/redoxfs
url = https://gitlab.redox-os.org/redox-os/redoxfs
[submodule "components/sources/zerod"]
path = components/sources/zerod
url = https://gitlab.redox-os.org/redox-os/zerod
[submodule "tools/initfs"]
path = tools/initfs
url = https://gitlab.redox-os.org/redox-os/redox-initfs.git
[submodule "kernel"]
path = kernel
url = https://gitlab.redox-os.org/redox-os/kernel.git

View File

@ -1,6 +1,10 @@
BUILD_DIR=./build
export QEMU?=qemu-system-x86_64
TOOLCHAIN = $(CURDIR)/tools/bin/x86_64-unknown-redox/toolchain
export PATH := $(TOOLCHAIN)/bin:$(PATH)
export CARGO := $(TOOLCHAIN)/bin/cargo
# Default rule
.PHONY: default
default: bios

View File

@ -1,161 +0,0 @@
; Simple ISO emulation with el torito
; Fill until CD sector 0x10
times (0x10*2048)-($-$$) db 0
; Volume record
;TODO: fill in more fields
iso_volume_record:
db 1 ; Type volume record
db "CD001" ; Identifier
db 1 ; Version
db 0 ; Unused
times 32 db ' ' ; System identifier
.volume_id: ; Volume identifier
db 'Redox OS'
times 32-($-.volume_id) db ' '
times 8 db 0 ; Unused
db 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15 ; Volume space size (0x15)
times 32 db 0 ; Unused
db 0x01, 0x00, 0x00, 0x01 ; Volume set size
db 0x01, 0x00, 0x00, 0x01 ; Volume sequence number
db 0x00, 0x08, 0x08, 0x00 ; Logical block size in little and big endian
times 156-($-iso_volume_record) db 0
; Root directory entry
.root_directory:
db 0x22 ; Length of entry
db 0x00 ; Length of extended attributes
db 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 ; Location of extent (0x14)
db 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 ; Size of extent
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ; Recording time
db 0x02 ; File flags
db 0x00 ; Interleaved file unit size
db 0x00 ; Interleaved gap size
db 0x01, 0x00, 0x00, 0x01 ; Volume sequence number
db 0x01 ; Length of file identifier
db 0x00 ; File identifier
times 128 db ' ' ; Volume set identifier
times 128 db ' ' ; Publisher identifier
times 128 db ' ' ; Data preparer identifier
times 128 db ' ' ; Application identifier
times 37 db ' ' ; Copyright file ID
times 37 db ' ' ; Abstract file ID
times 37 db ' ' ; Bibliographic file ID
times 881-($-iso_volume_record) db 0
db 1 ; File structure version
; Fill until CD sector 0x11
times (0x11*2048)-($-$$) db 0
; Boot record
iso_boot_record:
db 0 ; Type boot record
db "CD001" ; Identifier
db 1 ; Version
db "EL TORITO SPECIFICATION" ; Boot system identifier
times 0x47-($ - iso_boot_record) db 0 ; Padding
dd 0x13 ; Sector of boot catalog
; Fill until CD sector 0x12
times (0x12*2048)-($-$$) db 0
; Terminator
iso_terminator:
db 0xFF ; Type terminator
db "CD001" ; Identifier
db 1 ; Version
; Fill until CD sector 0x13
times (0x13*2048)-($-$$) db 0
; Boot catalog
iso_boot_catalog:
; Validation entry
.validation:
db 1 ; Header ID
db 0 ; Platform ID (x86)
dw 0 ; Reserved
times 24 db 0 ; ID string
dw 0x55aa ; Checksum
dw 0xaa55 ; Key
; Default entry
.default:
db 0x88 ; Bootable
db 4 ; Hard drive emulation
dw 0 ; Load segment (0 is platform default)
db 0xEE ; Partition type (0xEE is protective MBR)
db 0 ; Unused
dw 1 ; Sector count
dd 0 ; Start address for virtual disk
times 20 db 0 ; Padding
; EFI section header entry
.efi_section_header:
db 0x91 ; Final header
db 0xEF ; Platform ID (EFI)
dw 1 ; Number of section header entries
times 28 db 0 ; ID string
; EFI section entry
.efi_section_entry:
db 0x88 ; Bootable
db 0 ; No emulation
dw 0 ; Load segment (0 is platform default)
db 0 ; Partition type (not used)
db 0 ; Unused
dw 512 ; Sector count (1 MiB = 512 CD sectors)
dd 512 ; Start address for virtual disk (1 MiB = 512 CD sectors)
times 20 db 0 ; Padding
; Fill until CD sector 0x14
times (0x14*2048)-($-$$) db 0
iso_root_directory:
.self:
db 0x22 ; Length of entry
db 0x00 ; Length of extended attributes
db 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 ; Location of extent (0x14)
db 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 ; Size of extent
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ; Recording time
db 0x02 ; File flags
db 0x00 ; Interleaved file unit size
db 0x00 ; Interleaved gap size
db 0x01, 0x00, 0x00, 0x01 ; Volume sequence number
db 0x01 ; Length of file identifier
db 0x00 ; File identifier
.parent:
db 0x22 ; Length of entry
db 0x00 ; Length of extended attributes
db 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 ; Location of extent (0x14)
db 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 ; Size of extent
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ; Recording time
db 0x02 ; File flags
db 0x00 ; Interleaved file unit size
db 0x00 ; Interleaved gap size
db 0x01, 0x00, 0x00, 0x01 ; Volume sequence number
db 0x01 ; Length of file identifier
db 0x01 ; File identifier
.boot_cat:
db 0x2C ; Length of entry
db 0x00 ; Length of extended attributes
db 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13 ; Location of extent (0x13)
db 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 ; Size of extent
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ; Recording time
db 0x00 ; File flags
db 0x00 ; Interleaved file unit size
db 0x00 ; Interleaved gap size
db 0x01, 0x00, 0x00, 0x01 ; Volume sequence number
db 0x0A ; Length of file identifier
db "BOOT.CAT;1",0 ; File identifier
; Fill until CD sector 0x15
times (0x15*2048)-($-$$) db 0

View File

@ -1,31 +0,0 @@
sectalign off
; stage 1 is sector 0, loaded at 0x7C00
%include "stage1.asm"
; GPT area from sector 1 to 33, loaded at 0x7E00
times (33*512) db 0
; stage 2, loaded at 0xC000
stage2:
%include "stage2.asm"
align 512, db 0
stage2.end:
; the maximum size of stage2 is 4 KiB
times (4*1024)-($-stage2) db 0
; ISO compatibility, uses up space until 0x12400
%include "iso.asm"
times 3072 db 0 ; Pad to 0x13000
; stage3, loaded at 0x13000
stage3:
%defstr STAGE3_STR %[STAGE3]
incbin STAGE3_STR
align 512, db 0
.end:
; the maximum size of the boot loader portion is 384 KiB
times (384*1024)-($-$$) db 0

1
bootloader/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

48
bootloader/Makefile Normal file
View File

@ -0,0 +1,48 @@
# Build script for BIOS (legacy) boot.
#
# This compiles our bootloader as a static library,
# and wraps it in a multistage loader.
BUILD = ./build
BIOS_BUILD = $(BUILD)/bios
STAGE2_SECTOR=34
.PHONY: all
all: $(BIOS_BUILD)/bios.mbr.bin $(BIOS_BUILD)/bios.stage2.bin
.PHONY: clean
clean:
rm -drf $(BUILD)
include bios.mk
# Compile bootloader as library
LIB_SRC = ./bootloader/Cargo.toml ./bootloader/Cargo.lock $(shell find ./bootloader/src -type f)
$(BUILD)/bios.lib: $(LIB_SRC)
@mkdir -p $(BUILD)
env RUSTFLAGS="-C soft-float" \
cargo rustc \
--manifest-path="./bootloader/Cargo.toml" \
-Z build-std=core,alloc \
-Z build-std-features=compiler-builtins-mem \
--target "./bootloader/targets/x86-unknown-none.json" \
--lib \
--release \
-- \
--emit link="$(CURDIR)/$@"
# Link bootloader
BIOS_LD = ./bootloader/linkers/x86-unknown-none.ld
$(BUILD)/bios.elf: $(BUILD)/bios.lib $(BIOS_LD)
ld \
-m elf_i386 \
--gc-sections \
-z max-page-size=0x1000 \
-T "$(BIOS_LD)" \
-o "$@" \
"$<"
objcopy --only-keep-debug "$@" "$@.sym"
objcopy --strip-debug "$@"

30
bootloader/bios.mk Normal file
View File

@ -0,0 +1,30 @@
# Expects variables:
# STAGE3: path to linked stage 3 binary
# STAGE2_SECTOR: the index of the first sector
# of the stage 2 binary on the disk it will be written to.
BIOS_SRC = ./bios
# Wrap bootloader in three-stage BIOS loader
$(BIOS_BUILD)/bios.bin: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD)/bios.elf
@mkdir -p "$(BIOS_BUILD)"
nasm \
-f bin \
-D STAGE3="$(BUILD)/bios.elf" \
-D STAGE2_SECTOR=$(STAGE2_SECTOR) \
-o "$@" \
-l "$@.lst" \
-i "$(BIOS_SRC)" \
"$(BIOS_SRC)/main.asm"
# Extract MBR (first 440 bytes)
$(BIOS_BUILD)/bios.mbr.bin: $(BIOS_BUILD)/bios.bin
@mkdir -p "$(BIOS_BUILD)"
@echo ""
dd if="$(BIOS_BUILD)/bios.bin" bs=440 count=1 of="$@"
# Extract stage 2 (rest of file)
$(BIOS_BUILD)/bios.stage2.bin: $(BIOS_BUILD)/bios.bin
@mkdir -p "$(BIOS_BUILD)"
@echo ""
dd if="$(BIOS_BUILD)/bios.bin" bs=512 skip=1 of="$@"

4
bootloader/bios/defs.asm Normal file
View File

@ -0,0 +1,4 @@
; sector = 512 bytes
; first sector of stage 2, on disk.
%assign PARAM_STAGE2_SECTOR 34

70
bootloader/bios/main.asm Normal file
View File

@ -0,0 +1,70 @@
sectalign off
; This program expects two external macros:
; STAGE3, a path to the stage3 binary
; STAGE2_SECTOR, the location of stage 2
; on the disk, in 512-byte sectors.
; On a gpt disk, this is probably 34.
; Stage 1 is MBR code, and should fit in LBA 0
; (512 bytes). Layout is as follows:
; (Format is `offset, length: purpose`)
; 0, 424: x86 boot code
; 440, 4: Unique disk signature
; 444, 2: unknown
; 446, 16*4: Array of four legacy MBR records
; 510, 2: signature 0x55 0xAA
; 512 to end of logical block: reserved
;
; See https://uefi.org/specs/UEFI/2.10/05_GUID_Partition_Table_Format.html
ORG 0x7C00
SECTION .text
; stage 1 is sector 0, loaded into memory at 0x7C00
%include "stage1.asm"
; Stage 1 is at most 440 bytes
times 440-($-$$) db 0
db 0xee
; Pad until 512
times 510-($-$$) db 0
; MBR signature.
; This isn't loaded into memory, it's
; only here for debugging.
db 0x55
db 0xaa
; LEGACY
; GPT area from sector 1 to 33, loaded at 0x7E00
;times (33*512) db 0
stage2:
%include "stage2.asm"
align 512, db 0
stage2.end:
; TODO: why? Stage 1 read limit?
; Can we make this smaller?
; The maximum size of stage2 is 4 KiB,
; This fill will throw an error if the subtraction
; is negative.
times (4*1024)-($-stage2) db 0
; LEGACY
; Pad to 0x13000
; This needs to match the value configured
; in the stage3 linker script
times (0x13000 - 0x7c00)-($-$$) db 0
stage3:
%defstr STAGE3_STR %[STAGE3]
incbin STAGE3_STR
align 512, db 0
.end:
; TODO: why? Of the disk, or of memory?
; the maximum size of the boot loader portion is 384 KiB
times (384*1024)-($-$$) db 0

View File

@ -1,5 +1,3 @@
ORG 0x7C00
SECTION .text
USE16
stage1: ; dl comes with disk
@ -18,7 +16,6 @@ stage1: ; dl comes with disk
retf
.set_cs:
; save disk number
mov [disk], dl
@ -48,8 +45,19 @@ stage1: ; dl comes with disk
and cl, 0x3f
mov [chs.s], cl
mov eax, (stage2 - stage1) / 512
; PARAM stage1 0x7C00
; PARAM stage2 0xC000
; PARAM stage3.end 0x4b600
; disk address of stage 2
; (start sector)
mov eax, STAGE2_SECTOR
; where to load stage 2
mov bx, stage2
; length of stage2 + stage3
; (on disk, in sectors)
mov cx, (stage3.end - stage2) / 512
mov dx, 0
call load
@ -92,7 +100,40 @@ load:
mov [DAPACK.count], cx
mov [DAPACK.seg], dx
call print_dapack
; This should be a subroutine,
; but we don't call/ret to save a few bytes.
; (we only use this once)
;
;call print_dapack
;print_dapack:
mov bx, [DAPACK.addr + 2]
call print_hex
mov bx, [DAPACK.addr]
call print_hex
mov al, '#'
call print_char
mov bx, [DAPACK.count]
call print_hex
mov al, ' '
call print_char
mov bx, [DAPACK.seg]
call print_hex
mov al, ':'
call print_char
mov bx, [DAPACK.buf]
call print_hex
call print_line
;ret
; End of print_dapack
cmp byte [chs.s], 0
jne .chs
@ -146,35 +187,6 @@ load:
jc error ; carry flag set on error
ret
print_dapack:
mov bx, [DAPACK.addr + 2]
call print_hex
mov bx, [DAPACK.addr]
call print_hex
mov al, '#'
call print_char
mov bx, [DAPACK.count]
call print_hex
mov al, ' '
call print_char
mov bx, [DAPACK.seg]
call print_hex
mov al, ':'
call print_char
mov bx, [DAPACK.buf]
call print_hex
call print_line
ret
error_chs:
mov ah, 0
@ -185,12 +197,10 @@ error:
mov bl, ah
call print_hex
mov al, ' '
call print_char
mov si, error_msg
mov si, stage1_error_msg
call print
call print_line
.halt:
cli
hlt
@ -199,7 +209,7 @@ error:
%include "print.asm"
stage_msg: db "Stage ",0
error_msg: db "ERROR",0
stage1_error_msg: db " ERROR",0
disk: db 0
@ -216,7 +226,4 @@ DAPACK:
.seg: dw 0 ; in memory page zero
.addr: dq 0 ; put the lba to read in this spot
times 446-($-$$) db 0
partitions: times 4 * 16 db 0
db 0x55
db 0xaa
db 0xff

View File

@ -2,6 +2,13 @@ SECTION .text
USE16
stage2.entry:
mov si, stage_msg
call print
mov al, '3'
call print_char
call print_line
; check for required features
call cpuid_check

9
builder/.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false

1
builder/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

316
builder/Cargo.lock generated Normal file
View File

@ -0,0 +1,316 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "builder"
version = "0.1.0"
dependencies = [
"anstyle",
"clap",
"gpt",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "crc"
version = "3.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636"
dependencies = [
"crc-catalog",
]
[[package]]
name = "crc-catalog"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "gpt"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffa5448a0d9d541f1840c0e1b5fe513360861ca83c4b920619f54efe277f9254"
dependencies = [
"bitflags",
"crc",
"simple-bytes",
"uuid",
]
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "libc"
version = "0.2.168"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d"
[[package]]
name = "proc-macro2"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "simple-bytes"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c11532d9d241904f095185f35dcdaf930b1427a94d5b01d7002d74ba19b44cc4"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

58
builder/Cargo.toml Normal file
View File

@ -0,0 +1,58 @@
[package]
name = "builder"
version = "0.1.0"
edition = "2021"
#
# MARK: lints
#
[workspace.lints.rust]
unused_import_braces = "deny"
unit_bindings = "deny"
single_use_lifetimes = "deny"
non_ascii_idents = "deny"
macro_use_extern_crate = "deny"
elided_lifetimes_in_paths = "deny"
absolute_paths_not_starting_with_crate = "deny"
explicit_outlives_requirements = "warn"
unused_crate_dependencies = "warn"
redundant_lifetimes = "warn"
missing_docs = "allow"
[workspace.lints.clippy]
needless_return = "allow"
new_without_default = "allow"
tabs_in_doc_comments = "allow"
expect_used = "deny"
dbg_macro = "deny"
allow_attributes = "deny"
create_dir = "deny"
filetype_is_file = "deny"
integer_division = "deny"
lossy_float_literal = "deny"
map_err_ignore = "deny"
mutex_atomic = "deny"
needless_raw_strings = "deny"
print_stderr = "deny"
print_stdout = "deny"
str_to_string = "deny"
string_add = "deny"
string_to_string = "deny"
unimplemented = "deny"
use_debug = "deny"
verbose_file_reads = "deny"
large_types_passed_by_value = "deny"
match_on_vec_items = "deny"
wildcard_dependencies = "deny"
negative_feature_names = "deny"
redundant_feature_names = "deny"
#
# MARK: dependencies
#
[dependencies]
anstyle = "1.0.10"
clap = { version = "4.5.23", features = ["derive"] }
gpt = "4.0.0"

1
builder/rustfmt.toml Normal file
View File

@ -0,0 +1 @@
hard_tabs = true

228
builder/src/cmd/disk.rs Normal file
View File

@ -0,0 +1,228 @@
use clap::Subcommand;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use crate::gpt::{GPTDisk, PartitionType};
use crate::util::parse_bytes_postfix;
#[derive(Subcommand, Debug)]
pub enum DiskCommand {
/// Create an empty file of the given size
Create {
/// The new file's size, in bytes.
/// May be followed by the usual SI prefixes:
/// - K, M, G, T for powers of 10
/// - Kib,Mib,Gib,Tib for powers of 1024
size: String,
},
/// Initialize partition table on the given disk
Init {},
/// Show GPT information.
///
/// By default, this command dumps GPT headers & partitons.
/// Use the flags below to compute other values.
#[command(alias = "i")]
Inspect {
/// Show index of first byte of partition
#[clap(long, group = "inspect-mode", value_name = "PARTITION")]
part_start: Option<u32>,
/// Show index of sector of partition
#[clap(long, group = "inspect-mode", value_name = "PARTITION")]
part_start_sector: Option<u32>,
},
/// Initialize partition table on the given disk
#[command(alias = "addpart")]
AddPartition {
/// The partition's name
name: String,
/// The partition's size, in bytes.
/// May be followed by the usual SI prefixes:
/// - K, M, G, T for powers of 10
/// - Kib,Mib,Gib,Tib for powers of 1024
size: String,
/// The type of this partition
partition_type: PartitionType,
},
/// Write a file to the given partition
#[command(alias = "writepart")]
WritePartition {
/// The index of the partition to write to
part_idx: u32,
/// The data to write
source: PathBuf,
},
/// Write a BIOS bootloader to this disk
SetBootCode {
/// The data to write.
/// This file must contain exactly 440 bytes.
source: PathBuf,
},
}
impl DiskCommand {
pub fn run(&self, file: &Path) {
match self {
Self::Inspect {
part_start,
part_start_sector,
} => {
let file = OpenOptions::new()
.create(false)
.append(false)
.write(false)
.read(true)
.open(file)
.unwrap();
let mut dw = GPTDisk::new(file);
if let Some(part) = part_start {
println!("{}", dw.get_partition(*part).unwrap().start());
} else if let Some(part) = part_start_sector {
assert!(dw.get_partition(*part).unwrap().start() % 512 == 0);
println!("{}", dw.get_partition(*part).unwrap().start() / 512);
} else {
let disk = dw.disk(false);
println!("Disk header: {:#?}", disk.primary_header());
println!("Partition layout: {:#?}", disk.partitions());
}
}
Self::Create { size } => {
let size = match parse_bytes_postfix(&size) {
Some(x) => x,
None => panic!("Bad byte string"),
};
if file.exists() {
panic!("file exists")
}
let mut file = File::create(file).unwrap();
let mut buffer = [0; 1024];
let buffer_len: u64 = buffer.len().try_into().unwrap();
let mut remaining_size = size;
while remaining_size > 0 {
let to_write = remaining_size.min(buffer_len);
let to_write_usize: usize = to_write.try_into().unwrap();
let buffer = &mut buffer[..to_write_usize];
file.write(buffer).unwrap();
remaining_size -= to_write;
}
}
Self::Init {} => {
let file = OpenOptions::new()
.create(false)
.append(false)
.write(true)
.read(true)
.open(file)
.unwrap();
let mut dw = GPTDisk::new(file);
dw.init();
}
Self::AddPartition {
name,
size,
partition_type,
} => {
let file = OpenOptions::new()
.create(false)
.append(false)
.write(true)
.read(true)
.open(file)
.unwrap();
let size = match parse_bytes_postfix(&size) {
Some(x) => x,
None => panic!("Bad byte string"),
};
let mut dw = GPTDisk::new(file);
let mut disk = dw.disk(true);
disk.add_partition(name, size, partition_type.into(), 0, None)
.expect("failed to write disk");
disk.write().unwrap();
}
Self::WritePartition { part_idx, source } => {
let file = OpenOptions::new()
.create(false)
.append(false)
.write(true)
.read(true)
.open(file)
.unwrap();
let mut dw = GPTDisk::new(file);
let mut part = match dw.get_partition(*part_idx) {
Some(part) => part,
None => panic!("no such partition"),
};
let mut source = std::fs::File::open(source).unwrap();
let src_size = source.metadata().unwrap().len();
if src_size > part.len() {
panic!("file too big");
}
let n = std::io::copy(&mut source, &mut part).unwrap();
println!("wrote {n} bytes");
}
Self::SetBootCode { source } => {
let file = OpenOptions::new()
.create(false)
.append(false)
.write(true)
.read(true)
.open(file)
.unwrap();
let mut src = OpenOptions::new()
.create(false)
.append(false)
.write(false)
.read(true)
.open(source)
.unwrap();
if src.metadata().unwrap().len() != 440 {
panic!(
"Bad MBR size {}, expected 440.",
src.metadata().unwrap().len()
)
}
let mut mbr = [0u8; 440];
src.read_exact(&mut mbr).unwrap();
let mut dw = GPTDisk::new(file);
dw.set_boot_code(mbr);
}
}
}
}

25
builder/src/cmd/mod.rs Normal file
View File

@ -0,0 +1,25 @@
mod disk;
use clap::Subcommand;
use std::path::PathBuf;
#[derive(Subcommand, Debug)]
pub enum Command {
/// Disk utilities
#[command(alias = "d")]
Disk {
/// The disk image to work on
file: PathBuf,
#[command(subcommand)]
command: disk::DiskCommand,
},
}
impl Command {
pub fn run(&self) {
match self {
Self::Disk { command, file } => command.run(file),
}
}
}

272
builder/src/gpt.rs Normal file
View File

@ -0,0 +1,272 @@
use gpt::{partition_types, DiskDevice, GptDisk};
use std::io::{Read, Seek, SeekFrom, Write};
use std::str::FromStr;
/// Convenience wrapper.
/// Represents a disk with a GPT partition table
pub struct GPTDisk<D: DiskDevice> {
device: D,
start_offset: u64,
}
impl<D: DiskDevice> GPTDisk<D> {
pub fn new(mut device: D) -> Self {
//TODO:error handling
let start_offset = device.stream_position().unwrap();
return Self {
device,
start_offset,
};
}
/// Re-initilaize this disk's GPT metadata.
/// This destroys data and creates a new, empty disk.
pub fn init(&mut self) {
let disk = gpt::GptConfig::new()
.writable(true)
.create_from_device(&mut self.device, None)
.expect("failed to open disk");
disk.write().unwrap();
}
/// Read this disk's partition table.
pub fn disk(&mut self, writable: bool) -> GptDisk<&mut D> {
self.device
.seek(SeekFrom::Start(self.start_offset))
.unwrap();
let disk = gpt::GptConfig::new()
.writable(writable)
.readonly_backup(!writable)
.open_from_device(&mut self.device)
.expect("failed to open disk");
return disk;
}
/// Get a handle to a partition on this disk
pub fn get_partition<'a>(&'a mut self, partition_idx: u32) -> Option<GPTPartition<'a, D>> {
let disk = self.disk(false);
let part = match disk.partitions().get(&partition_idx) {
Some(part) => part,
None => return None,
};
let lb_size = *disk.logical_block_size();
let start_byte = part.bytes_start(lb_size).unwrap();
let length = part.bytes_len(lb_size).unwrap();
return Some(GPTPartition {
disk: self,
start_byte,
length,
seek: 0,
});
}
/// Set this disk's boot code (first 440 bytes of MBR)
pub fn set_boot_code(&mut self, boot_code: [u8; 440]) {
let disk = self.disk(false);
let lbs = *disk.logical_block_size();
drop(disk);
self.device
.seek(SeekFrom::Start(self.start_offset))
.unwrap();
// Get or make MBR
let mut mbr = gpt::mbr::ProtectiveMBR::from_disk(&mut self.device, lbs).unwrap_or(
gpt::mbr::ProtectiveMBR::with_lb_size(lbs.as_u64().try_into().unwrap_or(0xFF_FF_FF_FF)),
);
mbr.set_bootcode(boot_code);
self.device.write_all(&mbr.to_bytes()).unwrap();
}
}
/// A view into a [`GPTDisk`]'s partition.
pub struct GPTPartition<'a, D: DiskDevice> {
/// The disk this partition is on
disk: &'a mut GPTDisk<D>,
/// The index of the first byte of this partition inside its GPTDisk
start_byte: u64,
/// The length of this partition, in bytes.
length: u64,
/// The position we are reading/writing at within this file
seek: u64,
}
impl<'a, D: DiskDevice> Seek for GPTPartition<'a, D> {
fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
match pos {
SeekFrom::Current(x) => {
if x.is_negative() {
let x: u64 = x.abs().try_into().unwrap();
if x > self.seek {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Seek past start",
));
}
self.seek -= x;
} else {
let x: u64 = x.try_into().unwrap();
if self.seek + x > self.length {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Seek past end",
));
}
self.seek += x;
}
}
SeekFrom::Start(x) => {
let x: u64 = x.try_into().unwrap();
if x > self.length {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Seek past end",
));
}
self.seek = x;
}
SeekFrom::End(x) => {
let x: u64 = x.try_into().unwrap();
if x > self.length {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Seek past start",
));
}
self.seek = self.length - x;
}
}
assert!(self.seek <= self.length);
return Ok(self.seek);
}
}
impl<'a, D: DiskDevice> Read for GPTPartition<'a, D> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
// Save parent cursor & seek
// (Not necessary for now, we don't need to save the parent cursor)
// let initial_pos = self.disk.device.stream_position()?;
self.disk.device.seek(SeekFrom::Start(
self.disk.start_offset + self.start_byte + self.seek,
))?;
// Make sure we stay within this partition
let from_back = self.length - self.seek;
let len: u64 = buf.len().try_into().unwrap();
let len = len.min(from_back);
let len: usize = len.try_into().unwrap();
// Do the read
let n = self.disk.device.read(&mut buf[0..len])?;
// Update cursor
let n_u64: u64 = n.try_into().unwrap();
self.seek += n_u64;
assert!(n_u64 <= from_back);
assert!(self.seek <= self.length);
// Fix parent cursor
// self.disk.device.seek(SeekFrom::Start(initial_pos))?;
return Ok(n);
}
}
impl<'a, D: DiskDevice> Write for GPTPartition<'a, D> {
fn flush(&mut self) -> std::io::Result<()> {
self.disk.device.flush()
}
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
// Save parent cursor & seek
// (Not necessary for now, we don't need to save the parent cursor)
// let initial_pos = self.disk.device.stream_position()?;
self.disk.device.seek(SeekFrom::Start(
self.disk.start_offset + self.start_byte + self.seek,
))?;
// Make sure we stay within this partition
let from_back = self.length - self.seek;
let len: u64 = buf.len().try_into().unwrap();
let len = len.min(from_back);
let len: usize = len.try_into().unwrap();
// Do the write
let n = self.disk.device.write(&buf[0..len])?;
// Update cursor
let n_u64: u64 = n.try_into().unwrap();
self.seek += n_u64;
assert!(n_u64 <= from_back);
assert!(self.seek <= self.length);
// Fix parent cursor
// self.disk.device.seek(SeekFrom::Start(initial_pos))?;
return Ok(n);
}
}
impl<'a, D: DiskDevice> GPTPartition<'a, D> {
/// The index of the first byte in this partition
pub fn start(&self) -> u64 {
self.start_byte
}
/// The length of this partition, in bytes
pub fn len(&self) -> u64 {
self.length
}
}
#[derive(Debug, Clone, Copy)]
pub enum PartitionType {
BIOS,
EFI,
Linux,
}
impl FromStr for PartitionType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"bios" => Self::BIOS,
"efi" => Self::EFI,
"linux" => Self::Linux,
_ => return Err("unknown partition type".into()),
})
}
}
impl From<&PartitionType> for partition_types::Type {
fn from(value: &PartitionType) -> Self {
match value {
PartitionType::BIOS => partition_types::BIOS,
PartitionType::EFI => partition_types::EFI,
PartitionType::Linux => partition_types::LINUX_FS,
}
}
}

49
builder/src/main.rs Normal file
View File

@ -0,0 +1,49 @@
use anstyle::{AnsiColor, Color, Style};
use clap::Parser;
mod cmd;
mod gpt;
mod util;
fn get_styles() -> clap::builder::Styles {
clap::builder::Styles::styled()
.usage(
Style::new()
.bold()
.fg_color(Some(Color::Ansi(AnsiColor::BrightBlue))),
)
.header(
Style::new()
.bold()
.fg_color(Some(Color::Ansi(AnsiColor::Green))),
)
.literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::BrightBlack))))
.invalid(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red))))
.error(
Style::new()
.bold()
.fg_color(Some(Color::Ansi(AnsiColor::Red))),
)
.valid(
Style::new()
.bold()
.underline()
.fg_color(Some(Color::Ansi(AnsiColor::Green))),
)
.placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::White))))
}
/// Redox disk utility
#[derive(Parser, Debug)]
#[command(version, about, long_about = None, styles=get_styles())]
struct Cli {
#[command(subcommand)]
command: cmd::Command,
}
/// Demonstrates how to create a new partition table without anything pre-existing
fn main() {
let cli = Cli::parse();
cli.command.run();
}

45
builder/src/util.rs Normal file
View File

@ -0,0 +1,45 @@
// Parse a byte string like `5M` or `8 Tib` into a
// quantity of bytes. Returns `None` if the input
// could not be parsed.
pub fn parse_bytes_postfix(string: &str) -> Option<u64> {
let mut lower = string.trim().to_lowercase();
// Turn Mb & Mib into M and Mi
if lower.ends_with("b") {
lower.pop();
}
let mut string = &lower[..];
let mut multiplier = 1;
let len = string.len();
if string.ends_with("k") {
string = &string[0..len - 1];
multiplier = 1000;
} else if lower.ends_with("m") {
string = &string[0..len - 1];
multiplier = 1000 * 1000;
} else if lower.ends_with("g") {
string = &string[0..len - 1];
multiplier = 1000 * 1000 * 1000;
} else if lower.ends_with("t") {
string = &string[0..len - 1];
multiplier = 1000 * 1000 * 1000 * 1000;
} else if lower.ends_with("ki") {
string = &string[0..len - 2];
multiplier = 1024;
} else if lower.ends_with("mi") {
string = &string[0..len - 2];
multiplier = 1024 * 1024;
} else if lower.ends_with("gi") {
string = &string[0..len - 2];
multiplier = 1024 * 1024 * 1024;
} else if lower.ends_with("ti") {
string = &string[0..len - 2];
multiplier = 1024 * 1024 * 1024 * 1024;
}
return match string.trim().parse::<u64>() {
Ok(x) => Some(multiplier * x),
Err(_) => None,
};
}

1
components/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

40
components/Makefile Normal file
View File

@ -0,0 +1,40 @@
BUILD=./build
TOOLCHAIN = $(CURDIR)/../tools/bin/x86_64-unknown-redox/toolchain
CARGO = $(TOOLCHAIN)/bin/cargo
PATH := $(TOOLCHAIN)/bin:$(PATH)
export AR_x86_64_unknown_redox=x86_64-unknown-redox-ar
export CARGO_TARGET_X86_64_UNKNOWN_REDOX_LINKER=x86_64-unknown-redox-gcc
export CARGO_TARGET_X86_64_UNKNOWN_REDOX_RUNNER=../../redoxer/target/release/redoxer exec --folder .
export CC_x86_64_unknown_redox=x86_64-unknown-redox-gcc
export CFLAGS_riscv64gc_unknown_redox=-march=rv64gc -mabi=lp64d
export CXX_x86_64_unknown_redox=x86_64-unknown-redox-g++
export GNU_TARGET=x86_64-unknown-redox
export RUSTFLAGS=-L native=${TOOLCHAIN}/lib
export RUSTUP_TOOLCHAIN=${TOOLCHAIN}
export TARGET=x86_64-unknown-redox
.PHONY: all
all: \
$(BUILD)/bin/init $(BUILD)/bin/logd \
$(BUILD)/bin/ramfs $(BUILD)/bin/randd \
$(BUILD)/bin/redoxfs $(BUILD)/bin/zerod $(BUILD)/bin/nulld \
$(BUILD)/boot/bootstrap \
$(BUILD)/bin/acpid $(BUILD)/bin/fbcond \
$(BUILD)/bin/inputd $(BUILD)/bin/lived \
$(BUILD)/lib/drivers/nvmed $(BUILD)/bin/pcid \
$(BUILD)/bin/vesad \
$(BUILD)/lib/drivers/ahcid $(BUILD)/lib/drivers/ided \
$(BUILD)/bin/ps2d \
$(BUILD)/lib/drivers/virtio-blkd $(BUILD)/lib/drivers/virtio-gpud \
$(BUILD)/etc/pcid/initfs.toml \
$(BUILD)/etc/init.rc
include make/simple
include make/bootstrap
include make/drivers
$(BUILD)/etc/init.rc: ./init.rc
@mkdir -p $(BUILD)/etc
cp -v "init.rc" "$@"

24
components/init.rc Normal file
View File

@ -0,0 +1,24 @@
export PATH /bin
export RUST_BACKTRACE 1
nulld
zerod
randd
inputd
vesad G G G
unset FRAMEBUFFER_ADDR FRAMEBUFFER_VIRT FRAMEBUFFER_WIDTH FRAMEBUFFER_HEIGHT FRAMEBUFFER_STRIDE
#TODO: unset FRAMEBUFFER1 and beyond?
fbcond 1 2
logd /scheme/debug /scheme/fbcon/1
stdio /scheme/log
ramfs logging
ps2d us
acpid
pcid /etc/pcid/initfs.toml
lived
unset DISK_LIVE_ADDR DISK_LIVE_SIZE
redoxfs --uuid $REDOXFS_UUID file $REDOXFS_BLOCK
unset REDOXFS_UUID REDOXFS_BLOCK REDOXFS_PASSWORD_ADDR REDOXFS_PASSWORD_SIZE
set-default-scheme file
cd /
export PATH /usr/bin
run.d /usr/lib/init.d /etc/init.d

19
components/make/bootstrap Normal file
View File

@ -0,0 +1,19 @@
$(BUILD)/.inter/libbootstrap.a: $(shell find ./sources/bootstrap -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/.inter
cd sources/bootstrap && \
$(CARGO) \
-Zbuild-std=core,alloc,compiler_builtins \
-Zbuild-std-features=compiler-builtins-mem rustc \
--target "x86_64-unknown-redox" \
--release \
-- \
--emit link="../../$(BUILD)/.inter/libbootstrap.a"
$(BUILD)/boot/bootstrap: $(BUILD)/.inter/libbootstrap.a
@mkdir -p $(BUILD)/boot
x86_64-unknown-redox-ld \
-o "$(BUILD)/boot/bootstrap" \
--gc-sections \
-T "./sources/bootstrap/src/x86_64.ld" \
-z max-page-size=4096 \
"$(BUILD)/.inter/libbootstrap.a"

82
components/make/drivers Normal file
View File

@ -0,0 +1,82 @@
# These are special
$(BUILD)/etc/pcid/initfs.toml: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/etc/pcid
cp sources/drivers/initfs.toml $@
# These go in bin
$(BUILD)/bin/pcid: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p pcid
cp sources/drivers/target/x86_64-unknown-redox/release/pcid $@
$(BUILD)/bin/fbcond: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p fbcond
cp sources/drivers/target/x86_64-unknown-redox/release/fbcond $@
$(BUILD)/bin/inputd: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p inputd
cp sources/drivers/target/x86_64-unknown-redox/release/inputd $@
$(BUILD)/bin/vesad: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p vesad
cp sources/drivers/target/x86_64-unknown-redox/release/vesad $@
$(BUILD)/bin/lived: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p lived
cp sources/drivers/target/x86_64-unknown-redox/release/lived $@
$(BUILD)/bin/ps2d: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p ps2d
cp sources/drivers/target/x86_64-unknown-redox/release/ps2d $@
$(BUILD)/bin/acpid: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p acpid
cp sources/drivers/target/x86_64-unknown-redox/release/acpid $@
# These go in lib
$(BUILD)/lib/drivers/nvmed: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/lib/drivers
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p nvmed
cp sources/drivers/target/x86_64-unknown-redox/release/nvmed $@
$(BUILD)/lib/drivers/ahcid: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/lib/drivers
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p ahcid
cp sources/drivers/target/x86_64-unknown-redox/release/ahcid $@
$(BUILD)/lib/drivers/ided: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/lib/drivers
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p ided
cp sources/drivers/target/x86_64-unknown-redox/release/ided $@
$(BUILD)/lib/drivers/virtio-blkd: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/lib/drivers
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p virtio-blkd
cp sources/drivers/target/x86_64-unknown-redox/release/virtio-blkd $@
$(BUILD)/lib/drivers/virtio-gpud: $(shell find ./sources/drivers -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/lib/drivers
cd sources/drivers && \
$(CARGO) build --release --target x86_64-unknown-redox -p virtio-gpud
cp sources/drivers/target/x86_64-unknown-redox/release/virtio-gpud $@

41
components/make/simple Normal file
View File

@ -0,0 +1,41 @@
$(BUILD)/bin/init: $(shell find ./sources/init -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/init && \
$(CARGO) build --release --target x86_64-unknown-redox
cp sources/init/target/x86_64-unknown-redox/release/init $@
$(BUILD)/bin/logd: $(shell find ./sources/logd -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/logd && \
$(CARGO) build --release --target x86_64-unknown-redox
cp sources/logd/target/x86_64-unknown-redox/release/logd $@
$(BUILD)/bin/ramfs: $(shell find ./sources/ramfs -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/ramfs && \
$(CARGO) build --release --target x86_64-unknown-redox
cp sources/ramfs/target/x86_64-unknown-redox/release/ramfs $@
$(BUILD)/bin/randd: $(shell find ./sources/randd -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/randd && \
$(CARGO) build --release --target x86_64-unknown-redox
cp sources/randd/target/x86_64-unknown-redox/release/randd $@
$(BUILD)/bin/redoxfs: $(shell find ./sources/redoxfs -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/redoxfs && \
$(CARGO) build --release --target x86_64-unknown-redox
cp sources/redoxfs/target/x86_64-unknown-redox/release/redoxfs $@
$(BUILD)/bin/zerod: $(shell find ./sources/zerod -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/zerod && \
$(CARGO) build --release --target x86_64-unknown-redox --bin zerod
cp sources/zerod/target/x86_64-unknown-redox/release/zerod $@
$(BUILD)/bin/nulld: $(shell find ./sources/zerod -type f -not -path "*/target/*")
@mkdir -p $(BUILD)/bin
cd sources/zerod && \
$(CARGO) build --release --target x86_64-unknown-redox --bin zerod
cp sources/zerod/target/x86_64-unknown-redox/release/zerod $@

1
kernel Submodule

Submodule kernel added at d4797bbf50

View File

@ -1,57 +0,0 @@
# Build script for BIOS (legacy) boot.
#
# This compiles our bootloader as a static library,
# and wraps it in a multistage loader.
# Compile bootloader as library
LIB_SRC = ./bootloader/Cargo.toml ./bootloader/Cargo.lock $(shell find ./bootloader/src -type f)
$(BUILD_DIR)/bios.lib: $(LIB_SRC)
@mkdir -p $(BUILD_DIR)
env RUSTFLAGS="-C soft-float" \
cargo rustc \
--manifest-path="./bootloader/Cargo.toml" \
-Z build-std=core,alloc \
-Z build-std-features=compiler-builtins-mem \
--target "./bootloader/targets/x86-unknown-none.json" \
--lib \
--release \
-- \
--emit link="$(CURDIR)/$@"
# Link bootloader
BIOS_LD = ./bootloader/linkers/x86-unknown-none.ld
$(BUILD_DIR)/bios.elf: $(BUILD_DIR)/bios.lib $(BIOS_LD)
ld \
-m elf_i386 \
--gc-sections \
-z max-page-size=0x1000 \
-T "$(BIOS_LD)" \
-o "$@" \
"$<"
objcopy --only-keep-debug "$@" "$@.sym"
objcopy --strip-debug "$@"
# Wrap bootloader in three-stage BIOS loader
BIOS_SRC = ./bios
$(BUILD_DIR)/bios.bin: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD_DIR)/bios.elf
@mkdir -p "$(BUILD_DIR)"
nasm \
-f bin \
-o "$@" \
-l "$@.lst" \
-D STAGE3="$(BUILD_DIR)/bios.elf" \
-i "$(BIOS_SRC)" \
"$(BIOS_SRC)/main.asm"
# Build demo disk image
$(BUILD_DIR)/bios.img: $(BUILD_DIR)/bios.bin $(BUILD_DIR)/filesystem.img
rm -f "$@.partial"
fallocate -l 256MiB "$@.partial"
parted -s -a minimal "$@.partial" mklabel msdos
parted -s -a minimal "$@.partial" mkpart primary 2MiB 100%
dd if="$<" of="$@.partial" bs=1 count=512 conv=notrunc
dd if="$<" of="$@.partial" bs=512 skip=1 seek=1 conv=notrunc
dd if="$(BUILD_DIR)/filesystem.img" of="$@.partial" bs=1MiB seek=2 conv=notrunc
mv "$@.partial" "$@"

View File

@ -1,13 +1,22 @@
$(BUILD_DIR)/filesystem:
@mkdir -p $(BUILD_DIR)
rm -f $@.partial
mkdir $@.partial
fallocate -l 1MiB $@.partial/kernel
mv $@.partial $@
$(BUILD_DIR)/filesystem/boot/initfs: $(shell find ./components -type f -not -path "*/target/*")
@mkdir -p $(BUILD_DIR)/filesystem/boot
rm -f $@
make -C tools
make -C components
./tools/bin/redox-initfs-ar \
./components/build \
./components/build/boot/bootstrap \
--output $@
$(BUILD_DIR)/filesystem.img: $(BUILD_DIR)/filesystem
$(BUILD_DIR)/filesystem/boot/kernel: $(shell find ./kernel -type f -not -path "*/target/*")
@mkdir -p $(BUILD_DIR)/filesystem/boot
cd ./kernel && make
cp -v kernel/kernel "$@"
$(BUILD_DIR)/filesystem.img: $(BUILD_DIR)/filesystem/boot/kernel $(BUILD_DIR)/filesystem/boot/initfs
@mkdir -p $(BUILD_DIR)
rm -f $@.partial
fallocate -l 254MiB $@.partial
redoxfs-ar $@.partial $<
redoxfs-ar $@.partial $(BUILD_DIR)/filesystem
mv $@.partial $@

2
tools/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
bin/redox-initfs-ar
bin/redox-initfs-dump

14
tools/Makefile Normal file
View File

@ -0,0 +1,14 @@
.PHONY: all
all: bin/redox-initfs-ar bin/redox-initfs-dump
bin/redox-initfs-ar: $(shell find ./initfs -type f -not -path "*/target/*")
@mkdir -p bin
cd initfs/tools && \
cargo build --release --bin redox-initfs-ar
cp initfs/target/release/redox-initfs-ar $@
bin/redox-initfs-dump: $(shell find ./initfs -type f -not -path "*/target/*")
@mkdir -p bin
cd initfs/tools && \
cargo build --release --bin redox-initfs-dump
cp initfs/target/release/redox-initfs-dump $@

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,28 @@
#!/bin/sh
# Exit if anything fails
set -e
# Prefer rustc in the same directory as this script
DIR="$(dirname "$0")"
if [ -x "$DIR/rustc" ]; then
RUSTC="$DIR/rustc"
else
RUSTC="rustc"
fi
# Find out where the pretty printer Python module is
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
# Get the commit hash for path remapping
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \([a-zA-Z0-9_]*\)/\1/p')"
# Run GDB with the additional arguments that load the pretty printers
# Set the environment variable `RUST_GDB` to overwrite the call to a
# different/specific command (defaults to `gdb`).
RUST_GDB="${RUST_GDB:-gdb}"
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \
--directory="$GDB_PYTHON_MODULE_DIRECTORY" \
-iex "add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY" \
-iex "set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust" \
"$@"

View File

@ -0,0 +1,67 @@
#!/bin/sh
# Exit if anything fails
set -e
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
echo "
rust-gdbgui
===========
gdbgui - https://gdbgui.com - is a graphical front-end to GDB
that runs in a browser. This script invokes gdbgui with the Rust
pretty printers loaded.
Simple usage : rust-gdbgui target/debug/myprog
With arguments: rust-gdbgui 'target/debug/myprog arg1 arg2...'
(note the quotes)
Hints
=====
gdbgui won't be able to find the rust 'main' method automatically, so
in its options make sure to disable the 'Add breakpoint to main after
loading executable' setting to avoid a 'File not found: main' warning
on startup.
Instead, type 'main' into gdbgui's file browser and you should get
auto-completion on the filename. Just pick 'main.rs', add a breakpoint
by clicking in the line number gutter, and type 'r' or hit the Restart
icon to start your program running.
"
exit 0
fi
# Prefer rustc in the same directory as this script
DIR="$(dirname "$0")"
if [ -x "$DIR/rustc" ]; then
RUSTC="$DIR/rustc"
else
RUSTC="rustc"
fi
# Find out where the pretty printer Python module is
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
# Get the commit hash for path remapping
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \([a-zA-Z0-9_]*\)/\1/p')"
# Set the environment variable `RUST_GDB` to overwrite the call to a
# different/specific command (defaults to `gdb`).
RUST_GDB="${RUST_GDB:-gdb}"
# Set the environment variable `RUST_GDBGUI` to overwrite the call to a
# different/specific command (defaults to `gdbgui`).
RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"
# These arguments get passed through to GDB and make it load the
# Rust pretty printers.
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" \
-iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\" \
-iex \"set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust\""
# Finally we execute gdbgui.
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \
exec ${RUST_GDBGUI} \
--gdb-cmd "${RUST_GDB} ${GDB_ARGS}" \
"${@}"

View File

@ -0,0 +1,37 @@
#!/bin/sh
# Exit if anything fails
set -e
# Find the host triple so we can find lldb in rustlib.
host=$(rustc -vV | sed -n -e 's/^host: //p')
# Find out where to look for the pretty printer Python module
RUSTC_SYSROOT=$(rustc --print sysroot)
RUST_LLDB="$RUSTC_SYSROOT/lib/rustlib/$host/bin/lldb"
lldb=lldb
if [ -f "$RUST_LLDB" ]; then
lldb="$RUST_LLDB"
else
if ! command -v "$lldb" > /dev/null; then
echo "$lldb not found! Please install it." >&2
exit 1
else
LLDB_VERSION=$("$lldb" --version | cut -d ' ' -f3)
if [ "$LLDB_VERSION" = "3.5.0" ]; then
cat << EOF >&2
***
WARNING: This version of LLDB has known issues with Rust and cannot display the contents of local variables!
***
EOF
fi
fi
fi
script_import="command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_lookup.py\""
commands_file="$RUSTC_SYSROOT/lib/rustlib/etc/lldb_commands"
# Call LLDB with the commands added to the argument list
exec "$lldb" --one-line-before-file "$script_import" --source-before-file "$commands_file" "$@"

Binary file not shown.

View File

@ -0,0 +1,188 @@
#! /bin/sh
# Add a .gdb_index section to a file.
# Copyright (C) 2010-2024 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This program assumes gdb and objcopy are in $PATH.
# If not, or you want others, pass the following in the environment
GDB=${GDB:=gdb}
OBJCOPY=${OBJCOPY:=objcopy}
READELF=${READELF:=readelf}
myname="${0##*/}"
dwarf5=""
if [ "$1" = "-dwarf-5" ]; then
dwarf5="$1"
shift
fi
if test $# != 1; then
echo "usage: $myname [-dwarf-5] FILE" 1>&2
exit 1
fi
file="$1"
if test -L "$file"; then
if ! command -v readlink >/dev/null 2>&1; then
echo "$myname: 'readlink' missing. Failed to follow symlink $1." 1>&2
exit 1
fi
# Count number of links followed in order to detect loops.
count=0
while test -L "$file"; do
target=$(readlink "$file")
case "$target" in
/*)
file="$target"
;;
*)
file="$(dirname "$file")/$target"
;;
esac
count="$((count + 1))"
if test "$count" -gt 10; then
echo "$myname: Detected loop while following link $file"
exit 1
fi
done
fi
if test ! -r "$file"; then
echo "$myname: unable to access: $file" 1>&2
exit 1
fi
dir="${file%/*}"
test "$dir" = "$file" && dir="."
dwz_file=""
if $READELF -S "$file" | grep -q " \.gnu_debugaltlink "; then
dwz_file=$($READELF --string-dump=.gnu_debugaltlink "$file" \
| grep -A1 "'\.gnu_debugaltlink':" \
| tail -n +2 \
| sed 's/.*]//')
dwz_file=$(echo $dwz_file)
if $READELF -S "$dwz_file" | grep -E -q " \.(gdb_index|debug_names) "; then
# Already has an index, skip it.
dwz_file=""
fi
fi
set_files ()
{
fpath="$1"
index4="${fpath}.gdb-index"
index5="${fpath}.debug_names"
debugstr="${fpath}.debug_str"
debugstrmerge="${fpath}.debug_str.merge"
debugstrerr="${fpath}.debug_str.err"
}
tmp_files=
for f in "$file" "$dwz_file"; do
if [ "$f" = "" ]; then
continue
fi
set_files "$f"
tmp_files="$tmp_files $index4 $index5 $debugstr $debugstrmerge $debugstrerr"
done
rm -f $tmp_files
# Ensure intermediate index file is removed when we exit.
trap "rm -f $tmp_files" 0
$GDB --batch -nx -iex 'set auto-load no' \
-iex 'set debuginfod enabled off' \
-ex "file $file" -ex "save gdb-index $dwarf5 $dir" || {
# Just in case.
status=$?
echo "$myname: gdb error generating index for $file" 1>&2
exit $status
}
# In some situations gdb can exit without creating an index. This is
# not an error.
# E.g., if $file is stripped. This behaviour is akin to stripping an
# already stripped binary, it's a no-op.
status=0
handle_file ()
{
fpath="$1"
set_files "$fpath"
if test -f "$index4" -a -f "$index5"; then
echo "$myname: Both index types were created for $fpath" 1>&2
status=1
elif test -f "$index4" -o -f "$index5"; then
if test -f "$index4"; then
index="$index4"
section=".gdb_index"
else
index="$index5"
section=".debug_names"
fi
debugstradd=false
debugstrupdate=false
if test -s "$debugstr"; then
if ! $OBJCOPY --dump-section .debug_str="$debugstrmerge" "$fpath" \
/dev/null 2>$debugstrerr; then
cat >&2 $debugstrerr
exit 1
fi
if grep -q "can't dump section '.debug_str' - it does not exist" \
$debugstrerr; then
debugstradd=true
else
debugstrupdate=true
cat >&2 $debugstrerr
fi
cat "$debugstr" >>"$debugstrmerge"
fi
$OBJCOPY --add-section $section="$index" \
--set-section-flags $section=readonly \
$(if $debugstradd; then \
echo --add-section .debug_str="$debugstrmerge"; \
echo --set-section-flags .debug_str=readonly; \
fi; \
if $debugstrupdate; then \
echo --update-section .debug_str="$debugstrmerge"; \
fi) \
"$fpath" "$fpath"
status=$?
else
echo "$myname: No index was created for $fpath" 1>&2
echo "$myname: [Was there no debuginfo? Was there already an index?]" \
1>&2
fi
}
handle_file "$file"
if [ "$dwz_file" != "" ]; then
handle_file "$dwz_file"
fi
exit $status

Some files were not shown because too many files have changed in this diff Show More