Bootsect. s code annotation

Source: Internet
Author: User

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! Sys_size is the number of nodes to be loaded (16 bytes are 1 segment ). 0x3000

! 0x30000 bytes = 192 KB (the preceding Linus estimation is incorrect). The current version space is sufficient.
5!
6 syssize = 0x3000! Size of the system module after compilation and connection. See section 1.2 In list 92nd.
! The maximum default value is given here.
7!
8! Bootsect. S (c) 1991 Linus Torvalds
9!
10! Bootsect. S is loaded at 0x7c00 by the BIOS-startup routines, and moves
11! The 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 shoshould be no
17! Problem, even in the future. I want to keep it simple. This 512 KB
18! Kernel size shoshould be enough, especially as this doesn't contain
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.
!
! The following is the translation of the preceding text:
! Bootsect. S (c) 1991 Linus Torvalds Copyright
!
! Bootsect. S is loaded to 0x7c00 (31 K) by BIOS-start subroutine, and
! Moved to the address 0x90000 (576 K) and jumped to it.
!
! It then uses a BIOS interrupt to directly load 'setup' to its own backend (0x90200) (576.5 K ),
! And load the system to the address 0x10000.
!
! Note! The maximum length of the current kernel system is (8*65536) (512 K) bytes, even in
! There should be no problems in the future. I want to keep it simple and clear. So the maximum kernel length of 512 K should be
! This is sufficient, especially because there is no buffer speed buffer as in Minix.
!
! Loading programs is simple enough, so continuous read errors will lead to an endless loop. Only manual restart is allowed.
! As long as possible, the loading process can be quickly done by obtaining all the slices at a time.
24
25. globl begtext, begdata, begbss, endtext, enddata, endbss! Six global identifiers are defined;
26. Text! Text Segment;
27 begtext:
28. Data! Data segment;
29 begdata:
30. BSS! Stack segment;
31 begbss:
32. Text! Text Segment;
33
34 setuplen = 4! NR of setup-sectors
! The value of setup-sectors;
35 bootseg = 0x07c0! Original address of boot-sector
! The original bootsect address (segment address, which is the same as the following );
36 initseg = 0x9000! We move boot here-out of the way
! Move bootsect here -- avoid;

37 setupseg = 0x9020! Setup starts here
! The setup program starts from here;
38 sysseg = 0x1000! System loaded at 0x10000 (65536 ).
! The system module is loaded to 0x10000 (64 KB;
39 endseg = sysseg + syssize! Where to stop loading
! The segment address to stop loading;
40
41! Root_dev: 0x000-same type of floppy as boot.
! The root file system device uses the same drive device as the boot device;
42! 0x301-first partition on first drive etc
! The root file system device is located in the first partition of the first hard disk, and so on;
43 root_dev = 0x306! The specified root file system device is 2nd partitions of 1st hard disks. This is the old Linux hard drive name.
! Method. The specific values are as follows:
! Device number = master device Number * 256 + sub-device number (I .e. dev_no = (Major <8) + minor)
! (Main device number: 1-memory, 2-disk, 3-hard disk, 4-ttyx, 5-tty, 6-parallel port, 7-non-Named Pipe)
! 0x300-/dev/hd0-represents the entire 1st hard disks;
! 0x301-/dev/hd1-1st partitions of 1st disks;
! ...
! 0x304-/dev/hd4-1st partitions of 4th disks;
! 0x305-/dev/hd5-represents the entire 2nd hard disk;
! 0x306-/dev/hd6-2nd partitions of 1st disks;
! ...
! 0x309-/dev/hd9-2nd partitions of 4th disks;
! The same naming method has been used since Linux kernel 0.95.
44
45 Entry start! Inform the Connection Program that the program starts to run from the start label.
46 start :! Line 47--56 is used to set itself (bootsect) from the current segment position 0x07c0 (31 K)
! Move to 0x9000 (576 K), a total of 256 words (512 bytes), and then jump
! After the code is moved, the Go mark, that is, the next statement of the program.
47 mov ax, # bootseg! Set the DS segment register to 0x7c0;
48 mov ds, ax
49 mov ax, # initseg! Set the es segment register to 0x9000;
50 mov es, ax
51 mov CX, #256! Move the Count value = 256 words;
52 sub si, si! Source Address DS: SI = 0x07c0: 0x0000
53 sub Di, Di! Target address es: di = 0x9000: 0x0000
54 rep! Repeat until Cx = 0
55 movw! Move 1 word;
56 jmpi go, initseg! Indirect jump. Here, initseg indicates the segment address to jump.
57 go: mov ax, CS! Set ds, es, and SS to the segment where the code is moved (0x9000 ).
58 mov ds, ax! Stack operations (push, Pop, call) must be set in the program.
59 mov es, ax
60! Put stack at 0x9ff00 .! Point the stack pointer SP to 0x9ff00 (0x9000: 0xff00 ).
61 mov SS, ax
62 mov sp, #0xff00! Arbitrary value> & gt; 512
! Because the code segment has been moved, you need to reset the position of the stack segment.
! SP points to a value greater than 512 offset (that is, address 0x90200 ).
! Yes. Because the setup program will be placed at the beginning of the 0x90200 address,
! At this time, the setup program has about 4 sectors, so the SP must point to a large
! At (0x200 + 0x200*4 + stack size.
63
64! Load the setup-sectors directly after the bootblock.
65! Note that 'els' is already set up.

! After the bootsect program block, the code data of the setup module is loaded.
! Note that ES has been set. (When moving the code, es has pointed to 0x9000 at the destination segment address ).
66
67 load_setup:
! Row 68--77 is used to interrupt the setup module from the first sector of the disk using the BIOS int 0x13
! Start to read from the beginning of 0x90200, and read 4 Sectors in total. If a read error occurs, reset the drive and
! Retry. Use int 0x13 as follows:
! Read sector:
! Ah = 0x02-read disk sectors to memory; Al = number of sectors to be read;
! Ch = low 8 bits of the track (cylindrical) number; CL = start sector (0-5 bits); high 2 bits (6-7 );
! DH = head number; dl = drive number (if it is a hard disk, it must be set to 7 );
! ES: BX

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.