forked from StevenBaby/onix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
450df47
commit b7988b0
Showing
9 changed files
with
135 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 一些优化 | ||
|
||
## 更新初始化的方式 | ||
|
||
将需要中断功能的设备初始化放到 init 进程中,此使系统已经支持中断功能。一些设备初始化时必须要中断(比如软盘),使得后续功能尽可能一致。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,6 @@ typedef enum std_fd_t | |
|
||
typedef int32 off_t; // 文件偏移 | ||
|
||
typedef int err_t; // 错误类型 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <onix/interrupt.h> | ||
#include <onix/syscall.h> | ||
#include <onix/debug.h> | ||
|
||
// #include <asm/unistd_32.h> | ||
|
||
#define LOGK(fmt, args...) DEBUGK(fmt, ##args) | ||
|
||
void idle_thread() | ||
{ | ||
set_interrupt_state(true); | ||
u32 counter = 0; | ||
while (true) | ||
{ | ||
// LOGK("idle task.... %d\n", counter++); | ||
// BMB; | ||
asm volatile( | ||
"sti\n" // 开中断 | ||
"hlt\n" // 关闭 CPU,进入暂停状态,等待外中断的到来 | ||
); | ||
yield(); // 放弃执行权,调度执行其他任务 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <onix/types.h> | ||
#include <onix/syscall.h> | ||
#include <onix/stdio.h> | ||
#include <onix/task.h> | ||
|
||
// 进入用户态,准备内核栈 | ||
// 保证栈顶占用足够的大小 | ||
// 约等于 char temp[100]; | ||
static void prepare_stack() | ||
{ | ||
// 获取返回地址,也就是下面调用 task_to_user_mode 的位置 | ||
void *addr = __builtin_return_address(0); | ||
asm volatile( | ||
"subl $100, %%esp\n" // 为栈顶有足够的空间 | ||
"pushl %%eax\n" // 将返回地址压入栈中 | ||
"ret \n" // 直接返回 | ||
::"a"(addr)); | ||
} | ||
|
||
extern int main(); | ||
|
||
int init_user_thread() | ||
{ | ||
while (true) | ||
{ | ||
u32 status; | ||
pid_t pid = fork(); | ||
if (pid) | ||
{ | ||
pid_t child = waitpid(pid, &status); | ||
printf("wait pid %d status %d %d\n", child, status, time()); | ||
} | ||
else | ||
{ | ||
main(); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
extern void serial_init(); | ||
extern void keyboard_init(); | ||
extern void time_init(); | ||
extern void tty_init(); | ||
extern void rtc_init(); | ||
|
||
extern void ide_init(); | ||
extern void ramdisk_init(); | ||
|
||
extern void buffer_init(); | ||
extern void file_init(); | ||
extern void inode_init(); | ||
extern void super_init(); | ||
extern void dev_init(); | ||
|
||
void init_thread() | ||
{ | ||
serial_init(); // 初始化串口 | ||
keyboard_init(); // 初始化键盘 | ||
time_init(); // 初始化时间 | ||
tty_init(); // 初始化 TTY 设备,必须在键盘之后 | ||
// rtc_init(); // 初始化实时时钟,目前没用 | ||
|
||
ramdisk_init(); // 初始化内存虚拟磁盘 | ||
|
||
ide_init(); // 初始化 IDE 设备 | ||
|
||
buffer_init(); // 初始化高速缓冲 | ||
file_init(); // 初始化文件 | ||
inode_init(); // 初始化 inode | ||
super_init(); // 初始化超级块 | ||
|
||
dev_init(); // 初始化设备文件 | ||
|
||
prepare_stack(); // 准备栈顶 | ||
task_to_user_mode(); // 进入用户态 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,29 @@ | ||
|
||
#include <onix/debug.h> | ||
#include <onix/interrupt.h> | ||
|
||
#define LOGK(fmt, args...) DEBUGK(fmt, ##args) | ||
|
||
extern void tss_init(); | ||
extern void memory_map_init(); | ||
extern void mapping_init(); | ||
extern void arena_init(); | ||
|
||
extern void interrupt_init(); | ||
extern void clock_init(); | ||
extern void timer_init(); | ||
extern void time_init(); | ||
extern void rtc_init(); | ||
extern void keyboard_init(); | ||
extern void serial_init(); | ||
extern void tty_init(); | ||
extern void ide_init(); | ||
extern void ramdisk_init(); | ||
extern void task_init(); | ||
extern void syscall_init(); | ||
extern void tss_init(); | ||
extern void buffer_init(); | ||
extern void file_init(); | ||
extern void super_init(); | ||
extern void inode_init(); | ||
extern void hang(); | ||
extern void task_init(); | ||
|
||
void kernel_init() | ||
{ | ||
tss_init(); | ||
memory_map_init(); | ||
mapping_init(); | ||
arena_init(); | ||
|
||
interrupt_init(); | ||
clock_init(); | ||
timer_init(); | ||
keyboard_init(); | ||
tty_init(); | ||
time_init(); | ||
serial_init(); | ||
// rtc_init(); | ||
ide_init(); | ||
ramdisk_init(); | ||
tss_init(); // 初始化任务状态段 | ||
memory_map_init(); // 初始化物理内存数组 | ||
mapping_init(); // 初始化内存映射 | ||
arena_init(); // 初始化内核堆内存 | ||
|
||
syscall_init(); | ||
task_init(); | ||
interrupt_init(); // 初始化中断 | ||
timer_init(); // 初始化定时器 | ||
clock_init(); // 初始化时钟 | ||
|
||
buffer_init(); | ||
file_init(); | ||
inode_init(); | ||
super_init(); | ||
syscall_init(); // 初始化系统调用 | ||
task_init(); // 初始化任务 | ||
|
||
set_interrupt_state(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters