docs: preparation de la compilation de programmes en USER MODE (ring 3), ajout documentation API et librairies
This commit is contained in:
parent
ac537030a3
commit
f0f36a0f5c
|
@ -0,0 +1,15 @@
|
|||
## Liste des API
|
||||
|
||||
Bibliothèques disponibles dans COS2000
|
||||
|
||||
### libc
|
||||
|
||||
Fonctions disponibles dans la librairie "libc"
|
||||
|
||||
#### test_api
|
||||
|
||||
u32 test_api(void);
|
||||
|
||||
syscall id : 0
|
||||
arguments : 0
|
||||
résultat : oui (0x66666666)
|
|
@ -85,7 +85,7 @@
|
|||
/* OS identification */
|
||||
#define ELFOSABI_NONE 0 //No extensions or unspecified
|
||||
#define ELFOSABI_LINUX 3 //Linux
|
||||
#define ELFOSABI_COS2000 15 //COS2000
|
||||
#define ELFOSABI_COS2000 16 //COS2000
|
||||
|
||||
/* ELF header */
|
||||
typedef struct elf32 {
|
||||
|
|
|
@ -5,13 +5,6 @@
|
|||
#define sysexit() asm volatile ("sysexit"::);
|
||||
|
||||
|
||||
#define inb(port) ({ \
|
||||
u8 _v; \
|
||||
asm volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
|
||||
_v; \
|
||||
})
|
||||
|
||||
|
||||
#define syscall0(syscall) ({ \
|
||||
u32 _v; \
|
||||
asm volatile (\
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F pe-i386 -I ../include
|
||||
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F elf_i386 -I ../include
|
||||
LINK=ld -m elf_i386 -r -o
|
||||
SRCS= $(wildcard *.c)
|
||||
OBJS= $(SRCS:.c=.o)
|
||||
|
|
|
@ -14,7 +14,7 @@ u32 lastpid;
|
|||
|
||||
u8 elf_errors1[]="Aucune signature ELF";
|
||||
u8 elf_errors2[]="Fichier au format ELF mais non 32 bits";
|
||||
u8 elf_errors3[]="ELF non MSB";
|
||||
u8 elf_errors3[]="ELF non LSB";
|
||||
u8 elf_errors4[]="ELF mauvaise version";
|
||||
u8 elf_errors5[]="ELF pour OS ne correspondant pas";
|
||||
u8 elf_errors6[]="Mauvais type de machine";
|
||||
|
@ -37,8 +37,6 @@ u32 elf_test(u8 *src)
|
|||
&& header->e_ident[EI_MAG2] == ELFMAG2 && header->e_ident[EI_MAG3] == ELFMAG3)
|
||||
{
|
||||
if (header->e_ident[EI_CLASS]!=ELFCLASS32)
|
||||
return 1;
|
||||
if (header->e_ident[EI_DATA]!=ELFDATA2LSB)
|
||||
return 2;
|
||||
if (header->e_ident[EI_DATA]!=ELFDATA2LSB)
|
||||
return 3;
|
||||
|
|
33
makefile
33
makefile
|
@ -1,4 +1,4 @@
|
|||
all: bits32 bits64 harddisk uefi
|
||||
all: programs bits32 bits64 harddisk uefi
|
||||
sync
|
||||
|
||||
bits32: ARCH=bits32
|
||||
|
@ -9,6 +9,11 @@ bits64: ARCH=bits64
|
|||
bits64: lib/libs.o system/system.sys
|
||||
sync
|
||||
|
||||
programs: programs/test
|
||||
|
||||
programs/test:
|
||||
make -C programs
|
||||
|
||||
harddisk: final/harddisk.img.final
|
||||
|
||||
uefi: final/harddiskuefi.img.final
|
||||
|
@ -17,20 +22,22 @@ install:
|
|||
(sudo apt-get install nasm gcc qemu fusefat fuseext2 cgdb ovmf bsdmainutils tar bsdmainutils indent binutils bochs bochs-x bochsbios)
|
||||
|
||||
clean:
|
||||
(cd system; make clean)
|
||||
(cd lib;make clean)
|
||||
(cd final;make clean)
|
||||
make -C system clean
|
||||
make -C lib clean
|
||||
make -C final clean
|
||||
make -C programs clean
|
||||
sync
|
||||
|
||||
littleclean:
|
||||
(cd system; make clean)
|
||||
(cd lib;make clean)
|
||||
(cd final;make littleclean)
|
||||
make -C system clean
|
||||
make -C lib clean
|
||||
make -C final littleclean)
|
||||
make -C programs clean
|
||||
sync
|
||||
|
||||
indent:
|
||||
(cd system; make indent)
|
||||
(cd lib;make indent)
|
||||
make -C system indent
|
||||
make -C lib indent
|
||||
sync
|
||||
|
||||
backup: clean
|
||||
|
@ -85,13 +92,13 @@ qemu64:
|
|||
(killall qemu-system-x86_64;qemu-system-x86_64 -m 5G -drive format=raw,file=./final/harddiskuefi.img.final --bios /usr/share/qemu/OVMF.fd --enable-kvm -cpu host -s &)
|
||||
|
||||
system/system.sys:
|
||||
(cd system; VESA=$(VESA) make)
|
||||
make -C system VESA=$(VESA)
|
||||
|
||||
final/harddisk.img.final:
|
||||
(cd final; make harddisk.img.final)
|
||||
make -C final harddisk.img.final
|
||||
|
||||
final/harddiskuefi.img.final:
|
||||
(cd final; make harddiskuefi.img.final)
|
||||
make -C final harddiskuefi.img.final
|
||||
|
||||
lib/libs.o:
|
||||
(cd lib; make)
|
||||
make -C lib
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#include "types.h";
|
||||
|
||||
u32 test_api(void);
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#define syscall0(syscall) ({ \
|
||||
u32 _v; \
|
||||
asm volatile (\
|
||||
"mov %%esp,%%ecx;\
|
||||
mov $1f,%%edx;\
|
||||
sysenter;\
|
||||
1:" : "=a" (_v) : "a" (syscall): "ecx","edx","memory"); \
|
||||
_v; \
|
||||
})
|
||||
|
||||
#define syscall1(syscall,arg1) ({ \
|
||||
u32 _v; \
|
||||
asm volatile (\
|
||||
"mov %%esp,%%ecx;\
|
||||
mov $1f,%%edx;\
|
||||
sysenter;\
|
||||
1:" : "=a" (_v) : "a" (syscall), "b" (arg1) : "ecx","edx","memory"); \
|
||||
_v; \
|
||||
})
|
||||
|
||||
#define syscall2(syscall,arg1,arg2) ({ \
|
||||
u32 _v; \
|
||||
asm volatile (\
|
||||
"mov %%esp,%%ecx;\
|
||||
mov $1f,%%edx;\
|
||||
sysenter;\
|
||||
1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2) : "ecx","edx","memory"); \
|
||||
_v; \
|
||||
})
|
||||
|
||||
#define syscall3(syscall,arg1,arg2,arg3) ({ \
|
||||
u32 _v; \
|
||||
asm volatile (\
|
||||
"mov %%esp,%%ecx;\
|
||||
mov $1f,%%edx;\
|
||||
sysenter;\
|
||||
1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory"); \
|
||||
_v; \
|
||||
})
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
#ifndef ALLTYPES
|
||||
# define ALLTYPES
|
||||
|
||||
typedef char int8;
|
||||
typedef short int16;
|
||||
typedef int int32;
|
||||
typedef long long int64;
|
||||
|
||||
typedef char BYTE;
|
||||
typedef short WORD;
|
||||
typedef long DWORD;
|
||||
typedef long long QWORD;
|
||||
|
||||
typedef signed char SBYTE;
|
||||
typedef signed short SWORD;
|
||||
typedef signed long SDWORD;
|
||||
typedef signed long long SQWORD;
|
||||
|
||||
typedef unsigned char UBYTE;
|
||||
typedef unsigned short UWORD;
|
||||
typedef unsigned long UDWORD;
|
||||
typedef unsigned long long UQWORD;
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long int u64;
|
||||
typedef char s8;
|
||||
typedef short s16;
|
||||
typedef int s32;
|
||||
typedef long int s64;
|
||||
typedef int bool;
|
||||
|
||||
extern char ctype[];
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
#define NULL 0x0000
|
||||
|
||||
#define CT_UP 0x01 /* upper case */
|
||||
#define CT_LOW 0x02 /* lower case */
|
||||
#define CT_DIG 0x04 /* digit */
|
||||
#define CT_CTL 0x08 /* control */
|
||||
#define CT_PUN 0x10 /* punctuation */
|
||||
#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */
|
||||
#define CT_HEX 0x40 /* hex digit */
|
||||
#define CT_SP 0x80 /* hard space (0x20) */
|
||||
|
||||
/* without the cast to unsigned, DJGPP complains (using -Wall) */
|
||||
#define isalnum(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG))
|
||||
#define isalpha(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW))
|
||||
#define iscntrl(c) ((ctype + 1)[(unsigned)(c)] & (CT_CTL))
|
||||
#define isdigit(c) ((ctype + 1)[(unsigned)(c)] & (CT_DIG))
|
||||
#define isgraph(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG))
|
||||
#define islower(c) ((ctype + 1)[(unsigned)(c)] & (CT_LOW))
|
||||
#define isprint(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP))
|
||||
#define ispunct(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN))
|
||||
#define isspace(c) ((ctype + 1)[(unsigned)(c)] & (CT_WHT))
|
||||
#define isupper(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP))
|
||||
#define isxdigit(c) ((ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX))
|
||||
#define isascii(c) ((unsigned)(c) <= 0x7F)
|
||||
#define toascii(c) ((unsigned)(c) & 0x7F)
|
||||
|
||||
#define tolower(c) (isupper(c) ? c + 'a' - 'A' : c)
|
||||
#define toupper(c) (islower(c) ? c + 'A' - 'a' : c)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#include "libc.h";
|
||||
#include "syscall.h";
|
||||
#include "types.h";
|
||||
|
||||
u32 test_api(void)
|
||||
{
|
||||
syscall0(0x0);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F elf-i386 -I ../include
|
||||
LINK=ld -m elf_i386 -r -o
|
||||
SRCS= $(wildcard *.c)
|
||||
OBJS= $(SRCS:.c=.o)
|
||||
ARCH=ar rcs
|
||||
|
||||
all: makeall
|
||||
|
||||
makeall: libs.a
|
||||
|
||||
libs.a:libs.o
|
||||
$(ARCH) $@ $^
|
||||
|
||||
libs.o:$(OBJS)
|
||||
$(LINK) libs.o $(OBJS)
|
||||
|
||||
.o: .c
|
||||
$(CC) $^
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.c~
|
||||
rm -f *.a
|
||||
|
||||
indent:
|
||||
indent -linux -i8 -ts8 *.c
|
|
@ -0,0 +1,12 @@
|
|||
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
|
||||
OUTPUT_ARCH(i386)
|
||||
|
||||
ENTRY(main)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x40000000;
|
||||
.text ALIGN(16): {
|
||||
*(.text)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -I ./include -c -o
|
||||
LINK=ld -m elf_i386 -T linker.lds -n -o
|
||||
SRCS= $(wildcard *.c)
|
||||
EXECS= $(SRCS:.c=)
|
||||
|
||||
all: lib/libs.a $(EXECS)
|
||||
|
||||
lib/libs.a:
|
||||
make -C lib
|
||||
|
||||
%: %.c
|
||||
$(CC) $@.o $<
|
||||
$(LINK) $@ $@.o lib/libs.a
|
||||
chmod 644 $@
|
||||
elfedit --output-osabi FenixOS $@
|
||||
|
||||
clean:
|
||||
make -C lib clean
|
||||
rm -f *.o
|
||||
rm -f *.c~
|
||||
find . -type f ! -perm /u=x -maxdepth 1 -regex '.+/\.?[^\.]+' -exec rm {} \;
|
||||
|
||||
indent:
|
||||
indent -linux -i8 -ts8 *.c
|
|
@ -0,0 +1,11 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#include "libc.h";
|
||||
#include "types.h";
|
||||
|
||||
void main(void)
|
||||
{
|
||||
test_api();
|
||||
}
|
Loading…
Reference in New Issue