fix: corner cases when printing large content through term interface
authorMinep <lunaixsky@qq.com>
Mon, 11 Dec 2023 19:43:48 +0000 (19:43 +0000)
committerMinep <lunaixsky@qq.com>
Mon, 11 Dec 2023 19:43:48 +0000 (19:43 +0000)
refactor: make usr/ compilation more clean
refactor: clean up unused header files
refactor: renamed things

40 files changed:
lunaix-os/arch/i386/exceptions/intr_routines.c
lunaix-os/hal/char/lxconsole.c [moved from lunaix-os/kernel/tty/lxconsole.c with 85% similarity]
lunaix-os/hal/char/serial.c
lunaix-os/hal/term/console.c
lunaix-os/hal/term/lcntls/ansi_cntl.c
lunaix-os/hal/term/lcntls/lcntl.c
lunaix-os/hal/term/term.c
lunaix-os/hal/term/term_io.c
lunaix-os/includes/hal/term.h
lunaix-os/includes/lunaix/compiler.h
lunaix-os/includes/lunaix/ds/ldga.h
lunaix-os/includes/lunaix/ds/rbuffer.h
lunaix-os/includes/lunaix/kprintf.h [new file with mode: 0644]
lunaix-os/includes/lunaix/lxconsole.h [deleted file]
lunaix-os/includes/lunaix/owloysius.h
lunaix-os/includes/lunaix/syslog.h
lunaix-os/includes/lunaix/tty/console.h [deleted file]
lunaix-os/kernel/ds/rbuffer.c
lunaix-os/kernel/fs/twifs/twifs.c
lunaix-os/kernel/fs/vfs.c
lunaix-os/kernel/kinit.c
lunaix-os/kernel/kprint/kprintf.c
lunaix-os/kernel/proc0.c
lunaix-os/kernel/tty/tty.c
lunaix-os/link/linker.ld
lunaix-os/makeinc/toolchain.mkinc
lunaix-os/usr/apps.list [new file with mode: 0644]
lunaix-os/usr/cat.c [moved from lunaix-os/usr/cat/main.c with 100% similarity]
lunaix-os/usr/cat/makefile [deleted file]
lunaix-os/usr/execs.list [new file with mode: 0644]
lunaix-os/usr/init/init.c
lunaix-os/usr/ls.c [moved from lunaix-os/usr/ls/ls.c with 100% similarity]
lunaix-os/usr/ls/makefile [deleted file]
lunaix-os/usr/makefile
lunaix-os/usr/signal_demo.c [moved from lunaix-os/usr/signal_demo/signal_demo.c with 100% similarity]
lunaix-os/usr/signal_demo/makefile [deleted file]
lunaix-os/usr/stat.c [moved from lunaix-os/usr/stat/main.c with 100% similarity]
lunaix-os/usr/stat/makefile [deleted file]
lunaix-os/usr/testp.c [moved from lunaix-os/usr/testp/main.c with 100% similarity]
lunaix-os/usr/testp/makefile [deleted file]

index 77a13722f0373a61b15d5c00d83263c5f88b7de0..91366bf9080fb3da553a7dbc272eaac13889c667 100644 (file)
@@ -1,7 +1,6 @@
 #include <sys/interrupts.h>
 
 #include <lunaix/isrm.h>
 #include <sys/interrupts.h>
 
 #include <lunaix/isrm.h>
-#include <lunaix/lxconsole.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
@@ -32,7 +31,6 @@ intr_routine_divide_zero(const isr_param* param)
 {
     __print_panic_msg("div zero", param);
 
 {
     __print_panic_msg("div zero", param);
 
-    console_flush();
     spin();
 }
 
     spin();
 }
 
@@ -41,7 +39,6 @@ intr_routine_general_protection(const isr_param* param)
 {
     __print_panic_msg("general protection", param);
 
 {
     __print_panic_msg("general protection", param);
 
-    console_flush();
     spin();
 }
 
     spin();
 }
 
@@ -50,7 +47,6 @@ intr_routine_sys_panic(const isr_param* param)
 {
     __print_panic_msg((char*)(param->registers.edi), param);
 
 {
     __print_panic_msg((char*)(param->registers.edi), param);
 
-    console_flush();
     spin();
 }
 
     spin();
 }
 
@@ -59,7 +55,6 @@ intr_routine_fallback(const isr_param* param)
 {
     __print_panic_msg("unknown interrupt", param);
 
 {
     __print_panic_msg("unknown interrupt", param);
 
-    console_flush();
     spin();
 }
 
     spin();
 }
 
@@ -83,7 +78,6 @@ intr_routine_apic_error(const isr_param* param)
 
     __print_panic_msg(buf, param);
 
 
     __print_panic_msg(buf, param);
 
-    console_flush();
     spin();
 }
 
     spin();
 }
 
similarity index 85%
rename from lunaix-os/kernel/tty/lxconsole.c
rename to lunaix-os/hal/char/lxconsole.c
index 2540077437f6befe919880b4ee5126984a073271..53d01bbb50810360e3103eb6efadaa1e3510aaef 100644 (file)
 #include <lunaix/input.h>
 #include <lunaix/ioctl.h>
 #include <lunaix/keyboard.h>
 #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/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/tty/tty.h>
+#include <lunaix/ds/fifo.h>
+#include <lunaix/owloysius.h>
 
 #include <hal/term.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
 static struct console lx_console;
 
 int
@@ -39,6 +48,12 @@ console_write(struct console* console, u8_t* data, size_t size);
 void
 console_flush();
 
 void
 console_flush();
 
+void
+console_view_up();
+
+void
+console_view_down();
+
 static waitq_t lx_reader;
 
 static volatile pid_t fg_pgid = 0;
 static waitq_t lx_reader;
 
 static volatile pid_t fg_pgid = 0;
@@ -81,42 +96,6 @@ done:
     return INPUT_EVT_NEXT;
 }
 
     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)
 {
 int
 __tty_write_pg(struct device* dev, void* buf, size_t offset)
 {
@@ -153,12 +132,6 @@ __tty_read(struct device* dev, void* buf, size_t offset, size_t len)
     return count + fifo_read(&console->input, buf + count, len - count);
 }
 
     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)
 {
 size_t
 __find_next_line(size_t start)
 {
@@ -286,13 +259,17 @@ console_write_char(char str)
     console_write(&lx_console, (u8_t*)&str, 1);
 }
 
     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)
 
 static int
 lxconsole_spawn_ttydev(struct device_def* devdef)
@@ -302,7 +279,6 @@ 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.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);
 
     waitq_init(&lx_reader);
     input_add_listener(__lxconsole_listener);
index d93ff398b81231019595c332bf8daaae1ad5e1a6..826b3a6d5984a90166e52bd89bcc12532e68b77c 100644 (file)
@@ -1,6 +1,7 @@
 #include <lunaix/device.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 #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>
 #include <lunaix/status.h>
 
 #include <sys/mm/mempart.h>
@@ -20,6 +21,8 @@
 static DEFINE_LLIST(serial_devs);
 static int serial_idx = 0;
 
 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
 #define serial_device(dev) ((struct serial_dev*)(dev)->underlay)
 
 int
@@ -239,7 +242,7 @@ struct serial_dev*
 serial_create(struct devclass* class, char* if_ident)
 {
     struct serial_dev* sdev = valloc(sizeof(struct serial_dev));
 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;
     dev->ops.read = __serial_read;
     dev->ops.read_page = __serial_read_page;
     dev->ops.read_async = __serial_read_async;
@@ -264,7 +267,7 @@ serial_create(struct devclass* class, char* if_ident)
     
     device_grant_capability(dev, cap_meta(tp_cap));
 
     
     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);
 
 
     term_create(dev, if_ident);
 
@@ -284,4 +287,13 @@ serial_get_avilable()
     }
 
     return NULL;
     }
 
     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
