Skip to content

Commit 6b62536

Browse files
committed
[ai] update the copilot-instructions.md file
1 parent c7ced13 commit 6b62536

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

.github/copilot-instructions.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LK uses a 4-layer modular build system:
2222
- MMU setup, exception handling, context switching, atomic ops
2323

2424
### Module System Pattern
25-
Every component is a module with `rules.mk`:
25+
Every component is a module with a `rules.mk` file:
2626

2727
```make
2828
LOCAL_DIR := $(GET_LOCAL_DIR)
@@ -48,6 +48,7 @@ include make/module.mk
4848
- Module include paths auto-added: `$(MODULE)/include/` becomes available globally
4949
- Always use `$(LOCAL_DIR)` prefix for source paths
5050
- Must `include make/module.mk` at end of `rules.mk` to finalize the module definition
51+
- All MODULE_* variables are cleared after inclusion, preventing leakage between modules
5152

5253
## Critical Build Patterns
5354

@@ -66,7 +67,7 @@ make qemu-virt-arm64-test LK_HEAP_IMPLEMENTATION=cmpctmalloc
6667
make qemu-virt-arm64-test DEBUG=0
6768

6869
# Clean specific project
69-
rm -rf build-qemu-virt-arm64-test
70+
make build-qemu-virt-arm64-test clean
7071

7172
# Clean everything
7273
make spotless
@@ -84,7 +85,7 @@ scripts/do-qemuarm -6
8485
# ARM64 with 64KB pages
8586
scripts/do-qemuarm -6 -P 64k
8687

87-
# ARM64 with KVM/HVF acceleration
88+
# ARM64 with KVM/HVF acceleration (only if on ARM64 host)
8889
scripts/do-qemuarm -6 -k
8990

9091
# RISC-V 32-bit in machine mode
@@ -99,21 +100,23 @@ scripts/do-qemux86
99100
# x86-64
100101
scripts/do-qemux86 -6
101102

103+
# x86-64 with KVM acceleration (only if on x86-64 host)
104+
scripts/do-qemux86 -6 -k
105+
102106
# With various devices (disk, network, display)
103-
scripts/do-qemuarm -6 -n -d disk.img -g
107+
scripts/do-qemux86 -6 -n -d disk.img -g
104108
```
105109

106-
These scripts auto-build before launching QEMU.
110+
The do-qemu* scripts auto-build before launching QEMU.
107111

108112
### Running all unit tests
109113

110114
```bash
111-
112115
# Run all unit tests for ARM64 architecture
113-
./scripts/do-qemu-boot-tests.py --arch arm64
116+
./scripts/run-qemu-boot-tests.py --arch arm64
114117

115118
# For all architectures
116-
./scripts/do-qemu-boot-tests.py
119+
./scripts/run-qemu-boot-tests.py
117120
```
118121

119122
## Code Conventions
@@ -124,7 +127,7 @@ These scripts auto-build before launching QEMU.
124127
- **K&R braces**: `if (x) {` not `if (x)\n{`
125128
- **Header guards**: Always use `#pragma once` (never `#ifndef` guards)
126129
- Short if/loops allowed: `if (foo) return;` is acceptable
127-
- No column limit (long lines OK)
130+
- 100 Column soft limit (line breaks preferred before 100 chars)
128131

129132
### Compiler Warnings
130133
- Base flags: `-Wall -Werror=return-type -Wshadow -Wdouble-promotion`
@@ -151,11 +154,9 @@ STATIC_COMMAND("mytest", "my test command", &my_command)
151154
STATIC_COMMAND_END(mytest);
152155
```
153156
154-
Console commands are placed in linker section `"console_cmds"` and auto-registered at runtime:
155-
156-
```c
157+
Console commands are placed in linker section `"console_cmds"` and auto-registered at runtime.
157158
158-
**Note:** If `lib/console` not in build, these macros expand to nothing (no build errors).
159+
**Note:** If `lib/console` not in build, these macros expand to nothing and the code should not be emitted.
159160
160161
#### Defining Applications
161162
Apps start automatically at boot (unless `APP_FLAG_NO_AUTOSTART`):
@@ -196,8 +197,10 @@ LK_HEAP_IMPLEMENTATION ?= dlmalloc # default
196197
Architectures with MMU set `WITH_KERNEL_VM ?= 1` in `arch/*/rules.mk`:
197198
- Enables `kernel/vm` instead of `kernel/novm`
198199
- Requires `KERNEL_ASPACE_BASE/SIZE` and `USER_ASPACE_BASE/SIZE` definitions
199-
- Page size configurable: `ARM64_PAGE_SIZE` (4096, 16384, 65536)
200-
- Different projects for different page sizes: `qemu-virt-arm64-64k-test`
200+
- For ARM64 architecture:
201+
- Page size configurable: `ARM64_PAGE_SIZE` (4096, 16384, 65536) on ARM64 architecture
202+
- Different projects for different page sizes: `qemu-virt-arm64-64k-test`
203+
- All other architecture use 4KB pages by default.
201204

