bootsect.s

  1 !
  2 ! SYS_SIZE is the number of clicks (16 bytes) to be loaded.
  3 ! 0x3000 is 0x30000 bytes = 196kB, more than enough for current
  4 ! versions of linux
  5 !
  6 SYSSIZE = 0x3000
  7 !
  8 !    bootsect.s        (C) 1991 Linus Torvalds
  9 !
 10 ! bootsect.s is loaded at 0x7c00 by the bios-startup routines, and moves
 11 ! iself out of the way to address 0x90000, and jumps there.
 12 !
 13 ! It then loads ‘setup‘ directly after itself (0x90200), and the system
 14 ! at 0x10000, using BIOS interrupts.
 15 !
 16 ! NOTE! currently system is at most 8*65536 bytes long. This should be no
 17 ! problem, even in the future. I want to keep it simple. This 512 kB
 18 ! kernel size should be enough, especially as this doesn‘t contain the
 19 ! buffer cache as in minix
 20 !
 21 ! The loader has been made as simple as possible, and continuos
 22 ! read errors will result in a unbreakable loop. Reboot by hand. It
 23 ! loads pretty fast by getting whole sectors at a time whenever possible.
 24
 25 .globl begtext, begdata, begbss, endtext, enddata, endbss
 26 .text
 27 begtext:
 28 .data
 29 begdata:
 30 .bss
 31 begbss:
 32 .text
 33
 34 SETUPLEN = 4                ! nr of setup-sectors
 35 BOOTSEG  = 0x07c0            ! original address of boot-sector
 36 INITSEG  = 0x9000            ! we move boot here - out of the way
 37 SETUPSEG = 0x9020            ! setup starts here
 38 SYSSEG   = 0x1000            ! system loaded at 0x10000 (65536).
 39 ENDSEG   = SYSSEG + SYSSIZE        ! where to stop loading
 40
 41 ! ROOT_DEV:    0x000 - same type of floppy as boot.
 42 !        0x301 - first partition on first drive etc
 43 ROOT_DEV = 0x306
 44
 45 entry start
 46 start:
 47     mov    ax,#BOOTSEG
 48     mov    ds,ax
 49     mov    ax,#INITSEG
 50     mov    es,ax
 51     mov    cx,#256
 52     sub    si,si
 53     sub    di,di
 54     rep
 55     movw
 56     jmpi    go,INITSEG
 57 go:    mov    ax,cs
 58     mov    ds,ax
 59     mov    es,ax
 60 ! put stack at 0x9ff00.
 61     mov    ss,ax
 62     mov    sp,#0xFF00        ! arbitrary value >>512
 63
 64 ! load the setup-sectors directly after the bootblock.
 65 ! Note that ‘es‘ is already set up.
 66
 67 load_setup:
 68     mov    dx,#0x0000        ! drive 0, head 0
 69     mov    cx,#0x0002        ! sector 2, track 0
 70     mov    bx,#0x0200        ! address = 512, in INITSEG
 71     mov    ax,#0x0200+SETUPLEN    ! service 2, nr of sectors
 72     int    0x13            ! read it
 73     jnc    ok_load_setup        ! ok - continue
 74     mov    dx,#0x0000
 75     mov    ax,#0x0000        ! reset the diskette
 76     int    0x13
 77     j    load_setup
 78
 79 ok_load_setup:
 80
 81 ! Get disk drive parameters, specifically nr of sectors/track
 82
 83     mov    dl,#0x00
 84     mov    ax,#0x0800        ! AH=8 is get drive parameters
 85     int    0x13
 86     mov    ch,#0x00
 87     seg cs
 88     mov    sectors,cx
 89     mov    ax,#INITSEG
 90     mov    es,ax
 91
 92 ! Print some inane message
 93
 94     mov    ah,#0x03        ! read cursor pos
 95     xor    bh,bh
 96     int    0x10
 97
 98     mov    cx,#24
 99     mov    bx,#0x0007        ! page 0, attribute 7 (normal)
