> compile NEMU
ysyx_22040000 李心杨 Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar 1 12:35:11 UTC 2024 x86_64 GNU/Linux 16:26:21 up 4 days 3:32, 2 users, load average: 0.85, 0.91, 0.95
This commit is contained in:
parent
a210694e82
commit
d08c2860da
415 changed files with 44314 additions and 11 deletions
3
am-kernels/kernels/yield-os/Makefile
Normal file
3
am-kernels/kernels/yield-os/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
NAME = yield-os
|
||||
SRCS = yield-os.c
|
||||
include $(AM_HOME)/Makefile
|
31
am-kernels/kernels/yield-os/yield-os.c
Normal file
31
am-kernels/kernels/yield-os/yield-os.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <am.h>
|
||||
#include <klib-macros.h>
|
||||
|
||||
#define STACK_SIZE (4096 * 8)
|
||||
typedef union {
|
||||
uint8_t stack[STACK_SIZE];
|
||||
struct { Context *cp; };
|
||||
} PCB;
|
||||
static PCB pcb[2], pcb_boot, *current = &pcb_boot;
|
||||
|
||||
static void f(void *arg) {
|
||||
while (1) {
|
||||
putch("?AB"[(uintptr_t)arg > 2 ? 0 : (uintptr_t)arg]);
|
||||
for (int volatile i = 0; i < 100000; i++) ;
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
static Context *schedule(Event ev, Context *prev) {
|
||||
current->cp = prev;
|
||||
current = (current == &pcb[0] ? &pcb[1] : &pcb[0]);
|
||||
return current->cp;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cte_init(schedule);
|
||||
pcb[0].cp = kcontext((Area) { pcb[0].stack, &pcb[0] + 1 }, f, (void *)1L);
|
||||
pcb[1].cp = kcontext((Area) { pcb[1].stack, &pcb[1] + 1 }, f, (void *)2L);
|
||||
yield();
|
||||
panic("Should not reach here!");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue