xv6-simplified 0.1
简化版xv6
Loading...
Searching...
No Matches
Macros | Functions | Variables
defs.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NELEM(x)   (sizeof(x) / sizeof(x[0]))
 

Functions

void printf (char *fmt,...)
 打印格式化内容,与c语言printf类似,仅支持d, x, p, s, %%, c;暂剔除调用锁的代码
 
void panic (char *s) __attribute__((noreturn))
 程序中止并打印s字符串的内容,暂剔除调用锁的代码
 
void printfinit (void)
 printf初始化,暂剔除调用锁的代码
 
void kinit (void)
 初始化内存分配
 
void kfree (void *pa)
 释放内存,通常释放kalloc申请到的内存,初始化kinit时除外
 
void * kalloc (void)
 申请一个4096-byte的页表的物理内存
 
void * memset (void *dst, int c, uint n)
 给指定n大小的内存空间批量赋值
 
char * safestrcpy (char *s, const char *t, int n)
 类似于strncpy但保证一遇到'\0'就终止复制字符,且将'\0'也计入字符数量n
 
int strlen (const char *s)
 返回字符串长度
 
void * memmove (void *dst, const void *src, uint n)
 将src指向的字符串挪到dst指向的指针
 
int strncmp (const char *p, const char *q, uint n)
 比较q和p字符串大小
 
char * strncpy (char *s, const char *t, int n)
 从t字符串赋值n个字符到s指向字符串
 
char * strchr (const char *s, char c)
 在一个字符串中查找一个特定字符
 
void strw2u (char *dst, const uint16 *src, int n)
 将16bit的wchar字符串转化为8bit的char字符串
 
void procinit (void)
 初始化进程
 
void userinit (void)
 初始化第一个进程
 
void scheduler (void) __attribute__((noreturn))
 进程调度
 
void proc_mapstacks (pagetable_t kpgtbl)
 给每个进程的内核栈申请一个页,将其映射到内存高地址,后面紧跟着一个无效保护页
 
int cpuid (void)
 得到当前cpu的id,(此时中断需要禁用以防止进程间竞争挪到其他CPU)
 
struct cpumycpu (void)
 得到当前运行的cpu(结构体),(此时中断需要禁用)
 
struct procmyproc (void)
 返回当前运行的进程(结构体指针),若没有返回0
 
pagetable_t proc_pagetable (struct proc *p)
 给进程p创建一个不带用户内存的用户页表,但带有trampoline和trapframe页
 
void proc_freepagetable (pagetable_t pagetable, uint64 sz)
 释放进程页表并释放其引用的物理内存
 
int growproc (int n)
 扩充或缩减进程的用户内存
 
void exit (int status)
 退出当前进程,不返回,该退出的进程在其父进程调用wait()之前保持僵尸进程状态
 
int wait (uint64 addr)
 等待子进程退出
 
void sched (void)
 返回到调度器scheduler(),必须保证proc->state已经改变
 
int kill (int pid)
 kill给定pid的进程,但函数内不会直接让进程退出,只是设置killed状态为1,直到该进程试图返回用户空间时才会退出
 
void setkilled (struct proc *p)
 将给定进程状态设置为killed
 
int killed (struct proc *p)
 给定进程是否已被killed
 
int either_copyout (int user_dst, uint64 dst, void *src, uint64 len)
 要么向用户地址复制,要么向内核地址复制内容
 
int either_copyin (void *dst, int user_src, uint64 src, uint64 len)
 要么从用户地址复制,要么从内核地址复制内容
 
void procdump (void)
 用于debug,打印进程状态列表
 
void wakeup (void *)
 唤醒chan链上的所有进程
 
void sleep (void *chain)
 将进程p沉睡
 
void yield (void)
 当前进程放弃CPU,切换上下文给其他进程
 
void kvmmap (pagetable_t kpgtbl, uint64 va, uint64 pa, uint64 sz, int perm)
 将虚拟地址范围映射到物理地址,并将相应的PTE添加到页表中
 
pagetable_t uvmcreate ()
 创建一个空的用户页表
 
int mappages (pagetable_t pagetable, uint64 va, uint64 size, uint64 pa, int perm)
 从va开始的虚拟地址创建PTE,这些PTE指向从pa开始的物理地址
 
