Skip to content

Commit

Permalink
Fix diff script
Browse files Browse the repository at this point in the history
Closes #32
  • Loading branch information
andre-richter committed Oct 27, 2019
1 parent 88aa22b commit 8f2972d
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 48 deletions.
1 change: 1 addition & 0 deletions 02_runtime_init/README.md
Expand Up @@ -133,4 +133,5 @@ diff -uNr 01_wait_forever/src/runtime_init.rs 02_runtime_init/src/runtime_init.r
+
+ crate::kernel_init()
+}

```
4 changes: 2 additions & 2 deletions 03_hacky_hello_world/README.md
Expand Up @@ -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)*));
+ })
Expand All @@ -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();
+}

```
1 change: 1 addition & 0 deletions 04_zero_overhead_abstraction/README.md
Expand Up @@ -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;

```
6 changes: 3 additions & 3 deletions 05_safe_globals/README.md
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}

```
2 changes: 1 addition & 1 deletion 06_drivers_gpio_uart/Makefile
Expand Up @@ -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) \
Expand Down
21 changes: 9 additions & 12 deletions 06_drivers_gpio_uart/README.md
Expand Up @@ -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) \
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
+ }
+ }
Expand All @@ -959,4 +955,5 @@ diff -uNr 05_safe_globals/src/main.rs 06_drivers_gpio_uart/src/main.rs
+ bsp::console().write_char(c);
+ }
}

```
4 changes: 3 additions & 1 deletion 07_uart_chainloader/Makefile
Expand Up @@ -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) \
Expand Down
24 changes: 12 additions & 12 deletions 07_uart_chainloader/README.md
Expand Up @@ -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) \
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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!();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {}
}

```
2 changes: 1 addition & 1 deletion 08_timestamps/Makefile
Expand Up @@ -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) \
Expand Down
24 changes: 12 additions & 12 deletions 08_timestamps/README.md
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!();
Expand Down Expand Up @@ -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.
Expand All @@ -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) => ({
Expand Down Expand Up @@ -594,4 +593,5 @@ diff -uNr 07_uart_chainloader/src/runtime_init.rs 08_timestamps/src/runtime_init
- &Traitor {}
+ crate::kernel_init()
}

```
9 changes: 5 additions & 4 deletions utils/helpers/diff_tut_folders.bash
Expand Up @@ -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"
Expand All @@ -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"

0 comments on commit 8f2972d

Please sign in to comment.