复习
本次课回答的问题
本次课主要内容
数字电路是状态机
C 程序 (on AbstractMachine) 也是状态机
基础状态机
extern Area heap;
void putch (char ch);
void halt (int code);
输入/输出设备
bool ioe_init (void);
void ioe_read (int reg, void *buf);
void ioe_write (int reg, void *buf);
#include "amdev.h"
在框架代码的基础上实现一个能动的游戏
while (1) {
while (!next_frame()) ;
update_input();
update_state();
update_gfx();
}
与 Hello World 本质相同
温馨提示
共享内存多处理器状态机
atomic_xchg
是唯一的处理器间同步方法bool mpe_init (void (*entry)());
int cpu_count (void);
int cpu_current(void);
int atomic_xchg(int *addr, int newval);
实现 malloc/free 的内核版本
温馨提示
管理 C 语言状态机执行的 “快照” (context)
中断行为
cte_init
注册的 handlerbool cte_init(Context *(*handler)(Event ev, Context *ctx));
void yield (void);
bool ienabled(void);
void iset (bool enable);
Context *kcontext(Area kstk, void (*entry)(void *), void *arg);
处理器分别响应中断/异常
handler 执行时会使用当前执行流的堆栈
实现内核线程的创建和同步
温馨提示
允许为 context 增加 “VR 眼镜”
bool vme_init (void *(*alloc)(int), void (*free)(void *));
void protect (AddrSpace *as);
void unprotect(AddrSpace *as);
void map (AddrSpace *as, void *va, void *pa, int prot);
Context *ucontext (AddrSpace *as, Area kstk, void *entry);
实现若干系统调用
温馨提示
本次课回答的问题
Take-away messages