Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

hudson-ayers
Copy link
Contributor

@hudson-ayers hudson-ayers commented Sep 5, 2025

Pull Request Overview

This PR was entirely authored by Cursor (model: gpt-5). I intentionally did not make any edits to the generated code -- I wanted to use this as a brief exercise to see how capable cursor was of making a basic refactor. I picked the most recently opened issue. I did not review the changes in depth (yet), but made some suggestions in response to the initial changes. I gave the following 5 prompts to get it here:

  1. This file contains a component, but Tock components are all supposed to be defined in the boards/ crate. Can you move the component defined in this file into the boards crate in a similar style to how other components are defined, and update boards/qemu_i486_q35/src/main.rs accordingly so that board still builds?

  2. The component should go in the boards/components directory alongside other components. Can you move it there, in a file named x86_pc_component.rs?

  3. Please do not call static_init!() within finalize(), instead move that into x86_pc_component_static.

  4. Thank you. Can you also move serial_port_component_static!() into this component file?

  5. Can you just inline the macro rather than having it be a standalone macro? Also, please be sure to delete it from its original location

Based on the reply from Brad, I then issued four additional prompts:

  1. We do not want to include arch-specific crates in the components directory -- it does not make sense for arm boards to have dependencies on crates that only compile for x86. This is making me realize that components is actually not the right solution for this. Instead we should be splitting the initialization purely between the board crate and the chip crate, using something like Sam4lDefaultPeripherals and setup_circular_deps in chips/sam4l.rs. Can you pivot x86_q35_src/chip.rs to use this approach?

  2. We cannot have the macro calling static_buf!() in chip.rs. Please put initialization of these peripherals in the board file, similar to how is done in board/imix/src/main.rs. Then update the board file to not use the component anymore, and remove the component.

  3. Can you also port x86_q35 to use the interrupt_service trait and pattern, similar to sam4l?

  4. Lets keep the panic if an unhandled interrupt arrives (by matching on the return value from service_interrupt). Also, lets not have both new() and new_with_peripherals -- just rename new_with_peripherals to new and inline the implementation of the original new() method into it.

Testing Strategy

This pull request has not been tested.

TODO or Help Wanted

This pull request still careful review and testing.

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@bradjc
Copy link
Contributor

bradjc commented Sep 5, 2025

This initial version is not mergable (uses arch-specific crates in components), but this is, I think, close, and it is a very needed change.

@github-actions github-actions bot removed the component label Sep 8, 2025
@hudson-ayers hudson-ayers changed the title [Cursor Test] Move PcComponent out of chips/ and into boards/components [Cursor Test] Remove PcComponent from of chips/ in favor of DefaultPeripherals / InterruptService approach Sep 8, 2025
@hudson-ayers
Copy link
Contributor Author

This initial version is not mergable (uses arch-specific crates in components), but this is, I think, close, and it is a very needed change.

I went ahead and asked Cursor to use the DefaultPeripherals / InterruptService approach instead, which I think is how we typically handle this sort of thing in other chips.

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

bradjc
bradjc previously approved these changes Sep 26, 2025
This commit was primarily authored by Cursor (gpt-5). I used
the following prompts:

1. This file contains a component, but Tock components are all supposed to be defined in the boards/ crate. Can you move the component defined in this file into the boards crate in a similar style to how other components are defined, and update boards/qemu_i486_q35/src/main.rs accordingly so that board still builds?

2. The component should go in the boards/components directory alongside other components. Can you move it there, in a file named x86_pc_component.rs?

3. Please do not call static_init!() within finalize(), instead move that into x86_pc_component_static.

4. Thank you. Can you also move serial_port_component_static!() into this component file?

5. Can you just inline the macro rather than having it be a standalone macro? Also, please be sure to delete it from its original location

Next, I had Cursor remove PcComponent;
use DefaultPeripherals / InterruptService approach

1. We do not want to include arch-specific crates in the components directory -- it does not make sense for arm boards to have dependencies on crates that only compile for x86. This is making me realize that components is actually not the right solution for this. Instead we should be splitting the initialization purely between the board crate and the chip crate, using something like Sam4lDefaultPeripherals and setup_circular_deps in chips/sam4l.rs. Can you pivot x86_q35_src/chip.rs to use this approach?

2. We cannot have the macro calling static_buf!() in chip.rs. Please put initialization of these peripherals in the board file, similar to how is done in board/imix/src/main.rs. Then update the board file to not use the component anymore, and remove the component.

3. Can you also port x86_q35 to use the interrupt_service trait and pattern, similar to sam4l?

4. Lets keep the panic if an unhandled interrupt arrives (by matching on the return value from service_interrupt). Also, lets not have both new() and new_with_peripherals -- just rename new_with_peripherals to new and inline the implementation of the original new() method into it.

This includes some manual cleanup by me as well, including a bunch after
a big rebase.
@github-actions github-actions bot added kernel HIL This affects a Tock HIL interface. WG-OpenTitan In the purview of the OpenTitan working group. component WG-Network In the purview of the Network working group. stm32 nrf sam4l risc-v labels Oct 8, 2025
@hudson-ayers
Copy link
Contributor Author

I rebased this and applied some more changes based on my own review. There were a lot of conflicts in the original with #4596 which made rebasing tricky, so I squashed all the original commits to make rebasing simpler.

I did the rebase manually, not using Cursor, since it was tricky and I wanted to be sure I kept the spirit of #4596 .

@hudson-ayers hudson-ayers marked this pull request as ready for review October 8, 2025 05:21
@hudson-ayers
Copy link
Contributor Author

@reynoldsbd I would appreciate if you could take a look at this PR. This brings the x86 chip more in line with the rest of the Tock ecosystem and I think hopefully makes it even easier for your team to carry changes in your board file without having to modify the x86 chip file (you could even modify the DefaultPeripherals struct by just passing in your own version of it).

This change will of course require you to mirror the modifications to the qemu board file in any downstream x86 board files you have

@alevy
Copy link
Member

alevy commented Oct 8, 2025

@hudson-ayers perhaps the base for the PR is improper or something (it's not a PR against master) and there are tons of changes that are irrelevant (and I believe already in master).

@hudson-ayers hudson-ayers changed the base branch from hayers/add-agents.md to master October 8, 2025 05:56
@hudson-ayers hudson-ayers dismissed bradjc’s stale review October 8, 2025 05:56

The base branch was changed.

@hudson-ayers
Copy link
Contributor Author

@hudson-ayers perhaps the base for the PR is improper or something (it's not a PR against master) and there are tons of changes that are irrelevant (and I believe already in master).

Thanks, I forgot this was originally targeting my other cursor PR (which I did not rebase). fixed!

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say we merge this. It fixes a reasonably substantial technical debt as we shouldn't have had static_init in chips in the first place.

@alevy
Copy link
Member

alevy commented Oct 8, 2025

@tock/x86-wg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component HIL This affects a Tock HIL interface. kernel nrf risc-v sam4l stm32 WG-Network In the purview of the Network working group. WG-OpenTitan In the purview of the OpenTitan working group.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants