From kevin at tyndur.org Sun Aug 8 16:30:55 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 8 Aug 2010 16:30:55 +0200 Subject: [tyndur-devel] [PATCH] image_hd: Pruefen, ob root-local existiert Message-ID: <1281277855-10044-1-git-send-email-kevin@tyndur.org> ! image_hd: Wenn root-local nicht existiert, gibt das cp eine Fehlermeldung, was regelmaessig Leute verwirrt. Erstmal pruefen tut keinem weh. Signed-off-by: Kevin Wolf --- build/scripts/image_hd | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/build/scripts/image_hd b/build/scripts/image_hd index d8fb3f6..7014fe6 100755 --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -86,7 +86,7 @@ $SUDO chmod 777 -R $MOUNT # Daten Kopieren cp -rP --preserve=links,timestamps $ROOT/* $ROOT_COMMON/* $ROOT_HD/* $MOUNT/ -cp -rP --preserve=links,timestamps $ROOT_LOCAL/* $MOUNT/ +[ -d $ROOT_LOCAL ] && cp -rP --preserve=links,timestamps $ROOT_LOCAL/* $MOUNT/ # GRUB-Konfiguration kopieren mkdir -p $MOUNT/boot/grub -- 1.7.2 From max at tyndur.org Sun Aug 8 16:38:53 2010 From: max at tyndur.org (Max Reitz) Date: Sun, 08 Aug 2010 16:38:53 +0200 Subject: [tyndur-devel] [PATCH] image_hd: Pruefen, ob root-local existiert In-Reply-To: <1281277855-10044-1-git-send-email-kevin@tyndur.org> References: <1281277855-10044-1-git-send-email-kevin@tyndur.org> Message-ID: <4C5EC17D.4070505@tyndur.org> Kevin Wolf schrieb: > ! image_hd: Wenn root-local nicht existiert, gibt das cp eine Fehlermeldung, > was regelmaessig Leute verwirrt. Erstmal pruefen tut keinem weh. > > Signed-off-by: Kevin Wolf Acked-By: Max Reitz From kevin at tyndur.org Sun Aug 8 16:53:01 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 8 Aug 2010 16:53:01 +0200 Subject: [tyndur-devel] [PATCH] image_hd: Fuer GRUB install statt setup benutzen Message-ID: <1281279181-18220-1-git-send-email-kevin@tyndur.org> * image_hd: Es gibt kaputtgepatchte GRUB-Versionen, die nicht automatisch nach einer menu.lst suchen, sondern nach anderen Sachen (z.B. grub.conf). In diesme Fall gibt es mit setup nur eine GRUB-Shell und kein Menue. Mit install kann man den Pfad explizit angeben. Signed-off-by: Kevin Wolf --- build/scripts/image_hd | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/build/scripts/image_hd b/build/scripts/image_hd index 7014fe6..ea296ea 100755 --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -114,7 +114,7 @@ if [ $NEW -ne 0 ]; then $LOST_TOOLS_GRUB --no-floppy --batch > /dev/null < References: Message-ID: <6ca2b56d8d9139d0af0d.1281704909@laptop> * statt das hd-Image mit dd hin und her zu kopieren loop-devices verwenden Signed-off-by: MNemo --- build/scripts/image_hd | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build/scripts/image_hd b/build/scripts/image_hd --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -69,14 +69,15 @@ PART_START=`echo $PARTITIONS | awk '{pri PART_SIZE=`echo $PARTITIONS | awk '{print $2}'` if [ $NEW -ne 0 ]; then - PART_IMAGE=`mktemp` - build/scripts/empty_file $PART_IMAGE $(($PART_SIZE * 512)) + LOOP_DEV=`$SUDO losetup -f $IMAGE_PATH --sizelimit $(($PART_SIZE * 512)) -o $(($PART_START * 512)) --show` + if [ $? -ne 0 ]; then + die "Loop Device konnte nicht angelegt werden" + fi # Dateisystem erstellen - $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" + $SUDO $LOST_TOOLS_MKE2FS -T ext2 -F -q $LOOP_DEV || die "Dateisystem konnte nicht erstellt werden" - dd if=$PART_IMAGE of=$IMAGE_PATH bs=512 seek=$PART_START count=$PART_SIZE - rm $PART_IMAGE + $SUDO losetup -d $LOOP_DEV fi # Partition mounten From m.nemo at gmx.net Sat Aug 14 14:10:57 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sat, 14 Aug 2010 14:10:57 +0200 Subject: [tyndur-devel] =?utf-8?b?W1BBVENIIDAgb2YgMl0gYnVpbGQ6IGBkZCBpZi4u?= =?utf-8?q?=2E=60_ist_nicht_immer_die_beste_L=C3=B6sung?= Message-ID: Das hin und her Kopieren mit `dd ...` ist sehr langsam. Deshalb reduzieren die Zwei Patches den Gebrauch auf ein minimum. build/scripts/empty_file | 24 ++++++++++++++++++++++++ build/scripts/image_cdrom | 2 +- build/scripts/image_floppy | 2 +- build/scripts/image_hd | 4 ++-- build/scripts/image_hd | 11 ++++++----- 5 files changed, 34 insertions(+), 9 deletions(-) From m.nemo at gmx.net Sat Aug 14 14:10:58 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sat, 14 Aug 2010 14:10:58 +0200 Subject: [tyndur-devel] [PATCH 1 of 2] build: dd if='/dev/zero' ... ist zu langsam In-Reply-To: References: Message-ID: <5abe563fc8809ab410d5.1281787858@laptop> * Beim Erstellen von leeren Images auf dd verzichten, statt dessen ein kleines Python-Script verwenden Signed-off-by: Andreas Freimuth --- build/scripts/empty_file | 24 ++++++++++++++++++++++++ build/scripts/image_cdrom | 2 +- build/scripts/image_floppy | 2 +- build/scripts/image_hd | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/build/scripts/empty_file b/build/scripts/empty_file new file mode 100755 --- /dev/null +++ b/build/scripts/empty_file @@ -0,0 +1,24 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +# Eine leere Datei mit einer bestimmten Größe erzeugen +# Parameter: +# 1. Dateiname +# 2. Dateigröße +import sys + +def empty_file(filename, size): + f = open(filename,"wb") + if not f: + sys.exit(1) + + f.seek(size - 1) + f.write('\0') + f.close() + +if __name__ == "__main__": + if len(sys.argv[1:]) != 2: + print sys.stderr, "using: %s " % sys.argv[0] + sys.exit(1) + + empty_file(str(sys.argv[1]), int(sys.argv[2])) diff --git a/build/scripts/image_cdrom b/build/scripts/image_cdrom --- a/build/scripts/image_cdrom +++ b/build/scripts/image_cdrom @@ -96,7 +96,7 @@ EOF NEW=0 if ! [ -f $FLOPPY_IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$FLOPPY_IMAGE_PATH bs=1024 count=1440 + build/scripts/empty_file $FLOPPY_IMAGE_PATH $((1024 * 1440)) mformat l: NEW=1 fi diff --git a/build/scripts/image_floppy b/build/scripts/image_floppy --- a/build/scripts/image_floppy +++ b/build/scripts/image_floppy @@ -58,7 +58,7 @@ EOF NEW=0 if ! [ -f $IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$IMAGE_PATH bs=1024 count=1440 + build/scripts/empty_file $IMAGE_PATH $((1024 * 1440)) mformat l: NEW=1 fi diff --git a/build/scripts/image_hd b/build/scripts/image_hd --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -57,7 +57,7 @@ die() NEW=0 if ! [ -f $IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$IMAGE_PATH bs=$((1024*1024)) count=$IMAGE_SIZE 2> /dev/null + build/scripts/empty_file $IMAGE_PATH $(($IMAGE_SIZE * 1024 * 1024)) build/scripts/create_partition $IMAGE_PATH NEW=1 fi @@ -70,7 +70,7 @@ PART_SIZE=`echo $PARTITIONS | awk '{prin if [ $NEW -ne 0 ]; then PART_IMAGE=`mktemp` - dd if=$IMAGE_PATH of=$PART_IMAGE bs=512 skip=$PART_START count=$PART_SIZE + build/scripts/empty_file $PART_IMAGE $(($PART_SIZE * 512)) # Dateisystem erstellen $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" From kevin at tyndur.org Sat Aug 14 20:28:42 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 14 Aug 2010 20:28:42 +0200 Subject: [tyndur-devel] [PATCH 1 of 2] build: dd if='/dev/zero' ... ist zu langsam In-Reply-To: <5abe563fc8809ab410d5.1281787858@laptop> References: <5abe563fc8809ab410d5.1281787858@laptop> Message-ID: <20100814182842.GA9845@silvanus> On Sat, Aug 14, 2010 at 02:10:58PM +0200, Andreas Freimuth wrote: > > * Beim Erstellen von leeren Images auf dd verzichten, statt dessen ein > kleines Python-Script verwenden > > Signed-off-by: Andreas Freimuth > --- > build/scripts/empty_file | 24 ++++++++++++++++++++++++ > build/scripts/image_cdrom | 2 +- > build/scripts/image_floppy | 2 +- > build/scripts/image_hd | 4 ++-- > 4 files changed, 28 insertions(+), 4 deletions(-) > > diff --git a/build/scripts/empty_file b/build/scripts/empty_file > new file mode 100755 > --- /dev/null > +++ b/build/scripts/empty_file > @@ -0,0 +1,24 @@ > +#!/usr/bin/python > +# -*- coding: UTF-8 -*- > + > +# Eine leere Datei mit einer bestimmten Größe erzeugen > +# Parameter: > +# 1. Dateiname > +# 2. Dateigröße > +import sys > + > +def empty_file(filename, size): > + f = open(filename,"wb") > + if not f: > + sys.exit(1) > + > + f.seek(size - 1) > + f.write('\0') > + f.close() Funktioniert nicht für size = 0 und verkleinert schon vorhandene Dateien nicht. f.truncate (oder wie auch immer das heißen mag) wäre wahrscheinlich besser. > + > +if __name__ == "__main__": > + if len(sys.argv[1:]) != 2: > + print sys.stderr, "using: %s " % sys.argv[0] > + sys.exit(1) > + > + empty_file(str(sys.argv[1]), int(sys.argv[2])) Tut das ganze nicht dasselbe wie dd of=$file seek=$size count=0? (Bzw. in deiner Version auch noch conv=notrunc, aber das halte ich wie gesagt für einen Bug und nicht für ein Feature) Die Idee, nicht erstmal endlos Nullen zu schreiben, ist aber gut. Kevin From max at tyndur.org Sat Aug 14 20:35:03 2010 From: max at tyndur.org (Max Reitz) Date: Sat, 14 Aug 2010 20:35:03 +0200 Subject: [tyndur-devel] [PATCH] image_hd: Fuer GRUB install statt setup benutzen In-Reply-To: <1281279181-18220-1-git-send-email-kevin@tyndur.org> References: <1281279181-18220-1-git-send-email-kevin@tyndur.org> Message-ID: <4C66E1D7.1010009@tyndur.org> Kevin Wolf schrieb: > * image_hd: Es gibt kaputtgepatchte GRUB-Versionen, die nicht automatisch nach > einer menu.lst suchen, sondern nach anderen Sachen (z.B. grub.conf). In > diesme Fall gibt es mit setup nur eine GRUB-Shell und kein Menue. Mit install > kann man den Pfad explizit angeben. > > Signed-off-by: Kevin Wolf Diesen Patch, den ack ich ohne große Worte, Nun, ich lass ihn so durch diese güld'ne Pforte, Durch die Grenz' zum týndur-Repo ein, Ja, denn diese Zeilen fand ich fein. Acked-by: Max Reitz From m.nemo at gmx.net Sat Aug 14 20:45:42 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sat, 14 Aug 2010 20:45:42 +0200 Subject: [tyndur-devel] [PATCH 1 of 2] build: dd if='/dev/zero' ... ist zu langsam In-Reply-To: <20100814182842.GA9845@silvanus> References: <5abe563fc8809ab410d5.1281787858@laptop> <20100814182842.GA9845@silvanus> Message-ID: <4C66E456.9090907@gmx.net> Am 14.08.2010 20:28, schrieb Kevin Wolf: > On Sat, Aug 14, 2010 at 02:10:58PM +0200, Andreas Freimuth wrote: >> >> * Beim Erstellen von leeren Images auf dd verzichten, statt dessen ein >> kleines Python-Script verwenden >> >> Signed-off-by: Andreas Freimuth >> --- >> build/scripts/empty_file | 24 ++++++++++++++++++++++++ >> build/scripts/image_cdrom | 2 +- >> build/scripts/image_floppy | 2 +- >> build/scripts/image_hd | 4 ++-- >> 4 files changed, 28 insertions(+), 4 deletions(-) >> >> diff --git a/build/scripts/empty_file b/build/scripts/empty_file >> new file mode 100755 >> --- /dev/null >> +++ b/build/scripts/empty_file >> @@ -0,0 +1,24 @@ >> +#!/usr/bin/python >> +# -*- coding: UTF-8 -*- >> + >> +# Eine leere Datei mit einer bestimmten Größe erzeugen >> +# Parameter: >> +# 1. Dateiname >> +# 2. Dateigröße >> +import sys >> + >> +def empty_file(filename, size): >> + f = open(filename,"wb") >> + if not f: >> + sys.exit(1) >> + >> + f.seek(size - 1) >> + f.write('\0') >> + f.close() > > Funktioniert nicht für size = 0 und verkleinert schon vorhandene Dateien > nicht. f.truncate (oder wie auch immer das heißen mag) wäre > wahrscheinlich besser. Ok das mit der 0 stimmt. Aber schon vorhanden Dateien werden auch verkleinert. mit 'w' wird eine evtl. Vorhanden Datei ersetzt. > >> + >> +if __name__ == "__main__": >> + if len(sys.argv[1:]) != 2: >> + print sys.stderr, "using: %s " % sys.argv[0] >> + sys.exit(1) >> + >> + empty_file(str(sys.argv[1]), int(sys.argv[2])) > > Tut das ganze nicht dasselbe wie dd of=$file seek=$size count=0? (Bzw. > in deiner Version auch noch conv=notrunc, aber das halte ich wie gesagt > für einen Bug und nicht für ein Feature) Das hat zwar, mit dem passenden 'bs', den gleichen Effekt, aber es ist viel zu einfach, und außerdem hat es 0-Bug nicht ;) > > Die Idee, nicht erstmal endlos Nullen zu schreiben, ist aber gut. > > Kevin -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 900 bytes Beschreibung: OpenPGP digital signature URL : From kevin at tyndur.org Sat Aug 14 20:47:08 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 14 Aug 2010 20:47:08 +0200 Subject: [tyndur-devel] [PATCH 2 of 2] build: hd Image nicht hin und her Kopieren In-Reply-To: <6ca2b56d8d9139d0af0d.1281704909@laptop> References: <6ca2b56d8d9139d0af0d.1281704909@laptop> Message-ID: <20100814184708.GB9845@silvanus> On Fri, Aug 13, 2010 at 03:08:29PM +0200, Andreas Freimuth wrote: > * statt das hd-Image mit dd hin und her zu kopieren loop-devices > verwenden > > Signed-off-by: MNemo Da gehört dein richtiger Name hin, wie im anderen Patch auch. > --- > build/scripts/image_hd | 11 ++++++----- > 1 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/build/scripts/image_hd b/build/scripts/image_hd > --- a/build/scripts/image_hd > +++ b/build/scripts/image_hd > @@ -69,14 +69,15 @@ PART_START=`echo $PARTITIONS | awk '{pri > PART_SIZE=`echo $PARTITIONS | awk '{print $2}'` > > if [ $NEW -ne 0 ]; then > - PART_IMAGE=`mktemp` > - build/scripts/empty_file $PART_IMAGE $(($PART_SIZE * 512)) > + LOOP_DEV=`$SUDO losetup -f $IMAGE_PATH --sizelimit $(($PART_SIZE * 512)) -o $(($PART_START * 512)) --show` > + if [ $? -ne 0 ]; then > + die "Loop Device konnte nicht angelegt werden" > + fi > > # Dateisystem erstellen > - $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" > + $SUDO $LOST_TOOLS_MKE2FS -T ext2 -F -q $LOOP_DEV || die "Dateisystem konnte nicht erstellt werden" > > - dd if=$PART_IMAGE of=$IMAGE_PATH bs=512 seek=$PART_START count=$PART_SIZE > - rm $PART_IMAGE > + $SUDO losetup -d $LOOP_DEV > fi > > # Partition mounten Sieht ansonsten gut aus und scheint auch zu funktionieren. From kevin at tyndur.org Sun Aug 15 19:14:14 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 15 Aug 2010 19:14:14 +0200 Subject: [tyndur-devel] [PATCH 1 of 2] build: dd if='/dev/zero' ... ist zu langsam In-Reply-To: <4C66E456.9090907@gmx.net> References: <5abe563fc8809ab410d5.1281787858@laptop> <20100814182842.GA9845@silvanus> <4C66E456.9090907@gmx.net> Message-ID: <20100815171414.GA8100@silvanus> On Sat, Aug 14, 2010 at 08:45:42PM +0200, Andreas Freimuth wrote: > Am 14.08.2010 20:28, schrieb Kevin Wolf: > > On Sat, Aug 14, 2010 at 02:10:58PM +0200, Andreas Freimuth wrote: > >> > >> * Beim Erstellen von leeren Images auf dd verzichten, statt dessen ein > >> kleines Python-Script verwenden > >> > >> Signed-off-by: Andreas Freimuth > >> --- > >> build/scripts/empty_file | 24 ++++++++++++++++++++++++ > >> build/scripts/image_cdrom | 2 +- > >> build/scripts/image_floppy | 2 +- > >> build/scripts/image_hd | 4 ++-- > >> 4 files changed, 28 insertions(+), 4 deletions(-) > >> > >> diff --git a/build/scripts/empty_file b/build/scripts/empty_file > >> new file mode 100755 > >> --- /dev/null > >> +++ b/build/scripts/empty_file > >> @@ -0,0 +1,24 @@ > >> +#!/usr/bin/python > >> +# -*- coding: UTF-8 -*- > >> + > >> +# Eine leere Datei mit einer bestimmten Größe erzeugen > >> +# Parameter: > >> +# 1. Dateiname > >> +# 2. Dateigröße > >> +import sys > >> + > >> +def empty_file(filename, size): > >> + f = open(filename,"wb") > >> + if not f: > >> + sys.exit(1) > >> + > >> + f.seek(size - 1) > >> + f.write('\0') > >> + f.close() > > > > Funktioniert nicht für size = 0 und verkleinert schon vorhandene Dateien > > nicht. f.truncate (oder wie auch immer das heißen mag) wäre > > wahrscheinlich besser. > Ok das mit der 0 stimmt. Aber schon vorhanden Dateien werden auch > verkleinert. mit 'w' wird eine evtl. Vorhanden Datei ersetzt. Ja, du hast recht. > >> + > >> +if __name__ == "__main__": > >> + if len(sys.argv[1:]) != 2: > >> + print sys.stderr, "using: %s " % sys.argv[0] > >> + sys.exit(1) > >> + > >> + empty_file(str(sys.argv[1]), int(sys.argv[2])) > > > > Tut das ganze nicht dasselbe wie dd of=$file seek=$size count=0? (Bzw. > > in deiner Version auch noch conv=notrunc, aber das halte ich wie gesagt > > für einen Bug und nicht für ein Feature) > Das hat zwar, mit dem passenden 'bs', den gleichen Effekt, aber es ist > viel zu einfach, und außerdem hat es 0-Bug nicht ;) Hm, ja. Würde es dir was ausmachen, trotzdem einen neuen Patch mit der viel zu einfachen dd-Variante zu schicken? ;-) Und den anderen Patch auch nochmal für das richtige Signed-off-by. From m.nemo at gmx.net Sun Aug 15 20:23:38 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sun, 15 Aug 2010 20:23:38 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_0_of_2_v2=5D_build=3A_=60dd_if?= =?utf-8?q?=2E=2E=2E=60_ist_nicht_immer_die_beste_L=C3=B6sung?= Message-ID: So? Ich hab jetzt die Patches entsprechend ausgebessert vieleicht kommen die ja diesmal soger in der Mailing-Liste an ;) build/scripts/image_cdrom | 2 +- build/scripts/image_floppy | 2 +- build/scripts/image_hd | 4 ++-- build/scripts/image_hd | 11 ++++++----- 4 files changed, 10 insertions(+), 9 deletions(-) From m.nemo at gmx.net Sun Aug 15 20:23:39 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sun, 15 Aug 2010 20:23:39 +0200 Subject: [tyndur-devel] [PATCH 1 of 2 v2] build: dd if='/dev/zero' ... ist zu langsam In-Reply-To: References: Message-ID: * Beim Erstellen von leeren Images nicht Tausende Null-Bytes kopieren Signed-off-by: Andreas Freimuth --- build/scripts/image_cdrom | 2 +- build/scripts/image_floppy | 2 +- build/scripts/image_hd | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/scripts/image_cdrom b/build/scripts/image_cdrom --- a/build/scripts/image_cdrom +++ b/build/scripts/image_cdrom @@ -96,7 +96,7 @@ EOF NEW=0 if ! [ -f $FLOPPY_IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$FLOPPY_IMAGE_PATH bs=1024 count=1440 + dd of=$FLOPY_IMAGE_PATH bs=1024 seek=1440 mformat l: NEW=1 fi diff --git a/build/scripts/image_floppy b/build/scripts/image_floppy --- a/build/scripts/image_floppy +++ b/build/scripts/image_floppy @@ -58,7 +58,7 @@ EOF NEW=0 if ! [ -f $IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$IMAGE_PATH bs=1024 count=1440 + dd of=$IMAGE_PATH bs=1024 seek=1440 mformat l: NEW=1 fi diff --git a/build/scripts/image_hd b/build/scripts/image_hd --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -57,7 +57,7 @@ die() NEW=0 if ! [ -f $IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$IMAGE_PATH bs=$((1024*1024)) count=$IMAGE_SIZE 2> /dev/null + dd of=$IMAGE_PATH bs=$((1024 * 1024)) seek=$IMAGE_SIZE build/scripts/create_partition $IMAGE_PATH NEW=1 fi @@ -70,7 +70,7 @@ PART_SIZE=`echo $PARTITIONS | awk '{prin if [ $NEW -ne 0 ]; then PART_IMAGE=`mktemp` - dd if=$IMAGE_PATH of=$PART_IMAGE bs=512 skip=$PART_START count=$PART_SIZE + dd of=$PART_IMAGE bs=512 seek=$PART_SIZE # Dateisystem erstellen $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" From m.nemo at gmx.net Sun Aug 15 20:23:40 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sun, 15 Aug 2010 20:23:40 +0200 Subject: [tyndur-devel] [PATCH 2 of 2 v2] build: hd Image nicht hin und her Kopieren In-Reply-To: References: Message-ID: <60818ee57f62acb32d5e.1281896620@laptop> * statt das hd-Image mit dd hin und her zu kopieren loop-devices verwenden Signed-off-by: Andreas Freimuth --- build/scripts/image_hd | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build/scripts/image_hd b/build/scripts/image_hd --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -69,14 +69,15 @@ PART_START=`echo $PARTITIONS | awk '{pri PART_SIZE=`echo $PARTITIONS | awk '{print $2}'` if [ $NEW -ne 0 ]; then - PART_IMAGE=`mktemp` - dd of=$PART_IMAGE bs=512 seek=$PART_SIZE + LOOP_DEV=`$SUDO losetup -f $IMAGE_PATH --sizelimit $(($PART_SIZE * 512)) -o $(($PART_START * 512)) --show` + if [ $? -ne 0 ]; then + die "Loop Device konnte nicht angelegt werden" + fi # Dateisystem erstellen - $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" + $SUDO $LOST_TOOLS_MKE2FS -T ext2 -F -q $LOOP_DEV || die "Dateisystem konnte nicht erstellt werden" - dd if=$PART_IMAGE of=$IMAGE_PATH bs=512 seek=$PART_START count=$PART_SIZE - rm $PART_IMAGE + $SUDO losetup -d $LOOP_DEV fi # Partition mounten From m.nemo at gmx.net Sun Aug 15 21:13:33 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sun, 15 Aug 2010 21:13:33 +0200 Subject: [tyndur-devel] [PATCH 1 of 2 v3] build: dd if='/dev/zero' ... ist zu langsam In-Reply-To: References: Message-ID: <5d16af296e6eb57fc4e9.1281899613@laptop> * Beim Erstellen von leeren Images nicht Tausende Null-Bytes kopieren Signed-off-by: Andreas Freimuth --- build/scripts/image_cdrom | 2 +- build/scripts/image_floppy | 2 +- build/scripts/image_hd | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/scripts/image_cdrom b/build/scripts/image_cdrom --- a/build/scripts/image_cdrom +++ b/build/scripts/image_cdrom @@ -96,7 +96,7 @@ EOF NEW=0 if ! [ -f $FLOPPY_IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$FLOPPY_IMAGE_PATH bs=1024 count=1440 + dd of=$FLOPPY_IMAGE_PATH bs=1024 seek=1440 count=0 mformat l: NEW=1 fi diff --git a/build/scripts/image_floppy b/build/scripts/image_floppy --- a/build/scripts/image_floppy +++ b/build/scripts/image_floppy @@ -58,7 +58,7 @@ EOF NEW=0 if ! [ -f $IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$IMAGE_PATH bs=1024 count=1440 + dd of=$IMAGE_PATH bs=1024 seek=1440 count=0 mformat l: NEW=1 fi diff --git a/build/scripts/image_hd b/build/scripts/image_hd --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -57,7 +57,7 @@ die() NEW=0 if ! [ -f $IMAGE_PATH ]; then # Leeres Image erstellen und formatieren - dd if=/dev/zero of=$IMAGE_PATH bs=$((1024*1024)) count=$IMAGE_SIZE 2> /dev/null + dd of=$IMAGE_PATH bs=$((1024 * 1024)) seek=$IMAGE_SIZE count=0 build/scripts/create_partition $IMAGE_PATH NEW=1 fi @@ -70,7 +70,7 @@ PART_SIZE=`echo $PARTITIONS | awk '{prin if [ $NEW -ne 0 ]; then PART_IMAGE=`mktemp` - dd if=$IMAGE_PATH of=$PART_IMAGE bs=512 skip=$PART_START count=$PART_SIZE + dd of=$PART_IMAGE bs=512 seek=$PART_SIZE count=0 # Dateisystem erstellen $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" From m.nemo at gmx.net Sun Aug 15 21:13:32 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sun, 15 Aug 2010 21:13:32 +0200 Subject: [tyndur-devel] [PATCH 0 of 2 v3] build: und alles noch mal Message-ID: So... dieses mal ist es sogar getestet, so weit das ohne grub geht ;) build/scripts/image_cdrom | 2 +- build/scripts/image_floppy | 2 +- build/scripts/image_hd | 4 ++-- build/scripts/image_hd | 11 ++++++----- 4 files changed, 10 insertions(+), 9 deletions(-) From m.nemo at gmx.net Sun Aug 15 21:13:34 2010 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sun, 15 Aug 2010 21:13:34 +0200 Subject: [tyndur-devel] [PATCH 2 of 2 v3] build: hd Image nicht hin und her Kopieren In-Reply-To: References: Message-ID: <97379f786d5d40a26453.1281899614@laptop> * statt das hd-Image mit dd hin und her zu kopieren loop-devices verwenden Signed-off-by: Andreas Freimuth --- build/scripts/image_hd | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build/scripts/image_hd b/build/scripts/image_hd --- a/build/scripts/image_hd +++ b/build/scripts/image_hd @@ -69,14 +69,15 @@ PART_START=`echo $PARTITIONS | awk '{pri PART_SIZE=`echo $PARTITIONS | awk '{print $2}'` if [ $NEW -ne 0 ]; then - PART_IMAGE=`mktemp` - dd of=$PART_IMAGE bs=512 seek=$PART_SIZE count=0 + LOOP_DEV=`$SUDO losetup -f $IMAGE_PATH --sizelimit $(($PART_SIZE * 512)) -o $(($PART_START * 512)) --show` + if [ $? -ne 0 ]; then + die "Loop Device konnte nicht angelegt werden" + fi # Dateisystem erstellen - $LOST_TOOLS_MKE2FS -F -q $PART_IMAGE || die "Dateisystem konnte nicht erstellt werden" + $SUDO $LOST_TOOLS_MKE2FS -T ext2 -F -q $LOOP_DEV || die "Dateisystem konnte nicht erstellt werden" - dd if=$PART_IMAGE of=$IMAGE_PATH bs=512 seek=$PART_START count=$PART_SIZE - rm $PART_IMAGE + $SUDO losetup -d $LOOP_DEV fi # Partition mounten From kevin at tyndur.org Sat Aug 21 00:52:09 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 21 Aug 2010 00:52:09 +0200 Subject: [tyndur-devel] [PATCH] kernel2: user_isf fuer VM86-Task korrekt initialisieren Message-ID: <1282344729-8346-1-git-send-email-kevin@tyndur.org> ! kernel2: Wenn man am kernel_stack rumpfuscht, um zusaetzlichen Platz fuer die VM86-Informationen zu haben, dann muss man user_isf mitanpassen. Ansonsten rutscht ein Teil des Stacks auf die naechste Page und macht dort entweder was kaputt oder pagefaultet. Signed-off-by: Kevin Wolf --- src/kernel2/src/arch/i386/vm86.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/kernel2/src/arch/i386/vm86.c b/src/kernel2/src/arch/i386/vm86.c index cdee6f1..2aa7a25 100644 --- a/src/kernel2/src/arch/i386/vm86.c +++ b/src/kernel2/src/arch/i386/vm86.c @@ -152,6 +152,7 @@ static int create_vm86_task(int intr, vm86_regs_t* regs, uintptr_t stack) // Und das ganze auf den Stack task->kernel_stack = ((uint8_t*) task->kernel_stack) + sizeof(*isf) - sizeof(visf); + task->user_isf = task->kernel_stack; memcpy(task->kernel_stack, &visf, sizeof(visf)); // Sofort in den VM86-Task wechseln. Der aufrufende Thread wird -- 1.6.0.2 From kevin at tyndur.org Sat Aug 21 21:45:55 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 21 Aug 2010 21:45:55 +0200 Subject: [PATCH 0/2] Fix für Prüfung auf Doppelmapping Message-ID: <1282419957-14874-1-git-send-email-kevin@tyndur.org> Kevin Wolf (2): kernel2: Nicht mehr Videospeicher mappen als es gibt kernel2: Prüfung auf Doppelmapping gefixt src/kernel2/src/arch/i386/mm/mm_context.c | 6 +++--- src/kernel2/src/arch/i386/mm/virt.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) From kevin at tyndur.org Sat Aug 21 21:45:56 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 21 Aug 2010 21:45:56 +0200 Subject: [tyndur-devel] [PATCH 1/2] kernel2: Nicht mehr Videospeicher mappen als es gibt In-Reply-To: <1282419957-14874-1-git-send-email-kevin@tyndur.org> References: <1282419957-14874-1-git-send-email-kevin@tyndur.org> Message-ID: <1282419957-14874-2-git-send-email-kevin@tyndur.org> ! kernel2: Von 0xb8000 bis 0xc0000 sind es 8 Pages, nicht 16. Signed-off-by: Kevin Wolf --- src/kernel2/src/arch/i386/mm/virt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/kernel2/src/arch/i386/mm/virt.c b/src/kernel2/src/arch/i386/mm/virt.c index 9b0b4ea..a656a1a 100644 --- a/src/kernel2/src/arch/i386/mm/virt.c +++ b/src/kernel2/src/arch/i386/mm/virt.c @@ -66,7 +66,7 @@ void vmm_init(mmc_context_t* kernel_context) // TODO Usermodus muss die momentan wegen VM86 sehen. Waere wohl besser, // wenn VM86 einen eigenen Adressraum haette. mmc_map(kernel_context, (vaddr_t) 0xB8000, (paddr_t) 0xB8000, - PTE_U | PTE_W | PTE_P, 0x10); + PTE_U | PTE_W | PTE_P, 8); // BIOS mappen mmc_map(kernel_context, (vaddr_t) 0xC0000, (paddr_t) 0xC0000, -- 1.6.0.2 From kevin at tyndur.org Sat Aug 21 21:45:57 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 21 Aug 2010 21:45:57 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_2/2=5D_kernel2=3A_Pr=C3=BCfung_?= =?utf-8?q?auf_Doppelmapping_gefixt?= In-Reply-To: <1282419957-14874-1-git-send-email-kevin@tyndur.org> References: <1282419957-14874-1-git-send-email-kevin@tyndur.org> Message-ID: <1282419957-14874-3-git-send-email-kevin@tyndur.org> ! kernel2: Ein Mapping hat sich dann geändert, wenn die Adressen ungleich sind, nicht wenn sie gleich sind Signed-off-by: Kevin Wolf --- src/kernel2/src/arch/i386/mm/mm_context.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel2/src/arch/i386/mm/mm_context.c index b2b3d42..ad91567 100644 --- a/src/kernel2/src/arch/i386/mm/mm_context.c +++ b/src/kernel2/src/arch/i386/mm/mm_context.c @@ -337,9 +337,9 @@ static bool map_page bool page_is_present = (page_table[vpage % PAGE_TABLE_LENGTH] & PTE_P); bool unmap_page = ! (flags & PTE_P); - bool mapping_changed = - ((page_table[vpage % PAGE_TABLE_LENGTH] & ~(PTE_A | PTE_D)) - == + bool mapping_changed = + ((page_table[vpage % PAGE_TABLE_LENGTH] & ~(PTE_A | PTE_D)) + != ((uint32_t) paddr | flags)); if (page_is_present && !unmap_page && mapping_changed) -- 1.6.0.2 From max at tyndur.org Sat Aug 21 22:01:28 2010 From: max at tyndur.org (Max Reitz) Date: Sat, 21 Aug 2010 22:01:28 +0200 Subject: [tyndur-devel] [PATCH 1/2] kernel2: Nicht mehr Videospeicher mappen als es gibt In-Reply-To: <1282419957-14874-2-git-send-email-kevin@tyndur.org> References: <1282419957-14874-1-git-send-email-kevin@tyndur.org> <1282419957-14874-2-git-send-email-kevin@tyndur.org> Message-ID: <4C703098.4090707@tyndur.org> Am 21.08.2010 21:45, schrieb Kevin Wolf: > ! kernel2: Von 0xb8000 bis 0xc0000 sind es 8 Pages, nicht 16. > > Signed-off-by: Kevin Wolf Das sagt mein Taschenrechner auch. ;-) Acked-by: Max Reitz From max at tyndur.org Sat Aug 21 22:01:50 2010 From: max at tyndur.org (Max Reitz) Date: Sat, 21 Aug 2010 22:01:50 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH_2/2=5D_kernel2=3A_Pr=FCfun?= =?iso-8859-1?q?g_auf_Doppelmapping_gefixt?= In-Reply-To: <1282419957-14874-3-git-send-email-kevin@tyndur.org> References: <1282419957-14874-1-git-send-email-kevin@tyndur.org> <1282419957-14874-3-git-send-email-kevin@tyndur.org> Message-ID: <4C7030AE.1060506@tyndur.org> Am 21.08.2010 21:45, schrieb Kevin Wolf: > ! kernel2: Ein Mapping hat sich dann geändert, wenn die Adressen > ungleich sind, nicht wenn sie gleich sind > > Signed-off-by: Kevin Wolf Acked-by: Max Reitz From max at tyndur.org Sun Aug 22 11:36:40 2010 From: max at tyndur.org (max at tyndur.org) Date: Sun, 22 Aug 2010 11:36:40 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_kernel2=3A_KERNEL=5FMEM=5FST?= =?utf-8?q?ART_f=C3=BCr_vm86_anpassen?= Message-ID: <1282469800-7129-1-git-send-email-max@tyndur.org> From: Max Reitz * Wenn KERNEL_MEM_START NULL ist, ermuntert dies alle Tasks geradezu, sich Speicher ins virtuelle erste MB zu mappen und so jeglichen vm86-Versuch im Keim ersticken zu lassen. Hebt man den Wert auf 1 MB an, so ändert sich das. Signed-off-by: Max Reitz --- src/include/arch/i386/page.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/include/arch/i386/page.h b/src/include/arch/i386/page.h index ae12340..266d59c 100644 --- a/src/include/arch/i386/page.h +++ b/src/include/arch/i386/page.h @@ -41,7 +41,7 @@ // TODO: Muss das Kernelzeug wirklich hier sein? :/ // Die Adresse, an der der Kernel-Adressraum beginnt -#define KERNEL_MEM_START 0x00000000 +#define KERNEL_MEM_START 0x00100000 #define KERNEL_MEM_END 0x40000000 #define PAGETABLES_MEM_START 0x3fc00000 -- 1.7.1 From springreiter-christian at t-online.de Sun Aug 22 15:02:20 2010 From: springreiter-christian at t-online.de (Thylon) Date: Sun, 22 Aug 2010 15:02:20 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH_2/2=5D_kernel2=3A_Pr=FCfun?= =?iso-8859-1?q?g_auf_Doppelmapping_gefixt?= In-Reply-To: <1282419957-14874-3-git-send-email-kevin@tyndur.org> References: <1282419957-14874-1-git-send-email-kevin@tyndur.org> <1282419957-14874-3-git-send-email-kevin@tyndur.org> Message-ID: <4C711FDC.1080008@t-online.de> Am 21.08.2010 21:45, schrieb Kevin Wolf: > ! kernel2: Ein Mapping hat sich dann geändert, wenn die Adressen > ungleich sind, nicht wenn sie gleich sind > > Signed-off-by: Kevin Wolf > Acked-by: Thylon From springreiter-christian at t-online.de Sun Aug 22 14:59:12 2010 From: springreiter-christian at t-online.de (Thylon) Date: Sun, 22 Aug 2010 14:59:12 +0200 Subject: [tyndur-devel] [PATCH 1/2] kernel2: Nicht mehr Videospeicher mappen als es gibt In-Reply-To: <1282419957-14874-2-git-send-email-kevin@tyndur.org> References: <1282419957-14874-1-git-send-email-kevin@tyndur.org> <1282419957-14874-2-git-send-email-kevin@tyndur.org> Message-ID: <4C711F20.9000903@t-online.de> Am 21.08.2010 21:45, schrieb Kevin Wolf: > ! kernel2: Von 0xb8000 bis 0xc0000 sind es 8 Pages, nicht 16. > > Signed-off-by: Kevin Wolf > Meiner auch. Acked-by: Thylon From kevin at tyndur.org Sun Aug 22 16:51:54 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 22 Aug 2010 16:51:54 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_shell=3A_LIOv2-Fixes_f=C3=BC?= =?utf-8?q?r_cp?= Message-ID: <1282488714-2258-1-git-send-email-kevin@tyndur.org> ! shell: Verdrehte fread-Parameter in cp gefixt. cp muss 1 für die Objektgröße nehmen, sonst werden nur Dateien mit durch 4k teilbarer Größe richtig kopiert ! shell: Ein fread-Rückgabewert von 0 ist nicht zwingend ein Fehler Signed-off-by: Kevin Wolf --- src/modules/c/shell/cmds/cp.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/c/shell/cmds/cp.c b/src/modules/c/shell/cmds/cp.c index 5c0f0e8..88a04fd 100644 --- a/src/modules/c/shell/cmds/cp.c +++ b/src/modules/c/shell/cmds/cp.c @@ -250,13 +250,13 @@ int cp_file(char* src_path, char* dst_path) { uint8_t buffer[BUFFER_SIZE]; - while (!feof(src)) { - size_t length = fread(buffer, BUFFER_SIZE, 1, src); - if (length == 0) { - fprintf(stderr, "Fehler beim Kopieren: %d\n", length); + while (!feof(src)) { + size_t length = fread(buffer, 1, BUFFER_SIZE, src); + if (ferror(src)) { + fprintf(stderr, "Fehler beim Lesen der Quelldatei\n"); fclose(src); fclose(dst); - return EXIT_FAILURE; + return -3; } fwrite(buffer, length, 1, dst); -- 1.6.0.2 From kevin at tyndur.org Mon Aug 23 15:18:47 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 23 Aug 2010 15:18:47 +0200 Subject: [tyndur-devel] p ohne v Message-ID: <20100823151847.117659t77ihtu1pz@mail.famkaufmann.info> Nachdem ein tolles neues Spielzeug sogar Ergebnisse gebracht hat, poste ich die mal hierhin, damit sie nicht verloren gehen. Der folgende spatch... @@ @@ p(); ... ( v(); ... return ...; | +v(); return ...; ) ...hat folgende Stellen gefunden, in denen ein v(); fehlt. Unbesehen direkt als Patch nehmen sollte man das wohl nicht, aber bei Gelegenheit könnte man die Stellen fixen. diff -u -p a/dma/dma.c b/dma/dma.c --- a/dma/dma.c 2010-07-30 08:52:11.000000000 +0200 +++ b/dma/dma.c 2010-08-23 14:55:17.000000000 +0200 @@ -137,8 +137,10 @@ bool setup_dma(uint8_t channel, uint8_t // Mehrere Zugriffe auf einen DMA-Kanal? Is nich. // TODO Evtl. warten, bis der DMA-Kanal frei wird? - if (dma_transfers[channel].used) + if (dma_transfers[channel].used) { + v(); return false; + } // Wenn der Kanal schon die richtige Gr��e hat, wiederverawenden dma_mem_ptr_t dma_ptr; diff -u -p a/cdi/lib/fs/lostio_if.c b/cdi/lib/fs/lostio_if.c --- a/cdi/lib/fs/lostio_if.c 2010-07-30 08:52:11.000000000 +0200 +++ b/cdi/lib/fs/lostio_if.c 2010-08-23 14:55:18.000000000 +0200 @@ -474,6 +474,7 @@ int lostio_seek_handler(lostio_filehandl break; default: + v(); return -1; } diff -u -p a/lib/posix/wait.c b/lib/posix/wait.c --- a/lib/posix/wait.c 2010-07-30 08:52:11.000000000 +0200 +++ b/lib/posix/wait.c 2010-08-23 14:55:20.000000000 +0200 @@ -88,6 +88,7 @@ void wait_child_add(pid_t pid) // Es kann sein, dass der Prozess schon terminiert hat, wenn diese funktion // aufgerufen wird! if (wait_child != NULL) { + v(); return; } diff -u -p a/fat/file.c b/fat/file.c --- a/fat/file.c 2010-07-30 08:52:11.000000000 +0200 +++ b/fat/file.c 2010-08-23 14:55:20.000000000 +0200 @@ -166,6 +166,7 @@ size_t fat_file_write_handler(lostio_fil res_info->cluster = fat_allocate_cluster(filehandle); if (res_info->cluster == 0) { puts("fat: Keine freien Cluster mehr vorhanden!"); + v(); return 0; } fat_set_fat_entry(filehandle, res_info->cluster, 0xfff); @@ -184,6 +185,7 @@ size_t fat_file_write_handler(lostio_fil if (!fat_save_clusters(filehandle, res_info->cluster, res_info->data, res_info->size)) { + v(); return 0; } @@ -215,6 +217,7 @@ int fat_file_seek_handler(lostio_filehan { int newpos = offset; if ((filehandle->flags & IO_OPEN_MODE_WRITE) == 0) { + v(); return -1; } else { filehandle->pos = filehandle->node->size; @@ -225,6 +228,7 @@ int fat_file_seek_handler(lostio_filehan free(data); if (filehandle->pos != filehandle->pos) { + v(); return -1; } } @@ -241,6 +245,7 @@ int fat_file_seek_handler(lostio_filehan int newpos = offset + filehandle->pos; if ((filehandle->flags & IO_OPEN_MODE_WRITE) == 0) { + v(); return -1; } else { filehandle->pos = filehandle->node->size; @@ -251,6 +256,7 @@ int fat_file_seek_handler(lostio_filehan free(data); if (filehandle->pos != filehandle->pos) { + v(); return -1; } } From kevin at tyndur.org Mon Aug 23 22:01:22 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 23 Aug 2010 22:01:22 +0200 Subject: [PATCH 0/2] Fixes für p ohne v Message-ID: <1282593684-20412-1-git-send-email-kevin@tyndur.org> Die Bugs in FAT hab ich mal weggelassen, in der Hoffnung, dass bald der neue FAT-Treiber einsatzfähig ist... Kevin Wolf (2): libc: Fehlendes v() in wait_child_add dma: Fehlendes v() in setup_dma src/modules/dma/dma.c | 4 +++- src/modules/lib/posix/wait.c | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) From kevin at tyndur.org Mon Aug 23 22:01:23 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 23 Aug 2010 22:01:23 +0200 Subject: [tyndur-devel] [PATCH 1/2] libc: Fehlendes v() in wait_child_add In-Reply-To: <1282593684-20412-1-git-send-email-kevin@tyndur.org> References: <1282593684-20412-1-git-send-email-kevin@tyndur.org> Message-ID: <1282593684-20412-2-git-send-email-kevin@tyndur.org> ! libc: wait_child_add hat im Fehlerfall ein v() vergessen Signed-off-by: Kevin Wolf --- src/modules/lib/posix/wait.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/lib/posix/wait.c b/src/modules/lib/posix/wait.c index e7d52a6..2f32ccb 100644 --- a/src/modules/lib/posix/wait.c +++ b/src/modules/lib/posix/wait.c @@ -84,11 +84,11 @@ void wait_child_add(pid_t pid) { p(); struct wait_child* wait_child = wait_child_get(pid); - - // Es kann sein, dass der Prozess schon terminiert hat, wenn diese funktion + + // Es kann sein, dass der Prozess schon terminiert hat, wenn diese Funktion // aufgerufen wird! if (wait_child != NULL) { - return; + goto out; } wait_child = malloc(sizeof(struct wait_child)); @@ -98,7 +98,8 @@ void wait_child_add(pid_t pid) wait_child->running = true; wait_child->status = -1; list_push(wait_list, wait_child); - + +out: v(); } -- 1.6.0.2 From kevin at tyndur.org Mon Aug 23 22:01:24 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 23 Aug 2010 22:01:24 +0200 Subject: [tyndur-devel] [PATCH 2/2] dma: Fehlendes v() in setup_dma In-Reply-To: <1282593684-20412-1-git-send-email-kevin@tyndur.org> References: <1282593684-20412-1-git-send-email-kevin@tyndur.org> Message-ID: <1282593684-20412-3-git-send-email-kevin@tyndur.org> ! dma: Fehlendes v() korrigiert, wenn der angeforderte DMA-Kanal scho belegt ist Signed-off-by: Kevin Wolf --- src/modules/dma/dma.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/modules/dma/dma.c b/src/modules/dma/dma.c index 108e61e..4c4e00b 100644 --- a/src/modules/dma/dma.c +++ b/src/modules/dma/dma.c @@ -137,8 +137,10 @@ bool setup_dma(uint8_t channel, uint8_t mode, uint32_t length) // Mehrere Zugriffe auf einen DMA-Kanal? Is nich. // TODO Evtl. warten, bis der DMA-Kanal frei wird? - if (dma_transfers[channel].used) + if (dma_transfers[channel].used) { + v(); return false; + } // Wenn der Kanal schon die richtige Größe hat, wiederverawenden dma_mem_ptr_t dma_ptr; -- 1.6.0.2 From kevin at tyndur.org Sat Aug 28 17:43:04 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 28 Aug 2010 17:43:04 +0200 Subject: [tyndur-devel] [PATCH] libm: fmod implementiert Message-ID: <1283010184-28502-1-git-send-email-kevin@tyndur.org> + libm: fmod implementiert Signed-off-by: Kevin Wolf --- src/modules/include/math.h | 4 ++ src/modules/lib/stdlibc/math/fmod.c | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/stdlibc/math/fmod.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 207fd3d..968411b 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -117,6 +117,10 @@ long double nearbyintl(long double x); double rint(double x); double pow(double x, double y); +double fmod(double x, double y); +float fmodf(float x, float y); +long double fmodl(long double x, long double y); + #ifdef __cplusplus }; // extern "C" #endif diff --git a/src/modules/lib/stdlibc/math/fmod.c b/src/modules/lib/stdlibc/math/fmod.c new file mode 100644 index 0000000..d691ca1 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fmod.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +double fmod(double x, double y) +{ + double res; + + if (y == 0.0) { + errno = EDOM; + return NAN; + } + + asm("fprem" : "=t" (res) : "0" (x), "u" (y)); + return res; +} + +float fmodf(float x, float y) +{ + float res; + + if (y == 0.0) { + errno = EDOM; + return NAN; + } + + asm("fprem" : "=t" (res) : "0" (x), "u" (y)); + return res; +} + +long double fmodl(long double x, long double y) +{ + long double res; + + if (y == 0.0) { + errno = EDOM; + return NAN; + } + + asm("fprem" : "=t" (res) : "0" (x), "u" (y)); + return res; +} -- 1.6.0.2 From max at tyndur.org Sun Aug 29 17:20:05 2010 From: max at tyndur.org (Max Reitz) Date: Sun, 29 Aug 2010 17:20:05 +0200 Subject: [tyndur-devel] [PATCH] kernel2: vm86 Message-ID: <1283095205-26143-1-git-send-email-max@tyndur.org> * Mit diesem Patch wird für jeden vm86-Thread ein komplett eigener Adressraum erstellt, in welchen mittels Hardwaremultitasking gewechselt wird. Dies erlaubt zwar noch nicht, dass mehrere vm86- Threads gleichzeitig laufen können, sorgt aber zumindest dafür, dass die Nullpage erstens in anderen Threads ungemappt bleibt und diese anderen zweitens auch nicht auf den vm86-Speicher zugreifen können. Signed-off-by: Max Reitz --- src/kernel2/include/arch/i386/cpu.h | 1 + src/kernel2/include/mm.h | 4 + src/kernel2/src/arch/i386/gdt.c | 38 ++- src/kernel2/src/arch/i386/interrupts/im.c | 2 +- src/kernel2/src/arch/i386/interrupts/int_stubs.S | 23 ++ src/kernel2/src/arch/i386/kernel.ld | 9 + src/kernel2/src/arch/i386/mm/mm_context.c | 34 ++- src/kernel2/src/arch/i386/vm86.c | 411 +++++++++++++++------- src/kernel2/src/arch/i386/vm86_asm.S | 15 + src/kernel2/src/interrupts/im.c | 2 +- src/kernel2/src/tasks/scheduler.c | 2 +- 11 files changed, 401 insertions(+), 140 deletions(-) create mode 100644 src/kernel2/src/arch/i386/vm86_asm.S diff --git a/src/kernel2/include/arch/i386/cpu.h b/src/kernel2/include/arch/i386/cpu.h index bbc01b9..e1870b3 100644 --- a/src/kernel2/include/arch/i386/cpu.h +++ b/src/kernel2/include/arch/i386/cpu.h @@ -119,6 +119,7 @@ typedef struct { uint8_t apic_id; bool bootstrap; cpu_tss_t tss; + uint16_t tss_selector; pm_thread_t* thread; vaddr_t apic_base; mmc_context_t* mm_context; diff --git a/src/kernel2/include/mm.h b/src/kernel2/include/mm.h index ffb68b1..b3870ca 100644 --- a/src/kernel2/include/mm.h +++ b/src/kernel2/include/mm.h @@ -83,6 +83,7 @@ void vmm_kernel_unmap(vaddr_t start, size_t size); */ mmc_context_t mmc_create(void); +mmc_context_t mmc_create_empty(void); mmc_context_t mmc_create_kernel_context(void); void mmc_destroy(mmc_context_t* context); @@ -99,6 +100,9 @@ vaddr_t mmc_automap_user(mmc_context_t* target_ctx, mmc_context_t* source_ctx, vaddr_t start, size_t count, uintptr_t lower_limit, uintptr_t upper_limit, int flags); +vaddr_t get_pagetable(mmc_context_t* context, size_t index); +void free_pagetable(mmc_context_t* context, vaddr_t page_table); + /** * Alloziert einen virtuell (aber nicht zwingend physisch) zusammenhaengenden * Speicherbereich diff --git a/src/kernel2/src/arch/i386/gdt.c b/src/kernel2/src/arch/i386/gdt.c index 4b85a7a..dc4f3cb 100644 --- a/src/kernel2/src/arch/i386/gdt.c +++ b/src/kernel2/src/arch/i386/gdt.c @@ -33,6 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include "mm.h" @@ -60,7 +61,7 @@ typedef struct { } segment_descriptor; /// Die GDT -segment_descriptor gdt[GDT_SIZE]; +segment_descriptor gdt[GDT_SIZE] __attribute__((section(".gdt_section"))); /// Letzter Eintrag in der GDT uint16_t next_entry_index = 0; @@ -81,8 +82,10 @@ cpu_tss_t double_fault_tss = { void gdt_init_local(void); static void gdt_set_descriptor(int segment, uint32_t size, uint32_t base, uint8_t access, int dpl); -static void gdt_set_descriptor_byte_granularity(int segment, uint32_t size, +void gdt_set_descriptor_byte_granularity(int segment, uint32_t size, uint32_t base, uint8_t access, int dpl); +void* gdt_get_descriptor_base(int segment); +void gdt_set_busy_flag(int segment, bool state); /** * Legt eine GDT an und initialisiert sie mit mit jeweils einem Code- und @@ -122,8 +125,9 @@ void gdt_init_local(void) lock(&gdt_lock); // Deskriptor fuer das Task state segment anlegen + cpu_get_current()->tss_selector = next_entry_index << 3; gdt_set_descriptor_byte_granularity(next_entry_index++, sizeof(cpu_tss_t) - - 1, (uint32_t) &(cpu_get_current()->tss), GDT_PRESENT | GDT_TSS, 3); + 1, (uint32_t) &(cpu_get_current()->tss), GDT_PRESENT | GDT_TSS, 3); // TSS fuer Double-Fault-Handler double_fault_tss.cr3 = (uintptr_t) pmm_alloc(1); @@ -190,9 +194,35 @@ static void gdt_set_descriptor(int segment, uint32_t size, uint32_t base, * @param access Access-Byte des Deskriptors * @param dpl Descriptor Privilege Level */ -static void gdt_set_descriptor_byte_granularity(int segment, uint32_t size, +void gdt_set_descriptor_byte_granularity(int segment, uint32_t size, uint32_t base, uint8_t access, int dpl) { gdt_set_descriptor(segment, size, base, access, dpl); gdt[segment].size2 = ((size >> 16) & 0x0F) | 0x40; } + +/** + * Gibt die Basisadresse eines Deskriptors in der GDT zurück. + * + * @param segment Nummer des Deskriptors + * + * @return Basisadresse + */ +void* gdt_get_descriptor_base(int segment) +{ + return (void*) (gdt[segment].base | (gdt[segment].base2 << 16) | (gdt[segment].base3 << 24)); +} + +/** + * Setzt den Status des Busyflags eines Deskriptors (von TSS). + * + * @param segment Nummer des Deskriptors + * @param state Neuer Status + */ +void gdt_set_busy_flag(int segment, bool state) +{ + if (state == true) + gdt[segment].access |= (1 << 1); + else + gdt[segment].access &= ~(1 << 1); +} diff --git a/src/kernel2/src/arch/i386/interrupts/im.c b/src/kernel2/src/arch/i386/interrupts/im.c index d8a7c1b..b6a123f 100644 --- a/src/kernel2/src/arch/i386/interrupts/im.c +++ b/src/kernel2/src/arch/i386/interrupts/im.c @@ -69,7 +69,7 @@ typedef struct { } __attribute__((packed)) idt_gate_t; // Die ganze IDT (Achtung wird auch aus dem SMP-Trampoline-Code geladen!) -idt_gate_t idt[IDT_GATE_COUNT]; +idt_gate_t idt[IDT_GATE_COUNT] __attribute__((section(".idt_section"))); bool use_apic; static void idt_set_gate(size_t interrupt, vaddr_t handler, diff --git a/src/kernel2/src/arch/i386/interrupts/int_stubs.S b/src/kernel2/src/arch/i386/interrupts/int_stubs.S index d34e3b4..2c710ce 100644 --- a/src/kernel2/src/arch/i386/interrupts/int_stubs.S +++ b/src/kernel2/src/arch/i386/interrupts/int_stubs.S @@ -463,6 +463,29 @@ im_int_stub_8: hlt jmp . +.globl load_isf_and_return +load_isf_and_return: + mov 4(%esp), %esp + + pop %ebx + pop %ecx + pop %edx + pop %esi + pop %edi + pop %ebp + + pop %ds + pop %es + pop %fs + pop %gs + + pop %eax + + add $8, %esp + + iret + + msg_double_fault: .ascii "\033[1;41mPANIC: Double fault\n\0" diff --git a/src/kernel2/src/arch/i386/kernel.ld b/src/kernel2/src/arch/i386/kernel.ld index 6921bcf..d9dcd48 100644 --- a/src/kernel2/src/arch/i386/kernel.ld +++ b/src/kernel2/src/arch/i386/kernel.ld @@ -31,6 +31,15 @@ SECTIONS *(.bss) } + .gdt_section ALIGN(4096) : AT(ADDR(.gdt_section) - VIRT_TO_PHYS) + { + *(.gdt_section) + } + .idt_section ALIGN(4096) : AT(ADDR(.idt_section) - VIRT_TO_PHYS) + { + *(.idt_section) + } + . = ALIGN(4096); kernel_end = .; diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel2/src/arch/i386/mm/mm_context.c index 38c0d6b..dc7ef7a 100644 --- a/src/kernel2/src/arch/i386/mm/mm_context.c +++ b/src/kernel2/src/arch/i386/mm/mm_context.c @@ -63,8 +63,8 @@ bool use_phys_addr = true; */ static void mmc_sync(mmc_context_t* context); -static inline vaddr_t get_pagetable(mmc_context_t* context, size_t index); -static inline void free_pagetable(mmc_context_t* context, vaddr_t page_table); +vaddr_t get_pagetable(mmc_context_t* context, size_t index); +void free_pagetable(mmc_context_t* context, vaddr_t page_table); /** * Erstellt einen neuen MM-Kontext (Page Directory) @@ -92,6 +92,25 @@ mmc_context_t mmc_create() } /** + * Erstellt einen komplett neuen und unabhängigen MM-Kontext + */ +mmc_context_t mmc_create_empty() +{ + // Das Page Directory initialisieren + paddr_t phys_page_directory = pmm_alloc(1); + mmc_context_t context; + context.version = 0xFFFFFFFF; + context.lock = LOCK_UNLOCKED; + context.page_directory = phys_page_directory; + context.page_directory_virt = vmm_kernel_automap( + context.page_directory, PAGE_SIZE); + + memset(context.page_directory_virt, 0, PAGE_SIZE); + + return context; +} + +/** * Erstellt einen neuen MM-Kontext (Page Directory) für den Kernel. * Diese Funktion wird nur zur Initialisierung benutzt, solange Paging * noch nicht aktiviert ist. @@ -189,7 +208,7 @@ void mmc_destroy(mmc_context_t* context) * aktuellen Page Directory gehört. Ansonsten wird ein Pointer auf die * Page Table in den oberen 4 MB des Kernelspeichers zurückgegeben */ -static inline vaddr_t get_pagetable(mmc_context_t* context, size_t index) +vaddr_t get_pagetable(mmc_context_t* context, size_t index) { page_directory_t pagedir = context->page_directory_virt; page_table_t page_table; @@ -217,7 +236,7 @@ static inline vaddr_t get_pagetable(mmc_context_t* context, size_t index) * Gibt eine mit get_pagetable angeforderte Page Table wieder frei, falls sie * nicht zum aktuellen Page Directory gehört. */ -static inline void free_pagetable(mmc_context_t* context, vaddr_t page_table) +void free_pagetable(mmc_context_t* context, vaddr_t page_table) { if (context->page_directory != mmc_current_context().page_directory) { mmc_unmap(&mmc_current_context(), page_table, 1); @@ -277,12 +296,17 @@ static bool map_page // Kernelpages duerfen immer nur im gerade aktiven Kontext gemappt werden. // Ales andere ergibt keinen Sinn, weil diese Bereiche ohnehin zwischen // allen Kontexten synchron gehalten werden muessen. + // + // TODO: Ergibt sehr wohl Sinn, wenn man nämlich IDT und GDT von einem + // vm86-Task erstellen will. +#if 0 if ((context != &mmc_current_context()) && ((uintptr_t) vaddr >= KERNEL_MEM_START) && ((uintptr_t) vaddr < KERNEL_MEM_END)) { panic("Versuch, Kernelpages in inaktivem Kontext zu mappen"); } +#endif // Falls es sich im den aktuellen Kontext handelt, muss das Page directory // nicht gemappt werden, sonst schon. @@ -303,7 +327,7 @@ static bool map_page clear_page_table = true; if (((uintptr_t) vaddr >= KERNEL_MEM_START) && ((uintptr_t) vaddr < - KERNEL_MEM_END)) + KERNEL_MEM_END) && (context->version != 0xFFFFFFFF)) { context->version = ++page_directory_version; page_directory_current = context->page_directory_virt; diff --git a/src/kernel2/src/arch/i386/vm86.c b/src/kernel2/src/arch/i386/vm86.c index 2aa7a25..a040a55 100644 --- a/src/kernel2/src/arch/i386/vm86.c +++ b/src/kernel2/src/arch/i386/vm86.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -87,15 +88,28 @@ static struct { // FIXME Das darf eigentich nicht global sein static struct { bool in_use; - void* stack; - void* nullpage; + void* first_mb; uint32_t* memory; pm_thread_t* caller; vm86_regs_t* regs; + mmc_context_t mmc; } vm86_status = { .in_use = false, }; +extern uint16_t next_entry_index; +extern lock_t gdt_lock; +extern uint64_t idt[256]; +extern uint64_t gdt[255]; + +extern void gdt_set_descriptor_byte_granularity(int segment, uint32_t size, + uint32_t base, uint8_t access, int dpl); +extern void* gdt_get_descriptor_base(int segment); +extern void gdt_set_busy_flag(int segment, bool state); + +extern interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf); +extern void load_isf_and_return(uint32_t new_stack) __attribute__((noreturn)); + /** * Speichert BIOS-Daten, um sie den VM86-Tasks später bereitstellen zu können */ @@ -104,6 +118,94 @@ void vm86_init(void) memcpy(&bios_data, 0, 4096); } +// Einsprungspunkt für den vm86-Thread nach jedem Taskwechsel (setzt das +// NT-Flag und biegt den Backlinkpointer vom aktuellen TSS um) +extern void vm86_task_entry(void); + +/** + * Gibt einen Pointer zum Backlink des Standard-TSS zurück + */ +uint32_t vm86_get_backlink_pointer(void) +{ + return (uintptr_t) &cpu_get_current()->tss.backlink; +} + +static void vm86_gpf_entry(uint32_t above_error_code) +{ + // Der tatsächliche Fehlercode ist dort, wo normalerweise EIP für den + // Rücksprung liegt, also genau ein uint32_t unter dem ersten Parameter + uint32_t error_code = (&above_error_code)[-1]; + uint16_t tr; + + asm volatile ("str %0" : "=r"(tr)); + + cpu_tss_t* gpf_tss = gdt_get_descriptor_base(tr >> 3); + cpu_tss_t* vm86_tss = gdt_get_descriptor_base(gpf_tss->backlink >> 3); + + // Originalen Busyflagzustand wiederherstellen + gdt_set_busy_flag(tr >> 3, false); + gdt_set_busy_flag(gpf_tss->backlink >> 3, true); + + // Das Standard-TSS verwenden + asm volatile ("ltr %0" :: "r"(cpu_get_current()->tss_selector)); + + asm volatile ("pushfl;" + "pop %%eax;" + "and $0xFFFFBFFF,%%eax;" // NT-Flag löschen + "push %%eax;" + "popfl" ::: "eax"); + + // Der „künstliche“ Stackframe hier enthält zum Teil Werte, die nichts mit + // vm86 zu tun haben. Sollte der Thread unterbrochen werden, so wird die + // Ausführung beim nächsten Mal bei vm86_task_entry fortgeführt. + interrupt_stack_frame_t isf = { + .eax = vm86_tss->eax, + .ebx = gpf_tss->backlink, + .ecx = vm86_tss->ecx, + .edx = vm86_tss->edx, + .esi = vm86_tss->esi, + .edi = vm86_tss->edi, + .ebp = (uintptr_t) vm86_tss, + .esp = vm86_tss->esp, + .ds = 0x10, + .es = 0x10, + .fs = 0x10, + .gs = 0x10, + .ss = 0x10, + // Originale Interruptnummer wird aus dem Fehlercode bestimmt + .interrupt_number = (error_code & (1 << 1)) ? (error_code >> 3) : 13, + // Wenn dies ein reiner GPF ist, dann können wir den Fehlercode + // übernehmen, sonst ist er unbekannt. + .error_code = (error_code & (1 << 1)) ? 0 : error_code, + .eip = (uintptr_t) &vm86_task_entry, + .cs = 0x08, + // Das gelöschte Bit 1 zeigt, dass es sich um einen vm86-Task handelt + .eflags = 0x200 + }; + + if ((isf.interrupt_number < 0x20) && (isf.interrupt_number != 13)) { + // Das wird eine Exception, die eher nicht abgefangen werden dürfte. + // Also setzen wir die Registerwerte korrekt, damit man auch was vom + // Rot hat. + isf.ebx = vm86_tss->ebx; + isf.ebp = vm86_tss->ebp; + isf.eip = vm86_tss->eip; + isf.cs = vm86_tss->cs; + isf.ds = vm86_tss->ds; + isf.es = vm86_tss->es; + isf.fs = vm86_tss->fs; + isf.gs = vm86_tss->gs; + isf.ss = vm86_tss->ss; + isf.eflags = vm86_tss->eflags; + } + + asm volatile ("mov %%cr0,%%eax;" + "and $0xFFFFFFF7,%%eax;" // TS-Flag löschen (FPU sollte benutzbar bleiben) + "mov %%eax,%%cr0" ::: "eax"); + + load_isf_and_return((uintptr_t) im_handler(&isf)); +} + /** * Erstellt einen VM86-Thread im aktuellen Prozess. Der aktuell ausgefuehrte * Thread wird pausiert und ein Taskwechsel zum neuen VM86-Task wird @@ -120,40 +222,128 @@ static int create_vm86_task(int intr, vm86_regs_t* regs, uintptr_t stack) // Erst einmal einen ganz normalen Thread erzeugen pm_thread_t* task = pm_thread_create(current_process, - (vaddr_t)(uintptr_t) ivt_entry[0]); + &vm86_task_entry); + + cpu_tss_t* vm86_tss = calloc(2, sizeof(cpu_tss_t)); + cpu_tss_t* gpf_tss = vm86_tss + 1; + + lock(&gdt_lock); + + int vm86_tss_index = next_entry_index++; + gdt_set_descriptor_byte_granularity(vm86_tss_index, 2 * sizeof(*vm86_tss) + - 1, (uintptr_t) vm86_tss, 0x8B, 0); + + int gpf_tss_index = next_entry_index++; + gdt_set_descriptor_byte_granularity(gpf_tss_index, 2 * sizeof(*gpf_tss) - 1, + (uintptr_t) gpf_tss, 0x89, 0); + + unlock(&gdt_lock); + + interrupt_stack_frame_t* isf = task->user_isf; + isf->cs = 0x08; + isf->ds = isf->es = 0x10; + isf->ebx = vm86_tss_index << 3; + + vm86_tss->esp0 = (uintptr_t) isf; + vm86_tss->ss0 = 0x10; + + // TODO: Das Folgende ist sehr i386- und 4-kB-Page-lastig + mmc_context_t vm86_mmc = mmc_create_empty(); + mmc_context_t crnt_mmc = mmc_current_context(); + + vm86_status.mmc = vm86_mmc; - interrupt_stack_frame_t* isf = task->kernel_stack; + // Sorgt dafür, dass die erste Pagetable vorhanden ist. + mmc_map(&vm86_mmc, (vaddr_t) PAGE_SIZE, (paddr_t) 0, 0, 1); - struct vm86_isf visf; + page_table_t vm86_pt0 = get_pagetable(&vm86_mmc, 0); + uintptr_t first_mb = (uintptr_t) vm86_status.first_mb; + int pde = first_mb >> 22; - // Register setzen - isf->eflags = 0x20202; - isf->cs = ivt_entry[1]; - isf->ss = stack / 16; + page_table_t crnt_pt = get_pagetable(&crnt_mmc, pde); - isf->eax = regs->ax; - isf->ebx = regs->bx; - isf->ecx = regs->cx; - isf->edx = regs->dx; - isf->esi = regs->si; - isf->edi = regs->di; - isf->esp = PAGE_SIZE - 16; - isf->ebp = 0; + int page, pte = (first_mb >> 12) & 0x3FF; + for (page = 0; page < 256; page++) { + vm86_pt0[page] = crnt_pt[pte]; - // Segmentregister setzen - // Dabei wird der bisherige Kernelstack in die temporaere - // visf-Datenstruktur kopiert, denn er muss verschoben werden, damit die - // VM86-Segmentregister noch Platz auf dem Stack haben - visf.isf = *isf; - visf.ds = regs->ds; - visf.es = regs->es; + if (++pte >= 1024) { + free_pagetable(&crnt_mmc, crnt_pt); + crnt_pt = get_pagetable(&crnt_mmc, ++pde); + pte -= 1024; + } + } + + free_pagetable(&crnt_mmc, crnt_pt); + free_pagetable(&vm86_mmc, vm86_pt0); + + // Wird auf i386 nicht größer (wenn wir hier einigermaßen unabhängig + // sein wöllten, wirds spätestens beim uint64_t* schwierig + paddr_t idt_phys = pmm_alloc(1); + mmc_map(&vm86_mmc, idt, idt_phys, PTE_P | PTE_W, 1); + + uint64_t* vm86_idt = vmm_kernel_automap(idt_phys, PAGE_SIZE); + int i; + for (i = 0; i < 256; i++) { + switch (i) { + case 13: + vm86_idt[i] = (uint64_t) + (gpf_tss_index << 19) | (5LL << 40) | (1LL << 47); + break; + default: + vm86_idt[i] = 0; + } + } - // Und das ganze auf den Stack - task->kernel_stack = ((uint8_t*) task->kernel_stack) - + sizeof(*isf) - sizeof(visf); - task->user_isf = task->kernel_stack; - memcpy(task->kernel_stack, &visf, sizeof(visf)); + vmm_kernel_unmap(vm86_idt, PAGE_SIZE); + + paddr_t gdt_phys = mmc_resolve(&crnt_mmc, gdt); + mmc_map(&vm86_mmc, gdt, gdt_phys, PTE_P | PTE_W, + (sizeof(gdt) + PAGE_SIZE - 1) / PAGE_SIZE); + + vm86_tss->cr3 = (uintptr_t) vm86_mmc.page_directory; + vm86_tss->eip = ivt_entry[0]; + vm86_tss->eflags = 0x20202; + vm86_tss->eax = regs->ax; + vm86_tss->ebx = regs->bx; + vm86_tss->ecx = regs->cx; + vm86_tss->edx = regs->dx; + vm86_tss->esi = regs->si; + vm86_tss->edi = regs->di; + vm86_tss->esp = 0xFFFE; + vm86_tss->ebp = 0; + vm86_tss->cs = ivt_entry[1]; + vm86_tss->ds = regs->ds; + vm86_tss->es = regs->es; + vm86_tss->ss = (stack - 65536) >> 4; + + gpf_tss->esp0 = (uintptr_t) task->user_isf; + gpf_tss->ss0 = 0x10; + gpf_tss->cr3 = (uintptr_t) crnt_mmc.page_directory; + gpf_tss->eip = (uintptr_t) &vm86_gpf_entry; + gpf_tss->eflags = 0x2; + gpf_tss->esp = gpf_tss->esp0; + + gpf_tss->cs = 0x08; + gpf_tss->ds = 0x10; + gpf_tss->es = 0x10; + gpf_tss->fs = 0x10; + gpf_tss->gs = 0x10; + gpf_tss->ss = gpf_tss->ss0; + + uint8_t* tss_base = (uint8_t*) vm86_tss; + int base_offset = (uintptr_t) tss_base % PAGE_SIZE; + + paddr_t tss_phys = mmc_resolve(&crnt_mmc, tss_base - base_offset); + mmc_map(&vm86_mmc, tss_base - base_offset, tss_phys, PTE_P | PTE_W, 1); + + i = PAGE_SIZE - base_offset; + while (i < 2 * sizeof(cpu_tss_t)) { + paddr_t tss_phys = mmc_resolve(&crnt_mmc, tss_base + i); + mmc_map(&vm86_mmc, tss_base + i, tss_phys, PTE_P | PTE_W, 1); + + i += PAGE_SIZE; + } // Sofort in den VM86-Task wechseln. Der aufrufende Thread wird // waehrenddessen nicht in den Scheduler zurueckgegeben und gestoppt. @@ -177,41 +367,25 @@ static int create_vm86_task(int intr, vm86_regs_t* regs, uintptr_t stack) */ int arch_vm86(uint8_t intr, void* regs, uint32_t* memory) { - int res = 0; - // Wir koennen nur einen VM86-Task if (vm86_status.in_use) { return -EBUSY; } - // Nullpage mappen - uint32_t* page_table = (uint32_t*) PAGETABLES_MEM_START; - void* nullpage = pmm_alloc(1); - page_table[0] = (uintptr_t) nullpage | PTE_U | PTE_W | PTE_P; - asm volatile("invlpg %0" :: "m" (*(char*)0x0)); - memcpy(0, &bios_data, 4096); - - // Stack mappen - void* stack = mmc_valloc_limits(&mmc_current_context(), 1, NULL, NULL, - 0x0, 0x9fc00, PTE_U | PTE_W | PTE_P); - if (stack == NULL) { - kprintf("vm86: Kein Platz fuer den Stack\n"); - res = -ENOMEM; - goto fail_stack; - } + uint8_t* first_mb = mmc_valloc(&mmc_current_context(), + (0xA0000 + PAGE_SIZE - 1) / PAGE_SIZE, PTE_P | PTE_W | PTE_U); + + memcpy(first_mb, &bios_data, 4096); // Videospeicher mappen - // FIXME Das tut nur durch Zufall - bool ret = mmc_map(&mmc_current_context(), - (vaddr_t) 0xa0000, (paddr_t) 0xa0000, - PTE_U | PTE_W | PTE_P, 0x10); - if (!ret) { - kprintf("vm86: Kein Platz fuer den Videospeicher\n"); - res = -ENOMEM; - goto fail_video; - } + mmc_map(&mmc_current_context(), first_mb + 0xA0000, (paddr_t) 0xA0000, + PTE_U | PTE_W | PTE_P, (0x20000 + PAGE_SIZE - 1) / PAGE_SIZE); + + // BIOS mappen + mmc_map(&mmc_current_context(), first_mb + 0xC0000, (paddr_t) 0xC0000, + PTE_U | PTE_W | PTE_P, (0x40000 + PAGE_SIZE - 1) / PAGE_SIZE); - // Falls noetig, ein paar Pages mehr mappen + // Speicherbereiche reinkopieren if (memory != NULL) { uint32_t infosize = memory[0]; uint32_t i; @@ -221,19 +395,7 @@ int arch_vm86(uint8_t intr, void* regs, uint32_t* memory) uint32_t src = memory[1 + i * 3 + 1]; uint32_t size = memory[1 + i * 3 + 2]; - if (size > PAGE_SIZE) { - res = -EINVAL; - goto fail_memory; - } - - paddr_t phys_mem = pmm_alloc(1); - if (!mmc_map(&mmc_current_context(), (vaddr_t)(addr & ~0xFFF), - phys_mem, PTE_W | PTE_P | PTE_U, 1)) - { - res = -ENOMEM; - goto fail_memory; - } - memcpy((void*)addr, (void*)src, size); + memcpy(first_mb + addr, (void*) src, size); } } @@ -241,8 +403,7 @@ int arch_vm86(uint8_t intr, void* regs, uint32_t* memory) // TODO Ordentliches Locking fuer SMP vm86_status.in_use = 1; vm86_status.caller = current_thread; - vm86_status.stack = stack; - vm86_status.nullpage = nullpage; + vm86_status.first_mb = first_mb; vm86_status.memory = memory; vm86_status.regs = regs; @@ -250,28 +411,18 @@ int arch_vm86(uint8_t intr, void* regs, uint32_t* memory) pm_block_rpc(current_process, current_process->pid); // Task erstellen - create_vm86_task(intr, regs, (uintptr_t) stack); + create_vm86_task(intr, regs, 0x9FC00); return 0; - -fail_memory: - mmc_unmap(&mmc_current_context(), (vaddr_t) 0xa0000, 0x10); -fail_video: - mmc_vfree(&mmc_current_context(), stack, 1); -fail_stack: - pmm_free(nullpage, 1); - return res; } /** * Beendet einen VM86-Task, kopiert alle zu zurueckzugebenden Daten und setzt * die Ausfuehrung des aufrufenden Tasks fort. */ -static void destroy_vm86_task(interrupt_stack_frame_t* isf) +static void destroy_vm86_task(cpu_tss_t* tss) { pm_thread_t* vm86_task = current_thread; - struct vm86_isf* visf = (struct vm86_isf*) - (((char*) isf) + (sizeof(*isf) - sizeof(*visf))); // Den Thread loeschen und den Aufrufer wieder aktiv machen vm86_task->status = PM_STATUS_BLOCKED; @@ -280,17 +431,6 @@ static void destroy_vm86_task(interrupt_stack_frame_t* isf) current_thread = vm86_status.caller; current_thread->status = PM_STATUS_RUNNING; - // Temporaere Mappings rueckgaengig machen - mmc_unmap(&mmc_current_context(), (vaddr_t) 0xa0000, 0x10); - mmc_unmap(&mmc_current_context(), vm86_status.stack, 1); - - uint32_t* page_table = (uint32_t*) PAGETABLES_MEM_START; - page_table[0] = 0; - asm volatile("invlpg %0" :: "m" (*(char*)0x0)); - - pmm_free(vm86_status.nullpage, 1); - - // Vom Benutzer angeforderte Mappings rueckgaengig machen if (vm86_status.memory != NULL) { uint32_t infosize = vm86_status.memory[0]; uint32_t i; @@ -300,23 +440,27 @@ static void destroy_vm86_task(interrupt_stack_frame_t* isf) uint32_t src = vm86_status.memory[1 + i * 3 + 1]; uint32_t size = vm86_status.memory[1 + i * 3 + 2]; - memcpy((void*)src, (void*)addr, size); - pmm_free(mmc_resolve(&mmc_current_context(), - (vaddr_t) (addr & ~0xFFF)), 1); - mmc_unmap(&mmc_current_context(), (vaddr_t)(addr & ~0xFFF), 1); + memcpy((void*) src, vm86_status.first_mb + addr, size); } } + mmc_vfree(&mmc_current_context(), vm86_status.first_mb, + (0xA0000 + PAGE_SIZE - 1) / PAGE_SIZE); + mmc_unmap(&mmc_current_context(), vm86_status.first_mb + 0xA0000, + (0x60000 + PAGE_SIZE - 1) / PAGE_SIZE); + // Register sichern vm86_regs_t* regs = vm86_status.regs; - regs->ax = isf->eax; - regs->bx = isf->ebx; - regs->cx = isf->ecx; - regs->dx = isf->edx; - regs->si = isf->esi; - regs->di = isf->edi; - regs->ds = visf->ds; - regs->es = visf->es; + regs->ax = tss->eax; + regs->bx = tss->ebx; + regs->cx = tss->ecx; + regs->dx = tss->edx; + regs->si = tss->esi; + regs->di = tss->edi; + regs->ds = tss->ds; + regs->es = tss->es; + + mmc_destroy(&vm86_status.mmc); // Wir sind fertig mit VM86 :-) pm_unblock_rpc(current_process, current_process->pid); @@ -324,17 +468,17 @@ static void destroy_vm86_task(interrupt_stack_frame_t* isf) } /** Pusht einen Wert auf den Stack des VM86-Tasks */ -static inline void emulator_push(interrupt_stack_frame_t* isf, uint16_t value) +static inline void emulator_push(cpu_tss_t* tss, uint16_t value) { - isf->esp -= 2; - ((uint16_t*)(isf->esp + (isf->ss << 4)))[0] = value; + tss->esp -= 2; + ((uint16_t*)(vm86_status.first_mb + tss->esp + (tss->ss << 4)))[0] = value; } /** Popt einen Wert vom Stack des VM86-Tasks */ -static inline uint16_t emulator_pop(interrupt_stack_frame_t* isf) +static inline uint16_t emulator_pop(cpu_tss_t* tss) { - uint16_t res = ((uint16_t*)(isf->esp + (isf->ss << 4)))[0]; - isf->esp += 2; + uint16_t res = ((uint16_t*)(vm86_status.first_mb + tss->esp + (tss->ss << 4)))[0]; + tss->esp += 2; return res; } @@ -355,20 +499,22 @@ int vm86_exception(interrupt_stack_frame_t* isf) return 0; } + cpu_tss_t* tss = (cpu_tss_t*) isf->ebp; + // Ein toller Emulator fuer privilegierte Instruktionen - uint8_t* ops = (uint8_t*)(isf->eip + (isf->cs << 4)); + uint8_t* ops = (uint8_t*)(vm86_status.first_mb + tss->eip + (tss->cs << 4)); switch (ops[0]) { case 0x9c: /* pushf */ - emulator_push(isf, isf->eflags); - isf->eip++; + emulator_push(tss, tss->eflags); + tss->eip++; break; case 0x9d: /* popf */ // So tun, als würden wir die EFLAGS wiederherstellen. // Das hier ist wohl alles andere als korrekt, aber funzt erstmal. - emulator_pop(isf); - isf->eip++; + emulator_pop(tss); + tss->eip++; break; case 0xcd: /* int */ @@ -376,31 +522,40 @@ int vm86_exception(interrupt_stack_frame_t* isf) uint16_t intr = ops[1] & 0xff; uint16_t* ivt_entry = bios_data.ivt[intr]; - emulator_push(isf, isf->eip + 2); - emulator_push(isf, isf->cs); - emulator_push(isf, isf->eflags); + emulator_push(tss, tss->eip + 2); + emulator_push(tss, tss->cs); + emulator_push(tss, tss->eflags); - isf->eip = ivt_entry[0]; - isf->cs = ivt_entry[1]; + tss->eip = ivt_entry[0]; + tss->cs = ivt_entry[1]; break; } case 0xcf: /* iret */ // Wenn es das finale iret ist, koennen wir den VM86-Task beenden - if (isf->esp == PAGE_SIZE - 16) { - destroy_vm86_task(isf); + if (tss->esp == 0xFFFE) { + destroy_vm86_task(tss); return 1; } // Ansonsten muss es ganz normal emuliert werden - emulator_pop(isf); - isf->cs = emulator_pop(isf); - isf->eip = emulator_pop(isf); + emulator_pop(tss); + tss->cs = emulator_pop(tss); + tss->eip = emulator_pop(tss); break; default: - kprintf("vm86: Unbekannter Opcode %x\n", ops[0]); + kprintf("vm86: Unbekannte Opcodesequenz %02x %02x %02x %02x %02x " + "%02x\n", ops[0], ops[1], ops[2], ops[3], ops[4], ops[5]); + + // Für ordentliches Rot + isf->eflags = tss->eflags; + isf->eip = tss->eip; + isf->esp = tss->esp; + isf->cs = tss->cs; + isf->ss = tss->cs; + return 0; } diff --git a/src/kernel2/src/arch/i386/vm86_asm.S b/src/kernel2/src/arch/i386/vm86_asm.S new file mode 100644 index 0000000..bcafbd2 --- /dev/null +++ b/src/kernel2/src/arch/i386/vm86_asm.S @@ -0,0 +1,15 @@ +.code32 + +.globl vm86_task_entry +.extern vm86_get_backlink_pointer +vm86_task_entry: + call vm86_get_backlink_pointer + mov %bx, (%eax) + + pushfl + pop %eax + or $0x4000, %eax + push %eax + popfl + + iret diff --git a/src/kernel2/src/interrupts/im.c b/src/kernel2/src/interrupts/im.c index 8492ae6..85376cc 100644 --- a/src/kernel2/src/interrupts/im.c +++ b/src/kernel2/src/interrupts/im.c @@ -74,7 +74,7 @@ static void handle_exception(interrupt_stack_frame_t* isf, uint8_t int_num) // Pruefen, ob ein VM86-Task die Exception ausgeloest hat // Falls ja lassen wir sie vom VM86-Code behandeln, wenn er kann - if (isf->eflags & 0x20000) { + if (!(isf->eflags & (1 << 1))) { if (vm86_exception(isf)) { return; } diff --git a/src/kernel2/src/tasks/scheduler.c b/src/kernel2/src/tasks/scheduler.c index 84c7348..cb4f9dd 100644 --- a/src/kernel2/src/tasks/scheduler.c +++ b/src/kernel2/src/tasks/scheduler.c @@ -154,7 +154,7 @@ pm_thread_t* pm_scheduler_pop() thread = list_pop(threads_scheduled); // Falls das nicht geklappt hat, wird solange probiert, - while (thread == NULL) { + while ((thread == NULL) || (thread->status == PM_STATUS_BLOCKED)) { // FIXME: Das ist so nicht wirklich geschickt, wenn der aufrufer dafür // sorgen muss, dass wir nicht hängen bleiben. unlock(&scheduler_lock); -- 1.7.1 From kevin at tyndur.org Mon Aug 30 00:03:44 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 30 Aug 2010 00:03:44 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_Pascal-RTL=3A_Short_Writes_b?= =?utf-8?q?er=C3=BCcksichtigen?= Message-ID: <1283119424-18065-1-git-send-email-kevin@tyndur.org> ! Pascal-RTL: Do_Write muss die übergebenen Daten komplett schreiben, fwrite kann allerdings Short Writes zurückgeben. Signed-off-by: Kevin Wolf --- src/modules/pas/lib/rtl/sysfile.inc | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/modules/pas/lib/rtl/sysfile.inc b/src/modules/pas/lib/rtl/sysfile.inc index 5143ef8..bcd0889 100644 --- a/src/modules/pas/lib/rtl/sysfile.inc +++ b/src/modules/pas/lib/rtl/sysfile.inc @@ -6,8 +6,8 @@ const function c_fopen(filename, mode: PChar): THandle; cdecl; external name 'fopen'; function c_fclose(f: THandle): integer; cdecl; external name 'fclose'; -function c_fwrite(src: Pointer; blocksize, blockcount: TSize; f: THandle): TSize; cdecl; external name 'fwrite'; -function c_fread(dest: Pointer; blocksize, blockcount: TSize; f: THandle): TSize; cdecl; external name 'fread'; +function c_fwrite(src: Pointer; blocksize, blockcount: TSize; f: THandle): longint; cdecl; external name 'fwrite'; +function c_fread(dest: Pointer; blocksize, blockcount: TSize; f: THandle): longint; cdecl; external name 'fread'; function c_fseek(f: THandle; offset, whence: longint): longint; cdecl; external name 'fseek'; function c_ftell(f: THandle): TSize; cdecl; external name 'ftell'; @@ -36,8 +36,21 @@ begin { TODO } end; Function Do_Write(f: THandle; src: Pointer; len: TSize): TSize; -begin - Do_Write := c_fwrite(src, 1, len, f); +var + ret: longint; +begin + Do_Write := 0; + while len > 0 do begin + ret := c_fwrite(src, 1, len, f); + if ret < 0 then begin + InOutRes := 101; + exit(0); + end; + + Inc(Do_Write, ret); + Inc(src, ret); + Dec(len, ret); + end; end; Function Do_Read(f: THandle; dest: Pointer; len: TSize): TSize; -- 1.6.0.2