--- /dev/null
+#ifndef VDSO_H
+#define VDSO_H
+
+#include <stdint.h>
+
+/* Shared page layout — mapped read-only at VDSO_USER_ADDR in every process */
+#define VDSO_USER_ADDR 0x007FE000U /* one page below stack guard */
+
+struct vdso_data {
+ volatile uint32_t tick_count; /* updated by kernel timer ISR */
+ uint32_t tick_hz; /* ticks per second (e.g. 50) */
+};
+
+void vdso_init(void);
+void vdso_update_tick(uint32_t tick);
+
+/* Returns the physical address of the vDSO page (for mapping into user AS) */
+uintptr_t vdso_get_phys(void);
+
+#endif
return src2;
}
+ /* Map vDSO shared page read-only into user address space */
+ {
+ extern uintptr_t vdso_get_phys(void);
+ uintptr_t vp = vdso_get_phys();
+ if (vp) {
+ vmm_map_page((uint64_t)vp, (uint64_t)0x007FE000U,
+ VMM_FLAG_PRESENT | VMM_FLAG_USER);
+ }
+ }
+
*entry_out = real_entry;
*user_stack_top_out = user_stack_base + user_stack_size;
*addr_space_out = new_as;
#include "timer.h"
#include "uart_console.h"
#include "process.h"
+#include "vdso.h"
#include "hal/timer.h"
static void hal_tick_bridge(void) {
tick++;
+ vdso_update_tick(tick);
process_wake_check(tick);
schedule();
}
kprintf("[AdrOS] Initializing Scheduler...\n");
process_init();
+ // 7b. Initialize vDSO shared page
+ {
+ extern void vdso_init(void);
+ vdso_init();
+ }
+
// 8. Start Timer (Preemption!) - 50Hz
timer_init(50);
--- /dev/null
+#include "vdso.h"
+#include "pmm.h"
+#include "vmm.h"
+#include "utils.h"
+#include "uart_console.h"
+
+static uintptr_t vdso_phys = 0;
+static volatile struct vdso_data* vdso_kptr = 0;
+
+void vdso_init(void) {
+ void* page = pmm_alloc_page();
+ if (!page) {
+ uart_print("[VDSO] OOM\n");
+ return;
+ }
+ vdso_phys = (uintptr_t)page;
+
+ /* Map into kernel space at a fixed VA so we can write to it.
+ * Use 0xC0230000 (above ATA DMA bounce at 0xC0221000). */
+ uintptr_t kva = 0xC0230000U;
+ vmm_map_page((uint64_t)vdso_phys, (uint64_t)kva,
+ VMM_FLAG_PRESENT | VMM_FLAG_RW);
+
+ vdso_kptr = (volatile struct vdso_data*)kva;
+ memset((void*)vdso_kptr, 0, PAGE_SIZE);
+ vdso_kptr->tick_hz = 50;
+
+ uart_print("[VDSO] Initialized at phys=0x");
+ /* Simple hex print */
+ char hex[9];
+ for (int i = 7; i >= 0; i--) {
+ uint8_t nib = (uint8_t)((vdso_phys >> (i * 4)) & 0xF);
+ hex[7 - i] = (char)(nib < 10 ? '0' + nib : 'a' + nib - 10);
+ }
+ hex[8] = '\0';
+ uart_print(hex);
+ uart_print("\n");
+}
+
+void vdso_update_tick(uint32_t tick) {
+ if (vdso_kptr) {
+ vdso_kptr->tick_count = tick;
+ }
+}
+
+uintptr_t vdso_get_phys(void) {
+ return vdso_phys;
+}