void uvmfree (pagetable_t pagetable, uint64 sz)
 释放用户进程的内存页和页表页
 
void uvmunmap (pagetable_t pagetable, uint64 va, uint64 npages, int do_free)
 从虚拟地址va开始,移除npages页的映射,va必须是页对齐的,映射必须存在
 
void uvmfirst (pagetable_t pagetable, uchar *src, uint sz)
 将用户的initcode加载到进程的地址0处,用于第一个进程
 
uint64 uvmalloc (pagetable_t pagetable, uint64 oldsz, uint64 newsz, int xperm)
 为进程从oldsz到newsz分配PTE和物理内存
 
uint64 uvmdealloc (pagetable_t pagetable, uint64 oldsz, uint64 newsz)
 释放用户进程的内存页,以将进程大小从oldsz缩小到newsz
 
void kvminit (void)
 初始化内核页表kernel_pagetable
 
void kvminithart (void)
 将硬件页表寄存器切换到内核页表,并启用分页
 
int copyin (pagetable_t pagetable, char *dst, uint64 srcva, uint64 len)
 从用户空间复制数据到内核空间
 
int copyinstr (pagetable_t pagetable, char *dst, uint64 srcva, uint64 max)
 从用户空间复制一个以'\0'结尾的字符串到内核空间
 
void uvmclear (pagetable_t pagetable, uint64 va)
 将一个页表项标记为无效,使得用户无法访问该页。它通常被用于为用户栈设置保护页
 
int copyout (pagetable_t pagetable, uint64 dstva, char *src, uint64 len)
 从内核空间复制数据到用户空间
 
uint64 walkaddr (pagetable_t pagetable, uint64 va)
 查找虚拟地址对应的物理地址,如果没有映射则返回0,它只能用于查找用户页
 
pte_twalk (pagetable_t pagetable, uint64 va, int alloc)
 在页表中查找虚拟地址va对应的页表项,如果页表项不存在则根据alloc参数决定是否分配新的页表
 
int uvmcopy (pagetable_t old, pagetable_t new, uint64 sz)
 将一个进程的虚拟地址空间复制到另一个进程的虚拟地址空间,包括页表和物理内存
 
void binit (void)
 初始化缓冲区缓存,创建一个缓冲区的链表
 
struct bufbread (uint dev, uint sectorno)
 将指定设备上指定扇区的内容存储在buffer中
 
void brelse (struct buf *b)
 释放一个缓冲区,若当前的引用计数为0,则会被头插到空闲缓冲池中
 
void bwrite (struct buf *b)
 将一个缓冲区的内容写入到磁盘中
 
void bpin (struct buf *b)
 增加引用计数值
 
void bunpin (struct buf *b)
 减少引用计数值
 
void virtio_disk_init (void)
 初始化virtio,重置缓冲区描述符虚拟队列、空闲ring、used ring,初始化状态寄存器
 
void virtio_disk_rw (struct buf *b, int write)
 虚拟磁盘读写函数
 
void virtio_disk_intr (void)
 虚拟 I/O 磁盘设备的中断处理,回收已完成操作的used ring
 
void swtch (struct context *old, struct context *new)
 切换当前的上下文,将当前的上下文存入old,从new中取出上下文作为当前上下文
 
void argint (int n, int *ip)
 获取int类型的系统调用参数
 
int argstr (int n, char *buf, int max)
 获取一个str类型的'\0'结尾的系统调用参数,
 
void argaddr (int n, uint64 *ip)
 获取一个指针参数(不检查其合法性,后续过程中会检查)
 
int fetchstr (uint64 addr, char *buf, int max)
 从当前进程获取位于addr的以'\0'结尾的字符串
 
int fetchaddr (uint64 addr, uint64 *ip)
 从当前进程获取位于addr的64位整数(即地址)
 
void syscall (void)
 系统调用
 
int exec (char *path, char **argv)
 exec系统调用,执行path指向的文件,携带argv作为参数
 
void trapinit (void)
 初始化trap
 
void trapinithart (void)
 设置为在内核中接收异常和陷阱
 
void usertrapret (void)
 返回用户空间
 
void uartinit (void)
 初始化uart各个寄存器
 
