diff --git a/.gitmodules b/.gitmodules index 8ca1a0a..20ff0a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -12,7 +12,7 @@ url = https://github.com/redox-os/ion.git [submodule "openlibm"] path = openlibm - url = https://github.com/JuliaLang/openlibm.git + url = https://github.com/redox-os/openlibm.git [submodule "programs/coreutils"] path = programs/coreutils url = https://github.com/redox-os/coreutils.git diff --git a/Cargo.toml b/Cargo.toml index 097d7d6..82ebf7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ syscall = { path = "syscall/" } [dependencies.goblin] git = "https://github.com/m4b/goblin.git" default-features = false -features = ["no_mach", "no_mach32", "no_pe", "no_pe32", "no_endian_fd", "pure"] +features = ["elf32", "elf64"] [dev-dependencies] arch_test = { path = "arch/test" } diff --git a/Makefile b/Makefile index 76afcf5..8462dbb 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ KTARGET=$(ARCH)-unknown-none KBUILD=build/kernel KRUSTC=./krustc.sh KRUSTCFLAGS=--target $(KTARGET).json -C opt-level=s -C soft-float -KCARGO=RUSTC="$(KRUSTC)" cargo +KRUSTDOC=./krustdoc.sh +KCARGO=RUSTC="$(KRUSTC)" RUSTDOC="$(KRUSTDOC)" cargo KCARGOFLAGS=--target $(KTARGET).json -- -C opt-level=s -C soft-float # Userspace variables @@ -13,11 +14,12 @@ TARGET=$(ARCH)-unknown-redox BUILD=build/userspace RUSTC=./rustc.sh RUSTCFLAGS=--target $(TARGET).json -C opt-level=s --cfg redox -CARGO=RUSTC="$(RUSTC)" cargo +RUSTDOC=./rustdoc.sh +CARGO=RUSTC="$(RUSTC)" RUSTDOC="$(RUSTDOC)" cargo CARGOFLAGS=--target $(TARGET).json -- -C opt-level=s --cfg redox # Default targets -.PHONY: all clean update qemu bochs drivers schemes coreutils extrautils netutils userutils wireshark FORCE +.PHONY: all clean doc update qemu bochs drivers schemes coreutils extrautils netutils userutils wireshark FORCE all: $(KBUILD)/harddrive.bin @@ -48,6 +50,9 @@ clean: rm -rf filesystem/bin rm -rf build +doc: $(KBUILD)/libkernel.a + $(KCARGO) doc --target $(KTARGET).json + update: cargo update cargo update --manifest-path libstd/Cargo.toml @@ -91,11 +96,7 @@ $(KBUILD)/harddrive.bin: $(KBUILD)/kernel qemu: $(KBUILD)/harddrive.bin $(QEMU) $(QEMUFLAGS) -kernel $< else - LD=ld QEMUFLAGS+=-machine q35 -smp 4 -m 1024 - ifneq ($(kvm),no) - QEMUFLAGS+=-enable-kvm -cpu host - endif ifeq ($(net),no) QEMUFLAGS+=-net none else @@ -114,7 +115,26 @@ else UNAME := $(shell uname) ifeq ($(UNAME),Darwin) + CC=$(ARCH)-elf-gcc + CXX=$(ARCH)-elf-g++ + ECHO=/bin/echo + FUMOUNT=sudo umount LD=$(ARCH)-elf-ld + LDFLAGS=--gc-sections + KRUSTCFLAGS+=-C linker=$(CC) + KCARGOFLAGS+=-C linker=$(CC) + RUSTCFLAGS+=-C linker=$(CC) + CARGOFLAGS+=-C linker=$(CC) + else + CC=gcc + CXX=g++ + ECHO=echo + FUMOUNT=fusermount -u + LD=ld + LDFLAGS=--gc-sections + ifneq ($(kvm),no) + QEMUFLAGS+=-enable-kvm -cpu host + endif endif %.list: % @@ -151,10 +171,10 @@ $(KBUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(KBUILD)/libcore. $(KRUSTC) $(KRUSTCFLAGS) -o $@ $< $(KBUILD)/libkernel.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs - $(KCARGO) rustc $(KCARGOFLAGS) -C opt-level=s -C lto -o $@ + $(KCARGO) rustc $(KCARGOFLAGS) -C lto -o $@ $(KBUILD)/kernel: $(KBUILD)/libkernel.a - $(LD) --gc-sections -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $< + $(LD) $(LDFLAGS) -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $< # Userspace recipes $(BUILD)/libcore.rlib: rust/src/libcore/lib.rs @@ -174,7 +194,7 @@ $(BUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(BUILD)/libcore.rl $(RUSTC) $(RUSTCFLAGS) -o $@ $< openlibm/libopenlibm.a: - CFLAGS=-fno-stack-protector make -C openlibm + CROSSCC=$(CC) CFLAGS=-fno-stack-protector make -C openlibm libopenlibm.a $(BUILD)/libopenlibm.a: openlibm/libopenlibm.a mkdir -p $(BUILD) @@ -213,7 +233,7 @@ $(BUILD)/initfs.rs: \ echo ' let mut files: BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> = BTreeMap::new();' >> $@ for folder in `find initfs -type d | sort`; do \ name=$$(echo $$folder | sed 's/initfs//' | cut -d '/' -f2-) ; \ - echo -n ' files.insert(b"'$$name'", (b"' >> $@ ; \ + $(ECHO) -n ' files.insert(b"'$$name'", (b"' >> $@ ; \ ls -1 $$folder | sort | awk 'NR > 1 {printf("\\n")} {printf("%s", $$0)}' >> $@ ; \ echo '", true));' >> $@ ; \ done @@ -379,7 +399,7 @@ $(BUILD)/filesystem.bin: \ chmod +s $(BUILD)/filesystem/bin/su chmod +s $(BUILD)/filesystem/bin/sudo sync - -fusermount -u $(BUILD)/filesystem/ + -$(FUMOUNT) $(BUILD)/filesystem/ rm -rf $(BUILD)/filesystem/ mount: FORCE @@ -389,7 +409,7 @@ mount: FORCE unmount: FORCE sync - -fusermount -u $(KBUILD)/harddrive/ + -$(FUMOUNT) $(KBUILD)/harddrive/ rm -rf $(KBUILD)/harddrive/ wireshark: FORCE diff --git a/arch/x86_64/src/interrupt/irq.rs b/arch/x86_64/src/interrupt/irq.rs index ad9151d..c6a8733 100644 --- a/arch/x86_64/src/interrupt/irq.rs +++ b/arch/x86_64/src/interrupt/irq.rs @@ -27,10 +27,10 @@ pub unsafe fn acknowledge(irq: usize) { } interrupt!(pit, { - irq_trigger(0); + // Saves CPU time by not sending IRQ event irq_trigger(0); { - const PIT_RATE: u64 = 46500044; + const PIT_RATE: u64 = 2250286; let mut offset = time::OFFSET.lock(); let sum = offset.1 + PIT_RATE; diff --git a/arch/x86_64/src/paging/mod.rs b/arch/x86_64/src/paging/mod.rs index 5ebfe11..352c390 100644 --- a/arch/x86_64/src/paging/mod.rs +++ b/arch/x86_64/src/paging/mod.rs @@ -7,7 +7,7 @@ use x86::{msr, tlb}; use memory::{allocate_frame, Frame}; -use self::entry::{EntryFlags, PRESENT, WRITABLE, NO_EXECUTE}; +use self::entry::{EntryFlags, PRESENT, GLOBAL, WRITABLE, NO_EXECUTE}; use self::mapper::Mapper; use self::temporary_page::TemporaryPage; @@ -129,7 +129,7 @@ pub unsafe fn init(cpu_id: usize, stack_start: usize, stack_end: usize) -> (Acti let start_page = Page::containing_address(VirtualAddress::new(start)); let end_page = Page::containing_address(VirtualAddress::new(end - 1)); for page in Page::range_inclusive(start_page, end_page) { - mapper.map(page, PRESENT | NO_EXECUTE | WRITABLE); + mapper.map(page, PRESENT | GLOBAL | NO_EXECUTE | WRITABLE); } } @@ -145,22 +145,22 @@ pub unsafe fn init(cpu_id: usize, stack_start: usize, stack_end: usize) -> (Acti }; // Remap stack writable, no execute - remap(stack_start - ::KERNEL_OFFSET, stack_end - ::KERNEL_OFFSET, PRESENT | NO_EXECUTE | WRITABLE); + remap(stack_start - ::KERNEL_OFFSET, stack_end - ::KERNEL_OFFSET, PRESENT | GLOBAL | NO_EXECUTE | WRITABLE); // Remap a section with `flags` let mut remap_section = |start: &u8, end: &u8, flags: EntryFlags| { remap(start as *const _ as usize - ::KERNEL_OFFSET, end as *const _ as usize - ::KERNEL_OFFSET, flags); }; // Remap text read-only - remap_section(& __text_start, & __text_end, PRESENT); + remap_section(& __text_start, & __text_end, PRESENT | GLOBAL); // Remap rodata read-only, no execute - remap_section(& __rodata_start, & __rodata_end, PRESENT | NO_EXECUTE); + remap_section(& __rodata_start, & __rodata_end, PRESENT | GLOBAL | NO_EXECUTE); // Remap data writable, no execute - remap_section(& __data_start, & __data_end, PRESENT | NO_EXECUTE | WRITABLE); + remap_section(& __data_start, & __data_end, PRESENT | GLOBAL | NO_EXECUTE | WRITABLE); // Remap tdata master writable, no execute - remap_section(& __tdata_start, & __tdata_end, PRESENT | NO_EXECUTE); + remap_section(& __tdata_start, & __tdata_end, PRESENT | GLOBAL | NO_EXECUTE); // Remap bss writable, no execute - remap_section(& __bss_start, & __bss_end, PRESENT | NO_EXECUTE | WRITABLE); + remap_section(& __bss_start, & __bss_end, PRESENT | GLOBAL | NO_EXECUTE | WRITABLE); } }); @@ -207,7 +207,7 @@ pub unsafe fn init_ap(cpu_id: usize, stack_start: usize, stack_end: usize, kerne let start_page = Page::containing_address(VirtualAddress::new(start)); let end_page = Page::containing_address(VirtualAddress::new(end - 1)); for page in Page::range_inclusive(start_page, end_page) { - mapper.map(page, PRESENT | NO_EXECUTE | WRITABLE); + mapper.map(page, PRESENT | GLOBAL | NO_EXECUTE | WRITABLE); } } @@ -223,7 +223,7 @@ pub unsafe fn init_ap(cpu_id: usize, stack_start: usize, stack_end: usize, kerne }; // Remap stack writable, no execute - remap(stack_start - ::KERNEL_OFFSET, stack_end - ::KERNEL_OFFSET, PRESENT | NO_EXECUTE | WRITABLE); + remap(stack_start - ::KERNEL_OFFSET, stack_end - ::KERNEL_OFFSET, PRESENT | GLOBAL | NO_EXECUTE | WRITABLE); }); active_table.switch(new_table); diff --git a/arch/x86_64/src/start.rs b/arch/x86_64/src/start.rs index ba51fe5..aebd865 100644 --- a/arch/x86_64/src/start.rs +++ b/arch/x86_64/src/start.rs @@ -101,7 +101,7 @@ pub unsafe extern fn kstart() -> ! { let heap_start_page = Page::containing_address(VirtualAddress::new(::KERNEL_HEAP_OFFSET)); let heap_end_page = Page::containing_address(VirtualAddress::new(::KERNEL_HEAP_OFFSET + ::KERNEL_HEAP_SIZE-1)); for page in Page::range_inclusive(heap_start_page, heap_end_page) { - active_table.map(page, entry::WRITABLE | entry::NO_EXECUTE); + active_table.map(page, entry::PRESENT | entry::GLOBAL | entry::WRITABLE | entry::NO_EXECUTE); } // Init the allocator diff --git a/bootloader/x86_64/initialize.asm b/bootloader/x86_64/initialize.asm index 1d468a1..e723d37 100644 --- a/bootloader/x86_64/initialize.asm +++ b/bootloader/x86_64/initialize.asm @@ -38,7 +38,7 @@ initialize: .pit: ;initialize the PIT - mov ax, 55483 ;5370 ;this is the divider for the PIT + mov ax, 2685 ;this is the divider for the PIT out 0x40, al rol ax, 8 out 0x40, al diff --git a/bootloader/x86_64/startup-x86_64.asm b/bootloader/x86_64/startup-x86_64.asm index abe600f..d49c532 100644 --- a/bootloader/x86_64/startup-x86_64.asm +++ b/bootloader/x86_64/startup-x86_64.asm @@ -26,9 +26,9 @@ startup_ap: mov edi, 0x70000 mov cr3, edi - ;enable Page Address Extension and Page Size Extension + ;enable Page Global, Page Address Extension, and Page Size Extension mov eax, cr4 - or eax, 1 << 5 | 1 << 4 + or eax, 1 << 7 | 1 << 5 | 1 << 4 mov cr4, eax ; load protected mode GDT @@ -91,9 +91,9 @@ startup_arch: mov edi, 0x70000 mov cr3, edi - ;enable Page Address Extension and Page Size Extension + ;enable Page Global, Page Address Extension, and Page Size Extension mov eax, cr4 - or eax, 1 << 5 | 1 << 4 + or eax, 1 << 7 | 1 << 5 | 1 << 4 mov cr4, eax ; load protected mode GDT diff --git a/drivers/ahcid/src/main.rs b/drivers/ahcid/src/main.rs index 880177b..fba2503 100644 --- a/drivers/ahcid/src/main.rs +++ b/drivers/ahcid/src/main.rs @@ -1,5 +1,4 @@ #![feature(asm)] -#![feature(question_mark)] #[macro_use] extern crate bitflags; diff --git a/drivers/e1000d/src/main.rs b/drivers/e1000d/src/main.rs index 3b097df..00b31db 100644 --- a/drivers/e1000d/src/main.rs +++ b/drivers/e1000d/src/main.rs @@ -1,5 +1,4 @@ #![feature(asm)] -#![feature(question_mark)] extern crate dma; extern crate event; diff --git a/krustdoc.sh b/krustdoc.sh new file mode 100755 index 0000000..de4cdb6 --- /dev/null +++ b/krustdoc.sh @@ -0,0 +1,2 @@ +#!/bin/bash +RUST_BACKTRACE=1 rustdoc -L build/kernel --cfg redox $* diff --git a/libstd b/libstd index dccb2ab..61ba409 160000 --- a/libstd +++ b/libstd @@ -1 +1 @@ -Subproject commit dccb2ab0edfa87653786fc865dc4fcbb9bce863b +Subproject commit 61ba4092b0d4bf9ab0346dbb51ef489a182a84a2 diff --git a/openlibm b/openlibm index 1581174..3c837e7 160000 --- a/openlibm +++ b/openlibm @@ -1 +1 @@ -Subproject commit 1581174c85f7b645b15ba1ac1c3a98fb601f0fe7 +Subproject commit 3c837e79655c4be724efb945a6345ec97c07635c diff --git a/programs/extrautils b/programs/extrautils index ee284d8..7339814 160000 --- a/programs/extrautils +++ b/programs/extrautils @@ -1 +1 @@ -Subproject commit ee284d86473467b3a3acf11199476612114a3d0a +Subproject commit 7339814a20c78077b484e2bf89708293ec8e1111 diff --git a/programs/init/Cargo.toml b/programs/init/Cargo.toml index cd1a1ed..dd47c74 100644 --- a/programs/init/Cargo.toml +++ b/programs/init/Cargo.toml @@ -1,3 +1,6 @@ [package] name = "init" version = "0.1.0" + +[dependencies] +syscall = { path = "../../syscall" } diff --git a/programs/init/src/main.rs b/programs/init/src/main.rs index 09c64f6..f6e6a98 100644 --- a/programs/init/src/main.rs +++ b/programs/init/src/main.rs @@ -1,3 +1,5 @@ +extern crate syscall; + use std::env; use std::fs::File; use std::io::{BufRead, BufReader, Result}; @@ -50,6 +52,17 @@ pub fn run(file: &str) -> Result<()> { } else { println!("init: failed to run: no argument"); }, + "stdio" => if let Some(stdio) = args.next() { + let _ = syscall::close(2); + let _ = syscall::close(1); + let _ = syscall::close(0); + + let _ = syscall::open(&stdio, syscall::flag::O_RDWR); + let _ = syscall::open(&stdio, syscall::flag::O_RDWR); + let _ = syscall::open(&stdio, syscall::flag::O_RDWR); + } else { + println!("init: failed to set stdio: no argument"); + }, _ => { let mut command = Command::new(cmd); for arg in args { diff --git a/programs/ion b/programs/ion index ad2580c..100ed07 160000 --- a/programs/ion +++ b/programs/ion @@ -1 +1 @@ -Subproject commit ad2580cd35c6f6be0f09dfe279ffd93882e6b074 +Subproject commit 100ed07adfc02143dfa6b4ba81f988cfd2c7a835 diff --git a/programs/orbutils b/programs/orbutils index 2212c9b..fa9156d 160000 --- a/programs/orbutils +++ b/programs/orbutils @@ -1 +1 @@ -Subproject commit 2212c9b4822c44af90164bffeef29d903e6b39da +Subproject commit fa9156dee23d6da5b20a76f596c9ed263c7bd408 diff --git a/programs/userutils b/programs/userutils index 3b7448c..a05b8f4 160000 --- a/programs/userutils +++ b/programs/userutils @@ -1 +1 @@ -Subproject commit 3b7448c8fdb15857b813a90b2fba81393ef043be +Subproject commit a05b8f4d258929af777041f1362c0b9fca4ad090 diff --git a/ralloc b/ralloc index 65495da..be2a916 160000 --- a/ralloc +++ b/ralloc @@ -1 +1 @@ -Subproject commit 65495da00fc74e40b0047749a5d498547a07dfaa +Subproject commit be2a916a257344ed09345177f01b8fb367542185 diff --git a/rustdoc.sh b/rustdoc.sh new file mode 100755 index 0000000..4eff5a2 --- /dev/null +++ b/rustdoc.sh @@ -0,0 +1,2 @@ +#!/bin/bash +RUST_BACKTRACE=1 rustdoc -L build/userspace --cfg redox $*