Skip to content

Commit

Permalink
Fix delay_divisor value for proper delay(9) on 68040.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutsui committed Jan 20, 2023
1 parent b9f95d7 commit 883462c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
3 changes: 0 additions & 3 deletions sys/arch/next68k/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ void loadustp(int);
void doboot(void) __attribute__((__noreturn__));
int nmihand(void *);

/* clock.c functions */
void next68k_calibrate_delay(void);

#endif /* _KERNEL */

#define NEXT_RAMBASE (0x4000000) /* really depends on slot, but... */
Expand Down
32 changes: 0 additions & 32 deletions sys/arch/next68k/next68k/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,6 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.12 2010/04/24 19:58:13 dbj Exp $");
* -- jewell@mit.edu
*/

/*
* Note that the value of delay_divisor is roughly
* 2048 / cpuspeed (where cpuspeed is in MHz) on 68020
* and 68030 systems. See clock.c for the delay
* calibration algorithm.
*/
int cpuspeed; /* relative cpu speed; XXX skewed on 68040 */
int delay_divisor = 2048/25; /* delay constant */

/*
* Calibrate the delay constant.
*/
void
next68k_calibrate_delay(void)
{
extern int delay_divisor;

/* @@@ write this once we know how to read
* a real time clock
*/

/*
* Sanity check the delay_divisor value. If we totally lost,
* assume a 25MHz CPU;
*/
if (delay_divisor == 0)
delay_divisor = 2048 / 25;

/* Calculate CPU speed. */
cpuspeed = 2048 / delay_divisor;
}

int clock_intr(void *);

int
Expand Down
21 changes: 16 additions & 5 deletions sys/arch/next68k/next68k/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ phys_seg_list_t phys_seg_list[VM_PHYSSEG_MAX];
phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
int mem_cluster_cnt;

/*
* On the 68020/68030, the value of delay_divisor is roughly
* 2048 / cpuspeed (where cpuspeed is in MHz).
*
* On the 68040/68060(?), the value of delay_divisor is roughly
* 759 / cpuspeed (where cpuspeed is in MHz).
* XXX -- is the above formula correct?
*/
int cpuspeed = 33; /* relative cpu speed; XXX skewed on 68040 */
int delay_divisor = 759 / 33; /* delay constant; assume fastest 33 MHz */

/****************************************************************/

/*
Expand Down Expand Up @@ -208,9 +219,6 @@ next68k_init(void)
}
}

/* Calibrate the delay loop. */
next68k_calibrate_delay();

/*
* Initialize error message buffer (at end of core).
*/
Expand Down Expand Up @@ -256,8 +264,6 @@ consinit(void)
}

init = 1;
} else {
next68k_calibrate_delay();
}
}

Expand Down Expand Up @@ -316,16 +322,21 @@ void
identifycpu(void)
{
const char *mc, *mmu_str, *fpu_str, *cache_str;
extern int turbo;

/*
* ...and the CPU type.
*/
switch (cputype) {
case CPU_68040:
mc = "40";
cpuspeed = turbo ? 33 : 25;
delay_divisor = 759 / cpuspeed;
break;
case CPU_68030:
mc = "30";
cpuspeed = 25;
delay_divisor = 2048 / cpuspeed;
break;
case CPU_68020:
mc = "20";
Expand Down

0 comments on commit 883462c

Please sign in to comment.