index 7d9b57ba5381970a7f991213902ea56f85ed956f..1c2a2cf83497d6fbb7521f5f551dacbd47042fac 100644 (file)
@@ -4,6 +4,7 @@
 #include <lunaix/kcmd.h>
 #include <lunaix/fs.h>
 #include <lunaix/syslog.h>
 #include <lunaix/kcmd.h>
 #include <lunaix/fs.h>
 #include <lunaix/syslog.h>
+#include <lunaix/kprintf.h>
 
 #include <hal/term.h>
 
 
 #include <hal/term.h>
 
@@ -41,5 +42,7 @@ setup_default_tty()
     INFO("system console: %s", console_dev);
 
     sysconsole = dev;
     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
index 112f719b7fc74298ce0fc640d69ef5553c07520d..778eb4b5d24d931a79f3ae51beb47bca097b6a64 100644 (file)
@@ -22,12 +22,12 @@ __ansi_actcontrol(struct term* termdev, struct linebuffer* lbuf, char chr)
         default:
             if ((int)chr < 32) {
                 rbuffer_put(cooked, '^');
         default:
             if ((int)chr < 32) {
                 rbuffer_put(cooked, '^');
-                chr += 64;
+                return rbuffer_put(cooked, chr += 64);
             }
             break;
     }
 
             }
             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
 }
 
 struct term_lcntl ansi_line_controller = {.process_and_put = __ansi_actcontrol};
\ No newline at end of file
index 08023183ecab1f637d704e7d66e09a62662367c2..de3334cbb408e02830a5c0289b533d24856d5a20 100644 (file)
@@ -44,6 +44,13 @@ lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
 #define QUIT tdev->cc[_VQUIT]
 #define SUSP tdev->cc[_VSUSP]
 
 #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++) {
     if (!out) {
         // Keep all cc's (except VMIN & VTIME) up to L2 cache.
         for (size_t i = 0; i < _VMIN; i++) {
@@ -51,7 +58,7 @@ lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
         }
     }
 
         }
     }
 
-    while (rbuffer_get(raw, &c) && allow_more) {
+    while (allow_more && rbuffer_get(raw, &c)) {
 
         if (c == '\r' && ((_if & _ICRNL) || (_of & _OCRNL))) {
             c = '\n';
 
         if (c == '\r' && ((_if & _ICRNL) || (_of & _OCRNL))) {
             c = '\n';
@@ -136,14 +143,14 @@ lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
 
     do_out:
         if (c == '\n' && (_of & _ONLCR)) {
 
     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 {
         }
 
     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);
         }
     }
 
         }
     }
 
index 3cc9741cce9ca47e00bb40801d7283c6580185a4..3db875903761375fd575a265662659279fd9d4df 100644 (file)
@@ -136,7 +136,7 @@ tdev_do_write(struct device* dev, void* buf, off_t fpos, size_t len)
     if (!rbuffer_empty(deref(current))) {
         term_flush(tdev);
     }
     if (!rbuffer_empty(deref(current))) {
         term_flush(tdev);
     }
-    return 0;
+    return wrsz;
 }
 
 static int
 }
 
 static int
