|
AquilaOS documentation
How it works, and its code
|
Go to the source code of this file.
Functions | |
| 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, and a start at the program's entry point in user mode. | |
| void | arch_sleep (void) |
| Puts the current thread to sleep. | |
| 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(). | |
| void | arch_kthread_create (struct thread *thread, uintptr_t entry) |
| Sets up a kernel thread's CPU state. | |
| void | arch_thread_kill (struct thread *thread) |
| Frees a thread's CPU state and kernel stack. | |
| 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. | |
| 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. | |
| void | arch_idle (void) |
| Makes this CPU idle, on its idle stack, until an interrupt makes a thread ready. | |
| 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, registers and FPU state, so that the child returns from fork() as its parent does. | |
| 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. | |
| void | arch_sched_init (void) |
| Starts the timer tick on every CPU, and the clock where it needs to be started. | |
| void | arch_cur_thread_kill (void) |
| Ends the current thread. | |
| void | arch_yield (void) |
| Puts the current thread at the end of the ready list, and runs the next ready thread. | |
| 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, with its stack pointer at its initial stack, which the kernel has built already (argc, argv, envp and the auxiliary vector, as the System V ABI has them: sys/execve.c). | |
| void | arch_sigreturn (void) |
| Returns from a signal handler, for sigreturn(): restores the registers, the signal mask and the FPU state that the handler's frame saved. | |
| 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. | |
| void | arch_mm_setup (void) |
| Finishes setting up memory at boot, once mm_setup() has set up the page structures and the buddy allocator: the kernel's page tables. | |
| paddr_t | arch_page_get_mapping (struct pmap *pmap, vaddr_t vaddr) |
| Finds the page mapped at a virtual address of an address space. | |
| 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, or a mapping made in a window. | |
| 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). | |
| 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. | |
| void | arch_reboot (void) |
| Restarts the machine. | |
| void | arch_halt (void) |
| Stops the CPU for good, with interrupts off. | |
| void | arch_poweroff (void) |
| Powers the machine off, or halts it if it can't be powered off. | |
| uint64_t | arch_rtime_ns (void) |
| Reads the monotonic clock, which starts at boot. | |
| uint64_t | arch_rtime_us (void) |
| Reads the monotonic clock, in microseconds. | |
| uint64_t | arch_rtime_ms (void) |
| Reads the monotonic clock, in milliseconds. | |
| 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. | |
| int | arch_time_get (struct timespec *ts) |
| Reads the date and time from the real time clock. | |
| void | arch_stack_trace (void) |
| Prints the stack trace of the running code, for a panic: the return address of each frame. | |
| void arch_cur_thread_kill | ( | void | ) |
Ends the current thread.
Its kernel stack is freed with it, so this switches to the CPU's idle stack first. It doesn't return.
Definition at line 87 of file sched.c.
References __arch_cur_thread_kill(), aarch64_goto(), arch_cur_thread_kill(), and x86_goto().
Referenced by arch_cur_thread_kill(), proc_kill(), sched_thread_killed(), and sys_thread_exit().
| 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 at line 82 of file timer.c.
References arch_cycles(), and read_sysreg.
Referenced by arch_cycles(), random_stir(), and sched_timer_tick().
Sets up a thread to start a new program when it next returns to user mode: at its entry point, with its stack pointer at its initial stack, which the kernel has built already (argc, argv, envp and the auxiliary vector, as the System V ABI has them: sys/execve.c).
The other registers start as zeros, and so does the FPU's state.
| thread | the thread, which hasn't run since execve() (or ever) |
| entry | the program's entry point |
| sp | the initial stack pointer, 16-byte aligned |
Definition at line 15 of file execve.c.
References aarch64_fpsimd_drop(), thread::arch, arch_exec_start(), aarch64_thread::pc, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, aarch64_thread::sp, and X86_EFLAGS.
Referenced by arch_exec_start(), and exec_start().
| void arch_halt | ( | void | ) |
Stops the CPU for good, with interrupts off.
Definition at line 38 of file psci.c.
References arch_halt(), and arch_interrupts_disable().
Referenced by arch_halt(), arch_poweroff(), and kernel_reboot().
| void arch_idle | ( | void | ) |
Makes this CPU idle, on its idle stack, until an interrupt makes a thread ready.
It doesn't return.
Definition at line 62 of file sched.c.
References __arch_idle(), aarch64_goto(), arch_idle(), curthread, NULL, VMA, x86_goto(), and x86_kernel_stack_set().
Referenced by arch_idle(), kernel_idle(), and x86_ap_start().
Sets up a kernel thread's CPU state.
The thread starts at entry, a function without arguments that never returns, on its own kernel stack, once it is switched to.
| thread | the new thread; its arch stays NULL if there was no memory for its state |
| entry | the function it runs |
Definition at line 113 of file thread.c.
References aarch64_thread_new(), thread::arch, arch_kthread_create(), aarch64_thread::ctx, aarch64_ctx::fp, KERN_STACK_SIZE, kfree(), kmalloc(), aarch64_thread::kstack, x86_thread::kstack, x86_thread::kstack_base, aarch64_ctx::lr, M_ZERO, NULL, PUSH, x86_thread::rbp, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, aarch64_ctx::sp, and X86_EFLAGS.
Referenced by arch_kthread_create(), and kthread_create().
| void arch_mm_setup | ( | void | ) |
Finishes setting up memory at boot, once mm_setup() has set up the page structures and the buddy allocator: the kernel's page tables.
Definition at line 514 of file pmap.c.
References arch_mm_setup(), buddy_set_unusable(), pmap_init(), X86_TRAMPOLINE, and X86_TRAMPOLINE_SIZE.
Referenced by arch_mm_setup(), and mm_setup().
Maps a device's registers into the kernel's address space, uncached (memory-mapped I/O).
| paddr | the registers' physical address |
| size | their size, in bytes |
Definition at line 508 of file pmap.c.
References arch_mmio_map(), phys_window_map(), VM_KRW, VM_NOCACHE, and window_map().
Referenced by arch_mmio_map(), e1000_probe(), pci_host_set(), platform_device_io(), x86_apic_setup(), and x86_hpet_init().
| 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.
The message goes to the boot CPU's local APIC, with the IRQ's vector, edge-triggered.
| handler | the interrupt's handler |
| arg | the argument the handler gets |
| addr | set to the address the device writes the message to |
| data | set to the message |
Definition at line 271 of file apic.c.
References arch_msi_alloc(), irq_install(), lapic, lapic_id, msi_chip, and x86_irq_alloc().
Referenced by arch_msi_alloc(), and pci_msi_enable().
Finds the page mapped at a virtual address of an address space.
| pmap | the address space's page tables |
| vaddr | the virtual address |
Definition at line 431 of file pmap.c.
References arch_page_get_mapping(), D_ADDR, D_VALID, PG_ADDR, PG_PRESENT, and pte_get().
Referenced by arch_page_get_mapping(), kvmem_selftest_run(), kvmem_unmap(), mm_map(), mm_page_unmap(), and slab_page_free().
Returns a kernel address for a range of physical memory: its address in the direct map if it's there, or a mapping made in a window.
| paddr | the range's physical address |
| size | its size, in bytes |
Definition at line 497 of file pmap.c.
References arch_phys_map(), dmap_end, PHYS2VIRT, phys_window_map(), VM_KRW, and window_map().
Referenced by arch_phys_map(), netbuf_alloc(), page_get(), and rd_probe().
| void arch_poweroff | ( | void | ) |
Powers the machine off, or halts it if it can't be powered off.
Definition at line 31 of file psci.c.
References arch_halt(), arch_poweroff(), psci(), PSCI_SYSTEM_OFF, and x86_acpi_poweroff().
Referenced by arch_poweroff(), and kernel_reboot().
Sets up the CPU state of a fork() child's thread: a copy of the parent's kernel stack, registers and FPU state, so that the child returns from fork() as its parent does.
| thread | the thread that called fork() |
| fork | the child process, whose one thread gets the state |
Definition at line 21 of file fork.c.
References aarch64_fpsimd_fork(), aarch64_thread_new(), thread::arch, arch_proc_fork(), aarch64_thread::ctx, x86_regs::err, aarch64_ctx::fp, x86_thread::fpu_context, x86_thread::fpu_enabled, queue::head, KERN_STACK_SIZE, kfree(), kmalloc(), aarch64_thread::kstack, x86_thread::kstack, aarch64_thread::kstack_base, x86_thread::kstack_base, aarch64_ctx::lr, M_ZERO, memcpy(), NULL, aarch64_thread::regs, x86_thread::regs, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, aarch64_ctx::sp, proc::threads, qnode::value, and x86_fpu_save_to().
Referenced by arch_proc_fork(), and proc_fork().
| 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, and a start at the program's entry point in user mode.
| proc | the process |
Definition at line 19 of file proc.c.
References aarch64_thread_new(), thread::arch, arch_proc_init(), proc::entry, queue::head, KERN_STACK_SIZE, kmalloc(), x86_thread::kstack, x86_thread::kstack_base, M_ZERO, panic, aarch64_thread::pc, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, aarch64_thread::sp, proc::threads, USER_STACK, qnode::value, and X86_EFLAGS.
Referenced by arch_proc_init(), and kmain().
| void arch_reboot | ( | void | ) |
Restarts the machine.
Definition at line 25 of file psci.c.
References arch_reboot(), platform_reboot(), psci(), and PSCI_SYSTEM_RESET.
Referenced by arch_reboot(), kernel_ctrlaltdel(), kernel_reboot(), and proc_kill().
| uint64_t arch_rtime_ms | ( | void | ) |
Reads the monotonic clock, in milliseconds.
Definition at line 73 of file timer.c.
References arch_rtime_ms(), and arch_rtime_ns().
Referenced by arch_rtime_ms(), arp_lookup(), arp_update(), and procfs_uptime().
| uint64_t arch_rtime_ns | ( | void | ) |
Reads the monotonic clock, which starts at boot.
Definition at line 56 of file timer.c.
References arch_rtime_ns(), base_ns, counter(), last_ns, mul_shift32(), mult, read_sysreg, since(), source, SOURCE_PIT, tick_period, and ticks.
Referenced by arch_rtime_ms(), arch_rtime_ns(), arch_rtime_us(), callout_set_on(), deadline(), flush_old(), gettime(), make_dirty(), net_main(), poll_deadline(), posix_file_read(), random_stir(), sched_alarm(), sched_alarm_get(), sched_timer_tick(), sched_wait(), socket_inet_recv(), sys_clock_gettime(), sys_nanosleep(), sys_times(), tcp_iss(), tcp_output(), tcp_send_syn(), time_resync(), and timer_calibrate().
| uint64_t arch_rtime_us | ( | void | ) |
Reads the monotonic clock, in microseconds.
Definition at line 65 of file timer.c.
References arch_rtime_ns(), and arch_rtime_us().
Referenced by arch_rtime_us().
| void arch_sched_init | ( | void | ) |
Starts the timer tick on every CPU, and the clock where it needs to be started.
Definition at line 43 of file sched.c.
References arch_cpu_kick(), arch_sched_init(), cpus, cpus_count, platform_timer_setup(), sched_tick(), timer_period, timer_setup(), x86_clock_init(), x86_clock_ticks(), and x86_sched_handler().
Referenced by arch_sched_init(), and sched_init_spawn().
| 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.
| proc | the process |
Definition at line 107 of file signal.c.
References arch_sigcode_map(), vm_entry::base, vm_entry::flags, kfree(), kmalloc(), M_ZERO, PAGE_SIZE, vm_object::pages, SIGCODE_ADDR, sigcode_object, vm_entry::size, vm_entry::vm_object, vm_object_incref(), vm_page_eq(), proc::vm_space, vm_space_insert(), and VM_URX.
Referenced by arch_sigcode_map(), and binfmt_fmt_load().
| void arch_sigreturn | ( | void | ) |
Returns from a signal handler, for sigreturn(): restores the registers, the signal mask and the FPU state that the handler's frame saved.
A bad frame gets SIGSEGV.
Definition at line 247 of file signal.c.
References aarch64_fpsimd_restore(), arch_sigreturn(), x86_regs::cs, curproc, curthread, sigframe::fpsimd, sigframe::fpsimd_valid, sigframe::fpu, sigframe::fxsave, I386_ARGS, sigframe::mask, NULL, aarch64_regs::pstate, REG_FLAGS, REG_SP, aarch64_thread::regs, sigframe::regs, x86_thread::regs, SIG_UNMASKABLE, signal_force(), aarch64_regs::sp, x86_regs::ss, USER_FLAGS, X86_CS, X86_EFLAGS, x86_fpu_load_from(), and X86_SS.
Referenced by arch_sigreturn(), and sys_sigreturn().
| void arch_sleep | ( | void | ) |
Puts the current thread to sleep.
It stops here, and the next ready thread runs, or the CPU idles; it returns once the thread is woken up and chosen to run again.
Definition at line 101 of file sched.c.
References aarch64_ctx_save(), arch_sleep(), aarch64_thread::ctx, curthread, and kernel_idle().
Referenced by arch_sleep(), proc_execve(), signal_exit(), sleep_on(), and sys_exit().
| void arch_stack_trace | ( | void | ) |
Prints the stack trace of the running code, for a panic: the return address of each frame.
Definition at line 14 of file trace.c.
References __kboot, __printing_trace, ARCH_DMAP_BASE, arch_stack_trace(), stack_frame::bp, stack_frame::ip, NULL, printk(), elf32_shdr::sh_addr, elf32_sym::st_name, elf32_sym::st_value, boot::strtab, and symbol_of().
Referenced by arch_stack_trace().
Sets the result of a thread's system call, in the register that returns it to user mode.
That's in the thread's saved registers, or, for a thread that has never run (a child of fork()), where it will start from.
| thread | the thread |
| val | the result |
Definition at line 43 of file syscall.c.
References thread::arch, arch_syscall_return(), x86_regs::rax, x86_thread::rax, aarch64_thread::regs, x86_thread::regs, thread::spawned, aarch64_regs::x, and aarch64_thread::x0.
Referenced by arch_syscall_return(), proc_fork(), and syscall_dispatch().
| 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().
The thread will start at entry in user mode, on its user stack, and that code calls uentry with arg.
| thread | the new thread |
| stack | the top of its user stack |
| entry | where it starts in user mode (the C library's thread start routine) |
| uentry | the function that routine calls (the user's function) |
| arg | that function's argument |
Definition at line 92 of file thread.c.
References aarch64_thread_new(), thread::arch, arch_thread_create(), KERN_STACK_SIZE, kfree(), kmalloc(), x86_thread::kstack, x86_thread::kstack_base, M_ZERO, NULL, aarch64_thread::pc, PUSH, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, aarch64_thread::sp, aarch64_thread::x0, aarch64_thread::x1, and X86_EFLAGS.
Referenced by arch_thread_create(), and thread_create().
| void arch_thread_kill | ( | struct thread * | thread | ) |
Frees a thread's CPU state and kernel stack.
The thread must not be running on them.
| thread | the thread |
Definition at line 133 of file thread.c.
References aarch64_fpsimd_drop(), cpu::arch, thread::arch, arch_thread_kill(), cpus, cpus_count, curthread, x86_thread::fpu_context, arch_cpu::fpu_thread, kfree(), aarch64_thread::kstack_base, x86_thread::kstack_base, NULL, VMA, and x86_kernel_stack_set().
Referenced by arch_thread_kill(), and thread_kill().
| 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.
It doesn't return.
| thread | the thread, which has never run |
Definition at line 63 of file thread.c.
References aarch64_fpsimd_switch(), aarch64_goto(), thread::arch, arch_thread_spawn(), aarch64_thread::kstack, x86_thread::kstack, thread::owner, vm_space::pmap, pmap_switch(), thread_spawn(), proc::vm_space, x86_fpu_disable(), x86_goto(), and x86_kernel_stack_set().
Referenced by arch_thread_spawn(), and sched_thread_spawn().
| 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.
It doesn't return.
| thread | the thread |
Definition at line 76 of file thread.c.
References aarch64_ctx_load(), aarch64_fpsimd_switch(), thread::arch, arch_thread_switch(), aarch64_thread::ctx, x86_thread::kstack, thread::owner, vm_space::pmap, pmap_switch(), x86_thread::rbp, x86_thread::rip, x86_thread::rsp, proc::vm_space, x86_fpu_disable(), x86_goto(), and x86_kernel_stack_set().
Referenced by arch_thread_switch(), and schedule().
| int arch_time_get | ( | struct timespec * | ts | ) |
Reads the date and time from the real time clock.
| ts | set to the time since the epoch, to the second (tv_nsec is 0) |
Definition at line 16 of file rtc.c.
References arch_time_get(), cmos_time(), cmos_rtc::hrs, cmos_rtc::mday, cmos_rtc::min, cmos_rtc::mon, RTC_DR, cmos_rtc::sec, timespec::tv_nsec, timespec::tv_sec, VIRT_REG, VIRT_RTC, and cmos_rtc::yr.
Referenced by arch_time_get(), gettime(), and time_resync().
| void arch_yield | ( | void | ) |
Puts the current thread at the end of the ready list, and runs the next ready thread.
Definition at line 94 of file sched.c.
References aarch64_preempt(), and arch_yield().
Referenced by arch_yield(), and net_main().