Compare commits
10 Commits
de83ce2c58
...
528ab2becc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
528ab2becc | ||
|
|
f16fe745f2 | ||
|
|
f60929da69 | ||
|
|
5075504373 | ||
|
|
3a81b464c5 | ||
|
|
f2a26f8e83 | ||
|
|
cf4f2df43b | ||
|
|
d2dabadb14 | ||
|
|
9e8a511698 | ||
|
|
e6a8496959 |
17
README.adoc
17
README.adoc
@@ -16,6 +16,16 @@ link:{logo}[image:{logo}[]]
|
|||||||
|
|
||||||
toc::[]
|
toc::[]
|
||||||
|
|
||||||
|
== China
|
||||||
|
|
||||||
|
Before <<getting-started>>, read this important pre-requisite: https://github.com/cirosantilli/china-dictatorship
|
||||||
|
|
||||||
|
Because human rights is more important than profit and technology.
|
||||||
|
|
||||||
|
image::https://raw.githubusercontent.com/cirosantilli/china-dictatorship-media/master/Hao_Haidong_kick.jpg[width=600]
|
||||||
|
|
||||||
|
image::https://raw.githubusercontent.com/cirosantilli/china-dictatorship-media/master/Xi_sadomasochist.jpg[width=600]
|
||||||
|
|
||||||
== Getting started
|
== Getting started
|
||||||
|
|
||||||
First read this introduction: https://stackoverflow.com/questions/22054578/how-to-run-a-program-without-an-operating-system/32483545#32483545
|
First read this introduction: https://stackoverflow.com/questions/22054578/how-to-run-a-program-without-an-operating-system/32483545#32483545
|
||||||
@@ -1277,7 +1287,7 @@ Without segment manipulation, the output would be just: TODO
|
|||||||
|
|
||||||
===== Segmentation introduction
|
===== Segmentation introduction
|
||||||
|
|
||||||
First read the paging tutorial, and in particular: http://www.cirosantilli.com/x86-paging/#segmentation to get a feel for the type of register and data structure manipulation required to configure the CPU, and how segmentation compares to paging.
|
First read the paging tutorial, and in particular: https://cirosantilli.com/x86-paging#segmentation to get a feel for the type of register and data structure manipulation required to configure the CPU, and how segmentation compares to paging.
|
||||||
|
|
||||||
Segmentation modifies every memory access of a given segment by:
|
Segmentation modifies every memory access of a given segment by:
|
||||||
|
|
||||||
@@ -1485,7 +1495,7 @@ Try commenting out waking up the second processor and see it not get printed.
|
|||||||
|
|
||||||
==== Paging
|
==== Paging
|
||||||
|
|
||||||
Verbose beginner's tutorial: http://www.cirosantilli.com/x86-paging/
|
Verbose beginner's tutorial: https://cirosantilli.com/x86-paging
|
||||||
|
|
||||||
Change page tables and observe how that affects memory accesses:
|
Change page tables and observe how that affects memory accesses:
|
||||||
|
|
||||||
@@ -2311,6 +2321,7 @@ Almost entirely in C `-nostdlib`, with very few inline `asm` commands, and a sma
|
|||||||
* https://github.com/nanochess/fbird Flappy bird in the 512-byte boot sector.
|
* https://github.com/nanochess/fbird Flappy bird in the 512-byte boot sector.
|
||||||
* https://github.com/Overv/MineAssemble Minecraft
|
* https://github.com/Overv/MineAssemble Minecraft
|
||||||
* https://github.com/tsoding/pinpog Pong / Breakout
|
* https://github.com/tsoding/pinpog Pong / Breakout
|
||||||
|
* https://github.com/io12/bootmine Minesweeper game in a 512-byte boot sector.
|
||||||
|
|
||||||
=== Tutorials
|
=== Tutorials
|
||||||
|
|
||||||
@@ -2423,7 +2434,7 @@ A list of ARM bare metal resources can be found at: https://github.com/cirosanti
|
|||||||
|
|
||||||
== LICENSE
|
== LICENSE
|
||||||
|
|
||||||
Copyright Ciro Santilli http://www.cirosantilli.com/
|
Copyright Ciro Santilli https://cirosantilli.com
|
||||||
|
|
||||||
https://www.gnu.org/licenses/gpl-3.0.txt[GPL v3] for executable computer program usage.
|
https://www.gnu.org/licenses/gpl-3.0.txt[GPL v3] for executable computer program usage.
|
||||||
|
|
||||||
|
|||||||
22
common.h
22
common.h
@@ -212,8 +212,9 @@ protected_mode:
|
|||||||
mov %ebp, %esp
|
mov %ebp, %esp
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/* Setup a single page directory, which give us 2^10 * 2^12 == 4MiB
|
/* Setup the first Page Directory entry, which gives us a 4MB(2^10 * 2^12) memory region.
|
||||||
* of identity memory starting at address 0.
|
* The memory region starts at 0, and the virtual address and physical address are identical.
|
||||||
|
*
|
||||||
* The currently executing code is inside that range, or else we'd jump somewhere and die.
|
* The currently executing code is inside that range, or else we'd jump somewhere and die.
|
||||||
*/
|
*/
|
||||||
.equ page_directory, __end_align_4k
|
.equ page_directory, __end_align_4k
|
||||||
@@ -222,15 +223,15 @@ protected_mode:
|
|||||||
LOCAL page_setup_start page_setup_end
|
LOCAL page_setup_start page_setup_end
|
||||||
PUSH_EADX
|
PUSH_EADX
|
||||||
|
|
||||||
/* Page directory steup. */
|
/* Page Directory setup. */
|
||||||
/* Set the top 20 address bits. */
|
/* Set the top 20 address bits. */
|
||||||
mov $page_table, %eax
|
mov $page_table, %eax
|
||||||
/* Zero out the 4 low flag bits of the second byte (top 20 are address). */
|
/* Clear the low 12 bits of the first Page Directory entry. */
|
||||||
and $0xF000, %ax
|
and $0xF000, %ax
|
||||||
mov %eax, page_directory
|
/* Set the P, R/W, U/S, and A bits of the first Page Directory entry. */
|
||||||
/* Set flags for the first byte. */
|
|
||||||
mov $0b00100111, %al
|
mov $0b00100111, %al
|
||||||
mov %al, page_directory
|
/* Setup the first Page Directory entry. */
|
||||||
|
mov %eax, page_directory
|
||||||
|
|
||||||
/* Page table setup. */
|
/* Page table setup. */
|
||||||
mov $0, %eax
|
mov $0, %eax
|
||||||
@@ -241,14 +242,15 @@ page_setup_start:
|
|||||||
/* Top 20 address bits. */
|
/* Top 20 address bits. */
|
||||||
mov %eax, %edx
|
mov %eax, %edx
|
||||||
shl $12, %edx
|
shl $12, %edx
|
||||||
/* Set flag bits 0-7. We only set to 1:
|
/* For flag bits 0-7. We only set bit 0 and bit 1:
|
||||||
* * bit 0: Page present
|
* - bit 0: Page present
|
||||||
* * bit 1: Page is writable.
|
* - bit 1: Page is writable.
|
||||||
* Might work without this as the permission also depends on CR0.WP.
|
* Might work without this as the permission also depends on CR0.WP.
|
||||||
*/
|
*/
|
||||||
mov $0b00000011, %dl
|
mov $0b00000011, %dl
|
||||||
/* Zero flag bits 8-11 */
|
/* Zero flag bits 8-11 */
|
||||||
and $0xF0, %dh
|
and $0xF0, %dh
|
||||||
|
/* Setup the PTE(Page Table Entry). */
|
||||||
mov %edx, (%ebx)
|
mov %edx, (%ebx)
|
||||||
inc %eax
|
inc %eax
|
||||||
add $4, %ebx
|
add $4, %ebx
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* https://github.com/cirosantilli/x86-bare-metal-examples#ps-2-keyboard */
|
/* https://github.com/cirosantilli/x86-bare-metal-examples#ps2-keyboard */
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|||||||
13
paging.S
13
paging.S
@@ -1,4 +1,4 @@
|
|||||||
/* https://github.com/cirosantilli/x86-bare-metal-examples#paging.S */
|
/* https://github.com/cirosantilli/x86-bare-metal-examples#paging */
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@@ -14,8 +14,15 @@ BEGIN
|
|||||||
/* Print the canary to make sure it is really there. */
|
/* Print the canary to make sure it is really there. */
|
||||||
VGA_PRINT_HEX_4 0x1000
|
VGA_PRINT_HEX_4 0x1000
|
||||||
|
|
||||||
/* Make page 0 point to 4KiB. */
|
/* Make page 0 point to page frame 1(i.e. virtual address 0 points to physical address 4KB)
|
||||||
orb $0x10, page_table + 1
|
* by setting bit 12 of the Page Table Entry structure.
|
||||||
|
*
|
||||||
|
* At SETUP_PAGING_4M, page_table has been setup to
|
||||||
|
* point page frame 0(i.e. page 0 point to page frame 0).
|
||||||
|
* Bit 12 is the lowest bit of the "Address of 4KB page frame" field,
|
||||||
|
* By setting it, can relocate page 0 point to page frame 1.
|
||||||
|
*/
|
||||||
|
orw $0x1000, page_table
|
||||||
|
|
||||||
PAGING_ON
|
PAGING_ON
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user