void uartintr (void)
 uart中断处理,当输入数据抵达或uart准备好更多输出时调用,被devintr函数调用。
 
void uartputc (int c)
 将字符写入输出缓冲区,通知UART开始发送字符。
 
void uartputc_sync (int c)
 uartputc()的变体,不需要使用中断。
 
int uartgetc (void)
 从UART读入一个输入字符
 
void plicinit (void)
 初始化平台级中断
 
void plicinithart (void)
 设置hart中相应的比特位
 
int plic_claim (void)
 获取目前应该服务的中断请求
 
void plic_complete (int)
 告知PLIC正在处理的中断请求
 
void consoleinit (void)
 初始化console
 
void consoleintr (int)
 console输入中断处理程序
 
void consputc (int c)
 将字符输送到uart输出寄存器
 
struct filefilealloc (void)
 从文件描述符池中申请文件描述符
 
void fileclose (struct file *f)
 关闭文件描述符;若引用数不为0,则减少引用数,否则关闭
 
struct filefiledup (struct file *f)
 增加文件描述符f的引用计数值
 
void fileinit (void)
 初始化文件池中的文件
 
int fileread (struct file *f, uint64 addr, int n)
 读文件f
 
int filestat (struct file *f, uint64 addr)
 获取文件的元数据(只针对stat结构体)
 
int filewrite (struct file *f, uint64 addr, int n)
 写文件f
 
int fat32_init (void)
 初始化 FAT32 文件系统
 
struct direntdirlookup (struct dirent *entry, char *filename, uint *poff)
 在指定目录项中查找指定文件名的目录项
 
char * formatname (char *name)
 对输入的文件名进行格式化
 
struct direntedup (struct dirent *entry)
 增加目录项的引用链接数
 
void eupdate (struct dirent *entry)
 将目录的更改更新到磁盘上
 
void eput (struct dirent *entry)
 把目录项entry插入到root之后,减少entry引用链接数
 
void estat (struct dirent *ep, struct stat *st)
 将一个目录项的信息转换为一个文件状态结构体
 
void elock (struct dirent *entry)
 判断地址和链接数是否合法
 
void eunlock (struct dirent *entry)
 判断地址和链接数是否合法
 
int enext (struct dirent *dp, struct dirent *ep, uint off, int *count)
 在dp描述的目录项的off个字节偏移处寻找相应的目录项并存放到ep中
 
struct direntename (char *path)
 根据路径名查目录
 
int eread (struct dirent *entry, int user_dst, uint64 dst, uint off, uint n)
 从一个文件的指定偏移量开始读取一定数量的字节
 
int ewrite (struct dirent *entry, int user_src, uint64 src, uint off, uint n)
 从一个文件的指定偏移量开始写入一定数量的字节
 

Variables

uint ticks
 

Macro Definition Documentation

◆ NELEM

#define NELEM (   x)    (sizeof(x) / sizeof(x[0]))

Function Documentation

◆ argaddr()

void argaddr ( int  n,
uint64 ip 
)

获取一个指针参数(不检查其合法性,后续过程中会检查)

Parameters
n第n个参数
ip存放指针的指针
Here is the caller graph for this function:

◆ argint()

void argint ( int  n,
int *  ip 
)

获取int类型的系统调用参数

Parameters
n第n个参数
ip存放参数的指针
Here is the caller graph for this function:

◆ argstr()

int argstr ( int  n,
char *  buf,
int  max 
)

获取一个str类型的'\0'结尾的系统调用参数,

Parameters
n第n个参数
buf存放参数的指针
max字符串最大长度
Returns
获取的字符串参数长度,若出现错误则返回-1
Here is the call graph for this function:
Here is the caller graph for this function:

◆ binit()

void binit ( void  )

初始化缓冲区缓存,创建一个缓冲区的链表

最近使用的缓冲区在链表头部,最不常用的缓冲区在链表尾部,LRU

Here is the caller graph for this function:

◆ bpin()

void bpin ( struct buf b)

增加引用计数值

Parameters
b缓冲区

◆ bread()

struct buf * bread ( uint  dev,
uint  sectorno 
)

将指定设备上指定扇区的内容存储在buffer中

