revert 64 bit update and some other shit
This commit is contained in:
4
makefile
4
makefile
@@ -1,14 +1,16 @@
|
||||
build: prepare copygrub
|
||||
nasm -felf32 src/bootload/boot.asm -o build/boot.o # entrypoint for grub
|
||||
nasm -felf32 src/kernel/driverdriver.asm -o build/drivdriv.o # driver code for drivers
|
||||
|
||||
gcc -c src/kernel/entry.c -o build/kernel.o -ffreestanding -O2 -Wall -Wextra -m32 # kernel
|
||||
gcc -c src/kernel/registrar.c -o build/registrar.o -ffreestanding -O2 -Wall -Wextra -m32 # registrar
|
||||
gcc -c src/kernel/stdlib.c -o build/stdlib.o -ffreestanding -O2 -Wall -Wextra -m32 # registrar
|
||||
|
||||
gcc -c initrd/vga/main.c -o build/initrddir/vga_graph -ffreestanding -O2 -Wall -Wextra -m32 # initrd/vga driver
|
||||
|
||||
tar -czf build/initrd build/initrddir/* # build initrd
|
||||
|
||||
gcc -m32 -T linker.ld -o build/linked -ffreestanding -O2 -nostdlib build/boot.o build/kernel.o build/registrar.o -fno-pie -fno-pic -no-pie # link
|
||||
gcc -m32 -T linker.ld -o build/linked -ffreestanding -O2 -nostdlib build/boot.o build/kernel.o build/registrar.o build/drivdriv.o build/stdlib.o -fno-pie -fno-pic -no-pie # link
|
||||
|
||||
cp build/linked build/grub/boot/kernel # copy kernel over to grub template
|
||||
cp build/initrd build/grub/boot/JPOS.initrd # copy initrd to grub template
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
; DEPRECATED!
|
||||
|
||||
CPUID_EXTENSIONS equ 0x80000000
|
||||
CPUID_EXT_FEATURES equ 0x80000001
|
||||
EFLAGS_ID equ 1 << 21
|
||||
CPUID_EDX_EXT_FEAT_LM equ 1 << 29
|
||||
|
||||
enterlong:
|
||||
call .queryLongMode
|
||||
|
||||
|
||||
.NoLongMode
|
||||
cli
|
||||
hlt
|
||||
jmp .NoLongMode
|
||||
|
||||
.checkCPUID:
|
||||
pushfd
|
||||
pop eax
|
||||
|
||||
; The original value should be saved for comparison and restoration later
|
||||
mov ecx, eax
|
||||
xor eax, EFLAGS_ID
|
||||
|
||||
; storing the eflags and then retrieving it again will show whether or not
|
||||
; the bit could successfully be flipped
|
||||
push eax ; save to eflags
|
||||
popfd
|
||||
pushfd ; restore from eflags
|
||||
pop eax
|
||||
|
||||
; Restore EFLAGS to its original value
|
||||
push ecx
|
||||
popfd
|
||||
|
||||
; if the bit in eax was successfully flipped (eax != ecx), CPUID is supported.
|
||||
xor eax, ecx
|
||||
jnz .NoLongMode
|
||||
ret
|
||||
|
||||
.queryLongMode:
|
||||
call .checkCPUID
|
||||
|
||||
mov eax, CPUID_EXTENSIONS
|
||||
cpuid
|
||||
cmp eax, CPUID_FEATURES
|
||||
jb .NoLongMode
|
||||
|
||||
mov eax, CPUID_EXT_FEATURES
|
||||
cpuid
|
||||
test edx, CPUID_EDX_EXT_FEAT_LM
|
||||
jz .NoLongMode
|
||||
|
||||
ret
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#define uint8_t unsigned char
|
||||
#define uint16_t unsigned short
|
||||
#define uint32_t unsigned int
|
||||
#define uint64_t unsigned long
|
||||
|
||||
#define int8_t signed char
|
||||
#define int16_t signed short
|
||||
#define int32_t signed int
|
||||
#define int64_t signed long
|
||||
|
||||
#define size_t uint32_t
|
||||
#define size_t uint64_t
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "stddef.h"
|
||||
|
||||
uint32_t strlen32(char* str);
|
||||
void strrev32(char* str);
|
||||
uint8_t uitoa32(uint32_t x, char* str);
|
||||
4
src/headers/stdmem.h
Normal file
4
src/headers/stdmem.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "stddef.h"
|
||||
|
||||
void memcpy32(void* dest, void* src, uint32_t length);
|
||||
5
src/kernel/driverdriver.asm
Normal file
5
src/kernel/driverdriver.asm
Normal file
@@ -0,0 +1,5 @@
|
||||
section .text:
|
||||
[BITS 32]
|
||||
DRIV_storage:
|
||||
resb 16384 ; 16 KiB for driver code/functions
|
||||
DRIV_storage_end:
|
||||
@@ -1,29 +1,39 @@
|
||||
#include "../headers/stddef.h"
|
||||
#include "../headers/multiboot2.h"
|
||||
#include "../headers/registrar.h"
|
||||
#include "../headers/stdlib.h"
|
||||
|
||||
uint32_t basevga_postooffset(uint16_t x, uint16_t y) {
|
||||
volatile uint8_t VGA_MAX_COLS = 80*2;
|
||||
|
||||
return (y*VGA_MAX_COLS)+(x*2);
|
||||
}
|
||||
void basevga_writestdout(char* buf, uint16_t count) {
|
||||
volatile char *video = (volatile char*)0xB8000;
|
||||
volatile uint8_t VGA_MAX_ROWS = 25;
|
||||
volatile uint8_t VGA_MAX_COLS = 80;
|
||||
uint32_t offset = 0;
|
||||
uint32_t offsets[VGA_MAX_ROWS];
|
||||
for (uint8_t i=0;i<VGA_MAX_ROWS;i++) {
|
||||
offsets[i] = (VGA_MAX_COLS*2)*(i+1);
|
||||
}
|
||||
uint8_t x = 0;
|
||||
uint8_t y = 0;
|
||||
|
||||
for (uint32_t i=0;i<count;i++) {
|
||||
if (buf[i] == '\n') {
|
||||
for (uint8_t i=0;i<VGA_MAX_ROWS;i++) {
|
||||
if (offsets[i] > count*2%(VGA_MAX_COLS*VGA_MAX_ROWS)) {
|
||||
offset += (count*2%(VGA_MAX_COLS*VGA_MAX_ROWS))-offsets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
y ++;
|
||||
x = 0;
|
||||
}
|
||||
video[count*2%(VGA_MAX_COLS*VGA_MAX_ROWS)+offset] = buf[i];
|
||||
video[count*2%(VGA_MAX_COLS*VGA_MAX_ROWS)+1+offset] = 15;
|
||||
uint32_t offset = basevga_postooffset(x,y);
|
||||
if (buf[i] != '\n') {
|
||||
x ++;
|
||||
}
|
||||
if (x > VGA_MAX_ROWS) {
|
||||
x = 0;
|
||||
y ++;
|
||||
}
|
||||
if (y > VGA_MAX_COLS) {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
video[offset] = buf[i];
|
||||
video[offset+1] = 15;
|
||||
}
|
||||
}
|
||||
struct multiboot_info {
|
||||
@@ -49,33 +59,114 @@ void* FU_kupdbuf = basevga_writestdout; // register basevga_writestdout as kupdb
|
||||
char kstdout[8192] = {};
|
||||
uint16_t kstdout_count = 0;
|
||||
void kputchar(char x) {
|
||||
if (kstdout_count == 8192) {
|
||||
for (uint32_t i=0;i<8191;i++) {
|
||||
kstdout[i] = kstdout[i+1];
|
||||
}
|
||||
kstdout_count --;
|
||||
}
|
||||
kstdout[kstdout_count++] = x;
|
||||
FUINV_kupdbuf(kstdout, kstdout_count);
|
||||
}
|
||||
void kputstr(char* x) {
|
||||
|
||||
while (*x != 0) {
|
||||
kputchar(*x++);
|
||||
}
|
||||
kputchar('\n');
|
||||
//kputchar('\n');
|
||||
}
|
||||
|
||||
// basic tar parsing code for the initrd
|
||||
struct tar_header {
|
||||
char filename[100];
|
||||
char mode[8];
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char size[12];
|
||||
char mtime[12];
|
||||
char chksum[8];
|
||||
char typeflag[1];
|
||||
};
|
||||
uint32_t tar_getsize(const char *in) {
|
||||
uint32_t size = 0;
|
||||
uint32_t j;
|
||||
uint32_t count = 1;
|
||||
|
||||
for (j = 11; j > 0; j--, count *= 8)
|
||||
size += ((in[j - 1] - '0') * count);
|
||||
|
||||
return size;
|
||||
|
||||
}
|
||||
uint32_t tar_parse(uint64_t address, struct tar_header* headers[]) {
|
||||
uint32_t i;
|
||||
for (i = 0;;i++) {
|
||||
struct tar_header* header = (struct tar_header*)address;
|
||||
if (header->filename[i] == '\0') { // end of archive
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t size = tar_getsize(header->size);
|
||||
|
||||
headers[i] = header;
|
||||
|
||||
address += ((size / 512) + 1) * 512;
|
||||
|
||||
if (size % 512) {
|
||||
address += 512;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
// stuff for drivers
|
||||
struct driver_state_info {
|
||||
void* addr;
|
||||
uint32_t size;
|
||||
uint8_t inuse;
|
||||
};
|
||||
struct driver_state_info driversinfo[32];
|
||||
void loaddriv(void* addr) {
|
||||
|
||||
}
|
||||
|
||||
void kernel_main(struct multiboot_info* header, uint32_t magic) {
|
||||
kputstr("Hello JPOS, World!");
|
||||
kputstr("Hello JPOS, World!\n");
|
||||
while (1) {}
|
||||
|
||||
if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) {
|
||||
kputstr("Invalid magic from bootloader.");
|
||||
kputstr("Invalid magic from bootloader.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
kputstr("Got past magic check.");
|
||||
kputstr("Got past magic check.\n");
|
||||
|
||||
// load drivers
|
||||
|
||||
// find boot modules tag
|
||||
struct multiboot_tag_module* bootmodules = (struct multiboot_tag_module*)&header->tags[findtag(3, header)];
|
||||
if (bootmodules->type != 3) {kputstr("Boot module failure.");return;}
|
||||
//memcpy(0x200000, driver_code, size);
|
||||
//((void(*)())0x200000)();
|
||||
|
||||
if (bootmodules->type != 3) {kputstr("Boot module failure.\n");return;}
|
||||
|
||||
kputstr("Reading ramdisk...\n");
|
||||
char temp[10];
|
||||
uitoa32(bootmodules->mod_end-bootmodules->mod_start, temp);
|
||||
kputstr("Ramdisk size: ");
|
||||
kputstr(temp);
|
||||
kputchar('\n');
|
||||
|
||||
struct tar_header* rd_headers[32];
|
||||
uint8_t rd_header_count = tar_parse(bootmodules->mod_start, rd_headers);
|
||||
uitoa32(rd_header_count, temp);
|
||||
kputstr("Ramdisk modules: ");
|
||||
kputstr(temp);
|
||||
kputchar('\n');
|
||||
|
||||
kputstr((char*)&rd_headers[0]);
|
||||
for (uint8_t i=0;i<rd_header_count;i++) {
|
||||
kputstr(" ");
|
||||
kputstr(rd_headers[i]->filename);
|
||||
kputchar('\n');
|
||||
// TODO: actually load ramdisk stuff, first I'd like to enter 64 bit mode.
|
||||
}
|
||||
|
||||
kputstr("End of Ramdisk\n");
|
||||
}
|
||||
25
src/kernel/stdlib.c
Normal file
25
src/kernel/stdlib.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "../headers/stdlib.h"
|
||||
|
||||
uint32_t strlen32(char* str) {
|
||||
uint32_t i = 0;
|
||||
while (*str++ != 0) {i++;}
|
||||
return i;
|
||||
}
|
||||
void strrev32(char* str) {
|
||||
int c, i, j;
|
||||
for (i = 0, j = strlen32(str)-1; i < j; i++, j--) {
|
||||
c = str[i];
|
||||
str[i] = str[j];
|
||||
str[j] = c;
|
||||
}
|
||||
}
|
||||
uint8_t uitoa32(uint32_t x, char* str) {
|
||||
uint8_t i=0;
|
||||
while (x > 0) {
|
||||
str[i++] = x%10+'0';
|
||||
x /= 10;
|
||||
}
|
||||
str[i] = 0;
|
||||
strrev32(str);
|
||||
return i;
|
||||
}
|
||||
Reference in New Issue
Block a user