diff options
| author | Alejandro Soto <alejandro@34project.org> | 2023-10-04 00:58:57 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2023-10-04 00:58:57 -0600 |
| commit | 897bd990f9e5ef1be358172c6804d49ffe7c453c (patch) | |
| tree | c8ec072fff033aab81aff61fe9238db39d82740d /demo/smp.c | |
| parent | b3555efa723d0b7101ea6989dc04492eca6b8745 (diff) | |
demo: implement run, halt cmds
Diffstat (limited to 'demo/smp.c')
| -rw-r--r-- | demo/smp.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -15,12 +15,17 @@ void run_cpu(unsigned num) void run_cpus(unsigned mask) { - unsigned ctrl_word = 0; - for (unsigned cpu = 0; cpu < NUM_CPUS; ++cpu) - if (mask & (1 << cpu)) { + unsigned ctrl_word = 0, ctrl_read = SMP_CTRL; + for (unsigned cpu = 0; cpu < NUM_CPUS; ++cpu) { + if (!(mask & (1 << cpu))) + continue; + + if (ctrl_read & (0b001 << (cpu * 8))) { print("run cpu%u", cpu); ctrl_word |= 0b001 << (cpu * 8); - } + } else + print("cpu%u already running", cpu); + } SMP_CTRL = ctrl_word; } @@ -32,12 +37,17 @@ void halt_cpu(unsigned num) void halt_cpus(unsigned mask) { - unsigned ctrl_word = 0; - for (unsigned cpu = 0; cpu < NUM_CPUS; ++cpu) - if (mask & (1 << cpu)) { + unsigned ctrl_word = 0, ctrl_read = SMP_CTRL; + for (unsigned cpu = 0; cpu < NUM_CPUS; ++cpu) { + if (!(mask & (1 << cpu))) + continue; + + if (!(ctrl_read & (0b001 << (cpu * 8)))) { print("halt cpu%u%s", cpu, cpu == this_cpu->num ? " (myself)" : ""); ctrl_word |= 0b010 << (cpu * 8); - } + } else + print("cpu%u already halted", cpu); + } SMP_CTRL = ctrl_word; } |
