add: documentation: memory
This commit is contained in:
parent
5fba376e2f
commit
04211e2773
72
README.md
72
README.md
@ -2,68 +2,10 @@
|
||||
|
||||
This project aims to explore how a kernel works by building our own, gaining hands-on experience with core concepts like memory management, interrupt, keyboard driver, etc
|
||||
|
||||
## INSTALLATION
|
||||
|
||||
### Cross compile the compile
|
||||
[THE DOCUMENTATION](https://wiki.osdev.org/GCC_Cross-Compiler)
|
||||
- install requirement follow [THE DOCUMENTATION](https://wiki.osdev.org/GCC_Cross-Compiler)
|
||||
- Setup the shell
|
||||
``` sh
|
||||
export PREFIX="$HOME/opt/cross"
|
||||
export TARGET=i386-elf
|
||||
export PATH="$PREFIX/bin:$PATH"
|
||||
mkdir $HOME/src
|
||||
cd $HOME/src
|
||||
```
|
||||
- Download [binutils](https://ftp.gnu.org/gnu/binutils/?C=M;O=D)
|
||||
- Download [gcc](https://ftp.gnu.org/gnu/gcc/?C=M;O=D)
|
||||
- Download [gdb](https://ftp.gnu.org/gnu/gdb/?C=M;O=D)
|
||||
- extract archives
|
||||
``` sh
|
||||
tar xf [your binutils archive]
|
||||
tar xf [your gcc archive]
|
||||
tar xf [your gdb archive]
|
||||
```
|
||||
- (protips use -j [nb core])
|
||||
- Compile binutils
|
||||
``` sh
|
||||
cd $HOME/src
|
||||
mkdir build-binutils
|
||||
|
||||
cd build-binutils
|
||||
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
|
||||
make
|
||||
make install
|
||||
```
|
||||
- Compile gdb
|
||||
``` sh
|
||||
cd $HOME/src
|
||||
mkdir build-gdb
|
||||
|
||||
cd build-gdb
|
||||
../gdb.x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-werror
|
||||
make all-gdb
|
||||
make install-gdb
|
||||
make
|
||||
make install
|
||||
```
|
||||
- Compile gcc
|
||||
``` sh
|
||||
cd $HOME/src
|
||||
|
||||
# The $PREFIX/bin dir _must_ be in the PATH. We did that above.
|
||||
which -- $TARGET-as || echo $TARGET-as is not in the PATH
|
||||
|
||||
mkdir build-gcc
|
||||
cd build-gcc
|
||||
../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
|
||||
make all-gcc
|
||||
make all-target-libgcc
|
||||
make install-gcc
|
||||
make install-target-libgcc
|
||||
```
|
||||
|
||||
### Compile and the start the kernel
|
||||
``` sh
|
||||
make run
|
||||
```
|
||||
## Currently supported
|
||||
- screen driver
|
||||
- keyboard driver
|
||||
- [memory pagination](./documentation/memory.md)
|
||||
- interruption
|
||||
- power management (reboot, halt, shutdown)
|
||||
- simple shell
|
73
documentation/installation.md
Normal file
73
documentation/installation.md
Normal file
@ -0,0 +1,73 @@
|
||||
# INSTALLATION
|
||||
|
||||
## Cross compile the compile
|
||||
|
||||
### WHY ??
|
||||
Why cross compile the gcc ?
|
||||
|
||||
We must cross compile gcc cause our kernel is developped for i386 cpu but your current cpu is probally not an i386 so we need to create an i386 compiler
|
||||
|
||||
### HOW ?
|
||||
|
||||
[THE DOCUMENTATION](https://wiki.osdev.org/GCC_Cross-Compiler)
|
||||
- install requirement follow [THE DOCUMENTATION](https://wiki.osdev.org/GCC_Cross-Compiler)
|
||||
- Setup the shell
|
||||
``` sh
|
||||
export PREFIX="$HOME/opt/cross"
|
||||
export TARGET=i386-elf
|
||||
export PATH="$PREFIX/bin:$PATH"
|
||||
mkdir $HOME/src
|
||||
cd $HOME/src
|
||||
```
|
||||
- Download [binutils](https://ftp.gnu.org/gnu/binutils/?C=M;O=D)
|
||||
- Download [gcc](https://ftp.gnu.org/gnu/gcc/?C=M;O=D)
|
||||
- Download [gdb](https://ftp.gnu.org/gnu/gdb/?C=M;O=D)
|
||||
- extract archives
|
||||
``` sh
|
||||
tar xf [your binutils archive]
|
||||
tar xf [your gcc archive]
|
||||
tar xf [your gdb archive]
|
||||
```
|
||||
- (protips use -j [nb core])
|
||||
- Compile binutils
|
||||
``` sh
|
||||
cd $HOME/src
|
||||
mkdir build-binutils
|
||||
|
||||
cd build-binutils
|
||||
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
|
||||
make
|
||||
make install
|
||||
```
|
||||
- Compile gdb
|
||||
``` sh
|
||||
cd $HOME/src
|
||||
mkdir build-gdb
|
||||
|
||||
cd build-gdb
|
||||
../gdb.x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-werror
|
||||
make all-gdb
|
||||
make install-gdb
|
||||
make
|
||||
make install
|
||||
```
|
||||
- Compile gcc
|
||||
``` sh
|
||||
cd $HOME/src
|
||||
|
||||
# The $PREFIX/bin dir _must_ be in the PATH. We did that above.
|
||||
which -- $TARGET-as || echo $TARGET-as is not in the PATH
|
||||
|
||||
mkdir build-gcc
|
||||
cd build-gcc
|
||||
../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
|
||||
make all-gcc
|
||||
make all-target-libgcc
|
||||
make install-gcc
|
||||
make install-target-libgcc
|
||||
```
|
||||
|
||||
## Compile and the start the kernel
|
||||
``` sh
|
||||
make run
|
||||
```
|
5
documentation/memory.md
Normal file
5
documentation/memory.md
Normal file
@ -0,0 +1,5 @@
|
||||
# MEMOMY
|
||||
|
||||
## Pagination
|
||||
|
||||
To activate pagination you must put the physic [pd](./memory/page_directory.md) address in the cr3 register and 0x80000000 in the cr0 register. Now the [MMU](./memory/mmu.md) will translate your address
|
3
documentation/memory/frame.md
Normal file
3
documentation/memory/frame.md
Normal file
@ -0,0 +1,3 @@
|
||||
# FRAME
|
||||
|
||||
Like [page](./page.md) but in physical memory space
|
19
documentation/memory/mmu.md
Normal file
19
documentation/memory/mmu.md
Normal file
@ -0,0 +1,19 @@
|
||||
# Memory Management Unit (MMU)
|
||||
The MMU is a chip which translate virtual memory to physical memory. When you try to access to an address (/!\ only when you try to access) the MMU will get the physical address from the [pd](./page_directory.md).
|
||||
|
||||
## How translate an address ?
|
||||
The address will be divid in 3 parts:
|
||||
- Page Directory index (10bit (cause 1024))
|
||||
- Page Table index (10bit (cause 1024 too))
|
||||
- offset (12bit cause page size = 4096)
|
||||
|
||||
### Example
|
||||
|
||||
**address**: 0b000100000011101011111011101101
|
||||
|
||||
| Base | PD index | PT index | offset |
|
||||
|--------|----------|------------|--------------|
|
||||
| Binary | 00010000 | 0011101011 | 111011101101 |
|
||||
| Decimal| 16 | 235 | 3821 |
|
||||
|
||||
So to translate this address the MMU will get the 20 first bit of the value store at the 235th PTE of the 16th PDE and will replace the 20 first bit of the virtually address.
|
3
documentation/memory/page.md
Normal file
3
documentation/memory/page.md
Normal file
@ -0,0 +1,3 @@
|
||||
# PAGE
|
||||
|
||||
A page is a memory space with with a specific size (default 4096byte).
|
7
documentation/memory/page_directory.md
Normal file
7
documentation/memory/page_directory.md
Normal file
@ -0,0 +1,7 @@
|
||||
# PAGE DIRECTORY
|
||||
|
||||
The page directory (or pd) is
|
||||
|
||||
|
||||
## Indexed Size
|
||||
A PD can store 1024 PT, each PT index 1024 * 4096Byte = 4MB of address, so a PD can index 1024 * 4MB = 4GB.
|
12
documentation/memory/page_table.md
Normal file
12
documentation/memory/page_table.md
Normal file
@ -0,0 +1,12 @@
|
||||
# PAGE TABLE
|
||||
|
||||
A page table (or PT) is an 1024 array of 32bit value(Page Table Entry (or PTE)). The address of the PT is store in the [PD](./page_directory.md).
|
||||
|
||||
## Page Table Entry (PTE)
|
||||
The value is a 20 first bits of the [frame](./frame.md) address and the 12 last bit is for the flag.
|
||||
|
||||
### Not used PTE value
|
||||
To say to the [MMU](./mmu.md) the page is currently not attribued to a frame you should put the (PTE index << 12)
|
||||
|
||||
## Indexed Size
|
||||
Cause our kernel use 4096byte page and a PT can store 1024 value, each PT index 1024 * 4096Byte = 4MB of address.
|
@ -36,6 +36,11 @@ void kernel_main(void)
|
||||
"I see no way to confuse an array of 256 seg:off pairs with a "
|
||||
"complex 8*unknown quantity -byte descriptor table. -- Troy "
|
||||
"Martin 03:50, 22 March 2009 (UTC)\n");
|
||||
while (true) {
|
||||
void *ptr = alloc_pages(4096);
|
||||
memset(ptr, ~0, 4096);
|
||||
PRINT_PTR(ptr);
|
||||
}
|
||||
/* int i = 0; */
|
||||
/* while (vmalloc(10)) */
|
||||
/* ; */
|
||||
|
Loading…
Reference in New Issue
Block a user