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

[kernel,cmd] heap fix, meminfo update, discussion #105

Merged
merged 4 commits into from
Nov 22, 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
28 changes: 3 additions & 25 deletions libc/include/sys/cdefs.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@

#ifndef __SYS_CDEFS_H
#define __SYS_CDEFS_H
#include <features.h>

#if __STDC__

#define __CONCAT(x,y) x ## y
#define __STRING(x) #x

/* This is not a typedef so `const __ptr_t' does the right thing. */
#define __ptr_t void *
#ifndef __HAS_NO_FLOATS__
typedef long double __long_double_t;
#endif

#else
/* compiler-specific definitions for userspace */

#define __CONCAT(x,y) x/**/y
#define __STRING(x) "x"

#define __ptr_t char *

#ifndef __HAS_NO_FLOATS__
typedef double __long_double_t;
#endif

#endif
#include <features.h>
#include __SYSARCHINC__(cdefs.h)

/* No C++ */
#define __BEGIN_DECLS
Expand Down
12 changes: 12 additions & 0 deletions libc/include/sys/features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __FEATURES_H
#define __FEATURES_H

/* Pick an OS sysinclude directory */
/* Use with #include __SYSINC__(errno.h) */

#define __SYSINC__(_h_file_) <linuxmt/_h_file_>
#define __SYSARCHINC__(_h_file_) <arch/_h_file_>

#include <sys/cdefs.h>

#endif
4 changes: 2 additions & 2 deletions libc/system/signalcb.S
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

.text

.global _syscall_signal
.global _signal_cbhandler

_syscall_signal:
_signal_cbhandler:
push %bp
mov %sp,%bp

Expand Down
27 changes: 8 additions & 19 deletions tlvc/arch/i86/drivers/char/mem.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ELKS implmentation of memory devices
* TLVC implmentation of memory devices
* /dev/null, /dev/ports, /dev/zero, /dev/mem, /dev/kmem, etc...
*
* Heavily inspired by linux/drivers/char/mem.c
Expand All @@ -9,8 +9,6 @@
* /dev/mem refers to physical memory
* /dev/kmem refers to _virtual_ address space
* /dev/port refers to hardware ports <[email protected]>
* Currently these will be the same, but eventually, once ELKS has
* EMS, etc, we'll want to change these.
*/

#include <linuxmt/config.h>
Expand Down Expand Up @@ -38,12 +36,6 @@
#define DEV_PORT_MINOR 4
#define DEV_ZERO_MINOR 5

#define DEV_FULL_MINOR 7
#define DEV_RANDOM_MINOR 8
#define DEV_URANDOM_MINOR 9

//#define debugmem printk
//#define DEBUG
/*
* generally useful code...
*/
Expand All @@ -62,12 +54,6 @@ int memory_lseek(struct inode *inode, register struct file *filp,
}
if (offset != filp->f_pos) {
filp->f_pos = offset;

#ifdef BLOAT_FS
filp->f_reada = 0;
filp->f_version = ++event;
#endif

}
return 0;
}
Expand Down Expand Up @@ -269,7 +255,7 @@ int kmem_ioctl(struct inode *inode, struct file *file, int cmd, char *arg)
retword = kernel_ds;
break;
case MEM_GETFARTEXT:
retword = (unsigned)((long)kernel_init >> 16);
retword = (unsigned)((long)buffer_init >> 16);
break;
case MEM_GETUSAGE:
mm_get_usage (&(mu.free_memory), &(mu.used_memory));
Expand All @@ -281,14 +267,17 @@ int kmem_ioctl(struct inode *inode, struct file *file, int cmd, char *arg)
case MEM_GETHEAP:
retword = (unsigned short) &_heap_all;
break;
case MEM_GETJIFFADDR:
retword = (unsigned) &jiffies;
break;
case MEM_GETSEGALL:
retword = (unsigned short) &_seg_all;
break;
case MEM_GETUPTIME:
#ifdef CONFIG_CPU_USAGE
retword = (unsigned short) &uptime;
break;
#endif
case MEM_GETJIFFADDR:
retword = (unsigned) &jiffies;
break;
default:
return -EINVAL;
}
Expand Down
1 change: 1 addition & 0 deletions tlvc/arch/i86/drivers/net/ne2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ static int ne2k_open(struct inode *inode, struct file *file)
ne2k_reset();
ne2k_init();
#if NET_BUF_STRAT == HEAP_BUFS
/* allocate buffer control headers from the heap */
net_ibuf = (struct netbuf *)heap_alloc(sizeof(struct netbuf) * (netbufs[NET_RXBUFS] +
netbufs[NET_TXBUFS]), HEAP_TAG_NETWORK);
net_obuf = net_ibuf + netbufs[NET_RXBUFS];
Expand Down
76 changes: 44 additions & 32 deletions tlvc/arch/i86/kernel/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,88 @@
#include <linuxmt/memory.h>

