From a8ef8e497c96052eb33e77e1cffe47c34add1a41 Mon Sep 17 00:00:00 2001 From: MathNosseb Date: Tue, 30 Jun 2026 01:49:45 +0200 Subject: [PATCH] modif de la gestion des affichages d aide des programmes --- kernel/app/programs.c | 2 +- kernel/app/programs.h | 2 +- kernel/app/shell.c | 110 +++++++++++++++++++++++++++++++++++++++--- kernel/app/shell.h | 1 + kernel/sys/struct.c | 10 ++++ kernel/sys/struct.h | 1 + run.sh | 2 +- 7 files changed, 119 insertions(+), 9 deletions(-) diff --git a/kernel/app/programs.c b/kernel/app/programs.c index 5f099c4..e092ae8 100644 --- a/kernel/app/programs.c +++ b/kernel/app/programs.c @@ -59,7 +59,7 @@ void load_program(void *adr, int size) } -void run_program(void *adr, int size) +void run_program(void *adr) { char pointeur[11]; int_to_char((uint32_t)adr, pointeur); diff --git a/kernel/app/programs.h b/kernel/app/programs.h index eec21aa..9d7b05a 100644 --- a/kernel/app/programs.h +++ b/kernel/app/programs.h @@ -6,4 +6,4 @@ #include "../mem/mem.h" void load_program(void *adr, int size); -void run_program(void *adr, int size); +void run_program(void *adr); diff --git a/kernel/app/shell.c b/kernel/app/shell.c index 43c1a07..a468747 100644 --- a/kernel/app/shell.c +++ b/kernel/app/shell.c @@ -1,6 +1,7 @@ #include "shell.h" #include "../mem/mem.h" #include "../sys/hex.h" +#include "../sys/struct.h" #include "../disque/disk.h" #include "programs.h" @@ -22,6 +23,20 @@ void detect_command() int reconnu = 0; + if (compare_word_buff("man", argv[0])) + { + reconnu = 1; + free(argv); + vga_putchar("\n"); + system_functions_descriptions(argc, argv); + return; + } + if (compare_word_buff("shutdown", argv[0])) + { + outw(0x604, 0x2000);//qemu + outw(0x4004, 0x3400);//virtualbox + } + if (compare_word_buff("clear", argv[0])) { clear_screen(); @@ -87,7 +102,7 @@ void detect_command() //affiche les ressources de l'ordinateur //les ressources - uint64_t total_mem = (get_total_ram()/1024/1024); + uint64_t total_mem = (get_total_ram()); int heap_mem = get_heap_ram_usage(); int stack_mem = get_stack_ram_usage(); int heap_total_mem = get_heap_ram_usage_and_non_use(); @@ -127,20 +142,18 @@ void detect_command() load_program((uint32_t *)hex_to_int(argv[1]), char_to_int(argv[2])); free(argv); reconnu = 1; - - } if (compare_word_buff("run", argv[0])) { - if (argc < 3) + if (argc < 2) { free(argv); return; } //recuperer l adresse vga_putchar("\n"); - run_program((uint32_t *)hex_to_int(argv[1]), char_to_int(argv[2])); + run_program((uint32_t *)hex_to_int(argv[1])); free(argv); reconnu = 1; @@ -149,7 +162,7 @@ void detect_command() if (compare_word_buff("ata", argv[0])) { if (argc < 5) - { + { free(argv); return; } @@ -220,4 +233,89 @@ char *del_prefix(char *buffer) return &buffer[i]; +} + +/// @brief detail les commandes -> commande man +/// @param argv la commande split en liste de mots +void system_functions_descriptions(int argc, char **argv) +{ + if (argc >= 2) + { + //demande le detail d'une fonction + if (compare_word_buff("man", argv[1])) + { + vga_putchar("INCEPTION\n"); + vga_putchar("affiche les details d'une fonction systeme\n"); + } + else if (compare_word_buff("clear", argv[1])) + { + vga_putchar("efface l'ecran\n"); + }else if(compare_word_buff("info", argv[1])) + { + vga_putchar("affiche les infos systeme\n"); + }else if(compare_word_buff("echo", argv[1])) + { + vga_putchar("affiche du texte a l'ecran\n"); + vga_putchar("les parametres sont tous affiches\n"); + }else if(compare_word_buff("allocate", argv[1])) + { + vga_putchar("alloue une certaine quantite de memoire en octet dans la heap\n"); + vga_putchar("prend un parametre qui est un nombre en octet\n"); + vga_putchar("affiche \"done\" quand il a fini\n"); + }else if(compare_word_buff("allocate", argv[1])) + { + vga_putchar("reserve une quantite de memoire dans la heap\n"); + vga_putchar("prend en parametre la quantite en octet de ram a allouer\n"); + }else if(compare_word_buff("free", argv[1])) + { + vga_putchar("libere la ram alloue avec allocate\n"); + vga_putchar("prend l adresse de la donnee\n"); + }else if(compare_word_buff("dump", argv[1])) + { + vga_putchar("affiche les blocs memoire alloue libre ou non\n"); + vga_putchar("permet de connaitre l'adresse des blocs\n"); + }else if(compare_word_buff("monitor", argv[1])) + { + vga_putchar("affiche les ressources de l'ordinateur\n"); + }else if(compare_word_buff("load", argv[1])) + { + vga_putchar("charge depuis le primary disque dans la heap\n"); + vga_putchar("1er parametre: adresse sur le disque"); + vga_putchar("2eme parametre: taille de la donnee en octet"); + vga_putchar("affiche l'adresse dansizes la heap du debut de la donnee\n"); + vga_putchar("affiche en hexadecimal les donnees stockes\n"); + }else if(compare_word_buff("run", argv[1])) + { + vga_putchar("lance un programme qui se trouve dans la heap\n"); + vga_putchar("1er parametre: adresse du programme dans la heap\n"); + vga_putchar("saute au programme comme une fonction standart\n"); + }else if(compare_word_buff("ata", argv[1])) + { + vga_putchar("affiche des donnees dans le disque / les charges dans la ram\n"); + vga_putchar("1er param -> read or load\n"); + vga_putchar("2eme param -> numero du disque (1 pour le slave et 0 pour le primaire)\n"); + vga_putchar("3eme param -> adresse lba\n"); + vga_putchar("4eme param -> quantite de secteur a lire ou charger\n"); + }else if(compare_word_buff("shutdown", argv[1])){ + vga_putchar("eteint l'ordinateur\n"); + vga_putchar("fonctionne sur VirtualBox et Qemu\n"); + }else{ + vga_putchar("la commande n'existe pas\n"); + } + }else{ + //detail de toutes les fonctions systèmes + vga_putchar("man -> donne les details des programmes\n"); + vga_putchar("clear -> efface l'ecran\n"); + vga_putchar("info -> infos systeme\n"); + vga_putchar("echo -> affiche du texte\n"); + vga_putchar("allocate -> alloue de la memoire\n"); + vga_putchar("free -> libere de la memoire\n"); + vga_putchar("dump -> affiche le contenu de la memoire\n"); + vga_putchar("monitor -> affiche les ressources\n"); + vga_putchar("load -> charge depuis le primary disque dans la heap\n"); + vga_putchar("run -> lance un programme situe dans la ram\n"); + vga_putchar("ata -> lit un disque ou charge un disque en memoire\n"); + vga_putchar("shutdown -> arret de l'ordinateur\n"); + } + } \ No newline at end of file diff --git a/kernel/app/shell.h b/kernel/app/shell.h index 3454de2..d67ecae 100644 --- a/kernel/app/shell.h +++ b/kernel/app/shell.h @@ -8,3 +8,4 @@ void detect_command(); int compare_word_buff(char *, char *); int compare_first_word_buffer(char *, char *); char *del_prefix(char *); +void system_functions_descriptions(int argc, char **argv); diff --git a/kernel/sys/struct.c b/kernel/sys/struct.c index 14deea0..1b1506d 100644 --- a/kernel/sys/struct.c +++ b/kernel/sys/struct.c @@ -8,6 +8,16 @@ void outb(uint16_t port, uint8_t val) * The outb %al, %dx encoding is the only option for all other cases. * %1 expands to %dx because port is a uint16_t. %w1 could be used if we had the port number a wider C type */ } + +void outw(uint16_t port, uint16_t value) +{ + __asm__ volatile ( + "outw %0, %1" + : + : "a"(value), "Nd"(port) + ); +} + uint8_t inb(uint16_t port) { uint8_t ret; diff --git a/kernel/sys/struct.h b/kernel/sys/struct.h index 03d14aa..4d9833f 100644 --- a/kernel/sys/struct.h +++ b/kernel/sys/struct.h @@ -10,5 +10,6 @@ typedef signed long int32_t; typedef signed long long int64_t; void outb(uint16_t, uint8_t); +void outw(uint16_t port, uint16_t value); uint8_t inb(uint16_t); uint16_t inw(uint16_t port); \ No newline at end of file diff --git a/run.sh b/run.sh index ac77cd9..10f48ad 100755 --- a/run.sh +++ b/run.sh @@ -70,7 +70,7 @@ xxd Binaries/os.bin > os.hex qemu-system-x86_64 \ -enable-kvm -cpu host \ - -m 1G \ + -m 2M \ -monitor stdio \ -drive format=raw,file=Binaries/os.bin \ -drive format=raw,file=disk.bin,if=ide \ No newline at end of file