2013年1月6日 星期日

"Orange's 一個作業系統的實現"的 wait/exec/exit 實作

搞定 fork 之後, 我以為來到這步會很容易, 沒想到又經歷一些除錯的時間。特別是 kernel loader 的部份還是有錯誤, 載入 500000 byte 的 p_kernel.elf 有問題, fat sector 超過兩個 sector 時會讀取錯誤。花了不少時間解決, 在加上其他小問題, 總算來到這步。

這是在 eeepc 901 上的實機測試, "I am app" 是 fork 之後的 child process, 再經由 ramdisk 載入 echo 這個 elf 執行檔的執行結果。

上方紅框則是 parent process 列印的訊息。



下圖則是 child process 執行 exit() 結束自己的結果, parent process 得到 child process return value 2, 雖然和 Orange's 一個作業系統的實現書中比起來, 我已經大量簡化很多東西, 不過這已經足夠讓我理解 fork/wait/exec/exit 的實作方式。終於知道我想知道的答案。來到這步, 大概花了一年之久, 總算滿足了自己的好奇心。

其實應該不用這麼久, 因為這段期間我還弄懂 c runtime, c++ runtime, gas at&t 組合語言, vga 繪圖模式, 還復活了 jmcce, 只照書本學習有點枯燥, 還是混著玩點其他東西。

os 學習之旅可暫時告一個段落, 讓自己稍微輕鬆點。剩下的問題慢慢再來修正。



實機測試雖然沒問題, 不過在 bochs 上卻發生了 BOUND_GdMa: fails bounds test 訊息, 真是奇怪, 沒有個完美的結束, 找時間在處理這問題。

