Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
tyfkda edited this page Dec 13, 2018 · 18 revisions

memo

fs

  • Block size(BSIZE): 512B
  • inodestart = 32, ninodes = 200
    • inode info: 0x4000~ (= inodestart * BSIZE)
  • bmapstart: 57, size=1 (= FSSIZE / (BSIZE * 8) + 1)
  • freeblock: 58~

Boot process

Process switch

  1. Timer interrupt (100ms)
  2. trap.c trap(), case T_IRQ0 + IRQ_TIMER:
  3. proc.c yield()
  4. proc.c shed()
  5. swtch.S swtch

write to stdout

Kernel:

  • sysfile.c: sys_write()
  • file.c: filewrite()
  • fs.c: writei() => return devsw[ip->major].write(ip, src, n);
    • console.c: consoleinit() => devsw[1].write = consolewrite
  • console.c: consolewrite()
  • console.c: consputc()
  • uart.c: uartputc()
  • console.c: cgaputc()

Pipe

Creation:

  • User space:
    • usys.S: pipe(int*)
  • Kernel space:
    • vectors.S: vector64 (T_SYSCALL=64)
    • trapasm.S: alltraps
    • trap.c: trap()
    • syscall.c: syscall()
    • sysfile.c: sys_pipe()
    • pipe.c: pipealloc()
      • filealloc x 2, 1 for read, 1 for write
      • kalloc x 1, used to keep pipe struct.

Write:

  • sysfile.c: sys_write()
  • file.c: filewrite()
  • pipe.c: pipewrite()

Read:

  • sysfile.c: sys_read()
  • file.c: fileread()
  • pipe.c: piperead()

TODOs

  • Sleep/wakeup mechanism
  • Fork/exec mechanism
  • Support >> in shell
    • Add file append mode
  • Add mtime to file info
    • RTC
  • Analyze ELF execution sequence (How to allocate memory, etc.)
  • Use .text, .rodata, .data, .bss sections
  • POSIX

Memory map

$ memmap
execelf: /bin/memmap
  vaddr=1000, memsz=2c68, filesz=1c31, sz=3c68
  sz=3c68
  sp=6000
main: 0x1046
bss: 0x2c40
const_data: 0x2660
rw_data: 0x2b60
stack: 0x5f58
sbrk: 0x6000
  • User stack: 1 x PGSIZE = 4096
  • elfの段階でプログラム、定数データ、読み書きデータ、未初期化領域もすべて1つの領域になっていて、連続したメモリ領域に確保・読み込まれる。
  • その直後に1ページのアクセス不可領域、そしてスタック領域が確保される。

Memory Map (kernel)

Address Entity
0x80100000- Kernel program

Memory Map (user)

Virtual Address Entity
0x00001000- User program
data, bss
heap
0x10000000- User stack

コミットメモ

  • 0番地を空けて、アクセスするとページフォルトが起こるようにする: 33a6ea2
  • スタックをコード・データ領域から離す: 3d6de31

.

Clone this wiki locally