xref: /netbsd-src/sys/arch/atari/stand/tostools/libtos/sysinfo.c (revision 66d4986f4f843f343b613a35cef778e1f9860105)
1 /*	$NetBSD: sysinfo.c,v 1.10 2024/09/25 08:32:44 rin Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Leo Weppelman.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifdef TOSTOOLS
33 #include <stdio.h>
34 #include <sys/types.h>
35 #else
36 
37 #include <lib/libsa/stand.h>
38 #include <atari_stand.h>
39 #include <libkern.h>
40 #include <machine/cpu.h>
41 #endif /* TOSTOOLS */
42 
43 #include "libtos.h"
44 #include "tosdefs.h"
45 #include "kparamb.h"
46 
47 /*
48  * ADDR_* defined in tosdefs.h are in the 0-th page, even if 4KB page,
49  * i.e., [0, 0x1000). This causes -Warray-bounds for GCC12 and later.
50  */
51 #pragma GCC diagnostic push
52 #pragma GCC diagnostic ignored "-Warray-bounds"
53 
54 /*
55  * Extract memory and CPU/FPU info from system.
56  */
57 void
58 sys_info(osdsc_t *od)
59 {
60 	long	*jar;
61 	OSH	*oshdr;
62 
63 	od->cputype = 0;
64 
65 	/*
66 	 * Some GEMDOS versions use a different year-base in the RTC.
67 	 */
68 	oshdr = *ADDR_OSHEAD;
69 	oshdr = oshdr->os_beg;
70 	if ((oshdr->os_version > 0x0300) && (oshdr->os_version < 0x0306))
71 		od->cputype |= ATARI_CLKBROKEN;
72 
73 	/*
74 	 * Auto configure memory sizes when they are not pre-set.
75 	 */
76 	if (od->stmem_size <= 0)
77 		od->stmem_size  = *ADDR_PHYSTOP;
78 
79 	if (od->ttmem_size)
80 		od->ttmem_start  = TTRAM_BASE;
81 	else {
82 		if (*ADDR_CHKRAMTOP == RAMTOP_MAGIC) {
83 			od->ttmem_size  = *ADDR_RAMTOP;
84 			if (od->ttmem_size > TTRAM_BASE) {
85 				od->ttmem_size  -= TTRAM_BASE;
86 				od->ttmem_start  = TTRAM_BASE;
87 			}
88 			else od->ttmem_size = 0;
89 		}
90 	}
91 
92 	/*
93 	 * Scan cookiejar for CPU types, accellerator boards, etc.
94 	 */
95 	jar = *ADDR_P_COOKIE;
96 	if (jar != NULL) {
97 		do {
98 		    if (jar[0] == 0x5f435055) { /* _CPU	*/
99 			switch (jar[1]) {
100 				case 0:
101 					od->cputype |= ATARI_68000;
102 					break;
103 				case 10:
104 					od->cputype |= ATARI_68010;
105 					break;
106 				case 20:
107 					od->cputype |= ATARI_68020;
108 					break;
109 				case 30:
110 					od->cputype |= ATARI_68030;
111 					break;
112 				case 40:
113 					od->cputype |= ATARI_68040;
114 					break;
115 				case 60:
116 					od->cputype |= ATARI_68060;
117 					break;
118 				default:
119 					/* This error is caught later on */
120 					break;
121 		        }
122 		    }
123 		    if (jar[0] == 0x42504658) { /* BPFX	*/
124 			unsigned long	*p;
125 
126 			p = (unsigned long*)jar[1];
127 
128 			od->ttmem_start = p[1];
129 			od->ttmem_size  = p[2];
130 		    }
131 		    if (jar[0] == 0x5f435432) { /* _CT2	*/
132 			/*
133 			 * The CT2 board has a different physical base address!
134 			 */
135 			od->ttmem_start = CTRAM_BASE;
136 		    }
137 		    jar = &jar[2];
138 		} while (jar[-2]);
139 	}
140 }
141 
142 #pragma GCC diagnostic pop
143