#include <arch/segment.h>
#include <arch/system.h>
#include <arch/io.h>


byte_t sys_caps; /* system capabilities bits */
seg_t membase, memend; /* start and end segment of available main memory */
unsigned int heapsize; /* max size of kernel near heap */
byte_t sys_caps; /* system capabilities bits */
unsigned char arch_cpu; /* CPU type from cputype.S */

void INITPROC setup_arch(seg_t *start, seg_t *end)
unsigned int INITPROC setup_arch(void)
{
unsigned int endbss, heapsegs;

#ifdef CONFIG_HW_COMPAQFAST
outb_p(1,0xcf); /* Switch COMPAQ Deskpro to high speed */
#endif

/*
* Extend kernel data segment to maximum of 64K to make room
* for local heap.
* Extend kernel data segment to maximum of 64K to make room for local heap.
*
* Set start to beginning of available main memory, which
* Set membase to beginning of available main memory, which
* is directly after end of the kernel data segment.
*
* Set end to end of available main memory.
*
* Set memend to end of available main memory.
* If ramdisk configured, subtract space for it from end of memory.
*
* Calculate heapsize for near heap allocator.
* Return start address for near heap allocator.
*/

/* Heap allocations at even addresses, important for performance */
unsigned int endbss = (unsigned int)(_endbss + 1) & ~1;
/* Heap allocations at even addresses */
endbss = (unsigned int)(_endbss + 1) & ~1;

/*
* Calculate size of heap, which extends end of kernel data segment
*/
/* Calculate size of heap, which extends end of kernel data segment */

#ifdef SETUP_HEAPSIZE
unsigned int heapsegs = (1 + ~endbss) >> 4; /* max possible heap in segments*/
if ((SETUP_HEAPSIZE >> 4) < heapsegs) /* allow if less than max*/
heapsegs = SETUP_HEAPSIZE >> 4;
*start = kernel_ds + heapsegs + (((unsigned int) (_endbss+15)) >> 4);
heapsize = heapsegs << 4;
#else
*start = kernel_ds + 0x1000;
heapsize = 1 + ~endbss;
heapsize = SETUP_HEAPSIZE; /* may also be set via heap= in /bootopts */
#endif
if (heapsize) {
heapsegs = (1 + ~endbss) >> 4; /* max possible heap in segments */
if ((heapsize >> 4) < heapsegs) /* allow if less than max */
heapsegs = heapsize >> 4;
membase = kernel_ds + heapsegs + (((unsigned int) (_endbss+15)) >> 4);
heapsize = heapsegs << 4;
} else {
membase = kernel_ds + 0x1000;
heapsize = 1 + ~endbss;
}
//debug("endbss %x heap %x kdata size %x\n", endbss, heapsize, (membase-kernel_ds)<<4);

*end = (seg_t)SETUP_MEM_KBYTES << 6;
memend = SETUP_MEM_KBYTES << 6;

#if defined(CONFIG_RAMDISK_SEGMENT) && (CONFIG_RAMDISK_SEGMENT > 0)
if (CONFIG_RAMDISK_SEGMENT <= *end) {
/* reduce top of memory by size of ram disk*/
*end -= CONFIG_RAMDISK_SECTORS << 5;
/* reduce top of memory by size of ram disk */
memend -= CONFIG_RAMDISK_SECTORS << 5;
}
#endif

/* Now insert local heap at end of kernel data segment */
heap_init ();
heap_add ((void *)endbss, heapsize);

/* Misc */
ROOT_DEV = SETUP_ROOT_DEV;

arch_cpu = SETUP_CPU_TYPE;
#ifdef SYS_CAPS
sys_caps = SYS_CAPS; /* custom system capabilities */
#else
byte_t arch_cpu = SETUP_CPU_TYPE;
if (arch_cpu > 5) /* 80286+ IBM PC/AT capabilities or Unknown CPU */
sys_caps = CAP_ALL;
#endif
return endbss; /* used as start address in near heap init */

}

/*
* The following routines may need porting on non-IBM PC architectures
*/

/*
* This function gets called by the keyboard interrupt handler.
* As it's called within an interrupt, it may NOT sync.
*/
void ctrl_alt_del(void)
{
hard_reset_now();
}

void hard_reset_now(void)
{
#ifdef CONFIG_ARCH_IBMPC
Expand Down
45 changes: 45 additions & 0 deletions tlvc/include/arch/cdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef __ARCH_8086_CDEFS_H
#define __ARCH_8086_CDEFS_H
/* compiler-specific definitions for kernel and userspace */

#if __STDC__
#define __CONCAT(x,y) x ## y
#define __STRING(x) #x
#else
#define __CONCAT(x,y) x/**/y
#define __STRING(x) "x"
#endif

#define __P(x) x /* always ANSI C */

#ifdef __GNUC__
#define noreturn __attribute__((__noreturn__)) /* don't require <stdnoreturn.h> */
#define stdcall __attribute__((__stdcall__))
#define restrict __restrict
#define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define noinstrument __attribute__((no_instrument_function))
#define CONSTRUCTOR(fn,pri) void fn(void) __attribute__((constructor(pri)))
#define DESTRUCTOR(fn,pri) void fn(void) __attribute__((destructor(pri)))
#define __wcfar
#define __wcnear
#endif

#ifdef __WATCOMC__
#define noreturn __declspec(aborts)
#define stdcall __stdcall
#define restrict __restrict
#define printfesque(n)
#define noinstrument
#define CONSTRUCTOR(fn,pri) void fn(void); \
static struct _rt_init __based(__segname("XI")) \
__CONCAT(_ctor,fn) = { fn, pri, 0}
#define DESTRUCTOR(fn,pri) void fn(void); \
static struct _rt_init __based(__segname("YI")) \
__CONCAT(_dtor,fn) = { fn, pri, 0}
#define __attribute__(n)
#define __wcfar __far
#define __wcnear __near
#endif


#endif
16 changes: 8 additions & 8 deletions tlvc/include/linuxmt/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#define HEAP_TAG_TASK 0x04
#define HEAP_TAG_BUFHEAD 0x05
#define HEAP_TAG_PIPE 0x06
#define HEAP_TAG_NETWORK 0x07 /* packet buffer allocations */
#define HEAP_TAG_INDOE 0x08
#define HEAP_TAG_INODE 0x07
#define HEAP_TAG_FILE 0x08
#define HEAP_TAG_CACHE 0x09
#define HEAP_TAG_FILE 0x0A
#define HEAP_TAG_NETWORK 0x0A /* packet buffer allocations */


// TODO: move free list node from header to body
Expand All @@ -48,14 +48,14 @@ extern list_s _heap_all;

// Heap functions

void * heap_alloc (word_t size, byte_t tag);
void heap_free (void * data);
void *heap_alloc(word_t size, byte_t tag);
void heap_free(void *data);

void heap_add (void * data, word_t size);
void heap_init ();
void heap_add(void *data, word_t size);
void heap_init();

#ifdef HEAP_DEBUG
void heap_iterate (void (* cb) (heap_s * h));
void heap_iterate(void (*cb)(heap_s *h));
#endif /* HEAP_DEBUG */

#endif
1 change: 1 addition & 0 deletions tlvc/include/linuxmt/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define MEM_GETFARTEXT 9
#define MEM_GETMAXTASKS 10
#define MEM_GETJIFFADDR 11
#define MEM_GETSEGALL 12

struct mem_usage {
unsigned int free_memory;
Expand Down
Loading