SlideShare a Scribd company logo
1 of 17
Download to read offline
How Boot From Floppy Disk ?
AHashemB OS
By
Eng. Ahmed Hashem El Fiky
Network Security Engineer
Malware Analyst
Reference: http://sebastianmihai.com/main.php?t=128&n=Snowdrop...from...assembly-language
Boot
Sector
FAT 1 FAT 2 Root Directory Data Area
Floppy Disk
Each floppy disk consists of four logical parts—Boot Sector, File Allocation Table (FAT), Directory and Data space.
Boot Sector contains information about how the disk is organized. That is, how many sides does it contain, how
many tracks are there on each side, how many sectors are there per track, how many bytes are there per sector,
etc.
The files and the directories are stored in the Data Space.
The Directory contains information about the files like its attributes, name, size, etc
The FAT contains information about where the files and directories are stored in the data space.
the four logical parts of a 1.44 MB disk.
The boot sector contains two parts—‘Boot Parameters’ and ‘Disk Bootstrap Program’. The Boot Parameters
are useful while performing read/write operations on the disk.
Figure 19.6 shows the break up of the boot parameters for a floppy disk
The boot sector
Logical sector zero is known as the boot sector and contains all essential information regarding the layout of
information on the disk (see Figure 6). The first 3 bytes form an 8086 jump instruction, the destination of which is the
entry point of the bootstrap code at the end of the sector. If this disk is used to bootstrap the computer then sector
zero is read into memory and execution transferred to the bootstrap code via the jump. Following the jump
instruction is an 8 byte field which is used by the system manufacturer for an identification string.
Format of a directory entry
Loader Code that loaded Kernel File from Floppy Disk
to Memory at Location 0000h
Boot Sector (Logical Sector Zero)
jmp load_kernel
bpbOEM db “AHashemB"
bpbBytesPerSector: dw 512
bpbSectorsPerCluster: db 1
bpbReservedSectors: dw 1
bpbNumberOfFATs: db 2
bpbRootEntries: dw 224
bpbTotalSectors: dw 2880
bpbMedia: db 0F0h
bpbSectorsPerFAT: dw 9
bpbSectorsPerTrack: dw 18
bpbHeads: dw 2
bpbHiddenSectors: dd 0
bpbTotalSectorsBig: dd 0
bsDriveNumber: db 0
bsUnused: db 0
bsExtBootSignature: db 29h
bsSerialNumber: dd 538A538Ah
bsVolumeLabel: db “AHashemB OS"
bsFileSystem: db "FAT12 "
Loader code (that load Kernel File From Floppy Disk to Memory)
Notes of Load Kernel File In Memory
1- load Kernel File from Floppy Disk , How?
1.1 - search about kernel file Name in Root Directory entries (224 entry + each entry has
32-byte).
1.2 - if kernel file name exist, we need to read First Cluster of Kernel file at (26-27 byte)
from Root Directory Entry.
1.3 - Kernel File consists of many clusters in FAT 1 and FAT 2. The First Cluster that points
to next clusters is in Root Directory Entry (Kernel File Name).
1.4 - Now we will read cluster by cluster in FAT1 and FAT2 that consist of Kernel File.
1.5 - we have FAT1 (9 sectors) and FAT2 (9 sectors) . FAT1 is Logical Sector 1 where
bootsector is Logical sector 0.
1.6 - 0xFF8 - 0xFFF (Last cluster in file) FAT12.
1.7 - when read all clusters of Kernel File we will load kernel file in memory at location
0000h
BOOT_LOADER_SEGMENT equ 0000h
STACK_SEGMENT equ 1000h
KERNEL_SEGMENT equ 1000h
DISK_BUFFER_SEGMENT equ 2000h
bootDriveNumber: db 0
initialLoading: db 13, 10, “AHashemB OS loader is loading..", 13, 10, 0
floppyKernelNotFound: db "No kernel!", 0
floppyDriveError: db "Disk error!", 0
floppyDriveReset: db "reset!", 0
floppyDriveLoadingRoot: db ".directory", 13, 10, 0
floppyReadFat: db ".FAT", 13, 10, 0
floppyReadCluster: db ".clusters:", 0
floppyReadClusterIncrement: db "*", 0
kernelFileName: db “AHashemBKRN"
kernelCurrentCluster: dw 0
kernelDestinationPointer: dw 0
Declaration of Parameters
Load Kernel routines
1- load_root_directory routine.
2- find_root_directory_entry routine.
3- find_root_directory_entry_check_file routine.
4- find_root_directory_kernel_not_found routine.
5- find_root_directory_entry_found routine.
6- read_fat routine.
7- read_fat_success routine.
8- read_cluster_contents routine.
9- read_cluster_contents_perform routine.
10 - read_cluster_contents_success routine.
11- calculate_next_cluster routine.
12- cluster_is_odd routine.
13- cluster_is_even routine.
14- calculate_last_cluster routine.
15- transfer_control_to_kernel routine.
16- floppy_logical_to_physical routine.
17- reset_floppy routine.
18- reset_floppy_loop routine.
19- reset_floppy_success routine.
20- reset_floppy_failure routine.
21- halt_cpu routine.
22- debug_print_string routine.
23- debug_print_string_loop routine.
24- debug_print_string_end routine.
25- bootsector Signature.
Initialization Segments
load_kernel:
cld
push word BOOT_LOADER_SEGMENT
pop ds
mov byte [bootDriveNumber], dl
cli
mov ax, STACK_SEGMENT
mov ss, ax
mov ax, 0000h
mov sp, ax
sti
mov si, initialLoading
call debug_print_string
debug_print_string:
pusha
mov ah, 0Eh
mov bx, 0007h
debug_print_string_loop:
lodsb
cmp al, 0
je debug_print_string_end
int 10h
jmp debug_print_string_loop
debug_print_string_end:
popa
ret
load_root_directory:
mov si, floppyDriveLoadingRoot
call debug_print_string
mov ax, 19
call floppy_logical_to_physical
push word DISK_BUFFER_SEGMENT
pop es
mov bx, 0
mov ax, 020Eh
int 13h
jnc find_root_directory_entry
call reset_floppy
jmp load_root_directory
find_root_directory_entry:
mov di, 0
mov bx, [bpbRootEntries]
find_root_directory_entry_check_file:
push di
mov si, kernelFileName
mov cx, 11
repe cmpsb
jz find_root_directory_entry_found
dec bx
cmp bx, 0
je find_root_directory_kernel_not_found
pop di
add di, 32
jmp find_root_directory_entry_check_file
find_root_directory_kernel_not_found:
pop bx
mov si, floppyKernelNotFound
call debug_print_string
jmp halt_cpu
find_root_directory_entry_found:
pop di
mov ax, word [es:di+26]
mov word [kernelCurrentCluster], ax
halt_cpu:
cli
hlt
reset_floppy:
pusha
mov cx, 10
reset_floppy_loop:
mov si, floppyDriveReset
call debug_print_string
mov ah, 0
mov dl, byte [bootDriveNumber]
clc
int 13h
jnc reset_floppy_success
dec cx
jcxz reset_floppy_failure
jmp reset_floppy_loop
reset_floppy_success:
popa
ret
reset_floppy_failure:
mov si, floppyDriveError
call debug_print_string
floppy_logical_to_physical:
push ax
mov dx, 0
div word [bpbSectorsPerTrack]
inc dl
mov cl, dl
pop ax
mov dx, 0
div word [bpbSectorsPerTrack]
mov dx, 0
div word [bpbHeads]
mov dh, dl
mov ch, al
mov dl, byte [bootDriveNumber]
ret
read_fat:
mov si, floppyReadFat
call debug_print_string
mov ax, 1
call floppy_logical_to_physical
mov bx, 0
mov ax, 0212h
int 13h
jnc read_fat_success
call reset_floppy
jmp read_fat
read_fat_success:
push word KERNEL_SEGMENT
pop es
mov ax, word [kernelCurrentCluster]
mov si, floppyReadCluster
call debug_print_string
read_cluster_contents:
add ax, 31
read_cluster_contents_perform:
mov si, floppyReadClusterIncrement
call debug_print_string
push ax
call floppy_logical_to_physical
mov ax, 0201h
mov bx, [kernelDestinationPointer]
int 13h
jnc read_cluster_contents_success
call reset_floppy
pop ax
jmp read_cluster_contents_perform
read_cluster_contents_success:
pop ax
calculate_next_cluster:
mov ax, [kernelCurrentCluster]
mov bx, 3
mul bx
dec bx
push ds
push DISK_BUFFER_SEGMENT
pop ds
mov si, ax
mov ax, word [ds:si]
pop ds
dec dx
jnz cluster_is_even
cluster_is_odd:
shr ax, 4
jmp calculate_Last_cluster
cluster_is_even:
and ax, 0FFFh
calculate_Last_cluster:
mov word [kernelCurrentCluster], ax
cmp ax, 0FF8h
jae transfer_control_to_kernel
add word [kernelDestinationPointer], 512
jmp read_cluster_contents
transfer_control_to_kernel:
mov al, byte [bootDriveNumber]
jmp KERNEL_SEGMENT:0000
Part1 Finished

More Related Content

What's hot

101 2.1 design hard disk layout
101 2.1 design hard disk layout101 2.1 design hard disk layout
101 2.1 design hard disk layoutAcácio Oliveira
 
101 2.4 use debian package management
101 2.4 use debian package management101 2.4 use debian package management
101 2.4 use debian package managementAcácio Oliveira
 
Operating Systems: File Management
Operating Systems: File ManagementOperating Systems: File Management
Operating Systems: File ManagementDamian T. Gordon
 
Automating Disaster Recovery PostgreSQL
Automating Disaster Recovery PostgreSQLAutomating Disaster Recovery PostgreSQL
Automating Disaster Recovery PostgreSQLNina Kaufman
 
Logical volume manager xfs
Logical volume manager xfsLogical volume manager xfs
Logical volume manager xfsSarwar Javaid
 
Hadoop 20111215
Hadoop 20111215Hadoop 20111215
Hadoop 20111215exsuns
 
Root file system
Root file systemRoot file system
Root file systemBindu U
 
OSDC 2012 | Taking hot backups with XtraBackup by Alexey Kopytov
OSDC 2012 | Taking hot backups with XtraBackup by Alexey KopytovOSDC 2012 | Taking hot backups with XtraBackup by Alexey Kopytov
OSDC 2012 | Taking hot backups with XtraBackup by Alexey KopytovNETWAYS
 
Commands documentaion
Commands documentaionCommands documentaion
Commands documentaionTejalNijai
 
Linux fundamental - Chap 02 perm
Linux fundamental - Chap 02 permLinux fundamental - Chap 02 perm
Linux fundamental - Chap 02 permKenny (netman)
 
Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014
Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014
Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014Circling Cycle
 
Secondarystoragedevices1 130119040144-phpapp02
Secondarystoragedevices1 130119040144-phpapp02Secondarystoragedevices1 130119040144-phpapp02
Secondarystoragedevices1 130119040144-phpapp02Seshu Chakravarthy
 
Asm disk group migration from
Asm disk group migration from Asm disk group migration from
Asm disk group migration from Anar Godjaev
 
Hadoop spark performance comparison
Hadoop spark performance comparisonHadoop spark performance comparison
Hadoop spark performance comparisonarunkumar sadhasivam
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingZainab Almugbel
 
FreeBSD Jail Complete Example
FreeBSD Jail Complete ExampleFreeBSD Jail Complete Example
FreeBSD Jail Complete ExampleMohammed Farrag
 
Licão 06 process text streams with filters
Licão 06 process text streams with filtersLicão 06 process text streams with filters
Licão 06 process text streams with filtersAcácio Oliveira
 
AOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondAOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondZubair Nabi
 

What's hot (20)

101 2.1 design hard disk layout
101 2.1 design hard disk layout101 2.1 design hard disk layout
101 2.1 design hard disk layout
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
101 2.4 use debian package management
101 2.4 use debian package management101 2.4 use debian package management
101 2.4 use debian package management
 
Operating Systems: File Management
Operating Systems: File ManagementOperating Systems: File Management
Operating Systems: File Management
 
Automating Disaster Recovery PostgreSQL
Automating Disaster Recovery PostgreSQLAutomating Disaster Recovery PostgreSQL
Automating Disaster Recovery PostgreSQL
 
Logical volume manager xfs
Logical volume manager xfsLogical volume manager xfs
Logical volume manager xfs
 
Hadoop 20111215
Hadoop 20111215Hadoop 20111215
Hadoop 20111215
 
Root file system
Root file systemRoot file system
Root file system
 
OSDC 2012 | Taking hot backups with XtraBackup by Alexey Kopytov
OSDC 2012 | Taking hot backups with XtraBackup by Alexey KopytovOSDC 2012 | Taking hot backups with XtraBackup by Alexey Kopytov
OSDC 2012 | Taking hot backups with XtraBackup by Alexey Kopytov
 
Commands documentaion
Commands documentaionCommands documentaion
Commands documentaion
 
Linux fundamental - Chap 02 perm
Linux fundamental - Chap 02 permLinux fundamental - Chap 02 perm
Linux fundamental - Chap 02 perm
 
Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014
Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014
Hp ux-11iv3-multiple-clones-with-dynamic-root-disks-dusan-baljevic-mar2014
 
Secondarystoragedevices1 130119040144-phpapp02
Secondarystoragedevices1 130119040144-phpapp02Secondarystoragedevices1 130119040144-phpapp02
Secondarystoragedevices1 130119040144-phpapp02
 
Asm disk group migration from
Asm disk group migration from Asm disk group migration from
Asm disk group migration from
 
Hadoop spark performance comparison
Hadoop spark performance comparisonHadoop spark performance comparison
Hadoop spark performance comparison
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashing
 
FreeBSD Jail Complete Example
FreeBSD Jail Complete ExampleFreeBSD Jail Complete Example
FreeBSD Jail Complete Example
 
Upgrade & ndmp
Upgrade & ndmpUpgrade & ndmp
Upgrade & ndmp
 
Licão 06 process text streams with filters
Licão 06 process text streams with filtersLicão 06 process text streams with filters
Licão 06 process text streams with filters
 
AOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondAOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyond
 

Similar to Build Your OS Part1

An Insight into the Linux Booting Process
An Insight into the Linux Booting ProcessAn Insight into the Linux Booting Process
An Insight into the Linux Booting ProcessHardeep Bhurji
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsnullowaspmumbai
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209Tim Bunce
 
Introduction to filesystems and computer forensics
Introduction to filesystems and computer forensicsIntroduction to filesystems and computer forensics
Introduction to filesystems and computer forensicsMayank Chaudhari
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Tim Bunce
 
2.1 design hard disk layout v2
2.1 design hard disk layout v22.1 design hard disk layout v2
2.1 design hard disk layout v2Acácio Oliveira
 
101 2.1 design hard disk layout v2
101 2.1 design hard disk layout v2101 2.1 design hard disk layout v2
101 2.1 design hard disk layout v2Acácio Oliveira
 
Working with core dump
Working with core dumpWorking with core dump
Working with core dumpThierry Gayet
 
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...Mydbops
 
Linux booting process - Linux System Administration
Linux booting process - Linux System AdministrationLinux booting process - Linux System Administration
Linux booting process - Linux System AdministrationSreenatha Reddy K R
 
建構嵌入式Linux系統於SD Card
建構嵌入式Linux系統於SD Card建構嵌入式Linux系統於SD Card
建構嵌入式Linux系統於SD Card艾鍗科技
 
Live memory forensics
Live memory forensicsLive memory forensics
Live memory forensicsMehedi Hasan
 
Designing Information Structures For Performance And Reliability
Designing Information Structures For Performance And ReliabilityDesigning Information Structures For Performance And Reliability
Designing Information Structures For Performance And Reliabilitybryanrandol
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Bud Siddhisena
 

Similar to Build Your OS Part1 (20)

An Insight into the Linux Booting Process
An Insight into the Linux Booting ProcessAn Insight into the Linux Booting Process
An Insight into the Linux Booting Process
 
Linux Booting Steps
Linux Booting StepsLinux Booting Steps
Linux Booting Steps
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209
 
Introduction to filesystems and computer forensics
Introduction to filesystems and computer forensicsIntroduction to filesystems and computer forensics
Introduction to filesystems and computer forensics
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
 
101 1.2 boot the system
101 1.2 boot the system101 1.2 boot the system
101 1.2 boot the system
 
2.1 design hard disk layout v2
2.1 design hard disk layout v22.1 design hard disk layout v2
2.1 design hard disk layout v2
 
Linux boot process
Linux boot processLinux boot process
Linux boot process
 
101 2.1 design hard disk layout v2
101 2.1 design hard disk layout v2101 2.1 design hard disk layout v2
101 2.1 design hard disk layout v2
 
Working with core dump
Working with core dumpWorking with core dump
Working with core dump
 
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
 
Linux booting process - Linux System Administration
Linux booting process - Linux System AdministrationLinux booting process - Linux System Administration
Linux booting process - Linux System Administration
 
建構嵌入式Linux系統於SD Card
建構嵌入式Linux系統於SD Card建構嵌入式Linux系統於SD Card
建構嵌入式Linux系統於SD Card
 
Live memory forensics
Live memory forensicsLive memory forensics
Live memory forensics
 
Vmfs
VmfsVmfs
Vmfs
 
Designing Information Structures For Performance And Reliability
Designing Information Structures For Performance And ReliabilityDesigning Information Structures For Performance And Reliability
Designing Information Structures For Performance And Reliability
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)
 
5. boot process
5. boot process5. boot process
5. boot process
 
os
osos
os
 

More from Ahmed Hashem El Fiky

More from Ahmed Hashem El Fiky (7)

11 professional certificates
11 professional certificates11 professional certificates
11 professional certificates
 
FortiNet NSE 4 certificate
FortiNet NSE 4 certificateFortiNet NSE 4 certificate
FortiNet NSE 4 certificate
 
FortiNet NSE 2 certificate
FortiNet NSE 2 certificateFortiNet NSE 2 certificate
FortiNet NSE 2 certificate
 
FortiNet NSE 1 Certification
FortiNet NSE 1 CertificationFortiNet NSE 1 Certification
FortiNet NSE 1 Certification
 
Nexthink basics certification
Nexthink basics certificationNexthink basics certification
Nexthink basics certification
 
FortiWLC
FortiWLC FortiWLC
FortiWLC
 
Endpoint Security
Endpoint SecurityEndpoint Security
Endpoint Security
 

Recently uploaded

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 

Recently uploaded (20)

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

