-
-
Notifications
You must be signed in to change notification settings - Fork 4
Qemu to Avaota #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: avaota
Are you sure you want to change the base?
Conversation
…l1, /private/tmp/250313/nuttx/arch/arm64/src/common/arm64_mmu.c:616:11 err=Err(EXCEPTION) PC=0x40280634 WARNING: Your register accessing on id 290 is deprecated and will get UC_ERR_ARG in the future release (2.2.0) because the accessing is either no-op or not defined. If you believe the register should be implemented or there is a bug, please submit an issue to https://github.com/unicorn-engine/unicorn. Set UC_IGNORE_REG_BREAK=1 to ignore this warning. CP_REG=Ok(0) ESR_EL0=Ok(0) ESR_EL1=Ok(0) ESR_EL2=Ok(0) ESR_EL3=Ok(0) call_graph: enable_mmu_el1 --> ***_HALT_*** call_graph: click enable_mmu_el1 href "https://github.com/apache/nuttx/blob/master//private/tmp/250313/nuttx/arch/arm64/src/common/arm64_mmu.c#L605" "/private/tmp/250313/nuttx/arch/arm64/src/common/arm64_mmu.c " _blank Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
0x40280634 syndrome:2248147007 0x8600003f fsr:5 vaddress:1076623231 0x402bf77f target_el:1 Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
…ITS=32 Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @lupyuen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on transitioning the emulation environment from QEMU to Avaota, specifically using the Unicorn emulator. The changes include setting up the build environment, mapping memory regions, and implementing hooks for code emulation. A key addition is a diagram illustrating the NuttX boot flow, providing a visual representation of the system's startup process. The PR also incorporates a unit test for the Arm64 MMU.
Highlights
- Build Environment Setup: The
.vscode/tasks.json
file is modified to includeexport RUST_BACKTRACE=1
in the build command, enabling Rust backtraces for debugging purposes. - Memory Mapping and Code Emulation: The
src/main.rs
file is updated to map memory regions and implement hooks for code emulation using the Unicorn engine, replacing the previous QEMU setup. - NuttX Boot Flow Diagram: A Mermaid diagram illustrating the NuttX boot flow is added to
README.md
, providing a visual representation of the system's startup process. - Arm64 MMU Unit Test: The
src/main.rs
file includes a unit test for the Arm64 MMU, ensuring the memory management unit functions correctly within the emulated environment.
Changelog
Click here to see the changelog
- .vscode/bookmarks.json
- Adds a bookmark for a specific line in
unicorn_aarch64.c
.
- Adds a bookmark for a specific line in
- .vscode/tasks.json
- Adds
export RUST_BACKTRACE=1
to the build command to enable Rust backtraces.
- Adds
- README.md
- Adds a Mermaid diagram illustrating the NuttX boot flow, with clickable links to source code.
- Provides links to download the diagram in PDF, PNG, and SVG formats.
- mermaidRenderConfig.json
- Sets
maxTextSize
to a large value to prevent text overflow in Mermaid diagrams.
- Sets
- nuttx-boot-flow.mmd
- Defines the Mermaid diagram code for the NuttX boot flow, including nodes, links, and click interactions.
- src/main.rs
- Updates memory mapping to use the Unicorn engine instead of QEMU.
- Implements code hooks for instruction emulation.
- Adds a unit test for the Arm64 MMU.
- Changes UART base address and initialization method.
- Removes reliance on the
nuttx/Image
file and instead usesnuttx/nuttx.bin
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Did you know?
The Unicorn emulator is known for its fine-grained instrumentation, allowing developers to trace and analyze code execution at the instruction level.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces changes to the build process, README, and adds a mermaid diagram and configuration. The addition of the mermaid diagram is a great way to visualize the boot flow. The change to the task.json file adds backtrace support, which is helpful for debugging. Overall, the changes seem beneficial, but let's take a closer look.
Summary of Findings
- Inconsistent UART base address: The UART base address is changed from 0x02500000 to 0x90000000. Verify that this change is correct and consistent with the hardware documentation.
- Memory mapping and kernel loading: The memory mapping and kernel loading process has been modified. Ensure that the new mapping and loading mechanism is correct and doesn't introduce any memory corruption or security vulnerabilities.
- Missing error handling: The code uses
expect
for error handling, which can cause the program to crash if an error occurs. Consider using more robust error handling mechanisms, such asResult
and?
.
Merge Readiness
The pull request introduces significant changes to the system's core functionality. Due to the high
severity issues identified, I recommend that these issues be addressed before merging. Additionally, other reviewers should examine the changes to ensure system stability. I am unable to approve this pull request, and other reviewers should approve this code before merging.
static mut kernel_code: [u8; KERNEL_SIZE] = [0; KERNEL_SIZE]; | ||
|
||
/// UART Base Address | ||
const UART0_BASE_ADDRESS: u64 = 0x900_0000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Map the NuttX Kernel to 0x4028_0000 | ||
unsafe { | ||
emu.mem_map_ptr( | ||
ADDRESS, | ||
kernel_code.len(), | ||
Permission::READ | Permission::EXEC, | ||
kernel_code.as_mut_ptr() as _ | ||
).expect("failed to map kernel"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README.md
Outdated
click settimeofday href "https://github.com/apache/nuttx/blob/master/libs/libc/time/lib_settimeofday.c#L79" "libs/libc/time/lib_settimeofday.c " _blank | ||
memchr --> mm_addfreechunk | ||
click memchr href "https://github.com/apache/nuttx/blob/master/libs/libc/machine/arm64/gnu/arch_memchr.S#L155" "libs/libc/machine/arm64/gnu/arch_memchr.S " _blank | ||
mm_addfreechunk --> mm_size2ndx | ||
click mm_addfreechunk href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm.h#L326" "mm/mm_heap/mm.h " _blank | ||
mm_size2ndx --> STUB_utimens | ||
click mm_size2ndx href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm.h#L314" "mm/mm_heap/mm.h " _blank | ||
STUB_utimens --> STUB_writev | ||
click STUB_utimens href "https://github.com/apache/nuttx/blob/master/syscall/stubs/STUB_utimens.c#L7" "syscall/stubs/STUB_utimens.c " _blank | ||
click STUB_writev href "https://github.com/apache/nuttx/blob/master/syscall/stubs/STUB_writev.c#L7" "syscall/stubs/STUB_writev.c " _blank | ||
mm_size2ndx --> mm_realloc | ||
click mm_size2ndx href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm.h#L314" "mm/mm_heap/mm.h " _blank | ||
strncmp --> lib_get_tempbuffer | ||
click strncmp href "https://github.com/apache/nuttx/blob/master/libs/libc/machine/arm64/gnu/arch_strncmp.S#L92" "libs/libc/machine/arm64/gnu/arch_strncmp.S " _blank | ||
strncmp --> lib_get_tempbuffer | ||
click strncmp href "https://github.com/apache/nuttx/blob/master/libs/libc/machine/arm64/gnu/arch_strncmp.S#L106" "libs/libc/machine/arm64/gnu/arch_strncmp.S " _blank | ||
strncmp --> mm_realloc | ||
click strncmp href "https://github.com/apache/nuttx/blob/master/libs/libc/machine/arm64/gnu/arch_strncmp.S#L116" "libs/libc/machine/arm64/gnu/arch_strncmp.S " _blank | ||
mm_realloc --> memdump_handler | ||
click mm_realloc href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm_realloc.c#L117" "mm/mm_heap/mm_realloc.c " _blank | ||
memdump_handler --> addrenv_select | ||
click memdump_handler href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm_memdump.c#L168" "mm/mm_heap/mm_memdump.c " _blank | ||
addrenv_select --> kmm_initialize | ||
click addrenv_select href "https://github.com/apache/nuttx/blob/master/sched/addrenv/addrenv.c#L354" "sched/addrenv/addrenv.c " _blank | ||
kmm_initialize --> up_addrenv_create | ||
click kmm_initialize href "https://github.com/apache/nuttx/blob/master/mm/kmm_heap/kmm_initialize.c#L61" "mm/kmm_heap/kmm_initialize.c " _blank | ||
up_addrenv_create --> mmu_get_region_size | ||
click up_addrenv_create href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L487" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
mmu_get_region_size --> up_addrenv_create | ||
click mmu_get_region_size href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_mmu.c#L784" "arch/arm64/src/common/arm64_mmu.c " _blank | ||
up_addrenv_create --> copy_kernel_mappings | ||
click up_addrenv_create href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L515" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
copy_kernel_mappings --> up_addrenv_create | ||
click copy_kernel_mappings href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L218" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
up_addrenv_create --> mmu_ln_setentry | ||
click up_addrenv_create href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L433" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
mmu_ln_setentry --> arm64_fpu_func | ||
click mmu_ln_setentry href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_mmu.c#L725" "arch/arm64/src/common/arm64_mmu.c " _blank | ||
arm64_fpu_func --> arm64_vectors | ||
click arm64_fpu_func href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_fpu_func.S#L67" "arch/arm64/src/common/arm64_fpu_func.S " _blank | ||
arm64_vectors --> arm64_smccc | ||
click arm64_vectors href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_vectors.S#L270" "arch/arm64/src/common/arm64_vectors.S " _blank | ||
arm64_smccc --> mmu_ln_getentry | ||
click arm64_smccc href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_smccc.S#L57" "arch/arm64/src/common/arm64_smccc.S " _blank | ||
mmu_ln_getentry --> up_addrenv_vtext | ||
click mmu_ln_getentry href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_mmu.c#L747" "arch/arm64/src/common/arm64_mmu.c " _blank | ||
up_addrenv_vtext --> up_addrenv_create | ||
click up_addrenv_vtext href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L628" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
up_addrenv_create --> copy_kernel_mappings | ||
click up_addrenv_create href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L517" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
copy_kernel_mappings --> up_addrenv_create | ||
click copy_kernel_mappings href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L218" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
up_addrenv_create --> mmu_ln_setentry | ||
click up_addrenv_create href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L433" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
mmu_ln_setentry --> arm64_fpu_func | ||
click mmu_ln_setentry href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_mmu.c#L725" "arch/arm64/src/common/arm64_mmu.c " _blank | ||
arm64_fpu_func --> arm64_vectors | ||
click arm64_fpu_func href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_fpu_func.S#L67" "arch/arm64/src/common/arm64_fpu_func.S " _blank | ||
arm64_vectors --> arm64_smccc | ||
click arm64_vectors href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_vectors.S#L270" "arch/arm64/src/common/arm64_vectors.S " _blank | ||
arm64_smccc --> arm64_fpu_func | ||
click arm64_smccc href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_smccc.S#L70" "arch/arm64/src/common/arm64_smccc.S " _blank | ||
arm64_fpu_func --> arm64_smccc | ||
click arm64_fpu_func href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_fpu_func.S#L53" "arch/arm64/src/common/arm64_fpu_func.S " _blank | ||
arm64_smccc --> mmu_ln_getentry | ||
click arm64_smccc href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_smccc.S#L70" "arch/arm64/src/common/arm64_smccc.S " _blank | ||
mmu_ln_getentry --> up_addrenv_vtext | ||
click mmu_ln_getentry href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_mmu.c#L747" "arch/arm64/src/common/arm64_mmu.c " _blank | ||
up_addrenv_vtext --> up_addrenv_create | ||
click up_addrenv_vtext href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L628" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
up_addrenv_create --> kmm_initialize | ||
click up_addrenv_create href "https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_addrenv.c#L517" "arch/arm64/src/common/arm64_addrenv.c " _blank | ||
kmm_initialize --> mm_memalign | ||
click kmm_initialize href "https://github.com/apache/nuttx/blob/master/mm/kmm_heap/kmm_initialize.c#L62" "mm/kmm_heap/kmm_initialize.c " _blank | ||
mm_memalign --> mm_addfreechunk | ||
click mm_memalign href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm_memalign.c#L273" "mm/mm_heap/mm_memalign.c " _blank | ||
mm_addfreechunk --> memdump_handler | ||
click mm_addfreechunk href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm.h#L337" "mm/mm_heap/mm.h " _blank | ||
memdump_handler --> mm_addfreechunk | ||
click memdump_handler href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm_memdump.c#L164" "mm/mm_heap/mm_memdump.c " _blank | ||
mm_addfreechunk --> gettimeofday | ||
click mm_addfreechunk href "https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm.h#L326" "mm/mm_heap/mm.h " _blank | ||
gettimeofday --> syslog | ||
click gettimeofday href "https://github.com/apache/nuttx/blob/master/libs/libc/time/lib_gettimeofday.c#L69" "libs/libc/time/lib_gettimeofday.c " _blank | ||
mm_map_remove --> sq_remafter | ||
click mm_map_remove href "https://github.com/apache/nuttx/blob/master/mm/map/mm_map.c#L322" "mm/map/mm_map.c " _blank | ||
sq_remafter --> syslog | ||
click sq_remafter href "https://github.com/apache/nuttx/blob/master/include/nuttx/queue.h#L422" "include/nuttx/queue.h " _blank | ||
mm_map_remove --> syslog | ||
click mm_map_remove href "https://github.com/apache/nuttx/blob/master/mm/map/mm_map.c#L353" "mm/map/mm_map.c " _blank | ||
syslog --> gettimeofday | ||
click syslog href "https://github.com/apache/nuttx/blob/master/libs/libc/syslog/lib_syslog.c#L95" "libs/libc/syslog/lib_syslog.c " _blank | ||
strncmp --> nxsched_set_priority | ||
click strncmp href "https://github.com/apache/nuttx/blob/master/libs/libc/machine/arm64/gnu/arch_strncmp.S#L148" "libs/libc/machine/arm64/gnu/arch_strncmp.S " _blank | ||
nxsched_set_priority --> nxsched_blocked_setpriority | ||
click nxsched_set_priority href "https://github.com/apache/nuttx/blob/master/sched/sched/sched_setpriority.c#L432" "sched/sched/sched_setpriority.c " _blank | ||
nxsched_blocked_setpriority --> exec_module | ||
click nxsched_blocked_setpriority href "https://github.com/apache/nuttx/blob/master/sched/sched/sched_setpriority.c#L323" "sched/sched/sched_setpriority.c " _blank | ||
exec_module --> nxsched_add_prioritized | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let kernel = include_bytes!("../nuttx/nuttx.bin"); | ||
unsafe { | ||
assert!(kernel_code.len() >= kernel.len()); | ||
kernel_code[0..kernel.len()].copy_from_slice(kernel); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emu.mem_write( | ||
UART0_BASE_ADDRESS + 0x14, // UART Register Address | ||
&[0b10_0000] // UART Register Value | ||
UART0_BASE_ADDRESS + 0x18, // UART Register Address | ||
&[0] // UART Register Value | ||
).expect("failed to set UART_LSR"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
No description provided.