kernel32.bin is now written in C, make necessary modifications to Makefile, .gitignore, boot32.asm, etc to get this working
This commit is contained in:
parent
07ef9774c2
commit
1905f3babd
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*.bin
|
||||
*.img
|
||||
*.sector
|
||||
*.o
|
||||
img.d/
|
14
Makefile
14
Makefile
@ -1,4 +1,8 @@
|
||||
disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin
|
||||
|
||||
CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie
|
||||
LDFLAGS =
|
||||
|
||||
disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin kernel32.bin
|
||||
dd if=/dev/zero of=disk.img count=43 bs=100k
|
||||
dd if=boot.sector of=disk.img conv=notrunc
|
||||
mount disk.img img.d
|
||||
@ -20,4 +24,10 @@ print.bin: print.asm
|
||||
nasm $< -o $@
|
||||
|
||||
boot32.bin: boot32.asm
|
||||
nasm $< -o $@
|
||||
nasm $< -o $@
|
||||
|
||||
kernel32.bin: kernel32.ld kernel32.o
|
||||
ld $(LDFLAGS) -T $< -o $@ kernel32.o
|
||||
|
||||
kernel32.o: kernel32.c
|
||||
gcc $(CFLAGS) -o $@ -c $<
|
@ -80,7 +80,7 @@ gdt_code:
|
||||
gdt_data:
|
||||
dw 0xffff
|
||||
dw 0x0
|
||||
db 0x8
|
||||
db 0x0
|
||||
db 10010010b
|
||||
db 01001111b
|
||||
db 0
|
||||
|
58
kernel32.c
Normal file
58
kernel32.c
Normal file
@ -0,0 +1,58 @@
|
||||
void clear_screen();
|
||||
void set_curpos(int x, int y);
|
||||
void print(const char* string);
|
||||
|
||||
unsigned char* VMEM_ADDR = (unsigned char*)0xb8000;
|
||||
const int TERM_WIDTH = 80;
|
||||
const int TERM_HEIGHT = 25;
|
||||
|
||||
int cursor_x = 0;
|
||||
int cursor_y = 0;
|
||||
|
||||
int main() {
|
||||
asm(
|
||||
"mov $0x10, %ax\n"
|
||||
"mov %ax, %ds\n"
|
||||
"mov %ax, %ss\n"
|
||||
"mov $0x90000, %esp"
|
||||
);
|
||||
|
||||
clear_screen();
|
||||
set_curpos(0, 0);
|
||||
|
||||
print("Hello, World!\n\nWe are running XnoeOS Code in C now, Protected Mode has been achieved and everything is working super nicely!\n\nHow wonderful!\n\nNow I just need to hope my print function works properly too~~");
|
||||
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
void clear_screen() {
|
||||
for (int i=0; i<TERM_WIDTH*TERM_HEIGHT; i++) {
|
||||
VMEM_ADDR[i*2] = 0x20;
|
||||
VMEM_ADDR[i*2 + 1] = 0x07;
|
||||
}
|
||||
}
|
||||
|
||||
void set_curpos(int x, int y) {
|
||||
cursor_x = x;
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
void print(const char* string) {
|
||||
int index = 0;
|
||||
char current;
|
||||
while (current=string[index++]) {
|
||||
if (current == '\n') {
|
||||
set_curpos(0, cursor_y+1);
|
||||
continue;
|
||||
}
|
||||
|
||||
int mem_pos = cursor_y * TERM_WIDTH + cursor_x++;
|
||||
VMEM_ADDR[mem_pos*2] = current;
|
||||
VMEM_ADDR[mem_pos*2 + 1] = 0x07;
|
||||
|
||||
if (index == TERM_WIDTH) {
|
||||
cursor_x = 0;
|
||||
cursor_y++;
|
||||
}
|
||||
}
|
||||
}
|
9
kernel32.ld
Normal file
9
kernel32.ld
Normal file
@ -0,0 +1,9 @@
|
||||
ENTRY(main)
|
||||
OUTPUT_FORMAT(binary)
|
||||
OUTPUT_ARCH(i386:i386)
|
||||
|
||||
SECTIONS {
|
||||
. = 0x80000;
|
||||
|
||||
.text : { *(.text*) }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user