Cleanup and refactoring
This commit is contained in:
parent
46a560910b
commit
2932e2946e
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"ktypes.h": "c"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
mkdir /tmp/src
|
||||
cd /tmp/src
|
||||
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.39.tar.gz
|
||||
tar xf binutils-2.39.tar.gz
|
||||
mkdir binutils-build
|
||||
cd binutils-build
|
||||
../binutils-2.39/configure --target=$TARGET --enable-interwork --enable-multilib --disable-nls --disable-werror --prefix=$PREFIX 2>&1 | tee configure.log
|
||||
sudo make all install 2>&1 | tee make.log
|
||||
cd /tmp/src
|
||||
curl -O https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.gz
|
||||
tar xf gcc-12.2.0.tar.gz
|
||||
mkdir gcc-build
|
||||
cd gcc-build
|
||||
../gcc-12.2.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --disable-libssp --enable-languages=c --without-headers
|
||||
sudo make all-gcc
|
||||
sudo make all-target-libgcc
|
||||
sudo make install-gcc
|
||||
sudo make install-target-libgcc
|
7
build.sh
7
build.sh
|
@ -1,5 +1,6 @@
|
|||
#!/bin/bash
|
||||
i386-elf-gcc -ffreestanding -c src/kernel/main.c -o main.o
|
||||
nasm -f elf src/entrypoint.s -o entrypoint.o
|
||||
i386-elf-ld -o kernel.bin -Ttext 0x1000 entrypoint.o main.o --oformat binary
|
||||
i386-elf-gcc -ffreestanding -c src/kernel/main.c -o kernel.o
|
||||
nasm -f elf src/entrypoint.s -o entry.o
|
||||
nasm -f bin src/boot/mbr.s -o mbr.bin
|
||||
i386-elf-ld -o kernel.bin -Ttext 0x1000 entry.o kernel.o --oformat binary
|
||||
cat mbr.bin kernel.bin > os.bin
|
||||
|
|
2
env.sh
2
env.sh
|
@ -3,4 +3,4 @@ export CC=/usr/bin/gcc
|
|||
export LD=/usr/bin/gcc
|
||||
export PREFIX="/usr/local/i386elfgcc"
|
||||
export TARGET=i386-elf
|
||||
export PATH="$PREFIX/bin:$PATH"
|
||||
export PATH=$PATH:$PREFIX/bin
|
||||
|
|
|
@ -25,10 +25,10 @@ jmp $ ; Keeps jumping at the current address (loops forever)
|
|||
|
||||
; Now we include our "function definitions" (after the
|
||||
; loop, so they're never executed unless explicitly called)
|
||||
%include "src/bootloader/util/disk.s"
|
||||
%include "src/bootloader/util/io.s"
|
||||
%include "src/bootloader/gdt.s"
|
||||
%include "src/bootloader/switch32.s"
|
||||
%include "src/boot/util/disk.s"
|
||||
%include "src/boot/util/io.s"
|
||||
%include "src/boot/gdt.s"
|
||||
%include "src/boot/switch32.s"
|
||||
|
||||
[bits 16] ; All x86 CPUs start in 16 bit (aka "real") mode, so we tell nasm to emit 16-bit code
|
||||
load_kernel: ; Loads the kernel into memory
|
|
@ -0,0 +1,30 @@
|
|||
// Implementation of a simple video driver using VGA text mode
|
||||
#include "video.h"
|
||||
|
||||
|
||||
uchar_t vga_readb(u16_t port) {
|
||||
// Reads a byte from the specified I/O port
|
||||
uchar_t result;
|
||||
__asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void vga_writeb(u16_t port, uchar_t data) {
|
||||
// Writes a byte from the specified I/O port
|
||||
__asm__("out %%al, %%dx" : : "a" (data), "d" (port));
|
||||
}
|
||||
|
||||
|
||||
u16_t vga_writew(u16_t port) {
|
||||
// Reads a word (16 bits) from the specified I/O port
|
||||
u16_t result;
|
||||
__asm__("in %%dx, %%ax" : "=a" (result) : "d" (port));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void vga_readw(u16_t port, u16_t data) {
|
||||
// Writes a word (16 bits) to the specified I/O port
|
||||
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef TSOS_DRV_VGA_H // Avoid nasty double-inclusion problems
|
||||
#define TSOS_DRV_VGA_H
|
||||
#define VMEM_ADDR 0xb8000
|
||||
#include "kernel/types/ktypes.h"
|
||||
|
||||
|
||||
uchar_t vga_writeb(u16_t port);
|
||||
void vga_readb(u16_t port, uchar_t data);
|
||||
u16_t vga_writew(u16_t port);
|
||||
void vga_readw(u16_t port, u16_t data);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,15 +1,12 @@
|
|||
// C entry point of our kernel
|
||||
#define VMEM_ADDR 0xb8000
|
||||
|
||||
void dummy_test_entrypoint(void) {
|
||||
}
|
||||
// Entry point of the TSOS kernel
|
||||
#include "types/ktypes.h"
|
||||
|
||||
|
||||
void kmain(void) {
|
||||
char* vbuf = (char*)VMEM_ADDR;
|
||||
char_t* vbuf = (char_t*)0xb8000;
|
||||
vbuf += 480; // We skip the log messages before us
|
||||
char *s = "Hello from the TSOS kernel!";
|
||||
for (int i = 0; s[i] != '\0'; i++) {
|
||||
char_t *s = "Hello from the TSOS kernel!";
|
||||
for (int_t i = 0; s[i] != '\0'; i++) {
|
||||
*vbuf = s[i];
|
||||
vbuf += 2;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
// Shorthand definitions of various types
|
||||
// used in the kernel
|
||||
#ifndef TSOS_KTYPES
|
||||
#define TSOS_KTYPES
|
||||
|
||||
|
||||
typedef unsigned char uchar_t;
|
||||
typedef unsigned short int u16_t;
|
||||
typedef short int i16_t;
|
||||
typedef char char_t;
|
||||
typedef unsigned int uint_t;
|
||||
typedef int int_t;
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue