Skip to main content
  1. Posts/

geekok project0(上)(实验环境的搭建)

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

apt-get install build-essential apt-get install bochs bochs-x nasm

此处下载的bochs应该是比较新的…如果之后遇到

failed assertion in init_idt :g_handlersizenoterr == g_handlersizeerr

这个错误,建议安装比较老的nasm版本,比如2.08.02链接

下载geekos-0.3软件包,地址为: geekOS下载地址

然后解压到~/work目录。

然后进入到 /work/geekos-0.3.0/src/project0/build 目录下

之后的操作都是在这个目录下进行的。

 1rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ make depend
 2Makefile:249: depend.mak: 没有那个文件或目录
 3touch depend.mak
 4gcc -M -O -Wall  -Werror  -g -DGEEKOS -I../include \
 5		../src/geekos/idt.c ../src/geekos/int.c ../src/geekos/trap.c ../src/geekos/irq.c ../src/geekos/io.c ../src/geekos/keyboard.c ../src/geekos/screen.c ../src/geekos/timer.c ../src/geekos/mem.c ../src/geekos/crc32.c ../src/geekos/gdt.c ../src/geekos/tss.c ../src/geekos/segment.c ../src/geekos/bget.c ../src/geekos/malloc.c ../src/geekos/synch.c ../src/geekos/kthread.c ../src/geekos/main.c \
 6		| perl -n -e 's,^(\S),geekos/$1,;print' \
 7		> depend.mak
 8gcc -M -O -Wall  -Werror  -I../include -I../include/libc  \
 9		../src/common/fmtout.c ../src/common/string.c ../src/common/memmove.c \
10		| perl -n -e 's,^(\S),common/$1,;print' \
11		>> depend.mak

然后执行 make

 1rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ make
 2gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/idt.c -o geekos/idt.o
 3gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/int.c -o geekos/int.o
 4gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/trap.c -o geekos/trap.o
 5gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/irq.c -o geekos/irq.o
 6gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/io.c -o geekos/io.o
 7gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/keyboard.c -o geekos/keyboard.o
 8gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/screen.c -o geekos/screen.o
 9gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/timer.c -o geekos/timer.o
10gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/mem.c -o geekos/mem.o
11gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/crc32.c -o geekos/crc32.o
12gcc -c -O -Wall  -Werror  -g -DGEEKOS -I../include ../src/geekos/gdt.c -o geekos/gdt.o
13In file included from ../src/geekos/gdt.c:11:0:
14../include/geekos/segment.h:43:5: error: ‘packed’ attribute ignored for field of type ‘uchar_t’ [-Werror=attributes]
15     uchar_t baseHigh        PACKED ;
16     ^
17cc1: all warnings being treated as errors
18make: *** [geekos/gdt.o] 错误 1

报错,原因是编译检查过于严格。。我们修改makefile文件,取消把warning当成错误看待。

makefile 的路径就是当前路径,也就是:

rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ vim Makefile

把149行的 -Werror 去掉。

然后再次make

 1rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ make
 2gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/gdt.c -o geekos/gdt.o
 3In file included from ../src/geekos/gdt.c:11:0:
 4../include/geekos/segment.h:43:5: warning: ‘packed’ attribute ignored for field of type ‘uchar_t’ [-Wattributes]
 5     uchar_t baseHigh        PACKED ;
 6     ^
 7gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/tss.c -o geekos/tss.o
 8In file included from ../src/geekos/tss.c:18:0:
 9../include/geekos/segment.h:43:5: warning: ‘packed’ attribute ignored for field of type ‘uchar_t’ [-Wattributes]
