Skip to content

Commit

Permalink
Read ACPI tables (#94)
Browse files Browse the repository at this point in the history
Map the ACPI tables needed by the kernel. For now, this is done by the
user space loader and provided to the kernel through a system call. This
may change in the future.
  • Loading branch information
phaubertin authored Nov 24, 2024
1 parent 3d93a3a commit 7a8e0e9
Show file tree
Hide file tree
Showing 38 changed files with 1,080 additions and 17 deletions.
2 changes: 2 additions & 0 deletions devel/qemu/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ linux16 /boot/jinue \
DEBUG_DUMP_SYSCALL_IMPLEMENTATION=1 \
DEBUG_DUMP_RAMDISK=1 \
DEBUG_DO_REBOOT=1 \
RUN_TEST_ACPI=1 \
RUN_TEST_IPC=1

initrd16 /boot/jinue-testapp-initrd.tar.gz
boot
2 changes: 2 additions & 0 deletions devel/virtualbox/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ linux16 /boot/jinue \
DEBUG_DUMP_MEMORY_MAP=1 \
DEBUG_DUMP_SYSCALL_IMPLEMENTATION=1 \
DEBUG_DUMP_RAMDISK=1 \
RUN_TEST_ACPI=1 \
RUN_TEST_IPC=1

initrd16 /boot/jinue-testapp-initrd.tar.gz
boot
1 change: 1 addition & 0 deletions doc/init-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ The following table lists the auxiliary vectors:
| 6 | `JINUE_AT_ENTRY` | Address of program entry point |
| 7 | `JINUE_AT_STACKBASE` | Stack base address |
| 8 | `JINUE_AT_HOWSYSCALL` | System call implementation |
| 9 | `JINUE_AT_ACPI_RSDP` | Physical address of ACPI RSDP |

The value of the `JINUE_AT_HOWSYSCALL` auxiliary vector identifies the
system call implementation to use on architectures where there can be
Expand Down
5 changes: 3 additions & 2 deletions doc/syscalls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
| 19 | [MINT](mint.md) | Mint a Descriptor |
| 20 | [START_THREAD](start-thread.md) | Start a Thread |
| 21 | [AWAIT_THREAD](await-thread.md) | Wait for a Thread to Exit |
| 22 | [REPLY_ERROR](reply-error.md) | Reply to Message with an Error !
| 23-4095 | - | Reserved |
| 22 | [REPLY_ERROR](reply-error.md) | Reply to Message with an Error |
| 23 | [SET_ACPI](set-acpi.md) | Provide Mapped ACPI Tables |
| 24-4095 | - | Reserved |
| 4096+ | [SEND](send.md) | Send Message |

#### Reserved Function Numbers
Expand Down
59 changes: 59 additions & 0 deletions doc/syscalls/set-acpi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SET_ACPI - Provide Mapped ACPI Tables

## Description

Provide the mapped ACPI tables to the kernel.

This system call is reserved for use by the user space loader. It fails if
called by another process.

The user space loader must make a best effort to map the relevant ACPI tables
and must call this system call with the result, unless the `JINUE_AT_ACPI_RSDP`
auxiliary vector has been set to zero or omitted.

## Arguments

Function number (`arg0`) is 23.

A pointer to a [jinue_acpi_tables_t structure](../../include/jinue/shared/types.h)
(i.e. the ACPI tables structure) that contains pointers to mapped ACPI tables
is set in `arg1`.

If the user space loader could not map certain ACPI tables, it should set the
relevant pointers to zero (C language `NULL` value) and still call this
function.

```
+----------------------------------------------------------------+
| function = 23 | arg0
+----------------------------------------------------------------+
31 0
+----------------------------------------------------------------+
| pointer to ACPI tables structure | arg1
+----------------------------------------------------------------+
31 0
+----------------------------------------------------------------+
| reserved (0) | arg2
+----------------------------------------------------------------+
31 0
+----------------------------------------------------------------+
| reserved (0) | arg3
+----------------------------------------------------------------+
31 0
```

## Return Value

On success, this function returns 0 (in `arg0`). On failure, this function
returns -1 and an error number is set (in `arg1`).

## Errors

* JINUE_EINVAL if any part of the ACPI tables structure as specified by `arg1`
belongs to the kernel.
* JINUE_ENOSYS if this function does not exist on this CPU architecture.
* JINUE_ENOSYS if this function is called by a process other than the user
space loader.
4 changes: 2 additions & 2 deletions header.mk
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ endif
#
# These flags are used when preprocessing C and assembly language files.
CPPFLAGS.includes = -I$(includes)
CPPFLAGS.arch = -m32 -march=i686
CPPFLAGS.arch = -m32 -march=i686
CPPFLAGS.others = -nostdinc
CPPFLAGS = $(CPPFLAGS.arch) $(CPPFLAGS.includes) $(CPPFLAGS.debug) $(CPPFLAGS.others) $(CPPFLAGS.extra)

# C compiler flags
CFLAGS.warnings = -std=c99 -pedantic -Wall -Werror=implicit -Werror=uninitialized -Werror=return-type
CFLAGS.warnings = -std=c99 -pedantic -Wall -Wno-array-bounds -Werror=implicit -Werror=uninitialized -Werror=return-type
CFLAGS.arch = -m32 -march=i686
CFLAGS.optimization = -O3
CFLAGS.others = -ffreestanding -fno-pie -fno-common -fno-omit-frame-pointer -fno-delete-null-pointer-checks
Expand Down
2 changes: 2 additions & 0 deletions include/jinue/jinue.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ int jinue_await_thread(int fd, int *perrno);

int jinue_reply_error(uintptr_t errcode, int *perrno);

int jinue_set_acpi(jinue_acpi_tables_t *tables, int *perrno);

#endif
3 changes: 3 additions & 0 deletions include/jinue/shared/asm/auxv.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@
/** System call implementation */
#define JINUE_AT_HOWSYSCALL 8

/** Address of RSDP (ACPI) */
#define JINUE_AT_ACPI_RSDP 9

#endif
3 changes: 3 additions & 0 deletions include/jinue/shared/asm/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
/** reply to current message with an error code */
#define JINUE_SYS_REPLY_ERROR 22

/** provide the mapped ACPI tables */
#define JINUE_SYS_SET_ACPI 23

/** start of function numbers for user space messages */
#define JINUE_SYS_USER_BASE 4096

Expand Down
6 changes: 6 additions & 0 deletions include/jinue/shared/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ typedef struct {
uintptr_t cookie;
} jinue_mint_args_t;

typedef struct {
const void *rsdt;
const void *fadt;
const void *madt;
} jinue_acpi_tables_t;

#endif
2 changes: 2 additions & 0 deletions include/kernel/application/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ int reply_error(uintptr_t errcode);

int send(uintptr_t *errcode, int fd, int function, const jinue_message_t *message);

int set_acpi(const jinue_acpi_tables_t *tables);

void set_thread_local(void *addr, size_t size);

int start_thread(int fd, const thread_params_t *params);
Expand Down
54 changes: 54 additions & 0 deletions include/kernel/infrastructure/i686/drivers/acpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 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_KERNEL_INFRASTRUCTURE_I686_DRIVERS_ACPI_H
#define JINUE_KERNEL_INFRASTRUCTURE_I686_DRIVERS_ACPI_H

#include <kernel/infrastructure/i686/drivers/asm/acpi.h>
#include <stdint.h>

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);

#endif
43 changes: 43 additions & 0 deletions include/kernel/infrastructure/i686/drivers/asm/acpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 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_KERNEL_INFRASTRUCTURE_I686_DRIVERS_ASM_ACPI_H
#define JINUE_KERNEL_INFRASTRUCTURE_I686_DRIVERS_ASM_ACPI_H

#define ACPI_BDA_EBDA 0x40e

#define ACPI_V1_REVISION 0

#define ACPI_V2_REVISION 2

#define ACPI_V1_RSDP_SIZE 20

#endif
41 changes: 41 additions & 0 deletions include/kernel/machine/acpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 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_KERNEL_MACHINE_ACPI_H
#define JINUE_KERNEL_MACHINE_ACPI_H

#include <jinue/shared/types.h>
#include <stdint.h>

void machine_set_acpi_tables(const jinue_acpi_tables_t *tables);

#endif

2 changes: 2 additions & 0 deletions include/kernel/machine/auxv.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@

uint32_t machine_at_howsyscall(void);

uint32_t machine_at_acpi_rsdp(void);

#endif

7 changes: 7 additions & 0 deletions include/kernel/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,17 @@ struct descriptor_t {
uintptr_t cookie;
};

typedef enum {
PROCESS_ID_KERNEL,
PROCESS_ID_LOADER,
PROCESS_ID_USER
} process_id;

typedef struct {
object_header_t header;
addr_space_t addr_space;
int running_threads_count;
process_id id;
spinlock_t descriptors_lock;
descriptor_t descriptors[JINUE_DESC_NUM];
} process_t;
Expand Down
4 changes: 3 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ sources.kernel.c = \
application/interrupts/hardware.c \
application/interrupts/spurious.c \
application/interrupts/tick.c \
application/syscalls/acpi.c \
application/syscalls/close.c \
application/syscalls/create_endpoint.c \
application/syscalls/create_process.c \
Expand Down Expand Up @@ -100,10 +101,11 @@ sources.kernel.c = \
domain/services/panic.c \
domain/services/scheduler.c \
domain/config.c \
infrastructure/i686/drivers/vga.c \
infrastructure/i686/drivers/acpi.c \
infrastructure/i686/drivers/pic8259.c \
infrastructure/i686/drivers/pit8253.c \
infrastructure/i686/drivers/uart16550a.c \
infrastructure/i686/drivers/vga.c \
infrastructure/i686/pmap/nopae.c \
infrastructure/i686/pmap/pmap.c \
infrastructure/i686/pmap/pae.c \
Expand Down
1 change: 1 addition & 0 deletions kernel/application/kmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void kmain(const char *cmdline) {
panic("Could not create initial process.");
}

process->id = PROCESS_ID_LOADER;
process_switch_to(process);

/* create user space loader main thread */
Expand Down
Loading

0 comments on commit 7a8e0e9

Please sign in to comment.