Click here to Skip to main content
15,888,454 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Notification Hell Pin
ZurdoDev15-May-20 9:25
professionalZurdoDev15-May-20 9:25 
GeneralRe: Notification Hell Pin
Greg Utas15-May-20 9:47
professionalGreg Utas15-May-20 9:47 
GeneralHow would you slice up this turkey? Pin
CodeWraith15-May-20 2:43
CodeWraith15-May-20 2:43 
GeneralRe: How would you slice up this turkey? Pin
OriginalGriff15-May-20 4:05
mveOriginalGriff15-May-20 4:05 
GeneralRe: How would you slice up this turkey? Pin
CodeWraith15-May-20 6:08
CodeWraith15-May-20 6:08 
GeneralRe: How would you slice up this turkey? Pin
lopatir15-May-20 4:15
lopatir15-May-20 4:15 
GeneralRe: How would you slice up this turkey? Pin
CodeWraith15-May-20 6:39
CodeWraith15-May-20 6:39 
GeneralRe: How would you slice up this turkey? Pin
kalberts15-May-20 5:07
kalberts15-May-20 5:07 
What kind of software are you going to run on this "beast"Smile | :) ?
How much control do you have over the software?

My experience with that small systems is that stacks are surprisingly shallow.

If my memory is correct, the 8051 stack is 256 bytes. With that tight limits, you soon learn to pass multiple arguments as a pointer to a struct with the inidividual values, and to structure your code to "get out of there" as quickly as possible. Avoid nested calls whenever you can do them as a sequence. Maybe each operation nests 2-3 levels deep, but not dozens of levels. You should strive to keep the stack shallow: E.g. initialization functions should return before starting the "real" appliction code. Even if plan to run code that you cannot control, 16Ki is a lot.

Are you using languages requiring a static link? Or languages allowing pointers to locations in the calling routine (e.g. in frames deeper down on the stack)? If not, you could virtualize the stack segment as well, keeping only the topmost frame directly adressable. Then all function calls must go through a (redsident) stub that unmaps the current frame and sets up the new, and upon return remaps the caller's frame (as well as mapping in the code segment with the current function, if it is not the current one).

Years ago, I worked on a banked 8501: The upper 16K could be switched between four banks (but I believe that the architecture allowed extension to an arbitrary number). Banks were not pure data or code, they could have both. Each bank typically contained one module or functional subset: When you loaded a bank, you would usually stay in there for a major piece of work, with direct, "normal" calls within the bank. Libraries used by "everyone" was located in the common, lower 48K and could also be called directly; only when a function in one bank needed to call a function in another bank went via a stub (in the lower 48Ki).

Globally static data, shared among banks, were located in the lower 48Ki; data relevant only to the functions in one bank was located in that bank. Care was required: You could not pass a pointer to data in a bank to a function in another bank. For such needs, the data had to be allocated in the common 48K.

If I were to design a new banked system, I guess I would stick to the same solution: A bank can have both code and data. I would probably increase the bank size to 32Ki; that would make larger functionality in a single bank, reducing bank interactions, fewer bank switches. Most likely, a fair share of banks would not be filled up. For really large systems, filling up physical RAM, it would be nice if a half-filled bank, 16Ki, would require only 16Ki in backing RAM. Allocating bank space in e.g. 1Ki increments would allow a larger number of banks.

The lower half would hold interrupt handlers, DMA buffers, data shared between banks, stubs for all exported banked functions (e.g callable from arbitrary bank), and buffers where one bank can place argument structs when calling functions in other banks. The stack would be in the lower 32Ki. If your stack grows downwards (which is quite commmon) and you have Stack Limit register, why don't you fill the common 32Ki from the botton, ending with setting Stack Limit to the current load address, and the stack bottom to 32Ki - then you can increase stack space avialable when needed by moving more of the common code/data into yet another bank. For a stack growing upwards, you could of course let it grow from the end of common code/data, up to 32Ki, but there is a tradition for starting the stack at a "round" address.

The old open-source P4 Pascal compiler shared all unallocated adress space between the stack and the heap, growing from each end. If a heap allocation could not find a free area below the current HeapTop, HeapTop was pushed upwards for the request, and compared to the current StackTop, for an out-of-space check. Similarly, a function call would check tbe new StackTop against HeapTop, and report a collision if space was exhausted. So a program with deeply nested calls could not use as much heap space, and a program using the heap a lot would have to refrain from too deeply nested calls.

I guess I would not try to virtualize (bank) the stack; that would require dynamic allocation of banks.

Another factor: This CPU, does it provide any harware signal indicating whether it is fetching instructions (code), accessing data, whether the stack register is involved in the address calculation or if you are in an interrupt handler? Many CPUs do, and you might use these signals as bank selectors. The 16 bit address could effectively be extended to 18 bits: One 64Ki code space, one 64Ki data space, one 64Ki stack space, and one 64Ki interrupt space. (So it would switch the lower 32Ki as well). Where DMA fits it would depend on the how the signals are set during DMA. Each of these four spaces might be banked. (I guess that stack and DMA would have only a single bank, but if it treated as such, the banker should be able to map the DMA bank with data buffers as a data bank accessible to "ordinary" (non-DMA/interrupt) code.

All of this of course depends on the available signals from the CPU, as well as the flexibility of your bank mapping mechanism (e.g. if an interrupt can immediately swith to the interrupt bank, sufficiently fast for the interrupt handler), or if the DMA can be hardwired to one specific lower 32Ki independent of the mapping of code, data and stack. If the hardware is alredy designed and implemented, I guess it is difficult to accomodate new proposals at this level.
GeneralRe: How would you slice up this turkey? Pin
fd975015-May-20 6:25
professionalfd975015-May-20 6:25 
GeneralRe: How would you slice up this turkey? Pin
CodeWraith15-May-20 8:49
CodeWraith15-May-20 8:49 
GeneralRe: How would you slice up this turkey? Pin
Rick York15-May-20 6:01
mveRick York15-May-20 6:01 
GeneralRe: How would you slice up this turkey? Pin
kalberts15-May-20 8:44
kalberts15-May-20 8:44 
GeneralRe: How would you slice up this turkey? Pin
Rick York15-May-20 10:13
mveRick York15-May-20 10:13 
GeneralRe: How would you slice up this turkey? Pin
CodeWraith15-May-20 11:34
CodeWraith15-May-20 11:34 
GeneralRe: How would you slice up this turkey? Pin
Luc Pattyn15-May-20 7:34
sitebuilderLuc Pattyn15-May-20 7:34 
GeneralPomodoro Apps Pin
Brady Kelly15-May-20 1:48
Brady Kelly15-May-20 1:48 
GeneralRe: Pomodoro Apps Pin
musefan15-May-20 2:43
musefan15-May-20 2:43 
GeneralRe: Pomodoro Apps Pin
W Balboos, GHB15-May-20 2:46
W Balboos, GHB15-May-20 2:46 
GeneralRe: Pomodoro Apps Pin
musefan15-May-20 2:51
musefan15-May-20 2:51 
GeneralRe: Pomodoro Apps Pin
W Balboos, GHB15-May-20 2:58
W Balboos, GHB15-May-20 2:58 
GeneralRe: Pomodoro Apps Pin
PIEBALDconsult17-May-20 6:55
mvePIEBALDconsult17-May-20 6:55 
GeneralRe: Pomodoro Apps Pin
W Balboos, GHB18-May-20 0:40
W Balboos, GHB18-May-20 0:40 
GeneralRe: Pomodoro Apps Pin
Brady Kelly23-May-20 19:36
Brady Kelly23-May-20 19:36 
GeneralRe: Pomodoro Apps Pin
RickZeeland15-May-20 2:50
mveRickZeeland15-May-20 2:50 
GeneralRe: Pomodoro Apps Pin
Brady Kelly23-May-20 20:14
Brady Kelly23-May-20 20:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.