1. 程式人生 > >Minimum operating system with BOCHS

Minimum operating system with BOCHS

1.Envirment:

(see appendix Envriment create)

2.source


; 檔名 boot.asm
 
org 7c00h                     ; BIOS讀入MBR後,從0x7c00h處開始執行
 
; 下面部分和10h有關中斷,10h中斷用來顯示字元
mov ax, cs
mov es, ax
mov ax, msg
mov bp, ax                    ; ES:BP表示顯示字串的地址
mov cx, msgLen                ; CX存字元長度
mov ax, 1301h                 ; AH=13h表示向TTY顯示字元,AL=01h表示顯示方式(字串是否包含顯示屬性,01h表示不包含)
mov bx, 000fh                 ; BH=00h表示頁號,BL=0fh表示顏色
mov dl, 0                     ; 列
int 10h
  
msg: db "hello world, welcome to OS!"
msgLen: equ $ - msg           ; 字串長度
times 510 - ($ - $$) db 0     ; 填充剩餘部分
dw 0aa55h                     ; 魔數,必須有這兩個位元組BIOS才確認是MBR

3.Compile

If till not install nasm, should install first.

nasm install on ubuntu

2.tar zxvf nasm-2.10.07.tar.gz

進入剛解壓的目錄

然後執行命令:./configure

make

sudo make install

NOTE: Using "apt install nasm" to install is failled.

nasm usage

If only want to run without debugging, only input bellow:

# nasm boot.asm -o boot.bin

If want gdb can regcnise the format, should do more, convert it into ELF file format.

# nasm -f elf -g boot.asm -o boot.o

# gcc -c boot.o -o boot

If the gcc is bit32, should install some lib, as bellow:

sudo apt-get install g++-multilib libc6-dev-i386

then

# gcc boot.o -o boot -m32

4.Command line Debug

NOTE: Must copy the linux 0.11 project to windows disk, cannot in samba server, or not can't debug.

QEMU version: Download latest version from official site.

Input command:

"C:\Program Files\qemu\qemu-system-x86_64.exe" boot.bin
"C:\Program Files\qemu\qemu-system-x86_64.exe" -m 16M -boot a -fda boot.bin -s -S

-s              wait gdb connection to port 1234

'-S' means freeze CPU at startup (Can be remove to run directly), so you can debug step byt step.

After input the command, the linux 0.11 would be running succe

Open other cmd windows, then input:

F:\Linux-0.11-master>gdb Image

(gdb) target remote localhost:1234

(gdb) b *0x7c00

(gdb)c

(gdb)x /16b 0x7df0 //觀察0x7DFE和0x7DFF的值是否為0x55,0xAA

(gdb)

Then you would see the linux 0.11 is running successfully.

Can using "Ctrl+C" to stop running.

Appendix 1 Envriment create

1.VM-Envriment:windown 7, vmware(ubuntu-18.04.1-live-server-amd64.iso), SecureCRT(ssh remote ubuntu), samba-server(see appendix samba-server create).

2.Destnation-machine: BOCHS(download from official site),

3.Debug-method: TDMGCC(Using its GDB in command line debug).

Appendix 2 samba-server create

1首先確認網路可以相互ping通。

2終端輸入:apt-get install samba

3先備份 smb.conf 編輯配置,終端輸入:

cd /etc/samba/  

ls

cp smb.conf smb.conf-201x-xx-xx

4 nano /etc/samba/smb.conf 編輯配置檔案

  1. 找到[homes]browseable = no, 把no 改成 yes, 因為只有這樣,windows下才能通 過“計算機”看到“homes”共享目錄。----至此,您已經能看到samba共享的目錄了。
  2. 當然,以方便除錯為目的,所以我們不需要共享homes檔案,而是要共享整個根目錄。 所以在[homes]這一段下加入一段,不要在[homes]這一段改,否則出錯,一定要在下面加,如下:

[all]

comment = /

path = /

read only = no

接著在終端輸入:testparm 此命令不但能檢查引數是否正確,還能使配置立即生效, 不需要重啟。

5還要建立使用者,不然只能看到有共享卻無法登入。在終端輸入:

smbpasswd -a root 然後就會提示輸入密碼,其實這個名字可以任意,這裡用root是為 了方便記憶,因為我會用最高許可權。----到這一步,你就可以登入到samba共享檔案裡 了。

6(可以不要這一步)重啟samba,終端輸入: /etc/init.d/samba restart