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:
Xnoe 2021-09-02 12:46:14 +01:00
parent 1905f3babd
commit 76e61b1d71
Signed by: xnoe
GPG Key ID: 45AC398F44F0DAFE
5 changed files with 70 additions and 22 deletions

View File

@ -1,5 +1,4 @@
CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie
CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector
LDFLAGS =
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
nasm $< -o $@
kernel32.bin: kernel32.ld kernel32.o
ld $(LDFLAGS) -T $< -o $@ kernel32.o
kernel32.bin: kernel32.ld kernel32_strap.o kernel32.o
ld $(LDFLAGS) -T $<
kernel32.o: kernel32.c
gcc $(CFLAGS) -o $@ -c $<
kernel32_strap.o: kernel32_strap.asm
nasm -felf32 $< -o $@

View File

@ -1,28 +1,36 @@
void clear_screen();
void set_curpos(int x, int y);
void print(const char* string);
#include "types.h"
unsigned char* VMEM_ADDR = (unsigned char*)0xb8000;
uint8_t* VMEM_ADDR = (uint8_t*)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"
);
void outb(uint16_t portnumber, uint8_t data) {
asm volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber));
}
uint8_t inb(uint16_t portnumber) {
uint8_t result;
asm volatile("inb %1, %0" : "=a" (result) : "Nd" (portnumber));
return result;
}
clear_screen();
set_curpos(0, 0);
uint16_t get_cursor_position() {
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() {
@ -56,3 +64,14 @@ void print(const char* string) {
}
}
}
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) {}
}

View File

@ -1,9 +1,14 @@
ENTRY(main)
OUTPUT_FORMAT(binary)
OUTPUT_ARCH(i386:i386)
INPUT(kernel32_strap.o kernel32.o)
OUTPUT(kernel32.bin)
SECTIONS {
. = 0x80000;
.text : { *(.text*) }
.text : {
kernel32_strap.o(.text)
kernel32.o(.text)
}
}

11
kernel32_strap.asm Normal file
View File

@ -0,0 +1,11 @@
[BITS 32]
_start:
mov ax, 10h
mov ds, ax
mov ss, ax
mov esp, 90000h
call main
extern main

11
types.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef TYPES_H
#define TYPES_H
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long long int int32_t;
typedef unsigned long long int uint32_t;
#endif