Compare commits

..

4 Commits

Author SHA1 Message Date
Eric-Paul Ickhorn f0fcefc5eb
Add folder structure documentation for i386
As the project grows, it's a good idea to have an overview of the
project as a big picture. The newly added file will provide that big
picture for when the project is too big to read through for making a
small change. It contains unimplemented things in the described
folder structure (AHCI) as well as a documentation folder, which also
doesn't exist yet.
2024-08-17 19:04:18 +02:00
Eric-Paul Ickhorn c249510163
Fix bug in PCI driver with not saved registers
In the PCI driver's device enumeration function, there was a mistake
where a register that is being used in that function wasn't preserved
as it should've been. It didn't cause any errors (at least yet), but
it's better to fix such stuff once found.
2024-08-17 18:59:52 +02:00
Eric-Paul Ickhorn 459936de7a
Call driver setup function in protected entry
The driver manager's function for initializing all builtin drivers is
now being called in the 'stage2_protected_entry'-function, a function
that is called once the GDT is set up and calls all other functions
to get the system to boot.
2024-08-17 18:57:49 +02:00
Eric-Paul Ickhorn f73227fe74
Fix two syntax errors in ACPI utilities
The first one was a stray letter 'Z' somewhere in the source.
The second one was an error due to some changes being half-done; an
assembly label that did not yet exist was used.

Those two errors are fixed now.
2024-08-17 17:06:09 +02:00
5 changed files with 58 additions and 5 deletions

45
i386/folder-structure.md Normal file
View File

@ -0,0 +1,45 @@
# i386 Nightloader | Folder Structure
## Legacy BIOS bootsector (bootsector/)
Contains one file, the source of the bootsector. This assembly program
must span the first 512 byte of a legacy Nightloader-booted Partition.
## Legacy BIOS Edition (legacy-boot/)
This edition of the Nightloader is made for older devices that predate
UEFI (or potentially for devices that have unreliable UEFI-support).
This folder contains the assembly sources to create the loader
partition which contains raw machine code that is loaded by the
bootsector and to which the control is handed thereafter.
### Source Folder Structure
#### drivers/
- acpi
Driver for the Avanced Control and Power Interface.
- pci
Driver for the Peripheral Component Interconnect. This is used to
first find and then interact with the builtin devices in a computer,
mostly storage devices, but also network cards, USB keyboards, etc..
- ahci
Driver for AHCI, the ATA Host Controller Interface (ATA meaning
(IBM PC) AT Attachment), storage interface. This is used to interact
with practically every modern consumer SSD and HDD. Older HDDs might
use another interface, but that's not of elevated relevance.
#### memory/
Memory Management functions, A20 line check, GDT setup and, some day
in the future, paging for add-ons execution. This also contains utils
like the allocators (arena, pool) used throughout the bootloader.
#### utility/
Helper functions that make it easier to write the other functionality
but don't fall into any of the other categories on their own.
## Documentation (docs/)

View File

@ -53,7 +53,7 @@ acpi_enumerate_tables:
mov ebx, [esi + 8] mov ebx, [esi + 8]
add ebx, eax add ebx, eax
mov eax, [ebx]Z mov eax, [ebx]
inc ecx inc ecx
jmp .enumeration_loop jmp .enumeration_loop
@ -97,7 +97,7 @@ acpi_search_rsdt:
pop ebp pop ebp
cmp ax, 0 cmp ax, 0
jne .rsdp_found jne .resolve_rsdp
add ecx, 16 add ecx, 16
cmp ecx, 0x100000 cmp ecx, 0x100000
@ -105,6 +105,7 @@ acpi_search_rsdt:
; If no "RSD PTR "-signature could be found ; If no "RSD PTR "-signature could be found
xor ecx, ecx xor ecx, ecx
jmp .epilog
.resolve_rsdp: .resolve_rsdp:
; The 4-byte RSDT-pointer is at byte-offset 4 into the RSDP strucfture. ; The 4-byte RSDT-pointer is at byte-offset 4 into the RSDP strucfture.

View File

@ -34,7 +34,7 @@ initialize_pci_driver:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push dword PCI_DEVICE_COUNT_OFFSET
push dword 2 push dword 2
push dword 0 push dword 0
push dword 0 push dword 0

View File

@ -190,11 +190,12 @@ pci_enumerate_bus:
mov [esi + (64 - 8)], ebx mov [esi + (64 - 8)], ebx
mov [esi + (64 - 12)], ecx mov [esi + (64 - 12)], ecx
mov [esi + (64 - 16)], edx
mov [esi + (64 - 20)], edi mov [esi + (64 - 20)], edi
; [esi]: Device-in-bus Index ; [esi]: Device-in-bus Index
; [esi + 4]: Number of existing devices ; [esi + 4]: Number of existing devices
; [esi + 8]: Bus number ; [esi + 8]: Bus number
; [esi + 12]: ; [esi + 12]: PCI driver area pointer
mov [esi], dword 0 mov [esi], dword 0
mov [esi + 4], dword 0 mov [esi + 4], dword 0
mov eax, [ebp - 8] mov eax, [ebp - 8]
@ -259,6 +260,7 @@ pci_enumerate_bus:
.epilog: .epilog:
mov ebx, [esi + (64 - 8)] mov ebx, [esi + (64 - 8)]
mov ecx, [esi + (64 - 12)] mov ecx, [esi + (64 - 12)]
mov edx, [esi + (64 - 16)]
mov edi, [esi + (64 - 20)] mov edi, [esi + (64 - 20)]
mov eax, [esi + 4] mov eax, [esi + 4]
@ -313,7 +315,6 @@ pci_enumerate:
cmp edx, [ebp - 8] cmp edx, [ebp - 8]
jae .epilog jae .epilog
.call_bus_enumerator: .call_bus_enumerator:
push ebp push ebp
mov ebp, esp mov ebp, esp

View File

@ -54,6 +54,12 @@ stage_2_setup_entry:
bits 32 bits 32
stage2_protected_entry: stage2_protected_entry:
push ebp
mov ebp, esp
call setup_drivers
mov esp, ebp
pop ebp
cli cli
hlt hlt