@@ -170,6 +170,14 @@ load_default_setting(struct term* tdev)
     memcpy(tdev->cc, default_cc, _NCCS * sizeof(cc_t));
 }
 
     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)
 {
 struct term*
 term_create(struct device* chardev, char* suffix)
 {
@@ -189,8 +197,7 @@ term_create(struct device* chardev, char* suffix)
     // TODO choice of lcntl can be flexible
     terminal->lcntl = line_controls[ANSI_LCNTL];
 
     // 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);
 
     if (chardev) {
         int cdev_var = DEV_VAR_FROM(chardev->ident.unique);
index 835659dec048a70c61a2b14a8043e581e31c635c..57602c81f423abe2bf250101f870210ee7689001 100644 (file)
@@ -93,26 +93,35 @@ term_read(struct term* tdev)
 int
 term_flush(struct term* tdev)
 {
 int
 term_flush(struct term* tdev)
 {
-    if ((tdev->oflags & _OPOST)) {
-        lcntl_transform_outseq(tdev);
-    }
-
     struct linebuffer* line_out = &tdev->line_out;
     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
 }
\ No newline at end of file
index 0f11e525bac5ce73e15684fd55e9b4e06b609de9..4ddf74d38066b18dd4ea6d55cdf9e201f9a5a107 100644 (file)
@@ -61,6 +61,7 @@ struct term
     struct term_lcntl* lcntl;
     struct linebuffer line_out;
     struct linebuffer line_in;
     struct term_lcntl* lcntl;
     struct linebuffer line_out;
     struct linebuffer line_in;
+    char* scratch_pad;
     pid_t fggrp;
 
     struct termport_capability* tp_cap;
     pid_t fggrp;
 
     struct termport_capability* tp_cap;
index 75819785a212fa47fa656e4d366714983074197c..6c33779c81c3407b5f1beff723846230d32019ce 100644 (file)
@@ -10,6 +10,7 @@
 #define optimize(opt) __attribute__((optimize(opt)))
 #define must_inline __attribute__((always_inline))
 #define must_emit __attribute__((used))
 #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)
 
 #define clz(bits) __builtin_clz(bits)
 #define sadd_overflow(a, b, of) __builtin_sadd_overflow(a, b, of)
@@ -34,7 +35,7 @@ spin()
     volatile int __infloop = 1;
     while (__infloop)
         ;
     volatile int __infloop = 1;
     while (__infloop)
         ;
-    __builtin_unreachable();
+    unreachable;
 }
 
 #endif /* __LUNAIX_COMPILER_H */
 }
 
 #endif /* __LUNAIX_COMPILER_H */
index 8c00bbe12745d8c4e0eac421f13ee33a5f9d1979..a9b1430662fbebece728b1757744860d1422643e 100644 (file)
 #define __LUNAIX_LDGA_H
 
 #include <lunaix/types.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)                            \
 
 #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)                \
 
 #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)                              \
       (type)(val)
 
 #define export_ldga_el_idx(ga_name, i, type, val)                              \
index f3777b6f6b45b0f5b00c410fe698ed89a3143b32..d45c9fdf0e405f6aea9889c987fea36e1165e5a0 100644 (file)
@@ -20,6 +20,22 @@ rbuffer_init(struct rbuffer* rb, char* buf, size_t maxsz)
 struct rbuffer*
 rbuffer_create(char* buf, size_t maxsz);
 
 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)
 {
 static inline void
 rbuffer_clear(struct rbuffer* rb)
 {
@@ -38,19 +54,14 @@ rbuffer_full(struct rbuffer* rb)
     return rb->len == rb->maxsz;
 }
 
     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 */
 
 #endif /* __LUNAIX_RBUFFER_H */
diff --git a/lunaix-os/includes/lunaix/kprintf.h b/lunaix-os/includes/lunaix/kprintf.h
new file mode 100644 (file)
index 0000000..84fef64
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __LUNAIX_KPRINTF_H
+#define __LUNAIX_KPRINTF_H
+
+void kprintf_dump_logs();
+
+#endif /* __LUNAIX_KPRINTF_H */
diff --git a/lunaix-os/includes/lunaix/lxconsole.h b/lunaix-os/includes/lunaix/lxconsole.h
deleted file mode 100644 (file)
index fbf59a4..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#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 */
index 79480660772f63a1c2c36415326b5e82e6f23edd..c1f8584141c8b623e7607b0903af6acd45e63152 100644 (file)
@@ -3,11 +3,11 @@
 
 #include <lunaix/ds/ldga.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);
 
     export_ldga_el(lunainit, func, ptr_t, func);                            \
     export_ldga_el_sfx(lunainit, func##_##call_stage, ptr_t, func, call_stage);
 
index 487785762d1aa8542adf0a2effcc92dc790798e7..423823cc3d7335a64eb582e75b862e250bee3bd4 100644 (file)
 
 void
 kprintf_m(const char* component, const char* fmt, va_list args);
 
 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 */
 #endif /* __LUNAIX_SYSLOG_H */
diff --git a/lunaix-os/includes/lunaix/tty/console.h b/lunaix-os/includes/lunaix/tty/console.h
deleted file mode 100644 (file)
index 24d088f..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#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 */
index ab4dea50549c4c359f03a5c03e008a518377ef26..eea75d6e5b1d1f38df4098075a93200171b47301 100644 (file)
@@ -32,7 +32,7 @@ rbuffer_put(struct rbuffer* rb, char c)
     rb->ptr = (rb->ptr + 1) % rb->maxsz;
     rb->len = MIN(rb->len + 1, rb->maxsz);
 
     rb->ptr = (rb->ptr + 1) % rb->maxsz;
     rb->len = MIN(rb->len + 1, rb->maxsz);
 
-    return 1;
+    return rb->len < rb->maxsz;
 }
 
 int
 }
 
 int
@@ -41,21 +41,21 @@ rbuffer_puts(struct rbuffer* rb, char* buf, size_t len)
     if (!len)
         return 0;
 
     if (!len)
         return 0;
 
-    size_t ptr = (rb->ptr + len) % rb->maxsz;
     size_t nlen = MIN(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);
 
     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;
     } 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;
 }
 
     return nlen;
 }
