# HG changeset patch # User Takahiro SHIMIZU # Date 1522895403 -32400 # Node ID 7143a82401fa35c5bd4f7355069e9302b81d57ad # Parent 952136cc268ff28853b8937d8072a9fd09f10d8f update diff -r 952136cc268f -r 7143a82401fa .hgignore --- a/.hgignore Thu Apr 05 11:27:39 2018 +0900 +++ b/.hgignore Thu Apr 05 11:30:03 2018 +0900 @@ -24,3 +24,4 @@ lib/Slideshow/local/* .vstags +.DS_Store diff -r 952136cc268f -r 7143a82401fa slides/2018/04/05/memo.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/2018/04/05/memo.txt Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,61 @@ +- x86の歴史 + - corei7から64bit modeに変更された + - 8086 16bit --> 8086 + == z84 <- z8000 + - 4004 + +- CPUは起動すると16bit(8086)が起動する->32->64の順で立ち上がっていく +- 8086で動くものはある程度8086でも動く + +その変換はどこでする? EFIあたりで処理をしても良い + +- Segment Register と Addr Resgisterを使う + + - Segment Registerは CD,DS,EC,GS,SSの種類があるが、歴史的な理由でUNIXではシステム用とユーザー用の2種類しか使わない + - CSはスレッドでも利用する。 + + rax + rbx + rcx + rdp + rip + rsp + + これにr8~r15が追加される + +Logical -> Phiの変換表はTLB(キャッシュ)に入る為、キャシュの内部の処理を見ながらアクセスする +Logical + offsetの加算値をTLBで比較して、一致していればアドレスを取得する用になっている + +CPUから外の空間にアクセスする時はメモリコントローラの命令として処理される。 + +データの読み込みはキャッシュのinvalidが担当、コードの書き換え(OSロード時)はキャッシュのrehashが必要となる。 +TLBのクリアは特権命令, user側はTLBミスは管理していない. cache crea,pre fetchは用意されている。 + +[リバースページテーブル](https://www.ibm.com/developerworks/jp/linux/library/l-memmod/index.html) +invarse pagetable + +xv6は2段のページテーブルで構築されているはず + +[jxxx|yyyyy| ]からそれぞれ2つページテーブルにアクセスしている + +デバイスドライバ/filesystemなどを読む必要があります + +ページテーブル ==> 単なるメモリ空間なので、ポインタ演算で実装されていた。 +物理と論理で同じ区域を確保する + +- build build時のもの +- device timer割り込み処理を計算していく +- usr + clock signal などのregisterを管理している + +- buf.h + ras piが持っているファームウエアの記述 +mkfs + - ファイルシステム作るやつ +memide + - ディスコントロラーをmemoryにmappingする +spinlock + - multiprocessorを管理する奴 +swtch.S + +vim diff -r 952136cc268f -r 7143a82401fa slides/2018/04/05/slide.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/2018/04/05/slide.md Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,12 @@ +title: 近況報告 +author: Takahiro Shimizu +profile: +lang: Japanese + + +# 研究内容 +* OS + +# hoge +* foo + * puyo diff -r 952136cc268f -r 7143a82401fa slides/20180325/slide.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/20180325/slide.md Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,12 @@ +title: 近況報告 +author: Takahiro Shimizu +profile: +lang: Japanese + + +# 研究内容 +* OS + +# hoge +* foo + * puyo diff -r 952136cc268f -r 7143a82401fa slides/20180327/slide.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/20180327/slide.md Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,14 @@ +title: 近況報告 +author: Takahiro Shimizu +profile: +lang: Japanese + +# 近況報告 + +* バイトでRubyを書いたりしています +* x86エミュレータを作る本を読み始めました + +# 研究内容 + +* 個人的にはOSか言語系がやりたいと思っています +* VMを作る作業に興味があります diff -r 952136cc268f -r 7143a82401fa slides/20180327/text --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/20180327/text Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,17 @@ +- 命令のごとCodeGearを書けば良さそう +- PS3の + +命令レベルで並列度を追求する->4並列が最大 +byte codeレベルにあげた場合は不明 + +スクリプトは必ずなんらかのループが持っている + -> それを高速化させたい + +OpenMP的に指示子をいれるのを自動化したい + -> CbCのメタ部で処理したい + +OpenMPIはAssemblerレベルなので厳しい +どんなに早い通信路でも4Mbにしか締め切られない + +- MoarVMをイメージ化する + diff -r 952136cc268f -r 7143a82401fa slides/20180403/memo.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/20180403/memo.txt Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,18 @@ +- モデル検査 + - 実際に処理をしている箇所は? + - 並列実行をしている箇所を選択する + - Synchronized Queue + +- 方針 + - 使える部分だけCbCに書き換える + - 完全にGearsの形式に書き換える + +- CbCで書き直したxv6も同じ方式で行っている +- 帯域変数は入力で持ってくる,出力で出すという雰囲気 + +- PWDを環境変数に持たせると途中のディレクトリパスが異なる可能性がある + - syscallにすると途中のパスをuserdirに保存する + +- UEFI + - OSの立ち上げ時のBaseとなる部分 + diff -r 952136cc268f -r 7143a82401fa slides/20180403/slide.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/20180403/slide.md Thu Apr 05 11:30:03 2018 +0900 @@ -0,0 +1,181 @@ +title: 近況報告 +author: Takahiro Shimizu +profile: +lang: Japanese + +# 今週の進捗 + +- xv6をcloneして読み始めました + - [Xv6, a simple Unix-like teaching operating system](https://pdos.csail.mit.edu/6.828/2017/xv6.html) +- 教科書もありました + - [xv6 a simple, Unix-like teaching operating system](https://pdos.csail.mit.edu/6.828/2017/xv6/book-rev10.pdf) +- 木金で読み会をやる予定です + +# systemcall + +- `user.h` `usys.S`でそれぞれ定義されていました + +```c +// system calls +int fork(void); +int exit(void) __attribute__((noreturn)); +int wait(void); +int pipe(int*); +int write(int, void*, int); +int read(int, void*, int); +int close(int); +int kill(int); +int exec(char*, char**); +int open(char*, int); +int mknod(char*, short, short); +int unlink(char*); +int fstat(int fd, struct stat*); +int link(char*, char*); +int mkdir(char*); +int chdir(char*); +int dup(int); +int getpid(void); +char* sbrk(int); +int sleep(int); +int uptime(void); +``` + +# printf + +- printfは `%d, %x, %p, %s.` のみをサポートしています +- コンパイラ構成論で書いたような素朴な実装でした +- print時の進数は `printint` の引数で分けているようです + +```c +void +printf(int fd, char *fmt, ...) +{ + char *s; + int c, i, state; + uint *ap; + + state = 0; + ap = (uint*)(void*)&fmt + 1; + for(i = 0; fmt[i]; i++){ + c = fmt[i] & 0xff; + if(state == 0){ + if(c == '%'){ + state = '%'; + } else { + putc(fd, c); + } + } else if(state == '%'){ + if(c == 'd'){ + printint(fd, *ap, 10, 1); + ap++; + } else if(c == 'x' || c == 'p'){ + printint(fd, *ap, 16, 0); + ap++; + } else if(c == 's'){ + s = (char*)*ap; + ap++; + if(s == 0) + s = "(null)"; + while(*s != 0){ + putc(fd, *s); + s++; + } + } else if(c == 'c'){ + putc(fd, *ap); + ap++; + } else if(c == '%'){ + putc(fd, c); + } else { + // Unknown % sequence. Print it to draw attention. + putc(fd, '%'); + putc(fd, c); + } + state = 0; + } + } +} +``` + +# sysemcallを呼ぶ前 + +- まだ処理が追いきれていません。 + +``` +static void +printint(int fd, int xx, int base, int sgn) +{ + static char digits[] = "0123456789ABCDEF"; + char buf[16]; + int i, neg; + uint x; + + neg = 0; + if(sgn && xx < 0){ + neg = 1; + x = -xx; + } else { + x = xx; + } + + i = 0; + do{ + buf[i++] = digits[x % base]; + }while((x /= base) != 0); + if(neg) + buf[i++] = '-'; + + while(--i >= 0) + putc(fd, buf[i]); +} +``` + +# putc + +- 素朴にwriteを読んでいる + +``` +static void +putc(int fd, char c) +{ + write(fd, &c, 1); +} + +``` + +# sh + +- main関数 +- まずforkが入る +- cd以外はparseしてrunする世界観のようです + +```C +int +main(void) +{ + static char buf[100]; + int fd; + + // Ensure that three file descriptors are open. + while((fd = open("console", O_RDWR)) >= 0){ + if(fd >= 3){ + close(fd); + break; + } + } + + // Read and run input commands. + while(getcmd(buf, sizeof(buf)) >= 0){ + if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){ + // Chdir must be called by the parent, not the child. + buf[strlen(buf)-1] = 0; // chop \n + if(chdir(buf+3) < 0) + printf(2, "cannot cd %s\n", buf+3); + continue; + } + if(fork1() == 0) + runcmd(parsecmd(buf)); + wait(); + } + exit(); +} +```