202205
### Global Defines
203206
Architecture/platform rules set defines via `GLOBAL_DEFINES +=`:
@@ -210,8 +213,8 @@ Architecture/platform rules set defines via `GLOBAL_DEFINES +=`:
210213
### Adding a New Module
211214
1. Create directory under appropriate location (`lib/`, `dev/`, `app/`)
212215
2. Create `rules.mk` with module definition
213-
3. Add source files, set `MODULE_DEPS` for dependencies
214-
4. Include module in project: `MODULES += lib/mylib`
216+
3. Add source files, set `MODULE_DEPS` for dependencies to other modules from this module
217+
4. Include new module in project/target/platform as needed
215218
5. Headers in `<module>/include/` are globally accessible
216219

217220
### Adding Platform Support
@@ -222,16 +225,26 @@ Architecture/platform rules set defines via `GLOBAL_DEFINES +=`:
222225
5. Create project in `project/<board>-test.mk`
223226

224227
### Debugging
225-
- Builds at `DEBUG=2` (default) include symbols, `DEBUG=0` is release
228+
- Multiple DEBUG build levels, controlled via `DEBUG` make variable:
229+
- `DEBUG=0`: no DEBUG_ASSERT, dprintf only for ALWAYS level
230+
- `DEBUG=1`: DEBUG_ASSERT enabled, dprintf at INFO and ALWAYS
231+
- `DEBUG=2`: DEBUG_ASSERT enabled, dprintf at DEBUG, INFO, ALWAYS
232+
- `DEBUG=3`: DEBUG_ASSERT enabled, dprintf at DEBUG, INFO, ALWAYS, some extra runtime checks.
233+
- 'DEBUG=2' is default
226234
- QEMU scripts support GDB: `scripts/do-qemuarm -6 -s -S` (wait for GDB on :1234)
227235
- Print output via `printf()` goes to console (UART or QEMU serial)
236+
- dprintf levels:
237+
- `dprintf(ALWAYS, "message")` - always printed
238+
- `dprintf(INFO, "message")` - printed in DEBUG>=1
239+
- `dprintf(DEBUG, "message")` - printed in DEBUG>=2
228240
- `kernel/debug.c` provides: `hexdump()`, `panic()`, `ASSERT()`
229241

230242
### Testing
231-
- Shell commands test individual subsystems interactively
232-
- `app/tests/` contains unit test apps
233-
- Python test runner: `scripts/unittest.py` (runs unit tests at boot)
234-
- `scripts/buildall` builds all projects to verify no breakage
243+
- Some Shell commands test individual subsystems interactively
244+
- `app/tests/` contains some unit test commands to run through the shell
245+
- `lib/unittest` contains a unit test framework that other libraries can use to define tests.
246+
- Tests are auto-discovered and run with `ut all` on the command line shell, or automatically
247+
at boot time if `RUN_UNITTESTS_AT_BOOT` is defined at build time.
235248

236249
## Key Files Reference
237250

@@ -241,6 +254,7 @@ Architecture/platform rules set defines via `GLOBAL_DEFINES +=`:
241254
- `kernel/thread.c` - Threading and scheduler implementation
242255
- `kernel/vm/` - Virtual memory subsystem (for MMU architectures)
243256
- `lib/libc/` - Minimal C library (string, stdio, stdlib basics)
244-
- `top/` - Top-level compatibility headers for global includes
257+
- `top/` - Top level module in the system. Contains the kernel's lk_main() system init routines.
258+
Also contains top level lk/ include headers.
245259

246260
For detailed architecture info, see `docs/` (threading, VMM, platform-specific guides).

0 commit comments

Comments
 (0)