Skip to content

system table can get debug-formatted (including boot and runtime services) #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

phip1611
Copy link
Member

@phip1611 phip1611 commented Jul 2, 2021

Hey! This PR makes it possible to debug-format the UEFI system table. I'd love to see this functionality upstream. What do you think?

Example output (I can proof that it works in my QEMU setup)

UefiSystemTable {
    header: Header {
        signature: 6076298535811760713,
        revision: 2.7.0,
        size: 120,
        crc: 3701267086,
        _reserved: 0,
    },
    fw_vendor: "EDK II",
    fw_revision: 1.0.0,
    stdin_handle: Handle(
        0x000000000701a818,
    ),
    stdin: 0x0000000006de5b90,
    stdout_handle: Handle(
        0x0000000007019f18,
    ),
    stdout: 0x0000000006de5fd0,
    stderr_handle: Handle(
        0x0000000007018018,
    ),
    stderr: 0x0000000006de5a30,
    runtime: RuntimeServices {
        header: Header {
            signature: 6220110259551098194,
            revision: 2.7.0,
            size: 136,
            crc: 2242073619,
            _reserved: 0,
        },
        get_time: 0x0000000007abd56b,
        set_time: 0x0000000007abda01,
        set_virtual_address_map: 0x0000000007add013,
        reset: 0x0000000007ad7421,
    },
    boot: BootServices {
        header: Header {
            signature: 6220110259551162178,
            revision: 2.7.0,
            size: 376,
            crc: 4111088378,
            _reserved: 0,
        },
        raise_tpl (fn ptr): 0x0000000007eb05de,
        restore_tpl (fn ptr): 0x0000000007eb155a,
        allocate_pages (fn ptr): 0x0000000007eb490a,
        free_pages (fn ptr): 0x0000000007eb4826,
        get_memory_map (fn ptr): 0x0000000007eb70e2,
        allocate_pool (fn ptr): 0x0000000007eb4be2,
        free_pool (fn ptr): 0x0000000007eb4c5c,
        create_event (fn ptr): 0x0000000007eb2261,
        set_timer (fn ptr): 0x0000000007eb25b4,
        wait_for_event (fn ptr): 0x0000000007eb252e,
        signal_event: 132850730,
        close_event: 132861071,
        check_event: 132846796,
        install_protocol_interface: 132885880,
        reinstall_protocol_interface: 132890366,
        uninstall_protocol_interface: 132889596,
        handle_protocol (fn ptr): 0x0000000007ebaab2,
        register_protocol_notify: 132882914,
        locate_handle (fn ptr): 0x0000000007eb9f65,
        locate_device_path (fn ptr): 0x0000000007ebad9a,
        install_configuration_table: 132879987,
        load_image (fn ptr): 0x0000000007eb986e,
        start_image (fn ptr): 0x0000000007ebf541,
        exit: 132903955,
        unload_image (fn ptr): 0x0000000007ebe611,
        exit_boot_services (fn ptr): 0x0000000007eafe14,
        get_next_monotonic_count: 128680095,
        stall (fn ptr): 0x0000000007eb97db,
        set_watchdog_timer (fn ptr): 0x0000000007eb8b72,
        connect_controller: 132887446,
        disconnect_controller: 132883122,
        open_protocol: 132884407,
        close_protocol: 132881999,
        open_protocol_information: 132881682,
        protocols_per_handle: 132881409,
        locate_handle_buffer: 132882677,
        locate_protocol (fn ptr): 0x0000000007ebb2ab,
        install_multiple_protocol_interfaces: 132890020,
        uninstall_multiple_protocol_interfaces: 132889860,
        calculate_crc32: 128830808,
        copy_mem (fn ptr): 0x0000000007ea77d8,
        set_mem (fn ptr): 0x0000000007ea8258,
        create_event_ex: 132850204,
    },
    nf_cfg: 10,
    cfg_table: 0x00000000079eec98,
}

@GabrielMajeri
Copy link
Collaborator

Hmm, could you explain the motivation for such a change? Most of the contents of these tables are function pointers, what would be the use case for printing them out?

@phip1611 phip1611 force-pushed the debug-trait-for-system-table branch from c209a82 to c9ef2e9 Compare July 6, 2021 11:48
@phip1611
Copy link
Member Author

phip1611 commented Jul 6, 2021

Hey @GabrielMajeri,
At first I'd like to mention that I fixed the lint problems.
You are wondering, why this change is important? I have multiple reasons for that. At first I'm convinced that everything in the Rust ecosystem should be debug (except encryption-stuff) because there could be always a case where an information is relevant to someone. Also we are talking here about a few dozens lines of output and not thousands of verbose output. Currently I'm developing my first own Kernel/OS as part of a prototyping/exercise at my new Job. For the memory management, I think it's helpful to know the pointers so if things go wrong, I can quickly check if there was a memory corruption of some UEFI memory. Last but not least it's also just interesting out of curiosity where UEFI maps these functions.

I'm looking forward for your feedback.

@phip1611 phip1611 force-pushed the debug-trait-for-system-table branch 2 times, most recently from 8fcee21 to f10dbdb Compare July 19, 2021 08:46
@phip1611 phip1611 force-pushed the debug-trait-for-system-table branch from f10dbdb to 02ce9a3 Compare August 5, 2021 10:07
@phip1611
Copy link
Member Author

phip1611 commented Aug 5, 2021

Current debug format example:

UefiSystemTable {
    header: Header {
        signature: 0x0000000000000078,
        revision: 2.7.0,
        size: 120,
        crc: 149613055,
    },
    fw_vendor: CStr16(['E', 'D', 'K', ' ', 'I', 'I', '\u{0}']),
    fw_revision: 1.0.0,
    stdin_handle: Handle(
        0x0000000007294798,
    ),
    stdin: 0x00000000069ec3b0,
    stdout_handle: Handle(
        0x0000000007293518,
    ),
    stdout: 0x00000000069ec6b0,
    stderr_handle: Handle(
        0x0000000007292f98,
    ),
    stderr: 0x00000000069ec570,
    runtime: RuntimeServices {
        header: Header {
            signature: 0x0000000000000088,
            revision: 2.7.0,
            size: 136,
            crc: 3451577445,
        },
        get_time: 0x0000000007bb4641,
        set_time: 0x0000000007bb4a92,
        set_virtual_address_map: 0x0000000007bbf1f1,
        reset: 0x0000000007bbb27f,
    },
    boot: BootServices {
        header: Header {
            signature: 0x0000000000000178,
            revision: 2.7.0,
            size: 376,
            crc: 1265291667,
        },
        raise_tpl (fn ptr): 0x0000000007f1d421,
        restore_tpl (fn ptr): 0x0000000007f1eaff,
        allocate_pages (fn ptr): 0x0000000007f2222b,
        free_pages (fn ptr): 0x0000000007f22173,
        get_memory_map (fn ptr): 0x0000000007f204a2,
        allocate_pool (fn ptr): 0x0000000007f224d6,
        free_pool (fn ptr): 0x0000000007f22550,
        create_event (fn ptr): 0x0000000007f1efef,
        set_timer (fn ptr): 0x0000000007f20148,
        wait_for_event (fn ptr): 0x0000000007f200c2,
        signal_event: 0x0000000007f1ff45,
        close_event: 0x0000000007f23701,
        check_event: 0x0000000007f1ea71,
        install_protocol_interface: 0x0000000007f247d2,
        reinstall_protocol_interface: 0x0000000007f27f45,
        uninstall_protocol_interface: 0x0000000007f25a4a,
        handle_protocol (fn ptr): 0x0000000007f24474,
        register_protocol_notify: 0x0000000007f23ce5,
        locate_handle (fn ptr): 0x0000000007f23a9e,
        locate_device_path (fn ptr): 0x0000000007f24e44,
        install_configuration_table: 0x0000000007f2bcda,
        load_image (fn ptr): 0x0000000007f2d5bb,
        start_image (fn ptr): 0x0000000007f2d2d1,
        exit: 0x0000000007f2d1ec,
        unload_image (fn ptr): 0x0000000007f2d17e,
        exit_boot_services (fn ptr): 0x0000000007f1fdad,
        get_next_monotonic_count: 0x0000000007bb10b7,
        stall (fn ptr): 0x0000000007f282de,
        set_watchdog_timer (fn ptr): 0x0000000007f28252,
        connect_controller: 0x0000000007f2536d,
        disconnect_controller: 0x0000000007f23e14,
        open_protocol: 0x0000000007f241a8,
        close_protocol: 0x0000000007f239c2,
        open_protocol_information: 0x0000000007f238da,
        protocols_per_handle: 0x0000000007f23811,
        locate_handle_buffer: 0x0000000007f23bf8,
        locate_protocol (fn ptr): 0x0000000007f251c7,
        install_multiple_protocol_interfaces: 0x0000000007f25bed,
        uninstall_multiple_protocol_interfaces: 0x0000000007f25b4f,
        calculate_crc32: 0x0000000007bbf09f,
        copy_mem (fn ptr): 0x0000000007f2a0da,
        set_mem (fn ptr): 0x0000000007f2a677,
        create_event_ex: 0x0000000007f1efaa,
    },
    nf_cfg: 11,
    cfg_table: 0x0000000007beec98,
}

@phip1611 phip1611 requested a review from GabrielMajeri August 5, 2021 10:09
@GabrielMajeri
Copy link
Collaborator

Looks good, thank you!

@GabrielMajeri GabrielMajeri merged commit 8fbb126 into rust-osdev:master Aug 5, 2021
@phip1611 phip1611 deleted the debug-trait-for-system-table branch August 5, 2021 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants