30 day homemade Operating system reading notes (i)

Source: Internet
Author: User

At first, the author asked us to use the binary editor, hand-tapping 01 code to write an IMG (disk image file)

, and provides a number of files

Run.bat, Install.bat These one batch file, actually is writes the cmd instruction to save in the document, facilitates later executes.

Where Run.bat's instructions are like this.

Copy helloos.img. \z_tools\qemu\fdimage0.bin

.. \z_tools\make.exe-c. /z_tools/qemu

(A little explanation: the first line: copy instructions, helloos.img copied into the. \z_tools\qemu\fdimage0.bin one of them. \ represents the parent directory.

The second line uses the Make program-C: /z_tools/qemu represents the arguments passed to make. Specific what role is not known yet)

Then the Install.bat:

.. \z_tools\imgtol.com W a:helloos.img//This sentence is to write helloos.img on a floppy disk

(I will not, just Baidu's.) )

The author provides a virtual device, so in order to avoid trouble, I use the virtual device.

Oh, run.bat, the role of the virtual device is obvious, is to copy the disk image into the virtual directory and then start it.

Perhaps the author thinks the handwriting 01 code is too troublesome, so he switched to assembly code.

The compilation compiler Nask used in the book was developed by the author himself.

In the first assembly code, the author simply uses the DB directive, which represents the definition of a byte.

The author also felt that the code was too long and then used the RESB instruction.

Resb is an instruction to the editor, tell the editor how much space to empty, the author of the Nask editor, will automatically give an empty address to the 0x00, so the code length is much reduced!

Then the author unexpectedly a big jump, directly on even parents do not know the improved version of the code.

Just started a bunch of DB DW, the author called the standard FAT12 floppy disk code.

I don't know why I need this thing. Specifically Baidu has the following:

this completely data-composed code just conforms to the standard of a floppy boot sector

Well, I don't quite understand myself anyway, so I have a Baidu answer:

The boot sector is the No. 0 sector of the floppy disk, there is a very important data structure in this sector called BPB (BIOS Parameter Block), the following is the boot sector format, where Bpb_ is the beginning of the BPB, Bs_ beginning is only part of the boot sector, does not belong to BPB.

Name

Start byte

Length

Content

Reference values

Bs_jmpboot

0

3

A short jump instruction

JMP label_07c00h
Nop

Bs_oemname

3

8

Manufacturer name

' Qingfeng '

Bpb_bytespersec

11

2

Number of bytes per sector (Bytes/sector)

0x200

Bpb_secperclus

13

1

Number of sectors per cluster (Sector/cluster)

0x1

Bpb_resvdseccnt

14

2

How many sectors the boot record occupies

Ox1

Bpb_numfats

16

1

How many fat tables are there?

0x2

Bpb_rootentcnt

17

2

Maximum number of root zone files

0xE0

Bpb_totsec16

19

2

Total Sectors

0XB40[2*80*18]

Bpb_media

21st

1

Media descriptors

0xF0

Bpb_fatsz16

22

2

Number of sectors per fat table

0x9

Bpb_secpertrk

24

2

Number of sectors per track (Sector/track)

0x12

Bpb_numheads

26

2

Number of heads (number of faces)

0x2

Bpb_hiddsec

28

4

Number of hidden sectors

0

Bpb_totsec32

32

4

If bpb_totsec16=0, the number of sectors is given here

0

Bs_drvnum

36

1

The drive letter of the INT 13H

0

Bs_reserved1

37

1

Reserved, not used

0

Bs_bootsig

38

1

Extended boot tag (29h)

0x29

Bs_volid

39

4

Volume Serial Number

0

Bs_vollab

43

11

Volume label

' Qingfeng '

Bs_filesystype

54

8

File system type

' FAT12 '

Boot code and other content

62

448

Boot code and other data

Boot code (0 padding for remaining space)

End Flag 0xaa55

510

2

The No. 510 byte is 0x55, and the No. 511 byte is 0xAA

0xaa55

Oh! The original is the data structure. Called BIOS Parameter block (BIOS parameter block), then as the name implies? Perhaps it is for the BIOS read it!?

There is also an important $ symbol, the author explains very detailed, Bo master is lazy, so they do not type!

OK, there are only a few nouns left, read it by yourself.

A little summary of the less familiar points of knowledge:

1, ScanDisk is the first sector, 512 bytes is a sector. The last 2 bytes of a sector are

The name of the ScanDisk must be 8 bytes, not enough space to be padded.

2, IPL, start the program loader. The ScanDisk is only 512 bytes, so there is no operating system in this area,

So inside it is the program that loads the operating system itself.

3, DB definition byte type 1 byte, DW definition Word type 2 byte, DD definition double word class 4 bytes

Well, it's not too early, so let's go on the first day. Hey, hey, hey! That's such a long code, you do analysis Ah!

Not )

30 day homemade Operating system reading notes (i)

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.