From c9537bc5c131ce8099dafe83941989731a377784 Mon Sep 17 00:00:00 2001 From: Philippe Aubertin <39178965+phaubertin@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:39:46 -0500 Subject: [PATCH] Clean up system address map definitions (#95) * Rename/rework/clean up definitions related to system memory map to align with ACPI. * Rename `GET_USER_MEMORY` system call to `GET_ADDRESS_MAP` and be more consistent with naming. Unrelated cleanup: * Ensure there are no remaining tabs use for indentation. * Make sure no source file is set executable. --- doc/Doxyfile | 0 doc/init-process.md | 6 +- doc/layout.md | 2 +- doc/syscalls/README.md | 2 +- doc/syscalls/get-address-map.md | 107 ++++++++++++++ doc/syscalls/get-user-memory.md | 76 ---------- include/assert.h | 0 include/ctype.h | 0 include/errno.h | 0 include/internals.h | 0 include/inttypes.h | 0 include/jinue/jinue.h | 4 +- include/jinue/shared/asm/memtype.h | 62 ++++++++ include/jinue/shared/asm/syscalls.h | 6 +- include/jinue/shared/types.h | 14 +- include/kernel/application/syscalls.h | 2 +- include/kernel/domain/services/panic.h | 0 .../infrastructure/acpi/asm/addrmap.h} | 24 +-- .../e820.h => infrastructure/acpi/types.h} | 26 +++- .../kernel/infrastructure/i686/drivers/acpi.h | 12 -- .../kernel/infrastructure/i686/drivers/vga.h | 0 include/kernel/infrastructure/i686/isa/abi.h | 0 include/kernel/infrastructure/i686/isa/io.h | 0 include/kernel/infrastructure/i686/memory.h | 2 +- include/kernel/infrastructure/i686/types.h | 6 - include/kernel/interface/i686/asm/boot.h | 14 +- include/kernel/interface/i686/asm/bootinfo.h | 8 +- .../kernel/interface/i686/asm/exceptions.h | 0 include/kernel/interface/i686/asm/idt.h | 0 include/kernel/interface/i686/asm/irq.h | 0 include/kernel/interface/i686/boot.h | 0 include/kernel/interface/i686/types.h | 43 +++--- include/kernel/machine/acpi.h | 1 - include/kernel/machine/memory.h | 2 +- include/stdarg.h | 0 include/stdbool.h | 0 include/stddef.h | 0 include/stdint.h | 0 include/string.h | 0 include/sys/auxv.h | 0 include/sys/elf.h | 76 +++++----- include/tar.h | 0 include/unistd.h | 0 kernel/Makefile | 2 +- .../{get_user_memory.c => get_address_map.c} | 4 +- kernel/infrastructure/i686/drivers/acpi.c | 1 + .../infrastructure/i686/drivers/iodelay.asm | 0 kernel/infrastructure/i686/drivers/vga.c | 0 kernel/infrastructure/i686/isa/abi.asm | 0 kernel/infrastructure/i686/isa/io.asm | 0 kernel/infrastructure/i686/memory.c | 109 ++++++++------ kernel/interface/i686/ld/image.lds | 0 kernel/interface/i686/setup16.asm | 138 +++++++++--------- kernel/interface/i686/setup32.asm | 104 +++++++------ kernel/interface/syscalls.c | 24 +-- userspace/lib/jinue/syscalls.c | 8 +- userspace/lib/libc/physmem.c | 31 ++-- userspace/loader/loader.c | 10 +- userspace/loader/ramdisk.c | 6 +- userspace/loader/ramdisk.h | 2 +- userspace/loader/utils.c | 2 +- userspace/loader/utils.h | 2 +- userspace/testapp/debug.c | 58 +++++--- userspace/testapp/debug.h | 2 +- userspace/testapp/testapp.c | 2 +- 65 files changed, 577 insertions(+), 423 deletions(-) mode change 100755 => 100644 doc/Doxyfile create mode 100644 doc/syscalls/get-address-map.md delete mode 100644 doc/syscalls/get-user-memory.md mode change 100755 => 100644 include/assert.h mode change 100755 => 100644 include/ctype.h mode change 100755 => 100644 include/errno.h mode change 100755 => 100644 include/internals.h mode change 100755 => 100644 include/inttypes.h create mode 100644 include/jinue/shared/asm/memtype.h mode change 100755 => 100644 include/kernel/domain/services/panic.h rename include/{jinue/shared/asm/memory.h => kernel/infrastructure/acpi/asm/addrmap.h} (75%) rename include/kernel/{interface/i686/asm/e820.h => infrastructure/acpi/types.h} (73%) mode change 100755 => 100644 mode change 100755 => 100644 include/kernel/infrastructure/i686/drivers/vga.h mode change 100755 => 100644 include/kernel/infrastructure/i686/isa/abi.h mode change 100755 => 100644 include/kernel/infrastructure/i686/isa/io.h mode change 100755 => 100644 include/kernel/interface/i686/asm/boot.h mode change 100755 => 100644 include/kernel/interface/i686/asm/bootinfo.h mode change 100755 => 100644 include/kernel/interface/i686/asm/exceptions.h mode change 100755 => 100644 include/kernel/interface/i686/asm/idt.h mode change 100755 => 100644 include/kernel/interface/i686/asm/irq.h mode change 100755 => 100644 include/kernel/interface/i686/boot.h mode change 100755 => 100644 include/stdarg.h mode change 100755 => 100644 include/stdbool.h mode change 100755 => 100644 include/stddef.h mode change 100755 => 100644 include/stdint.h mode change 100755 => 100644 include/string.h mode change 100755 => 100644 include/sys/auxv.h mode change 100755 => 100644 include/tar.h mode change 100755 => 100644 include/unistd.h rename kernel/application/syscalls/{get_user_memory.c => get_address_map.c} (94%) mode change 100755 => 100644 kernel/infrastructure/i686/drivers/iodelay.asm mode change 100755 => 100644 kernel/infrastructure/i686/drivers/vga.c mode change 100755 => 100644 kernel/infrastructure/i686/isa/abi.asm mode change 100755 => 100644 kernel/infrastructure/i686/isa/io.asm mode change 100755 => 100644 kernel/interface/i686/ld/image.lds mode change 100755 => 100644 kernel/interface/i686/setup16.asm diff --git a/doc/Doxyfile b/doc/Doxyfile old mode 100755 new mode 100644 diff --git a/doc/init-process.md b/doc/init-process.md index 51776bda..64cc2c28 100644 --- a/doc/init-process.md +++ b/doc/init-process.md @@ -230,7 +230,7 @@ An empty message with message number 4096 (JINUE_MSG_GET_MEMINFO) allows the initial process to request information from the loader regarding memory it has used to extract the initial RAM disk and for the initial process itself. This information should be used alongside -the information from the [GET_USER_MEMORY](syscalls/get-user-memory.md) +the information from the [GET_ADDRESS_MAP](syscalls/get-address-map.md) system call to determine what memory is available for use. Note the loader does not report information about memory it itself is @@ -296,7 +296,7 @@ The memory information structure contains the following members: As long as the loader has exited, the initial process is free to allocate memory anywhere that is described as user memory by the kernel -memory map (see the [GET_USER_MEMORY](syscalls/get-user-memory.md) +memory map (see the [GET_ADDRESS_MAP](syscalls/get-address-map.md) system call) and that is not identified as in use by one of the segment structures. It is also free to either map the extracted RAM disk for its own use or instead reclaim that memory. However, early in its @@ -330,7 +330,7 @@ Segments may overlap in the following ways: * Future direction: if the RAM disk image has the right format and is uncompressed, the memory range of the extracted RAM disk might be identical to the RAM disk image as described by the - [GET_USER_MEMORY](syscalls/get-user-memory.md) system call, i.e. the + [GET_ADDRESS_MAP](syscalls/get-address-map.md) system call, i.e. the loader might be using the RAM disk image in place. #### The Mapping Structure diff --git a/doc/layout.md b/doc/layout.md index ee259839..e40313e0 100644 --- a/doc/layout.md +++ b/doc/layout.md @@ -96,7 +96,7 @@ looks like this: | kernel command line | | allocations +---------------------------------------+ bootinfo.cmdline | | BIOS physical memory map | | - +---------------------------------------+ bootinfo.e820_map | + +---------------------------------------+ bootinfo.acpi_addr_map | | kernel data segment | | ^ | | | | +---------------------------------------+ bootinfo.data_physaddr -+- address | diff --git a/doc/syscalls/README.md b/doc/syscalls/README.md index c18ea29d..5b9faca6 100644 --- a/doc/syscalls/README.md +++ b/doc/syscalls/README.md @@ -14,7 +14,7 @@ | 5 | [YIELD_THREAD](yield-thread.md) | Yield the Current Thread | | 6 | [SET_THREAD_LOCAL](set-thread-local.md) | Set Thread-Local Storage | | 7 | - | Reserved | -| 8 | [GET_USER_MEMORY](get-user-memory.md) | Get User Memory Map | +| 8 | [GET_ADDRESS_MAP](get-address-map.md) | Get Memory Address Map | | 9 | [CREATE_ENDPOINT](create-endpoint.md) | Create IPC Endpoint | | 10 | [RECEIVE](receive.md) | Receive Message | | 11 | [REPLY](reply.md) | Reply to Message | diff --git a/doc/syscalls/get-address-map.md b/doc/syscalls/get-address-map.md new file mode 100644 index 00000000..1df636cf --- /dev/null +++ b/doc/syscalls/get-address-map.md @@ -0,0 +1,107 @@ +# GET_ADDRESS_MAP - Get Memory Address Map + +## Description + +This function writes the system and kernel memory address map to a buffer +provided by the caller. + +Specifically, the data written in the buffer is a +[jinue_addr_map_t structure](../../include/jinue/shared/types.h) (the header) +followed by an array of +[jinue_addr_map_entry_t structures](../../include/jinue/shared/types.h) (the map +entries). + +Each map entry describes a contiguous block of memory. Some entries describe +memory regions reported by the system firmware whereas other entries describe +memory regions of interest reported by the kernel itself. + +The header contains a single 32-bit field (`num_entries`) that specifies the +number of map entries. If the call fails with `JINUE_E2BIG`, which indicates the +buffer it too small to receive the full memory map, the kernel still sets this +field to the total number of map entries, as long as the buffer is at least +large enough for the header. + +Each map entry contains the following fields, in this order: + +* `addr` (64 bits) the address of the start of the memory block. +* `size` (64 bits) the size of the block, in bytes. +* `type` (32 bits) the type of the block. + +The type numbers are described in the table below and are based on the +[ACPI address range types](https://uefi.org/specs/ACPI/6.4_A/15_System_Address_Map_Interfaces.html). + +| Type Number | Name | Description | +|-------------|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 1 | `JINUE_MEMYPE_MEMORY` | Memory available for use.

Equivalent to ACPI address range type `AddressRangeMemory`. | +| 2 | `JINUE_MEMYPE_RESERVED` | Reserved, do not use.

Equivalent to ACPI address range type `AddressRangeReserved`. | +| 3 | `JINUE_MEMYPE_ACPI` | ACPI tables are located in this range. Once the ACPI tables are no longer needed, this range can be used as normal memory.

Equivalent to ACPI address range type `AddressRangeACPI`. | +| 4 | `JINUE_MEMYPE_NVS` | Reserved, do not use. Must be saved and restored across Non-Volatile Sleep (NVS).

Equivalent to ACPI address range type `AddressRangeNVS`. | +| 5 | `JINUE_MEMYPE_UNUSABLE` | Reserved, do not use.

Equivalent to ACPI address range type `AddressRangeUnusable`. | +| 6 | `JINUE_MEMYPE_DISABLED` | Reserved, do not use.

Equivalent to ACPI address range type `AddressRangeDisabled`. | +| 7 | `JINUE_MEMYPE_PERSISTENT` | This range is available for use and has byte-addressable non-volatile memory rather that standard RAM.

Equivalent to ACPI address range type `AddressRangePersistent-Memory`. | +| 12/0xc | `JINUE_MEMYPE_OEM` | Reserved, do not use.

Equivalent to ACPI "OEM defined" address range type. | +| 0xf0000000 | `JINUE_MEMYPE_KERNEL_RESERVED` | Memory reserved for kernel use. This address range cannot be mapped in user space.

Ranges of this type are page aligned.

See the Future Direction section below. | +| 0xf0000001 | `JINUE_MEMYPE_KERNEL_IMAGE` | Kernel image.

This address range can be mapped read only in user space. There will be exactly one entry with this type. This range is page aligned. | +| 0xf0000002 | `JINUE_MEMYPE_RAMDISK` | Compressed RAM disk image.

This address range can be mapped read only in user space. There will be exactly one entry with this type. This range is page aligned. | +| 0xf0000003 | `JINUE_MEMYPE_LOADER_AVAILABLE` | This entry is a hint to the user space loader for memory that it can use for it's own needs. The [Get Memory Information](../init-process.md#get-memory-information-jinue_msg_get_meminfo) message provides a similar functionality for the initial process.

There will be exactly one entry with this type. This range is page aligned. | +| Any Other | N/A | Reserved, do not use. Should be treated in the same way as a `JINUE_MEMYPE_RESERVED` range. | + +Notes: + +* The system ranges comes directly from the memory map provided by the system + firmware, without filtering or processing. No assumption should be made + regarding alignment, overlap, etc. +* A memory manager in user space should use the information reported by this + function in conjunction with the information provided by the + [Get Memory Information](../init-process.md#get-memory-information-jinue_msg_get_meminfo) + message of the [Initial Process Execution Environment](../init-process.md) to + determine which memory ranges it can allocate to applications. + +## Arguments + +Function number (`arg0`) is 8. + +A pointer to the destination buffer is set in `arg1`. The size of the buffer is +set in `arg2`. + +``` + +----------------------------------------------------------------+ + | function = 8 | arg0 + +----------------------------------------------------------------+ + 31 0 + + +----------------------------------------------------------------+ + | buffer address | arg1 + +----------------------------------------------------------------+ + 31 0 + + +----------------------------------------------------------------+ + | buffer size | arg2 + +----------------------------------------------------------------+ + 31 0 + + +----------------------------------------------------------------+ + | reserved (0) | arg3 + +----------------------------------------------------------------+ + 31 0 +``` + +## Return Value + +On success, this function returns 0 (in `arg0`). On failure, it returns -1 and +an error number is set (in `arg1`). + +## Errors + +* JINUE_EINVAL if any part of the destination buffer belongs to the kernel. +* JINUE_E2BIG if the output buffer is too small to fit the result. + +## Future Direction + +The memory map reported by this function is static and represents the situation +at the start of the initial user space process. System calls will be added that +will allow a memory manager in user space to give memory to or reclaim memory +from the kernel. The user space memory manager will be responsible for keeping +track of memory ownership changes that it causes. The memory map reported by +this function, specifically the `JINUE_MEMYPE_KERNEL_RESERVED` entries, will not +reflect these changes. diff --git a/doc/syscalls/get-user-memory.md b/doc/syscalls/get-user-memory.md deleted file mode 100644 index 7c787fbe..00000000 --- a/doc/syscalls/get-user-memory.md +++ /dev/null @@ -1,76 +0,0 @@ -# GET_USER_MEMORY - Get User Memory Map - -## Description - -This function writes the system memory map to a buffer provided by the caller. - -Specifically, the data written in the buffer is a -[jinue_mem_map_t structure](../../include/jinue/shared/types.h) (the header) -followed by an array of -[jinue_mem_entry_t structures](../../include/jinue/shared/types.h) (the map -entries). - -Each map entry describes a contiguous block of memory. Some entries describe -memory regions reported by the system firmware whereas other entries describe -memory regions of interest reported by the kernel itself. - -The header contains a single 32-bit field (`num_entries`) that specifies the -number of map entries. If the call fails with `JINUE_E2BIG`, which indicates the -buffer it too small to receive the full memory map, the kernel still sets this -field to the total number of map entries, as long as the buffer is at least -large enough for the header. - -Each map entry contains the following fields, in this order: - -* `addr` (64 bits) the address of the start of the memory block. -* `size` (64 bits) the size of the block, in bytes. -* `type` (32 bits) the type of the block, as described in the table below. - -| Type Number | Name | Description | -|-------------|---------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 0 | JINUE_MEM_TYPE_BIOS_RESERVED | Memory reported as unusable by the system firmware.

This range comes directly from the memory map provided by the system firmware, without filtering or processing. No assumption should be made regarding alignment, overlap, etc. | -| 1 | JINUE_MEM_TYPE_AVAILABLE | Memory reported as available for use by the system firmware.

This range comes directly from the memory map provided by the system firmware, without filtering or processing. No assumption should be made regarding alignment, overlap, etc. | -| 2 | JINUE_MEM_TYPE_ACPI | Memory reported by the system firmware as used for ACPI tables and reclaimable once these tables have been read.

This range comes directly from the memory map provided by the system firmware, without filtering or processing. No assumption should be made regarding alignment, overlap, etc. | -| 3 | JINUE_MEM_TYPE_RAMDISK | Compressed RAM disk image.

This region can be mapped read only. There will be exactly one entry with this type. | -| 4 | JINUE_MEM_TYPE_KERNEL_IMAGE | Kernel image.

This region can be mapped read only. There will be exactly one entry with this type. | -| 5 | JINUE_MEM_TYPE_KERNEL_RESERVED | Memory reserved for kernel use.

Cannot be mapped. Entries of this type reflect the situation at the end of kernel initialization. They can no longer be relied upon once the memory manager in user space has started giving memory to or reclaiming memory from the kernel. | -| 6 | JINUE_MEM_TYPE_LOADER_AVAILABLE | This entry is a hint to the user space loader for memory that it can use for it's own needs.

There will be exactly one entry with this type. | - -## Arguments - -Function number (`arg0`) is 8. - -A pointer to the destination buffer is set in `arg1`. The size of the buffer is -set in `arg2`. - -``` - +----------------------------------------------------------------+ - | function = 8 | arg0 - +----------------------------------------------------------------+ - 31 0 - - +----------------------------------------------------------------+ - | buffer address | arg1 - +----------------------------------------------------------------+ - 31 0 - - +----------------------------------------------------------------+ - | buffer size | arg2 - +----------------------------------------------------------------+ - 31 0 - - +----------------------------------------------------------------+ - | reserved (0) | arg3 - +----------------------------------------------------------------+ - 31 0 -``` - -## Return Value - -On success, this function returns 0 (in `arg0`). On failure, it returns -1 and -an error number is set (in `arg1`). - -## Errors - -* JINUE_EINVAL if any part of the destination buffer belongs to the kernel. -* JINUE_E2BIG if the output buffer is too small to fit the result. diff --git a/include/assert.h b/include/assert.h old mode 100755 new mode 100644 diff --git a/include/ctype.h b/include/ctype.h old mode 100755 new mode 100644 diff --git a/include/errno.h b/include/errno.h old mode 100755 new mode 100644 diff --git a/include/internals.h b/include/internals.h old mode 100755 new mode 100644 diff --git a/include/inttypes.h b/include/inttypes.h old mode 100755 new mode 100644 diff --git a/include/jinue/jinue.h b/include/jinue/jinue.h index ffe1834f..60393765 100644 --- a/include/jinue/jinue.h +++ b/include/jinue/jinue.h @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ void jinue_putc(char c); int jinue_puts(int loglevel, const char *str, size_t n, int *perrno); -int jinue_get_user_memory(jinue_mem_map_t *buffer, size_t buffer_size, int *perrno); +int jinue_get_address_map(const jinue_buffer_t *buffer, int *perrno); int jinue_mmap( int process, diff --git a/include/jinue/shared/asm/memtype.h b/include/jinue/shared/asm/memtype.h new file mode 100644 index 00000000..492b1dd1 --- /dev/null +++ b/include/jinue/shared/asm/memtype.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023-2024 Philippe Aubertin. + * All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the author nor the names of other contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _JINUE_SHARED_ASM_MEMTYPE_H +#define _JINUE_SHARED_ASM_MEMTYPE_H + +/* Assignments: use the same values as the ACPI/e820 address range types. Use + * the 0xf0000000 to 0xffffffff OEM defined range for custom values. */ + +#define JINUE_MEMYPE_MEMORY 1 + +#define JINUE_MEMYPE_RESERVED 2 + +#define JINUE_MEMYPE_ACPI 3 + +#define JINUE_MEMYPE_NVS 4 + +#define JINUE_MEMYPE_UNUSABLE 5 + +#define JINUE_MEMYPE_DISABLED 6 + +#define JINUE_MEMYPE_PERSISTENT 7 + +#define JINUE_MEMYPE_OEM 12 + +#define JINUE_MEMYPE_KERNEL_RESERVED 0xf0000000 + +#define JINUE_MEMYPE_KERNEL_IMAGE (JINUE_MEMYPE_KERNEL_RESERVED + 1) + +#define JINUE_MEMYPE_RAMDISK (JINUE_MEMYPE_KERNEL_RESERVED + 2) + +#define JINUE_MEMYPE_LOADER_AVAILABLE (JINUE_MEMYPE_KERNEL_RESERVED + 3) + +#endif diff --git a/include/jinue/shared/asm/syscalls.h b/include/jinue/shared/asm/syscalls.h index ad1e82e6..bb9d2930 100644 --- a/include/jinue/shared/asm/syscalls.h +++ b/include/jinue/shared/asm/syscalls.h @@ -47,11 +47,11 @@ /** set address and size of thread local storage for current thread */ #define JINUE_SYS_SET_THREAD_LOCAL 6 -/** get free memory block list for management by user space */ -#define JINUE_SYS_GET_USER_MEMORY 8 +/** get system and kernel address map */ +#define JINUE_SYS_GET_ADDRESS_MAP 8 /** create an IPC object to receive messages */ -#define JINUE_SYS_CREATE_ENDPOINT 9 +#define JINUE_SYS_CREATE_ENDPOINT 9 /** receive a message on an IPC object */ #define JINUE_SYS_RECEIVE 10 diff --git a/include/jinue/shared/types.h b/include/jinue/shared/types.h index 2c39e4d8..5396f852 100644 --- a/include/jinue/shared/types.h +++ b/include/jinue/shared/types.h @@ -82,15 +82,15 @@ typedef struct { } jinue_message_t; typedef struct { - uint64_t addr; - uint64_t size; - uint32_t type; -} jinue_mem_entry_t; + uint64_t addr; + uint64_t size; + uint32_t type; +} jinue_addr_map_entry_t; typedef struct { - uint32_t num_entries; - jinue_mem_entry_t entry[]; -} jinue_mem_map_t; + uint32_t num_entries; + jinue_addr_map_entry_t entry[]; +} jinue_addr_map_t; typedef struct { void *addr; diff --git a/include/kernel/application/syscalls.h b/include/kernel/application/syscalls.h index be6e5412..d538ae5c 100644 --- a/include/kernel/application/syscalls.h +++ b/include/kernel/application/syscalls.h @@ -52,7 +52,7 @@ void exit_thread(void); void *get_thread_local(void); -int get_user_memory(const jinue_buffer_t *buffer); +int get_address_map(const jinue_buffer_t *buffer); int mclone(int src, int dest, const jinue_mclone_args_t *args); diff --git a/include/kernel/domain/services/panic.h b/include/kernel/domain/services/panic.h old mode 100755 new mode 100644 diff --git a/include/jinue/shared/asm/memory.h b/include/kernel/infrastructure/acpi/asm/addrmap.h similarity index 75% rename from include/jinue/shared/asm/memory.h rename to include/kernel/infrastructure/acpi/asm/addrmap.h index f7e4965b..8f9594b0 100644 --- a/include/jinue/shared/asm/memory.h +++ b/include/kernel/infrastructure/acpi/asm/addrmap.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Philippe Aubertin. + * Copyright (C) 2024 Philippe Aubertin. * All rights reserved. * Redistribution and use in source and binary forms, with or without @@ -29,21 +29,25 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _JINUE_SHARED_ASM_MEMORY_H -#define _JINUE_SHARED_ASM_MEMORY_H +#ifndef JINUE_KERNEL_INFRASTRUCTURE_ACPI_ASM_ADDRMAP_H +#define JINUE_KERNEL_INFRASTRUCTURE_ACPI_ASM_ADDRMAP_H -#define JINUE_MEM_TYPE_BIOS_RESERVED 0 +#define ACPI_ADDR_RANGE_MEMORY 1 -#define JINUE_MEM_TYPE_AVAILABLE 1 +#define ACPI_ADDR_RANGE_RESERVED 2 -#define JINUE_MEM_TYPE_ACPI 2 +#define ACPI_ADDR_RANGE_ACPI 3 -#define JINUE_MEM_TYPE_RAMDISK 3 +#define ACPI_ADDR_RANGE_NVS 4 -#define JINUE_MEM_TYPE_KERNEL_IMAGE 4 +#define ACPI_ADDR_RANGE_UNUSABLE 5 -#define JINUE_MEM_TYPE_KERNEL_RESERVED 5 +#define ACPI_ADDR_RANGE_DISABLED 6 -#define JINUE_MEM_TYPE_LOADER_AVAILABLE 6 +#define ACPI_ADDR_RANGE_PERSISTENT 7 + +#define ACPI_ADDR_RANGE_OEM 12 + +#define ACPI_ADDR_RANGE_OEM_START 0xf0000000 #endif diff --git a/include/kernel/interface/i686/asm/e820.h b/include/kernel/infrastructure/acpi/types.h old mode 100755 new mode 100644 similarity index 73% rename from include/kernel/interface/i686/asm/e820.h rename to include/kernel/infrastructure/acpi/types.h index 26d31cd5..6ab908ca --- a/include/kernel/interface/i686/asm/e820.h +++ b/include/kernel/infrastructure/acpi/types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Philippe Aubertin. + * Copyright (C) 2024 Philippe Aubertin. * All rights reserved. * Redistribution and use in source and binary forms, with or without @@ -29,13 +29,27 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef JINUE_KERNEL_I686_ASM_E820_H -#define JINUE_KERNEL_I686_ASM_E820_H +#ifndef JINUE_KERNEL_INFRASTRUCTURE_ACPI_TYPES_H +#define JINUE_KERNEL_INFRASTRUCTURE_ACPI_TYPES_H -#define E820_RAM 1 +#include -#define E820_RESERVED 2 +typedef struct { + uint64_t addr; + uint64_t size; + uint32_t type; +} acpi_addr_range_t; -#define E820_ACPI 3 +typedef struct { + char signature[8]; + uint8_t checksum; + char oemid[6]; + uint8_t revision; + uint32_t rsdt_address; + uint32_t length; + uint64_t xsdt_address; + uint8_t extended_checksum; + uint8_t reserved[3]; +} acpi_rsdp_t; #endif diff --git a/include/kernel/infrastructure/i686/drivers/acpi.h b/include/kernel/infrastructure/i686/drivers/acpi.h index e5ae275c..216ea95c 100644 --- a/include/kernel/infrastructure/i686/drivers/acpi.h +++ b/include/kernel/infrastructure/i686/drivers/acpi.h @@ -35,18 +35,6 @@ #include #include -typedef struct { - char signature[8]; - uint8_t checksum; - char oemid[6]; - uint8_t revision; - uint32_t rsdt_address; - uint32_t length; - uint64_t xsdt_address; - uint8_t extended_checksum; - uint8_t reserved[3]; -} acpi_rsdp_t; - void acpi_init(void); uint32_t acpi_get_rsdp_paddr(void); diff --git a/include/kernel/infrastructure/i686/drivers/vga.h b/include/kernel/infrastructure/i686/drivers/vga.h old mode 100755 new mode 100644 diff --git a/include/kernel/infrastructure/i686/isa/abi.h b/include/kernel/infrastructure/i686/isa/abi.h old mode 100755 new mode 100644 diff --git a/include/kernel/infrastructure/i686/isa/io.h b/include/kernel/infrastructure/i686/isa/io.h old mode 100755 new mode 100644 diff --git a/include/kernel/infrastructure/i686/memory.h b/include/kernel/infrastructure/i686/memory.h index 0a36774c..4fe78caf 100644 --- a/include/kernel/infrastructure/i686/memory.h +++ b/include/kernel/infrastructure/i686/memory.h @@ -32,7 +32,7 @@ #ifndef JINUE_KERNEL_INFRASTRUCTURE_I686_MEMORY_H #define JINUE_KERNEL_INFRASTRUCTURE_I686_MEMORY_H -#include +#include #include #include #include diff --git a/include/kernel/infrastructure/i686/types.h b/include/kernel/infrastructure/i686/types.h index 1f65a900..fb367151 100644 --- a/include/kernel/infrastructure/i686/types.h +++ b/include/kernel/infrastructure/i686/types.h @@ -38,12 +38,6 @@ #include #include -typedef struct { - uint64_t addr; - uint64_t size; - uint32_t type; -} e820_t; - typedef uint64_t seg_descriptor_t; typedef uint32_t seg_selector_t; diff --git a/include/kernel/interface/i686/asm/boot.h b/include/kernel/interface/i686/asm/boot.h old mode 100755 new mode 100644 index e87bf4b0..3995f9b4 --- a/include/kernel/interface/i686/asm/boot.h +++ b/include/kernel/interface/i686/asm/boot.h @@ -36,7 +36,7 @@ #include #include -#define BOOT_E820_ENTRIES 0x1e8 +#define BOOT_ADDR_MAP_ENTRIES 0x1e8 #define BOOT_SETUP_SECTS 0x1f1 @@ -54,21 +54,21 @@ #define BOOT_RAMDISK_IMAGE 0x218 -#define BOOT_RAMDISK_SIZE 0x21C +#define BOOT_RAMDISK_SIZE 0x21C -#define BOOT_CMD_LINE_PTR 0x228 +#define BOOT_CMD_LINE_PTR 0x228 -#define BOOT_E820_MAP 0x2d0 +#define BOOT_ADDR_MAP 0x2d0 -#define BOOT_E820_MAP_END 0xd00 +#define BOOT_ADDR_MAP_END 0xd00 -#define BOOT_E820_MAP_SIZE (BOOT_E820_MAP_END - BOOT_E820_MAP) +#define BOOT_ADDR_MAP_SIZE (BOOT_ADDR_MAP_END - BOOT_ADDR_MAP) #define BOOT_SETUP32_ADDR MEMORY_ADDR_1MB #define BOOT_SETUP32_SIZE PAGE_SIZE -#define BOOT_DATA_STRUCT BOOT_E820_ENTRIES +#define BOOT_DATA_STRUCT BOOT_ADDR_MAP_ENTRIES #define BOOT_STACK_HEAP_SIZE (4 * PAGE_SIZE) diff --git a/include/kernel/interface/i686/asm/bootinfo.h b/include/kernel/interface/i686/asm/bootinfo.h old mode 100755 new mode 100644 index 6e75dfe3..b6627edd --- a/include/kernel/interface/i686/asm/bootinfo.h +++ b/include/kernel/interface/i686/asm/bootinfo.h @@ -60,11 +60,11 @@ /** Offset of the ramdisk_size bootinfo_t member */ #define BOOTINFO_RAMDISK_SIZE 28 -/** Offset of the e820_entries bootinfo_t member */ -#define BOOTINFO_E820_ENTRIES 32 +/** Offset of the acpi_addr_map bootinfo_t member */ +#define BOOTINFO_ACPI_ADDR_MAP 32 -/** Offset of the e820_map bootinfo_t member */ -#define BOOTINFO_E820_MAP 36 +/** Offset of the addr_map_entries bootinfo_t member */ +#define BOOTINFO_ADDR_MAP_ENTRIES 36 /** Offset of the cmdline bootinfo_t member */ #define BOOTINFO_CMDLINE 40 diff --git a/include/kernel/interface/i686/asm/exceptions.h b/include/kernel/interface/i686/asm/exceptions.h old mode 100755 new mode 100644 diff --git a/include/kernel/interface/i686/asm/idt.h b/include/kernel/interface/i686/asm/idt.h old mode 100755 new mode 100644 diff --git a/include/kernel/interface/i686/asm/irq.h b/include/kernel/interface/i686/asm/irq.h old mode 100755 new mode 100644 diff --git a/include/kernel/interface/i686/boot.h b/include/kernel/interface/i686/boot.h old mode 100755 new mode 100644 diff --git a/include/kernel/interface/i686/types.h b/include/kernel/interface/i686/types.h index cb0e6a3c..34ca86f4 100644 --- a/include/kernel/interface/i686/types.h +++ b/include/kernel/interface/i686/types.h @@ -32,6 +32,7 @@ #ifndef JINUE_KERNEL_INTERFACE_I686_TYPES_H #define JINUE_KERNEL_INTERFACE_I686_TYPES_H +#include #include #include #include @@ -43,27 +44,27 @@ * * See also the setup code, i.e. kernel/i686/setup32.asm. */ typedef struct { - Elf32_Ehdr *kernel_start; - size_t kernel_size; - Elf32_Ehdr *loader_start; - size_t loader_size; - void *image_start; - void *image_top; - kern_paddr_t ramdisk_start; - size_t ramdisk_size; - uint32_t e820_entries; - const e820_t *e820_map; - void *cmdline; - void *boot_heap; - void *boot_end; - pte_t *page_table_1mb; - pte_t *page_table_16mb; - pte_t *page_table_klimit; - pte_t *page_directory; - uint32_t setup_signature; - void *data_start; - size_t data_size; - size_t data_physaddr; + Elf32_Ehdr *kernel_start; + size_t kernel_size; + Elf32_Ehdr *loader_start; + size_t loader_size; + void *image_start; + void *image_top; + kern_paddr_t ramdisk_start; + size_t ramdisk_size; + const acpi_addr_range_t *acpi_addr_map; + uint32_t addr_map_entries; + void *cmdline; + void *boot_heap; + void *boot_end; + pte_t *page_table_1mb; + pte_t *page_table_16mb; + pte_t *page_table_klimit; + pte_t *page_directory; + uint32_t setup_signature; + void *data_start; + size_t data_size; + size_t data_physaddr; } bootinfo_t; typedef struct { diff --git a/include/kernel/machine/acpi.h b/include/kernel/machine/acpi.h index 2f95086b..c3a4affd 100644 --- a/include/kernel/machine/acpi.h +++ b/include/kernel/machine/acpi.h @@ -38,4 +38,3 @@ void machine_set_acpi_tables(const jinue_acpi_tables_t *tables); #endif - diff --git a/include/kernel/machine/memory.h b/include/kernel/machine/memory.h index fbe0bd79..cbf56bd2 100644 --- a/include/kernel/machine/memory.h +++ b/include/kernel/machine/memory.h @@ -34,6 +34,6 @@ #include -int machine_get_memory_map(const jinue_buffer_t *buffer); +int machine_get_address_map(const jinue_buffer_t *buffer); #endif diff --git a/include/stdarg.h b/include/stdarg.h old mode 100755 new mode 100644 diff --git a/include/stdbool.h b/include/stdbool.h old mode 100755 new mode 100644 diff --git a/include/stddef.h b/include/stddef.h old mode 100755 new mode 100644 diff --git a/include/stdint.h b/include/stdint.h old mode 100755 new mode 100644 diff --git a/include/string.h b/include/string.h old mode 100755 new mode 100644 diff --git a/include/sys/auxv.h b/include/sys/auxv.h old mode 100755 new mode 100644 diff --git a/include/sys/elf.h b/include/sys/elf.h index 9f0ed73d..59ff9526 100644 --- a/include/sys/elf.h +++ b/include/sys/elf.h @@ -47,53 +47,53 @@ typedef int32_t Elf32_Sword; typedef uint32_t Elf32_Word; typedef struct { - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; } Elf32_Ehdr; typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; } Elf32_Phdr; typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; } Elf32_Shdr; typedef struct { - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Half st_shndx; + Elf32_Word st_name; + Elf32_Addr st_value; + Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf32_Half st_shndx; } Elf32_Sym; typedef struct { diff --git a/include/tar.h b/include/tar.h old mode 100755 new mode 100644 diff --git a/include/unistd.h b/include/unistd.h old mode 100755 new mode 100644 diff --git a/kernel/Makefile b/kernel/Makefile index 92614e36..58f2c53b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -71,7 +71,7 @@ sources.kernel.c = \ application/syscalls/destroy.c \ application/syscalls/dup.c \ application/syscalls/exit_thread.c \ - application/syscalls/get_user_memory.c \ + application/syscalls/get_address_map.c \ application/syscalls/await_thread.c \ application/syscalls/mint.c \ application/syscalls/mmap.c \ diff --git a/kernel/application/syscalls/get_user_memory.c b/kernel/application/syscalls/get_address_map.c similarity index 94% rename from kernel/application/syscalls/get_user_memory.c rename to kernel/application/syscalls/get_address_map.c index 53cf3b71..101813be 100644 --- a/kernel/application/syscalls/get_user_memory.c +++ b/kernel/application/syscalls/get_address_map.c @@ -32,6 +32,6 @@ #include #include -int get_user_memory(const jinue_buffer_t *buffer) { - return machine_get_memory_map(buffer); +int get_address_map(const jinue_buffer_t *buffer) { + return machine_get_address_map(buffer); } diff --git a/kernel/infrastructure/i686/drivers/acpi.c b/kernel/infrastructure/i686/drivers/acpi.c index 6d9eb81d..9e069d2f 100644 --- a/kernel/infrastructure/i686/drivers/acpi.c +++ b/kernel/infrastructure/i686/drivers/acpi.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/kernel/infrastructure/i686/drivers/iodelay.asm b/kernel/infrastructure/i686/drivers/iodelay.asm old mode 100755 new mode 100644 diff --git a/kernel/infrastructure/i686/drivers/vga.c b/kernel/infrastructure/i686/drivers/vga.c old mode 100755 new mode 100644 diff --git a/kernel/infrastructure/i686/isa/abi.asm b/kernel/infrastructure/i686/isa/abi.asm old mode 100755 new mode 100644 diff --git a/kernel/infrastructure/i686/isa/io.asm b/kernel/infrastructure/i686/isa/io.asm old mode 100755 new mode 100644 diff --git a/kernel/infrastructure/i686/memory.c b/kernel/infrastructure/i686/memory.c index 75ea31da..67ccd7b3 100644 --- a/kernel/infrastructure/i686/memory.c +++ b/kernel/infrastructure/i686/memory.c @@ -32,10 +32,11 @@ #include #include #include +#include +#include #include #include #include -#include #include #include #include @@ -74,14 +75,14 @@ static bool range_is_in_available_memory( bool retval = false; - for(int idx = 0; idx < bootinfo->e820_entries; ++idx) { + for(int idx = 0; idx < bootinfo->addr_map_entries; ++idx) { memory_range_t entry_range; - const e820_t *entry = &bootinfo->e820_map[idx]; - entry_range.start = entry->addr; - entry_range.end = entry->addr + entry->size; + const acpi_addr_range_t *entry = &bootinfo->acpi_addr_map[idx]; + entry_range.start = entry->addr; + entry_range.end = entry->addr + entry->size; - if(entry->type == E820_RAM) { + if(entry->type == ACPI_ADDR_RANGE_MEMORY) { if(memory_range_is_within(range, &entry_range)) { retval = true; } @@ -172,11 +173,11 @@ void check_memory(const bootinfo_t *bootinfo) { static uint64_t memory_find_top(const bootinfo_t *bootinfo) { uint64_t memory_top = 0; - for(int idx = 0; idx < bootinfo->e820_entries; ++idx) { - const e820_t *entry = &bootinfo->e820_map[idx]; + for(int idx = 0; idx < bootinfo->addr_map_entries; ++idx) { + const acpi_addr_range_t *entry = &bootinfo->acpi_addr_map[idx]; /* Only consider available memory entries. */ - if(entry->type != E820_RAM) { + if(entry->type != ACPI_ADDR_RANGE_MEMORY) { continue; } @@ -251,15 +252,34 @@ void *memory_lookup_page(uint64_t paddr) { return (void *)memory_array[entry_index]; } -static int map_memory_type(int e820_type) { - switch(e820_type) { - case E820_RAM: - return JINUE_MEM_TYPE_AVAILABLE; - case E820_ACPI: - return JINUE_MEM_TYPE_ACPI; - case E820_RESERVED: +static int map_memory_type(const acpi_addr_range_t *addr_range) { + /* The values of the JINUE_MEMYPE_... constants are based on the ACPI + * address range types, i.e. all non OEM-defined values are the same + * between both. + * + * We reserve the OEM defined range from 0xf0000000 for Jinue-specific + * values, so we fold all OEM defined values from the system address map + * into a single value that means "OEM defined". */ + if(addr_range->type >= ACPI_ADDR_RANGE_OEM_START) { + return JINUE_MEMYPE_OEM; + } + + switch(addr_range->type) { + case ACPI_ADDR_RANGE_MEMORY: + case ACPI_ADDR_RANGE_RESERVED: + case ACPI_ADDR_RANGE_ACPI: + case ACPI_ADDR_RANGE_NVS: + case ACPI_ADDR_RANGE_UNUSABLE: + case ACPI_ADDR_RANGE_DISABLED: + case ACPI_ADDR_RANGE_PERSISTENT: + case ACPI_ADDR_RANGE_OEM: + /* ACPI address range types and Jinue memory type have the same value + * for these types. */ + return addr_range->type; default: - return JINUE_MEM_TYPE_BIOS_RESERVED; + /* The ACPI specification states that any undefined type value should + * be treated as reserved. */ + return JINUE_MEMYPE_RESERVED; } } @@ -276,10 +296,10 @@ static void align_range(memory_range_t *dest, bool is_available) { } } -static void assign_and_align_entry(memory_range_t *dest, const e820_t *entry) { +static void assign_and_align_entry(memory_range_t *dest, const acpi_addr_range_t *entry) { dest->start = entry->addr; dest->end = entry->addr + entry->size; - align_range(dest, entry->type == E820_RAM); + align_range(dest, entry->type == ACPI_ADDR_RANGE_MEMORY); } static void clip_memory_range(memory_range_t *dest, const memory_range_t *clipping) { @@ -318,10 +338,10 @@ static void clip_memory_range(memory_range_t *dest, const memory_range_t *clippi } static void clip_available_range(memory_range_t *dest, const bootinfo_t *bootinfo) { - for(int idx = 0; idx < bootinfo->e820_entries; ++idx) { - const e820_t *entry = &bootinfo->e820_map[idx]; + for(int idx = 0; idx < bootinfo->addr_map_entries; ++idx) { + const acpi_addr_range_t *entry = &bootinfo->acpi_addr_map[idx]; - if(entry->type == E820_RAM) { + if(entry->type == ACPI_ADDR_RANGE_MEMORY) { continue; } @@ -342,10 +362,10 @@ static void find_range_for_loader(memory_range_t *dest, const bootinfo_t *bootin /* First, find the largest available range over the 4GB mark. */ memory_range_t largest_over_4gb = {0}; - for(int idx = 0; idx < bootinfo->e820_entries; ++idx) { - const e820_t *entry = &bootinfo->e820_map[idx]; + for(int idx = 0; idx < bootinfo->addr_map_entries; ++idx) { + const acpi_addr_range_t *entry = &bootinfo->acpi_addr_map[idx]; - if(entry->type != E820_RAM) { + if(entry->type != ACPI_ADDR_RANGE_MEMORY) { continue; } @@ -368,10 +388,10 @@ static void find_range_for_loader(memory_range_t *dest, const bootinfo_t *bootin /* Then, compare this to the region just above the kernel data. */ memory_range_t under_4gb = {0}; - for(int idx = 0; idx < bootinfo->e820_entries; ++idx) { - const e820_t *entry = &bootinfo->e820_map[idx]; + for(int idx = 0; idx < bootinfo->addr_map_entries; ++idx) { + const acpi_addr_range_t *entry = &bootinfo->acpi_addr_map[idx]; - if(entry->type != E820_RAM) { + if(entry->type != ACPI_ADDR_RANGE_MEMORY) { continue; } @@ -399,7 +419,7 @@ static void find_range_for_loader(memory_range_t *dest, const bootinfo_t *bootin } } -int machine_get_memory_map(const jinue_buffer_t *buffer) { +int machine_get_address_map(const jinue_buffer_t *buffer) { const bootinfo_t *bootinfo = get_bootinfo(); const uintptr_t kernel_image_size = @@ -408,38 +428,38 @@ int machine_get_memory_map(const jinue_buffer_t *buffer) { memory_range_t loader_range; find_range_for_loader(&loader_range, bootinfo); - const jinue_mem_entry_t kernel_regions[] = { + const jinue_addr_map_entry_t kernel_regions[] = { { .addr = bootinfo->ramdisk_start, .size = bootinfo->ramdisk_size, - .type = JINUE_MEM_TYPE_RAMDISK + .type = JINUE_MEMYPE_RAMDISK }, { .addr = VIRT_TO_PHYS_AT_16MB(bootinfo->image_start), .size = kernel_image_size, - .type = JINUE_MEM_TYPE_KERNEL_IMAGE + .type = JINUE_MEMYPE_KERNEL_IMAGE }, { .addr = VIRT_TO_PHYS_AT_16MB(bootinfo->image_top), .size = BOOT_SIZE_AT_16MB - kernel_image_size, - .type = JINUE_MEM_TYPE_KERNEL_RESERVED + .type = JINUE_MEMYPE_KERNEL_RESERVED }, { .addr = loader_range.start, .size = loader_range.end - loader_range.start, - .type = JINUE_MEM_TYPE_LOADER_AVAILABLE + .type = JINUE_MEMYPE_LOADER_AVAILABLE } }; - const size_t e820_entries = bootinfo->e820_entries; + const size_t addr_map_entries = bootinfo->addr_map_entries; const size_t kernel_entries = sizeof(kernel_regions) / sizeof(kernel_regions[0]); - const size_t total_entries = e820_entries + kernel_entries; + const size_t total_entries = addr_map_entries + kernel_entries; const size_t result_size = - sizeof(jinue_mem_map_t) + total_entries * sizeof(jinue_mem_entry_t); + sizeof(jinue_addr_map_t) + total_entries * sizeof(jinue_addr_map_entry_t); - jinue_mem_map_t *map = buffer->addr; + jinue_addr_map_t *map = buffer->addr; - if(buffer->size >= sizeof(jinue_mem_map_t)) { + if(buffer->size >= sizeof(jinue_addr_map_t)) { map->num_entries = total_entries; } @@ -447,14 +467,15 @@ int machine_get_memory_map(const jinue_buffer_t *buffer) { return -JINUE_E2BIG; } - for(unsigned int idx = 0; idx < e820_entries; ++idx) { - map->entry[idx].addr = bootinfo->e820_map[idx].addr; - map->entry[idx].size = bootinfo->e820_map[idx].size; - map->entry[idx].type = map_memory_type(bootinfo->e820_map[idx].type); + for(unsigned int idx = 0; idx < addr_map_entries; ++idx) { + const acpi_addr_range_t *addr_range = &bootinfo->acpi_addr_map[idx]; + map->entry[idx].addr = addr_range->addr; + map->entry[idx].size = addr_range->size; + map->entry[idx].type = map_memory_type(addr_range); } for(unsigned int idx = 0; idx < kernel_entries; ++idx) { - map->entry[e820_entries + idx] = kernel_regions[idx]; + map->entry[addr_map_entries + idx] = kernel_regions[idx]; } return 0; diff --git a/kernel/interface/i686/ld/image.lds b/kernel/interface/i686/ld/image.lds old mode 100755 new mode 100644 diff --git a/kernel/interface/i686/setup16.asm b/kernel/interface/i686/setup16.asm old mode 100755 new mode 100644 index 7f8ec2ce..2914a981 --- a/kernel/interface/i686/setup16.asm +++ b/kernel/interface/i686/setup16.asm @@ -31,14 +31,11 @@ #include #include #include -#include %define CODE_SEG 1 %define DATA_SEG 2 %define SETUP_SEG 3 -%define E820_SMAP 0x534d4150 - bits 16 ; defined by linker - see image.lds linker script @@ -47,44 +44,44 @@ bootsect_start: - times BOOT_E820_ENTRIES -($-$$) db 0 + times BOOT_ADDR_MAP_ENTRIES -($-$$) db 0 -e820_entries: db 0 +address_map_entries: db 0 times BOOT_SETUP_SECTS -($-$$) db 0 -setup_sects: db setup_size_div512 -root_flags: dw 1 -sysize: dd kernel_size_div16 -ram_size: dw 0 -vid_mode: dw 0xffff -root_dev: dw 0 -signature: dw BOOT_MAGIC +setup_sects: db setup_size_div512 +root_flags: dw 1 +sysize: dd kernel_size_div16 +ram_size: dw 0 +vid_mode: dw 0xffff +root_dev: dw 0 +signature: dw BOOT_MAGIC jmp short start -header: db "HdrS" -version: dw 0x0206 -realmode_swtch: dd 0 -start_sys: dw 0x1000 -kernel_version: dw str_version -type_of_loader: db 0 -loadflags: db 1 -setup_move_size: dw 0 -code32_start: dd BOOT_SETUP32_ADDR -ramdisk_image: dd 0 -ramdisk_size: dd 0 -bootsect_kludge: dd 0 -heap_end_ptr: dw 0 -pad1: dw 0 -cmd_line_ptr: dd 0 +header: db "HdrS" +version: dw 0x0206 +realmode_swtch: dd 0 +start_sys: dw 0x1000 +kernel_version: dw str_version +type_of_loader: db 0 +loadflags: db 1 +setup_move_size: dw 0 +code32_start: dd BOOT_SETUP32_ADDR +ramdisk_image: dd 0 +ramdisk_size: dd 0 +bootsect_kludge: dd 0 +heap_end_ptr: dw 0 +pad1: dw 0 +cmd_line_ptr: dd 0 initrd_addr_max: -ramdisk_max: dd BOOT_RAMDISK_LIMIT - 1 -kernel_alignment: dd 0 ; Not relevant because kernel is not relocatable... -relocatable_kernel: db 0 ; ... as indicated here -min_alignment: db 0 ; not relevant, protocol 2.10+ -xloadflags: dw 0 ; not relevant, protocol 2.12+ -cmdline_size: dd CMDLINE_MAX_VALID_LENGTH +ramdisk_max: dd BOOT_RAMDISK_LIMIT - 1 +kernel_alignment: dd 0 ; Not relevant: kernel is not relocatable... +relocatable_kernel: db 0 ; ... as indicated here +min_alignment: db 0 ; not relevant, protocol 2.10+ +xloadflags: dw 0 ; not relevant, protocol 2.12+ +cmdline_size: dd CMDLINE_MAX_VALID_LENGTH start: ; Setup the segment registers @@ -174,25 +171,25 @@ code_32: ; Jump to the kernel entry point jmp dword SEG_SELECTOR(CODE_SEG, RPL_KERNEL):BOOT_SETUP32_ADDR +;------------------------------------------------------------------------------ +; ACPI Address Map +; +; Warning: The ACPI address map starts here and IT OVERWRITES the code below. +; Only code that runs *before* the address map is generated should go here. +;------------------------------------------------------------------------------ + ; This adds only a few bytes (or none). The main reason for this line is to ; ensure an error is generated (TIMES value is negative) if the code above - ; crosses into the e820 memory map. - times BOOT_E820_MAP -($-$$) db 0 + ; crosses into the address map. + times BOOT_ADDR_MAP -($-$$) db 0 -;------------------------------------------------------------------------ -; E820 Memory map -; -; The e820 memory map starts here. The code below gets overwritten by the -; memory map. Only code that runs *before* the memory map is generated -; should go here. -;------------------------------------------------------------------------ -e820_map: +address_map: -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ ; FUNCTION: check_a20 ; DESCRIPTION: Check if A20 gate is activated. Return with ZF=0 if it ; is. -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ check_a20: ; Save segment registers push ds @@ -234,10 +231,10 @@ check_a20: sti ret -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ ; FUNCTION: enable_a20 ; DESCRIPTION: Activate the A20 gate. -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ enable_a20: ; If we are lucky, there is nothing to do... call check_a20 @@ -286,30 +283,33 @@ enable_a20: jnz .empty_8042 ret - ; Skip to end of e820 memory map - times BOOT_E820_MAP_END-($-$$) db 0 - -;------------------------------------------------------------------------ -; End of E820 Memory map +;------------------------------------------------------------------------------ +; End of ACPI Address map ; -; Code below is safe: it does not get overwritten by the e820 memory map. -;------------------------------------------------------------------------ -e820_map_end: +; Code below is safe: it does not get overwritten by the ACPI address map. +;------------------------------------------------------------------------------ + + ; Skip to the end of the ACPI address map + times BOOT_ADDR_MAP_END-($-$$) db 0 -;------------------------------------------------------------------------ +address_map_end: + +;------------------------------------------------------------------------------ ; FUNCTION: iodelay ; DESCRIPTION: Wait for about 1 µs. -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ iodelay: out 0x80, al ret -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ ; FUNCTION: bios_e820 ; DESCRIPTION: Obtain physical memory map from BIOS. -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ + %define E820_SMAP 0x534d4150 + bios_e820: - mov di, e820_map ; Buffer (start of memory map) + mov di, address_map ; Buffer (start of memory map) mov ebx, 0 ; Continuation set to 0 cld @@ -340,26 +340,26 @@ bios_e820: mov ax, di ; Check that we can still fit one more entry add ax, 20 - cmp ax, e820_map_end + cmp ax, address_map_end jbe .loop .exit: ; Compute number of entries mov ax, di ; Size is end ... - sub ax, e820_map ; ... minus start + sub ax, address_map ; ... minus start xor dx, dx ; High 16-bits of dx:ax (i.e. dx) are zero mov bx, 20 ; Divide by 20 div bx ; Set number of entries - mov byte [BOOT_E820_ENTRIES], al + mov byte [BOOT_ADDR_MAP_ENTRIES], al ret -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ ; FUNCTION: reset_fpu ; DESCRIPTION: Reset the floating-point unit. -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ reset_fpu: xor ax, ax out 0xf0, al @@ -370,16 +370,16 @@ reset_fpu: ret -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ ; Data section -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ str_version: db "Test kernel v0.0", 0 -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ ; Global Descriptor Table (minimal) -;------------------------------------------------------------------------ +;------------------------------------------------------------------------------ align 16 gdt: diff --git a/kernel/interface/i686/setup32.asm b/kernel/interface/i686/setup32.asm index 116c466e..5ac6ce25 100644 --- a/kernel/interface/i686/setup32.asm +++ b/kernel/interface/i686/setup32.asm @@ -27,7 +27,7 @@ ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -; ------------------------------------------------------------------------------ +; ----------------------------------------------------------------------------- ; This setup code performs a few tasks to support the kernel's initialization, ; which include: @@ -50,7 +50,7 @@ ; | kernel command line | | allocations ; +-----------------------------------+ bootinfo.cmdline | ; | BIOS physical memory map | | -; +-----------------------------------+ bootinfo.e820_map | +; +-----------------------------------+ bootinfo.acpi_addr_map | ; | kernel data segment | | ; | (copied from ELF binary) | v ; +-----------------------------------+ bootinfo.data_physaddr --- @@ -263,7 +263,7 @@ start: ; copy BIOS memory map mov esi, dword [esp + VAR_ZERO_PAGE] - call copy_e820_memory_map + call copy_acpi_address_map ; copy command line mov esi, dword [esp + VAR_ZERO_PAGE] @@ -291,7 +291,7 @@ start: add dword [ebp + BOOTINFO_LOADER_START], BOOT_OFFSET_FROM_1MB add dword [ebp + BOOTINFO_IMAGE_START], BOOT_OFFSET_FROM_1MB add dword [ebp + BOOTINFO_IMAGE_TOP], BOOT_OFFSET_FROM_1MB - add dword [ebp + BOOTINFO_E820_MAP], BOOT_OFFSET_FROM_1MB + add dword [ebp + BOOTINFO_ACPI_ADDR_MAP], BOOT_OFFSET_FROM_1MB add dword [ebp + BOOTINFO_CMDLINE], BOOT_OFFSET_FROM_1MB add dword [ebp + BOOTINFO_BOOT_HEAP], BOOT_OFFSET_FROM_1MB add dword [ebp + BOOTINFO_BOOT_END], BOOT_OFFSET_FROM_1MB @@ -332,10 +332,10 @@ just_right_here: ; * * * - ; -------------------------------------------------------------------------- - ; Function: copy_e820_memory_map - ; -------------------------------------------------------------------------- - ; Copy BIOS memory map. + ; ------------------------------------------------------------------------- + ; Function: copy_acpi_address_map + ; ------------------------------------------------------------------------- + ; Copy ACPI address map. ; ; Arguments: ; esi real mode code start/zero-page address @@ -345,15 +345,16 @@ just_right_here: ; Returns: ; edi end of memory map ; ecx, esi are caller saved -copy_e820_memory_map: + ; ------------------------------------------------------------------------- +copy_acpi_address_map: ; Set memory map address in bootinfo_t structure - mov dword [ebp + BOOTINFO_E820_MAP], edi + mov dword [ebp + BOOTINFO_ACPI_ADDR_MAP], edi ; Source address - add esi, BOOT_E820_MAP + add esi, BOOT_ADDR_MAP ; Compute size to copy - mov ecx, dword [ebp + BOOTINFO_E820_ENTRIES] + mov ecx, dword [ebp + BOOTINFO_ADDR_MAP_ENTRIES] lea ecx, [5 * ecx] ; times 20 (size of one entry), which is 5 ... shl ecx, 2 ; ... times 2^2 @@ -362,9 +363,9 @@ copy_e820_memory_map: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: copy_cmdline - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Copy kernel command line ; ; Arguments: @@ -375,6 +376,7 @@ copy_e820_memory_map: ; Returns: ; edi end of kernel command line ; eax, ecx, esi are caller saved + ; ------------------------------------------------------------------------- copy_cmdline: mov dword [ebp + BOOTINFO_CMDLINE], empty_string @@ -402,21 +404,21 @@ copy_cmdline: stosb ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: initialize_bootinfo - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Initialize most fields in the bootinfo_t structure, specifically: ; - ; kernel_start (ebp + BOOTINFO_KERNEL_START) - ; kernel_size (ebp + BOOTINFO_KERNEL_SIZE) - ; loader_start (ebp + BOOTINFO_LOADER_START) - ; loader_size (ebp + BOOTINFO_LOADER_SIZE) - ; image_start (ebp + BOOTINFO_IMAGE_START) - ; image_top (ebp + BOOTINFO_IMAGE_TOP) - ; ramdisk_start (ebp + BOOTINFO_RAMDISK_START) - ; ramdisk_size (ebp + BOOTINFO_RAMDISK_SIZE) - ; setup_signature (ebp + BOOTINFO_SETUP_SIGNATURE) - ; e820_entries (ebp + BOOTINFO_E820_ENTRIES) + ; kernel_start (ebp + BOOTINFO_KERNEL_START) + ; kernel_size (ebp + BOOTINFO_KERNEL_SIZE) + ; loader_start (ebp + BOOTINFO_LOADER_START) + ; loader_size (ebp + BOOTINFO_LOADER_SIZE) + ; image_start (ebp + BOOTINFO_IMAGE_START) + ; image_top (ebp + BOOTINFO_IMAGE_TOP) + ; ramdisk_start (ebp + BOOTINFO_RAMDISK_START) + ; ramdisk_size (ebp + BOOTINFO_RAMDISK_SIZE) + ; setup_signature (ebp + BOOTINFO_SETUP_SIGNATURE) + ; addr_map_entries (ebp + BOOTINFO_ADDR_MAP_ENTRIES) ; ; Arguments: ; esi real mode code start/zero-page address @@ -424,6 +426,7 @@ copy_cmdline: ; ; Returns: ; eax is caller saved + ; ------------------------------------------------------------------------- initialize_bootinfo: ; Values provided by linker. mov dword [ebp + BOOTINFO_KERNEL_START], kernel_start @@ -446,15 +449,15 @@ initialize_bootinfo: mov dword [ebp + BOOTINFO_SETUP_SIGNATURE], eax ; Number of entries in BIOS memory map - mov al, byte [esi + BOOT_E820_ENTRIES] + mov al, byte [esi + BOOT_ADDR_MAP_ENTRIES] movzx eax, al - mov dword [ebp + BOOTINFO_E820_ENTRIES], eax + mov dword [ebp + BOOTINFO_ADDR_MAP_ENTRIES], eax ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: prepare_data_segment - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Find and copy the kernel's data segment, add zero padding for ; uninitialized data and set its location and size in the bootinfo_t ; structure. @@ -466,6 +469,7 @@ initialize_bootinfo: ; Returns: ; edi address of top of copied data segment (for subsequent allocations) ; eax, ebx, ecx, edx, esi are caller saved + ; ------------------------------------------------------------------------- prepare_data_segment: ; Check magic numbers at the beginning of the ELF header. mov eax, kernel_start @@ -559,9 +563,9 @@ prepare_data_segment: ; Return value: edi is unchanged ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: allocate_page_tables - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Allocate initial non-PAE page tables and page directory. ; ; Page tables that need to be allocated: @@ -577,6 +581,7 @@ prepare_data_segment: ; ; Returns: ; edi end of allocations + ; ------------------------------------------------------------------------- allocate_page_tables: ; Align allocation address to page size before allocating page tables. add edi, PAGE_SIZE - 1 ; align address up... @@ -600,9 +605,9 @@ allocate_page_tables: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: map_kernel_image_1mb - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Map the 1MB of memory that starts with the kernel image, followed by boot ; stack/heap and initial memory allocations. ; @@ -613,6 +618,7 @@ allocate_page_tables: ; Returns: ; edi address of first page table entry after mapped 1MB ; eax, ebx, ecx are caller saved + ; ------------------------------------------------------------------------- map_kernel_image_1mb: ; Compute number of entries to map kernel image mov ecx, dword [ebp + BOOTINFO_IMAGE_TOP] ; end of image @@ -640,9 +646,9 @@ map_kernel_image_1mb: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: map_kernel - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Map the 1MB of memory that starts with the kernel image, followed by boot ; stack/heap and initial memory allocations. ; @@ -653,6 +659,7 @@ map_kernel_image_1mb: ; Returns: ; edi address of first page table entry after mapped 1MB ; eax, ebx, ecx are caller saved + ; ------------------------------------------------------------------------- map_kernel: ; remember edi for later push edi @@ -753,9 +760,9 @@ map_kernel: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: initialize_page_tables - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Initialize initial non-PAE page tables. ; ; Arguments: @@ -763,6 +770,7 @@ map_kernel: ; ; Returns: ; eax, ebx, ecx, edi are caller saved + ; ------------------------------------------------------------------------- initialize_page_tables: ; ---------------------------------------------- ; First page table: first 4 MB of memory (1:1) @@ -802,9 +810,9 @@ initialize_page_tables: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: initialize_page_directory - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Initialize initial non-PAE page directory. ; ; Arguments: @@ -812,6 +820,7 @@ initialize_page_tables: ; ; Returns: ; eax, ecx, edi are caller saved + ; ------------------------------------------------------------------------- initialize_page_directory: ; clear initial page directory mov edi, dword [ebp + BOOTINFO_PAGE_DIRECTORY] ; write address @@ -839,9 +848,9 @@ initialize_page_directory: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: enable_paging - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Enable paging and protect read-only pages from being written to by the ; kernel. ; @@ -850,6 +859,7 @@ initialize_page_directory: ; ; Returns: ; eax is caller saved + ; ------------------------------------------------------------------------- enable_paging: ; set page directory address in CR3 mov eax, [ebp + BOOTINFO_PAGE_DIRECTORY] @@ -862,9 +872,9 @@ enable_paging: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: map_linear - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Initialize consecutive non-PAE page table entries to map consecutive ; pages of physical memory (i.e. page frames). ; @@ -876,6 +886,7 @@ enable_paging: ; Returns: ; edi updated write address ; eax, ecx are caller saved + ; ------------------------------------------------------------------------- map_linear: ; page table entry flags or eax, X86_PTE_PRESENT @@ -893,9 +904,9 @@ map_linear: ret - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; Function: clear_ptes - ; -------------------------------------------------------------------------- + ; ------------------------------------------------------------------------- ; clear consecutive non-PAE page table entries. ; ; Arguments: @@ -905,6 +916,7 @@ map_linear: ; Returns: ; edi updated write address ; eax, ecx are caller saved + ; ------------------------------------------------------------------------- clear_ptes: xor eax, eax ; write value: 0 rep stosd ; clear entries diff --git a/kernel/interface/syscalls.c b/kernel/interface/syscalls.c index 93e26021..35b0ea6d 100644 --- a/kernel/interface/syscalls.c +++ b/kernel/interface/syscalls.c @@ -51,17 +51,17 @@ static void set_return_value(jinue_syscall_args_t *args, int retval) { - args->arg0 = (uintptr_t)retval; - args->arg1 = 0; - args->arg2 = 0; - args->arg3 = 0; + args->arg0 = (uintptr_t)retval; + args->arg1 = 0; + args->arg2 = 0; + args->arg3 = 0; } static void set_error(jinue_syscall_args_t *args, int error) { - args->arg0 = (uintptr_t)-1; - args->arg1 = (uintptr_t)error; - args->arg2 = 0; - args->arg3 = 0; + args->arg0 = (uintptr_t)-1; + args->arg1 = (uintptr_t)error; + args->arg2 = 0; + args->arg3 = 0; } static void set_return_value_or_error(jinue_syscall_args_t *args, int retval) { @@ -142,7 +142,7 @@ static void sys_set_thread_local(jinue_syscall_args_t *args) { set_return_value(args, 0); } -static void sys_get_user_memory(jinue_syscall_args_t *args) { +static void sys_get_address_map(jinue_syscall_args_t *args) { jinue_buffer_t buffer; buffer.addr = (void *)args->arg1; @@ -153,7 +153,7 @@ static void sys_get_user_memory(jinue_syscall_args_t *args) { return; } - int retval = get_user_memory(&buffer); + int retval = get_address_map(&buffer); set_return_value_or_error(args, retval); } @@ -600,8 +600,8 @@ void handle_syscall(jinue_syscall_args_t *args) { case JINUE_SYS_SET_THREAD_LOCAL: sys_set_thread_local(args); break; - case JINUE_SYS_GET_USER_MEMORY: - sys_get_user_memory(args); + case JINUE_SYS_GET_ADDRESS_MAP: + sys_get_address_map(args); break; case JINUE_SYS_CREATE_ENDPOINT: sys_create_endpoint(args); diff --git a/userspace/lib/jinue/syscalls.c b/userspace/lib/jinue/syscalls.c index 45ca6522..2c96328f 100644 --- a/userspace/lib/jinue/syscalls.c +++ b/userspace/lib/jinue/syscalls.c @@ -114,12 +114,12 @@ int jinue_puts(int loglevel, const char *str, size_t n, int *perrno) { return call_with_usual_convention(&args, perrno); } -int jinue_get_user_memory(jinue_mem_map_t *buffer, size_t buffer_size, int *perrno) { +int jinue_get_address_map(const jinue_buffer_t *buffer, int *perrno) { jinue_syscall_args_t args; - args.arg0 = JINUE_SYS_GET_USER_MEMORY; - args.arg1 = (uintptr_t)buffer; - args.arg2 = buffer_size; + args.arg0 = JINUE_SYS_GET_ADDRESS_MAP; + args.arg1 = (uintptr_t)buffer->addr; + args.arg2 = buffer->size; args.arg3 = 0; return call_with_usual_convention(&args, perrno); diff --git a/userspace/lib/libc/physmem.c b/userspace/lib/libc/physmem.c index e89de2b8..eb4f3fad 100644 --- a/userspace/lib/libc/physmem.c +++ b/userspace/lib/libc/physmem.c @@ -81,26 +81,35 @@ static int initialize_range_from_loader_info(void) { return status; } +static const jinue_addr_map_entry_t *find_range_by_type(const jinue_addr_map_t *map, int type) { + for(int idx = 0; idx < map->num_entries; ++idx) { + const jinue_addr_map_entry_t *entry = &map->entry[idx]; + + if(entry->type == type) { + return entry; + } + } + + return NULL; +} + static int initialize_range_from_kernel_info(void) { char map_buffer[BUFFER_SIZE]; - jinue_mem_map_t *map = (void *)map_buffer; - int status = jinue_get_user_memory(map, sizeof(map_buffer), NULL); + jinue_buffer_t call_buffer; + call_buffer.addr = map_buffer; + call_buffer.size = sizeof(map_buffer); + + int status = jinue_get_address_map(&call_buffer, NULL); if(status < 0) { return EXIT_FAILURE; } - const jinue_mem_entry_t *entry = NULL; - - for(int idx = 0; idx < map->num_entries; ++idx) { - entry = &map->entry[idx]; - if(entry->type == JINUE_MEM_TYPE_LOADER_AVAILABLE) { - break; - } - } + const jinue_addr_map_t *map = (const jinue_addr_map_t *)map_buffer; + const jinue_addr_map_entry_t *entry = find_range_by_type(map, JINUE_MEMYPE_LOADER_AVAILABLE); - if(entry == NULL || entry->type != JINUE_MEM_TYPE_LOADER_AVAILABLE) { + if(entry == NULL) { return EXIT_FAILURE; } diff --git a/userspace/loader/loader.c b/userspace/loader/loader.c index db8e6ff8..a1f4df13 100644 --- a/userspace/loader/loader.c +++ b/userspace/loader/loader.c @@ -47,8 +47,12 @@ #define MAP_BUFFER_SIZE 16384 -static jinue_mem_map_t *get_memory_map(void *buffer, size_t bufsize) { - int status = jinue_get_user_memory(buffer, bufsize, &errno); +static jinue_addr_map_t *get_address_map(void *buffer, size_t bufsize) { + jinue_buffer_t call_buffer; + call_buffer.addr = buffer; + call_buffer.size = bufsize; + + int status = jinue_get_address_map(&call_buffer, &errno); if(status != 0) { jinue_error("error: could not get memory map from kernel: %s", strerror(errno)); @@ -204,7 +208,7 @@ int main(int argc, char *argv[]) { initialize_meminfo(); char map_buffer[MAP_BUFFER_SIZE]; - jinue_mem_map_t *map = get_memory_map(map_buffer, sizeof(map_buffer)); + jinue_addr_map_t *map = get_address_map(map_buffer, sizeof(map_buffer)); if(map == NULL) { return EXIT_FAILURE; diff --git a/userspace/loader/ramdisk.c b/userspace/loader/ramdisk.c index 6b29a397..4e129fab 100644 --- a/userspace/loader/ramdisk.c +++ b/userspace/loader/ramdisk.c @@ -66,10 +66,10 @@ static struct stream_initializer stream_initializers[] = { * @return EXIT_SUCCESS on success, other value on failure * * */ -int map_ramdisk(ramdisk_t *ramdisk, const jinue_mem_map_t *map) { - const jinue_mem_entry_t *ramdisk_entry = get_mem_map_entry_by_type( +int map_ramdisk(ramdisk_t *ramdisk, const jinue_addr_map_t *map) { + const jinue_addr_map_entry_t *ramdisk_entry = get_addr_map_entry_by_type( map, - JINUE_MEM_TYPE_RAMDISK + JINUE_MEMYPE_RAMDISK ); if(ramdisk_entry == NULL || ramdisk_entry->addr == 0 || ramdisk_entry->size == 0) { diff --git a/userspace/loader/ramdisk.h b/userspace/loader/ramdisk.h index 8556f657..82087322 100644 --- a/userspace/loader/ramdisk.h +++ b/userspace/loader/ramdisk.h @@ -47,7 +47,7 @@ typedef struct { jinue_dirent_t *root; } extracted_ramdisk_t; -int map_ramdisk(ramdisk_t *ramdisk, const jinue_mem_map_t *map); +int map_ramdisk(ramdisk_t *ramdisk, const jinue_addr_map_t *map); int extract_ramdisk(extracted_ramdisk_t *extracted, const ramdisk_t *ramdisk); diff --git a/userspace/loader/utils.c b/userspace/loader/utils.c index 668eb91b..00877f3b 100644 --- a/userspace/loader/utils.c +++ b/userspace/loader/utils.c @@ -50,7 +50,7 @@ bool bool_getenv(const char *name) { strcmp(value, "1") == 0; } -const jinue_mem_entry_t *get_mem_map_entry_by_type(const jinue_mem_map_t *map, int type) { +const jinue_addr_map_entry_t *get_addr_map_entry_by_type(const jinue_addr_map_t *map, int type) { for(int idx = 0; idx < map->num_entries; ++idx) { if(map->entry[idx].type == type) { return &map->entry[idx]; diff --git a/userspace/loader/utils.h b/userspace/loader/utils.h index c694715a..a8fac180 100644 --- a/userspace/loader/utils.h +++ b/userspace/loader/utils.h @@ -36,6 +36,6 @@ bool bool_getenv(const char *name); -const jinue_mem_entry_t *get_mem_map_entry_by_type(const jinue_mem_map_t *map, int type); +const jinue_addr_map_entry_t *get_addr_map_entry_by_type(const jinue_addr_map_t *map, int type); #endif diff --git a/userspace/testapp/debug.c b/userspace/testapp/debug.c index ca8a94df..3c03a33e 100644 --- a/userspace/testapp/debug.c +++ b/userspace/testapp/debug.c @@ -145,26 +145,37 @@ void dump_syscall_implementation(void) { static const char *phys_memory_type_description(uint32_t type) { switch(type) { - case JINUE_MEM_TYPE_AVAILABLE: + case JINUE_MEMYPE_MEMORY: return "Available"; - case JINUE_MEM_TYPE_BIOS_RESERVED: - return "Unavailable/Reserved"; - case JINUE_MEM_TYPE_ACPI: - return "Unavailable/ACPI"; - case JINUE_MEM_TYPE_RAMDISK: - return "Compressed RAM Disk"; - case JINUE_MEM_TYPE_KERNEL_IMAGE: - return "Kernel Image"; - case JINUE_MEM_TYPE_KERNEL_RESERVED: - return "Unavailable/Kernel Data"; - case JINUE_MEM_TYPE_LOADER_AVAILABLE: - return "Available (Loader Hint)"; + case JINUE_MEMYPE_RESERVED: + return "Reserved"; + case JINUE_MEMYPE_ACPI: + return "Reserved/ACPI"; + case JINUE_MEMYPE_NVS: + return "Reserved/NVS"; + case JINUE_MEMYPE_UNUSABLE: + return "Reserved/Unusable"; + case JINUE_MEMYPE_DISABLED: + return "Reserved/Disabled"; + case JINUE_MEMYPE_PERSISTENT: + return "Available/Persistent"; + case JINUE_MEMYPE_OEM: + return "Reserved/OEM"; + case JINUE_MEMYPE_KERNEL_RESERVED: + return "Jinue/Reserved"; + case JINUE_MEMYPE_KERNEL_IMAGE: + return "Jinue/Kernel Image"; + case JINUE_MEMYPE_RAMDISK: + return "Jinue/Compressed RAM Disk"; + case JINUE_MEMYPE_LOADER_AVAILABLE: + return "Jinue/Available (Loader Hint)"; default: - return "Unavailable/???"; + /* escaped to prevent trigraph */ + return "Reserved (??\?)"; } } -static void dump_phys_memory_map(const jinue_mem_map_t *map) { +static void dump_phys_memory_map(const jinue_addr_map_t *map) { const char *name = "DEBUG_DUMP_MEMORY_MAP"; const char *value = getenv(name); @@ -184,12 +195,12 @@ static void dump_phys_memory_map(const jinue_mem_map_t *map) { jinue_info("Dump of the BIOS memory map%s:", ram_only?" (showing only available entries)":""); for(int idx = 0; idx < map->num_entries; ++idx) { - const jinue_mem_entry_t *entry = &map->entry[idx]; + const jinue_addr_map_entry_t *entry = &map->entry[idx]; - if(entry->type == JINUE_MEM_TYPE_AVAILABLE || !ram_only) { + if(entry->type == JINUE_MEMYPE_MEMORY || !ram_only) { jinue_info( " %c [%016" PRIx64 "-%016" PRIx64 "] %s", - (entry->type==JINUE_MEM_TYPE_AVAILABLE)?'*':' ', + (entry->type==JINUE_MEMYPE_MEMORY) ? '*' : ' ', entry->addr, entry->addr + entry->size - 1, phys_memory_type_description(entry->type) @@ -198,19 +209,22 @@ static void dump_phys_memory_map(const jinue_mem_map_t *map) { } } -void dump_user_memory(void) { - char call_buffer[MAP_BUFFER_SIZE]; +void dump_address_map(void) { + char map_buffer[MAP_BUFFER_SIZE]; - jinue_mem_map_t *map = (jinue_mem_map_t *)&call_buffer; + jinue_buffer_t call_buffer; + call_buffer.addr = map_buffer; + call_buffer.size = sizeof(map_buffer); /* get free memory blocks from microkernel */ - int status = jinue_get_user_memory(map, sizeof(call_buffer), &errno); + int status = jinue_get_address_map(&call_buffer, &errno); if(status != 0) { jinue_error("error: could not get memory map from kernel: %s", strerror(errno)); return; } + const jinue_addr_map_t *map = (const jinue_addr_map_t *)&map_buffer; dump_phys_memory_map(map); } diff --git a/userspace/testapp/debug.h b/userspace/testapp/debug.h index dd15516e..55084434 100644 --- a/userspace/testapp/debug.h +++ b/userspace/testapp/debug.h @@ -40,7 +40,7 @@ void dump_auxvec(void); void dump_syscall_implementation(void); -void dump_user_memory(void); +void dump_address_map(void); void dump_loader_memory_info(void); diff --git a/userspace/testapp/testapp.c b/userspace/testapp/testapp.c index 80333a56..458b1c33 100644 --- a/userspace/testapp/testapp.c +++ b/userspace/testapp/testapp.c @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) { dump_environ(); dump_auxvec(); dump_syscall_implementation(); - dump_user_memory(); + dump_address_map(); dump_loader_memory_info(); dump_loader_ramdisk();