You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Chapter-3/README.md
+55-2Lines changed: 55 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,63 @@ During the "Boot sequence", the BIOS will first choose the "boot device" (floopy
12
12
13
13
The BIOS will read the 512 bytes from the first valid bootsector (If the last two bytes are 0x55, and then 0xAA, then the BIOS considers this to be a valid bootsector), If the BIOS never finds a valid bootsector, it will lock up with an error message. And it'll transfer these 512 bytes into physical memory starting at address 0x7c00 then starts running the code that now begins at 0x7c00.
14
14
15
+
When the BIOS transfers control to the bootsector, the bootsector code is loaded and running at physical address 0x7c00 and the CPU is in 16-bit Real Mode but our kernel will be only 32bits so we need a bootloader to read our kernel switch to protected mode and starts running it.
16
+
15
17
#### What is GRUB?
16
18
17
19
> GNU GRUB (short for GNU GRand Unified Bootloader) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Free Software Foundation's Multiboot Specification, which provides a user the choice to boot one of multiple operating systems installed on a computer or select a specific kernel configuration available on a particular operating system's partitions.
18
20
19
-
To make it simple, Grub is the first thing booted by the machine (a boot-loader) and will simplify the loading of our kernel stored on the hard-disk.
21
+
To make it simple, GRUB is the first thing booted by the machine (a boot-loader) and will simplify the loading of our kernel stored on the hard-disk.
22
+
23
+
#### Why are we using GRUB?
24
+
25
+
* GRUB is very simple to use
26
+
* Make it very simple to load 32bits kernels without needs of 16bits code
27
+
* Multiboot with Linux, Windows and others
28
+
* Make it easy to laod external modules in memory
29
+
30
+
#### How to use GRUB?
31
+
32
+
GRUB use the Multiboot specification, the executable binary should be 32bits and must contains a special header (multiboot header) in its 8192 first bytes. Our kernel will be a ELF executable file ("Executable and Linkable Format", it is a common standard file format for executables in most UNIX system).
33
+
34
+
The first boot sequence of our kernel is written in Assembly: [start.asm](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/arch/x86/start.asm) and we use a linker file to define our executable structure: [linker.ld](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/arch/x86/linker.ld).
35
+
36
+
This boot process alse initialize some of our C++ runtime, it will be described in the next chapter.
37
+
38
+
Multiboot header structure:
39
+
40
+
```
41
+
struct multiboot_info {
42
+
u32 flags;
43
+
u32 low_mem;
44
+
u32 high_mem;
45
+
u32 boot_device;
46
+
u32 cmdline;
47
+
u32 mods_count;
48
+
u32 mods_addr;
49
+
struct {
50
+
u32 num;
51
+
u32 size;
52
+
u32 addr;
53
+
u32 shndx;
54
+
} elf_sec;
55
+
unsigned long mmap_length;
56
+
unsigned long mmap_addr;
57
+
unsigned long drives_length;
58
+
unsigned long drives_addr;
59
+
unsigned long config_table;
60
+
unsigned long boot_loader_name;
61
+
unsigned long apm_table;
62
+
unsigned long vbe_control_info;
63
+
unsigned long vbe_mode_info;
64
+
unsigned long vbe_mode;
65
+
unsigned long vbe_interface_seg;
66
+
unsigned long vbe_interface_off;
67
+
unsigned long vbe_interface_len;
68
+
};
69
+
```
70
+
71
+
#### See Also
20
72
21
-
#### Why are we using Grub?
73
+
*[GNU GRUB on wikipedia](http://en.wikipedia.org/wiki/GNU_GRUB)
0 commit comments