Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[system] Major synchronization with ELKS updates in header file etc. #106

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootblocks/boot_minix.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static int strcmp (const char * s, const char * d)

static void load_super ()
{
disk_read (2, 2, sb_block, seg_data ());
disk_read (2, 1, sb_block, seg_data());

/*
if (sb_data->s_log_zone_size) {
Expand Down
51 changes: 51 additions & 0 deletions libc/ia16.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

INCLUDES=-I$(TOPDIR)/include -I$(TOPDIR)/libc/include -I$(TOPDIR)/tlvc/include
DEFINES=-D__LIBC__

INCS=$(INCLUDES)
SDEFS=$(DEFINES)
CDEFS=$(DEFINES)

ARCH=-ffreestanding -fno-inline -melks -mtune=i8086
ifeq "" "$(filter -mcmodel=%,$(MULTILIB))"
ARCH+=-mcmodel=small -mno-segment-relocation-stuff
endif

CC=ia16-elf-gcc
AS=ia16-elf-as
AR=ia16-elf-ar
LD=ia16-elf-ld

CFLAGS=$(ARCH) $(INCLUDES) $(CDEFS) -Wall -Os $(MULTILIB)
ASFLAGS=--32-segelf -mtune=i8086
LDFLAGS=-mtune=i8086
# This is used in subdirectories to quickly create a library archive without
# a symbol index
ARFLAGS_SUB=cqS

ifdef MULTISUBDIR
LIBC=$(TOPDIR)/libc/build-ml/$(MULTISUBDIR)/libc.a
CRT0=$(TOPDIR)/libc/build-ml/$(MULTISUBDIR)/crt0.o
endif
LIB_CPU=i86
LIB_OS=ELKS

.S.o:
$(CC) -E $(MULTILIB) $(INCS) $(SDEFS) -MD -o $*.tmp $<
$(AS) $(ASFLAGS) -o $*.o $*.tmp
rm -f $*.tmp

ifdef MULTISUBDIR
$(TOPDIR)/libc/build-ml/$(MULTISUBDIR)/%.o: %.S
$(CC) -E $(MULTILIB) $(INCS) $(SDEFS) -MD -o [email protected] $<
$(AS) $(ASFLAGS) -o $@ [email protected]
rm -f [email protected]
endif

.s.o:
$(AS) $(ASFLAGS) -o $*.o $<

.c.o:
$(CC) $(CFLAGS) -c -MD -o $*.o $<

-include *.d
6 changes: 3 additions & 3 deletions libc/misc/getcwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
static char * path_buf;
static size_t path_size;
static dev_t root_dev;
static u_ino_t root_ino;
static ino_t root_ino;
static struct stat st;

/* routine to find the step back down */
static char *
search_dir(dev_t this_dev, u_ino_t this_ino)
search_dir(dev_t this_dev, ino_t this_ino)
{
DIR * dp;
struct dirent * d;
Expand Down Expand Up @@ -76,7 +76,7 @@ static char *
recurser(void)
{
dev_t this_dev;
u_ino_t this_ino;
ino_t this_ino;

if( stat(path_buf, &st) < 0 ) return NULL;
this_dev = st.st_dev;
Expand Down
85 changes: 45 additions & 40 deletions libc/system/signal.c
Original file line number Diff line number Diff line change
@@ -1,59 +1,64 @@
#include <errno.h>
#include <signal.h>

typedef sighandler_t Sig;

extern int _signal (int, __kern_sighandler_t);
#if defined __TINY__ || defined __SMALL__ || defined __COMPACT__
/*
* If we are building libc for a near-code memory model (tiny, small, or
* compact), then we will arrange for _syscall_signal( ) to be within the
* same near code section as this module.
*/
extern __attribute__((near_section, stdcall))
#else
extern __attribute__((stdcall))
#endif
__far void _syscall_signal (int);

Sig _sigtable[_NSIG];

/*
* Signal handler.
* Signal handling routines.
*
*/

/*
* KERNEL INTERFACE:
* It is assumed the kernel will never give us a signal we haven't
* _explicitly_ asked for!
*
* The Kernel need only save space for _one_ function pointer
* (to _syscall_signal) and must deal with SIG_DFL and SIG_IGN
* (to _signal_cbhandler) and must deal with SIG_DFL and SIG_IGN
* in kernel space.
*
* When a signal is required the kernel must set all the registers as if
* returning from a interrupt normally then push the number of the signal
* to be generated, push the current pc value, then set the pc to the
* address of the '_syscall_signal' function.
* When a signal is required to be sent the kernel will setup a specialized
* user stack frame as described in elks/arch/i86/kernel/process.c in the
* arch_setup_sighandler_stack() function. This will look like returning
* from a interrupt normally except the C library kernel signal callback
* routine will be called as _signal_cbhandler(sig), after which a normal
* interrupt return will be executed.
*
* Not all C library routines are safe to call from a C signal handler,
* as the mechanism can be reentrant.
*/

sighandler_t _sigtable[_NSIG];

#ifdef __GNUC__
#if defined __TINY__ || defined __SMALL__ || defined __COMPACT__
/*
* If we are building libc for a near-code memory model (tiny, small, or
* compact), then we will arrange for _signal_cbhandler( ) to be within the
* same near code section as this module.
*/
extern __attribute__((near_section, __stdcall__)) __far void _signal_cbhandler(int);
#else
extern stdcall __far void _signal_cbhandler(int);
#endif
#endif

Sig signal(int number, Sig pointer)
#ifdef __WATCOMC__
extern void stdcall __far _signal_cbhandler(int); /* kernel callback in ASM */
void __far _signal_wchandler(int sig) /* callback handler calls this */
{
Sig old_sig;
int rv;
if( number < 1 || number > _NSIG ) { errno=EINVAL; return SIG_ERR; }
_sigtable[sig-1](sig);
}
#endif

#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
if( pointer == SIG_DFL || pointer == SIG_IGN )
rv = _signal(number, (__kern_sighandler_t) (long) (int) pointer);
else
rv = _signal(number, (__kern_sighandler_t) _syscall_signal);
sighandler_t signal(int number, sighandler_t pointer)
{
sighandler_t old_sig;
int rv;
if (number < 1 || number > _NSIG) { errno = EINVAL; return SIG_ERR; }

if( rv < 0 ) return SIG_ERR;
if (pointer == SIG_DFL || pointer == SIG_IGN)
rv = _signal(number, (__kern_sighandler_t) (unsigned long)pointer);
else
rv = _signal(number, (__kern_sighandler_t) _signal_cbhandler);
if (rv < 0) return SIG_ERR;

old_sig = _sigtable[number-1];
_sigtable[number-1] = pointer;
old_sig = _sigtable[number-1];
_sigtable[number-1] = pointer;

return old_sig;
return old_sig;
}
2 changes: 1 addition & 1 deletion tlvc/arch/i86/drivers/block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ void INITPROC setup_dev(register struct gendisk *dev)
#ifdef BDEV_SIZE_CHK
blk_size[dev->major] = NULL;
#endif
//printk("setup_dev %04x/%d\n", dev, dev->major);
memset((void *)dev->part, 0, sizeof(struct hd_struct)*dev->max_nr*dev->max_p);
dev->init(dev);
printk("setup_dev %04x/%d(%d)\n", dev, dev->major,sizeof(struct hd_struct)*dev->max_nr*dev->max_p);

/*
* A system can have only one disk 'category' - BIOS, IDE/ATA or XD.
Expand Down
25 changes: 14 additions & 11 deletions tlvc/arch/i86/drivers/block/ll_rw_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ static struct request *__get_request_wait(int, kdev_t);
* take precedence.
*/

#define NR_REQUEST 20
//#define DEBUG_BUFFER 1
//#define NR_REQUEST 20 /* Moved to limits.h */

static struct request request_list[NR_REQUEST];

Expand Down Expand Up @@ -127,7 +126,8 @@ static struct request *get_request_wait(int n, kdev_t dev)
#endif

/*
* add-request adds a request to the linked list.
* add_request passes a request on to the low level driver if the device
* request queue is empty, otherwise adds a request to the linked list.
* It disables interrupts so that it can muck with the
* request-lists in peace.
*/
Expand All @@ -141,8 +141,8 @@ static void add_request(struct blk_dev_struct *dev, struct request *req)
if (!(tmp = dev->current_request)) { /* if queue empty, process ... */
dev->current_request = req;
set_irq();
#if DEBUG_BUFFER
printk("AD%04x|", req);
#if DEBUG_ASYNC
if (debug_level > 2) printk("AD%04x|", req);
#endif
(dev->request_fn) ();
} else { /* otherwise just add to queue */
Expand All @@ -155,8 +155,8 @@ static void add_request(struct blk_dev_struct *dev, struct request *req)
req->rq_next = tmp->rq_next;
tmp->rq_next = req;
set_irq();
#if DEBUG_BUFFER
printk("AQ%04x|", req);
#if DEBUG_ASYNC
if (debug_level > 2) printk("AQ%04x|", req);
#endif
}
//mark_buffer_clean(req->rq_bh); /* EXPERIMENTAL: moved to end_request, blk.h */
Expand All @@ -168,8 +168,11 @@ static void make_request(unsigned short major, int rw, struct buffer_head *bh)
int max_req;
ext_buffer_head *ebh = EBH(bh);

debug_blk("BLK (%d) %lu %s %lx:%x\n", major, buffer_blocknr(bh), rw==READ? "read": "write",
#if DEBUG_ASYNC
if (debug_level)
printk("BLK (%d) %lu %s %lx:%x\n", major, buffer_blocknr(bh), rw==READ? "read": "write",
(unsigned long)buffer_seg(bh), buffer_data(bh));
#endif

#ifdef BDEV_SIZE_CHK /* NOTE: not updated for raw IO */
sector_t count = BLOCK_SIZE / FIXED_SECTOR_SIZE; /* FIXME must move to lower level*/
Expand Down Expand Up @@ -243,8 +246,8 @@ static void make_request(unsigned short major, int rw, struct buffer_head *bh)
req->rq_seg = buffer_seg(bh);
req->rq_buffer = buffer_data(bh);
}
#if DEBUG_BUFFER
printk("\n|seg%lx:%04x|%cblk%d|BH%04x|dev%04x;", (unsigned long)buffer_seg(bh),
#if DEBUG_ASYNC
if (debug_level) printk("\n|seg%lx:%04x|%cblk%d|BH%04x|dev%04x;", (unsigned long)buffer_seg(bh),
buffer_data(bh), rw == READ ? 'R' : 'W',
(word_t)ebh->b_blocknr, (word_t)bh, (word_t)buffer_dev(bh));
#endif
Expand Down Expand Up @@ -434,7 +437,7 @@ void INITPROC blk_dev_init(void)
#endif

#ifdef CONFIG_ROMFS_FS
romflash_init ();
romflash_init();
#endif

#ifdef CONFIG_BLK_DEV_XD
Expand Down
2 changes: 1 addition & 1 deletion tlvc/arch/i86/drivers/char/console-direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct tty_ops dircon_ops = {
Console_conout
};

void console_init(void)
void INITPROC console_init(void)
{
Console *C;
int i;
Expand Down
14 changes: 6 additions & 8 deletions tlvc/arch/i86/drivers/char/ntty.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ struct tty *determine_tty(dev_t dev)
{
register struct tty *ttyp = &ttys[0];
unsigned short minor = MINOR(dev);
extern dev_t dev_console;

/* handle /dev/tty*/
if (minor == 255 && current->pgrp && (current->pgrp == ttyp->pgrp))
Expand Down Expand Up @@ -144,13 +143,12 @@ void tty_freeq(struct tty *tty)
int tty_open(struct inode *inode, struct file *file)
{
register struct tty *otty;
register __ptask currentp = current;
int err;

if (!(otty = determine_tty(inode->i_rdev)))
return -ENODEV;

debug_tty("TTY open pid %d\n", currentp->pid);
debug_tty("TTY open pid %d\n", current->pid);
#if 0
memcpy(&otty->termios, &def_vals, sizeof(struct termios));
#endif
Expand All @@ -164,11 +162,11 @@ int tty_open(struct inode *inode, struct file *file)

err = otty->ops->open(otty);
if (!err) {
if (!(file->f_flags & O_NOCTTY) && currentp->session == currentp->pid
&& currentp->tty == NULL && otty->pgrp == 0) {
debug_tty("TTY setting pgrp %d pid %d\n", currentp->pgrp, currentp->pid);
otty->pgrp = currentp->pgrp;
currentp->tty = otty;
if (!(file->f_flags & O_NOCTTY) && current->session == current->pid
&& current->tty == NULL && otty->pgrp == 0) {
debug_tty("TTY setting pgrp %d pid %d\n", current->pgrp, current->pid);
otty->pgrp = current->pgrp;
current->tty = otty;
}
otty->flags |= TTY_OPEN;
}
Expand Down
20 changes: 9 additions & 11 deletions tlvc/arch/i86/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,28 @@ int run_init_process_sptr(const char *cmd, char *sptr, int slen)
*/
void stack_check(void)
{
register __ptask currentp = current;
register char *end = (char *)currentp->t_endbrk;
segoff_t end = current->t_endbrk;

#ifdef CONFIG_EXEC_LOW_STACK
if (currentp->t_begstack <= currentp->t_enddata) { /* stack below heap?*/
if (currentp->t_regs.sp < (__u16)end)
if (current->t_begstack <= current->t_enddata) { /* stack below heap?*/
if (current->t_regs.sp < (__u16)end)
return;
end = 0;
} else
#endif
{
/* optional: check stack over min stack*/
if (currentp->t_regs.sp < currentp->t_begstack - currentp->t_minstack) {
if (currentp->t_minstack) /* display if protected stack*/
printk("(%d)STACK OVER MINSTACK by %u BYTES\n", currentp->pid,
currentp->t_begstack - currentp->t_minstack - currentp->t_regs.sp);
if (current->t_regs.sp < current->t_begstack - current->t_minstack) {
if (current->t_minstack) /* display if protected stack*/
printk("(%d)STACK OVER MINSTACK by %u BYTES\n", current->pid,
current->t_begstack - current->t_minstack - current->t_regs.sp);
}

/* check stack overflow heap*/
if (currentp->t_regs.sp > (__u16)end)
if (current->t_regs.sp > end)
return;
}
printk("(%d)STACK OVERFLOW BY %u BYTES\n",
currentp->pid, (__u16)end - currentp->t_regs.sp);
printk("(%P)STACK OVERFLOW BY %u BYTES\n", end - current->t_regs.sp);
do_exit(SIGSEGV);
}

Expand Down
Loading