Parameters
dev设备号
sectorno扇区号
Returns
缓冲区
Here is the call graph for this function:
Here is the caller graph for this function:

◆ brelse()

void brelse ( struct buf b)

释放一个缓冲区,若当前的引用计数为0,则会被头插到空闲缓冲池中

Parameters
b待释放的缓冲区
Here is the caller graph for this function:

◆ bunpin()

void bunpin ( struct buf b)

减少引用计数值

Parameters
b缓冲区

◆ bwrite()

void bwrite ( struct buf b)

将一个缓冲区的内容写入到磁盘中

Parameters
b缓冲区
Here is the call graph for this function:

◆ consoleinit()

void consoleinit ( void  )

初始化console

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consoleintr()

void consoleintr ( int  c)

console输入中断处理程序

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consputc()

void consputc ( int  c)

将字符输送到uart输出寄存器

Parameters
c输入字符
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyin()

int copyin ( pagetable_t  pagetable,
char *  dst,
uint64  srcva,
uint64  len 
)

从用户空间复制数据到内核空间

Parameters
pagetable页表
dst目标内存地址
srcva源内存地址
len要复制的数据长度
Returns
0:成功 -1:失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyinstr()

int copyinstr ( pagetable_t  pagetable,
char *  dst,
uint64  srcva,
uint64  max 
)

从用户空间复制一个以'\0'结尾的字符串到内核空间

Parameters
pagetable页表
dst目标内存地址
srcva源内存地址
max最大复制字节数
Returns
0:成功 -1:失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyout()

int copyout ( pagetable_t  pagetable,
uint64  dstva,
char *  src,
uint64  len 
)

从内核空间复制数据到用户空间

Parameters
pagetable用户进程的页表
dstva目标虚拟地址
src源数据的指针
len要复制的数据长度
Returns
0:成功 -1:失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpuid()

int cpuid ( void  )

得到当前cpu的id,(此时中断需要禁用以防止进程间竞争挪到其他CPU)

Returns
tp存储的cpuid
Here is the caller graph for this function:

◆ dirlookup()

struct dirent * dirlookup ( struct dirent entry,
char *  filename,
uint poff 
)

在指定目录项中查找指定文件名的目录项

Parameters
entry指定的目录项
filename目标文件名
poff若找到目标目录项不启用,否则用于记录与目标文件等长目录项的空目录项的起始偏移或目录末尾
Returns
在内存中找到的目录项,若未找到返回0
Here is the call graph for this function:

◆ edup()

struct dirent * edup ( struct dirent entry)

增加目录项的引用链接数

Parameters
entry待更新的目录项
Returns
更新后的目录项
Here is the caller graph for this function:

◆ either_copyin()

int either_copyin ( void *  dst,
int  user_src,
uint64  src,
uint64  len 
)

要么从用户地址复制,要么从内核地址复制内容

Parameters
user_src1:从用户地址复制;0:从内核地址复制
dst复制的目标地址
src源地址
len复制的长度
Returns
0:复制成功;-1:复制失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ either_copyout()

int either_copyout ( int  user_dst,
uint64  dst,
void *  src,
uint64  len 
)

要么向用户地址复制,要么向内核地址复制内容

Parameters
user_dst1:向用户地址复制;0:向内核地址复制
dst复制的目标地址
src源地址
len复制的长度
Returns
0:复制成功;-1:复制失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ elock()

void elock ( struct dirent entry)

判断地址和链接数是否合法

Parameters
entry目录
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ename()

struct dirent * ename ( char *  path)

根据路径名查目录

Parameters
path路径名
Returns
查找到的目录项
Here is the caller graph for this function:

◆ enext()

int enext ( struct dirent dp,
struct dirent ep,
uint  off,
int *  count 
)

在dp描述的目录项的off个字节偏移处寻找相应的目录项并存放到ep中

Parameters
dp要查找目录项所在的上级目录描述符
ep存放目标目录项的描述符
off从dp开始的偏移字节数
count存放目标目录项数量的地址
Returns
1:成功找到目标目录项
0:dp的off偏移处的目录项已被删除
-1:查找失败或没找到
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eput()

void eput ( struct dirent entry)

把目录项entry插入到root之后,减少entry引用链接数

Parameters
entry目录
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eread()

int eread ( struct dirent entry,
int  user_dst,
uint64  dst,
uint  off,
uint  n 
)

从一个文件的指定偏移量开始读取一定数量的字节

Parameters
entry目录项的指针,要读取的文件
user_dst目标地址是否在用户空间
dst数据读取的目标地址
off从文件的哪个偏移量开始读取
n读取的字节数
Returns
0:失败 tot:读取字节数
Here is the caller graph for this function:

◆ estat()

void estat ( struct dirent ep,
struct stat st 
)

将一个目录项的信息转换为一个文件状态结构体

Parameters
de目录项
st文件状态结构体
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eunlock()

void eunlock ( struct dirent entry)

判断地址和链接数是否合法

Parameters
entry目录
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eupdate()

void eupdate ( struct dirent entry)

将目录的更改更新到磁盘上

Parameters
entry目录
Here is the caller graph for this function:

◆ ewrite()

int ewrite ( struct dirent entry,
int  user_src,
uint64  src,
uint  off,
uint  n 
)

从一个文件的指定偏移量开始写入一定数量的字节

Parameters
entry目录项的指针,要写入的文件
user_src数据来源是否在用户空间
src数据来源的地址
off写入文件的偏移量
n写入的字节数
Returns
-1:失败 tot:写入字节数
Here is the caller graph for this function:

◆ exec()

int exec ( char *  path,
char **  argv 
)

exec系统调用,执行path指向的文件,携带argv作为参数

Parameters
path执行的文件路径
argv携带的参数
Returns
返回携带的参数个数,若出现错误返回-1
Here is the call graph for this function:
Here is the caller graph for this function:

◆ exit()

void exit ( int  status)

退出当前进程,不返回,该退出的进程在其父进程调用wait()之前保持僵尸进程状态

Parameters
status该进程退出时的状态
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fat32_init()

int fat32_init ( void  )

初始化 FAT32 文件系统

从磁盘上读取文件系统的元数据,然后将这些元数据存储在内存中的相应数据结构中

Returns
0:成功 -1:失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetchaddr()

int fetchaddr ( uint64  addr,
uint64 ip 
)

从当前进程获取位于addr的64位整数(即地址)

Parameters
addr要获取的64位整数的地址
ip存放64位整数的指针
Returns
0:成功 1:失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetchstr()

int fetchstr ( uint64  addr,
char *  buf,
int  max 
)

从当前进程获取位于addr的以'\0'结尾的字符串

Parameters
addr要获取的字符串地址
buf存放字符串的指针
max获取的字符串最大长度
Returns
获取的字符串长度,若出现错误返回-1
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filealloc()

struct file * filealloc ( void  )

从文件描述符池中申请文件描述符

Returns
指向文件描述符的指针

◆ fileclose()

void fileclose ( struct file f)

关闭文件描述符;若引用数不为0,则减少引用数,否则关闭

Parameters
f待关闭的文件描述符
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filedup()

struct file * filedup ( struct file f)

增加文件描述符f的引用计数值

Parameters
f文件描述符
Returns
文件描述符f
Here is the call graph for this function:

◆ fileinit()

void fileinit ( void  )

初始化文件池中的文件

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileread()

int fileread ( struct file f,
uint64  addr,
int  n 
)

读文件f

Parameters
f文件
addr用户虚拟地址
n读取字节数
Returns
读取到的字节数
Here is the call graph for this function:

◆ filestat()

int filestat ( struct file f,
uint64  addr 
)

获取文件的元数据(只针对stat结构体)

Parameters
f文件描述符
addr存放元数据的用户虚拟地址
Returns
0:成功 -1:失败
Here is the call graph for this function:

◆ filewrite()

int filewrite ( struct file f,
uint64  addr,
int  n 
)

写文件f

Parameters
f文件描述符
addr源数据用户虚拟地址
n写字节数
Returns
写入字节数
Here is the call graph for this function:
Here is the caller graph for this function:

◆ formatname()

char * formatname ( char *  name)

对输入的文件名进行格式化

Parameters
name要格式化的文件名
Returns
指向格式化后的文件名的指针
Here is the call graph for this function:

◆ growproc()

int growproc ( int  n)

扩充或缩减进程的用户内存

