chore: remove useless file and trying refactor bootloader
This commit is contained in:
parent
fdd16ec651
commit
6d5cfb1669
|
@ -15,7 +15,7 @@
|
|||
| |
|
||||
0x008000 +-----------------------+
|
||||
| |
|
||||
| Boot0 |
|
||||
| bootsector |
|
||||
| |
|
||||
0x007000 +-----------------------+
|
||||
| |
|
||||
|
@ -23,7 +23,7 @@
|
|||
| |
|
||||
0x006000 +-----------------------+
|
||||
| |
|
||||
| Boot1 |
|
||||
| stpdldr.sys |
|
||||
| |
|
||||
0x001000 +-----------------------+
|
||||
| |
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
;; File: bios.inc
|
||||
|
||||
|
||||
;; Function: bios_print
|
||||
;;
|
||||
;; Parameters:
|
||||
;;
|
||||
;; si - null-terminated string to print
|
||||
;;
|
||||
bios_print:
|
||||
lodsb
|
||||
or al, al
|
||||
|
|
4
boot/common/protocol.inc
Normal file
4
boot/common/protocol.inc
Normal file
|
@ -0,0 +1,4 @@
|
|||
struct BootProtocol
|
||||
{
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
; File: bootia32.asm
|
||||
;; File: bootia32.asm
|
||||
format PE DLL EFI at 10000000h
|
||||
entry efimain
|
||||
|
||||
|
@ -8,9 +8,17 @@
|
|||
include '../common/macro.inc'
|
||||
include 'uefi.inc'
|
||||
|
||||
; ESP => return address
|
||||
; ESP + 4 => Handle
|
||||
; ESP + 8 => SysTable
|
||||
;; Function: efimain
|
||||
;;
|
||||
;; Parameters:
|
||||
;;
|
||||
;; [esp+4] - handle
|
||||
;; [esp+8] - <EFI_SYSTEM_TABLE>
|
||||
;;
|
||||
;; Returns:
|
||||
;;
|
||||
;; eax - efi status
|
||||
;;
|
||||
efimain:
|
||||
mov eax, [esp+4]
|
||||
mov [handle], eax
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
;; File: uefi.inc
|
||||
|
||||
struc BOOLEAN
|
||||
{
|
||||
. db ?
|
||||
|
@ -112,6 +114,7 @@ EFI_1_02_SYSTEM_TABLE_REVISION = ((1 shl 16) or (02))
|
|||
EFI_SYSTEM_TABLE_REVISION = EFI_2_90_SYSTEM_TABLE_REVISION
|
||||
EFI_SPECIFICATION_VERSION = EFI_SYSTEM_TABLE_REVISION
|
||||
|
||||
;; Struct: EFI_SYSTEM_TABLE
|
||||
struc EFI_SYSTEM_TABLE
|
||||
{
|
||||
.Hdr EFI_TABLE_HEADER
|
||||
|
|
4
boot/intro.txt
Normal file
4
boot/intro.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
File: Introduction
|
||||
|
||||
About: Legacy
|
||||
|
18
boot/loader/gdt.inc
Normal file
18
boot/loader/gdt.inc
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
gdt:
|
||||
; null descriptor
|
||||
dd 0
|
||||
dd 0
|
||||
|
||||
; code descriptor
|
||||
dw 0xFFFF, 0x0000
|
||||
db 0x00, 0x9a, 0xcf, 0x00
|
||||
|
||||
; data descriptor
|
||||
dw 0xFFFF, 0x0000
|
||||
db 0x00, 0x92, 0xcf, 0x00
|
||||
.end:
|
||||
|
||||
gdt_ptr:
|
||||
dw gdt.end - gdt - 1
|
||||
dd gdt
|
|
@ -15,10 +15,13 @@ multiboot_header:
|
|||
|
||||
_start:
|
||||
cmp eax, MULTIBOOT_MAGIC
|
||||
je .multiboot
|
||||
je multiboot
|
||||
|
||||
use16
|
||||
;; non multiboot process
|
||||
|
||||
; =========================================================================
|
||||
; real mode code
|
||||
; =========================================================================
|
||||
push cs
|
||||
pop ds
|
||||
|
||||
|
@ -31,12 +34,13 @@ _start:
|
|||
; detect memory
|
||||
call memory_get_map
|
||||
jc .error_memory
|
||||
xchg bx, bx
|
||||
|
||||
call video_setup
|
||||
|
||||
.multiboot:
|
||||
jmp .hang
|
||||
;cli
|
||||
;lgdt [gdt_ptr]
|
||||
;jmp 0x8:common32
|
||||
;jmp $
|
||||
|
||||
.error_memory:
|
||||
mov si, msg_error_memory
|
||||
|
@ -45,14 +49,15 @@ _start:
|
|||
mov si, msg_error_a20
|
||||
.error:
|
||||
call bios_print
|
||||
.hang:
|
||||
@@:
|
||||
hlt
|
||||
jmp $
|
||||
jmp @b
|
||||
|
||||
include 'a20.inc'
|
||||
include '../common/bios.inc'
|
||||
include 'memory.inc'
|
||||
include 'video.inc'
|
||||
include 'gdt.inc'
|
||||
|
||||
msg_stage2 db "StupidOS Bootloader (Stage 1)", CR, LF, 0
|
||||
msg_error_a20 db "ERROR: can't enable a20 line", CR, LF, 0
|
||||
|
@ -62,9 +67,33 @@ msg_error_memory db "ERROR: can't detect available memory", CR, LF, 0
|
|||
bi_screen_width: dw 0
|
||||
bi_screen_height: dw 0
|
||||
|
||||
use32
|
||||
; =========================================================================
|
||||
; protected mode code
|
||||
; =========================================================================
|
||||
multiboot:
|
||||
|
||||
common32:
|
||||
;mov bx, 0x0f01
|
||||
;mov word [eax], bx
|
||||
; paging
|
||||
; identity map first 1MB
|
||||
; map kernel to 0xC0000000
|
||||
|
||||
hang:
|
||||
hlt
|
||||
jmp $
|
||||
|
||||
_edata:
|
||||
|
||||
; BSS
|
||||
rb 0x4000
|
||||
align 4096
|
||||
boot_page_directory:
|
||||
rb 4096
|
||||
|
||||
boot_0_page_table:
|
||||
rb 4096
|
||||
|
||||
boot_768_page_table:
|
||||
rb 4096
|
||||
|
||||
_end:
|
||||
|
|
7
boot/loader/mmu.inc
Normal file
7
boot/loader/mmu.inc
Normal file
|
@ -0,0 +1,7 @@
|
|||
PE_PRESENT = (1 shl 0)
|
||||
PE_WRITABLE = (1 shl 1)
|
||||
PE_USERMODE = (1 shl 2)
|
||||
PE_ACCESSED = (1 shl 5)
|
||||
PE_DIRTY = (1 shl 6)
|
||||
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
video_setup:
|
||||
ret
|
||||
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
---
|
||||
title: pmap_bootstrap
|
||||
---
|
||||
flowchart TD
|
||||
|
||||
R_BEGIN("Begin")
|
||||
R_GETMMAP["Get Memory Map entry"]
|
||||
R_MMAP_LAST{"Last Item ?"}
|
||||
R_END("End")
|
||||
|
||||
subgraph "entry to pmap_block"
|
||||
C_BEGIN("Begin Proc")
|
||||
C_IS_FREE{"Is
|
||||
entry free?"}
|
||||
C_END("End Proc")
|
||||
C_OVERLAP_KERNEL{"entry
|
||||
overlap
|
||||
kernel?"}
|
||||
C_REMOVE_KRESERVED["Remove Kernel
|
||||
Memory from entry"]
|
||||
C_MEMORY_SIZE_EXCEED{"Is entry size
|
||||
larger than
|
||||
0x0x7f80000 ?"}
|
||||
C_MEMORY_SPLIT["Split entry"]
|
||||
C_MEMORY_LAST["Is last ?"]
|
||||
|
||||
C_BEGIN-->C_IS_FREE
|
||||
C_IS_FREE--No-->C_END
|
||||
C_IS_FREE--Yes-->C_OVERLAP_KERNEL
|
||||
C_OVERLAP_KERNEL--Yes-->C_REMOVE_KRESERVED
|
||||
C_REMOVE_KRESERVED-->C_MEMORY_SIZE_EXCEED
|
||||
C_OVERLAP_KERNEL--No-->C_MEMORY_SIZE_EXCEED
|
||||
C_MEMORY_SIZE_EXCEED--Yes-->C_MEMORY_SPLIT
|
||||
C_MEMORY_SPLIT-->C_MEMORY_LAST
|
||||
C_MEMORY_LAST--Yes-->C_END
|
||||
|
||||
end
|
||||
|
||||
subgraph "create & store pmap_block"
|
||||
D_BEGIN("Begin Proc")
|
||||
D_BOOSTRAP_EXIST{"Bootstrap
|
||||
pmap_block
|
||||
exist?"}
|
||||
D_SETUP_BOOTSTRAP["Setup bootstrap pmap"]
|
||||
D_END("End Proc")
|
||||
D_SET_HEAD_BOOTSTRAP["Set bootstrap as Head"]
|
||||
D_SEARCH_FREE_PAGE["Search free page in Head->bitmap"]
|
||||
D_FREE_PAGE_FOUND{"Free Page found ?"}
|
||||
D_HEAD_NEXT_NULL{"Head->next == NULL?"}
|
||||
D_HEAD_NEXT["Set Head to Head->next"]
|
||||
D_CREATE_PMAP["Create new pmap_block
|
||||
in free page"]
|
||||
D_APPEND_PMAP["Append pmap_block
|
||||
at end of
|
||||
linked list"]
|
||||
|
||||
D_BEGIN-->D_BOOSTRAP_EXIST
|
||||
D_BOOSTRAP_EXIST--No-->D_SETUP_BOOTSTRAP
|
||||
D_SETUP_BOOTSTRAP-->D_END
|
||||
D_BOOSTRAP_EXIST--Yes-->D_SET_HEAD_BOOTSTRAP
|
||||
D_SET_HEAD_BOOTSTRAP-->D_SEARCH_FREE_PAGE
|
||||
D_SEARCH_FREE_PAGE-->D_FREE_PAGE_FOUND
|
||||
D_FREE_PAGE_FOUND--No-->D_HEAD_NEXT_NULL
|
||||
D_HEAD_NEXT_NULL--No-->D_HEAD_NEXT
|
||||
D_HEAD_NEXT-->D_SEARCH_FREE_PAGE
|
||||
D_FREE_PAGE_FOUND--Yes-->D_CREATE_PMAP
|
||||
D_CREATE_PMAP-->D_APPEND_PMAP
|
||||
D_APPEND_PMAP-->D_END
|
||||
end
|
||||
|
||||
R_BEGIN-->R_GETMMAP
|
||||
R_GETMMAP-->R_MMAP_LAST
|
||||
R_MMAP_LAST--Yes-->R_END
|
||||
|
||||
R_MMAP_LAST--No-->C_BEGIN
|
||||
C_MEMORY_SIZE_EXCEED--No-->D_BEGIN
|
||||
D_END--Try get next-->C_MEMORY_LAST
|
||||
C_MEMORY_LAST--No-->D_BEGIN
|
||||
C_END--Try get next entry-->R_MMAP_LAST
|
||||
|
||||
|
||||
style R_BEGIN fill:#6CA300
|
||||
style R_END fill:#A30000
|
||||
|
||||
style C_BEGIN fill:#6CA300
|
||||
style C_END fill:#A30000
|
||||
|
||||
style D_BEGIN fill:#6CA300
|
||||
style D_END fill:#A30000
|
Binary file not shown.
Before Width: | Height: | Size: 93 KiB |
Loading…
Reference in a new issue