ref: 91f14160d425ce557a3fc589b9286fd82c56b7a8
parent: cc3c4401a74588c302c55ba7acb19cd773fdf775
author: kitzman <kitzman@disroot.org>
date: Sun Nov 12 07:32:14 EST 2023
alloc fixes; missing files
--- a/alloc.c
+++ b/alloc.c
@@ -9,8 +9,8 @@
#define BHDR_MAGIC 0xcafebafe
#define BHDR_POISON 0xdeadbeef
-#define BPTR(h) ((Bhdr *)(h + sizeof(Bhdr)))
-#define BNEXT(h) ((Bhdr *)(h + sizeof(Bhdr) + h->size))
+#define BPTR(h) ((Bhdr *)((uint)h + sizeof(Bhdr)))
+#define BNEXT(h) ((Bhdr *)((uint)h + sizeof(Bhdr) + h->size))
enum {
Bfree = 0,
@@ -80,7 +80,7 @@
ptr = BPTR(hdr);
// create next block
- if(BNEXT(hdr) < (first + CMEMSIZE - sizeof(Bhdr)) &&
+ if((uint)BNEXT(hdr) < ((uint)first + CMEMSIZE - sizeof(Bhdr)) &&
BNEXT(hdr)->magic != BHDR_MAGIC) {
hdr = BNEXT(hdr);
hdr->magic = BHDR_MAGIC;
@@ -106,7 +106,7 @@
smalloc(ulong size)
{
void *ptr;
- while((ptr = malloc(size)) != nil)
+ while((ptr = malloc(size)) == nil)
_wait(100);
return ptr;
@@ -120,7 +120,7 @@
// first pass: find and free the block
DBGALLOC print("alloc: free'ing block\n");
- for(Bhdr *t = first; t - first < CMEMSIZE && hdr == nil; t = BNEXT(t)) {
+ for(Bhdr *t = first; (uint)t - (uint)first < CMEMSIZE && hdr == nil; t = BNEXT(t)) {
void *t_ptr = BPTR(t);
if(t_ptr == ptr)
hdr = t;
@@ -134,13 +134,13 @@
// second pass: coalesce with the next block
DBGALLOC print("alloc: coalesce with next block\n");
- if(BNEXT(hdr) < first + CMEMSIZE && BNEXT(hdr)->tp == Bfree) {
+ if((uint)BNEXT(hdr) < (uint)first + CMEMSIZE && BNEXT(hdr)->tp == Bfree) {
hdr->size = hdr->size + BNEXT(hdr)->size + sizeof(Bhdr);
}
// third pass: coalesce with the previous block
DBGALLOC print("alloc: coalesce with previous block\n");
- for(Bhdr *t = first; t - first < CMEMSIZE && c == nil; t = BNEXT(t)) {
+ for(Bhdr *t = first; (uint)t - (uint)first < CMEMSIZE && c == nil; t = BNEXT(t)) {
if(BNEXT(t) < first + CMEMSIZE && BNEXT(t) == hdr && t->tp == Bfree)
c = t;
}
@@ -157,7 +157,7 @@
Bhdr *hdr = nil;
void *nptr;
- for(Bhdr *t = first; t - first < CMEMSIZE && hdr == nil; t = BNEXT(t)) {
+ for(Bhdr *t = first; (uint)t - (uint)first < CMEMSIZE && hdr == nil; t = BNEXT(t)) {
void *t_ptr = BPTR(t);
if(t_ptr == ptr)
hdr = t;
--- /dev/null
+++ b/libkern/NOTICE
@@ -1,0 +1,29 @@
+This copyright NOTICE applies to all files in this directory and
+subdirectories, unless another copyright notice appears in a given
+file or subdirectory. If you take substantial code from this software to use in
+other programs, you must somehow include with it an appropriate
+copyright notice that includes the copyright notice and the other
+notices below. It is fine (and often tidier) to do that in a separate
+file such as NOTICE, LICENCE or COPYING.
+
+ Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+ Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
--- /dev/null
+++ b/libkern/mkfile
@@ -1,0 +1,99 @@
+</sys/src/mkfile.proto
+<../mkconfig
+
+LIB=libkern.a
+
+OFILES=\
+ abort.$O\
+ abs.$O\
+ atol.$O\
+ charstod.$O\
+ cistrcmp.$O\
+ cistrncmp.$O\
+ cistrstr.$O\
+ cleanname.$O\
+ dofmt.$O\
+ exp.$O\
+ floor.$O\
+ fmt.$O\
+ fmtprint.$O\
+ fmtquote.$O\
+ fmtstr.$O\
+ fmtvprint.$O\
+ frexp-thumb.$O\
+ getfcr-thumb.$O\
+ getfields.$O\
+ log.$O\
+ memccpy.$O\
+ memchr.$O\
+ memcmp.$O\
+ memmove.$O\
+ memset.$O\
+ nan-thumb.$O\
+ pow.$O\
+ pow10.$O\
+ qsort.$O\
+ rune.$O\
+ runestrlen.$O\
+ seprint.$O\
+ sin.$O\
+ smprint.$O\
+ snprint.$O\
+ sqrt.$O\
+ strcat.$O\
+ strchr.$O\
+ strcmp.$O\
+ strcpy.$O\
+ strdup.$O\
+ strecpy.$O\
+ strlen.$O\
+ strncmp.$O\
+ strncpy.$O\
+ strrchr.$O\
+ strstr.$O\
+ strtod.$O\
+ strtol.$O\
+ strtoll.$O\
+ strtoul.$O\
+ strtoull.$O\
+ tokenize.$O\
+ toupper.$O\
+ u16.$O\
+ u32.$O\
+ u64.$O\
+ utfecpy.$O\
+ utflen.$O\
+ utfnlen.$O\
+ utfrrune.$O\
+ utfrune.$O\
+ vlop-thumb.$O\
+ vlrt-thumb.$O\
+ vseprint.$O\
+ vsmprint.$O\
+ vsnprint.$O\
+
+HFILES=fmtdef.h
+
+LIBDIR=../bin
+LIBRARY=$LIBDIR/$LIB
+LIBOBJ=${OFILES:%=$LIBRARY(%)}
+
+%.$O: $HFILES # don't combine with following %.$O rules
+
+%.$O: %.c
+ $CC $CFLAGS $stem.c
+
+%.$O: %.s
+ $AS $ASFLAGS $stem.s
+
+default:V: all
+
+all install:V: $LIBRARY
+
+$LIBRARY: $LIBOBJ
+ $AR $ARFLAGS $target $newmember
+
+$LIBRARY(%.$O):N: %.$O
+
+clean:V:
+ rm *.t
--- /dev/null
+++ b/util.rc
@@ -1,0 +1,45 @@
+#!/bin/rc
+
+baudrate=19200
+kernel=kernel
+
+fn stm_info {
+ echo 'using flashdev' $flashdev 'with baud' $baudrate
+ if(! ~ $flashdev '') {
+ stm32up -d -D $flashdev -b $baudrate info
+ }
+ if not {
+ echo '$flashdev or $baudrate not set'
+ }
+}
+
+fn stm_flash {
+ echo 'using flashdev' $flashdev 'with baud' $baudrate
+ if(! ~ $flashdev '') {
+ cat $kernel | stm32up -d -D $flashdev -b $baudrate \
+ flash 0x08000000 '0x'`{cat $kernel | xd | tail -n 1}
+ }
+ if not {
+ echo '$flashdev or $baudrate not set'
+ }
+}
+
+fn stm_go {
+ echo 'using flashdev' $flashdev 'with baud' $baudrate
+ if(! ~ $flashdev '') {
+ stm32up -d -D $flashdev -b $baudrate go 0x08000000
+ }
+ if not {
+ echo '$flashdev or $baudrate not set'
+ }
+}
+
+fn stm_wunp {
+ echo 'using flashdev' $flashdev 'with baud' $baudrate
+ if(! ~ $flashdev '') {
+ stm32up -d -D $flashdev -b $baudrate writeunp
+ }
+ if not {
+ echo '$flashdev or $baudrate not set'
+ }
+}