Parameters
n扩充的大小(byte)
Returns
0——成功;-1——失败
Here is the call graph for this function:

◆ kalloc()

void * kalloc ( void  )

申请一个4096-byte的页表的物理内存

Returns
指向申请到的页表的指针,若申请失败返回0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kfree()

void kfree ( void *  pa)

释放内存,通常释放kalloc申请到的内存,初始化kinit时除外

Parameters
pa指向待释放内存的指针
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill()

int kill ( int  pid)

kill给定pid的进程,但函数内不会直接让进程退出,只是设置killed状态为1,直到该进程试图返回用户空间时才会退出

Parameters
pid要kill的进程id
Returns
找到要kill的进程返回0,否则-1

◆ killed()

int killed ( struct proc p)

给定进程是否已被killed

Parameters
p待判定的进程
Returns
1:是;0:否
Here is the caller graph for this function:

◆ kinit()

void kinit ( void  )

初始化内存分配

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvminit()

void kvminit ( void  )

初始化内核页表kernel_pagetable

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvminithart()

void kvminithart ( void  )

将硬件页表寄存器切换到内核页表,并启用分页

Here is the caller graph for this function:

◆ kvmmap()

void kvmmap ( pagetable_t  kpgtbl,
uint64  va,
uint64  pa,
uint64  sz,
int  perm 
)

将虚拟地址范围映射到物理地址,并将相应的PTE添加到页表中

Parameters
kpgtbl内核页表的起始地址
va起始虚拟地址
pa起始物理地址
sz映射的大小
perm相应的权限
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mappages()

int mappages ( pagetable_t  pagetable,
uint64  va,
uint64  size,
uint64  pa,
int  perm 
)

从va开始的虚拟地址创建PTE,这些PTE指向从pa开始的物理地址

Parameters
pagetable页表的起始地址
va起始虚拟地址
size映射的大小
pa起始物理地址
perm相应的权限
Returns
0:创建成功 -1:walk()无法分配页表
Here is the call graph for this function:
Here is the caller graph for this function:

◆ memmove()

void * memmove ( void *  dst,
const void *  src,
uint  n 
)

将src指向的字符串挪到dst指向的指针

Parameters
dst目标指针
src源指针
Returns
目标指针
Here is the caller graph for this function:

◆ memset()

void * memset ( void *  dst,
int  c,
uint  n 
)

给指定n大小的内存空间批量赋值

Parameters
dst待赋值的内存开始指针
c将赋值的值
n赋值空间的大小
Returns
赋值后的内存开始指针
Here is the caller graph for this function:

◆ mycpu()

struct cpu * mycpu ( void  )

得到当前运行的cpu(结构体),(此时中断需要禁用)

Returns
当前运行的cpu(结构体)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ myproc()

struct proc * myproc ( void  )

返回当前运行的进程(结构体指针),若没有返回0

Returns
当前运行的进程(结构体指针)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ panic()

void panic ( char *  s)

程序中止并打印s字符串的内容,暂剔除调用锁的代码

Parameters
s要打印的字符串
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plic_claim()

int plic_claim ( void  )

获取目前应该服务的中断请求

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plic_complete()

void plic_complete ( int  irq)

告知PLIC正在处理的中断请求

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plicinit()

void plicinit ( void  )

初始化平台级中断

Here is the caller graph for this function:

◆ plicinithart()

void plicinithart ( void  )

设置hart中相应的比特位

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printf()

void printf ( char *  fmt,
  ... 
)

打印格式化内容,与c语言printf类似,仅支持d, x, p, s, %%, c;暂剔除调用锁的代码

Parameters
fmt字符指针,要打印的内容
...可变长度参数,格式化替换变量值
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printfinit()

void printfinit ( void  )

printf初始化,暂剔除调用锁的代码

Here is the caller graph for this function:

◆ proc_freepagetable()

void proc_freepagetable ( pagetable_t  pagetable,
uint64  sz 
)

释放进程页表并释放其引用的物理内存

Parameters
pagetable待释放的页表
sz释放的大小
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proc_mapstacks()

void proc_mapstacks ( pagetable_t  kpgtbl)

给每个进程的内核栈申请一个页,将其映射到内存高地址,后面紧跟着一个无效保护页

