times to start writing an operating system (H1-OS) for Heritage / 1 are far yet, but peek at the issue now has served me from design to ensure proper hardware support. For example, thinking about how an operating system would be to host various programs in memory, I have come to understand the need to include "relative addressing" in the design of the CPU instruction set. ON ADDRESSING
The program counter (PC) Heritage / 1 is designed to increase in a unit (PC = PC + 1), loaded with a given address (PC = ADDR), or to add your content under a given operation (PC = PC + OFFSET). This corresponds to the addressing modes: implicit, direct and on respectively.
A program that uses only relative jumps easily be located anywhere within the memory as the program does not care "where to jump," but "how far", as illustrated in the following example.
400 mvi d, 1000; variable points to 402 in 1000
ldx a, d; read variable (indirect) 403
jr 5, 5-way jumps forward
...
408; the jump occurrirá this direction.
If this segment of the program is loaded into an address other than 400, the jump will still work well, which was the purpose. However, we can not say the same if we place the variable in a different direction to 1000.
Unfortunately (and for reasons of economy) I'm just implementing relative addressing specifically for PC and jump instructions. The solution for the relocation of variables comes from the way in which H1-OS programs loaded into memory and how these are structured.
ANATOMY OF A PROGRAM IN HERITAGE / 1
recycle programs in "storage" (V-TAPE) as files. These consist of a label (LABEL), a body that contains the executable code (Code) and an end of file character (EOF).
The label contains information about the program, including the requirements of your data area, ie the size of the stack. When loaded into memory, the operating system (H1-OS) hosting the code on the first available memory and another portion reserved for data area (Stack) as illustrated below.
As this is not the only program coexisting in memory, H1-OS maintains a table of all loaded programs, saving her address Stack the Code and allocated. Before passing control to the program, load the SP value (SP '= OS_VAR + TAMAÑO_ASIGNADO_AL_STACK).
When the program goes into execution, the SP register is pointed to the bottom of the stack, the first thing the program does the task of initialization is organized. Take for example (see figure) that this program uses two global variables: an integer of 16 bits called N, and a 32-bit dual-called X. To allocate memory for both variables, the program runs three steps above SP (SP = SP '-3). From that point, the stack itself is "above" the global variables of the program. The program then accesses the variables as "Distances" on the current position of SP. The following will
example illustrates the above.
; Reservation memory for global variables.
dec sp; Reserved memory for N
dec sp dec sp; Reserved
X memory ...
, Lee N variable A:
mov a, sp; A = SP
adi a, 3, A = A + 3
mov d, a, D = A (ie, SP + 3) ldx
a, d A = [D] (ie, variable N)
A program typically calls functions using the CALL statement endorsed. When this happens, both F PC automatically be saved to the stack (just above the area variable because there was where he was positioned.) The code for the SP move in turn to create your own data area as did the main program and accessed the same way. When the function returns, this area will be released queando SP in its original position, ie just above the global variables. This process can be repeated recursively until the size of the stack permits.
multiple instances
H1-OS allows multiple instances of programs, namely the existence of multiple copies of the same program running simultaneously in memory. What we have done so far (to load a program into memory) is not is to create a first "instance" of it. To create a second, do not bring back the code from V-TAPE but only create a second stack for the same code. Thus, both instances use the same copy of the code but will have separate data areas, one for each instance.
The multiple instantiation is vital for the Multi-Processing, as explained in the next article.
0 comments:
Post a Comment