#include <sys/interrupts.h>
#include <lunaix/isrm.h>
-#include <lunaix/lxconsole.h>
#include <lunaix/process.h>
#include <lunaix/sched.h>
#include <lunaix/spike.h>
{
__print_panic_msg("div zero", param);
- console_flush();
spin();
}
{
__print_panic_msg("general protection", param);
- console_flush();
spin();
}
{
__print_panic_msg((char*)(param->registers.edi), param);
- console_flush();
spin();
}
{
__print_panic_msg("unknown interrupt", param);
- console_flush();
spin();
}
__print_panic_msg(buf, param);
- console_flush();
spin();
}
#include <lunaix/input.h>
#include <lunaix/ioctl.h>
#include <lunaix/keyboard.h>
-#include <lunaix/lxconsole.h>
#include <lunaix/mm/pmm.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/mm/vmm.h>
#include <lunaix/sched.h>
#include <lunaix/signal.h>
-#include <lunaix/tty/console.h>
#include <lunaix/tty/tty.h>
+#include <lunaix/ds/fifo.h>
+#include <lunaix/owloysius.h>
#include <hal/term.h>
+struct console
+{
+ struct lx_timer* flush_timer;
+ struct fifo_buf output;
+ struct fifo_buf input;
+ size_t wnd_start;
+ size_t lines;
+};
+
static struct console lx_console;
int
void
console_flush();
+void
+console_view_up();
+
+void
+console_view_down();
+
static waitq_t lx_reader;
static volatile pid_t fg_pgid = 0;
return INPUT_EVT_NEXT;
}
-int
-__tty_exec_cmd(struct device* dev, u32_t req, va_list args)
-{
- switch (req) {
- case TIOCGPGRP:
- return fg_pgid;
- case TIOCSPGRP:
- fg_pgid = va_arg(args, pid_t);
- break;
- case TIOCCLSBUF:
- fifo_clear(&lx_console.output);
- fifo_clear(&lx_console.input);
- lx_console.wnd_start = 0;
- lx_console.lines = 0;
- lx_console.output.flags |= FIFO_DIRTY;
- break;
- case TIOCFLUSH:
- lx_console.output.flags |= FIFO_DIRTY;
- console_flush();
- break;
- default:
- return EINVAL;
- }
- return 0;
-}
-
-void
-lxconsole_init()
-{
- memset(&lx_console, 0, sizeof(lx_console));
- fifo_init(&lx_console.output, valloc(8192), 8192, 0);
- fifo_init(&lx_console.input, valloc(4096), 4096, 0);
-
- lx_console.flush_timer = NULL;
-}
-
int
__tty_write_pg(struct device* dev, void* buf, size_t offset)
{
return count + fifo_read(&console->input, buf + count, len - count);
}
-void
-console_schedule_flush()
-{
- // TODO make the flush on-demand rather than periodic
-}
-
size_t
__find_next_line(size_t start)
{
console_write(&lx_console, (u8_t*)&str, 1);
}
-void
-console_start_flushing()
+
+static void
+lxconsole_init()
{
- struct lx_timer* timer =
- timer_run_ms(20, console_flush, NULL, TIMER_MODE_PERIODIC);
- lx_console.flush_timer = timer;
+ memset(&lx_console, 0, sizeof(lx_console));
+ fifo_init(&lx_console.output, valloc(8192), 8192, 0);
+ fifo_init(&lx_console.input, valloc(4096), 4096, 0);
+
+ lx_console.flush_timer = NULL;
}
+owloysius_fetch_init(lxconsole_init, on_earlyboot)
static int
lxconsole_spawn_ttydev(struct device_def* devdef)
tty_dev->ops.write_page = __tty_write_pg;
tty_dev->ops.read = __tty_read;
tty_dev->ops.read_page = __tty_read_pg;
- tty_dev->ops.exec_cmd = __tty_exec_cmd;
waitq_init(&lx_reader);
input_add_listener(__lxconsole_listener);
#include <lunaix/device.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/spike.h>
+#include <lunaix/owloysius.h>
#include <lunaix/status.h>
#include <sys/mm/mempart.h>
static DEFINE_LLIST(serial_devs);
static int serial_idx = 0;
+static struct device_cat* serial_cat;
+
#define serial_device(dev) ((struct serial_dev*)(dev)->underlay)
int
serial_create(struct devclass* class, char* if_ident)
{
struct serial_dev* sdev = valloc(sizeof(struct serial_dev));
- struct device* dev = device_allocseq(NULL, sdev);
+ struct device* dev = device_allocseq(dev_meta(serial_cat), sdev);
dev->ops.read = __serial_read;
dev->ops.read_page = __serial_read_page;
dev->ops.read_async = __serial_read_async;
device_grant_capability(dev, cap_meta(tp_cap));
- register_device(dev, class, "serial%d", class->variant);
+ register_device(dev, class, "s%d", class->variant);
term_create(dev, if_ident);
}
return NULL;
-}
\ No newline at end of file
+}
+
+static void
+init_serial_dev()
+{
+ serial_cat = device_addcat(NULL, "serial");
+
+ assert(serial_cat);
+}
+owloysius_fetch_init(init_serial_dev, on_earlyboot)
\ No newline at end of file
#include <lunaix/kcmd.h>
#include <lunaix/fs.h>
#include <lunaix/syslog.h>
+#include <lunaix/kprintf.h>
#include <hal/term.h>
INFO("system console: %s", console_dev);
sysconsole = dev;
+
+ kprintf_dump_logs();
}
-lunaix_initfn(setup_default_tty, call_on_boot);
\ No newline at end of file
+owloysius_fetch_init(setup_default_tty, on_boot);
\ No newline at end of file
default:
if ((int)chr < 32) {
rbuffer_put(cooked, '^');
- chr += 64;
+ return rbuffer_put(cooked, chr += 64);
}
break;
}
- return rbuffer_put(cooked, chr);
+ return rbuffer_put_nof(cooked, chr);
}
struct term_lcntl ansi_line_controller = {.process_and_put = __ansi_actcontrol};
\ No newline at end of file
#define QUIT tdev->cc[_VQUIT]
#define SUSP tdev->cc[_VSUSP]
+#define putc_safe(rb, chr) \
+ ({ \
+ if (!rbuffer_put_nof(rb, chr)) { \
+ break; \
+ } \
+ })
+
if (!out) {
// Keep all cc's (except VMIN & VTIME) up to L2 cache.
for (size_t i = 0; i < _VMIN; i++) {
}
}
- while (rbuffer_get(raw, &c) && allow_more) {
+ while (allow_more && rbuffer_get(raw, &c)) {
if (c == '\r' && ((_if & _ICRNL) || (_of & _OCRNL))) {
c = '\n';
do_out:
if (c == '\n' && (_of & _ONLCR)) {
- rbuffer_put(cooked, '\r');
+ putc_safe(cooked, '\r');
}
put_char:
if (!out && (_lf & _IEXTEN) && lcntl_slave_put) {
allow_more = lcntl_slave_put(tdev, lbuf, c);
} else {
- allow_more = rbuffer_put(cooked, c);
+ allow_more = rbuffer_put_nof(cooked, c);
}
}
if (!rbuffer_empty(deref(current))) {
term_flush(tdev);
}
- return 0;
+ return wrsz;
}
static int
memcpy(tdev->cc, default_cc, _NCCS * sizeof(cc_t));
}
+static void
+alloc_term_buffer(struct term* terminal, size_t sz_hlf)
+{
+ line_alloc(&terminal->line_in, sz_hlf);
+ line_alloc(&terminal->line_out, sz_hlf);
+ terminal->scratch_pad = valloc(sz_hlf);
+}
+
struct term*
term_create(struct device* chardev, char* suffix)
{
// TODO choice of lcntl can be flexible
terminal->lcntl = line_controls[ANSI_LCNTL];
- line_alloc(&terminal->line_in, 1024);
- line_alloc(&terminal->line_out, 1024);
+ alloc_term_buffer(terminal, 1024);
if (chardev) {
int cdev_var = DEV_VAR_FROM(chardev->ident.unique);
int
term_flush(struct term* tdev)
{
- if ((tdev->oflags & _OPOST)) {
- lcntl_transform_outseq(tdev);
- }
-
struct linebuffer* line_out = &tdev->line_out;
- size_t xmit_len = line_out->current->len;
- char* xmit_buf = line_out->next->buffer;
+ char* xmit_buf = tdev->scratch_pad;
+ lbuf_ref_t current_ref = ref_current(line_out);
- rbuffer_gets(line_out->current, xmit_buf, xmit_len);
+ int count = 0;
- off_t off = 0;
- int ret = 0;
- while (xmit_len && ret >= 0) {
- ret = tdev->chdev->ops.write(tdev->chdev, &xmit_buf[off], 0, xmit_len);
- xmit_len -= ret;
- off += ret;
- }
+ while (!rbuffer_empty(deref(current_ref))) {
+ if ((tdev->oflags & _OPOST)) {
+ lcntl_transform_outseq(tdev);
+ }
+
+ size_t xmit_len = line_out->current->len;
- // put back the left over if transmittion went south
- rbuffer_puts(line_out->current, xmit_buf, xmit_len);
+ rbuffer_gets(line_out->current, xmit_buf, xmit_len);
+
+ off_t off = 0;
+ int ret = 0;
+ while (xmit_len && ret >= 0) {
+ ret = tdev->chdev->ops.write(tdev->chdev, &xmit_buf[off], 0, xmit_len);
+ xmit_len -= ret;
+ off += ret;
+ count += ret;
+ }
+
+ // put back the left over if transmittion went south
+ rbuffer_puts(line_out->current, xmit_buf, xmit_len);
+
+ line_flip(line_out);
+ }
- return off;
+ return count;
}
\ No newline at end of file
struct term_lcntl* lcntl;
struct linebuffer line_out;
struct linebuffer line_in;
+ char* scratch_pad;
pid_t fggrp;
struct termport_capability* tp_cap;
#define optimize(opt) __attribute__((optimize(opt)))
#define must_inline __attribute__((always_inline))
#define must_emit __attribute__((used))
+#define unreachable __builtin_unreachable()
#define clz(bits) __builtin_clz(bits)
#define sadd_overflow(a, b, of) __builtin_sadd_overflow(a, b, of)
volatile int __infloop = 1;
while (__infloop)
;
- __builtin_unreachable();
+ unreachable;
}
#endif /* __LUNAIX_COMPILER_H */
#define __LUNAIX_LDGA_H
#include <lunaix/types.h>
+#include <lunaix/compiler.h>
#define ldga_el_id(ga_name, el_name) __lga_##ga_name##_##el_name
#define ldga_section(ga_name) __attribute__((section(".lga." ga_name)))
#define export_ldga_el(ga_name, el_name, type, val) \
- type ldga_section(#ga_name) ldga_el_id(ga_name, el_name) = (type)(val)
+ type ldga_section(#ga_name) must_emit ldga_el_id(ga_name, el_name) = (type)(val)
#define export_ldga_el_sfx(ga_name, el_name, type, val, suffix) \
- type ldga_section(#ga_name "." #suffix) ldga_el_id(ga_name, el_name) = \
+ type ldga_section(#ga_name "." #suffix) must_emit ldga_el_id(ga_name, el_name) = \
(type)(val)
#define export_ldga_el_idx(ga_name, i, type, val) \
struct rbuffer*
rbuffer_create(char* buf, size_t maxsz);
+int
+rbuffer_erase(struct rbuffer* rb);
+
+int
+rbuffer_put(struct rbuffer* rb, char c);
+
+int
+rbuffer_puts(struct rbuffer* rb, char* c, size_t len);
+
+int
+rbuffer_gets(struct rbuffer* rb, char* buf, size_t len);
+
+int
+rbuffer_get(struct rbuffer* rb, char* c);
+
+
static inline void
rbuffer_clear(struct rbuffer* rb)
{
return rb->len == rb->maxsz;
}
-int
-rbuffer_erase(struct rbuffer* rb);
-
-int
-rbuffer_put(struct rbuffer* rb, char c);
-
-int
-rbuffer_puts(struct rbuffer* rb, char* c, size_t len);
-
-int
-rbuffer_gets(struct rbuffer* rb, char* buf, size_t len);
+static inline int
+rbuffer_put_nof(struct rbuffer* rb, char c)
+{
+ if (rbuffer_full(rb)) {
+ return 0;
+ }
-int
-rbuffer_get(struct rbuffer* rb, char* c);
+ return rbuffer_put(rb, c);
+}
#endif /* __LUNAIX_RBUFFER_H */
--- /dev/null
+#ifndef __LUNAIX_KPRINTF_H
+#define __LUNAIX_KPRINTF_H
+
+void kprintf_dump_logs();
+
+#endif /* __LUNAIX_KPRINTF_H */
+++ /dev/null
-#ifndef __LUNAIX_LXCONSOLE_H
-#define __LUNAIX_LXCONSOLE_H
-
-#define TCINTR 0x03 // ETX
-#define TCEOF 0x04 // EOT
-#define TCBS 0x08 // BS
-#define TCLF 0x0A // LF
-#define TCCR 0x0D // CR
-#define TCSTOP 0x1A // SUB
-
-void
-lxconsole_init();
-
-void
-console_write_str(char* str);
-
-void
-console_write_char(char chr);
-
-void
-console_view_up();
-
-void
-console_view_down();
-
-void
-console_flush();
-
-void
-console_start_flushing();
-#endif /* __LUNAIX_LXCONSOLE_H */
#include <lunaix/ds/ldga.h>
-#define call_on_earlyboot c_earlyboot
-#define call_on_boot c_boot
-#define call_on_postboot c_postboot
+#define on_earlyboot c_earlyboot
+#define on_boot c_boot
+#define on_postboot c_postboot
-#define lunaix_initfn(func, call_stage) \
+#define owloysius_fetch_init(func, call_stage) \
export_ldga_el(lunainit, func, ptr_t, func); \
export_ldga_el_sfx(lunainit, func##_##call_stage, ptr_t, func, call_stage);
void
kprintf_m(const char* component, const char* fmt, va_list args);
-
-// TODO need more thought on it
-
-// struct klog_chunk
-// {
-// void* log_entry;
-// size_t max_len;
-// size_t len;
-// };
-
-// struct klog_chunk*
-// kprintf_lcstart_m(const char* component, size_t size);
-
-// void
-// kprintf_lcappend_m(struct klog_chunk*, const char* fmt, va_list args);
-
-// void
-// kprintf_lcdone_m(struct klog_chunk*);
-
#endif /* __LUNAIX_SYSLOG_H */
+++ /dev/null
-#ifndef __LUNAIX_CONSOLE_H
-#define __LUNAIX_CONSOLE_H
-
-#include <lunaix/ds/fifo.h>
-#include <lunaix/timer.h>
-
-struct console
-{
- struct lx_timer* flush_timer;
- struct fifo_buf output;
- struct fifo_buf input;
- size_t wnd_start;
- size_t lines;
-};
-
-#endif /* __LUNAIX_CONSOLE_H */
rb->ptr = (rb->ptr + 1) % rb->maxsz;
rb->len = MIN(rb->len + 1, rb->maxsz);
- return 1;
+ return rb->len < rb->maxsz;
}
int
if (!len)
return 0;
- size_t ptr = (rb->ptr + len) % rb->maxsz;
size_t nlen = MIN(len, rb->maxsz);
- size_t ptr_start = (ptr - nlen) % rb->maxsz;
+ size_t ptr = (rb->ptr + nlen) % rb->maxsz;
+ size_t ptr_start = rb->ptr;
buf = &buf[nlen];
if (ptr_start >= ptr) {
size_t llen = rb->maxsz - ptr_start;
memcpy(&rb->buffer[ptr_start], &buf[-nlen], llen);
- memcpy(&rb->buffer[0], &buf[-nlen + llen], ptr + 1);
+ memcpy(&rb->buffer[0], &buf[-nlen + llen], ptr);
} else {
memcpy(&rb->buffer[ptr_start], &buf[-nlen], nlen);
}
rb->ptr = ptr;
- rb->len = nlen;
+ rb->len = MIN(rb->len + nlen, rb->maxsz);
return nlen;
}
if (ptr_start >= ptr_end) {
size_t llen = rb->maxsz - ptr_start;
memcpy(&buf[-nlen], &rb->buffer[ptr_start], llen);
- memcpy(&buf[-nlen + llen], &rb->buffer[0], ptr_end + 1);
+ memcpy(&buf[-nlen + llen], &rb->buffer[0], ptr_end);
} else {
memcpy(&buf[-nlen], &rb->buffer[ptr_start], nlen);
}
char buf[VFS_NAME_MAXLEN];
size_t len = ksnprintfv(buf, fmt, VFS_NAME_MAXLEN, args);
- return __twifs_new_node(parent ? parent : fs_root, buf, len, VFS_IFSEQDEV);
+ return __twifs_new_node(parent ? parent : fs_root, buf, len, F_FILE);
}
struct twifs_node*
file->inode->atime = clock_unixtime();
if ((file->inode->itype & VFS_IFSEQDEV) || (fd_s->flags & FO_DIRECT)) {
- errno = file->ops->read(file->inode, buf, count, file->f_pos);
+ errno = file->ops->read(file->inode, buf, count, file->f_pos);
} else {
errno = pcache_read(file->inode, buf, count, file->f_pos);
}
#include <lunaix/foptions.h>
#include <lunaix/fs/twifs.h>
#include <lunaix/input.h>
-#include <lunaix/lxconsole.h>
#include <lunaix/mm/cake.h>
#include <lunaix/mm/mmio.h>
#include <lunaix/mm/page.h>
device_scan_drivers();
- // crt
+ invoke_init_function(on_earlyboot);
+
+ // FIXME this goes to hal/gfxa
tty_init(ioremap(0xB8000, PG_SIZE));
tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
- lxconsole_init();
device_sysconf_load();
must_success(vfs_mount_root("ramfs", NULL));
must_success(vfs_mount("/dev", "devfs", NULL, 0));
- invoke_init_function(call_on_boot);
+ invoke_init_function(on_boot);
must_success(vfs_unmount("/dev"));
EXPORT_TWIFS_PLUGIN(kprintf, kprintf_mapping_init);
-static void kprintf_init() {
+void
+kprintf_dump_logs() {
if (unlikely(!sysconsole)) {
return;
}
sysconsole->ops.write(sysconsole, pos->content, 0, pos->len);
}
}
-lunaix_initfn(kprintf_init, call_on_postboot);
__DEFINE_LXSYSCALL3(void, syslog, int, level, const char*, fmt, va_list, args)
{
init_platform()
{
device_postboot_load();
- invoke_init_function(call_on_postboot);
+ invoke_init_function(on_postboot);
twifs_register_plugins();
#include <klibc/string.h>
#include <lunaix/spike.h>
-#include <lunaix/tty/console.h>
#include <lunaix/tty/tty.h>
#include <stdint.h>
tty_clear();
char chr;
- int state = 0;
- int g[2] = { 0, 0 };
- vga_attribute current_theme = tty_theme_color;
while (fifo_readone_async(buf, (u8_t*)&chr)) {
- if (state == 0 && chr == '\033') {
- state = 1;
- } else if (state == 1 && chr == '[') {
- state = 2;
- } else if (state > 1) {
- if ('0' <= chr && chr <= '9') {
- g[state - 2] = (chr - '0') + g[state - 2] * 10;
- } else if (chr == ';' && state == 2) {
- state = 3;
- } else {
- if (g[0] == 39 && g[1] == 49) {
- current_theme = tty_theme_color;
- } else {
- current_theme = (g[1] << 4 | g[0]) << 8;
- }
- g[0] = 0;
- g[1] = 0;
- state = 0;
- }
- } else {
- state = 0;
- switch (chr) {
- case '\t':
- x += 4;
- break;
- case '\n':
- y++;
- // fall through
- case '\r':
- x = 0;
- break;
- // case '\x08':
- // *(tty_vga_buffer + x + y * TTY_WIDTH) =
- // (current_theme | 0x20);
- // break;
- default:
- *(tty_vga_buffer + x + y * TTY_WIDTH) =
- (current_theme | chr);
- (x)++;
- break;
- }
-
- if (x >= TTY_WIDTH) {
- x = 0;
+ switch (chr) {
+ case '\t':
+ x += 4;
+ break;
+ case '\n':
y++;
- }
- if (y >= TTY_HEIGHT) {
- y--;
+ // fall through
+ case '\r':
+ x = 0;
+ break;
+ default:
+ *(tty_vga_buffer + x + y * TTY_WIDTH) =
+ (tty_theme_color | chr);
+ (x)++;
break;
- }
+ }
+
+ if (x >= TTY_WIDTH) {
+ x = 0;
+ y++;
+ }
+ if (y >= TTY_HEIGHT) {
+ y--;
+ break;
}
}
+
tty_set_cursor(x, y);
}
. = ALIGN(8);
- PROVIDE(__lga_lunainit_call_on_boot_start = .);
+ PROVIDE(__lga_lunainit_on_earlyboot_start = .);
+
+ KEEP(*(.lga.lunainit.c_earlyboot));
+
+ PROVIDE(__lga_lunainit_on_earlyboot_end = .);
+
+ /* ---- */
+
+ . = ALIGN(8);
+
+ PROVIDE(__lga_lunainit_on_boot_start = .);
KEEP(*(.lga.lunainit.c_boot));
- PROVIDE(__lga_lunainit_call_on_boot_end = .);
+ PROVIDE(__lga_lunainit_on_boot_end = .);
/* ---- */
. = ALIGN(8);
- PROVIDE(__lga_lunainit_call_on_postboot_start = .);
+ PROVIDE(__lga_lunainit_on_postboot_start = .);
KEEP(*(.lga.lunainit.c_postboot));
- PROVIDE(__lga_lunainit_call_on_postboot_end = .);
+ PROVIDE(__lga_lunainit_on_postboot_end = .);
}
-fno-indirect-inlining\
-fno-omit-frame-pointer
-CFLAGS := $(ARCH_OPT) -std=gnu99 -MMD $(OFLAGS) $(W)
+CFLAGS := $(ARCH_OPT) -std=gnu99 $(OFLAGS) $(W)
ifeq ($(BUILD_MODE),debug)
O = -Og
--- /dev/null
+init
+sh
\ No newline at end of file
+++ /dev/null
-define src_files
- main.c
-endef
-
-obj_files := $(addsuffix .o,$(src_files))
-include_opt := $(addprefix -I,$(INCLUDES))
-
-out := $(BUILD_DIR)/bin
-
-%.c.o: %.c
- $(call status_,CC,$<)
- @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
-
-$(out)/$(BUILD_NAME): $(obj_files)
- $(call status_,LD,$(@F))
- @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
-
-all: $(out)/$(BUILD_NAME)
-
-clean:
- @rm -f $(obj_files)
\ No newline at end of file
--- /dev/null
+testp
+ls
+signal_demo
+cat
+stat
\ No newline at end of file
} \
} while (0)
-#define check(statement) \
- do { \
+#define check(statement) \
+ ({ \
int err = 0; \
- if ((err = (statement))) { \
- syslog(2, #statement " failed: %d", err); \
- return err; \
+ if ((err = (statement)) < 0) { \
+ syslog(2, #statement " failed: %d", err); \
+ _exit(1); \
} \
- } while (0)
+ err; \
+ })
int
init_termios(int fd) {
term.c_iflag = ICRNL | IGNBRK;
term.c_oflag = ONLCR | OPOST;
term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
- term.c_cc[VERASE] = 0x08;
+ term.c_cc[VERASE] = 0x7f;
check(tcsetattr(fd, 0, &term));
int
main(int argc, const char** argv)
{
- int err = 0;
mkdir("/dev");
mkdir("/sys");
must_mount(NULL, "/sys", "twifs", MNT_RO);
must_mount(NULL, "/task", "taskfs", MNT_RO);
- if ((err = open("/dev/tty", 0)) < 0) {
- syslog(2, "fail to open tty (%d)\n", errno);
- return err;
- }
+ int fd = check(open("/dev/tty", 0));
- check(init_termios(err));
+ check(init_termios(fd));
- if ((err = dup(err)) < 0) {
- syslog(2, "fail to setup tty i/o (%d)\n", errno);
- return err;
- }
+ check(dup(fd));
- if ((err = symlink("/usr", "/mnt/lunaix-os/usr"))) {
- syslog(2, "symlink /usr:/mnt/lunaix-os/usr (%d)\n", errno);
- return err;
- }
+ check(symlink("/usr", "/mnt/lunaix-os/usr"));
pid_t pid;
+ int err = 0;
if (!(pid = fork())) {
err = execve("/usr/bin/sh", NULL, NULL);
printf("fail to execute (%d)\n", errno);
+++ /dev/null
-define src_files
- ls.c
-endef
-
-obj_files := $(addsuffix .o,$(src_files))
-include_opt := $(addprefix -I,$(INCLUDES))
-
-out := $(BUILD_DIR)/bin
-
-%.c.o: %.c
- $(call status_,CC,$<)
- @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
-
-$(out)/$(BUILD_NAME): $(obj_files)
- $(call status_,LD,$(@F))
- @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
-
-all: $(out)/$(BUILD_NAME)
-
-clean:
- @rm -f $(obj_files)
\ No newline at end of file
build_dir := $(CURDIR)/build
libc_name := liblunac
libc_files := $(libc_name).a
+libc := $(addprefix $(build_dir)/lib/,$(libc_files))
+ldscript := $(CURDIR)/link-usr.ld
common_param := CC AR INCLUDES BUILD_DIR BUILD_NAME CFLAGS LDFLAGS
$(call status,TASK,$(BUILD_NAME))
@$(MAKE) $(MKFLAGS) -C libc/ $(task)
-app-list := ls
-app-list += init
-app-list += signal_demo
-app-list += sh
-app-list += cat
-app-list += testp
-app-list += stat
+app-list = $(shell cat apps.list)
+exec-list = $(shell cat execs.list)
mkapp-list := $(addprefix app-, $(app-list))
+mkexec-list := $(addprefix $(build_dir)/bin/, $(exec-list))
-export LD_SCRIPT := $(CURDIR)/link-usr.ld
-export LIBC := $(addprefix $(build_dir)/lib/,$(libc_files))
+export LD_SCRIPT := $(ldscript)
+export LIBC := $(libc)
app-%:
$(call status,TASK,$*)
@$(MAKE) $(MKFLAGS) -C $* $(task) BUILD_NAME="$*"
+exec_%.o: %.c
+ $(call status,CC,$<)
+ @$(CC) $(CFLAGS) $(addprefix -I,$(INCLUDES)) -c $< -o $@
+
+$(build_dir)/bin/%: exec_%.o
+ $(call status,LD,$(@F))
+ @$(CC) -T $(ldscript) -o $@ $< $(libc) $(LDFLAGS)
+
app: task := all
app: INCLUDES += $(build_dir)/includes
app: $(mkapp-list)
+exec: task := all
+exec: INCLUDES += $(build_dir)/includes
+exec: $(mkexec-list)
+
clean: task := clean
clean: $(mkapp-list)
@rm -rf $(build_dir)
@$(MAKE) $(MKFLAGS) -C libc/ $(task)
all: task := all
-all: $(build_dir)/$(libc_name).a app
\ No newline at end of file
+all: $(build_dir)/$(libc_name).a exec app
\ No newline at end of file
+++ /dev/null
-define src_files
- signal_demo.c
-endef
-
-obj_files := $(addsuffix .o,$(src_files))
-include_opt := $(addprefix -I,$(INCLUDES))
-
-out := $(BUILD_DIR)/bin
-
-%.c.o: %.c
- $(call status_,CC,$<)
- @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
-
-$(out)/$(BUILD_NAME): $(obj_files)
- $(call status_,LD,$(@F))
- @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
-
-all: $(out)/$(BUILD_NAME)
-
-clean:
- @rm -f $(obj_files)
\ No newline at end of file
+++ /dev/null
-define src_files
- main.c
-endef
-
-obj_files := $(addsuffix .o,$(src_files))
-include_opt := $(addprefix -I,$(INCLUDES))
-
-out := $(BUILD_DIR)/bin
-
-%.c.o: %.c
- $(call status_,CC,$<)
- @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
-
-$(out)/$(BUILD_NAME): $(obj_files)
- $(call status_,LD,$(@F))
- @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
-
-all: $(out)/$(BUILD_NAME)
-
-clean:
- @rm -f $(obj_files)
\ No newline at end of file
+++ /dev/null
-define src_files
- main.c
-endef
-
-obj_files := $(addsuffix .o,$(src_files))
-include_opt := $(addprefix -I,$(INCLUDES))
-
-out := $(BUILD_DIR)/bin
-
-%.c.o: %.c
- $(call status_,CC,$<)
- @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
-
-$(out)/$(BUILD_NAME): $(obj_files)
- $(call status_,LD,$(@F))
- @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
-
-all: $(out)/$(BUILD_NAME)
-
-clean:
- @rm -f $(obj_files)
\ No newline at end of file