Build Your OS Part1

  • 1. How Boot From Floppy Disk ? AHashemB OS By Eng. Ahmed Hashem El Fiky Network Security Engineer Malware Analyst Reference: http://sebastianmihai.com/main.php?t=128&n=Snowdrop...from...assembly-language
  • 2. Boot Sector FAT 1 FAT 2 Root Directory Data Area Floppy Disk Each floppy disk consists of four logical parts—Boot Sector, File Allocation Table (FAT), Directory and Data space. Boot Sector contains information about how the disk is organized. That is, how many sides does it contain, how many tracks are there on each side, how many sectors are there per track, how many bytes are there per sector, etc. The files and the directories are stored in the Data Space. The Directory contains information about the files like its attributes, name, size, etc The FAT contains information about where the files and directories are stored in the data space.
  • 3. the four logical parts of a 1.44 MB disk.
  • 4. The boot sector contains two parts—‘Boot Parameters’ and ‘Disk Bootstrap Program’. The Boot Parameters are useful while performing read/write operations on the disk. Figure 19.6 shows the break up of the boot parameters for a floppy disk
  • 5. The boot sector Logical sector zero is known as the boot sector and contains all essential information regarding the layout of information on the disk (see Figure 6). The first 3 bytes form an 8086 jump instruction, the destination of which is the entry point of the bootstrap code at the end of the sector. If this disk is used to bootstrap the computer then sector zero is read into memory and execution transferred to the bootstrap code via the jump. Following the jump instruction is an 8 byte field which is used by the system manufacturer for an identification string.
  • 6. Format of a directory entry
  • 7. Loader Code that loaded Kernel File from Floppy Disk to Memory at Location 0000h
  • 8. Boot Sector (Logical Sector Zero) jmp load_kernel bpbOEM db “AHashemB" bpbBytesPerSector: dw 512 bpbSectorsPerCluster: db 1 bpbReservedSectors: dw 1 bpbNumberOfFATs: db 2 bpbRootEntries: dw 224 bpbTotalSectors: dw 2880 bpbMedia: db 0F0h bpbSectorsPerFAT: dw 9 bpbSectorsPerTrack: dw 18 bpbHeads: dw 2 bpbHiddenSectors: dd 0 bpbTotalSectorsBig: dd 0 bsDriveNumber: db 0 bsUnused: db 0 bsExtBootSignature: db 29h bsSerialNumber: dd 538A538Ah bsVolumeLabel: db “AHashemB OS" bsFileSystem: db "FAT12 " Loader code (that load Kernel File From Floppy Disk to Memory)
  • 9. Notes of Load Kernel File In Memory 1- load Kernel File from Floppy Disk , How? 1.1 - search about kernel file Name in Root Directory entries (224 entry + each entry has 32-byte). 1.2 - if kernel file name exist, we need to read First Cluster of Kernel file at (26-27 byte) from Root Directory Entry. 1.3 - Kernel File consists of many clusters in FAT 1 and FAT 2. The First Cluster that points to next clusters is in Root Directory Entry (Kernel File Name). 1.4 - Now we will read cluster by cluster in FAT1 and FAT2 that consist of Kernel File. 1.5 - we have FAT1 (9 sectors) and FAT2 (9 sectors) . FAT1 is Logical Sector 1 where bootsector is Logical sector 0. 1.6 - 0xFF8 - 0xFFF (Last cluster in file) FAT12. 1.7 - when read all clusters of Kernel File we will load kernel file in memory at location 0000h
  • 10. BOOT_LOADER_SEGMENT equ 0000h STACK_SEGMENT equ 1000h KERNEL_SEGMENT equ 1000h DISK_BUFFER_SEGMENT equ 2000h bootDriveNumber: db 0 initialLoading: db 13, 10, “AHashemB OS loader is loading..", 13, 10, 0 floppyKernelNotFound: db "No kernel!", 0 floppyDriveError: db "Disk error!", 0 floppyDriveReset: db "reset!", 0 floppyDriveLoadingRoot: db ".directory", 13, 10, 0 floppyReadFat: db ".FAT", 13, 10, 0 floppyReadCluster: db ".clusters:", 0 floppyReadClusterIncrement: db "*", 0 kernelFileName: db “AHashemBKRN" kernelCurrentCluster: dw 0 kernelDestinationPointer: dw 0 Declaration of Parameters
  • 11. Load Kernel routines 1- load_root_directory routine. 2- find_root_directory_entry routine. 3- find_root_directory_entry_check_file routine. 4- find_root_directory_kernel_not_found routine. 5- find_root_directory_entry_found routine. 6- read_fat routine. 7- read_fat_success routine. 8- read_cluster_contents routine. 9- read_cluster_contents_perform routine. 10 - read_cluster_contents_success routine. 11- calculate_next_cluster routine. 12- cluster_is_odd routine. 13- cluster_is_even routine. 14- calculate_last_cluster routine. 15- transfer_control_to_kernel routine. 16- floppy_logical_to_physical routine. 17- reset_floppy routine. 18- reset_floppy_loop routine. 19- reset_floppy_success routine. 20- reset_floppy_failure routine. 21- halt_cpu routine. 22- debug_print_string routine. 23- debug_print_string_loop routine. 24- debug_print_string_end routine. 25- bootsector Signature.
  • 12. Initialization Segments load_kernel: cld push word BOOT_LOADER_SEGMENT pop ds mov byte [bootDriveNumber], dl cli mov ax, STACK_SEGMENT mov ss, ax mov ax, 0000h mov sp, ax sti mov si, initialLoading call debug_print_string debug_print_string: pusha mov ah, 0Eh mov bx, 0007h debug_print_string_loop: lodsb cmp al, 0 je debug_print_string_end int 10h jmp debug_print_string_loop debug_print_string_end: popa ret
  • 13. load_root_directory: mov si, floppyDriveLoadingRoot call debug_print_string mov ax, 19 call floppy_logical_to_physical push word DISK_BUFFER_SEGMENT pop es mov bx, 0 mov ax, 020Eh int 13h jnc find_root_directory_entry call reset_floppy jmp load_root_directory find_root_directory_entry: mov di, 0 mov bx, [bpbRootEntries] find_root_directory_entry_check_file: push di mov si, kernelFileName mov cx, 11 repe cmpsb jz find_root_directory_entry_found dec bx cmp bx, 0 je find_root_directory_kernel_not_found pop di add di, 32 jmp find_root_directory_entry_check_file find_root_directory_kernel_not_found: pop bx mov si, floppyKernelNotFound call debug_print_string jmp halt_cpu find_root_directory_entry_found: pop di mov ax, word [es:di+26] mov word [kernelCurrentCluster], ax halt_cpu: cli hlt
  • 14. reset_floppy: pusha mov cx, 10 reset_floppy_loop: mov si, floppyDriveReset call debug_print_string mov ah, 0 mov dl, byte [bootDriveNumber] clc int 13h jnc reset_floppy_success dec cx jcxz reset_floppy_failure jmp reset_floppy_loop reset_floppy_success: popa ret reset_floppy_failure: mov si, floppyDriveError call debug_print_string floppy_logical_to_physical: push ax mov dx, 0 div word [bpbSectorsPerTrack] inc dl mov cl, dl pop ax mov dx, 0 div word [bpbSectorsPerTrack] mov dx, 0 div word [bpbHeads] mov dh, dl mov ch, al mov dl, byte [bootDriveNumber] ret
  • 15. read_fat: mov si, floppyReadFat call debug_print_string mov ax, 1 call floppy_logical_to_physical mov bx, 0 mov ax, 0212h int 13h jnc read_fat_success call reset_floppy jmp read_fat read_fat_success: push word KERNEL_SEGMENT pop es mov ax, word [kernelCurrentCluster] mov si, floppyReadCluster call debug_print_string read_cluster_contents: add ax, 31 read_cluster_contents_perform: mov si, floppyReadClusterIncrement call debug_print_string push ax call floppy_logical_to_physical mov ax, 0201h mov bx, [kernelDestinationPointer] int 13h jnc read_cluster_contents_success call reset_floppy pop ax jmp read_cluster_contents_perform read_cluster_contents_success: pop ax
  • 16. calculate_next_cluster: mov ax, [kernelCurrentCluster] mov bx, 3 mul bx dec bx push ds push DISK_BUFFER_SEGMENT pop ds mov si, ax mov ax, word [ds:si] pop ds dec dx jnz cluster_is_even cluster_is_odd: shr ax, 4 jmp calculate_Last_cluster cluster_is_even: and ax, 0FFFh calculate_Last_cluster: mov word [kernelCurrentCluster], ax cmp ax, 0FF8h jae transfer_control_to_kernel add word [kernelDestinationPointer], 512 jmp read_cluster_contents transfer_control_to_kernel: mov al, byte [bootDriveNumber] jmp KERNEL_SEGMENT:0000