Parameters
kpgtbl内核页表
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proc_pagetable()

pagetable_t proc_pagetable ( struct proc p)

给进程p创建一个不带用户内存的用户页表,但带有trampoline和trapframe页

Parameters
p给定的进程
Returns
成功创建则返回页表指针,否则返回0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ procdump()

void procdump ( void  )

用于debug,打印进程状态列表

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procinit()

void procinit ( void  )

初始化进程

Here is the caller graph for this function:

◆ safestrcpy()

char * safestrcpy ( char *  s,
const char *  t,
int  n 
)

类似于strncpy但保证一遇到'\0'就终止复制字符,且将'\0'也计入字符数量n

Parameters
s目标字符指针
t源字符指针
n复制字符数量
Returns
复制的结果指针
Here is the caller graph for this function:

◆ sched()

void sched ( void  )

返回到调度器scheduler(),必须保证proc->state已经改变

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduler()

void scheduler ( void  )

进程调度

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setkilled()

void setkilled ( struct proc p)

将给定进程状态设置为killed

Parameters
p待killed的进程
Here is the caller graph for this function:

◆ sleep()

void sleep ( void *  chain)

将进程p沉睡

Parameters
chain等待的资源
Here is the call graph for this function:
Here is the caller graph for this function:

◆ strchr()

char * strchr ( const char *  s,
char  c 
)

在一个字符串中查找一个特定字符

Parameters
s目标字符串
c查找字符
Returns
0:未找到 n:第一个字符的地址
Here is the caller graph for this function:

◆ strlen()

int strlen ( const char *  s)

返回字符串长度

Parameters
s
Returns
字符串s的长度
Here is the caller graph for this function:

◆ strncmp()

int strncmp ( const char *  p,
const char *  q,
uint  n 
)

比较q和p字符串大小

Parameters
p字符串(前)
q字符串(后)
n比较字符数目
Returns
p大:正数 q大:负数 一样大:0
Here is the caller graph for this function:

◆ strncpy()

char * strncpy ( char *  s,
const char *  t,
int  n 
)

从t字符串赋值n个字符到s指向字符串

Parameters
s目标字符串
t源字符串
n欲复制的字符数量
Returns
目标字符串指针
Here is the caller graph for this function:

◆ strw2u()

void strw2u ( char *  dst,
const uint16 src,
int  n 
)

将16bit的wchar字符串转化为8bit的char字符串

Parameters
dst目标存放地址
src源数据存放地址
n转化的src字符串长度

◆ swtch()

void swtch ( struct context old,
struct context new 
)

切换当前的上下文,将当前的上下文存入old,从new中取出上下文作为当前上下文

Parameters
old存放当前上下文的地址
new作为当前上下文的地址
Here is the caller graph for this function:

◆ syscall()

void syscall ( void  )

系统调用

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trapinit()

void trapinit ( void  )

初始化trap

Here is the caller graph for this function:

◆ trapinithart()

void trapinithart ( void  )

设置为在内核中接收异常和陷阱

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartgetc()

int uartgetc ( void  )

从UART读入一个输入字符

Returns
若LSR(line status register)最低位为1,输出RHR寄存器中的值,否则输出-1。
最低位表示receive data ready。
Here is the caller graph for this function:

◆ uartinit()

void uartinit ( void  )

初始化uart各个寄存器

Here is the caller graph for this function:

◆ uartintr()

void uartintr ( void  )

uart中断处理,当输入数据抵达或uart准备好更多输出时调用,被devintr函数调用。

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartputc()

void uartputc ( int  c)

将字符写入输出缓冲区,通知UART开始发送字符。

若输出缓冲区满则阻塞。只适合在write调用中使用。

Parameters
c输入字符
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartputc_sync()

void uartputc_sync ( int  c)

uartputc()的变体,不需要使用中断。

内核的printf使用该函数输入字符,它会忙等uart的输出寄存器变为空。

Parameters
c输入字符
Here is the caller graph for this function:

◆ userinit()

void userinit ( void  )

初始化第一个进程

设置第一个用户进程

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usertrapret()

void usertrapret ( void  )

返回用户空间

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmalloc()

uint64 uvmalloc ( pagetable_t  pagetable,
uint64  oldsz,
uint64  newsz,
int  xperm 
)