100     mov    bp,#msg1
101     mov    ax,#0x1301        ! write string, move cursor
102     int    0x10
103
104 ! ok, we‘ve written the message, now
105 ! we want to load the system (at 0x10000)
106
107     mov    ax,#SYSSEG
108     mov    es,ax        ! segment of 0x010000
109     call    read_it
110     call    kill_motor
111
112 ! After that we check which root-device to use. If the device is
113 ! defined (!= 0), nothing is done and the given device is used.
114 ! Otherwise, either /dev/PS0 (2,28) or /dev/at0 (2,8), depending
115 ! on the number of sectors that the BIOS reports currently.
116
117     seg cs
118     mov    ax,root_dev
119     cmp    ax,#0
120     jne    root_defined
121     seg cs
122     mov    bx,sectors
123     mov    ax,#0x0208        ! /dev/ps0 - 1.2Mb
124     cmp    bx,#15
125     je    root_defined
126     mov    ax,#0x021c        ! /dev/PS0 - 1.44Mb
127     cmp    bx,#18
128     je    root_defined
129 undef_root:
130     jmp undef_root
131 root_defined:
132     seg cs
133     mov    root_dev,ax
134
135 ! after that (everyting loaded), we jump to
136 ! the setup-routine loaded directly after
137 ! the bootblock:
138
139     jmpi    0,SETUPSEG
140
141 ! This routine loads the system at address 0x10000, making sure
142 ! no 64kB boundaries are crossed. We try to load it as fast as
143 ! possible, loading whole tracks whenever we can.
144 !
145 ! in:    es - starting address segment (normally 0x1000)
146 !
147 sread:    .word 1+SETUPLEN    ! sectors read of current track
148 head:    .word 0            ! current head
149 track:    .word 0            ! current track
150
151 read_it:
152     mov ax,es
153     test ax,#0x0fff
154 die:    jne die            ! es must be at 64kB boundary
155     xor bx,bx        ! bx is starting address within segment
156 rp_read:
157     mov ax,es
158     cmp ax,#ENDSEG        ! have we loaded all yet?
159     jb ok1_read
160     ret
161 ok1_read:
162     seg cs
163     mov ax,sectors
164     sub ax,sread
165     mov cx,ax
166     shl cx,#9
167     add cx,bx
168     jnc ok2_read
169     je ok2_read
170     xor ax,ax
171     sub ax,bx
172     shr ax,#9
173 ok2_read:
174     call read_track
175     mov cx,ax
176     add ax,sread
177     seg cs
178     cmp ax,sectors
179     jne ok3_read
180     mov ax,#1
181     sub ax,head
182     jne ok4_read
183     inc track
184 ok4_read:
185     mov head,ax
186     xor ax,ax
187 ok3_read:
188     mov sread,ax
189     shl cx,#9
190     add bx,cx
191     jnc rp_read
192     mov ax,es
193     add ax,#0x1000
194     mov es,ax
195     xor bx,bx
196     jmp rp_read
197
198 read_track:
199     push ax
200     push bx
201     push cx
202     push dx
203     mov dx,track
204     mov cx,sread
205     inc cx
206     mov ch,dl
207     mov dx,head
208     mov dh,dl
209     mov dl,#0
210     and dx,#0x0100
211     mov ah,#2
212     int 0x13
213     jc bad_rt
214     pop dx
215     pop cx
216     pop bx
217     pop ax
218     ret
219 bad_rt:    mov ax,#0
220     mov dx,#0
221     int 0x13
222     pop dx
223     pop cx
224     pop bx
225     pop ax
226     jmp read_track
227
228 /*
229  * This procedure turns off the floppy drive motor, so
230  * that we enter the kernel in a known state, and
231  * don‘t have to worry about it later.
232  */
233 kill_motor:
234     push dx
235     mov dx,#0x3f2
236     mov al,#0
237     outb
238     pop dx
239     ret
240
241 sectors:
242     .word 0
243
244 msg1:
245     .byte 13,10
246     .ascii "Loading system ..."
247     .byte 13,10,13,10
248
249 .org 508
250 root_dev:
251     .word ROOT_DEV
252 boot_flag:
253     .word 0xAA55
254
255 .text
256 endtext:
257 .data
258 enddata:
259 .bss
260 endbss:
时间: 2024-10-19 01:11:02

bootsect.s的相关文章

bootsect

*/--> pre.src {background-color: Black; color: White;} bootsect 全局变量 SYSSIZE = 0x3000 # nr of clicks (16 bytes) to be loaded. 0x3000 is 0x30000 bytes = 196kB SETUPLEN = 4 # nr of setup-sectors setup.s SETUPSEG = 0x9020 # setup starts here setup.s BOO

bootsect及setup

