From 9547bf77af6ddc88de7b80aea9b95d06953cf058 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Fri, 25 Oct 2019 19:37:51 +0200 Subject: [PATCH] Fix diff script Closes #32 --- 02_runtime_init/README.md | 1 + 03_hacky_hello_world/README.md | 4 ++-- 04_zero_overhead_abstraction/README.md | 1 + 05_safe_globals/README.md | 6 +++--- 06_drivers_gpio_uart/Makefile | 2 +- 06_drivers_gpio_uart/README.md | 21 +++++++++------------ 07_uart_chainloader/Makefile | 4 +++- 07_uart_chainloader/README.md | 24 ++++++++++++------------ 08_timestamps/Makefile | 2 +- 08_timestamps/README.md | 24 ++++++++++++------------ utils/helpers/diff_tut_folders.bash | 9 +++++---- 11 files changed, 50 insertions(+), 48 deletions(-) diff --git a/02_runtime_init/README.md b/02_runtime_init/README.md index efd8c4bd..3907ef38 100644 --- a/02_runtime_init/README.md +++ b/02_runtime_init/README.md @@ -133,4 +133,5 @@ diff -uNr 01_wait_forever/src/runtime_init.rs 02_runtime_init/src/runtime_init.r + + crate::kernel_init() +} + ``` diff --git a/03_hacky_hello_world/README.md b/03_hacky_hello_world/README.md index b521b492..c6b173b0 100644 --- a/03_hacky_hello_world/README.md +++ b/03_hacky_hello_world/README.md @@ -217,8 +217,7 @@ diff -uNr 02_runtime_init/src/print.rs 03_hacky_hello_world/src/print.rs +/// Carbon copy from https://doc.rust-lang.org/src/std/macros.rs.html +#[macro_export] +macro_rules! println { -+ () => ($crate::print!(" -")); ++ () => ($crate::print!("\n")); + ($($arg:tt)*) => ({ + $crate::print::_print(format_args_nl!($($arg)*)); + }) @@ -229,4 +228,5 @@ diff -uNr 02_runtime_init/src/print.rs 03_hacky_hello_world/src/print.rs + + bsp::console().write_fmt(args).unwrap(); +} + ``` diff --git a/04_zero_overhead_abstraction/README.md b/04_zero_overhead_abstraction/README.md index a62ce90c..371650b3 100644 --- a/04_zero_overhead_abstraction/README.md +++ b/04_zero_overhead_abstraction/README.md @@ -150,4 +150,5 @@ diff -uNr 03_hacky_hello_world/src/runtime_init.rs 04_zero_overhead_abstraction/ extern "C" { // Boundaries of the .bss section, provided by the linker script. static mut __bss_start: u64; + ``` diff --git a/05_safe_globals/README.md b/05_safe_globals/README.md index 9c68b70b..51fe8053 100644 --- a/05_safe_globals/README.md +++ b/05_safe_globals/README.md @@ -167,9 +167,8 @@ diff -uNr 04_zero_overhead_abstraction/src/bsp/rpi.rs 05_safe_globals/src/bsp/rp - unsafe { - core::ptr::write_volatile(0x3F20_1000 as *mut u8, c as u8); + // Convert newline to carrige return + newline. -+ if c == ' -' { -+ self.write_char(' ') ++ if c == '\n' { ++ self.write_char('\r') } + + self.write_char(c); @@ -346,4 +345,5 @@ diff -uNr 04_zero_overhead_abstraction/src/main.rs 05_safe_globals/src/main.rs + println!("[2] Stopping here."); arch::wait_forever() } + ``` diff --git a/06_drivers_gpio_uart/Makefile b/06_drivers_gpio_uart/Makefile index 4c611a40..6ba564ab 100644 --- a/06_drivers_gpio_uart/Makefile +++ b/06_drivers_gpio_uart/Makefile @@ -65,8 +65,8 @@ doc: xdg-open target/$(TARGET)/doc/kernel/index.html ifeq ($(QEMU_MACHINE_TYPE),) -$(info This board is not yet supported for QEMU.) qemu: + @echo "This board is not yet supported for QEMU." else qemu: all $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ diff --git a/06_drivers_gpio_uart/README.md b/06_drivers_gpio_uart/README.md index f8f39ed6..fd256520 100644 --- a/06_drivers_gpio_uart/README.md +++ b/06_drivers_gpio_uart/README.md @@ -118,8 +118,8 @@ diff -uNr 05_safe_globals/Makefile 06_drivers_gpio_uart/Makefile xdg-open target/$(TARGET)/doc/kernel/index.html +ifeq ($(QEMU_MACHINE_TYPE),) -+$(info This board is not yet supported for QEMU.) +qemu: ++ @echo "This board is not yet supported for QEMU." +else qemu: all $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ @@ -522,9 +522,8 @@ diff -uNr 05_safe_globals/src/bsp/driver/bcm/bcm2xxx_pl011_uart.rs 06_drivers_gp + fn write_str(&mut self, s: &str) -> fmt::Result { + for c in s.chars() { + // Convert newline to carrige return + newline. -+ if c == ' -' { -+ self.write_char(' ') ++ if c == '\n' { ++ self.write_char('\r') + } + + self.write_char(c); @@ -624,9 +623,8 @@ diff -uNr 05_safe_globals/src/bsp/driver/bcm/bcm2xxx_pl011_uart.rs 06_drivers_gp + let mut ret = inner.DR.get() as u8 as char; + + // Convert carrige return to newline. -+ if ret == ' ' { -+ ret = ' -' ++ if ret == '\r' { ++ ret = '\n' + } + + ret @@ -746,9 +744,8 @@ diff -uNr 05_safe_globals/src/bsp/rpi.rs 06_drivers_gpio_uart/src/bsp/rpi.rs - fn write_str(&mut self, s: &str) -> fmt::Result { - for c in s.chars() { - // Convert newline to carrige return + newline. -- if c == ' -' { -- self.write_char(' ') +- if c == '\n' { +- self.write_char('\r') - } - - self.write_char(c); @@ -934,8 +931,7 @@ diff -uNr 05_safe_globals/src/main.rs 06_drivers_gpio_uart/src/main.rs + + // UART should be functional now. Wait for user to hit Enter. + loop { -+ if bsp::console().read_char() == ' -' { ++ if bsp::console().read_char() == '\n' { + break; + } + } @@ -959,4 +955,5 @@ diff -uNr 05_safe_globals/src/main.rs 06_drivers_gpio_uart/src/main.rs + bsp::console().write_char(c); + } } + ``` diff --git a/07_uart_chainloader/Makefile b/07_uart_chainloader/Makefile index aee6c01e..f411e281 100644 --- a/07_uart_chainloader/Makefile +++ b/07_uart_chainloader/Makefile @@ -72,9 +72,11 @@ doc: xdg-open target/$(TARGET)/doc/kernel/index.html ifeq ($(QEMU_MACHINE_TYPE),) -$(info This board is not yet supported for QEMU.) qemu: + @echo "This board is not yet supported for QEMU." + qemuasm: + @echo "This board is not yet supported for QEMU." else qemu: all $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ diff --git a/07_uart_chainloader/README.md b/07_uart_chainloader/README.md index 6ceac950..bc4ab3bd 100644 --- a/07_uart_chainloader/README.md +++ b/07_uart_chainloader/README.md @@ -120,11 +120,13 @@ diff -uNr 06_drivers_gpio_uart/Makefile 07_uart_chainloader/Makefile all: clean $(OUTPUT) -@@ -67,12 +74,22 @@ +@@ -67,12 +74,24 @@ ifeq ($(QEMU_MACHINE_TYPE),) - $(info This board is not yet supported for QEMU.) qemu: + @echo "This board is not yet supported for QEMU." ++ +qemuasm: ++ @echo "This board is not yet supported for QEMU." else qemu: all $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ @@ -189,9 +191,8 @@ diff -uNr 06_drivers_gpio_uart/src/bsp/driver/bcm/bcm2xxx_pl011_uart.rs 07_uart_ + } - // Convert carrige return to newline. -- if ret == ' ' { -- ret = ' -' +- if ret == '\r' { +- ret = '\n' + fn clear(&self) { + let mut r = &self.inner; + r.lock(|inner| loop { @@ -300,14 +301,13 @@ diff -uNr 06_drivers_gpio_uart/src/main.rs 07_uart_chainloader/src/main.rs - // UART should be functional now. Wait for user to hit Enter. - loop { -- if bsp::console().read_char() == ' -' { +- if bsp::console().read_char() == '\n' { - break; - } + println!(" __ __ _ _ _ _ "); -+ println!("| \/ (_)_ _ (_) | ___ __ _ __| |"); -+ println!("| |\/| | | ' \| | |__/ _ \/ _` / _` |"); -+ println!("|_| |_|_|_||_|_|____\___/\__,_\__,_|"); ++ println!("| \\/ (_)_ _ (_) | ___ __ _ __| |"); ++ println!("| |\\/| | | ' \\| | |__/ _ \\/ _` / _` |"); ++ println!("|_| |_|_|_||_|_|____\\___/\\__,_\\__,_|"); + println!(); + println!("{:^37}", bsp::board_name()); + println!(); @@ -347,8 +347,7 @@ diff -uNr 06_drivers_gpio_uart/src/main.rs 07_uart_chainloader/src/main.rs - println!("[2] Chars written: {}", bsp::console().chars_written()); - println!("[3] Echoing input now"); -+ println!("[ML] Loaded! Executing the payload now -"); ++ println!("[ML] Loaded! Executing the payload now\n"); + bsp::console().flush(); - loop { @@ -469,4 +468,5 @@ diff -uNr 06_drivers_gpio_uart/src/runtime_init.rs 07_uart_chainloader/src/runti +pub fn get() -> &'static dyn RunTimeInit { + &Traitor {} } + ``` diff --git a/08_timestamps/Makefile b/08_timestamps/Makefile index 656a12b9..fe1b643c 100644 --- a/08_timestamps/Makefile +++ b/08_timestamps/Makefile @@ -70,8 +70,8 @@ doc: xdg-open target/$(TARGET)/doc/kernel/index.html ifeq ($(QEMU_MACHINE_TYPE),) -$(info This board is not yet supported for QEMU.) qemu: + @echo "This board is not yet supported for QEMU." else qemu: all $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ diff --git a/08_timestamps/README.md b/08_timestamps/README.md index 760071bc..7940c540 100644 --- a/08_timestamps/README.md +++ b/08_timestamps/README.md @@ -70,11 +70,13 @@ diff -uNr 07_uart_chainloader/Makefile 08_timestamps/Makefile all: clean $(OUTPUT) -@@ -74,21 +72,16 @@ +@@ -74,23 +72,16 @@ ifeq ($(QEMU_MACHINE_TYPE),) - $(info This board is not yet supported for QEMU.) qemu: + @echo "This board is not yet supported for QEMU." +- -qemuasm: +- @echo "This board is not yet supported for QEMU." else qemu: all $(DOCKER_CMD) $(DOCKER_ARG_CURDIR) $(CONTAINER_UTILS) \ @@ -237,9 +239,8 @@ diff -uNr 07_uart_chainloader/src/bsp/driver/bcm/bcm2xxx_pl011_uart.rs 08_timest + let mut ret = inner.DR.get() as u8 as char; + + // Convert carrige return to newline. -+ if ret == ' ' { -+ ret = ' -' ++ if ret == '\r' { ++ ret = '\n' + } + + ret @@ -343,9 +344,9 @@ diff -uNr 07_uart_chainloader/src/main.rs 08_timestamps/src/main.rs - use interface::console::All; - - println!(" __ __ _ _ _ _ "); -- println!("| \/ (_)_ _ (_) | ___ __ _ __| |"); -- println!("| |\/| | | ' \| | |__/ _ \/ _` / _` |"); -- println!("|_| |_|_|_||_|_|____\___/\__,_\__,_|"); +- println!("| \\/ (_)_ _ (_) | ___ __ _ __| |"); +- println!("| |\\/| | | ' \\| | |__/ _ \\/ _` / _` |"); +- println!("|_| |_|_|_||_|_|____\\___/\\__,_\\__,_|"); - println!(); - println!("{:^37}", bsp::board_name()); - println!(); @@ -389,8 +390,7 @@ diff -uNr 07_uart_chainloader/src/main.rs 08_timestamps/src/main.rs + println!(" {}. {}", i + 1, driver.compatible()); } -- println!("[ML] Loaded! Executing the payload now -"); +- println!("[ML] Loaded! Executing the payload now\n"); - bsp::console().flush(); - - // Use black magic to get a function pointer. @@ -417,8 +417,7 @@ diff -uNr 07_uart_chainloader/src/print.rs 08_timestamps/src/print.rs -/// Carbon copy from https://doc.rust-lang.org/src/std/macros.rs.html #[macro_export] macro_rules! println { - () => ($crate::print!(" -")); + () => ($crate::print!("\n")); - ($($arg:tt)*) => ({ - $crate::print::_print(format_args_nl!($($arg)*)); + ($string:expr) => ({ @@ -594,4 +593,5 @@ diff -uNr 07_uart_chainloader/src/runtime_init.rs 08_timestamps/src/runtime_init - &Traitor {} + crate::kernel_init() } + ``` diff --git a/utils/helpers/diff_tut_folders.bash b/utils/helpers/diff_tut_folders.bash index ea2c76e0..de2e1121 100755 --- a/utils/helpers/diff_tut_folders.bash +++ b/utils/helpers/diff_tut_folders.bash @@ -14,7 +14,8 @@ DIFF=$( $1 $2 \ | sed -r "s/[12][90][127][90]-.*//g" \ | sed -r "s/[[:space:]]*$//g" \ - | sed -r "s/%/modulo/g" + | sed -r "s/%/modulo/g" \ + | sed -r "s/diff -uNr -x README.md -x kernel -x kernel8.img -x Cargo.lock -x target/\ndiff -uNr/g" ) HEADER="## Diff to previous" @@ -23,8 +24,8 @@ ORIGINAL=$( | sed -rn "/$HEADER/q;p" ) -printf "$ORIGINAL" > "$2/README.md" -printf "\n\n$HEADER\n" >> "$2/README.md" +echo "$ORIGINAL" > "$2/README.md" +printf "\n$HEADER\n" >> "$2/README.md" printf "\`\`\`diff\n" >> "$2/README.md" -printf "${DIFF//'diff -uNr -x README.md -x kernel -x kernel8.img -x Cargo.lock -x target'/'\ndiff -uNr'}" >> "$2/README.md" +echo "$DIFF" >> "$2/README.md" printf "\n\`\`\`\n" >> "$2/README.md"