将jos的源码放到github上去了

123 views
Skip to first unread message

Chunis Deng

unread,
Nov 1, 2010, 10:10:53 AM11/1/10
to xv6-jos
只是弄上去了而已,使用方法等稍后再仔细研究
以后大家就可以通过patch或者checkin的方式参与了,努力折腾吧! ^_^

访问地址:http://github.com/chunis/mit-jos

dave

unread,
Nov 2, 2010, 5:01:10 AM11/2/10
to xv6...@googlegroups.com
LAB1给代码中的'\t'的处理很简陋,直接把'\t'替换为5个空格,这和我们平时习惯有很大不同,所以要改造一下。

1、在kern/console.c cga_putc()函数中,可以看到'\t'case分支,把这个分支替换为如下代码:
        case '\t':
                do{
                        cons_putc(' ');
                }while(crt_pos%TAB_SIZE != 0);
                break;
其中的TAB_SIZE我将其定义在kern/console.h,尺寸为8:
#define TAB_SIZE 8
这样重新编译,用输出一些TAB字符,其行为已正常。

2、发现在系统终端下输入TAB是被禁止的,但是我想把TAB键作为制表符输入,所以要修改输入的部分,经过定位,发现是在lib/readline.c readline()函数中处理的输入,于是把22行的:
} else if ( c >= ' ' && i < BUFLEN-1) {
修改为:
} else if ( ((c >= ' ')||(c == '\t')) && i < BUFLEN-1) {
保存后重新编译,可以正常输入TAB字符。

3、又发现输入TAB后的退格处理不正常,一个TAB应该一次性退格,但是目前的退格仅仅是退一个空格,这不是我们想要的功能,发现对退格的处理仍然是在kern/console.c cga_putc()函数中。
思考:cga_putc()要怎么才能知道退格的是一个空格还是一个制表符?
参考步骤1,我们都是输出的' ',在显示缓冲区里面是不能区分,这必然要求我们用一个缓冲来保存以前处理的字符串,而且TAB在不同位置下长度不固定,也这也要求我们必须要记录其输出长度。对于缓冲长度要取多少,肯定要大于等于lib/readline.c readline()函数中缓冲区的长度,至于上限,就是个见仁见智的问题。
cga_putc()代码修改如下:
//mod by davelv @ 2010-11-02
//add the facility to display and clear '\t'
static void cga_putc(int c)
{
        static int line_buf[CRT_SIZE];//line buffer = 80*25,high_word:char's length,low_word:attribute &  value
        static int line_pos;//line buffer's current postion
        int i;//i as a temp var;
        // if no attribute given, then use black on white
        if (!(c & ~0xFF))
                c |= 0x0700;

        switch (c & 0xff) {
        case '\b':
                if ((crt_pos > 0)&&(line_pos > 0)) {//not only crt_pos but also line_pos
                        i = line_buf[--line_pos]>>16;//get char's length
                        do{
                                crt_buf[--crt_pos] = (c & ~0xff) | ' ';//clear last char
                        }while(((line_buf[line_pos]&0xff) == '\t')&&( --i));//loop when char '\t' hasn't been clear all;
                }
                break;
        case '\n':
                crt_pos += CRT_COLS;
                /* fallthru */
        case '\r':
                crt_pos -= (crt_pos % CRT_COLS);
                line_pos = 0;//when '\r' or '\n',clear buf
                break;
        case '\t':
                i = 0;//TAB length counter
                do{
                        crt_buf[crt_pos++]=(c & ~0xff) | ' ';//display one blan
                        i++;//length ++
                }while(crt_pos%TAB_SIZE != 0);
                line_buf[line_pos++] = c|(i<<16) ;//save length&value
                break;
        default:
                line_buf[line_pos++] = c;       //save new char
                crt_buf[crt_pos++] = c;         /* write the character */
                break;
        }

        // What is the purpose of this?
        if (crt_pos >= CRT_SIZE) {

                memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t));
                for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++)
                        crt_buf[i] = 0x0700 | ' ';
                crt_pos -= CRT_COLS;
        }

        /* move that little blinky thing */
        outb(addr_6845, 14);
        outb(addr_6845 + 1, crt_pos >> 8);
        outb(addr_6845, 15);
        outb(addr_6845 + 1, crt_pos);
}

保存,编译,运行,无论是输入TAB还是删除TAB均已变得正常。

4、新的问题,我暂不说个人看法,先供大家讨论和思考:
(1)据我们所知,TAB的尺寸是可以由软件定制的,但是我们这个LAB只有内核,所以直接些死到驱动里面,但哪些是应该由驱动做的,哪些是由用户程序自定义的,这是OS设计者必须划分清楚的,在驱动里去做TAB,还有我新加的行缓冲,这样是否合理,应该怎样改进或者拆分。
(2)我这里把驱动里面的行缓冲定义为一屏字符,但是如果只输出TAB的话,其实是八屏,但是一旦屏幕字符刷到上面去以后,就不能再回来。如何实现整屏缓冲,缓冲要做到哪里合适。

不知道新的LAB中会不会添加新的代码,如果添加新的代码正好把这部分做了的话,倒是可以参考下。
BTW:欢迎debug

_________________________
davelv, a Linux programer
http://blog.csdn.net/davelv
E-mali: dav...@qq.com
Zhuhai Kingsoft  Co. ,Ltd.