@@ -74,7 +74,7 @@ rbuffer_gets(struct rbuffer* rb, char* buf, size_t len)
     if (ptr_start >= ptr_end) {
         size_t llen = rb->maxsz - ptr_start;
         memcpy(&buf[-nlen], &rb->buffer[ptr_start], llen);
     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);
     }
     } else {
         memcpy(&buf[-nlen], &rb->buffer[ptr_start], nlen);
     }
index 9d6d9f7189be246fd0ad1c8cb70b580d2aec671f..6aa5f6a8779b017de635a684a8fb6fee90c3b71d 100644 (file)
@@ -208,7 +208,7 @@ twifs_file_node_vargs(struct twifs_node* parent, const char* fmt, va_list args)
     char buf[VFS_NAME_MAXLEN];
     size_t len = ksnprintfv(buf, fmt, VFS_NAME_MAXLEN, args);
 
     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*
 }
 
 struct twifs_node*
index 28cede5e5a2ad44e2dc90487acb3dad79c98e93e..4ec74b402208c7cedd9f12c82f076dc4e41e164e 100644 (file)
@@ -708,7 +708,7 @@ __DEFINE_LXSYSCALL3(int, read, int, fd, void*, buf, size_t, count)
     file->inode->atime = clock_unixtime();
 
     if ((file->inode->itype & VFS_IFSEQDEV) || (fd_s->flags & FO_DIRECT)) {
     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);
     }
     } else {
         errno = pcache_read(file->inode, buf, count, file->f_pos);
     }
index 5884e5bb681e5cfc45b12a1025c7adecc1440488..a54b68a7adaf0e76ecc9e9410d0376ea9796e54a 100644 (file)
@@ -5,7 +5,6 @@
 #include <lunaix/foptions.h>
 #include <lunaix/fs/twifs.h>
 #include <lunaix/input.h>
 #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>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/page.h>
@@ -57,10 +56,11 @@ kernel_bootstrap(struct boot_handoff* bhctx)
 
     device_scan_drivers();
 
 
     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);
     tty_init(ioremap(0xB8000, PG_SIZE));
     tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
-    lxconsole_init();
 
     device_sysconf_load();
 
 
     device_sysconf_load();
 
@@ -89,7 +89,7 @@ kernel_bootstrap(struct boot_handoff* bhctx)
     must_success(vfs_mount_root("ramfs", NULL));
     must_success(vfs_mount("/dev", "devfs", NULL, 0));
     
     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"));
 
 
     must_success(vfs_unmount("/dev"));
 
index 310b1f67d1b8ba8da48a3b90fa88255ce42bd392..158a799ad5d4f8cf52b4f9d5274c1b1fda118883 100644 (file)
@@ -87,7 +87,8 @@ kprintf_mapping_init()
 EXPORT_TWIFS_PLUGIN(kprintf, kprintf_mapping_init);
 
 
 EXPORT_TWIFS_PLUGIN(kprintf, kprintf_mapping_init);
 
 
-static void kprintf_init() {
+void 
+kprintf_dump_logs() {
     if (unlikely(!sysconsole)) {
         return;
     }
     if (unlikely(!sysconsole)) {
         return;
     }
@@ -98,7 +99,6 @@ static void kprintf_init() {
         sysconsole->ops.write(sysconsole, pos->content, 0, pos->len);
     }
 }
         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)
 {
 
 __DEFINE_LXSYSCALL3(void, syslog, int, level, const char*, fmt, va_list, args)
 {
index a9d25a78cf186a27108c93b59e116ac07ca94226..a935a3b6f465cc5074728dace78deb59d709af58 100644 (file)
@@ -82,7 +82,7 @@ void
 init_platform()
 {
     device_postboot_load();
 init_platform()
 {
     device_postboot_load();
-    invoke_init_function(call_on_postboot);
+    invoke_init_function(on_postboot);
 
     twifs_register_plugins();
 
 
     twifs_register_plugins();
 
index 6f988552822e239af0d7903b3b71a12606c19816..e5a913f2c97256f76203c1ae29fa808c76596413 100644 (file)
@@ -1,6 +1,5 @@
 #include <klibc/string.h>
 #include <lunaix/spike.h>
 #include <klibc/string.h>
 #include <lunaix/spike.h>
-#include <lunaix/tty/console.h>
 #include <lunaix/tty/tty.h>
 #include <stdint.h>
 
 #include <lunaix/tty/tty.h>
 #include <stdint.h>
 
@@ -61,62 +60,34 @@ tty_flush_buffer(struct fifo_buf* buf)
     tty_clear();
 
     char chr;
     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)) {
     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++;
                 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;
                 break;
-            }
+        }
+
+        if (x >= TTY_WIDTH) {
+            x = 0;
+            y++;
+        }
+        if (y >= TTY_HEIGHT) {
+            y--;
+            break;
         }
     }
         }
     }
+
     tty_set_cursor(x, y);
 }
 
     tty_set_cursor(x, y);
 }
 
index c91bcb2100e728113e3c6e1f61aaed373ceb6ea5..3941b361697ad75987bf8f33170ff9eb41ecfa2b 100644 (file)
@@ -130,21 +130,31 @@ SECTIONS {
 
         . = ALIGN(8);
 
 
         . = 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));
 
         
         KEEP(*(.lga.lunainit.c_boot));
 
-        PROVIDE(__lga_lunainit_call_on_boot_end = .);
+        PROVIDE(__lga_lunainit_on_boot_end = .);
 
         /* ---- */
 
         . = ALIGN(8);
 
 
         /* ---- */
 
         . = ALIGN(8);
 
-        PROVIDE(__lga_lunainit_call_on_postboot_start = .);
+        PROVIDE(__lga_lunainit_on_postboot_start = .);
         
         KEEP(*(.lga.lunainit.c_postboot));
 
         
         KEEP(*(.lga.lunainit.c_postboot));
 
-        PROVIDE(__lga_lunainit_call_on_postboot_end = .);
+        PROVIDE(__lga_lunainit_on_postboot_end = .);
 
     }
 
 
     }
 
index 6882e8d9d64a4bb56b97ca17ed975a5a40e4638d..c63f84628550d752c914dbd19503e872e403cc68 100644 (file)
@@ -27,7 +27,7 @@ OFLAGS := -fno-gcse\
                  -fno-indirect-inlining\
                  -fno-omit-frame-pointer
 
                  -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
 
 ifeq ($(BUILD_MODE),debug)
        O = -Og