BIOS和bootsect CPU加电即进入16位实模式 硬件逻辑设计为加电瞬间强行设置:CS=0xF000,IP=0xFFF0,CS:IP=0xFFFF0 而BIOS程序的入口地址即0xFFFF0,是计算机上电后CPU执行的第一条指令的地址 BIOS程序在内存中加载中断向量表和中断服务程序 调用INT 0x19中断,将软盘第一扇区(0面0磁道1扇区)的512字节即bootsect.s加载到内存0x07C00处 bootsect.s将自身复制到0x90000~0x90200,ds:si -> e

操作系统开发之——一个简单的Bootsect

先吓唬一下读者朋友呵呵,直接发代码:(这是UOS操作系统的Bootsect)(有兴趣的朋友能够增加我们,联系方式在最后) ;------------------------------ ;文件名称:Bootsect.asm ;文件创建者:@Imcjy ;文件參与编辑者:@Imcjy ;文件编码:UTF-8 ;状态:O ;Build:3 ;文件创建日期:2015年7月24日 ;文件最后改动日期:2015年8月12日 ;备注:本文件为Nasm ;凝视等级:LV2 ;-----------------

linux0.12内核bootsect.S

这个文件就是0.12内核的主引导扇区代码,他的作用就是加载操作系统内核. 计算机加电,自检完毕后,BOIS就将启动设备的第一扇区加载到内存0x7c00(31KB)处,并开始从这里执行,若启动设备是硬盘的话,加载的即为该硬盘0磁道0柱面1扇区的内容,共512字节,以0xAA55为结束标志,这就是硬盘的MBR(master boot recorder). linux0.12内核bootsect.S中的代码编译后,将会写入启动设备的MBR中,它的主要工作加载操作系统内核的初始化程序setup.S和操作

Linux内核0.11 bootsect文件说明

一.总体功能介绍 这是关于Linux-kernel-0.11中boot文件夹下bootsect.s源文件的说明,其中涉及到了一些基础知识可以参考这两篇文章. 操作系统启动过程 软盘相关知识和通过BIOS中断访问软盘 bootsect.s 代码是磁盘引导块程序,存储在磁盘的第一个扇区中(0面0道1扇区),在计算机上电BIOS自检后,BIOS 会吧引导扇区代码bootsect加载到内存0x90000处开并运行. bootsect代码主要完成以下几项工作: 加载从磁盘第二个扇区开始的4个扇区的内容(由

linux学习(一)--启动文件bootsect.s

 这是linux由BIOS加载后执行的第一段的启动程序代码,即文件 boot/bootsect.s 1 .globl begtext, begdata, begbss, endtext, enddata, endbss 2 .text 3 begtext: 4 .data 5 begdata: 6 .bss 7 begbss: 8 .text 9 10 //规划内存,由BIOS执行 11 SETUPLEN = 4 ! nr of setup-sectors 12 BOOTSEG = 0x07c0

linux0.11的bootsect.s和setup.s

 1.计算机的启动 1.首先计算机的工作原理可以简单的概述为取指,执行:再取指,再执行:以此类推的过程,cpu就是一个不停取指执行不会休息的机器.  2.那么x86结构的计算机上电后是是怎么工作的呢?其实上电后(未加载操作系统代码之前)会先执行内存中一段为BIOS固化的区域,这段区域是每次开机都必须执行的,正常情况下不被我们所控,主要作用是对一些硬件环境做出检测,是否有硬件损坏.这段期间cpu处在实模式下工作.在BIOS代码执行完毕后,cpu会去磁盘的0磁道0扇区读取512字节到内存地址的0x7

操作系统--第一模块 bootsect.s

---------------------- 操作系统的第一段代码是 汇编代码,而不是C代码.C代码需要编译.编译中会产生很多乱七八糟的代码,int  i 也不可以控制在内存中的位置.而汇编语言可以. DS:SI    ES:DI  段寄存器一个是形不成地址的   rep movw 移动字,移动256个字,也就是512个字节,是把7C00处的代码移动到9W这个位置.腾出这段空间. jmpi    表示把go--->ip ,  INSERT--->CS BIOS  10 号中断. 在屏幕 rea

调试bootsect和setup和head到main

<bochs:1> b 0x0:0x7c00 <bochs:2> c (0) Breakpoint 1, 0x7c00 in ?? () Next at t=16165613 (0) [0x00007c00] 0000:7c00 (unk. ctxt): mov ax, 0x7c0             ; b8c007 <bochs:3> b 0x90200 <bochs:4> c (0) Breakpoint 2, 0x90200 in ?? () N