为进程从oldsz到newsz分配PTE和物理内存

Parameters
pagetable进程的页表
oldsz进程的旧大小
newsz进程的新大小
xperm权限
Returns
0:分配失败 newsz:分配成功
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmclear()

void uvmclear ( pagetable_t  pagetable,
uint64  va 
)

将一个页表项标记为无效,使得用户无法访问该页。它通常被用于为用户栈设置保护页

Parameters
pagetable用户进程的页表
va虚拟地址
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmcopy()

int uvmcopy ( pagetable_t  old,
pagetable_t  new,
uint64  sz 
)

将一个进程的虚拟地址空间复制到另一个进程的虚拟地址空间,包括页表和物理内存

Parameters
old源进程的页表
new目标进程的页表
sz源进程的大小
Returns
0:成功 -1:失败,并释放已映射的物理页
Here is the call graph for this function:

◆ uvmcreate()

pagetable_t uvmcreate ( )

创建一个空的用户页表

Returns
返回页表的指针,如果内存不足返回0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmdealloc()

uint64 uvmdealloc ( pagetable_t  pagetable,
uint64  oldsz,
uint64  newsz 
)

释放用户进程的内存页,以将进程大小从oldsz缩小到newsz

Parameters
pagetable进程的页表
oldsz进程的旧大小
newsz进程的新大小
Returns
新进程的大小
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmfirst()

void uvmfirst ( pagetable_t  pagetable,
uchar src,
uint  sz 
)

将用户的initcode加载到进程的地址0处,用于第一个进程

Parameters
pagetable进程的页表
src指向用户initcode的指针
sz用户initcode的大小,必须小于一页
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmfree()

void uvmfree ( pagetable_t  pagetable,
uint64  sz 
)

释放用户进程的内存页和页表页

Parameters
pagetable用户进程的页表
sz用户进程的大小
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uvmunmap()

void uvmunmap ( pagetable_t  pagetable,
uint64  va,
uint64  npages,
int  do_free 
)

从虚拟地址va开始,移除npages页的映射,va必须是页对齐的,映射必须存在

Parameters
pagetable页表
va虚拟地址
npages要移除的页数
do_free是否释放物理内存
Here is the call graph for this function:
Here is the caller graph for this function:

◆ virtio_disk_init()

void virtio_disk_init ( void  )

初始化virtio,重置缓冲区描述符虚拟队列、空闲ring、used ring,初始化状态寄存器

Here is the call graph for this function:
Here is the caller graph for this function:

◆ virtio_disk_intr()

void virtio_disk_intr ( void  )

虚拟 I/O 磁盘设备的中断处理,回收已完成操作的used ring

Here is the call graph for this function:
Here is the caller graph for this function:

◆ virtio_disk_rw()

void virtio_disk_rw ( struct buf b,
int  write 
)

虚拟磁盘读写函数

Parameters
b操作的缓冲区
write是否为写设备
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait()

int wait ( uint64  addr)

等待子进程退出

Parameters
addr存放子进程退出时状态的地址
Returns
退出的子进程pid
Here is the call graph for this function:

◆ wakeup()

void wakeup ( void *  chan)

唤醒chan链上的所有进程

Parameters
chansleep链,即其他进程申请的资源
Here is the call graph for this function:
Here is the caller graph for this function:

◆ walk()

pte_t * walk ( pagetable_t  pagetable,
uint64  va,
int  alloc 
)

在页表中查找虚拟地址va对应的页表项,如果页表项不存在则根据alloc参数决定是否分配新的页表

Parameters
pagetable页表的起始地址
va所需查找的虚拟地址
alloc是否需要分配新的页表项
Returns
所指页表项的指针,若未找到则返回0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ walkaddr()

uint64 walkaddr ( pagetable_t  pagetable,
uint64  va 
)

查找虚拟地址对应的物理地址,如果没有映射则返回0,它只能用于查找用户页

Parameters
pagetable页表
va虚拟地址
Returns
物理地址
Here is the call graph for this function:
Here is the caller graph for this function:

◆ yield()

void yield ( void  )

当前进程放弃CPU,切换上下文给其他进程

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ticks

uint ticks
extern