Skip to content

Commit c8dc758

Browse files
Merge branch '0006-Keyboard-Support'
2 parents 39f83fb + fcf4c4f commit c8dc758

File tree

25 files changed

+2468
-418
lines changed

25 files changed

+2468
-418
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"files.associations": {
3+
"common.h": "c",
4+
"idt.h": "c",
5+
"screen.h": "c",
6+
"irq.h": "c",
7+
"keyboard.h": "c"
8+
}
9+
}

Commands.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
docker run --rm -it -v $HOME/Documents/GitHub/SQLpassion/osdev:/src sqlpassion/kaos-buildenv /bin/sh /src/main64/clean.sh
3333
docker run --rm -it -v $HOME/Documents/GitHub/SQLpassion/osdev:/src sqlpassion/kaos-buildenv /bin/sh /src/main64/build.sh
3434
- Write the final FAT12 image to a virtual disk:
35-
sudo dd if="$HOME/Documents/GitHub/SQLpassion/osdev/main64/kaos64.img" of="$HOME/Documents/Virtual Machines/KAOS.vmwarevm/Virtual Disk-flat.vmdk" conv=notrunc
35+
dd if="$HOME/Documents/GitHub/SQLpassion/osdev/main64/kaos64.img" of="$HOME/Documents/Virtual Machines/KAOS.vmwarevm/Virtual Disk-flat.vmdk" conv=notrunc
36+
- Everything in one command:
37+
clear && docker run --rm -it -v $HOME/Documents/GitHub/SQLpassion/osdev:/src sqlpassion/kaos-buildenv /bin/sh /src/main64/clean.sh && docker run --rm -it -v $HOME/Documents/GitHub/SQLpassion/osdev:/src sqlpassion/kaos-buildenv /bin/sh /src/main64/build.sh && dd if="$HOME/Documents/GitHub/SQLpassion/osdev/main64/kaos64.img" of="$HOME/Documents/Virtual Machines/KAOS.vmwarevm/Virtual Disk-flat.vmdk" conv=notrunc
3638

3739
###########################
3840
# Run on physical Notebook

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 SQLpassion
3+
Copyright (c) 2022 - 2023 Klaus Aschenbrenner, www.SQLpassion.at
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

main64/MemoryMap.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Real Mode
22
=========
3-
0x000500 - 0x004500: FAT Root Directory and FAT Tables (32 Sectors)
4-
0x001000 - 0x001FFF: BIOS Information Block
5-
0x002000 - 0x002FFF: KLDR16.BIN
6-
0x003000 - 0x007BFF: KLDR64.BIN
7-
0x007c00 - 0x007e00: Boot Sector
8-
0x007e00 - 0x008000: Real Mode Stack (512 Bytes)
3+
0x000500 - 0x004500: FAT Root Directory and FAT Tables (32 Sectors)
4+
0x001000 - 0x001FFF: BIOS Information Block
5+
0x002000 - 0x002FFF: KLDR16.BIN
6+
0x003000 - 0x007BFF: KLDR64.BIN
7+
0x007c00 - 0x007e00: Boot Sector
8+
0x007e00 - 0x008000: Real Mode Stack (512 Bytes)
99
0x009000 to 0x009FFF: Page Map Level 4
1010
0x010000 to 0x010FFF: Page Directory Pointer Table
1111
0x011000 to 0x011FFF: Page Directory Table
@@ -19,4 +19,7 @@ Long Mode
1919
=========
2020
0x030000 - 0x031BFF: Root Directory Buffer used by KLDR64.BIN
2121
0x031C00 - 0x033FFF: FAT Buffer used by KLDR64.BIN
22+
0x034000 - 0x050000: x64 Kernel Stack
23+
0x060000 - 0x060FFF: x64 IDT Table
24+
0x061000 - 0x061FFF: Structure "RegisterState" for Exception Handlers
2225
0x100000 - 0x200000: KERNEL.BIN

