"compilerArgs": [
"-ffreestanding",
"-D__ARCH_IA32",
- "-D__LUNAIXOS_DEBUG__"
+ "-D__LUNAIXOS_DEBUG__",
+ "-include flags.h"
],
"defines": [],
"compilerPath": "${HOME}/opt/cross-compiler/bin/i686-elf-gcc",
AS := i686-elf-as
-ARCH_OPT := -D__ARCH_IA32
+ARCH_OPT := -D__ARCH_IA32 -include flags.h
O := -O2
W := -Wall -Wextra -Wno-unknown-pragmas \
-Wno-unused-function \
#ifndef __LUNAIX_FLAGS_H
#define __LUNAIX_FLAGS_H
+#ifdef __ARCH_IA32
+#define PLATFORM_TARGET "x86_32"
+#else
+#define PLATFORM_TARGET "unknown"
+#endif
+
+#define LUNAIX_VER "0.0.1-dev"
+
/*
Uncomment below to force LunaixOS use kernel page table when context switch
to kernel space NOTE: This will make the kernel global.
#include <cpuid.h>
#include <hal/cpu.h>
+#include <hal/rnd.h>
#include <stdint.h>
void
cpu_wrmsr(u32_t msr_idx, u32_t reg_high, u32_t reg_low)
{
asm volatile("wrmsr" : : "d"(reg_high), "a"(reg_low), "c"(msr_idx));
+}
+
+int
+rnd_is_supported()
+{
+ reg32 eax, ebx, ecx, edx;
+ __get_cpuid(0x01, &eax, &ebx, &ecx, &edx);
+ return (ecx & (1 << 30));
}
\ No newline at end of file
--- /dev/null
+#ifndef __LUNAIX_RND_H
+#define __LUNAIX_RND_H
+
+#include <lunaix/types.h>
+
+static inline void
+rnd_fill(void* data, size_t len)
+{
+ asm volatile("1:\n"
+ "rdrand %%eax\n"
+ "movl %%eax, (%0)\n"
+ "addl $4, %%eax\n"
+ "subl $4, %1\n"
+ "jnz 1b" ::"r"((ptr_t)data),
+ "r"((len & ~0x3))
+ : "%al");
+}
+
+int
+rnd_is_supported();
+
+#endif /* __LUNAIX_RND_H */
struct device*
device_getbyoffset(struct device* root_dev, int pos);
+void
+device_init_builtin();
+
#endif /* __LUNAIX_DEVICE_H */
struct device* dev;
struct v_dnode* root;
struct filesystem* fs;
- u32_t iobuf_size;
struct hbucket* i_cache;
void* data;
struct
--- /dev/null
+#include <lunaix/device.h>
+
+extern void
+devbuiltin_init_rand();
+
+extern void
+devbuiltin_init_null();
+
+void
+device_init_builtin()
+{
+ devbuiltin_init_null();
+ devbuiltin_init_rand();
+}
\ No newline at end of file
--- /dev/null
+#include <lunaix/device.h>
+
+int
+__null_wr_pg(struct device* dev, void* buf, size_t offset)
+{
+ // do nothing
+ return PG_SIZE;
+}
+
+int
+__null_wr(struct device* dev, void* buf, size_t offset, size_t len)
+{
+ // do nothing
+ return len;
+}
+
+int
+__null_rd_pg(struct device* dev, void* buf, size_t offset)
+{
+ // do nothing
+ return 0;
+}
+
+int
+__null_rd(struct device* dev, void* buf, size_t offset, size_t len)
+{
+ // do nothing
+ return 0;
+}
+
+void
+devbuiltin_init_null()
+{
+ struct device* devnull = device_addseq(NULL, NULL, "null");
+ devnull->write_page = __null_wr_pg;
+ devnull->write = __null_wr;
+ devnull->read_page = __null_rd_pg;
+ devnull->read = __null_rd;
+}
\ No newline at end of file
--- /dev/null
+#include <hal/rnd.h>
+#include <lunaix/device.h>
+#include <lunaix/syslog.h>
+
+LOG_MODULE("rand")
+
+int
+__rand_rd_pg(struct device* dev, void* buf, size_t offset)
+{
+ rnd_fill(buf, PG_SIZE);
+ return PG_SIZE;
+}
+
+int
+__rand_rd(struct device* dev, void* buf, size_t offset, size_t len)
+{
+ rnd_fill(buf, len);
+ return len;
+}
+
+void
+devbuiltin_init_rand()
+{
+ if (!rnd_is_supported()) {
+ kprintf(KWARN "not supported.\n");
+ return;
+ }
+ struct device* devrand = device_addseq(NULL, NULL, "rand");
+ devrand->read = __rand_rd;
+ devrand->read_page = __rand_rd_pg;
+}
\ No newline at end of file
map->index = container_of(all_mnts.next, struct v_mount, list);
}
+void
+__version_rd(struct twimap* map)
+{
+ twimap_printf(map,
+ "LunaixOS version %s (%s-gnu-gcc %s) %s %s",
+ LUNAIX_VER,
+ PLATFORM_TARGET,
+ __VERSION__,
+ __DATE__,
+ __TIME__);
+}
+
void
vfs_export_attributes()
{
map->read = __mount_read;
map->go_next = __mount_next;
map->reset = __mount_reset;
+
+ map = twifs_mapping(NULL, NULL, "version");
+ map->read = __version_rd;
}
\ No newline at end of file
vfs_mount("/task", "taskfs", NULL, MNT_RO);
lxconsole_spawn_ttydev();
+ device_init_builtin();
syscall_install();