typescript
  1 Script started on Wed 28 Nov 2012 09:48:02 AM CST
  2  ]0;descent@w-linux: simple_os descent@w-linux:simple_os$ exit    make^C
  3  ]0;descent@w-linux: simple_os descent@w-linux:simple_os$ bochs -f bo  [K  [Kx8 6nobp.bxrc 
  4 ========================================================================
  5                        Bochs x86 Emulator 2.5.1
  6               Built from SVN snapshot on January 6, 2012
  7                   Compiled on May 16 2012 at 08:33:16
  8 ========================================================================
  9 00000000000i[     ] reading configuration from x86nobp.bxrc
 10 ------------------------------
 11 Bochs Configuration: Main Menu
 12 ------------------------------
 13 
 14 This is the Bochs Configuration Interface, where you can describe the
 15 machine that you want to simulate.  Bochs has already searched for a
 16 configuration file (typically called bochsrc.txt) and loaded it if it
 17 could be found.  When you are satisfied with the configuration, go
 18 ahead and start the simulation.
 19 
 20 You can also start bochs with the -q option to skip these menus.
 21 
 22 1. Restore factory default configuration
 23 2. Read options from...
 24 3. Edit options
 25 4. Save options to...
 26 5. Restore the Bochs state from...
 27 6. Begin simulation
 28 7. Quit now
 29 
 30 Please choose one: [6] 
 31 00000000000i[     ] installing x module as the Bochs GUI
 32 00000000000i[     ] Bochs x86 Emulator 2.5.1
 33 00000000000i[     ]   Built from SVN snapshot on January 6, 2012
 34 00000000000i[     ] Compiled on May 16 2012 at 08:33:16
 35 00000000000i[     ] System configuration
 36 00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
 37 00000000000i[     ]   A20 line support: yes
 38 00000000000i[     ]   load configurable MSRs from file "msrs.def"
 39 00000000000i[     ] IPS is set to 50000000
 40 00000000000i[     ] CPU configuration
 41 00000000000i[     ]   level: 6
 42 00000000000i[     ]   SMP support: no
 43 00000000000i[     ]   APIC support: xapic
 44 00000000000i[     ]   FPU support: yes
 45 00000000000i[     ]   MMX support: yes
 46 00000000000i[     ]   3dnow! support: no
 47 00000000000i[     ]   SEP support: yes
 48 00000000000i[     ]   SSE support: sse2
 49 00000000000i[     ]   XSAVE support: no 
 50 00000000000i[     ]   AES support: no
 51 00000000000i[     ]   MOVBE support: no
 52 00000000000i[     ]   x86-64 support: no
 53 00000000000i[     ]   MWAIT support: yes
 54 00000000000i[     ] Optimization configuration
 55 00000000000i[     ]   RepeatSpeedups support: no
 56 00000000000i[     ]   Fast function calls: no
 57 00000000000i[     ]   Handlers Chaining speedups: no
 58 00000000000i[     ] Devices configuration
 59 00000000000i[     ]   NE2000 support: no
 60 00000000000i[     ]   PCI support: no, enabled=yes
 61 00000000000i[     ]   SB16 support: no
 62 00000000000i[     ]   USB support: no
 63 00000000000i[     ]   VGA extension support: vbe 
 64 00000000000i[MEM0 ] allocated memory at 0x7ff3ce3a2010. after alignment, vector=0x7ff3ce3a3000
 65 00000000000i[MEM0 ] 128.00MB
 66 00000000000i[MEM0 ] mem block size = 0x00100000, blocks=128
 67 00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('/usr/local/share/bochs/BIOS-bochs-latest')
 68 00000000000e[DEV  ] Bochs is not compiled with PCI support
 69 00000000000i[CMOS ] Using local time for initial clock
 70 00000000000i[CMOS ] Setting initial clock to: Wed Nov 28 09:48:12 2012 (time0=1354067292)
 71 00000000000i[DMA  ] channel 4 used by cascade
 72 00000000000i[DMA  ] channel 2 used by Floppy Drive
 73 00000000000i[FDD  ] fd0: './boot.img' ro=0, h=2,t=80,spt=18
 74 00000000000i[MEM0 ] Register memory access handlers: 0x00000000000a0000 - 0x00000000000bffff
 75 00000000000i[XGUI ] test_alloc_colors: 16 colors available out of 16 colors tried
 76 00000000000i[XGUI ] font 8 wide x 16 high, display depth = 24
 77 00000000000i[VGA  ] interval=200000
 78 00000000000i[MEM0 ] Register memory access handlers: 0x00000000e0000000 - 0x00000000e0ffffff
 79 00000000000i[BXVGA] VBE Bochs Display Extension Enabled
 80 00000000000i[MEM0 ] rom at 0xc0000/41472 ('/usr/local/share/bochs/VGABIOS-lgpl-latest')
 81 00000000000i[     ] init_dev of 'unmapped' plugin device by virtual method
 82 00000000000i[     ] init_dev of 'biosdev' plugin device by virtual method
 83 00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
 84 00000000000i[SPEAK] Failed to open /dev/console: Resource temporarily unavailable
 85 00000000000i[SPEAK] Deactivating beep on console
 86 00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
 87 00000000000i[     ] init_dev of 'iodebug' plugin device by virtual method
 88 00000000000i[     ] init_dev of 'ioapic' plugin device by virtual method
 89 00000000000i[IOAP ] initializing I/O APIC
 90 00000000000i[MEM0 ] Register memory access handlers: 0x00000000fec00000 - 0x00000000fec00fff
 91 00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
 92 00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
 93 00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
 94 00000000000i[HD   ] Using boot sequence floppy, none, none
 95 00000000000i[HD   ] Floppy boot signature check is enabled
 96 00000000000i[     ] init_dev of 'serial' plugin device by virtual method
 97 00000000000i[SER  ] com1 at 0x03f8 irq 4
 98 00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
 99 00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
100 00000000000i[     ] register state of 'unmapped' plugin device by virtual method
101 00000000000i[     ] register state of 'biosdev' plugin device by virtual method
102 00000000000i[     ] register state of 'speaker' plugin device by virtual method
103 00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
104 00000000000i[     ] register state of 'iodebug' plugin device by virtual method
105 00000000000i[     ] register state of 'ioapic' plugin device by virtual method
106 00000000000i[     ] register state of 'keyboard' plugin device by virtual method
107 00000000000i[     ] register state of 'harddrv' plugin device by virtual method
108 00000000000i[     ] register state of 'serial' plugin device by virtual method
109 00000000000i[     ] register state of 'parallel' plugin device by virtual method
110 00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
111 00000000000i[CPU0 ] cpu hardware reset
112 00000000000i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x00000000fee00000
113 00000000000i[CPU0 ] CPUID[0x00000000]: 00000005 756e6547 6c65746e 49656e69
114 00000000000i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00000008 0fcbfbff
115 00000000000i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
116 00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
117 00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
118 00000000000i[CPU0 ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020
119 00000000000i[CPU0 ] CPUID[0x80000000]: 80000004 00000000 00000000 00000000
120 00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000000 00000000
121 00000000000i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
122 00000000000i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
123 00000000000i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
124 00000000000i[     ] reset of 'unmapped' plugin device by virtual method
125 00000000000i[     ] reset of 'biosdev' plugin device by virtual method
126 00000000000i[     ] reset of 'speaker' plugin device by virtual method
127 00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
128 00000000000i[     ] reset of 'iodebug' plugin device by virtual method
129 00000000000i[     ] reset of 'ioapic' plugin device by virtual method
130 00000000000i[     ] reset of 'keyboard' plugin device by virtual method
131 00000000000i[     ] reset of 'harddrv' plugin device by virtual method
132 00000000000i[     ] reset of 'serial' plugin device by virtual method
133 00000000000i[     ] reset of 'parallel' plugin device by virtual method
134 00000000000i[XGUI ] Mouse capture off
135 00000000000i[     ] set SIGINT handler to bx_debug_ctrlc_handler
136 Next at t=0
137 (0) [0x00000000fffffff0] f000:fff0 (unk. ctxt): jmp far f000:e05b         ; ea5be000f0
138 00000000000i[XGUI ] Mouse capture off
139 <bochs:1> c
140 00000004855i[BIOS ] $Revision: 10789 $ $Date: 2011-11-24 17:03:51 +0100 (Do, 24. Nov 2011) $
141 00000387568i[KBD  ] reset-disable command received
142 00000413342i[BIOS ] Starting rombios32
143 00000413789i[BIOS ] Shutdown flag 0
144 00000414399i[BIOS ] ram_size=0x08000000
145 00000414857i[BIOS ] ram_end=128MB
146 00000910945i[BIOS ] Found 1 cpu(s)
147 00000927199i[BIOS ] bios_table_addr: 0x000fbde8 end=0x000fcc00
148 00000939769i[BIOS ] bios_table_cur_addr: 0x000fbde8
149 00001067387i[VBIOS] VGABios $Id: vgabios.c,v 1.75 2011/10/15 14:07:21 vruppert Exp $

150 00001067458i[BXVGA] VBE known Display Interface b0c0
151 00001067490i[BXVGA] VBE known Display Interface b0c5
152 00001070415i[VBIOS] VBE Bios $Id: vbe.c,v 1.64 2011/07/19 18:25:05 vruppert Exp $
153 00010000003i[XGUI ] charmap update. Font Height is 16
154 00153230042i[BIOS ] Booting from 0000:7c00
155 00195623915i[CPU0 ] BOUND_GdMa: fails bounds test
156 00195623917i[CPU0 ] BOUND_GdMa: fails bounds test
157 00195623919i[CPU0 ] BOUND_GdMa: fails bounds test
158 00195623921i[CPU0 ] BOUND_GdMa: fails bounds test
159 00195623923i[CPU0 ] BOUND_GdMa: fails bounds test
160 00195623925i[CPU0 ] BOUND_GdMa: fails bounds test
161 00195623927i[CPU0 ] BOUND_GdMa: fails bounds test
162 00195623929i[CPU0 ] BOUND_GdMa: fails bounds test
163 00195623931i[CPU0 ] BOUND_GdMa: fails bounds test
164 00195623933i[CPU0 ] BOUND_GdMa: fails bounds test
165 00195623935i[CPU0 ] BOUND_GdMa: fails bounds test
166 00195623937i[CPU0 ] BOUND_GdMa: fails bounds test
167 Next at t=195652676
168 (0) [0x00000000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
169 00195652676i[XGUI ] Mouse capture off
170 <bochs:2> quit
171 00195652676i[     ] dbg: Quit
172 00195652676i[CPU0 ] CPU is in real mode (active)
173 00195652676i[CPU0 ] CS.mode = 16 bit
174 00195652676i[CPU0 ] SS.mode = 16 bit
175 00195652676i[CPU0 ] | EAX=0000fd06  EBX=00002486  ECX=00009048  EDX=00002300
176 00195652676i[CPU0 ] | ESP=0000fe52  EBP=00009000  ESI=0000e07d  EDI=00000000
177 00195652676i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf AF pf CF
178 00195652676i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
179 00195652676i[CPU0 ] |  CS:f000( 0004| 0|  0) 000f0000 0000ffff 0 0
180 00195652676i[CPU0 ] |  DS:5f1b( 0005| 0|  0) 0005f1b0 0000ffff 0 0
181 00195652676i[CPU0 ] |  SS:9000( 0005| 0|  0) 00090000 0000ffff 0 0
182 00195652676i[CPU0 ] |  ES:1000( 0005| 0|  0) 00010000 0000ffff 0 0
183 00195652676i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
184 00195652676i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
185 00195652676i[CPU0 ] | EIP=0000ff53 (00000459)
186 00195652676i[CPU0 ] | CR0=0x60000010 CR2=0x00000000
187 00195652676i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
188 (0).[195652676] [0x00000000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
189 00195652676i[CMOS ] Last time is 1354067295 (Wed Nov 28 09:48:15 2012)
190 00195652676i[XGUI ] Exit
191 00195652676i[CTRL ] quit_sim called with exit code 0
192  ]0;descent@w-linux: simple_os descent@w-linux:simple_os$ exit
193 
194 Script done on Wed 28 Nov 2012 09:48:18 AM CST

沒有留言:

張貼留言

使用 google 的 reCAPTCHA 驗證碼, 總算可以輕鬆留言了。

我實在受不了 spam 了, 又不想讓大家的眼睛花掉, 只好放棄匿名留言。這是沒辦法中的辦法了。留言的朋友需要有 google 帳號。