main64/ScanCodes.png

83 KB
Loading

main64/kernel/common.c

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
#include "common.h"
2+
#include "drivers/screen.h"
3+
4+
char tbuf[64];
5+
char tbuf_long[64];
6+
char bchars[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
7+
8+
// Reads a single char (8 bytes) from the specified port
9+
unsigned char inb(unsigned short Port)
10+
{
11+
unsigned char ret;
12+
asm volatile("inb %1, %0" : "=a" (ret) : "dN" (Port));
13+
14+
return ret;
15+
}
16+
17+
// Reads a single short (16 bytes) from the specific port
18+
unsigned short inw(unsigned short Port)
19+
{
20+
unsigned short ret;
21+
asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (Port));
22+
23+
return ret;
24+
}
25+
26+
// Writes a single char (8 bytes) to the specified port
27+
void outb(unsigned short Port, unsigned char Value)
28+
{
29+
asm volatile ("outb %1, %0" : : "dN" (Port), "a" (Value));
30+
}
31+
32+
// Writes a single short (16 bytes) to the specified port
33+
void outw(unsigned short Port, unsigned short Value)
34+
{
35+
asm volatile ("outw %1, %0" : : "dN" (Port), "a" (Value));
36+
}
37+
38+
// Writes a single int (32 bytes) to the specified port
39+
void outl(unsigned short Port, unsigned int Value)
40+
{
41+
asm volatile ("outl %1, %0" : : "dN" (Port), "a" (Value));
42+
}
43+
44+
// A simple memset implementation
45+
void *memset(void *s, int c, long n)
46+
{
47+
unsigned char *p = s;
48+
49+
while (n--)
50+
*p++ = (unsigned char)c;
51+
52+
return s;
53+
}
54+
55+
// A simple memcpy implementation
56+
void memcpy(void *dest, void *src, int len)
57+
{
58+
int i;
59+
char *csrc = (char *)src;
60+
char *cdest = (char *)dest;
61+
62+
for (i = 0; i < len; i++)
63+
{
64+
cdest[i] = csrc[i];
65+
}
66+
}
67+
68+
// Returns the length of the given string
69+
int strlen(char *string)
70+
{
71+
int len = 0;
72+
73+
while (*string != '\0')
74+
{
75+
len++;
76+
string++;
77+
}
78+
79+
return len;
80+
}
81+
82+
// A simple strcpy implementation
83+
char *strcpy(char *destination, const char *source)
84+
{
85+
// return if no memory is allocated to the destination
86+
if (destination == 0x0)
87+
return 0x0;
88+
89+
// take a pointer pointing to the beginning of destination string
90+
char *ptr = destination;
91+
92+
// copy the C-string pointed by source into the array pointed by destination
93+
while (*source != '\0')
94+
{
95+
*destination = *source;
96+
destination++;
97+
source++;
98+
}
99+
100+
// include the terminating null character
101+
*destination = '\0';
102+
103+
// destination is returned by standard strcpy()
104+
return ptr;
105+
}
106+
107+
// A simple strcmp implementation
108+
int strcmp(char *s1, char *s2)
109+
{
110+
int i = 0;
111+
int len = strlen(s2);
112+
113+
while (*s1 && (*s1 == *s2) && i < len)
114+
{
115+
s1++;
116+
s2++;
117+
i++;
118+
}
119+
120+
return *(unsigned char *)s1 - *(unsigned char *)s2;
121+
}
122+
123+
// Returns a substring from a given string
124+
int substring(char *source, int from, int n, char *target)
125+
{
126+
int length,i;
127+
//get string length
128+
for(length=0;source[length]!='\0';length++);
129+
130+
if(from>length){
131+
printf("Starting index is invalid.\n");
132+
return 1;
133+
}
134+
135+
if((from+n)>length){
136+
//get substring till end
137+
n=(length-from);
138+
}
139+
140+
//get substring in target
141+
for(i=0;i<n;i++){
142+
target[i]=source[from+i];
143+
}
144+
target[i]='\0'; //assign null at last
145+
146+
return 0;
147+
}
148+
149+
// Returns the position of the specific character in the given string
150+
int find(char *string, char junk)
151+
{
152+
int pos = 0;
153+
154+
while (*string != junk)
155+
{
156+
pos++;
157+
string++;
158+
}
159+
160+
return pos;
161+
}
162+
163+
// Checks if a string starts with a given prefix
164+
int startswith(char *string, char *prefix)
165+
{
166+
while (*prefix)
167+
{
168+
if (*prefix++ != *string++)
169+
return 0;
170+
}
171+
172+
return 1;
173+
}
174+
175+
// Converts a string to upper case
176+
void toupper(char *s)
177+
{
178+
for (; *s; s++)
179+
if (('a' <= *s) && (*s <= 'z'))
180+
*s = 'A' + (*s - 'a');
181+
}
182+
183+
// Converts a string to lower case
184+
void tolower(char *s)
185+
{
186+
for(; *s; s++)
187+
if(('A' <= *s) && (*s <= 'Z'))
188+
*s = 'a' + (*s - 'A');
189+
}
190+
191+
// Converts an integer value to a string value for a specific base (base 10 => decimal, base 16 => hex)
192+
void itoa(int i, unsigned base, char *buf)
193+
{
194+
if (base > 16) return;
195+
196+
if (i < 0)
197+
{
198+
*buf++ = '-';
199+
i *= -1;
200+
}
201+
202+
itoa_helper(i, base, buf);
203+
}
204+
205+
// Helper function for the itoa function.
206+
static void itoa_helper(unsigned short i, unsigned base, char *buf)
207+
{
208+
int pos = 0;
209+
int opos = 0;
210+
int top = 0;
211+
212+
if (i == 0 || base > 16)
213+
{
214+
buf[0] = '0';
215+
buf[1] = '\0';
216+
return;
217+
}
218+
219+
while (i != 0)
220+
{
221+
tbuf[pos] = bchars[i % base];
222+
pos++;
223+
i /= base;
224+
}
225+
226+
top = pos--;
227+
228+
for (opos = 0; opos < top; pos--,opos++)
229+
{
230+
buf[opos] = tbuf[pos];
231+
}
232+
233+
buf[opos] = 0;
234+
}
235+
236+
// Converts a long value to a string value for a specific base (base 10 => decimal, base 16 => hex)
237+
void ltoa(unsigned long i, unsigned base, char *buf)
238+
{
239+
if (base > 16) return;
240+
241+
if (i < 0)
242+
{
243+
*buf++ = '-';
244+
i *= -1;
245+
}
246+
247+
ltoa_helper(i, base, buf);
248+
}
249+
250+
// Helper function for the ltoa function.
251+
static void ltoa_helper(unsigned long i, unsigned base, char *buf)
252+
{
253+
int pos = 0;
254+
int opos = 0;
255+
int top = 0;
256+
257+
if (i == 0 || base > 16)
258+
{
259+
buf[0] = '0';
260+
buf[1] = '\0';
261+
return;
262+
}
263+
264+
while (i != 0)
265+
{
266+
tbuf[pos] = bchars[i % base];
267+
pos++;
268+
i /= base;
269+
}
270+
271+
top = pos--;
272+
273+
for (opos = 0; opos < top; pos--,opos++)
274+
{
275+
buf[opos] = tbuf[pos];
276+
}
277+
278+
buf[opos] = 0;
279+
}
280+
281+
// Converts an ASCII string to its integer value
282+
int atoi(char *str)
283+
{
284+
int res = 0;
285+
int i;
286+
287+
for (i = 0; str[i] != '\0'; ++i)
288+
{
289+
res = res * 10 + str[i] - '0';
290+
}
291+
292+
return res;
293+
}

0 commit comments

Comments
 (0)