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

linux下的对拍写法

·1 min
1首先先生成三个程序: 2$ g++ a+b.cpp -o a+b 3$ g++ a+b2.cpp -o a+b2 4$ g++ make.cpp -o make 5然后生成数据 6$ ./make > in.txt 7然后运行两个程序 8$ ./a+b < in.txt > out.txt 9$ ./a+b2 < in.txt > ans.txt 10最后对拍 11$ diff out.txt ans.txt 12输出的结果可以man diff查阅一下相关文档中关于输出含义的内容 13注:上面的$都是命令提示符,复制粘贴时不需要

tmp

·1 min
1#include <iostream> 2#include <vector> 3#include <cstring> 4#include <set> 5#include <algorithm> 6#include <cstdio> 7 8using namespace std; 9const int N=1E4+7; 10int n,k,Q; 11int siz; 12int pos[N]; 13int sum[N]; 14int dis[N]; 15bool vis[N]; 16vector < pair<int,int> > edge[N]; 17 18struct node 19{ 20 int l,r; 21 int id; 22 23 bool operator < (node b)const 24 { 25 if (pos[l]==pos[b.l]) return r<b.r; 26 return pos[l]<pos[b.l]; 27 } 28 29 30}q[N]; 31 32 33void dfs( int u,int val) 34{ 35 vis[u] = true; 36 dis[u+1] = val; 37 38 int Siz = edge[u].size(); 39 for ( int i = 0 ; i < Siz ; i ++) 40 { 41 int v = edge[u][i].first; 42 43 if (!vis[v]) 44 { 45 dfs(v,val+edge[u][i].second); 46 } 47 } 48} 49int main() 50{ 51 52 freopen("in.txt","r",stdin); 53 siz = 100; 54 for ( int i = 0 ; i < 10000 ; i++) pos[i] = i/siz; 55 while (scanf("%d %d %d",&n,&k,&Q)!=EOF) 56 { 57 memset(vis,false,sizeof(vis)); 58 memset(dis,0,sizeof(dis)); 59 memset(sum,0,sizeof(sum)); 60 for ( int i = 1 ;i < n ; i++) 61 { 62 int u = i; 63 int v = i/k; 64 edge[u].push_back(make_pair(v,i)); 65 edge[v].push_back(make_pair(u,i)); 66 } 67 68 for ( int i = 1 ;i <= Q ; i++) 69 { 70 scanf("%d %d",&q[i].l,&q[i].r); 71 q[i].id = i; 72 } 73 74 sort(q+1,q+Q+1); 75 76 dfs(0,0); 77 for ( int i = 1 ; i <= n ; i++) sum[i] = sum[i-1]+dis[i]; 78 } 79}

NYOJ 505 因子和阶乘

·1 min
http://acm.nyist.net/JudgeOnline/problem.php?pid=509 题意:中文题目。。。 思路:快速筛即可。。。妈蛋。。。这个oj不能用宏编译==。。。然后一直TLE…去掉了就好了。。sad

poj 1350 Cabric Number Problem

·1 min
http://poj.org/problem?id=1350 题意:6174问题。。。一个四位数。。四个数字重排。。。最大的减去最小的得到新的数字。最后一定能得到6174或者0.除非这个四位数的四个数字都一样。写出变化的过程。