public inbox for linux-8086@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <gnomes@lxorguk.ukuu.org.uk>
To: Juan Perez-Sanchez <lithoxs@gmail.com>
Cc: linux-8086 <linux-8086@vger.kernel.org>
Subject: Re: New GCC compiler for 8086 cpu's
Date: Mon, 19 Jun 2017 21:55:28 +0100	[thread overview]
Message-ID: <20170619215459.3d7382b1@alans-desktop> (raw)
In-Reply-To: <CAD6VGubryFchyiWL_Rn2jE7BX6ySNCELcGghmiGv_qwm0SFCfA@mail.gmail.com>

> A simple solution for the kernel stacks is to use the user stack in
> kernel mode, this is:
> 
> DS = ES = Kernel segment
> SS = User data segment.

DS != SS requires far pointers.

Think about

	char x[40];
	char *p = x;


p now points to SS:something which is not the same as DS:something.

> Of course, this leads to problems. And the current kernel will require
> very careful inspection and corrections. But I think this is doable by
> enforcing some simple rules.
> 
> What do you think?

It doesn't work because you can take the address of a stack based object,
and not only that the compiler will do so itself internally when
generating code.

So to fix the stack you need a per process store for stacks and to do
something on task switch akin to


switch:
	while nothing else to run
		idle();
	if we are now the only/next thing to run (usual case)
		return;
	save our kernel stack somewhere
	(asm code to set ds: es: rep movs restore)
	change task
	load new kernel stack
	(ditto)

Note btw you can't use prefixes with rep movs on 8086 because there is a
CPU errata that a restarted rep instruction sometimes forgets the
prefixes!

The fancier version is to hash processes by stack (so say slots 1,5,9,13
use stack 0, 2,6,10,14, stack 1 .. etc). You have to keep the stack you
use for a given process constant but you can attempt to make sure that
usually a switch doesn't cause a copy in or out of stacks.

It turns out that on a small single user machine in particular the number
of task switches between tasks is miniscule. From the shell you switch
once to the app, once back to wait(), then back to the app and probably
don't switch again to anything but idle state unless the user changes
console, exits the program or runs a sub process. Now and then cron or
similar will briefly juggle things around but that's about it.

Fuzix uses the simple algorithm above on many platforms for the same
reason and it work extremely well even on a 4MHz Z80.

Alan

	

  reply	other threads:[~2017-06-19 20:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14  0:08 New GCC compiler for 8086 cpu's Juan Perez-Sanchez
2017-06-14  6:47 ` Tom
2017-06-14 19:53   ` Juan Perez-Sanchez
2017-06-15 10:19 ` Edoardo
2017-06-15 22:53   ` Juan Perez-Sanchez
2017-06-16 13:33     ` David O'Shea
2017-06-16 18:57       ` Juan Perez-Sanchez
2017-06-19  3:58         ` David O'Shea
2017-06-19  6:58           ` Georg Potthast
2017-06-19  9:15             ` David O'Shea
2017-06-19 19:36           ` Juan Perez-Sanchez
2017-06-19 13:16       ` Alan Cox
2017-06-19 13:43     ` Alan Cox
2017-06-19 19:57       ` Juan Perez-Sanchez
2017-06-19 20:55         ` Alan Cox [this message]
2017-06-19 22:53           ` Juan Perez-Sanchez
2017-06-20 11:37             ` Alan Cox
2017-06-20 21:57               ` Juan Perez-Sanchez
     [not found]                 ` <CALgV52iFRay4y8dYrP0ZGnF2JQJi2h7c=QnSsDniv72azmFPbA@mail.gmail.com>
2017-06-20 22:46                   ` Fwd: " David Given

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170619215459.3d7382b1@alans-desktop \
    --to=gnomes@lxorguk.ukuu.org.uk \
    --cc=linux-8086@vger.kernel.org \
    --cc=lithoxs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox