AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1#ifndef _CORE_ARCH_H
2#define _CORE_ARCH_H
3
4/*
5 * The functions every architecture provides to the generic kernel, in
6 * arch/ARCH/. See docs/kernel/architecture.md for how the kernel and the
7 * architecture meet.
8 */
9
10#include <core/types.h>
11#include <sys/proc.h>
12#include <dev/irq.h>
13
14/* arch/ARCH/sys/proc.c */
15
23void arch_proc_init(struct proc *proc);
24
30void arch_sleep(void);
31
32/* arch/ARCH/sys/thread.c */
33
48int arch_thread_create(struct thread *thread, uintptr_t stack, uintptr_t entry, uintptr_t uentry, uintptr_t arg);
49
59void arch_kthread_create(struct thread *thread, uintptr_t entry);
60
67void arch_thread_kill(struct thread *thread);
68
75void arch_thread_spawn(struct thread *thread);
76
83void arch_thread_switch(struct thread *thread);
84
87void arch_idle(void);
88
89/* arch/ARCH/sys/fork.c */
90
100int arch_proc_fork(struct thread *thread, struct proc *fork);
101
102/* arch/ARCH/sys/syscall.c */
103
113void arch_syscall_return(struct thread *thread, uintptr_t val);
114
115/* arch/ARCH/sys/sched.c */
116
119void arch_sched_init(void);
120
123void arch_cur_thread_kill(void);
124
127void arch_yield(void);
128
129/* arch/ARCH/sys/execve.c */
130
142void arch_exec_start(struct thread *thread, uintptr_t entry, uintptr_t sp);
143
144/* arch/ARCH/sys/signal.c */
145
149void arch_sigreturn(void);
150
158int arch_sigcode_map(struct proc *proc);
159
160/* arch/ARCH/mm/ */
161
164void arch_mm_setup(void);
165
174
183void *arch_phys_map(uintptr_t paddr, size_t size);
184
193void *arch_mmio_map(uintptr_t paddr, size_t size);
194
195/* Allocates an IRQ for a device's MSI, with its handler, and returns the
196 * message the device must write (address, data). It is weak: an
197 * architecture whose interrupt controller takes no MSI doesn't have it. */
198int arch_msi_alloc(irq_handler_t handler, void *arg, uint64_t *addr, uint32_t *data) __attribute__((weak));
199
201void arch_reboot(void);
202
204void arch_halt(void) __attribute__((noreturn));
205
207void arch_poweroff(void) __attribute__((noreturn));
208
215
222
229
237
245int arch_time_get(struct timespec *ts);
246
249void arch_stack_trace(void);
250
251#endif /* ! _CORE_ARCH_H */
void arch_stack_trace(void)
Prints the stack trace of the running code, for a panic: the return address of each frame.
Definition trace.c:14
int arch_msi_alloc(irq_handler_t handler, void *arg, uint64_t *addr, uint32_t *data)
Gets an IRQ for a device's MSI, and installs its handler.
Definition apic.c:271
uint64_t paddr_t
Definition mm.h:39
uint64_t vaddr_t
Definition mm.h:40
void arch_exec_start(struct thread *thread, uintptr_t entry, uintptr_t sp)
Sets up a thread to start a new program when it next returns to user mode: at its entry point,...
Definition execve.c:15
int arch_proc_fork(struct thread *thread, struct proc *fork)
Sets up the CPU state of a fork() child's thread: a copy of the parent's kernel stack,...
Definition fork.c:21
void arch_proc_init(struct proc *proc)
Sets up the architecture's part of a new process's thread (init's, at boot): its kernel stack,...
Definition proc.c:19
void arch_yield(void)
Puts the current thread at the end of the ready list, and runs the next ready thread.
Definition sched.c:94
void arch_idle(void)
Makes this CPU idle, on its idle stack, until an interrupt makes a thread ready.
Definition sched.c:62
void arch_sleep(void)
Puts the current thread to sleep.
Definition sched.c:101
void arch_cur_thread_kill(void)
Ends the current thread.
Definition sched.c:87
void arch_sched_init(void)
Starts the timer tick on every CPU, and the clock where it needs to be started.
Definition sched.c:43
void arch_sigreturn(void)
Returns from a signal handler, for sigreturn(): restores the registers, the signal mask and the FPU s...
Definition signal.c:247
int arch_sigcode_map(struct proc *proc)
Maps the page with the code that calls sigreturn() (the sigcode) into a process's new address space.
Definition signal.c:107
void arch_syscall_return(struct thread *thread, uintptr_t val)
Sets the result of a thread's system call, in the register that returns it to user mode.
Definition syscall.c:43
int arch_thread_create(struct thread *thread, uintptr_t stack, uintptr_t entry, uintptr_t uentry, uintptr_t arg)
Sets up a new user thread's CPU state and kernel stack, for pthread_create().
Definition thread.c:92
void arch_kthread_create(struct thread *thread, uintptr_t entry)
Sets up a kernel thread's CPU state.
Definition thread.c:113
void arch_thread_switch(struct thread *thread)
Switches to a thread that has run before: its address space, its kernel stack, then where it stopped.
Definition thread.c:76
void arch_thread_kill(struct thread *thread)
Frees a thread's CPU state and kernel stack.
Definition thread.c:133
void arch_thread_spawn(struct thread *thread)
Runs a thread for the first time: switches to its address space and kernel stack, and starts it.
Definition thread.c:63
void(*) irq_handler_t(void *arg)
Definition irq.h:21
paddr_t arch_page_get_mapping(struct pmap *pmap, vaddr_t vaddr)
Finds the page mapped at a virtual address of an address space.
Definition pmap.c:431
void * arch_phys_map(uintptr_t paddr, size_t size)
Returns a kernel address for a range of physical memory: its address in the direct map if it's there,...
Definition pmap.c:497
void arch_mm_setup(void)
Finishes setting up memory at boot, once mm_setup() has set up the page structures and the buddy allo...
Definition pmap.c:514
void * arch_mmio_map(uintptr_t paddr, size_t size)
Maps a device's registers into the kernel's address space, uncached (memory-mapped I/O).
Definition pmap.c:508
void arch_reboot(void)
Restarts the machine.
Definition psci.c:25
void arch_halt(void)
Stops the CPU for good, with interrupts off.
Definition psci.c:38
void arch_poweroff(void)
Powers the machine off, or halts it if it can't be powered off.
Definition psci.c:31
int arch_time_get(struct timespec *ts)
Reads the date and time from the real time clock.
Definition rtc.c:16
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned int uint32_t
Definition stddef.h:22
unsigned long long int uint64_t
Definition stddef.h:23
An installed handler, on its interrupt's list.
Definition irq.c:19
An address space's page tables, on x86.
Definition pmap.h:9
A process.
Definition proc.h:75
A thread.
Definition thread.h:23
uint64_t arch_rtime_ns(void)
Reads the monotonic clock, which starts at boot.
Definition timer.c:56
uint64_t arch_rtime_us(void)
Reads the monotonic clock, in microseconds.
Definition timer.c:65
uint64_t arch_rtime_ms(void)
Reads the monotonic clock, in milliseconds.
Definition timer.c:73
uint64_t arch_cycles(void)
Reads a counter that changes as fast as the CPU runs, which the kernel uses as a source of randomness...
Definition timer.c:82