Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

msp430: memset and memcpy in core don't write anything, so globals aren't initialized

未关闭 适合新手
#1,101 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
zig
领域
embedded-iot

调研方向

阅读core/src/cpus/msp430.zig中memset和memcpy的实现,然后使用提供的MSP430模拟器命令和examples/texasinstruments/msp430/src/empty.zig设置重现启动行为。修复循环比较和控制流,使.bss被清零且.data被复制;确认内存转储在0x200处显示34 12,在0x204处显示00 00。

由索引模型根据 Issue 内容生成。

描述

msp430

memset and memcpy in core/src/cpus/msp430.zig return without writing anything. The startup code (initialize_system_memories) uses them to clear .bss and copy .data, so on MSP430 global variables start with whatever is in RAM. This affects both boards (msp430x.zig uses the same functions).

Both loops compare a register with itself, because MOV is src, dst:

  • memset: MOV R12, R5 and ADD R5, R14 leave the end in R14, but the loop does CMP R5, R12 (start against start), so it exits right away.
  • memcpy: MOV R5, R12 overwrites the destination with R5, so CMP R5, R12 also exits right away. It also has no JMP memcpy_loop, and SUB R12, R14 changes R14 instead of restoring R12.

Reproduce on 8862a281 with Zig 0.17.0, in the mspdebug simulator (I don't have MSP430 hardware). Replace examples/texasinstruments/msp430/src/empty.zig with:

const std = @import("std");
const microzig = @import("microzig");

pub const std_options = microzig.std_options(.{});

comptime {
    _ = microzig.export_startup();
}

pub const panic = std.debug.no_panic;

var initialized: u16 = 0x1234; // .data
var zeroed: u16 = 0; // .bss

pub fn main() void {
    std.mem.doNotOptimizeAway(&initialized);
    std.mem.doNotOptimizeAway(&zeroed);
}
cd examples/texasinstruments/msp430
zig build -Doptimize=ReleaseSmall
# initialized is at 0x200 and zeroed at 0x204; 0xc02a is microzig_main
mspdebug -q sim "prog zig-out/firmware/empty_MSP430G2553.elf" "fill 0x200 16 0xaa" "reset" "setbreak 0xc02a" "run" "md 0x200 8"

Result:

00200: aa aa aa aa aa aa aa aa

Expected 34 12 at 0x200 and 00 00 at 0x204. With both loops fixed (end in R14, compare the cursor against it, jump back), the same program gives:

00200: 34 12 00 00 00 00 00 00

I can open a PR with the fix if you want.

主要语言
Zig
星标
2.3k
派生
198
平均合并
2 天 12 小时
30 天内合并 PR
28

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ZigEmbeddedGroup/microzig 的其他 Issue

查看 ZigEmbeddedGroup/microzig 的全部 Issue

相似的 Issue

更多 Embedded & IoT Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。