dachuan

unread,
Nov 2, 2010, 7:08:09 AM11/2/10
to xv6-jos
我写了个lab/hdc/printf_test.c准备调试。但是编译后运行出现Segmentation fault 。

//  hdc/printf_test.c

#include <inc/stdio.h>

int main()
{
        int x = 1;
        cprintf("%d\n", x);
        return 0;
}

我在lab/下是这样编译的。
gcc -I. -g -fno-builtin hdc/printf_test.c kern/console.c lib/printfmt.c kern/printf.c

然后./a.out
[root@dachuanvm lab]# ./a.out
Segmentation fault


2010/11/2 dave <dav...@qq.com>



--
Dachuan Huang, Graduate Candidate
-----------------------------------------------------------
Cluster and Grid Computing Lab
Services Computing Technology and System Lab
Huazhong University of Science and Technology
Wuhan, 430074, China
Tel: +86-15902733227
 
Email: hdc...@gmail.com

dave

unread,
Nov 2, 2010, 7:24:00 AM11/2/10
to xv6...@googlegroups.com
人家的函数都是运行在内核,你写这个东西在普通用户下跑肯定会出故障了。
在 2010-11-02二的 19:08 +0800,dachuan写道:
我写了个lab/hdc/printf_test.c准备调试。但是编译后运行出现Segmentation fault 。

//  hdc/printf_test.c

#include <inc/stdio.h>

int main()
{
        int x = 1;
        cprintf("%d\n", x);
        return 0;
}

我在lab/下是这样编译的。
gcc -I. -g -fno-builtin hdc/printf_test.c kern/console.c lib/printfmt.c kern/printf.c

然后./a.out
[root@dachuanvm lab]# ./a.out
Segmentation fault

dave

unread,
Nov 2, 2010, 8:30:29 AM11/2/10
to xv6...@googlegroups.com
BUGFIX1:
忘记添加判断行缓冲是否满的情况,但在当前的kernel功能下不会出现bug,fixcode:


//mod by davelv @ 2010-11-02
//add the facility to display and clear '\t'
static void cga_putc(int c)
{
static int line_buf[CRT_SIZE];//line buffer = 80*25,high_word:char's length,low_word:attribute &  value
static int line_pos;//line buffer's current postion
int i;//i as a temp var;
// if no attribute given, then use black on white
if (!(c & ~0xFF))
c |= 0x0700;

switch (c & 0xff) {
case '\b':
if ((crt_pos > 0)&&(line_pos > 0)) {//not only crt_pos but also line_pos
i = line_buf[--line_pos]>>16;//get char's length
do{
crt_buf[--crt_pos] = (c & ~0xff) | ' ';//clear last char
}while(--i);//loop when char '\t' hasn't been clear all;

}
break;
case '\n':
crt_pos += CRT_COLS;
/* fallthru */
case '\r':
crt_pos -= (crt_pos % CRT_COLS);
line_pos = 0;//when '\r' or '\n',clear buf
break;
case '\t':
if (line_pos == CRT_SIZE)//buf full
return;

i = 0;//TAB length counter
do{
crt_buf[crt_pos++]=(c & ~0xff) | ' ';//display one blank
i++;//length++

}while(crt_pos%TAB_SIZE != 0);
line_buf[line_pos++] = c|(i<<16) ;//save length&value
break;
default:
if (line_pos == CRT_SIZE)//buf full
return;
line_buf[line_pos++] = c|(1<<16); //save new char

dachuan

unread,
Nov 2, 2010, 9:42:33 AM11/2/10
to xv6...@googlegroups.com
我很崩溃的提个问题
 
        // if no attribute given, then use black on white
        if (!(c & ~0xFF))
                c |= 0x0700;
 
从这个可以看出c的上部分是有颜色信息的。而你用来存储tab长度信息。是否会冲突。


 
2010/11/2 dave <dav...@qq.com>

dave

unread,
Nov 2, 2010, 9:44:40 AM11/2/10
to xv6...@googlegroups.com
用来存储属性的的位只占了一个字节。
在 2010-11-02二的 21:42 +0800,dachuan写道:

Sunus Lee

unread,
Nov 3, 2010, 12:35:53 AM11/3/10
to xv6...@googlegroups.com


2010/11/2 dachuan <hdc...@gmail.com>
这里一共有32位,字符的值8位,字符属性8位
还剩16位可以用呢

Chunis Deng

unread,
May 1, 2012, 9:45:13 AM5/1/12
to xv6-jos
2010年的lab和2011年的有较大差别,尤其是2011的lab4加入了对smp的支持。
考虑到mit-jos一直没做checkin,我将之删除了,新建了另外一个针对2011年的lab的:
http://github.com/chunis/mit-jos2011
目前已经完成了lab2的part 1. 欢迎大家关注/fork

Chunis Deng

unread,
May 20, 2012, 6:41:16 AM5/20/12
to xv6-jos
由于以前对git不熟悉,对代码的管理方式不对,导致在checkout原来的代码以及merge的时候造成了极大的混乱,以至于几乎没办法继续下去了
所以前段时间以正确的方法对代码进行了一次梳理,并在github上新建了一个项目:
http://github.com/chunis/mit-jos2012
原有的mit-jos2011本想删除,但发现有人fork了,所以只好废弃之。
目前开始做lab4
Reply all
Reply to author
Forward
0 new messages