10     uchar_t baseHigh        PACKED ;
11     ^
12gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/segment.c -o geekos/segment.o
13In file included from ../src/geekos/segment.c:18:0:
14../include/geekos/segment.h:43:5: warning: ‘packed’ attribute ignored for field of type ‘uchar_t’ [-Wattributes]
15     uchar_t baseHigh        PACKED ;
16     ^
17gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/bget.c -o geekos/bget.o
18gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/malloc.c -o geekos/malloc.o
19gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/synch.c -o geekos/synch.o
20gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/kthread.c -o geekos/kthread.o
21gcc -c -O -Wall    -g -DGEEKOS -I../include ../src/geekos/main.c -o geekos/main.o
22nasm -I../src/geekos/ -f elf  ../src/geekos/lowlevel.asm -o geekos/lowlevel.o
23gcc -c -O -Wall    -I../include -I../include/libc  ../src/common/fmtout.c -o common/fmtout.o
24gcc -c -O -Wall    -I../include -I../include/libc  ../src/common/string.c -o common/string.o
25gcc -c -O -Wall    -I../include -I../include/libc  ../src/common/memmove.c -o common/memmove.o
26ld -o geekos/kernel.exe -Ttext 0x00010000 -e Main \
27		geekos/idt.o geekos/int.o geekos/trap.o geekos/irq.o geekos/io.o geekos/keyboard.o geekos/screen.o geekos/timer.o geekos/mem.o geekos/crc32.o geekos/gdt.o geekos/tss.o geekos/segment.o geekos/bget.o geekos/malloc.o geekos/synch.o geekos/kthread.o geekos/main.o geekos/lowlevel.o common/fmtout.o common/string.o common/memmove.o
28ld: i386 architecture of input file `geekos/lowlevel.o' is incompatible with i386:x86-64 output
29common/fmtout.o:在函数‘Format_Output’中:
30fmtout.c:(.text+0xa16):对‘__stack_chk_fail’未定义的引用
31make: *** [geekos/kernel.exe] 错误 1

解决办法是把makefile文件中第148行添加编译选项

-fno-stack-protector

然后把makefile文件中的100行至109行修改为如下内容 (修改了100行,106行,109行,条件编译什么的。。可能遇到依赖的库不全的情况。。。安装就好)

 1TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
 2101
 3# Host C compiler.  This is used to compile programs to execute on
 4# the host platform, not the target (x86) platform.  On x86/ELF
 5# systems, such as Linux and FreeBSD, it can generally be the same
 6# as the target C compiler.
 7HOST_CC := gcc -m32
 8107
 9# Target linker.  GNU ld is probably to only one that will work.
10TARGET_LD := $(TARGET_CC_PREFIX)ld  -m elf_i386

然后要把以前失败的清理干净。。重新编译。。。

 1rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ make clean
 2for d in geekos common libc user tools; do \
 3		(cd $d && rm -f *); \
 4	done
 5rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ make depend
 6gcc -m32 -M -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include \
 7		../src/geekos/idt.c ../src/geekos/int.c ../src/geekos/trap.c ../src/geekos/irq.c ../src/geekos/io.c ../src/geekos/keyboard.c ../src/geekos/screen.c ../src/geekos/timer.c ../src/geekos/mem.c ../src/geekos/crc32.c ../src/geekos/gdt.c ../src/geekos/tss.c ../src/geekos/segment.c ../src/geekos/bget.c ../src/geekos/malloc.c ../src/geekos/synch.c ../src/geekos/kthread.c ../src/geekos/main.c \
 8		| perl -n -e 's,^(\S),geekos/$1,;print' \
 9		> depend.mak
10gcc -m32 -M -O -Wall  -fno-stack-protector   -I../include -I../include/libc  \
11		../src/common/fmtout.c ../src/common/string.c ../src/common/memmove.c \
12		| perl -n -e 's,^(\S),common/$1,;print' \
13		>> depend.mak
14rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ make
15gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/idt.c -o geekos/idt.o
16gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/int.c -o geekos/int.o
17gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/trap.c -o geekos/trap.o
18gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/irq.c -o geekos/irq.o
19gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/io.c -o geekos/io.o
20gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/keyboard.c -o geekos/keyboard.o
21gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/screen.c -o geekos/screen.o
22gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/timer.c -o geekos/timer.o
23gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/mem.c -o geekos/mem.o
24gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/crc32.c -o geekos/crc32.o
25gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/gdt.c -o geekos/gdt.o
26In file included from ../src/geekos/gdt.c:11:0:
27../include/geekos/segment.h:43:5: warning: packed attribute ignored for field of type uchar_t [-Wattributes]
28     uchar_t baseHigh        PACKED ;
29     ^
30gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/tss.c -o geekos/tss.o
31In file included from ../src/geekos/tss.c:18:0:
32../include/geekos/segment.h:43:5: warning: packed attribute ignored for field of type uchar_t [-Wattributes]
33     uchar_t baseHigh        PACKED ;
34     ^
35gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/segment.c -o geekos/segment.o
36In file included from ../src/geekos/segment.c:18:0:
37../include/geekos/segment.h:43:5: warning: packed attribute ignored for field of type uchar_t [-Wattributes]
38     uchar_t baseHigh        PACKED ;
39     ^
40gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/bget.c -o geekos/bget.o
41gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/malloc.c -o geekos/malloc.o
42gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/synch.c -o geekos/synch.o
43gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/kthread.c -o geekos/kthread.o
44gcc -m32 -c -O -Wall  -fno-stack-protector   -g -DGEEKOS -I../include ../src/geekos/main.c -o geekos/main.o
45nasm -I../src/geekos/ -f elf  ../src/geekos/lowlevel.asm -o geekos/lowlevel.o
46gcc -m32 -c -O -Wall  -fno-stack-protector   -I../include -I../include/libc  ../src/common/fmtout.c -o common/fmtout.o
47gcc -m32 -c -O -Wall  -fno-stack-protector   -I../include -I../include/libc  ../src/common/string.c -o common/string.o
48gcc -m32 -c -O -Wall  -fno-stack-protector   -I../include -I../include/libc  ../src/common/memmove.c -o common/memmove.o
49ld -m elf_i386 -o geekos/kernel.exe -Ttext 0x00010000 -e Main \
50		geekos/idt.o geekos/int.o geekos/trap.o geekos/irq.o geekos/io.o geekos/keyboard.o geekos/screen.o geekos/timer.o geekos/mem.o geekos/crc32.o geekos/gdt.o geekos/tss.o geekos/segment.o geekos/bget.o geekos/malloc.o geekos/synch.o geekos/kthread.o geekos/main.o geekos/lowlevel.o common/fmtout.o common/string.o common/memmove.o
51nm geekos/kernel.exe > geekos/kernel.syms
52nasm -f bin \
53		-I../src/geekos/ \
54		-DENTRY_POINT=0x`egrep 'Main$' geekos/kernel.syms |awk '{print $1}'` \
55		../src/geekos/setup.asm \
56		-o geekos/setup.bin
57perl ../scripts/pad geekos/setup.bin 512
58objcopy -R .dynamic -R .note -R .comment -S -O binary geekos/kernel.exe geekos/kernel.bin
59perl ../scripts/pad geekos/kernel.bin 512
60nasm -f bin \
61		-I../src/geekos/ \
62		-DNUM_SETUP_SECTORS=`perl ../scripts/numsecs geekos/setup.bin` \
63		-DNUM_KERN_SECTORS=`perl ../scripts/numsecs geekos/kernel.bin` \
64		../src/geekos/fd_boot.asm \
65		-o geekos/fd_boot.bin
66cat geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin > fd.img

编译成功。。。 检查一下:

rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ ls -a
.  ..  .bochsrc  common  depend.mak  fd.img  geekos  libc  Makefile  tools  user

然后启动bochs

报错:

 1rkz2013@111qqz-ThinkPad-X200 ~/work/geekos-0.3.0/src/project0/build $ bochs
 2========================================================================
 3                       Bochs x86 Emulator 2.4.6
 4             Build from CVS snapshot, on February 22, 2011
 5                   Compiled at Jun  8 2013, 05:16:04
 6========================================================================
 700000000000i[     ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins'
 800000000000i[     ] BXSHARE not set. using compile time default '/usr/share/bochs'
 900000000000i[     ] reading configuration from .bochsrc
1000000000000p[     ] >>PANIC<< .bochsrc:4: vgaromimage directive malformed.
1100000000000e[CTRL ] notify called, but no bxevent_callback function is registered
1200000000000i[CTRL ] quit_sim called with exit code 1

因为配置文件.bochsrc 太古老了。。。路径什么的都是错的。。。

最终修改为如下:

 1# An example .bochsrc file.
 2# You will need to edit these lines to reflect your system.
 3vgaromimage: file=/usr/share/vgabios/vgabios.bin
 4romimage: file=/usr/share/bochs/BIOS-bochs-latest
 5megs: 8
 6boot: a
 7floppya: 1_44=fd.img, status=inserted
 8#floppya: 1_44=fd_aug.img, status=inserted
 9log: ./bochs.out
10keyboard_serial_delay: 200
11vga_update_interval: 300000
12mouse: enabled=0
13private_colormap: enabled=0
14i440fxsupport: enabled=0
15# Uncomment this to write all bochs debugging messages to
16# bochs.out.  This produces a lot of output, but can be very
17# useful for debugging the kernel.
18#debug: action=report

然后继续启动。。报错:

 1========================================================================
 2                       Bochs x86 Emulator 2.4.6
 3             Build from CVS snapshot, on February 22, 2011
 4                   Compiled at Jun  8 2013, 05:16:04
 5========================================================================
 600000000000i[     ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins'
 700000000000i[     ] BXSHARE not set. using compile time default '/usr/share/bochs'
 800000000000i[     ] reading configuration from .bochsrc
 900000000000i[     ] lt_dlhandle is 0x2668a40
1000000000000i[PLGIN] loaded plugin libbx_x.so
1100000000000i[     ] installing x module as the Bochs GUI
1200000000000i[     ] using log file ./bochs.out
13bochs-bin: symbol lookup error: /usr/lib/bochs/plugins/libbx_x.so: undefined symbol: XpmCreatePixmapFromData

这是由apt-get install bochs-x 得到的 libbx_x.so不完善造成的 解决办法: 换个显示方案。

sudo apt-get install bochs-sdl

然后在.bochsrc文件中添加

display_library: sdl

再次运行bochs  。。终于可以了。。。感动

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一般步骤是先将树转换为有根树,然后在树上进行深搜操作,从子节点或子树中返回信息层层往上更新至根节点。这里面的关键就是返回的信息部分,这个也没一般性的东西可讲,因为每道题目要求做的事都不尽相同。