Skip to main content
  1. Posts/

geek OS project 0 (下)

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

现在我们环境已经搭好了,参考 geekos实验环境的搭建

在main.c中新加个函数,命名为projecto,函数的代码如下:

 1/*
 2 * GeekOS C code entry point
 3 * Copyright (c) 2001,2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
 4 * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
 5 * Copyright (c) 2004, Iulian Neamtiu <neamtiu@cs.umd.edu>
 6 * $Revision: 1.51 $
 7 *
 8 * This is free software.  You are permitted to use,
 9 * redistribute, and modify it as specified in the file "COPYING".
10 */
11
12#include <geekos/bootinfo.h>
13#include <geekos/string.h>
14#include <geekos/screen.h>
15#include <geekos/mem.h>
16#include <geekos/crc32.h>
17#include <geekos/tss.h>
18#include <geekos/int.h>
19#include <geekos/kthread.h>
20#include <geekos/trap.h>
21#include <geekos/timer.h>
22#include <geekos/keyboard.h>
23
24//added by 111qqz for project 0
25void project0()
26{
27    Print("To Exit hit Ctrl + d.\n");
28    Print("Hello from 111qqz !\n");
29    Print("This is a test of project0 !\n");
30
31
32
33    Keycode keycode;
34    while(1)
35    {
36        if( Read_Key(&keycode) )    //读取键盘按键状态
37        {
38            if(!( (keycode & KEY_SPECIAL_FLAG) || (keycode & KEY_RELEASE_FLAG)) ) //只处理非特殊按键的按下事件
39            {
40                 int asciiCode = keycode &  0xff;    //低8位为Ascii码
41
42                if( (keycode & KEY_CTRL_FLAG)==KEY_CTRL_FLAG  &&  asciiCode=='d')    //按下Ctrl键
43                {
44                    Print("\n---------BYE!--------\n");
45                    Exit(1);
46                }else
47                {
48                    Print("%c",(asciiCode=='\r') ? '\n' : asciiCode);
49                }
50            }
51        }
52    }
53}
54
55
56/*
57 * Kernel C code entry point.
58 * Initializes kernel subsystems, mounts filesystems,
59 * and spawns init process.
60 */
61void Main(struct Boot_Info* bootInfo)
62{
63    Init_BSS();
64    Init_Screen();
65    Init_Mem(bootInfo);
66    Init_CRC32();
67    Init_TSS();
68    Init_Interrupts();
69    Init_Scheduler();
70    Init_Traps();
71    Init_Timer();
72    Init_Keyboard();
73
74
75    Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT));
76    Print("Welcome 111qqz to GeekOS!\n");
77    Set_Current_Attr(ATTRIB(BLACK, GRAY));
78
79
80
81   // TODO("Start a kernel thread to echo pressed keys and print counts");
82    //added by 111qqz for project 0
83          struct Kernel_Thread *thread;
84    thread = Start_Kernel_Thread(&project0,0,PRIORITY_NORMAL,false);
85      // added for project 0 end
86
87
88    /* Now this thread is done. */
89    Exit(0);
90}

