Linker script now makes use of kernel32_strap.asm in order to ensure that we enter the correct position in kernel32.bin, updated kernel32.ld, Makefile, etc accordingly. Added types.h for convenience.
This commit is contained in:
parent
1905f3babd
commit
76e61b1d71
12
Makefile
12
Makefile
@ -1,5 +1,4 @@
|
|||||||
|
CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector
|
||||||
CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie
|
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin kernel32.bin
|
disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin kernel32.bin
|
||||||
@ -26,8 +25,11 @@ print.bin: print.asm
|
|||||||
boot32.bin: boot32.asm
|
boot32.bin: boot32.asm
|
||||||
nasm $< -o $@
|
nasm $< -o $@
|
||||||
|
|
||||||
kernel32.bin: kernel32.ld kernel32.o
|
kernel32.bin: kernel32.ld kernel32_strap.o kernel32.o
|
||||||
ld $(LDFLAGS) -T $< -o $@ kernel32.o
|
ld $(LDFLAGS) -T $<
|
||||||
|
|
||||||
kernel32.o: kernel32.c
|
kernel32.o: kernel32.c
|
||||||
gcc $(CFLAGS) -o $@ -c $<
|
gcc $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
kernel32_strap.o: kernel32_strap.asm
|
||||||
|
nasm -felf32 $< -o $@
|
49
kernel32.c
49
kernel32.c
@ -1,28 +1,36 @@
|
|||||||
void clear_screen();
|
#include "types.h"
|
||||||
void set_curpos(int x, int y);
|
|
||||||
void print(const char* string);
|
|
||||||
|
|
||||||
unsigned char* VMEM_ADDR = (unsigned char*)0xb8000;
|
uint8_t* VMEM_ADDR = (uint8_t*)0xb8000;
|
||||||
const int TERM_WIDTH = 80;
|
const int TERM_WIDTH = 80;
|
||||||
const int TERM_HEIGHT = 25;
|
const int TERM_HEIGHT = 25;
|
||||||
|
|
||||||
int cursor_x = 0;
|
int cursor_x = 0;
|
||||||
int cursor_y = 0;
|
int cursor_y = 0;
|
||||||
|
|
||||||
int main() {
|
void outb(uint16_t portnumber, uint8_t data) {
|
||||||
asm(
|
asm volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber));
|
||||||
"mov $0x10, %ax\n"
|
}
|
||||||
"mov %ax, %ds\n"
|
uint8_t inb(uint16_t portnumber) {
|
||||||
"mov %ax, %ss\n"
|
uint8_t result;
|
||||||
"mov $0x90000, %esp"
|
asm volatile("inb %1, %0" : "=a" (result) : "Nd" (portnumber));
|
||||||
);
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
clear_screen();
|
uint16_t get_cursor_position() {
|
||||||
set_curpos(0, 0);
|
uint16_t cursor_position = 0;
|
||||||
|
uint8_t* cursor_position_split = (uint8_t*)&cursor_position;
|
||||||
|
outb(0x3D4, 0x0F);
|
||||||
|
cursor_position_split[0] = inb(0x3D5);
|
||||||
|
outb(0x3D4, 0x0E);
|
||||||
|
cursor_position_split[1] = inb(0x3D5);
|
||||||
|
return cursor_position;
|
||||||
|
}
|
||||||
|
|
||||||
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~~");
|
void init_term() {
|
||||||
|
uint16_t cursor_position = get_cursor_position();
|
||||||
|
|
||||||
while (1) {}
|
cursor_y = cursor_position / TERM_WIDTH;
|
||||||
|
cursor_x = cursor_position % TERM_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_screen() {
|
void clear_screen() {
|
||||||
@ -55,4 +63,15 @@ void print(const char* string) {
|
|||||||
cursor_y++;
|
cursor_y++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
init_term();
|
||||||
|
|
||||||
|
print("KERNEL32 OK!\n\n");
|
||||||
|
|
||||||
|
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) {}
|
||||||
}
|
}
|
@ -1,9 +1,14 @@
|
|||||||
ENTRY(main)
|
|
||||||
OUTPUT_FORMAT(binary)
|
OUTPUT_FORMAT(binary)
|
||||||
OUTPUT_ARCH(i386:i386)
|
OUTPUT_ARCH(i386:i386)
|
||||||
|
|
||||||
|
INPUT(kernel32_strap.o kernel32.o)
|
||||||
|
OUTPUT(kernel32.bin)
|
||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = 0x80000;
|
. = 0x80000;
|
||||||
|
|
||||||
.text : { *(.text*) }
|
.text : {
|
||||||
|
kernel32_strap.o(.text)
|
||||||
|
kernel32.o(.text)
|
||||||
|
}
|
||||||
}
|
}
|
11
kernel32_strap.asm
Normal file
11
kernel32_strap.asm
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[BITS 32]
|
||||||
|
|
||||||
|
_start:
|
||||||
|
mov ax, 10h
|
||||||
|
mov ds, ax
|
||||||
|
mov ss, ax
|
||||||
|
mov esp, 90000h
|
||||||
|
|
||||||
|
call main
|
||||||
|
|
||||||
|
extern main
|
Loading…
x
Reference in New Issue
Block a user