### Git Installation and Configuration Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/git Installs Git using apt-get and configures global user settings such as name, email, default editor, and enables UI coloring. ```bash apt-get install git git config --global user.name "Zhang San" git config --global user.email "zhangsan@foo.com" git config --global core.editor vim git config --global color.ui true ``` -------------------------------- ### Git Repository Initialization and Cloning Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/git Initializes a new Git repository in the current directory or clones an existing repository from a remote source. ```bash git init git clone ``` -------------------------------- ### Git Branching and Checkout Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/git Manages branches by listing them, checking out existing branches or commits, and creating new branches from current work. ```bash git branch git checkout git checkout -B ``` -------------------------------- ### Git Add and Commit Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/git Stages changes for commit, tracks new files, and commits the staged changes with a descriptive message. Includes a note on using `.gitignore`. ```bash git add git add -A git commit ``` -------------------------------- ### Initialize SDL Audio Subsystem - C Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.5 Initializes the SDL audio subsystem with specified parameters and opens the audio device. It then starts audio playback. This snippet is part of the sound card implementation. ```c SDL_AudioSpec s = {}; s.format = AUDIO_S16SYS; // Assume system audio data format is always 16-bit signed s.userdata = NULL; // Not used ...... SDL_InitSubSystem(SDL_INIT_AUDIO); SDL_OpenAudio(&s, NULL); SDL_PauseAudio(0); ``` -------------------------------- ### Install ccache for Build Optimization Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/1.1 This command installs the ccache tool, a compiler cache that speeds up recompilation by storing previous build results. It is useful for projects with frequent rebuilds. ```bash apt-get install ccache ``` -------------------------------- ### Git Status and Logging Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/git Checks the current status of the working directory and staging area, and displays the commit history. ```bash git status git log ``` -------------------------------- ### Program as a State Machine Sequence Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/1.2 This example visualizes a program's execution as a sequence of state transitions within a state machine model. Starting from an initial state (e.g., state 8), each instruction execution corresponds to a transition to a new state. The example shows a potential execution path for a given program. ```pseudocode 8->1->32->31->32->31->... ``` -------------------------------- ### Install scons Build Tool Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/4.1 Installs the 'scons' build system, which is required to compile the RT-Thread codebase after it has been integrated with the Abstract Machine (AM). This step is crucial for the build process. ```bash apt-get install scons ``` -------------------------------- ### Implementing execve with Parameters in C Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/4.1 This snippet demonstrates the implementation of the `execve` system call with parameters. It involves creating a new process context, allocating user stack space using `new_page()`, and handling the termination of the current process flow. The `context_uload()` function is central to setting up the new process, and `switch_boot_pcb()` along with `yield()` are used to initiate process scheduling. ```c /* ... (context_uload and related functions) ... */ // In sys_execve() or similar handler: int sys_execve(const char *fname, char *const argv[], char *const envp[]) { struct pcb *new_pcb = alloc_pcb(); // Allocate a new PCB if (!new_pcb) return -1; // Allocation failed // Allocate user stack space for the new process void *user_stack = new_page(32); // Allocate 32KB for user stack if (!user_stack) { free_pcb(new_pcb); // Clean up if stack allocation fails return -1; } // Prepare arguments and environment for context_uload // ... (details depend on specific implementation of context_uload) // Load the new program into the new process context if (context_uload(new_pcb, fname, argv, envp, user_stack) != 0) { // Handle context loading error, potentially free user_stack and new_pcb return -1; } // Terminate the current process flow and schedule the new one switch_boot_pcb(new_pcb); yield(); return 0; // Indicate success (though the current process is effectively replaced) } // Note: Specific details for context_uload parameters and PCB setup are omitted and depend on the project's architecture. ``` -------------------------------- ### Install RISC-V Cross-Compilation Tools Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.2 This command installs the necessary GCC and binutils for RISC-V32/64 cross-compilation on a Debian-based system. These tools are essential for compiling C code to run on a RISC-V target architecture within NEMU. ```bash apt-get install g++-riscv64-linux-gnu binutils-riscv64-linux-gnu ``` -------------------------------- ### Install MIPS Cross-Compilation Tools Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.2 This command installs the necessary GCC and binutils for MIPS32 cross-compilation on a Debian-based system. These tools are essential for compiling C code to run on a MIPS32 target architecture within NEMU. ```bash apt-get install g++-mips-linux-gnu binutils-mips-linux-gnu ``` -------------------------------- ### Running Hello World in NEMU (Makefile) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.5 Instructions for compiling and running the 'hello world' program on the NEMU simulator. The process varies slightly depending on the target architecture (x86 requires manual implementation of in/out instructions, while mips32 and riscv32 are supported by default). ```makefile ARCH ?= x86 # For x86, ensure in/out instructions are implemented and call pio_read/pio_write correctly. # For mips32 and riscv32, MMIO is already supported. # Build and run the hello world kernel make ARCH=$(ARCH) -C am-kernels/kernels/hello run # Example with custom main arguments make ARCH=$(ARCH) run mainargs=I-love-PA ``` -------------------------------- ### Compiling QEMU for DiffTest (Shell) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.4 This shell command installs the QEMU system emulator, which can be used as a reference (REF) for DiffTest on MIPS32 architectures within NEMU. Proper installation of QEMU is necessary for its integration with NEMU's DiffTest functionality. ```shell apt-get install qemu-system ``` -------------------------------- ### Prepare and Compile RT-Thread on AM (Native) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/4.1 Initializes the RT-Thread build environment for the Abstract Machine (AM) and compiles the RT-Thread kernel. The `make init` command performs one-time setup, while `make ARCH=native` compiles the system for the native environment. This process results in the RT-Thread kernel running on AM. ```bash cd rt-thread-am/bsp/abstract-machine/ make init make ARCH=native ``` -------------------------------- ### x86 mov Instruction Examples Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/exec Demonstrates two example x86 'mov' instructions from the NEMU client program. The first is a simple move of an immediate value to a register, and the second involves moving a word to a memory address with a complex offset. ```assembly 100000: b8 34 12 00 00 mov $0x1234,%eax ...... 100017: 66 c7 84 99 00 e0 ff movw $0x1,-0x2000(%ecx,%ebx,4) 10001e: ff 01 00 ``` -------------------------------- ### Basic Makefile for Compilation and Cleaning Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/linux This Makefile defines two rules: `hello` for compiling `hello.c` into an executable named `hello`, and `clean` for removing the `hello` executable. It demonstrates the basic syntax of a Makefile with targets, dependencies, and commands. Note the use of tabs before commands, which is crucial. ```makefile hello:hello.c gcc hello.c -o hello # 注意开头的tab, 而不是空格 .PHONY: clean clean: rm hello # 注意开头的tab, 而不是空格 ``` -------------------------------- ### AddressSanitizer Error Example (LeakSanitizer) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/1.6 An example output from AddressSanitizer's LeakSanitizer component, indicating a memory leak. It details the size of the leak, the number of objects, and the allocation call stack. This helps pinpoint memory management issues. Dependencies: AddressSanitizer enabled during compilation. ```text ====ERROR: LeakSanitizer: detected memory leaks Direct leak of 32 byte(s) in 1 object(s) allocated from: #0 0x7f55100b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f5510b4fbac in xmalloc (/lib/x86_64-linux-gnu/libreadline.so.8+0x39bac) SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s). ``` -------------------------------- ### MIPS32 Branch Delay Slot Example Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.2 Illustrates the execution flow of MIPS32 instructions involving a branch delay slot. The example shows how the instruction immediately following a branch (the delay slot) is executed before the target instruction, regardless of whether the branch is taken. This technique requires software and hardware coordination for correct program execution. ```assembly 100: beq 200 101: add 102: xor ... 200: sub 201: j 102 202: slt ``` -------------------------------- ### Instruction Fetch and PC Update (C) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.2 Illustrates the basic instruction fetch operation using `inst_fetch` and the update of the program counter (PC). It highlights the distinction between static next PC (snpc) and dynamic next PC (dnpc), emphasizing that `dnpc` should be used for updating the actual PC to handle control flow changes like jumps. ```c imm = inst_fetch(pc, 4); // ... // Update PC with dynamic next PC s->pc = s->dnpc; ``` -------------------------------- ### NEMU Build and Run Test Case Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.2 This command demonstrates how to build and run a specific test case (e.g., 'xxx') on NEMU for a given architecture. It utilizes the `make` utility with specified `ARCH` and `ALL` variables. ```bash make ARCH=$ISA-nemu ALL=xxx run ``` -------------------------------- ### Compile and Run Dummy C Program Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/2.2 This command compiles a 'dummy' C program and runs it within the NEMU emulator. It requires specifying the target architecture (ISA) and ensures that the compilation and execution process is set up correctly for the chosen ISA. ```bash make ARCH=$ISA-nemu ALL=dummy run ``` -------------------------------- ### User Program Entry Point (_start) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/3.3 The assembly code for the user program entry point `_start`. This function, located in `start.S`, is responsible for setting up the C runtime environment and calling the `crt0.c` initialization function. ```assembly .global _start _start: # Setup stack pointer if needed # Call crt0 initialization function call call_main # If call_main returns (e.g., main returned), call exit call exit ``` -------------------------------- ### Git Reset (Hard Mode) Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/git Resets the current HEAD to a specified state, discarding all commits after the target commit. Use with caution. ```bash git reset --hard ``` -------------------------------- ### 编译和运行C语言Hello World程序 Source: https://nju-projectn.github.io/ics-pa-gitbook/ics2024/linux 展示了如何使用gcc编译器编译C语言源代码生成可执行文件,并说明了如何执行该文件,以及./的含义。 ```shell gcc hello.c -o hello ./hello ```