Skip to content

Mallocation #30

Open
Open

Description

@Sploder12

Memory management!

Querying the BIOS to know what memory is available must be done to know what memory we have.
Once that is done, an allocator can be made using the free regions.

This will be difficult, and despite sharing the same concept of CSE220's malloc project,
it will be nothing like that project.

The OS should do all the bookkeeping itself (also unlike CSE 220's malloc).
It is recommended that allocation occurs in 4KiB blocks (pages).

Activity

  1. self-assigned this
    on Apr 21, 2023
  2. emilkovacev commented on Sep 30, 2023

    @emilkovacev
    Member

    Ok, so I'm a bit stumped - I've been stuck on this issue for a while, in particular trying to get the 0x15 eax=0xe820 bios interrupt to work. I am executing the bios call right before the bootloader, in an attempt to detect upper segments of memory that are useable. It seems that in the following snippet of code (most of which is referenced from osdev.org):

    Here's my fork

    [bits 16]
    detect_mem:
    	mov di, 0x8004
    	xor ebx, ebx
    	xor bp, bp
    	mov edx, 0x534D4150
    	mov eax, 0xe820
    	mov [es:di + 20], dword 1 ; force a valid ACPI 3.X entry
    	mov ecx, 24 ; ask for 24 bytes
    	int 0x15
    

    The line with mov edx, 0x534D4150 seems to be crashing, before the instruction is even made (or if it is made at all). My guess is either that it's overriding a register either from the 0x13 interrupt or for something down the line that isn't reset. Are there any calls that depend on a specific value for edx that I can set it back to later?

    This is my first exposure to writing code in a bootloader, so I'm really enjoying this :)

  3. Sploder12 commented on Sep 30, 2023

    @Sploder12
    MemberAuthor

    On my machine the crash appears to come from executing garbage memory (It jumps to 0x1000 [_start] and proceeds to NOP slide a great distance [gdb displays zeros as add %al(%eax)] ). I agree with your suspicion, It seems some registers that aren't explicitly set for int 0x13 are being changed here (ES:BX maybe? Definitely dl) which is causing the OS to load somewhere in the aether (if at all).

    ^^^ for historical purposes (forgive me, it's late at night)

    Yes, your suspicion is correct. dl needs to be reset.

    Luckily dl is preserved in [BOOT_DRIVE] already!

  4. emilkovacev commented on Oct 19, 2023

    @emilkovacev
    Member

    Just an update: I'm able to get the first few hundred kilobytes mapped! I was able to verify the mapping using gdb, and I am working on getting it to work for many mappings. I believe we talked about using bitmaps, so I think I can get a simple page allocator in a week or so!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions