OS_ARCH := x86
OS_NAME := lunaix
+OS_ID := LunaixOS
+OS_VER := dev20230618
OS_BIN := $(OS_NAME).bin
OS_ISO := $(OS_NAME).iso
-USR_LIB := liblxusrt.a
\ No newline at end of file
+USR_LIB := liblxusrt.a
#define ISO_SIGNATURE_HI 0x31
// Volume Types
-#define ISO_VOLBOOT 0 // Boot Record
-#define ISO_VOLPRIM 1 // Primary
-#define ISO_VOLSUPP 2 // Supplementary
-#define ISO_VOLPART 3 // Partition
-#define ISO_VOLTERM 255 // Volume descriptor set terminator
+#define ISO_VOLBOOT 0 // Boot Record
+#define ISO_VOLPRIM 1 // Primary
+#define ISO_VOLSUPP 2 // Supplementary
+#define ISO_VOLPART 3 // Partition
+#define ISO_VOLTERM 255 // Volume descriptor set terminator
#define ISO_FHIDDEN 0x1 // a hidden file
#define ISO_FDIR 0x2 // a directory file
#define ISO9660_BLKSZ 2048
#define ISO9660_IDLEN 256
+#define ISO9660_READ_OFF (ISO9660_BLKSZ * 16)
// NOTES:
// Each Descriptor sized 1 logical block (2048 bytes in common cases)
iso_bbo32_t data_size;
struct iso_datetime2 PACKED mktime; // Time the record is made, see 9.1.5
u8_t flags;
- u8_t fu_sz; // size of file unit (FU)
- u8_t gap_sz; // size of gap if FU is interleaved.
+ u8_t fu_sz; // size of file unit (FU)
+ u8_t gap_sz; // size of gap if FU is interleaved.
iso_bbo16_t vol_seq;
struct iso_var_mdu name;
} PACKED;
--- /dev/null
+#ifndef __LUNAIX_PROBE_BOOT_H
+#define __LUNAIX_PROBE_BOOT_H
+
+#include <lunaix/device.h>
+
+struct device*
+probe_boot_medium();
+
+#endif /* __LUNAIX_PROBE_BOOT_H */
static struct cake_pile* lbd_pile;
static struct block_dev** dev_registry;
static struct twifs_node* blk_sysroot;
+static struct device* blk_parent_dev;
int free_slot = 0;
dev_registry = vcalloc(sizeof(struct block_dev*), MAX_DEV);
free_slot = 0;
blk_sysroot = twifs_dir_node(NULL, "block");
+ blk_parent_dev = device_addcat(NULL, "block");
}
int
return 0;
}
- struct device* dev = device_addvol(NULL, bdev, "sd%c", 'a' + free_slot);
+ struct device* dev =
+ device_addvol(blk_parent_dev, bdev, "sd%c", 'a' + free_slot);
dev->write = __block_write;
dev->write_page = __block_write_page;
dev->read = __block_read;
--- /dev/null
+#include <lunaix/fs/iso9660.h>
+#include <lunaix/fs/probe_boot.h>
+#include <lunaix/mm/valloc.h>
+#include <lunaix/syslog.h>
+
+LOG_MODULE("PROBE")
+
+#define LUNAIX_ID 0x414e554cUL // "LUNA"
+
+struct device*
+probe_boot_medium()
+{
+ struct device* block_cat = device_getbyname(NULL, "block", 5);
+ if (!block_cat) {
+ return NULL;
+ }
+
+ struct iso_vol_primary* volp = valloc(ISO9660_BLKSZ);
+
+ struct device *pos, *n;
+ llist_for_each(pos, n, &block_cat->children, siblings)
+ {
+ int errno =
+ pos->read(pos, (void*)volp, ISO9660_READ_OFF, ISO9660_BLKSZ);
+ if (errno < 0) {
+ kprintf(KWARN "can not probe %x:%s (%d)\n",
+ pos->dev_id,
+ pos->name.value,
+ errno);
+ pos = NULL;
+ goto done;
+ }
+
+ if (*(u32_t*)volp->header.std_id != ISO_SIGNATURE_LO) {
+ continue;
+ }
+
+ if (*(u32_t*)volp->sys_id == LUNAIX_ID) {
+ kprintf(KINFO "[%x:%s] %s\n",
+ pos->dev_id,
+ pos->name.value,
+ (char*)volp->vol_id);
+ break;
+ }
+ }
+
+done:
+ vfree(volp);
+ return pos;
+}
\ No newline at end of file
sz += strlen(chr);
len++;
- chr = *(str_arr + sz);
+ chr = *(str_arr++);
}
*length = len;
- return sz + 1;
+ return sz + sizeof(char*);
}
void
memcpy(arg_start + sz_argv, (void*)envp, sz_envp);
ptr_t* ustack = (ptr_t*)USTACK_TOP;
- struct usr_exec_param* exec_param = mapped;
+ struct usr_exec_param* exec_param = (struct usr_exec_param*)mapped;
ustack[-1] = (ptr_t)mapped;
param->info.stack_top = &ustack[-1];
#include <lunaix/common.h>
#include <lunaix/foptions.h>
#include <lunaix/fs.h>
+#include <lunaix/fs/probe_boot.h>
#include <lunaix/fs/twifs.h>
#include <lunaix/ld.h>
#include <lunaix/lxconsole.h>
{
struct v_dnode* dnode;
int errno = 0;
- if ((errno = vfs_walk_proc("/dev/sdb", &dnode, NULL, 0))) {
+ struct device* dev = probe_boot_medium();
+ if (!dev) {
kprintf(KERROR "fail to acquire device. (%d)", errno);
return 0;
}
- struct device* dev = (struct device*)dnode->inode->data;
if ((errno = vfs_mount("/mnt/lunaix-os", "iso9660", dev, 0))) {
- kprintf(KERROR "fail to boot medium. (%d)", errno);
+ kprintf(KERROR "fail to mount boot medium. (%d)", errno);
return 0;
}
@./config-grub.sh ${OS_NAME} $(ISO_GRUB_DIR)/grub.cfg
@cp $(BIN_DIR)/$(OS_BIN) $(ISO_BOOT_DIR)
@cp -r $(USR_DIR) $(ISO_DIR)
- @grub-mkrescue -o $(BUILD_DIR)/$(OS_ISO) $(ISO_DIR)
+ @grub-mkrescue -o $(BUILD_DIR)/$(OS_ISO) $(ISO_DIR) -- -volid "$(OS_ID) $(OS_VER)" -system_id "$(OS_NAME)"
all: $(BUILD_DIR)/$(OS_ISO)
l++;
}
*cmd = line;
- *arg_part = strltrim_safe(line + l);
+ if (c) {
+ *arg_part = strltrim_safe(line + l);
+ } else {
+ *arg_part = NULL;
+ }
}
void
// stdout (by default, unless user did smth) is the tty we are currently at
ioctl(stdout, TIOCSPGRP, getpgid());
+ char* argv[] = { 0, 0 };
+
while (1) {
getcwd(pwd, 512);
printf("[\033[2m%s\033[39;49m]$ ", pwd);
size_t sz = read(stdin, buf, 511);
+
if (sz < 0) {
printf("fail to read user input (%d)\n", geterrno());
return;
}
+
buf[sz] = '\0';
- parse_cmdline(buf, &cmd, &argpart);
+
+ // currently, this shell only support single argument
+ parse_cmdline(buf, &cmd, &argv[0]);
+
if (cmd[0] == 0) {
printf("\n");
goto cont;
}
+
// cmd=="exit"
if (*(unsigned int*)cmd == 0x74697865U) {
break;
}
- sh_exec(cmd, NULL);
+
+ sh_exec(cmd, (const char**)&argv);
cont:
printf("\n");
}
.section .text
.global _u_start
_u_start:
+ movl (%esp), %eax
+ pushl %eax
call usr_pre_init
jnz 1f
popl %eax
- pushl (%eax) // argc
pushl 4(%eax) // argv
+ pushl (%eax) // argc
xorl %eax, %eax
call main