1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/* $NetBSD: proto.h,v 1.3 1994/10/27 04:21:24 cgd Exp $ */
/*
* TBD - need for common typedefs - rethink?
* TBD - move config include into the source files - this is just expedient
*/
#include "config.h"
#include "nbtypes.h"
#define TRUE 1
#define FALSE 0
#define MDUMP 100 /* TBD - remove */
#define MAX_FILE_NAME_LEN 128
#define CRTBASE ((char *)0xb8000)
#define CHECKPOINT(x) (CRTBASE[0] = x)
#define nelt(x) (sizeof(x)/sizeof((x)[0]))
void ENTER(char *); /* remove TBD */
int IsKbdCharReady(void);
u_char GetKbdChar(void);
void HandleKbdAttn(void);
void KbdWait(int n);
int bcmp(const void *, const void *, int);
void volatile exit(int);
void volatile ExitToBios(void);
void gateA20(void);
int getc(void);
int getchar(void);
u_short GetMemSize(u_short);
int gets(char *);
int ischar(void);
void longjmp(jmp_buf env, int val);
void printf( /* const char *, ... */ );
void putc(int);
void putchar(int);
int rand(void);
void ResetCpu(void);
int setjmp(jmp_buf env);
void srand(u_int);
void StartProg(u_long phyaddr, u_long *args);
int strlen(const char *);
char *strncat(char *, const char *, int len);
char *strncpy(char *, const char *, int len);
int strcmp(const char *, const char *);
u_long timer(void);
/* macros in pio.h, rewritten as in-line functions */
/* TBD - define addr arg as long - short might result in extra
bit masking whereas longs simply get plonked down in %edx */
#undef inb
#undef outb
#undef inw
#undef outw
#undef inl
#undef outl
static inline u_char
inb(u_short addr) {
u_char datum;
asm volatile("inb %1, %0" : "=a" (datum) : "d" (addr));
return datum;
}
static inline void
outb(u_short addr, u_char datum) {
asm volatile("outb %0, %1" : : "a" (datum), "d" (addr));
}
static inline u_short
inw(u_short addr) {
u_short datum;
asm volatile(".byte 0x66; inl %1, %0" : "=a" (datum) : "d" (addr));
return datum;
}
static inline void
outw(u_short addr, u_short datum) {
asm volatile(".byte 0x66; outw %0, %1" : : "a" (datum), "d" (addr));
}
static inline u_long
inl(u_short addr) {
u_long datum;
asm volatile("inw %1, %0" : "=a" (datum) : "d" (addr));
return datum;
}
static inline void
outl(u_short addr, u_long datum) {
asm volatile("outw %0, %1" : : "a" (datum), "d" (addr));
}
#if __GCC__ >= 2
/* fast versions of bcopy(), bzero() */
static inline void
bcopy(const void *from, void *to, int len) {
/* assumes %es == %ds */
asm("
mov %0, %%esi
mov %1, %%edi
mov %2, %%ecx
cld
rep
movsb
" : : "g" (from), "g" (to), "g" (len) : "esi", "edi", "ecx");
}
static inline void
bzero(void *dest, int len) {
/* assumes %es == %ds */
asm("
mov %0, %%edi
mov %1, %%ecx
xor %%eax, %%eax
cld
rep
stosb
" : : "g" (dest), "g" (len) : "edi", "ecx", "eax");
}
#else
static inline void
bcopy(char *from, char *to, int len)
{
while (len-- > 0)
*to++ = *from++;
}
static inline void
bzero(char *to, int len)
{
while (len-- > 0)
*to++ = '\0';
}
#endif
static inline void PhysBcopy(u_long src, u_long dest, u_long nbytes) {
bcopy((void *)src, (void *)dest, nbytes);
}
static inline void PhysBzero(u_long dest, u_long nbytes) {
bzero((void *)dest, nbytes);
}
|