- make-uefi-iso.sh: UEFI ISO image builder - test_boot.S, test_boot.ld: test boot assembly and linker script - eim_config.toml: EIM (External Interface Module) configuration - edk2-ovmf RPM for UEFI firmware - GAP_ANALYSIS_PIKEOS_PARITY.md: PikeOS parity gap analysis
94 lines
2.7 KiB
C
94 lines
2.7 KiB
C
/*
|
|
* UniversalisOS Microkernel — Comprehensive Test
|
|
* Tests: tasks, semaphores, mutex, tick delays
|
|
*/
|
|
#include "uos_api.h"
|
|
#include "uos_port.h"
|
|
|
|
#define UART0_DR (*(volatile uint32_t*)0x4000C000)
|
|
static void putc(char c) { UART0_DR = c; }
|
|
static void puts(const char *s) { while (*s) putc(*s++); }
|
|
static void putnum(uint32_t n) {
|
|
char buf[10]; int i = 0;
|
|
if (n == 0) { putc('0'); return; }
|
|
while (n > 0) { buf[i++] = '0' + (n % 10); n /= 10; }
|
|
while (i > 0) putc(buf[--i]);
|
|
}
|
|
|
|
static uos_sem_t sem1;
|
|
static uos_mutex_t mtx;
|
|
|
|
static uint8_t st1[512] __attribute__((aligned(8)));
|
|
static uint8_t st2[512] __attribute__((aligned(8)));
|
|
static uint8_t st3[512] __attribute__((aligned(8)));
|
|
|
|
/* Task 1: Sem post + Mutex lock/unlock */
|
|
static void task1(void *a) {
|
|
(void)a;
|
|
for (int i = 0; i < 3; i++) {
|
|
puts("[T1] sem post t="); putnum(uos_tick_get()); puts("\n");
|
|
uos_sem_post(&sem1);
|
|
uos_tick_delay(uos_ms_to_ticks(50));
|
|
}
|
|
/* Mutex */
|
|
puts("[T1] mtx lock\n");
|
|
uos_mutex_lock(&mtx, UOS_WAIT_FOREVER);
|
|
puts("[T1] mtx held\n");
|
|
uos_tick_delay(uos_ms_to_ticks(30));
|
|
uos_mutex_unlock(&mtx);
|
|
puts("[T1] mtx free\n");
|
|
/* Re-lock and unlock */
|
|
uos_mutex_lock(&mtx, UOS_WAIT_FOREVER);
|
|
puts("[T1] mtx2 held\n");
|
|
uos_mutex_unlock(&mtx);
|
|
puts("[T1] done\n");
|
|
for (;;) uos_task_yield();
|
|
}
|
|
|
|
/* Task 2: Sem wait + Mutex contention */
|
|
static void task2(void *a) {
|
|
(void)a;
|
|
for (int i = 0; i < 3; i++) {
|
|
uos_sem_wait(&sem1, UOS_WAIT_FOREVER);
|
|
puts("[T2] sem got t="); putnum(uos_tick_get()); puts("\n");
|
|
}
|
|
/* Mutex contention */
|
|
uos_tick_delay(uos_ms_to_ticks(10));
|
|
puts("[T2] mtx try\n");
|
|
if (uos_mutex_lock(&mtx, 0) == UOS_ERR_WOULDBLOCK) {
|
|
puts("[T2] blocked (correct)\n");
|
|
}
|
|
uos_tick_delay(uos_ms_to_ticks(40));
|
|
uos_mutex_lock(&mtx, UOS_WAIT_FOREVER);
|
|
puts("[T2] mtx got\n");
|
|
uos_mutex_unlock(&mtx);
|
|
puts("[T2] mtx free\n");
|
|
puts("[T2] done\n");
|
|
for (;;) uos_task_yield();
|
|
}
|
|
|
|
/* Task 3: Tick delay */
|
|
static void task3(void *a) {
|
|
(void)a;
|
|
for (int i = 0; i < 3; i++) {
|
|
puts("[T3] t="); putnum(uos_tick_get()); puts("\n");
|
|
uos_tick_delay(uos_ms_to_ticks(100));
|
|
}
|
|
puts("[T3] done\n");
|
|
for (;;) uos_task_yield();
|
|
}
|
|
|
|
int main(void) {
|
|
uos_init();
|
|
uos_sem_init(&sem1, "sem1", 0);
|
|
uos_mutex_init(&mtx, "mtx", false);
|
|
|
|
uos_task_create("t1", 2, task1, NULL, st1, sizeof(st1));
|
|
uos_task_create("t2", 3, task2, NULL, st2, sizeof(st2));
|
|
uos_task_create("t3", 4, task3, NULL, st3, sizeof(st3));
|
|
|
|
puts("\n=== UniversalisOS Microkernel ===\n");
|
|
puts("3 tasks | semaphore | mutex | preemptive\n");
|
|
uos_sched_start();
|
|
for (;;) ;
|
|
}
|