再修改Main函数,将TODO(“…..这一行替换为以下代码:

struct Kernel_Thread *thread; thread = Start_Kernel_Thread(&project0,0,PRIORITY_NORMAL,false);

替换的意思是,要把TODO那一行注释掉。。。

TODO语句的定义在src/project0/include/geekos/kassert.h中

1#define TODO(message)					\
2do {							\
3    Set_Current_Attr(ATTRIB(BLUE, GRAY|BRIGHT));	\
4    Print("Unimplemented feature: %s\n", (message));	\
5    while (1)						\
6	;						\
7} while (0)

可以看到,这是一个宏打印错误提示后,就直接进入一个死循环中,也就是执行到TODO之后程序就不会继续往下运行了,所以要继续进行调试project0就必须删除或者注释掉那条TODO。

保存代码,按上一篇文章中的方法编译,并在bochs中引导系统。 运行效果如下图所示:

参考博客:参考博客1 参考博客2

Related

华科软院计组概念复习

·6 mins
noip初赛加强版既视感… 自己手动整理的 第二章 机器数:正负符号数码化后的数据称为机器数。 BCD码:用二进制编码的十进制数称为bcd码。 有权码:每位二进制数码元都有确定权值的编码。 校验码:为了发现或纠正数据传送中出现错误的编码。 浮点数的精度由尾数的位数决定。 第三章 溢出:运算结果超出了机器能表示的数据范围。 溢出的特征:结果的符号与操作数的符号不同。 变形补码:两个符号位的补码(用来检测溢出,00,11说明没有溢出,10,01说明有溢出) 对阶:使阶码相等的过程(原则是小阶码向大阶码看齐) 结果规格化:将非规格化数处理为规格化形式。

codeforces 660 C. Hard Process (ruler)

·1 min
cf660C solution:ruler.1A 1/* *********************************************** 2Author :111qqz 3Created Time :2016年06月08日 星期三 23时43分18秒 4File Name :code/cf/problem/660C.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <ctime> 19#define fst first 20#define sec second 21#define lson l,m,rt<<1 22#define rson m+1,r,rt<<1|1 23#define ms(a,x) memset(a,x,sizeof(a)) 24typedef long long LL; 25#define pi pair < int ,int > 26#define MP make_pair 27 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33const int N=3E5+7; 34int n,k; 35int sum[N],a[N]; 36 37void ruler() 38{ 39 int head = 1; 40 int tail = 1; 41 int l,r; 42 int res = -1; 43 int cnt = 0 ; 44 45 while (tail<=n) 46 { 47 while (a[tail]==1) tail++; 48// cout<<"head:"<<head<<" tail:"<<tail<<endl; 49 if (a[tail]==0&&tail<=n) cnt++; 50 51 while (sum[tail]-sum[head-1]<=k&&tail<=n) tail++; 52// cout<<"head:"<<head<<"tail:"<<tail<<endl; 53 if (tail-head>res) 54 { 55 res = tail-head; 56 // cout<<"res:"<<res<<endl; 57 l = head; 58 r = tail-1; 59 } 60 61 while (head<=tail&&sum[tail]-sum[head-1]>k) head++; 62// cout<<"head::"<<head<<" tail:"<<tail<<endl; 63 if (tail<=n&&tail-head+1>res) 64 { 65 res = tail-head+1; 66 l = head; 67 r = tail; 68 } 69 70 71 } 72 73 74 for ( int i = l ; i <= r ; i++) a[i] = 1; 75 76 cout<<res<<endl; 77 for ( int i = 1 ; i <= n ; i++) cout<<a[i]<<" "; 78} 79int main() 80{ 81 #ifndef ONLINE_JUDGE 82 freopen("code/in.txt","r",stdin); 83 #endif 84 85 cin>>n>>k; 86 87 sum[0] = 0; 88 for ( int i = 1; i <= n ; i++) 89 { 90 scanf("%d",&a[i]); 91 sum[i] = sum[i-1] +(1-a[i]); 92 } 93 94 ruler(); 95 96 97 #ifndef ONLINE_JUDGE 98 fclose(stdin); 99 #endif 100 return 0; 101}

(转)树形dp题目集

·4 mins
树,一种十分优美的数据结构,因为它本身就具有的递归性,所以它和子树见能相互传递很多信息,还因为它作为被限制的图在上面可进行的操作更多,所以各种用于不同地方的树都出现了,二叉树、三叉树、静态搜索树、AVL树,线段树、SPLAY树,后缀树等等.. 枚举那么多种数据结构只是想说树方面的内容相当多,本专辑只针对在树上的动态规划,即树形DP.做树形DP一般步骤是先将树转换为有根树,然后在树上进行深搜操作,从子节点或子树中返回信息层层往上更新至根节点。这里面的关键就是返回的信息部分,这个也没一般性的东西可讲,因为每道题目要求做的事都不尽相同。