Fix stack alignment issue, ffop.pl1 call to divide_fx3 now works (corruption occurred...
authorNick Downing <nick@ndcode.org>
Mon, 21 Oct 2019 10:18:42 +0000 (21:18 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 21 Oct 2019 10:18:42 +0000 (21:18 +1100)
dps8/dps8_eis.c
dps8/dps8_ins.c
multics_sim.c

index 04bdaaf..9a4d089 100644 (file)
@@ -447,6 +447,7 @@ sim_printf ("getMFReg18 %012"PRIo64"\n", IWB_IRODD);
 
 static word36 getMFReg36 (uint n, bool allowDU, bool allowNIC, fault_ipr_subtype_ *mod_fault)
   {
+ //printf("getMFReg36 %02o\n", n);
     switch (n)
       {
         case 0: // n
@@ -1130,6 +1131,7 @@ static void setupOperandDescriptorCache (int k)
 
 static void setupOperandDescriptor (int k, fault_ipr_subtype_ *mod_fault)
   {
+ //printf("setupOperandDescriptor %d\n", k);
     EISstruct * e = & cpu.currentEISinstruction;
     switch (k)
       {
@@ -1307,6 +1309,7 @@ void setupEISoperands (void)
 
 static void parseAlphanumericOperandDescriptor (uint k, uint useTA, bool allowDU, fault_ipr_subtype_ *mod_fault)
   {
+ //printf("parseAlphanumericOperandDescriptor %d\n", k);
     EISstruct * e = & cpu.currentEISinstruction;
     word18 MFk = e -> MF [k - 1];
     
@@ -1449,6 +1452,7 @@ sim_debug (DBG_TRACEEXT, & cpu_dev, "AR n %u k %u\n", n, k - 1);
     sim_debug (DBG_TRACEEXT, & cpu_dev, "N%u %o\n", k, e->N[k-1]);
 
     word36 r = getMFReg36 (MFk & 017, allowDU, true, mod_fault); // allow du based on instruction, allow n,ic
+ //printf("r %012llo\n", r);
     
     if ((MFk & 017) == 4)   // reg == IC ?
       {
@@ -4310,6 +4314,7 @@ static bool isGBCDOvp (uint c, bool * isNeg)
 
 void mlr (void)
   {
+ //printf("mlr\n");
     EISstruct * e = & cpu.currentEISinstruction;
 
     // For i = 1, 2, ..., minimum (N1,N2)
index aca3657..088f5f1 100644 (file)
@@ -1258,6 +1258,7 @@ force:;
                   GET_TD (cpu.currentInstruction.tag) & 017);
               }
           }
+ fflush(stdout);
       }
 
   }
index f956aff..031f579 100644 (file)
@@ -112,18 +112,18 @@ struct object_map *get_object_map(struct loaded_segment *p) {
   return object_map;
 }
 
-int allocate_linkage(int length, bool even) {
-  if (even)
-    next_linkage_offset = (next_linkage_offset + 1) & ~1;
+int allocate_linkage(int length, int align) {
+  align -= 1;
+  next_linkage_offset = (next_linkage_offset + align) & ~align;
   rassert(next_linkage_offset + length <= 01000000);
   int offset = next_linkage_offset;
   next_linkage_offset += length;
   return offset;
 }
 
-int allocate_stack(int length, bool even) {
-  if (even)
-    next_stack_offset = (next_stack_offset + 1) & ~1;
+int allocate_stack(int length, int align) {
+  align -= 1;
+  next_stack_offset = (next_stack_offset + align) & ~align;
   rassert(next_stack_offset + length <= 01000000);
   int offset = next_stack_offset;
   next_stack_offset += length;
@@ -248,7 +248,7 @@ found_bitcount:
   );
 
   // copy and fill in linkage section
-  p->linkage_offset = allocate_linkage(object_map->linkage_length, true);
+  p->linkage_offset = allocate_linkage(object_map->linkage_length, 2);
   struct linkage_header *linkage_header = (struct linkage_header *)(
     M[linkage_segment] + p->linkage_offset
   );
@@ -272,7 +272,7 @@ found_bitcount:
   linkage_header->stats_segment_number = linkage_segment;
 
   // copy static section
-  int static_offset = allocate_linkage(object_map->static_length, true);
+  int static_offset = allocate_linkage(object_map->static_length, 2);
   memcpy(
     M[linkage_segment] + static_offset,
     M[p->segment] + object_map->static_offset,
@@ -518,10 +518,10 @@ int main(int argc, char **argv) {
 
   // allocate LOT and ISOT
   stack_header->max_lot_size = N_SEGMENT;
-  int lot_offset = allocate_linkage(N_SEGMENT, false);
+  int lot_offset = allocate_linkage(N_SEGMENT, 1);
   lot = (struct packed_pointer *)(M[linkage_segment] + lot_offset);
   stack_header->lot_ptr = its_pointer(linkage_segment, lot_offset);
-  int isot_offset = allocate_linkage(N_SEGMENT, false);
+  int isot_offset = allocate_linkage(N_SEGMENT, 1);
   isot = (struct packed_pointer *)(M[linkage_segment] + isot_offset);
   stack_header->isot_ptr = its_pointer(linkage_segment, isot_offset);
 
@@ -561,7 +561,7 @@ int main(int argc, char **argv) {
   // create first stack frame
   int stack_frame_offset = allocate_stack(
     sizeof(struct stack_frame) / sizeof(uint64_t),
-    true
+    8
   );
   struct stack_frame *stack_frame = (struct stack_frame *)(
     M[stack_segment] + stack_frame_offset
@@ -572,7 +572,7 @@ int main(int argc, char **argv) {
   );
 
   // append command line to first stack frame
-  int arg_list_offset = allocate_stack(6 + n_args * 4, true);
+  int arg_list_offset = allocate_stack(6 + n_args * 4, 2);
   struct arg_list *arg_list = (struct arg_list *)(
     M[stack_segment] + arg_list_offset
   );
@@ -581,7 +581,7 @@ int main(int argc, char **argv) {
   //arg_list->desc_count = n_args;
 
   for (int i = 0; i < n_args; ++i) {
-    int arg_offset = allocate_stack((strlen(args[i]) + 3) >> 2, false);
+    int arg_offset = allocate_stack((strlen(args[i]) + 3) >> 2, 1);
     arg_list->args[i] = its_pointer(stack_segment, arg_offset);
 
     uint64_t *arg = (uint64_t *)(M[stack_segment] + arg_offset);
@@ -591,7 +591,7 @@ int main(int argc, char **argv) {
 
     int arg_desc_offset = allocate_stack(
       sizeof(struct arg_desc) / sizeof(uint64_t),
-      false
+      1
     );
     arg_list->args[n_args + 1 + i] =
       its_pointer(stack_segment, arg_desc_offset);
@@ -606,12 +606,12 @@ int main(int argc, char **argv) {
     arg_desc->size = strlen(args[i]);
   }
 
-  int result_offset = allocate_stack(0x101, false); // 1 kbyte of output
+  int result_offset = allocate_stack(0x101, 1); // 1 kbyte of output
   arg_list->args[n_args] = its_pointer(stack_segment, result_offset + 1);
 
   int arg_desc_offset = allocate_stack(
     sizeof(struct arg_desc) / sizeof(uint64_t),
-    false
+    1
   );
   arg_list->args[n_args * 2 + 1] =
     its_pointer(stack_segment, arg_desc_offset);
@@ -627,11 +627,11 @@ int main(int argc, char **argv) {
 
   stack_header->stack_end_ptr = its_pointer(
     stack_segment,
-    allocate_stack(0, true)
+    allocate_stack(0, 8)
   );
 
   // create calling stub
-  int calling_stub_offset = allocate_linkage(2, false);
+  int calling_stub_offset = allocate_linkage(2, 1);
   uint64_t *calling_stub = (uint64_t *)(
     M[linkage_segment] + calling_stub_offset
   );