diff --git a/lunaix-os/usr/apps.list b/lunaix-os/usr/apps.list
new file mode 100644 (file)
index 0000000..cf7abdd
--- /dev/null
@@ -0,0 +1,2 @@
+init
+sh
\ No newline at end of file
similarity index 100%
rename from lunaix-os/usr/cat/main.c
rename to lunaix-os/usr/cat.c
diff --git a/lunaix-os/usr/cat/makefile b/lunaix-os/usr/cat/makefile
deleted file mode 100644 (file)
index 33802bd..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-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
diff --git a/lunaix-os/usr/execs.list b/lunaix-os/usr/execs.list
new file mode 100644 (file)
index 0000000..c661258
--- /dev/null
@@ -0,0 +1,5 @@
+testp
+ls
+signal_demo
+cat
+stat
\ No newline at end of file
index 0a2f5418a9de84eca57dcd9af649b7360ed167c7..5aebfcbdffe6673ffbdaa92c767095594d5efa5f 100644 (file)
         }                                                                      \
     } while (0)
 
         }                                                                      \
     } while (0)
 
-#define check(statement)                                      \
-    do {                                                                       \
+#define check(statement)                                                       \
+    ({                                                                         \
         int err = 0;                                                           \
         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) {
 
 int
 init_termios(int fd) {
@@ -34,7 +35,7 @@ init_termios(int fd) {
     term.c_iflag = ICRNL | IGNBRK;
     term.c_oflag = ONLCR | OPOST;
     term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
     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));
 
 
     check(tcsetattr(fd, 0, &term));
 
@@ -44,7 +45,6 @@ init_termios(int fd) {
 int
 main(int argc, const char** argv)
 {
 int
 main(int argc, const char** argv)
 {
-    int err = 0;
 
     mkdir("/dev");
     mkdir("/sys");
 
     mkdir("/dev");
     mkdir("/sys");
@@ -54,24 +54,16 @@ main(int argc, const char** argv)
     must_mount(NULL, "/sys", "twifs", MNT_RO);
     must_mount(NULL, "/task", "taskfs", MNT_RO);
 
     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;
 
     pid_t pid;
+    int err = 0;
     if (!(pid = fork())) {
         err = execve("/usr/bin/sh", NULL, NULL);
         printf("fail to execute (%d)\n", errno);
     if (!(pid = fork())) {
         err = execve("/usr/bin/sh", NULL, NULL);
         printf("fail to execute (%d)\n", errno);
similarity index 100%
rename from lunaix-os/usr/ls/ls.c
rename to lunaix-os/usr/ls.c
diff --git a/lunaix-os/usr/ls/makefile b/lunaix-os/usr/ls/makefile
deleted file mode 100644 (file)
index 5351d43..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-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
index e2a98d021d39aa23b9dc612e806599fc986a0fb9..e49d7d05ee68ffb5ef40046a86fa8a35c7112511 100644 (file)
@@ -7,6 +7,8 @@ sys_include := $(CURDIR)/includes
 build_dir := $(CURDIR)/build
 libc_name := liblunac
 libc_files := $(libc_name).a
 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
 
 
 common_param :=        CC AR INCLUDES BUILD_DIR BUILD_NAME CFLAGS LDFLAGS
 
@@ -28,30 +30,38 @@ $(build_dir)/$(libc_name).a: $(build_dir)/bin $(build_dir)/lib $(build_dir)/incl
        $(call status,TASK,$(BUILD_NAME))
        @$(MAKE) $(MKFLAGS) -C libc/ $(task)
 
        $(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))
 
 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="$*"
 
 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)
 
 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
 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
diff --git a/lunaix-os/usr/signal_demo/makefile b/lunaix-os/usr/signal_demo/makefile
deleted file mode 100644 (file)
index 1bb1248..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-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
diff --git a/lunaix-os/usr/stat/makefile b/lunaix-os/usr/stat/makefile
deleted file mode 100644 (file)
index 33802bd..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-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
diff --git a/lunaix-os/usr/testp/makefile b/lunaix-os/usr/testp/makefile
deleted file mode 100644 (file)
index 33802bd..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-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