From ae10d3e6986a53e85e1411ee2ee9393b92474568 Mon Sep 17 00:00:00 2001 From: Wang Chen Date: Thu, 27 Jan 2022 11:06:33 +0800 Subject: [PATCH] fixed some minor issues. - https://gitee.com/unicornx/riscv-operating-system-mooc/issues/I4QLTP - https://gitee.com/unicornx/riscv-operating-system-mooc/issues/I4PJTQ - https://gitee.com/unicornx/riscv-operating-system-mooc/issues/I49VW5 Signed-off-by: Wang Chen --- code/asm/asm2c/test.s | 2 +- code/asm/c2asm/test.s | 2 +- code/asm/cc_leaf/test.s | 118 +++++++++---------- code/asm/cc_nested/test.s | 198 ++++++++++++++++---------------- code/asm/srai/test.s | 46 ++++---- code/os/01-helloRVOS/uart.c | 2 +- code/os/02-memanagement/uart.c | 2 +- code/os/03-contextswitch/uart.c | 2 +- code/os/04-multitask/uart.c | 2 +- code/os/05-traps/uart.c | 2 +- code/os/06-interrupts/uart.c | 2 +- code/os/07-hwtimer/uart.c | 2 +- code/os/08-preemptive/uart.c | 2 +- code/os/09-lock/uart.c | 2 +- code/os/10-swtimer/uart.c | 2 +- code/os/11-syscall/uart.c | 2 +- 16 files changed, 194 insertions(+), 194 deletions(-) diff --git a/code/asm/asm2c/test.s b/code/asm/asm2c/test.s index 8292fa2..c6f7dab 100644 --- a/code/asm/asm2c/test.s +++ b/code/asm/asm2c/test.s @@ -20,7 +20,7 @@ stop: nop # just for demo effect stack_start: - .rept 10 + .rept 12 .word 0 .endr stack_end: diff --git a/code/asm/c2asm/test.s b/code/asm/c2asm/test.s index cbf6e31..07134e0 100644 --- a/code/asm/c2asm/test.s +++ b/code/asm/c2asm/test.s @@ -17,7 +17,7 @@ stop: nop # just for demo effect stack_start: - .rept 10 + .rept 12 .word 0 .endr stack_end: diff --git a/code/asm/cc_leaf/test.s b/code/asm/cc_leaf/test.s index 92880ff..986e054 100644 --- a/code/asm/cc_leaf/test.s +++ b/code/asm/cc_leaf/test.s @@ -1,59 +1,59 @@ -# Calling Convention -# Demo to create a leaf routine -# -# void _start() -# { -# // calling leaf routine -# square(3); -# } -# -# int square(int num) -# { -# return num * num; -# } - - .text # Define beginning of text section - .global _start # Define entry _start - -_start: - la sp, stack_end # prepare stack for calling functions - - li a0, 3 - call square - - # the time return here, a0 should stores the result -stop: - j stop # Infinite loop to stop execution - -# int square(int num) -square: - # prologue - addi sp, sp, -8 - sw s0, 0(sp) - sw s1, 4(sp) - - # `mul a0, a0, a0` should be fine, - # programing as below just to demo we can contine use the stack - mv s0, a0 - mul s1, s0, s0 - mv a0, s1 - - # epilogue - lw s0, 0(sp) - lw s1, 4(sp) - addi sp, sp, 8 - - ret - - # add nop here just for demo in gdb - nop - - # allocate stack space -stack_start: - .rept 10 - .word 0 - .endr -stack_end: - - .end # End of file - +# Calling Convention +# Demo to create a leaf routine +# +# void _start() +# { +# // calling leaf routine +# square(3); +# } +# +# int square(int num) +# { +# return num * num; +# } + + .text # Define beginning of text section + .global _start # Define entry _start + +_start: + la sp, stack_end # prepare stack for calling functions + + li a0, 3 + call square + + # the time return here, a0 should stores the result +stop: + j stop # Infinite loop to stop execution + +# int square(int num) +square: + # prologue + addi sp, sp, -8 + sw s0, 0(sp) + sw s1, 4(sp) + + # `mul a0, a0, a0` should be fine, + # programing as below just to demo we can contine use the stack + mv s0, a0 + mul s1, s0, s0 + mv a0, s1 + + # epilogue + lw s0, 0(sp) + lw s1, 4(sp) + addi sp, sp, 8 + + ret + + # add nop here just for demo in gdb + nop + + # allocate stack space +stack_start: + .rept 12 + .word 0 + .endr +stack_end: + + .end # End of file + diff --git a/code/asm/cc_nested/test.s b/code/asm/cc_nested/test.s index c32d76d..cfe3441 100644 --- a/code/asm/cc_nested/test.s +++ b/code/asm/cc_nested/test.s @@ -1,99 +1,99 @@ -# Calling Convention -# Demo how to write nested routines -# -# void _start() -# { -# // calling nested routine -# aa_bb(3, 4); -# } -# -# int aa_bb(int a, int b) -# { -# return square(a) + square(b); -# } -# -# int square(int num) -# { -# return num * num; -# } - - .text # Define beginning of text section - .global _start # Define entry _start - -_start: - la sp, stack_end # prepare stack for calling functions - - # aa_bb(3, 4); - li a0, 3 - li a1, 4 - call aa_bb - -stop: - j stop # Infinite loop to stop execution - -# int aa_bb(int a, int b) -# return a^2 + b^2 -aa_bb: - # prologue - addi sp, sp, -16 - sw s0, 0(sp) - sw s1, 4(sp) - sw s2, 8(sp) - sw ra, 12(sp) - - # cp and store the input params - mv s0, a0 - mv s1, a1 - - # sum will be stored in s2 and is initialized as zero - li s2, 0 - - mv a0, s0 - jal square - add s2, s2, a0 - - mv a0, s1 - jal square - add s2, s2, a0 - - mv a0, s2 - - # epilogue - lw s0, 0(sp) - lw s1, 4(sp) - lw s2, 8(sp) - lw ra, 12(sp) - addi sp, sp, 16 - ret - -# int square(int num) -square: - # prologue - addi sp, sp, -8 - sw s0, 0(sp) - sw s1, 4(sp) - - # `mul a0, a0, a0` should be fine, - # programing as below just to demo we can contine use the stack - mv s0, a0 - mul s1, s0, s0 - mv a0, s1 - - # epilogue - lw s0, 0(sp) - lw s1, 4(sp) - addi sp, sp, 8 - - ret - - # add nop here just for demo in gdb - nop - - # allocate stack space -stack_start: - .rept 10 - .word 0 - .endr -stack_end: - - .end # End of file +# Calling Convention +# Demo how to write nested routines +# +# void _start() +# { +# // calling nested routine +# aa_bb(3, 4); +# } +# +# int aa_bb(int a, int b) +# { +# return square(a) + square(b); +# } +# +# int square(int num) +# { +# return num * num; +# } + + .text # Define beginning of text section + .global _start # Define entry _start + +_start: + la sp, stack_end # prepare stack for calling functions + + # aa_bb(3, 4); + li a0, 3 + li a1, 4 + call aa_bb + +stop: + j stop # Infinite loop to stop execution + +# int aa_bb(int a, int b) +# return a^2 + b^2 +aa_bb: + # prologue + addi sp, sp, -16 + sw s0, 0(sp) + sw s1, 4(sp) + sw s2, 8(sp) + sw ra, 12(sp) + + # cp and store the input params + mv s0, a0 + mv s1, a1 + + # sum will be stored in s2 and is initialized as zero + li s2, 0 + + mv a0, s0 + jal square + add s2, s2, a0 + + mv a0, s1 + jal square + add s2, s2, a0 + + mv a0, s2 + + # epilogue + lw s0, 0(sp) + lw s1, 4(sp) + lw s2, 8(sp) + lw ra, 12(sp) + addi sp, sp, 16 + ret + +# int square(int num) +square: + # prologue + addi sp, sp, -8 + sw s0, 0(sp) + sw s1, 4(sp) + + # `mul a0, a0, a0` should be fine, + # programing as below just to demo we can contine use the stack + mv s0, a0 + mul s1, s0, s0 + mv a0, s1 + + # epilogue + lw s0, 0(sp) + lw s1, 4(sp) + addi sp, sp, 8 + + ret + + # add nop here just for demo in gdb + nop + + # allocate stack space +stack_start: + .rept 12 + .word 0 + .endr +stack_end: + + .end # End of file diff --git a/code/asm/srai/test.s b/code/asm/srai/test.s index c17369b..e20e4f4 100644 --- a/code/asm/srai/test.s +++ b/code/asm/srai/test.s @@ -1,23 +1,23 @@ -# Shift Right Arithmetic Immediate -# Format: -# SLLI RD, RS1, IMM -# Description: -# The immediate value determines the number of bits to shift. The contents of -# RS1 is shifted right that many bits and the result is placed in RD. The shift -# is “arithmetic”, i.e., the sign bit is repeatedly shifted in on the -# most-significant end. -# Comment: -# In C, for signed integer, >> is shift right with arithmetic. - - .text # Define beginning of text section - .global _start # Define entry _start - -_start: -# li x6, 0x80 # x6 = 0b1000-0000 - li x6, 0x80000000 # x6 = 0b1000-0000-0000-0000-0000-0000-0000-0000 - srai x5, x6, 4 # x5 = x6 >> 3 - -stop: - j stop # Infinite loop to stop execution - - .end # End of file +# Shift Right Arithmetic Immediate +# Format: +# SRAI RD, RS1, IMM +# Description: +# The immediate value determines the number of bits to shift. The contents of +# RS1 is shifted right that many bits and the result is placed in RD. The shift +# is “arithmetic”, i.e., the sign bit is repeatedly shifted in on the +# most-significant end. +# Comment: +# In C, for signed integer, >> is shift right with arithmetic. + + .text # Define beginning of text section + .global _start # Define entry _start + +_start: +# li x6, 0x80 # x6 = 0b1000-0000 + li x6, 0x80000000 # x6 = 0b1000-0000-0000-0000-0000-0000-0000-0000 + srai x5, x6, 4 # x5 = x6 >> 4 + +stop: + j stop # Infinite loop to stop execution + + .end # End of file diff --git a/code/os/01-helloRVOS/uart.c b/code/os/01-helloRVOS/uart.c index a4945a2..89781da 100644 --- a/code/os/01-helloRVOS/uart.c +++ b/code/os/01-helloRVOS/uart.c @@ -33,7 +33,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/02-memanagement/uart.c b/code/os/02-memanagement/uart.c index db80aeb..ed22367 100644 --- a/code/os/02-memanagement/uart.c +++ b/code/os/02-memanagement/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/03-contextswitch/uart.c b/code/os/03-contextswitch/uart.c index db80aeb..ed22367 100644 --- a/code/os/03-contextswitch/uart.c +++ b/code/os/03-contextswitch/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/04-multitask/uart.c b/code/os/04-multitask/uart.c index db80aeb..ed22367 100644 --- a/code/os/04-multitask/uart.c +++ b/code/os/04-multitask/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/05-traps/uart.c b/code/os/05-traps/uart.c index db80aeb..ed22367 100644 --- a/code/os/05-traps/uart.c +++ b/code/os/05-traps/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/06-interrupts/uart.c b/code/os/06-interrupts/uart.c index 2905331..a75a1ef 100644 --- a/code/os/06-interrupts/uart.c +++ b/code/os/06-interrupts/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/07-hwtimer/uart.c b/code/os/07-hwtimer/uart.c index 2905331..a75a1ef 100644 --- a/code/os/07-hwtimer/uart.c +++ b/code/os/07-hwtimer/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/08-preemptive/uart.c b/code/os/08-preemptive/uart.c index 2905331..a75a1ef 100644 --- a/code/os/08-preemptive/uart.c +++ b/code/os/08-preemptive/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/09-lock/uart.c b/code/os/09-lock/uart.c index 2905331..a75a1ef 100644 --- a/code/os/09-lock/uart.c +++ b/code/os/09-lock/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/10-swtimer/uart.c b/code/os/10-swtimer/uart.c index 2905331..a75a1ef 100644 --- a/code/os/10-swtimer/uart.c +++ b/code/os/10-swtimer/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0 diff --git a/code/os/11-syscall/uart.c b/code/os/11-syscall/uart.c index 2905331..a75a1ef 100644 --- a/code/os/11-syscall/uart.c +++ b/code/os/11-syscall/uart.c @@ -32,7 +32,7 @@ /* * POWER UP DEFAULTS - * IER = 0: TX/RX holding register interrupts are bith disabled + * IER = 0: TX/RX holding register interrupts are both disabled * ISR = 1: no interrupt penting * LCR = 0 * MCR = 0