setup.s代碼注釋

來源:互聯網
上載者:User

1 !
2 ! setup.s (C) 1991 Linus Torvalds
3 !
4 ! setup.s is responsible for getting the system data from the BIOS,
5 ! and putting them into the appropriate places in system memory.
6 ! both setup.s and system has been loaded by the bootblock.
7 !
8 ! This code asks the bios for memory/disk/other parameters, and
9 ! puts them in a "safe" place: 0x90000-0x901FF, ie where the
10 ! boot-block used to be. It is then up to the protected mode
11 ! system to read them from there before the area is overwritten
12 ! for buffer-blocks.
!
! setup.s 負責從BIOS 中擷取系統資料,並將這些資料放到系統記憶體的適當地方。
! 此時setup.s 和system 已經由bootsect 引導塊載入到記憶體中。
!
! 這段代碼詢問bios 有關記憶體/磁碟/其它參數,並將這些參數放到一個
! “安全的”地方:0x90000-0x901FF,也即原來bootsect 代碼塊曾經在
! 的地方,然後在被緩衝塊覆蓋掉之前由保護模式的system 讀取。
13 !
14
15 ! NOTE! These had better be the same as in bootsect.s!

! 以下這些參數最好和bootsect.s 中的相同!
16
17 INITSEG = 0x9000 ! we move boot here - out of the way ! 原來bootsect 所處的段。
18 SYSSEG = 0x1000 ! system loaded at 0x10000 (65536). ! system 在0x10000(64k)處。
19 SETUPSEG = 0x9020 ! this is the current segment ! 本程式所在的段地址。
20
21 .globl begtext, begdata, begbss, endtext, enddata, endbss
22 .text
23 begtext:
24 .data
25 begdata:
26 .bss
27 begbss:
28 .text
29
30 entry start
31 start:
32
33 ! ok, the read went well so we get current cursor position and save it for
34 ! posterity.
! ok,整個讀磁碟過程都正常,現在將游標位置儲存以備今後使用。
35
36 mov ax,#INITSEG ! this is done in bootsect already, but...
! 將ds 置成#INITSEG(0x9000)。這已經在bootsect 程式中
! 設定過,但是現在是setup 程式,Linus 覺得需要再重新
! 設定一下。
37 mov ds,ax
38 mov ah,#0x03 ! read cursor pos
! BIOS 中斷0x10 的讀游標功能號 ah = 0x03
! 輸入:bh = 頁號
! 返回:ch = 掃描開始線,cl = 掃描結束線,
! dh = 行號(0x00 是頂端),dl = 列號(0x00 是左邊)。
39 xor bh,bh
40 int 0x10 ! save it in known place, con_init fetches
41 mov [0],dx ! it from 0x90000.
! 上兩句是說將游標位置資訊存放在0x90000 處,控制台
! 初始化時會來取。
42
43 ! Get memory size (extended mem, kB) ! 下面3 句取擴充記憶體的大小值(KB)。
! 是調用中斷0x15,功能號ah = 0x88
! 返回:ax = 從0x100000(1M)處開始的擴充記憶體大小(KB)。
! 若出錯則CF 置位,ax = 出錯碼。
44
45 mov ah,#0x88
46 int 0x15
47 mov [2],ax ! 將擴充記憶體數值存在0x90002 處(1 個字)。
48
49 ! Get video-card data: ! 下面這段用於取顯示卡當前顯示模式。
! 調用BIOS 中斷0x10,功能號 ah = 0x0f
! 返回:ah = 字元列數,al = 顯示模式,bh = 當前顯示頁。
! 0x90004(1 字)存放當前頁,0x90006 顯示模式,0x90007 字元列數。
50
51 mov ah,#0x0f

52 int 0x10
53 mov [4],bx ! bh = display page
54 mov [6],ax ! al = video mode, ah = window width
55
56 ! check for EGA/VGA and some config parameters ! 檢查顯示方式(EGA/VGA)並取參數。
! 調用BIOS 中斷0x10,附加功能選擇 -取方式資訊
! 功能號:ah = 0x12,bl = 0x10
! 返回:bh = 顯示狀態
! (0x00 - 彩色模式,I/O 連接埠=0x3dX)
! (0x01 - 單色模式,I/O 連接埠=0x3bX)
! bl = 安裝的顯示記憶體
! (0x00 - 64k, 0x01 - 128k, 0x02 - 192k, 0x03 = 256k)
! cx = 顯示卡特性參數(參見程式後的說明)。
57
58 mov ah,#0x12
59 mov bl,#0x10
60 int 0x10
61 mov [8],ax ! 0x90008 = ??
62 mov [10],bx ! 0x9000A = 安裝的顯示記憶體,0x9000B = 顯示狀態(彩色/單色)
63 mov [12],cx ! 0x9000C = 顯示卡特性參數。
64
65 ! Get hd0 data ! 取第一個硬碟的資訊(複製硬碟參數表)。
! 第1 個硬碟參數表的首地址竟然是中斷向量0x41 的向量值!而第2 個硬碟
! 參數表緊接第1 個表的後面,中斷向量0x46 的向量值也指向這第2 個硬碟
! 的參數表首址。表的長度是16 個位元組(0x10)。
! 下面兩段程式分別複製BIOS 有關兩個硬碟的參數表,0x90080 處存放第1 個
! 硬碟的表,0x90090 處存放第2 個硬碟的表。
66
67 mov ax,#0x0000
68 mov ds,ax
69 lds si,[4*0x41] ! 取中斷向量0x41 的值,也即hd0 參數表的地址

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.