From 87fa53c543531231cd54ab4857d5e21f76555265 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Thu, 7 Apr 2011 22:52:57 -0700 Subject: core: declare jiffies_t and mstime_t and use them. Create specific types for jiffies and for the output of the millisecond timer and use them where appropriate in the code base. Signed-off-by: Eric W. Biederman --- core/include/core.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index 114b049a..a593c268 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -65,12 +65,15 @@ __noreturn _kaboom(void); /* * Basic timer function... */ -extern volatile uint32_t __jiffies, __ms_timer; -static inline uint32_t jiffies(void) +typedef uint32_t jiffies_t; +extern volatile jiffies_t __jiffies, __ms_timer; +static inline jiffies_t jiffies(void) { return __jiffies; } -static inline uint32_t ms_timer(void) +typedef uint32_t mstime_t; +typedef int32_t mstimediff_t; +static inline mstime_t ms_timer(void) { return __ms_timer; } -- cgit v1.2.1 From 884e5778c9b66b943eb02d8437bc0b26a219e2ec Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 8 Sep 2009 21:06:34 -0700 Subject: core: simple thread library Simple thread library with the intent of making lwIP easier to port. -- Modified to use milliseconds instead of jiffies, as lwIP expresses everything in milliseconds. EWB Signed-off-by: H. Peter Anvin Signed-off-by: Eric W. Biederman --- core/include/thread.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core/include/thread.h (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h new file mode 100644 index 00000000..917c36a6 --- /dev/null +++ b/core/include/thread.h @@ -0,0 +1,84 @@ +#ifndef _THREAD_H +#define _THREAD_H + +#include +#include +#include "core.h" + +struct semaphore; + +struct thread_state { + uint32_t ebx, esp, ebp, esi, edi; +}; + +struct thread_list { + struct thread_list *next, *prev; +}; + +struct thread_block { + struct thread_list list; + struct thread *thread; + struct semaphore *semaphore; + mstime_t block_time; + mstime_t timeout; + bool timed_out; +}; + +struct thread { + struct thread_state state; + struct thread_list list; + struct thread_block *blocked; + int prio; +}; + +void __schedule(void); +void __switch_to(struct thread *); +void thread_yield(void); + +extern struct thread *__current; +static inline struct thread *current(void) +{ + return __current; +} + +struct semaphore { + int count; + struct thread_list list; +}; + +mstime_t sem_down(struct semaphore *, mstime_t); +void sem_up(struct semaphore *); +void sem_init(struct semaphore *, int); + +typedef unsigned long irq_state_t; + +static inline irq_state_t irq_state(void) +{ + irq_state_t __st; + + asm volatile("pushfl ; popl %0" : "=rm" (__st)); + return __st; +} + +static inline irq_state_t irq_save(void) +{ + irq_state_t __st; + + asm volatile("pushfl ; popl %0 ; cli" : "=rm" (__st)); + return __st; +} + +static inline void irq_restore(irq_state_t __st) +{ + asm volatile("pushl %0 ; popfl" : : "rm" (__st)); +} + +void start_thread(struct thread *t, void *stack, size_t stack_size, int prio, + void (*start_func)(void *), void *func_arg); +void __exit_thread(void); +void kill_thread(struct thread *); + +void start_idle_thread(void); +void test_thread(void); + +#endif /* _THREAD_H */ -- cgit v1.2.1 From 0c44fcf078132b1f2915b7df9fcf4724f9d96b23 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 9 Sep 2009 09:07:58 -0700 Subject: core: thread: have start_thread() allocate memory dynamically Have start_thread() allocate memory dynamically, using malloc(). XXX: should probably free that memory in __exit_thread()... could be "interesting". Signed-off-by: H. Peter Anvin --- core/include/thread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 917c36a6..514c30be 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -73,8 +73,8 @@ static inline void irq_restore(irq_state_t __st) asm volatile("pushl %0 ; popfl" : : "rm" (__st)); } -void start_thread(struct thread *t, void *stack, size_t stack_size, int prio, - void (*start_func)(void *), void *func_arg); +struct thread *start_thread(size_t stack_size, int prio, + void (*start_func)(void *), void *func_arg); void __exit_thread(void); void kill_thread(struct thread *); -- cgit v1.2.1 From f7de2806b8fe4acbcec64a3084bfecf002d72a5c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 9 Sep 2009 12:25:04 -0700 Subject: core: add simple mailbox library A very simple mailbox library, designed for lwIP porting. Signed-off-by: H. Peter Anvin --- core/include/mbox.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 core/include/mbox.h (limited to 'core/include') diff --git a/core/include/mbox.h b/core/include/mbox.h new file mode 100644 index 00000000..ac139ff5 --- /dev/null +++ b/core/include/mbox.h @@ -0,0 +1,24 @@ +/* + * mbox.h + * + * Simple thread mailbox interface + */ + +#ifndef _MBOX_H +#define _MBOX_H + +#include "thread.h" + +struct mailbox { + struct semaphore prod_sem; /* Producer semaphore (empty slots) */ + struct semaphore cons_sem; /* Consumer semaphore (data slots) */ + struct semaphore head_sem; /* Head pointer semaphore */ + struct semaphore tail_sem; /* Tail pointer semaphore */ + void **wrap; /* Where pointers wrap */ + void **head; /* Head pointer */ + void **tail; /* Tail pointer */ + + void *data[]; /* Data array */ +}; + +#endif /* _MBOX_H */ -- cgit v1.2.1 From c565a5f27c2a4d341bf6f800230a282489d5c164 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 9 Sep 2009 16:29:15 -0700 Subject: core: thread: merge mbox_post() and mbox_trypost() Merge mbox_post() and mbox_trypost() into a single function with a timeout parameter. Signed-off-by: H. Peter Anvin --- core/include/mbox.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/include') diff --git a/core/include/mbox.h b/core/include/mbox.h index ac139ff5..9b927a0b 100644 --- a/core/include/mbox.h +++ b/core/include/mbox.h @@ -21,4 +21,8 @@ struct mailbox { void *data[]; /* Data array */ }; +void mbox_init(struct mailbox *mbox, size_t size); +int mbox_post(struct mailbox *mbox, void *msg, mstime_t timeout); +mstime_t mbox_fetch(struct mailbox *mbox, void **msg, mstime_t timeout); + #endif /* _MBOX_H */ -- cgit v1.2.1 From 6f2535876ff37db8a4a215f0e06a88b2671be0bc Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 9 Sep 2009 21:34:28 -0700 Subject: core: thread: move most thread state to stack; task switch errno Move most our thread state to the stack. Task switch the errno variable. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 514c30be..e644b9fa 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -7,10 +7,6 @@ struct semaphore; -struct thread_state { - uint32_t ebx, esp, ebp, esi, edi; -}; - struct thread_list { struct thread_list *next, *prev; }; @@ -25,7 +21,7 @@ struct thread_block { }; struct thread { - struct thread_state state; + void *esp; /* Must be first; stack pointer */ struct thread_list list; struct thread_block *blocked; int prio; -- cgit v1.2.1 From 5cf65b7ca34bd3638603b16b4ef2cef1345354a5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 9 Sep 2009 22:24:55 -0700 Subject: core: thread: add a "timeouts" pointer to the thread structure Add a "timeouts" pointer to the thread structure; this is a private per-thread pointer for the benefit of lwIP. This is ad hoc, but a lot easier than implementing TLS. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index e644b9fa..f1212ebf 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -20,10 +20,13 @@ struct thread_block { bool timed_out; }; +struct sys_timeouts; + struct thread { void *esp; /* Must be first; stack pointer */ struct thread_list list; struct thread_block *blocked; + struct sys_timeouts *timeouts; /* For the benefit of lwIP */ int prio; }; -- cgit v1.2.1 From 853e2e8034316a07beedff69adcdb0d04c4cd113 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Fri, 8 Apr 2011 05:31:41 -0700 Subject: core thread: Rename timeouts pvt to better reflect it's use. lwip needs to find a per thread list of timeouts when it calls sys_arch_thread_timeouts(). Since we support threads we can easily support this extra bit of private data. Signed-off-by: Eric W. Biederman --- core/include/thread.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index f1212ebf..55a3ed7c 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -20,13 +20,11 @@ struct thread_block { bool timed_out; }; -struct sys_timeouts; - struct thread { void *esp; /* Must be first; stack pointer */ struct thread_list list; struct thread_block *blocked; - struct sys_timeouts *timeouts; /* For the benefit of lwIP */ + void *pvt; /* For the benefit of lwIP */ int prio; }; -- cgit v1.2.1 From cd8b37053cc36014379fefdecf1d409bc7dc5b45 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 10 Sep 2009 17:50:26 -0700 Subject: thread: add support for locking the scheduler Add support for locking the scheduler; this is needed for the pm return hook to operate properly. Signed-off-by: H. Peter Anvin --- core/include/core.h | 3 +++ core/include/thread.h | 3 +++ 2 files changed, 6 insertions(+) (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index a593c268..62a61f6e 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -18,6 +18,9 @@ extern char ConfigFile[]; /* diskstart.inc isolinux.asm*/ extern void getlinsec(void); +/* pm.inc */ +extern void (*core_pm_hook)(void); + /* getc.inc */ extern void core_open(void); diff --git a/core/include/thread.h b/core/include/thread.h index 55a3ed7c..7d346760 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -28,6 +28,9 @@ struct thread { int prio; }; +extern int __schedule_lock; +extern bool __need_schedule; +void __thread_process_timeouts(void); void __schedule(void); void __switch_to(struct thread *); void thread_yield(void); -- cgit v1.2.1 From 83d03ef60fe5cdb7083e12e18b2ac83c567c29d5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 14 Sep 2009 21:34:57 -0700 Subject: core: thread: add static declaration of semaphores Add the ability to statically declare initialized semaphores. Signed-off-by: Eric W. Biederman --- core/include/thread.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 7d346760..e82a80b2 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -46,6 +46,15 @@ struct semaphore { struct thread_list list; }; +#define DECLARE_INIT_SEMAPHORE(sem, cnt) \ + struct semaphore sem = { \ + .count = (cnt), \ + .list = { \ + .next = &sem.list, \ + .prev = &sem.list \ + } \ + } + mstime_t sem_down(struct semaphore *, mstime_t); void sem_up(struct semaphore *); void sem_init(struct semaphore *, int); -- cgit v1.2.1 From 117cc6f82e163769c5b59ef8f93d25452e0d83dc Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 14 Sep 2009 21:34:57 -0700 Subject: core: thread: add a name field Add a name field to struct thread, for debugging's sake. Signed-off-by: Eric W. Biederman --- core/include/thread.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index e82a80b2..db4ef5e2 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -22,6 +22,7 @@ struct thread_block { struct thread { void *esp; /* Must be first; stack pointer */ + const char *name; /* Name (for debugging) */ struct thread_list list; struct thread_block *blocked; void *pvt; /* For the benefit of lwIP */ @@ -82,7 +83,7 @@ static inline void irq_restore(irq_state_t __st) asm volatile("pushl %0 ; popfl" : : "rm" (__st)); } -struct thread *start_thread(size_t stack_size, int prio, +struct thread *start_thread(const char *name, size_t stack_size, int prio, void (*start_func)(void *), void *func_arg); void __exit_thread(void); void kill_thread(struct thread *); -- cgit v1.2.1 From b6cfb0672af84a643351a0db46664f8ba68baf36 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Fri, 8 Apr 2011 15:13:26 -0700 Subject: core: Move kaboom into it's own header. This allows kaboom to be used by lwip without having to inclued all of core.h Signed-off-by: Eric W. Biederman --- core/include/core.h | 7 +------ core/include/kaboom.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 core/include/kaboom.h (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index 62a61f6e..d32bacb4 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -4,6 +4,7 @@ #include #include #include +#include extern char core_xfer_buf[65536]; extern char core_cache_buf[65536]; @@ -58,12 +59,6 @@ void call16(void (*)(void), const com32sys_t *, com32sys_t *); */ #define __hugebss __attribute__((nocommon,section(".hugebss"),aligned(4096))) -/* - * Death! The macro trick is to avoid symbol conflict with - * the real-mode symbol kaboom. - */ -__noreturn _kaboom(void); -#define kaboom() _kaboom() /* * Basic timer function... diff --git a/core/include/kaboom.h b/core/include/kaboom.h new file mode 100644 index 00000000..4a763be9 --- /dev/null +++ b/core/include/kaboom.h @@ -0,0 +1,11 @@ +#ifndef KABOOM_H +#define KABOOM_H + +/* + * Death! The macro trick is to avoid symbol conflict with + * the real-mode symbol kaboom. + */ +__noreturn _kaboom(void); +#define kaboom() _kaboom() + +#endif /* KABOOM_H */ -- cgit v1.2.1 From 71b54fdaeb8b82293f1a19df401b3645d8096144 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Fri, 8 Apr 2011 15:20:26 -0700 Subject: core: Move timer functions into timer.h lwip gets symbol conflicts when we include all of core.h so move the declaration of the timers into their own header so that we can use those declartions in thread.h and so we can use thread.h from lwip without having to deal with symbol conflicts. Signed-off-by: Eric W. Biederman --- core/include/core.h | 17 +---------------- core/include/timer.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 core/include/timer.h (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index d32bacb4..034e9965 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -5,6 +5,7 @@ #include #include #include +#include extern char core_xfer_buf[65536]; extern char core_cache_buf[65536]; @@ -60,22 +61,6 @@ void call16(void (*)(void), const com32sys_t *, com32sys_t *); #define __hugebss __attribute__((nocommon,section(".hugebss"),aligned(4096))) -/* - * Basic timer function... - */ -typedef uint32_t jiffies_t; -extern volatile jiffies_t __jiffies, __ms_timer; -static inline jiffies_t jiffies(void) -{ - return __jiffies; -} -typedef uint32_t mstime_t; -typedef int32_t mstimediff_t; -static inline mstime_t ms_timer(void) -{ - return __ms_timer; -} - /* * Helper routine to return a specific set of flags */ diff --git a/core/include/timer.h b/core/include/timer.h new file mode 100644 index 00000000..1d66ba73 --- /dev/null +++ b/core/include/timer.h @@ -0,0 +1,21 @@ +#ifndef TIMER_H +#define TIMER_H + +/* + * Basic timer function... + */ +typedef uint32_t jiffies_t; +extern volatile jiffies_t __jiffies, __ms_timer; +static inline jiffies_t jiffies(void) +{ + return __jiffies; +} + +typedef uint32_t mstime_t; +typedef int32_t mstimediff_t; +static inline mstime_t ms_timer(void) +{ + return __ms_timer; +} + +#endif /* TIMER_H */ -- cgit v1.2.1 From e23d01c50f80fa14cefa0e62fb8741a28eaa9776 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Fri, 8 Apr 2011 15:24:20 -0700 Subject: core thread: Don't include core.h from thread.h core.h brings in a lot of symbols and causes conflicts when included into lwip, in particular conflicts on the symbol lfree. So do the simple thing and simplify what thread.h brings in to reduce the change of symbol conflicts. Signed-off-by: Eric W. Biederman --- core/include/thread.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index db4ef5e2..cdc3a901 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -3,7 +3,8 @@ #include #include -#include "core.h" +#include +#include struct semaphore; -- cgit v1.2.1 From 6372d4c8c5c56bb5381823131ef0995f351c4111 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Sun, 10 Apr 2011 09:38:45 -0700 Subject: core: Add isspace to ctype.h This is needed for the http file downloader. Signed-off-by: Eric W. Biederman --- core/include/ctype.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core/include') diff --git a/core/include/ctype.h b/core/include/ctype.h index 5c6d4cb4..6c7f57f4 100644 --- a/core/include/ctype.h +++ b/core/include/ctype.h @@ -22,4 +22,17 @@ static inline int tolower(int c) return c; } +static inline int isspace(int ch) +{ + int space = 0; + if ((ch == ' ') || + (ch == '\f') || + (ch == '\n') || + (ch == '\r') || + (ch == '\t') || + (ch == '\v')) + space = 1; + return space; +} + #endif /* CTYPE_H */ -- cgit v1.2.1 From abf7a9d75878f7eac2fc363d934fce52fa33f532 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Mon, 11 Apr 2011 22:47:31 -0700 Subject: core: pxe: Improve the situation with installing and uninstalling irq handlers Signed-off-by: Eric W. Biederman --- core/include/core.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index 034e9965..46c41bc0 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -21,6 +21,7 @@ extern char ConfigFile[]; extern void getlinsec(void); /* pm.inc */ +void core_pm_null_hook(void); extern void (*core_pm_hook)(void); /* getc.inc */ -- cgit v1.2.1 From 2674de6ed89756ad1b6954354e461bfd36f9d402 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Tue, 12 Apr 2011 04:28:32 -0700 Subject: core: thread: Implement polling for wakeups. For some reason the core_pm_hook is not getting called every time we get an interrupt with the result that in some situations like arping for our neighbours mac address or a tftp transfer we can stall, we never move forward again. The reason for those stalls likely bears more investigating but for now it is sufficient for me to know that they exist and that I can work around them by polling for wakekup conditions everytime we call schedule. That gives us code that works reliably and stays within the letter of the pxe spec. The oddities of the pxelinux core can be ironed out later. Signed-off-by: Eric W. Biederman --- core/include/thread.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index cdc3a901..704962e1 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -32,6 +32,8 @@ struct thread { extern int __schedule_lock; extern bool __need_schedule; +extern void (*sched_hook_func)(void); + void __thread_process_timeouts(void); void __schedule(void); void __switch_to(struct thread *); -- cgit v1.2.1 From f5203bfa11fde88d16f471b4050ed1da73387c7a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 21 Apr 2011 22:16:14 -0700 Subject: thread: thread-switch the real-mode stack, too When this code was originally written, we didn't have lmalloc(). Now when lmalloc() is implemented, let each real-mode task have its own stack. Note that this means we absolutely have to continue to support the SS != CS, DS model in the real-mode code, which should already be the case, but... Signed-off-by: H. Peter Anvin --- core/include/thread.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 704962e1..b283424d 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -26,6 +26,7 @@ struct thread { const char *name; /* Name (for debugging) */ struct thread_list list; struct thread_block *blocked; + void *stack, *rmstack; /* Stacks, iff allocated by malloc/lmalloc */ void *pvt; /* For the benefit of lwIP */ int prio; }; -- cgit v1.2.1 From 2fa8eb93e5b2fc684d27f018c0a84341eaed5476 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 22 Apr 2011 15:57:33 -0700 Subject: lwip: handle UNDI stacks which need to be polled If the UNDI stack reports either IRQ 0 or does NOT report the NDIS IRQ supported flag, then poll the interrupt routine from the idle thread instead. This is somewhat limited; we really should have a chain of idle poll routines to support things like serial console. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index b283424d..7c83b5a9 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -95,4 +95,6 @@ void kill_thread(struct thread *); void start_idle_thread(void); void test_thread(void); +extern void (*idle_hook)(void); + #endif /* _THREAD_H */ -- cgit v1.2.1 From f180d7c8ec74e0e15f1bcdf25c51899e2ca811c3 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 24 Apr 2011 20:55:47 -0700 Subject: pxe: use a separate poll thread instead of using an idle thread hook The idle thread can never sleep, so it's not really safe to do anything inside it. Instead, run a separate poll thread at low priority; we can also do that to poll the serial console if needed. Overall, the "classic" Syslinux idle handling really should go away and be replaced by the idle thread. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 7c83b5a9..be3844af 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -3,9 +3,16 @@ #include #include +#include #include #include +/* The idle thread runs at this priority */ +#define IDLE_THREAD_PRIORITY INT_MAX + +/* This priority should normally be used for hardware-polling threads */ +#define POLL_THREAD_PRIORITY (INT_MAX-1) + struct semaphore; struct thread_list { @@ -95,6 +102,4 @@ void kill_thread(struct thread *); void start_idle_thread(void); void test_thread(void); -extern void (*idle_hook)(void); - #endif /* _THREAD_H */ -- cgit v1.2.1 From 9ca79e92e60dd243c60e257a2dc60ba7b3677f37 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 25 Apr 2011 11:46:56 -0700 Subject: PXE Cleanups, allow for 128 open files Clean up dead code in the PXE stack. The buffer assignment no longer limits the number of open files either, so raise it to something more than reasonable. Signed-off-by: H. Peter Anvin --- core/include/fs.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'core/include') diff --git a/core/include/fs.h b/core/include/fs.h index ecd148da..4301481e 100644 --- a/core/include/fs.h +++ b/core/include/fs.h @@ -11,12 +11,9 @@ #include "disk.h" /* - * Maximum number of open files. This is *currently* constrained by the - * fact that PXE needs to be able to fit all its packet buffers into a - * 64K segment; this should be fixed by moving the packet buffers to high - * memory. + * Maximum number of open files. */ -#define MAX_OPEN_LG2 5 +#define MAX_OPEN_LG2 7 #define MAX_OPEN (1 << MAX_OPEN_LG2) #define FILENAME_MAX_LG2 8 -- cgit v1.2.1 From 3b772bb6588a28fd5741ca86f579e3838d96eb80 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 25 Apr 2011 16:47:09 -0700 Subject: core: remove the .hugebss section There are no more users of the .hugebss section, so remove it from existence. Signed-off-by: H. Peter Anvin --- core/include/core.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index 46c41bc0..cfb82133 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -56,12 +56,6 @@ void call16(void (*)(void), const com32sys_t *, com32sys_t *); #define __lowmem __attribute__((nocommon,section(".lowmem"))) #define __bss16 __attribute__((nocommon,section(".bss16"))) -/* - * Section for very large aligned objects, not zeroed on startup - */ -#define __hugebss __attribute__((nocommon,section(".hugebss"),aligned(4096))) - - /* * Helper routine to return a specific set of flags */ -- cgit v1.2.1 From 3953ca3532ca3281cc248f9985d9276c6f8486f0 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 25 Apr 2011 20:08:32 -0700 Subject: Generalize ipappend handling as "sysappend", and move to PM code Generalize the ipappend handling to cover all the derivatives, and rename it "sysappend" ("ipappend" is a valid alias for all derivatives.) Move all the string handling to protected mode. Currently only pxelinux exports strings, but the plan is to change that in the future. Signed-off-by: H. Peter Anvin --- core/include/core.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index cfb82133..4420fec1 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,11 @@ extern void *zalloc(size_t); extern void free(void *); extern void mem_init(void); +/* sysappend.c */ +extern void print_sysappend(void); +extern const char *sysappend_strings[SYSAPPEND_MAX]; +extern uint32_t SysAppends; + void __cdecl core_intcall(uint8_t, const com32sys_t *, com32sys_t *); void __cdecl core_farcall(uint32_t, const com32sys_t *, com32sys_t *); int __cdecl core_cfarcall(uint32_t, const void *, uint32_t); -- cgit v1.2.1 From b6401220c0bf7482ad5b204d08ba831a7cf9eabb Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 26 Apr 2011 14:41:31 -0700 Subject: Additional sysappend strings from DMI; pre-bake the http cookies - Add additional sysappend strings from DMI; we may want to add even more but let's think about it first. - Pre-generate http cookies. - Add a "sendcookies" command to mask out some of the information. Signed-off-by: H. Peter Anvin --- core/include/core.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/include') diff --git a/core/include/core.h b/core/include/core.h index 4420fec1..965b9900 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -48,6 +48,7 @@ extern void mem_init(void); extern void print_sysappend(void); extern const char *sysappend_strings[SYSAPPEND_MAX]; extern uint32_t SysAppends; +extern void sysappend_set_uuid(const uint8_t *uuid); void __cdecl core_intcall(uint8_t, const com32sys_t *, com32sys_t *); void __cdecl core_farcall(uint32_t, const com32sys_t *, com32sys_t *); -- cgit v1.2.1 From e0d9a80bd9690cdd4fc6c13c7eebe11cb26bf53e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 27 Apr 2011 09:27:10 -0700 Subject: thread: make kill_thread() actually do its job kill_thread() had been modifying errno(!) as if it had been the return value... in other words, it really did absolutely nothing. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index be3844af..44084ff3 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -19,6 +19,16 @@ struct thread_list { struct thread_list *next, *prev; }; +/* + * Stack frame used by __switch_to, see thread_asm.S + */ +struct thread_stack { + int errno; + uint16_t rmsp, rmss; + uint32_t edi, esi, ebp, ebx; + void (*eip)(void); +}; + struct thread_block { struct thread_list list; struct thread *thread; @@ -29,7 +39,7 @@ struct thread_block { }; struct thread { - void *esp; /* Must be first; stack pointer */ + struct thread_stack *esp; /* Must be first; stack pointer */ const char *name; /* Name (for debugging) */ struct thread_list list; struct thread_block *blocked; -- cgit v1.2.1 From da6d596aae0ebd3d4f6042ae361812242981a46e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sat, 30 Apr 2011 12:21:57 -0700 Subject: thread: simplify the scheduler need_schedule was no longer used by anything else, and schedule_lock only verified if we were being called from inside sched_hook_func(). Make the localness of this data explicit. While we're at it, call kaboom if we ever find ourselves without a runnable thread (which should not be possible, as the idle thread is not allowed to block.) Signed-off-by: H. Peter Anvin --- core/include/thread.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 44084ff3..5852df21 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -48,8 +48,6 @@ struct thread { int prio; }; -extern int __schedule_lock; -extern bool __need_schedule; extern void (*sched_hook_func)(void); void __thread_process_timeouts(void); -- cgit v1.2.1 From f8e82f9f4dab637783b5dbcec61956bba1c57faf Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 1 May 2011 18:05:23 -0700 Subject: thread: fix warnings Fix set-but-not-used variable warnings and undefined references. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 5852df21..73e88242 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -6,6 +6,7 @@ #include #include #include +#include /* The idle thread runs at this priority */ #define IDLE_THREAD_PRIORITY INT_MAX -- cgit v1.2.1 From 6ed325a3c881565cc2473d1fbfa69d806b4b7bbf Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 1 May 2011 18:11:40 -0700 Subject: core: pass the file flags down through the stack Pass the file flags down through the stack. This allows us to distinguish between open for read, open for write, or opendir in the low-level filesystem functions; this will matter for the PXE methods. Signed-off-by: H. Peter Anvin --- core/include/fs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core/include') diff --git a/core/include/fs.h b/core/include/fs.h index 4301481e..0691caa5 100644 --- a/core/include/fs.h +++ b/core/include/fs.h @@ -52,7 +52,7 @@ struct fs_ops { enum fs_flags fs_flags; int (*fs_init)(struct fs_info *); - void (*searchdir)(const char *, struct file *); + void (*searchdir)(const char *, int, struct file *); uint32_t (*getfssec)(struct file *, char *, int, bool *); void (*close_file)(struct file *); void (*mangle_name)(char *, const char *); @@ -179,10 +179,10 @@ static inline struct file *handle_to_file(uint16_t handle) void pm_mangle_name(com32sys_t *); void pm_searchdir(com32sys_t *); void mangle_name(char *, const char *); -int searchdir(const char *name); +int searchdir(const char *name, int flags); void _close_file(struct file *); size_t pmapi_read_file(uint16_t *handle, void *buf, size_t sectors); -int open_file(const char *name, struct com32_filedata *filedata); +int open_file(const char *name, int flags, struct com32_filedata *filedata); void pm_open_file(com32sys_t *); void close_file(uint16_t handle); void pm_close_file(com32sys_t *); -- cgit v1.2.1 From cd89ddbde2e1680f537a32010d64fd5465330122 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 9 May 2011 20:35:35 -0700 Subject: pxe: when hooking an interrupt, explicitly enable it at the PIC At least gPXE/iPXE apparently enters the NBP with the interrupt line disabled at the PIC; explicitly enable it instead. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 73e88242..213fb441 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -80,29 +80,6 @@ mstime_t sem_down(struct semaphore *, mstime_t); void sem_up(struct semaphore *); void sem_init(struct semaphore *, int); -typedef unsigned long irq_state_t; - -static inline irq_state_t irq_state(void) -{ - irq_state_t __st; - - asm volatile("pushfl ; popl %0" : "=rm" (__st)); - return __st; -} - -static inline irq_state_t irq_save(void) -{ - irq_state_t __st; - - asm volatile("pushfl ; popl %0 ; cli" : "=rm" (__st)); - return __st; -} - -static inline void irq_restore(irq_state_t __st) -{ - asm volatile("pushl %0 ; popfl" : : "rm" (__st)); -} - struct thread *start_thread(const char *name, size_t stack_size, int prio, void (*start_func)(void *), void *func_arg); void __exit_thread(void); -- cgit v1.2.1 From 5b08704e284545c82b4c5d3ff3aaee815107f6ef Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 11 Oct 2011 20:22:08 -0700 Subject: thread: allow marking invalid; allow for static mboxes Add an operation to mark a semaphore or a mailbox invalid (need to be reinitialized); and to test whether or not they are initialized. Allow for static mboxes, that is, not using dynamic memory. Both these changes should allow for the use of non-dynamic allocations in lwIP 1.4 and higher. Signed-off-by: H. Peter Anvin --- core/include/mbox.h | 33 ++++++++++++++++++++++++++++++++- core/include/thread.h | 21 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'core/include') diff --git a/core/include/mbox.h b/core/include/mbox.h index 9b927a0b..3c35ce4e 100644 --- a/core/include/mbox.h +++ b/core/include/mbox.h @@ -9,6 +9,12 @@ #include "thread.h" +/* + * If a mailbox is allocated statically (as a struct mailbox), this + * is the number of slots it gets. + */ +#define MAILBOX_STATIC_SIZE 512 + struct mailbox { struct semaphore prod_sem; /* Producer semaphore (empty slots) */ struct semaphore cons_sem; /* Consumer semaphore (data slots) */ @@ -18,11 +24,36 @@ struct mailbox { void **head; /* Head pointer */ void **tail; /* Tail pointer */ - void *data[]; /* Data array */ + void *data[MAILBOX_STATIC_SIZE]; /* Data array */ }; +/* The number of bytes for an mailbox of size s */ +#define MBOX_BYTES(s) (sizeof(struct mailbox) + \ + ((s)-MAILBOX_STATIC_SIZE)*sizeof(void *)) + void mbox_init(struct mailbox *mbox, size_t size); int mbox_post(struct mailbox *mbox, void *msg, mstime_t timeout); mstime_t mbox_fetch(struct mailbox *mbox, void **msg, mstime_t timeout); +/* + * This marks a mailbox object as unusable; it will remain unusable + * until sem_init() is called on it again. This DOES NOT clear the + * list of blocked processes on this mailbox! + * + * It is also possible to mark the mailbox invalid by zeroing its + * memory structure. + */ +static inline void mbox_set_invalid(struct mailbox *mbox) +{ + sem_set_invalid(&mbox->prod_sem); +} + +/* + * Ask if a mailbox object has been initialized. + */ +static inline bool mbox_is_valid(struct mailbox *mbox) +{ + return sem_is_valid(&mbox->prod_sem); +} + #endif /* _MBOX_H */ diff --git a/core/include/thread.h b/core/include/thread.h index 213fb441..85f2dafc 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -80,6 +80,27 @@ mstime_t sem_down(struct semaphore *, mstime_t); void sem_up(struct semaphore *); void sem_init(struct semaphore *, int); +/* + * This marks a semaphore object as unusable; it will remain unusable + * until sem_init() is called on it again. This DOES NOT clear the + * list of blocked processes on this semaphore! + * + * It is also possible to mark the semaphore invalid by zeroing its + * memory structure. + */ +static inline void sem_set_invalid(struct semaphore *sem) +{ + sem->list.next = NULL; +} + +/* + * Ask if a semaphore object has been initialized. + */ +static inline bool sem_is_valid(struct semaphore *sem) +{ + return !!sem->list.next; +} + struct thread *start_thread(const char *name, size_t stack_size, int prio, void (*start_func)(void *), void *func_arg); void __exit_thread(void); -- cgit v1.2.1 From 12b2033fc541241f1b5a286a1a80dd309fe2a708 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 30 Mar 2012 16:09:03 -0700 Subject: thread: Add magic number, debugging code, min stack size Add a magic number to the thread control block; this helps check for memory overwrites. Add dprintf()s to the scheduler. Force a minimum stack size. Signed-off-by: H. Peter Anvin --- core/include/thread.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/include') diff --git a/core/include/thread.h b/core/include/thread.h index 85f2dafc..6bfdfaa7 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -39,8 +39,11 @@ struct thread_block { bool timed_out; }; +#define THREAD_MAGIC 0x3568eb7d + struct thread { struct thread_stack *esp; /* Must be first; stack pointer */ + unsigned int thread_magic; const char *name; /* Name (for debugging) */ struct thread_list list; struct thread_block *blocked; -- cgit v1.2.1