From 78369c702d13e25384073554d4d8c3b372472efb Mon Sep 17 00:00:00 2001 From: corey Date: Fri, 5 Apr 2024 17:10:50 -0500 Subject: [PATCH] remove duplicate files --- cstdlib/stdio.h | 2 +- kernel.c | 88 ---------------------------------------------- link.ld | 34 ------------------ loader.s | 27 -------------- scripts/include.mk | 2 +- stdbool.h | 5 --- stdint.h | 12 ------- stdio.c | 79 ----------------------------------------- stdio.h | 32 ----------------- string.h | 10 ------ 10 files changed, 2 insertions(+), 289 deletions(-) delete mode 100644 kernel.c delete mode 100644 link.ld delete mode 100644 loader.s delete mode 100644 stdbool.h delete mode 100644 stdint.h delete mode 100644 stdio.c delete mode 100644 stdio.h delete mode 100644 string.h diff --git a/cstdlib/stdio.h b/cstdlib/stdio.h index b9a34d0..14f04ca 100644 --- a/cstdlib/stdio.h +++ b/cstdlib/stdio.h @@ -29,4 +29,4 @@ void fputs(FILE*f,char*s); //#define print(x) fprint(stdout,x) #define printi(x) fprinti(stdout,x) //#define printi16(x) fprinti16(stdout,x) -// #define puts(x) fputs(stdout,x) +//#define puts(x) fputs(stdout,x) diff --git a/kernel.c b/kernel.c deleted file mode 100644 index 622431d..0000000 --- a/kernel.c +++ /dev/null @@ -1,88 +0,0 @@ -#include"stdio.h" -#include"stdint.h" -#include"stdbool.h" -#include"string.h" - -#define at at8 -#define at8(x) (*(char*)x) - -uint8_t kbdus[128]={0,27,'1','2','3','4','5','6','7','8','9','0','-','=','\b','\t','q','w','e','r','t','y','u','i','o','p','[',']','\n',0,'a','s','d','f','g','h','j','k','l',';','\'','`',0,'\\','z','x','c','v','b','n','m',',','.','/',0,'*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0}; - -void outb(uint16_t port,uint8_t val) -{ - asm("out %0,%1"::"a"(val),"Nd"(port)); -} - -uint8_t inb(uint16_t port) -{ - uint8_t ret; - asm("in %1,%0":"=a"(ret):"Nd"(port)); - return ret; -} - -__attribute__ ((naked)) static void halt(void) -{ - asm( - "cli\n" - "hlt\n" - "jmp halt\n" - ); -} - -uint8_t*const vram=(uint8_t*)0xB8000; -void putpixel(uint8_t*const screen,int32_t x,int32_t y,int32_t color) -{ - const uint32_t width=320; - const uint32_t height=240; - uint32_t where=x*width+y*height; - screen[where]=color&0xff; - screen[where+1]=(color>>8)&0xff; - screen[where+2]=(color>>16)&0xff; -} - -// Entry point -void kernelmain(void*multiboot_structure,uint32_t magicnumber) -{ - - // Clear text mode buffer - memset((void*)0xb8000,0,2000); - - puts(""); - puts(""); - puts("This is an operating system or something."); - - print("Multiboot structure:"); - printi16((int32_t)multiboot_structure); - puts(""); - - print("Magic number:"); - printi16((int32_t)magicnumber); - puts(""); - - putpixel(vram,3,3,0x0000ffff); - - //((char*)0x64)[0]=(uint8_t)0xaa; - outb(0x64,0xaa); - outb(0x64,0xee); - - uint32_t lastchar=0; - - stdout->seek=0; - // Check PS/2 status register - while(true) - { - - uint32_t r=inb(0x60); - while(!(r&0x80)&&(r!=lastchar)) - { - if(r=='\b')stdout->seek-=2; - else if(r!=0)fputc(kbdus[r],stdout); - lastchar=r; - } - - if(stdout->seek>=1000) - stdout->seek=0; - } - - halt(); -} diff --git a/link.ld b/link.ld deleted file mode 100644 index 8492dae..0000000 --- a/link.ld +++ /dev/null @@ -1,34 +0,0 @@ -ENTRY(loader) -OUTPUT_FORMAT(elf32-i386) -OUTPUT_ARCH(i386:i386) - -SECTIONS -{ - . = 0x0100000; - - .text : - { - *(.multiboot ) - *(.text* ) - *(.rodata ) - } - - .data : - { - start_ctors = .; - KEEP(*(.init_array )); - KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* ) )); - end_ctors = .; - } - - .bss : - { - *(.bss ) - } - - /DISCARD/ : - { - *(.fini_array* ) - *(.comment ) - } -} diff --git a/loader.s b/loader.s deleted file mode 100644 index cb59e12..0000000 --- a/loader.s +++ /dev/null @@ -1,27 +0,0 @@ -.set MAGIC, 0x1badb002 -.set FLAGS, (1<<0 | 1<<1) -.set CHECKSUM, -(MAGIC + FLAGS) - -.section .multiboot - .long MAGIC - .long FLAGS - .long CHECKSUM - -.section .text -.extern kernelmain -.global loader - -loader: - mov $kernel_stack, %esp - push %eax - push %ebx - call kernelmain -.L1: - cli - hlt - jmp .L1 - -.section bss -.space 2*1024*1024 ; # 2 MiB -kernel_stack: - diff --git a/scripts/include.mk b/scripts/include.mk index 89af8b7..4e9a8b1 100644 --- a/scripts/include.mk +++ b/scripts/include.mk @@ -6,7 +6,7 @@ CC = cc LD = ld LR = lr RM = rm -f -CFLAGS := -Werror -fno-stack-protector -fno-builtin -ffreestanding -m32 -Wall -Wextra -Wfatal-errors -nostdlib -Wno-builtin-declaration-mismatch -g3 -Werror=discarded-qualifiers -Werror=ignored-qualifiers -I$(SRCTOP) -I$(CURDIR) -I$(SRCTOP)/cstdlib +CFLAGS := -fno-stack-protector -fno-builtin -ffreestanding -m32 -Wall -Wextra -Wfatal-errors -nostdlib -Wno-builtin-declaration-mismatch -g3 -Werror=discarded-qualifiers -Werror=ignored-qualifiers -I$(SRCTOP) -I$(CURDIR) -I$(SRCTOP)/cstdlib ASFLAGS ?= --32 LDFLAGS ?= --no-warn-rwx-segments -no-pie -nostdlib -e loader -T scripts/link.ld -z noexecstack LRFLAGS ?= -m i386 diff --git a/stdbool.h b/stdbool.h deleted file mode 100644 index 7745cdf..0000000 --- a/stdbool.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -typedef unsigned char bool; -#define true 1 -#define false 0 diff --git a/stdint.h b/stdint.h deleted file mode 100644 index 4dbedf3..0000000 --- a/stdint.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; -typedef unsigned long long uint64_t; -typedef uint64_t size_t; - -typedef char int8_t; -typedef short int16_t; -typedef long int32_t; -typedef long long int64_t; diff --git a/stdio.c b/stdio.c deleted file mode 100644 index e2b9f17..0000000 --- a/stdio.c +++ /dev/null @@ -1,79 +0,0 @@ -#include"stdio.h" -#include"stdint.h" - -FILE*stdout=&(FILE){.fd=0,.offset=(uint16_t*)0xb8000,.seek=0}; - -void fputc(char c,FILE*f) -{ - if(c=='\n') - f->seek=(f->seek+WIDTH)/WIDTH*WIDTH; - else - f->offset[f->seek++]=0x1f00|c; -} - -// puts to FILE -void fputs(FILE*f,char*s) -{ - for(uint32_t i=0;s[i];++i) - //*f->offset++=0x1f00|s[i]; - fputc(s[i],f); - fputc('\n',f); -} - -// print to FILE -void fprint(FILE*f,char*s) -{ - for(uint32_t i=0;s[i];++i) - fputc(s[i],f); -} - -// print integer -void fprinti(FILE*f,int32_t d) -{ - char b[32]; - int32_t i=0; - - if(d<0) - { - fprint(f,"-"); - d=-d; - } - - // Get each digit as character - while(d>0) - { - int32_t m=d%10; - d/=10; - b[i++]=m+'0'; - } - b[i]=0; - - // Print reversed string - for(;i>=0;--i) - if(b[i]>31) - fputc(b[i],f); -} - -// print integer (hex) -void fprinti16(FILE*f,uint32_t d) -{ - static char g[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; - static char b[32]; - int32_t i=0; - - fprint(f,"0x"); - - // Get each digit as character - while(d>0) - { - uint32_t m=d%16; - d/=16; - b[i++]=g[m]; - } - b[i]=0; - - // Print reversed string - for(;i>=0;--i) - if(b[i]>31) - fputc(b[i],f); -} diff --git a/stdio.h b/stdio.h deleted file mode 100644 index 510dbef..0000000 --- a/stdio.h +++ /dev/null @@ -1,32 +0,0 @@ -/**** - * Tiny standard C library - * subset implementation - ****/ - -#pragma once - -#include"stdint.h" - -#define SPACE " " -#define WIDTH 80 - -// FILE type -typedef struct FILE -{ - uint32_t fd; - uint16_t*offset; - uint32_t seek; -} FILE; - -extern FILE*stdout; - -void fprint(FILE*f,char*s); -void fprinti(FILE*f,int32_t d); -void fprinti16(FILE*f,uint32_t d); -void fputc(char c,FILE*f); -void fputs(FILE*f,char*s); - -#define print(x) fprint(stdout,x) -#define printi(x) fprinti(stdout,x) -#define printi16(x) fprinti16(stdout,x) -#define puts(x) fputs(stdout,x) diff --git a/string.h b/string.h deleted file mode 100644 index 670febe..0000000 --- a/string.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include"stdint.h" - -void*memset(void*dst,uint8_t val,size_t count) -{ - for(uint32_t i=0;i