From 5b300cb7fd35d60ae6e8edea76f8e74c63b7a417 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 18:45:53 +0100 Subject: [PATCH 01/17] Temporary disable of clean registers code --- micro_kernel/interrupts.asm | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/micro_kernel/interrupts.asm b/micro_kernel/interrupts.asm index 5964e393..9544223b 100644 --- a/micro_kernel/interrupts.asm +++ b/micro_kernel/interrupts.asm @@ -111,36 +111,20 @@ _isr%1: %macro CREATE_IRQ 1 _irq%1: + push rax + ; Disable interruptions to avoid being interrupted cli - push rax - mov rax, [irq_handlers + 8 *%1] ; If there are no handler, just send EOI test rax, rax je .eoi - push rbx - push rcx - push rdx - push rsi - push rdi - push r8 - push r9 - ; Call the handler call rax - push r9 - push r8 - pop rdi - pop rsi - pop rdx - pop rcx - pop rbx - .eoi: mov rax, %1 ; IRQ number From 551dd10dc22a5472706a86d2f95f858a8ad9fcca Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 19:06:03 +0100 Subject: [PATCH 02/17] Rewrite the keyboard driver much more properly --- kernel/include/keyboard.hpp | 9 +++++ kernel/src/kernel.cpp | 2 + kernel/src/keyboard.cpp | 45 ++++++++++++++++++++++- kernel/src/shell.cpp | 73 ++++++++++++++++++------------------- 4 files changed, 91 insertions(+), 38 deletions(-) diff --git a/kernel/include/keyboard.hpp b/kernel/include/keyboard.hpp index 76b7bfc2..8532b6e1 100644 --- a/kernel/include/keyboard.hpp +++ b/kernel/include/keyboard.hpp @@ -3,6 +3,15 @@ #include "types.hpp" +namespace keyboard { + +const char KEY_ENTER = 0x1C; +const char KEY_BACKSPACE = 0x0E; + +void install_driver(); +char get_char(); char key_to_ascii(uint8_t key); +} + #endif diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 71e8f888..6c8b5c22 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,6 +1,7 @@ #include "memory.hpp" #include "timer.hpp" #include "shell.hpp" +#include "keyboard.hpp" extern "C" { @@ -8,6 +9,7 @@ void __attribute__ ((section ("main_section"))) kernel_main(){ load_memory_map(); init_memory_manager(); install_timer(); + keyboard::install_driver(); init_shell(); return; diff --git a/kernel/src/keyboard.cpp b/kernel/src/keyboard.cpp index 586a9031..87ff9a04 100644 --- a/kernel/src/keyboard.cpp +++ b/kernel/src/keyboard.cpp @@ -1,4 +1,5 @@ #include "keyboard.hpp" +#include "kernel_utils.hpp" namespace { @@ -42,8 +43,50 @@ char qwertz[128] = 0, /* All other keys are undefined */ }; +const uint8_t BUFFER_SIZE = 64; + +char input_buffer[BUFFER_SIZE]; +volatile uint8_t start; +volatile uint8_t count; + +void keyboard_handler(){ + auto key = static_cast(in_byte(0x60)); + + if(count == BUFFER_SIZE){ + //The buffer is full, we loose the characters + } else { + auto end = (start + count) % BUFFER_SIZE; + input_buffer[end] = key; + ++count; + } } -char key_to_ascii(uint8_t key){ +} + +void keyboard::install_driver(){ + register_irq_handler<1>(keyboard_handler); + + start = 0; + count = 0; +} + +char keyboard::get_char(){ + //Wait for the buffer to contains something + while(count == 0){ + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + __asm__ __volatile__ ("nop"); + } + + auto key = input_buffer[start]; + start = (start + 1) % BUFFER_SIZE; + --count; + + return key; +} + +char keyboard::key_to_ascii(uint8_t key){ return qwertz[key]; } diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index fc99ffd0..cf17ad31 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -46,45 +46,44 @@ char current_input[50]; void exec_command(); -#define KEY_ENTER 0x1C -#define KEY_BACKSPACE 0x0E +void start_shell(){ + while(true){ + auto key = keyboard::get_char(); -void keyboard_handler(){ - uint8_t key = in_byte(0x60); - - if(key & 0x80){ - //TODO Handle shift - } else { - if(key == KEY_ENTER){ - current_input[current_input_length] = '\0'; - - k_print_line(); - - exec_command(); - - if(get_column() != 0){ - set_column(0); - set_line(get_line() + 1); - } - - current_input_length = 0; - - k_print("thor> "); - } else if(key == KEY_BACKSPACE){ - if(current_input_length > 0){ - set_column(get_column() - 1); - k_print(' '); - set_column(get_column() - 1); - - --current_input_length; - } + if(key & 0x80){ + //TODO Handle shift } else { - auto qwertz_key = key_to_ascii(key); + if(key == keyboard::KEY_ENTER){ + current_input[current_input_length] = '\0'; - if(qwertz_key > 0){ - current_input[current_input_length++] = qwertz_key; - k_print(qwertz_key); - } + k_print_line(); + + exec_command(); + + if(get_column() != 0){ + set_column(0); + set_line(get_line() + 1); + } + + current_input_length = 0; + + k_print("thor> "); + } else if(key == keyboard::KEY_BACKSPACE){ + if(current_input_length > 0){ + set_column(get_column() - 1); + k_print(' '); + set_column(get_column() - 1); + + --current_input_length; + } + } else { + auto qwertz_key = keyboard::key_to_ascii(key); + + if(qwertz_key > 0){ + current_input[current_input_length++] = qwertz_key; + k_print(qwertz_key); + } + } } } } @@ -291,5 +290,5 @@ void init_shell(){ k_print("thor> "); - register_irq_handler<1>(keyboard_handler); + start_shell(); } From ed91c5ce5ab18ddf909386ce5845074049a2ddd7 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 19:14:42 +0100 Subject: [PATCH 03/17] Fix interruptions --- micro_kernel/interrupts.asm | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/micro_kernel/interrupts.asm b/micro_kernel/interrupts.asm index 9544223b..baf4419b 100644 --- a/micro_kernel/interrupts.asm +++ b/micro_kernel/interrupts.asm @@ -111,20 +111,40 @@ _isr%1: %macro CREATE_IRQ 1 _irq%1: - push rax - ; Disable interruptions to avoid being interrupted cli + push rax + mov rax, [irq_handlers + 8 *%1] ; If there are no handler, just send EOI test rax, rax je .eoi + push rax + push rcx + push rdx + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + ; Call the handler call rax + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rdx + pop rcx + pop rax + .eoi: mov rax, %1 ; IRQ number From a2a461f74c39c2ceec31efb1070dabeac1dd2a00 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 19:56:08 +0100 Subject: [PATCH 04/17] Cleanup --- kernel/src/shell.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index cf17ad31..43fca38d 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -255,20 +255,6 @@ void memory_command(const char*){ k_printf("Total used memory: %m\n", used_memory()); k_printf("Total free memory: %m\n", free_memory()); } - - uint16_t* buffer = reinterpret_cast(k_malloc(512)); - - if(!ata_read_sectors(drive(0), 2048, 1, buffer)){ - k_print_line("Read failed"); - } else { - for(int i = 0; i < 80; i += 8){ - k_printf("%.4h %.4h %.4h %.4h %.4h %.4h %.4h %.4h\n", - (uint64_t) buffer[i+0], (uint64_t) buffer[i+1], (uint64_t) buffer[i+2], (uint64_t) buffer[i+3], - (uint64_t) buffer[i+4], (uint64_t) buffer[i+5], (uint64_t) buffer[i+6], (uint64_t) buffer[i+7]); - } - - k_free(reinterpret_cast(buffer)); - } } void disks_command(const char*){ From 3f3b388d616c1f80ad2900c9676c70f03eea2146 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 19:56:18 +0100 Subject: [PATCH 05/17] Fix e820 mmap --- kernel/src/memory.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/src/memory.cpp b/kernel/src/memory.cpp index 9cc97ab6..7b02c0d6 100644 --- a/kernel/src/memory.cpp +++ b/kernel/src/memory.cpp @@ -1,4 +1,5 @@ #include "memory.hpp" +#include "console.hpp" namespace { @@ -20,7 +21,12 @@ mmapentry e820_mmap[32]; void mmap_query(uint64_t cmd, uint64_t* result){ uint64_t tmp; - __asm__ __volatile__ ("mov r8, %0; int 62; mov %1, rax" : : "dN" (cmd), "a" (tmp)); + + __asm__ __volatile__ ("mov r8, %[port]; int 62; mov %[dst], rax" + : [dst] "=a" (tmp) + : [port] "dN" (cmd) + : "cc", "memory", "r8"); + *result = tmp; } From 08a1fc21bbbbc9b0496c5165eb5bf024fa0da543 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 20:00:19 +0100 Subject: [PATCH 06/17] Clean inline assembly --- kernel/src/kernel_utils.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/kernel/src/kernel_utils.cpp b/kernel/src/kernel_utils.cpp index 6be8ba80..4b4ffe99 100644 --- a/kernel/src/kernel_utils.cpp +++ b/kernel/src/kernel_utils.cpp @@ -2,20 +2,32 @@ uint8_t in_byte(uint16_t _port){ uint8_t rv; - __asm__ __volatile__ ("in %0, %1" : "=a" (rv) : "dN" (_port)); - return rv; -} -void out_byte (uint16_t _port, uint8_t _data){ - __asm__ __volatile__ ("out %0, %1" : : "dN" (_port), "a" (_data)); + __asm__ __volatile__ ("in %[data], %[port]" + : [data] "=a" (rv) + : [port] "dN" (_port)); + + return rv; } uint16_t in_word(uint16_t _port){ uint16_t rv; - __asm__ __volatile__ ("in %0, %1" : "=a" (rv) : "dN" (_port)); + + __asm__ __volatile__ ("in %[data], %[port]" + : [data] "=a" (rv) + : [port] "dN" (_port)); + return rv; } -void out_word(uint16_t _port, uint16_t _data){ - __asm__ __volatile__ ("out %0, %1" : : "dN" (_port), "a" (_data)); +void out_byte (uint16_t _port, uint8_t _data){ + __asm__ __volatile__ ("out %[port], %[data]" + : /* No outputs */ + : [port] "dN" (_port), [data] "a" (_data)); +} + +void out_word(uint16_t _port, uint16_t _data){ + __asm__ __volatile__ ("out %[port], %[data]" + : /* No outputs */ + : [port] "dN" (_port), [data] "a" (_data)); } From 9c9db190a8eda7ddafb4dbafd32e5a18cd3534e7 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 4 Nov 2013 20:27:52 +0100 Subject: [PATCH 07/17] Prepare ls command --- kernel/src/shell.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 43fca38d..9b0403ae 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -22,13 +22,14 @@ void echo_command(const char* params); void mmap_command(const char* params); void memory_command(const char* params); void disks_command(const char* params); +void ls_command(const char* params); struct command_definition { const char* name; void (*function)(const char*); }; -command_definition commands[10] = { +command_definition commands[11] = { {"reboot", reboot_command}, {"help", help_command}, {"uptime", uptime_command}, @@ -39,6 +40,7 @@ command_definition commands[10] = { {"mmap", mmap_command}, {"memory", memory_command}, {"disks", disks_command}, + {"ls", ls_command}, }; uint64_t current_input_length = 0; @@ -267,6 +269,22 @@ void disks_command(const char*){ } } +void ls_command(const char*){ + uint16_t* buffer = reinterpret_cast(k_malloc(512)); + + if(!ata_read_sectors(drive(0), 1, 1, buffer)){ + k_print_line("Read failed"); + } else { + for(int i = 0; i < 128; i += 8){ + k_printf("%.4h %.4h %.4h %.4h %.4h %.4h %.4h %.4h\n", + (uint64_t) buffer[i+0], (uint64_t) buffer[i+1], (uint64_t) buffer[i+2], (uint64_t) buffer[i+3], + (uint64_t) buffer[i+4], (uint64_t) buffer[i+5], (uint64_t) buffer[i+6], (uint64_t) buffer[i+7]); + } + + k_free(reinterpret_cast(buffer)); + } +} + } //end of anonymous namespace void init_shell(){ From 7ac012403008abfe5c9132bb68370b27862516e1 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 5 Nov 2013 20:00:35 +0100 Subject: [PATCH 08/17] Start implementation of the partitions commands --- kernel/Makefile | 5 +- kernel/include/ata.hpp | 6 +- kernel/include/disks.hpp | 46 +++++++++++ kernel/src/ata.cpp | 51 +++++-------- kernel/src/disks.cpp | 159 +++++++++++++++++++++++++++++++++++++++ kernel/src/shell.cpp | 47 +++++++----- 6 files changed, 261 insertions(+), 53 deletions(-) create mode 100644 kernel/include/disks.hpp create mode 100644 kernel/src/disks.cpp diff --git a/kernel/Makefile b/kernel/Makefile index b5dfc9bb..4ed3e92e 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -5,7 +5,7 @@ CPP_FLAGS=-masm=intel -Iinclude/ -nostdlib -O1 -std=c++11 -fno-exceptions -fno-r KERNEL_FLAGS=$(CPP_FLAGS) KERNEL_LINK_FLAGS=-lgcc -T linker.ld $(CPP_FLAGS) -KERNEL_O_FILES=kernel.o keyboard.o console.o kernel_utils.o timer.o shell.o utils.o memory.o ata.o thor.o +KERNEL_O_FILES=kernel.o keyboard.o console.o kernel_utils.o timer.o shell.o utils.o memory.o ata.o thor.o disks.o CRTBEGIN_OBJ:=$(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o) CRTEND_OBJ:=$(shell $(CC) $(CFLAGS) -print-file-name=crtend.o) @@ -47,6 +47,9 @@ ata.o: src/ata.cpp thor.o: src/thor.cpp $(CC) $(KERNEL_FLAGS) -c src/thor.cpp -o thor.o +disks.o: src/disks.cpp + $(CC) $(KERNEL_FLAGS) -c src/disks.cpp -o disks.o + clean: rm -f *.o rm -f *.bin diff --git a/kernel/include/ata.hpp b/kernel/include/ata.hpp index d50056cf..b57de4bb 100644 --- a/kernel/include/ata.hpp +++ b/kernel/include/ata.hpp @@ -3,6 +3,8 @@ #include "types.hpp" +namespace ata { + struct drive_descriptor { uint16_t controller; uint8_t drive; @@ -14,6 +16,8 @@ void detect_disks(); uint8_t number_of_disks(); drive_descriptor& drive(uint8_t disk); -bool ata_read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination); +bool read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination); + +} #endif diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp new file mode 100644 index 00000000..1cb92d08 --- /dev/null +++ b/kernel/include/disks.hpp @@ -0,0 +1,46 @@ +#ifndef DISKS_H +#define DISKS_H + +#include "types.hpp" + +namespace disks { + +enum class disk_type { + ATA +}; + +struct disk_descriptor { + uint64_t uuid; + disk_type type; + void* descriptor; +}; + +enum class partition_type { + FAT32, + UNKNOWN +}; + +struct partition_descriptor { + uint64_t uuid; + partition_type type; + uint64_t start; + uint64_t sectors; +}; + +uint64_t detected_disks(); + +bool disk_exists(uint64_t uuid); + +const disk_descriptor& disk_by_index(uint64_t index); +const disk_descriptor& disk_by_uuid(uint64_t uuid); + +const char* disk_type_to_string(disk_type type); +const char* partition_type_to_string(partition_type type); + +bool read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination); + +partition_descriptor* partitions(const disk_descriptor& disk); + +} + +#endif diff --git a/kernel/src/ata.cpp b/kernel/src/ata.cpp index cbc78bb8..1421f722 100644 --- a/kernel/src/ata.cpp +++ b/kernel/src/ata.cpp @@ -37,8 +37,7 @@ namespace { #define MASTER_BIT 0 #define SLAVE_BIT 1 -bool detected = false; -drive_descriptor* drives; +ata::drive_descriptor* drives; volatile bool primary_invoked = false; volatile bool secondary_invoked = false; @@ -88,7 +87,7 @@ static uint8_t wait_for_controller(uint16_t controller, uint8_t mask, uint8_t va return timeout; } -bool select_device(drive_descriptor& drive){ +bool select_device(ata::drive_descriptor& drive){ auto controller = drive.controller; if(in_byte(controller + ATA_STATUS) & (ATA_STATUS_BSY | ATA_STATUS_DRQ)){ @@ -107,47 +106,35 @@ bool select_device(drive_descriptor& drive){ } //end of anonymous namespace -void detect_disks(){ - if(!detected){ - drives = reinterpret_cast(k_malloc(4 * sizeof(drive_descriptor))); +void ata::detect_disks(){ + drives = reinterpret_cast(k_malloc(4 * sizeof(drive_descriptor))); - drives[0] = {ATA_PRIMARY, 0xE0, false, MASTER_BIT}; - drives[1] = {ATA_PRIMARY, 0xF0, false, SLAVE_BIT}; - drives[2] = {ATA_SECONDARY, 0xE0, false, MASTER_BIT}; - drives[3] = {ATA_SECONDARY, 0xF0, false, SLAVE_BIT}; + drives[0] = {ATA_PRIMARY, 0xE0, false, MASTER_BIT}; + drives[1] = {ATA_PRIMARY, 0xF0, false, SLAVE_BIT}; + drives[2] = {ATA_SECONDARY, 0xE0, false, MASTER_BIT}; + drives[3] = {ATA_SECONDARY, 0xF0, false, SLAVE_BIT}; - for(uint8_t i = 0; i < 4; ++i){ - auto& drive = drives[i]; + for(uint8_t i = 0; i < 4; ++i){ + auto& drive = drives[i]; - out_byte(drive.controller + 0x6, drive.drive); - sleep_ms(4); - drive.present = in_byte(drive.controller + 0x7) & 0x40; - } - - register_irq_handler<14>(primary_controller_handler); - register_irq_handler<15>(secondary_controller_handler); - - detected = true; + out_byte(drive.controller + 0x6, drive.drive); + sleep_ms(4); + drive.present = in_byte(drive.controller + 0x7) & 0x40; } + + register_irq_handler<14>(primary_controller_handler); + register_irq_handler<15>(secondary_controller_handler); } -uint8_t number_of_disks(){ - if(!detected){ - detect_disks(); - } - +uint8_t ata::number_of_disks(){ return 4; } -drive_descriptor& drive(uint8_t disk){ - if(!detected){ - detect_disks(); - } - +ata::drive_descriptor& ata::drive(uint8_t disk){ return drives[disk]; } -bool ata_read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination){ +bool ata::read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination){ //Select the device if(!select_device(drive)){ return false; diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp new file mode 100644 index 00000000..3b23e236 --- /dev/null +++ b/kernel/src/disks.cpp @@ -0,0 +1,159 @@ +#include "disks.hpp" +#include "ata.hpp" +#include "thor.hpp" +#include "console.hpp" + +namespace { + +bool detected = false; + +//For now, 4 is enough as only the ata driver is implemented +disks::disk_descriptor _disks[4]; +uint64_t number_of_disks = 0; + +void detect_disks(){ + ata::detect_disks(); + + for(uint8_t i = 0; i < ata::number_of_disks(); ++i){ + auto& descriptor = ata::drive(i); + + if(descriptor.present){ + _disks[number_of_disks] = {number_of_disks, disks::disk_type::ATA, &descriptor}; + ++number_of_disks; + } + } + + detected = true; +} + +struct partition_descriptor_t { + uint8_t boot_flag; + uint8_t chs_begin[3]; + uint8_t type_code; + uint8_t chs_end[3]; + uint32_t lba_begin; + uint32_t sectors; +} __attribute__ ((packed)); + +static_assert(sizeof(partition_descriptor_t) == 16, "A partition descriptor is 16 bytes long"); + +struct boot_record_t { + uint8_t boot_code[446]; + partition_descriptor_t partitions[4]; + uint16_t signature; +} __attribute__ ((packed)); + +static_assert(sizeof(boot_record_t) == 512, "The boot record is 512 bytes long"); + +} //end of anonymous namespace + +uint64_t disks::detected_disks(){ + if(!detected){ + detect_disks(); + } + + return number_of_disks; +} + +const disks::disk_descriptor& disks::disk_by_index(uint64_t index){ + return _disks[index]; +} + +const disks::disk_descriptor& disks::disk_by_uuid(uint64_t uuid){ + for(uint64_t i = 0; i < number_of_disks; ++i){ + if(_disks[i].uuid == uuid){ + return _disks[i]; + } + } + + //Unreachable +} + +bool disks::disk_exists(uint64_t uuid){ + for(uint64_t i = 0; i < number_of_disks; ++i){ + if(_disks[i].uuid == uuid){ + return true; + } + } + + return false; +} + +const char* disks::disk_type_to_string(disk_type type){ + switch(type){ + case disk_type::ATA: + return "ATA"; + default: + return "Invalid Type"; + } +} + +const char* disks::partition_type_to_string(partition_type type){ + switch(type){ + case partition_type::FAT32: + return "FAT32"; + case partition_type::UNKNOWN: + return "Unknown"; + default: + return "Invalid Type"; + } +} + +bool disks::read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination){ + switch(disk.type){ + case disk_type::ATA: + return ata::read_sectors(*static_cast(disk.descriptor), start, count, destination); + + default: + return false; + } +} + +disks::partition_descriptor* disks::partitions(const disk_descriptor& disk){ + //TODO Can be leaked + uint16_t* buffer = reinterpret_cast(k_malloc(512)); + + if(!read_sectors(disk, 0, 1, buffer)){ + k_print_line("Read Boot Record failed"); + + return nullptr; + } else { + auto* boot_record = reinterpret_cast(buffer); + + if(boot_record->signature != 0xAA55){ + k_print_line("Invalid boot record signature"); + + return nullptr; + } + + uint64_t n = 0; + for(int i = 0; i < 4; ++i){ + if(boot_record->partitions[i].type_code > 0){ + ++n; + } + } + + //TODO: This is a memory leak, partitions should be cached + auto* partitions = reinterpret_cast(k_malloc(n * sizeof(partition_descriptor))); + uint64_t p = 0; + + for(uint64_t i = 0; i < 4; ++i){ + if(boot_record->partitions[i].type_code > 0){ + partition_type type; + if(boot_record->partitions[i].type_code == 0x0B || boot_record->partitions[i].type_code == 0x0C){ + type = partition_type::FAT32; + } else { + type = partition_type::UNKNOWN; + } + + partitions[p] = {p, type, boot_record->partitions[i].lba_begin, boot_record->partitions[i].sectors}; + + ++p; + } + } + + k_free(reinterpret_cast(buffer)); + + return partitions; + } +} diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 9b0403ae..6caa7aee 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -6,7 +6,7 @@ #include "timer.hpp" #include "utils.hpp" #include "memory.hpp" -#include "ata.hpp" +#include "disks.hpp" namespace { @@ -22,6 +22,7 @@ void echo_command(const char* params); void mmap_command(const char* params); void memory_command(const char* params); void disks_command(const char* params); +void partitions_command(const char* params); void ls_command(const char* params); struct command_definition { @@ -29,7 +30,7 @@ struct command_definition { void (*function)(const char*); }; -command_definition commands[11] = { +command_definition commands[12] = { {"reboot", reboot_command}, {"help", help_command}, {"uptime", uptime_command}, @@ -40,6 +41,7 @@ command_definition commands[11] = { {"mmap", mmap_command}, {"memory", memory_command}, {"disks", disks_command}, + {"partitions", partitions_command}, {"ls", ls_command}, }; @@ -260,29 +262,36 @@ void memory_command(const char*){ } void disks_command(const char*){ - k_print_line("Controller Drive Present"); + k_print_line("UUID Type"); - for(uint64_t i = 0; i < number_of_disks(); ++i){ - auto& descriptor = drive(i); + for(uint64_t i = 0; i < disks::detected_disks(); ++i){ + auto& descriptor = disks::disk_by_index(i); - k_printf("%12h %8h %s\n", descriptor.controller, descriptor.drive, descriptor.present ? "Yes" : "No"); + k_printf("%10d %s\n", descriptor.uuid, disks::disk_type_to_string(descriptor.type)); + } +} + +void partitions_command(const char* params){ + const char* delay_str = params + 11; + + auto uuid = parse(delay_str); + + if(disks::disk_exists(uuid)){ + auto partitions = disks::partitions(disks::disk_by_uuid(uuid)); + + k_print_line("UUID Type Start Sectors"); + + //TODO Make that dynamic + k_printf("%10d %12s %10d %d\n", partitions[0].uuid, disks::partition_type_to_string(partitions[0].type), + partitions[0].start, partitions[0].sectors); + } else { + k_printf("Disks %d does not exist\n", uuid); } } void ls_command(const char*){ - uint16_t* buffer = reinterpret_cast(k_malloc(512)); - - if(!ata_read_sectors(drive(0), 1, 1, buffer)){ - k_print_line("Read failed"); - } else { - for(int i = 0; i < 128; i += 8){ - k_printf("%.4h %.4h %.4h %.4h %.4h %.4h %.4h %.4h\n", - (uint64_t) buffer[i+0], (uint64_t) buffer[i+1], (uint64_t) buffer[i+2], (uint64_t) buffer[i+3], - (uint64_t) buffer[i+4], (uint64_t) buffer[i+5], (uint64_t) buffer[i+6], (uint64_t) buffer[i+7]); - } - - k_free(reinterpret_cast(buffer)); - } + //TODO Implement mount first + //TODO Implement ls } } //end of anonymous namespace From 2076949a29445c07fbe9a505c7880a80018f7902 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 5 Nov 2013 20:33:49 +0100 Subject: [PATCH 09/17] Improve code and remove memory leak --- kernel/include/disks.hpp | 3 +- kernel/include/unique_ptr.hpp | 60 +++++++++++++++++++++++++++++++++++ kernel/src/disks.cpp | 19 +++++------ kernel/src/shell.cpp | 10 +++--- 4 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 kernel/include/unique_ptr.hpp diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp index 1cb92d08..114e830b 100644 --- a/kernel/include/disks.hpp +++ b/kernel/include/disks.hpp @@ -2,6 +2,7 @@ #define DISKS_H #include "types.hpp" +#include "unique_ptr.hpp" namespace disks { @@ -39,7 +40,7 @@ const char* partition_type_to_string(partition_type type); bool read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination); -partition_descriptor* partitions(const disk_descriptor& disk); +unique_ptr partitions(const disk_descriptor& disk); } diff --git a/kernel/include/unique_ptr.hpp b/kernel/include/unique_ptr.hpp new file mode 100644 index 00000000..dea5dec9 --- /dev/null +++ b/kernel/include/unique_ptr.hpp @@ -0,0 +1,60 @@ +#ifndef UNIQUE_PTR_H +#define UNIQUE_PTR_H + +#include "thor.hpp" + +template +class unique_ptr { +public: + typedef T* pointer_type; + typedef T element_type; + +private: + pointer_type pointer; + +public: + explicit unique_ptr(pointer_type p) : pointer(p){} + + unique_ptr() : pointer(pointer_type()) {} + + unique_ptr(unique_ptr&& u) : pointer(u.release()) {} + unique_ptr& operator=(unique_ptr&& u){ + reset(u.release()); + return *this; + } + + ~unique_ptr(){ + reset(); + } + + // Disable copy + unique_ptr(const unique_ptr& rhs) = delete; + unique_ptr& operator=(const unique_ptr& rhs) = delete; + + element_type& operator*() const { + return *get(); + } + + pointer_type operator->() const { + return get(); + } + + pointer_type get() const { + return pointer; + } + + pointer_type release(){ + pointer_type p = pointer; + pointer = nullptr; + return p; + } + + void reset(pointer_type p = pointer_type()){ + if(pointer != p){ + k_free(reinterpret_cast(pointer)); + pointer = nullptr; + } + } +}; + +#endif diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index 3b23e236..6428892e 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -105,25 +105,25 @@ bool disks::read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t co return ata::read_sectors(*static_cast(disk.descriptor), start, count, destination); default: + k_print_line("BOOH"); return false; } } -disks::partition_descriptor* disks::partitions(const disk_descriptor& disk){ - //TODO Can be leaked - uint16_t* buffer = reinterpret_cast(k_malloc(512)); +unique_ptr disks::partitions(const disk_descriptor& disk){ + unique_ptr buffer(k_malloc(512)); - if(!read_sectors(disk, 0, 1, buffer)){ + if(!read_sectors(disk, 0, 1, buffer.get())){ k_print_line("Read Boot Record failed"); - return nullptr; + return {}; } else { - auto* boot_record = reinterpret_cast(buffer); + auto* boot_record = reinterpret_cast(buffer.get()); if(boot_record->signature != 0xAA55){ k_print_line("Invalid boot record signature"); - return nullptr; + return {}; } uint64_t n = 0; @@ -133,7 +133,6 @@ disks::partition_descriptor* disks::partitions(const disk_descriptor& disk){ } } - //TODO: This is a memory leak, partitions should be cached auto* partitions = reinterpret_cast(k_malloc(n * sizeof(partition_descriptor))); uint64_t p = 0; @@ -152,8 +151,6 @@ disks::partition_descriptor* disks::partitions(const disk_descriptor& disk){ } } - k_free(reinterpret_cast(buffer)); - - return partitions; + return unique_ptr(partitions); } } diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 6caa7aee..a1bf20e7 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -279,11 +279,13 @@ void partitions_command(const char* params){ if(disks::disk_exists(uuid)){ auto partitions = disks::partitions(disks::disk_by_uuid(uuid)); - k_print_line("UUID Type Start Sectors"); + if(partitions.get()){ + k_print_line("UUID Type Start Sectors"); - //TODO Make that dynamic - k_printf("%10d %12s %10d %d\n", partitions[0].uuid, disks::partition_type_to_string(partitions[0].type), - partitions[0].start, partitions[0].sectors); + //TODO Make that dynamic + k_printf("%10d %12s %10d %d\n", partitions.get()[0].uuid, disks::partition_type_to_string(partitions.get()[0].type), + partitions.get()[0].start, partitions.get()[0].sectors); + } } else { k_printf("Disks %d does not exist\n", uuid); } From d49f115a155c4e03c02713575aba5969abec3504 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 5 Nov 2013 21:12:06 +0100 Subject: [PATCH 10/17] Add unique_heap_array to simplify code --- kernel/include/array.hpp | 69 ++++++++++++++++++++++++++++++++++++++++ kernel/include/disks.hpp | 4 +-- kernel/src/disks.cpp | 8 +++-- kernel/src/shell.cpp | 10 +++--- 4 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 kernel/include/array.hpp diff --git a/kernel/include/array.hpp b/kernel/include/array.hpp new file mode 100644 index 00000000..3454a728 --- /dev/null +++ b/kernel/include/array.hpp @@ -0,0 +1,69 @@ +#ifndef ARRAY_H +#define ARRAY_H + +#include "thor.hpp" + +template +class unique_heap_array { +public: + typedef T* pointer_type; + +private: + T* array; + uint64_t _size; + +public: + unique_heap_array() : array(nullptr), _size(0) {} + + explicit unique_heap_array(T* a, uint64_t s) : array(a), _size(s) {} + explicit unique_heap_array(uint64_t s) : _size(s) { + array = reinterpret_cast(k_malloc(sizeof(T) * s)); + } + + unique_heap_array(unique_heap_array&& u) : array(u.release()), _size(u._size) { + u._size = 0; + } + + unique_heap_array& operator=(unique_heap_array&& u){ + _size = u._size; + reset(u.release()); + u._size = 0; + return *this; + } + + ~unique_heap_array(){ + reset(); + _size = 0; + } + + // Disable copy + unique_heap_array(const unique_heap_array& rhs) = delete; + unique_heap_array& operator=(const unique_heap_array& rhs) = delete; + + uint64_t size() const { + return _size; + } + + const T& operator[](uint64_t pos) const { + return array[pos]; + } + + T& operator[](uint64_t pos){ + return array[pos]; + } + + pointer_type release(){ + pointer_type p = array; + array = nullptr; + return p; + } + + void reset(pointer_type p = pointer_type()){ + if(array!= p){ + k_free(reinterpret_cast(array)); + array= nullptr; + } + } +}; + +#endif diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp index 114e830b..4fdf7c7d 100644 --- a/kernel/include/disks.hpp +++ b/kernel/include/disks.hpp @@ -2,7 +2,7 @@ #define DISKS_H #include "types.hpp" -#include "unique_ptr.hpp" +#include "array.hpp" namespace disks { @@ -40,7 +40,7 @@ const char* partition_type_to_string(partition_type type); bool read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination); -unique_ptr partitions(const disk_descriptor& disk); +unique_heap_array partitions(const disk_descriptor& disk); } diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index 6428892e..aa3a6c33 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -3,6 +3,8 @@ #include "thor.hpp" #include "console.hpp" +#include "unique_ptr.hpp" + namespace { bool detected = false; @@ -110,7 +112,7 @@ bool disks::read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t co } } -unique_ptr disks::partitions(const disk_descriptor& disk){ +unique_heap_array disks::partitions(const disk_descriptor& disk){ unique_ptr buffer(k_malloc(512)); if(!read_sectors(disk, 0, 1, buffer.get())){ @@ -133,7 +135,7 @@ unique_ptr disks::partitions(const disk_descriptor& } } - auto* partitions = reinterpret_cast(k_malloc(n * sizeof(partition_descriptor))); + unique_heap_array partitions(n); uint64_t p = 0; for(uint64_t i = 0; i < 4; ++i){ @@ -151,6 +153,6 @@ unique_ptr disks::partitions(const disk_descriptor& } } - return unique_ptr(partitions); + return partitions; } } diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index a1bf20e7..389a31a4 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -279,12 +279,14 @@ void partitions_command(const char* params){ if(disks::disk_exists(uuid)){ auto partitions = disks::partitions(disks::disk_by_uuid(uuid)); - if(partitions.get()){ + if(partitions.size() > 0){ k_print_line("UUID Type Start Sectors"); - //TODO Make that dynamic - k_printf("%10d %12s %10d %d\n", partitions.get()[0].uuid, disks::partition_type_to_string(partitions.get()[0].type), - partitions.get()[0].start, partitions.get()[0].sectors); + for(uint64_t i = 0; i < partitions.size(); ++i){ + k_printf("%10d %12s %10d %d\n", partitions[i].uuid, + disks::partition_type_to_string(partitions[i].type), + partitions[i].start, partitions[i].sectors); + } } } else { k_printf("Disks %d does not exist\n", uuid); From 178726b20f845fa9e52b7202e071c3cc31915967 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 5 Nov 2013 21:21:36 +0100 Subject: [PATCH 11/17] Use array template to constant sized array --- kernel/include/array.hpp | 19 +++++++++++++++++++ kernel/src/disks.cpp | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/include/array.hpp b/kernel/include/array.hpp index 3454a728..3f186b2f 100644 --- a/kernel/include/array.hpp +++ b/kernel/include/array.hpp @@ -3,6 +3,25 @@ #include "thor.hpp" +template +class array { +private: + T data[N]; + +public: + const T& operator[](uint64_t pos) const { + return data[pos]; + } + + T& operator[](uint64_t pos){ + return data[pos]; + } + + uint64_t size(){ + return N; + } +}; + template class unique_heap_array { public: diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index aa3a6c33..9d7d323f 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -4,13 +4,15 @@ #include "console.hpp" #include "unique_ptr.hpp" +#include "array.hpp" namespace { bool detected = false; //For now, 4 is enough as only the ata driver is implemented -disks::disk_descriptor _disks[4]; +array _disks; + uint64_t number_of_disks = 0; void detect_disks(){ From a6cdf46cc47542cfa7f0c9d4822db7080085e1d1 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 5 Nov 2013 21:36:59 +0100 Subject: [PATCH 12/17] Add iteration support to array and unique_heap_array --- kernel/include/array.hpp | 59 ++++++++++++++++++++++++++++++++++------ kernel/include/disks.hpp | 2 ++ kernel/src/disks.cpp | 33 ++++++++++------------ kernel/src/kernel.cpp | 2 ++ kernel/src/shell.cpp | 8 +++--- 5 files changed, 73 insertions(+), 31 deletions(-) diff --git a/kernel/include/array.hpp b/kernel/include/array.hpp index 3f186b2f..86ce330b 100644 --- a/kernel/include/array.hpp +++ b/kernel/include/array.hpp @@ -9,23 +9,48 @@ private: T data[N]; public: - const T& operator[](uint64_t pos) const { + typedef T value_type; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef uint64_t size_type; + + T& operator[](size_type pos){ return data[pos]; } - T& operator[](uint64_t pos){ + const T& operator[](size_type pos) const { return data[pos]; } - uint64_t size(){ + size_type size(){ return N; } + + iterator begin(){ + return iterator(&data[0]); + } + + const_iterator begin() const { + return const_iterator(&data[0]); + } + + iterator end(){ + return iterator(&data[N]); + } + + const_iterator end() const { + return const_iterator(&data[N]); + } }; template class unique_heap_array { public: - typedef T* pointer_type; + typedef T value_type; + typedef value_type* pointer_type; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef uint64_t size_type; private: T* array; @@ -34,8 +59,8 @@ private: public: unique_heap_array() : array(nullptr), _size(0) {} - explicit unique_heap_array(T* a, uint64_t s) : array(a), _size(s) {} - explicit unique_heap_array(uint64_t s) : _size(s) { + explicit unique_heap_array(T* a, size_type s) : array(a), _size(s) {} + explicit unique_heap_array(size_type s) : _size(s) { array = reinterpret_cast(k_malloc(sizeof(T) * s)); } @@ -59,15 +84,15 @@ public: unique_heap_array(const unique_heap_array& rhs) = delete; unique_heap_array& operator=(const unique_heap_array& rhs) = delete; - uint64_t size() const { + size_type size() const { return _size; } - const T& operator[](uint64_t pos) const { + const T& operator[](size_type pos) const { return array[pos]; } - T& operator[](uint64_t pos){ + T& operator[](size_type pos){ return array[pos]; } @@ -83,6 +108,22 @@ public: array= nullptr; } } + + iterator begin(){ + return iterator(&array[0]); + } + + const_iterator begin() const { + return const_iterator(&array[0]); + } + + iterator end(){ + return iterator(&array[_size]); + } + + const_iterator end() const { + return const_iterator(&array[_size]); + } }; #endif diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp index 4fdf7c7d..14dc0272 100644 --- a/kernel/include/disks.hpp +++ b/kernel/include/disks.hpp @@ -28,6 +28,8 @@ struct partition_descriptor { uint64_t sectors; }; +void detect_disks(); + uint64_t detected_disks(); bool disk_exists(uint64_t uuid); diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index 9d7d323f..38c87653 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -15,21 +15,6 @@ array _disks; uint64_t number_of_disks = 0; -void detect_disks(){ - ata::detect_disks(); - - for(uint8_t i = 0; i < ata::number_of_disks(); ++i){ - auto& descriptor = ata::drive(i); - - if(descriptor.present){ - _disks[number_of_disks] = {number_of_disks, disks::disk_type::ATA, &descriptor}; - ++number_of_disks; - } - } - - detected = true; -} - struct partition_descriptor_t { uint8_t boot_flag; uint8_t chs_begin[3]; @@ -51,11 +36,23 @@ static_assert(sizeof(boot_record_t) == 512, "The boot record is 512 bytes long") } //end of anonymous namespace -uint64_t disks::detected_disks(){ - if(!detected){ - detect_disks(); +void disks::detect_disks(){ + ata::detect_disks(); + + for(uint8_t i = 0; i < ata::number_of_disks(); ++i){ + auto& descriptor = ata::drive(i); + + if(descriptor.present){ + _disks[number_of_disks] = {number_of_disks, disks::disk_type::ATA, &descriptor}; + ++number_of_disks; + } } + detected = true; +} + + +uint64_t disks::detected_disks(){ return number_of_disks; } diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 6c8b5c22..004b0700 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -2,6 +2,7 @@ #include "timer.hpp" #include "shell.hpp" #include "keyboard.hpp" +#include "disks.hpp" extern "C" { @@ -10,6 +11,7 @@ void __attribute__ ((section ("main_section"))) kernel_main(){ init_memory_manager(); install_timer(); keyboard::install_driver(); + disks::detect_disks(); init_shell(); return; diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 389a31a4..72b949e8 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -282,10 +282,10 @@ void partitions_command(const char* params){ if(partitions.size() > 0){ k_print_line("UUID Type Start Sectors"); - for(uint64_t i = 0; i < partitions.size(); ++i){ - k_printf("%10d %12s %10d %d\n", partitions[i].uuid, - disks::partition_type_to_string(partitions[i].type), - partitions[i].start, partitions[i].sectors); + for(auto& partition : partitions){ + k_printf("%10d %12s %10d %d\n", partition.uuid, + disks::partition_type_to_string(partition.type), + partition.start, partition.sectors); } } } else { From f2f4a747df070dcd2a91e550075336bc3601abb3 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 6 Nov 2013 20:34:53 +0100 Subject: [PATCH 13/17] Implement mount --- kernel/include/disks.hpp | 7 ++++++- kernel/include/utils.hpp | 1 + kernel/src/disks.cpp | 44 ++++++++++++++++++++++++++++++++++++---- kernel/src/shell.cpp | 38 +++++++++++++++++++++++++++++++++- kernel/src/utils.cpp | 14 +++++++++++++ 5 files changed, 98 insertions(+), 6 deletions(-) diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp index 14dc0272..aa8262c9 100644 --- a/kernel/include/disks.hpp +++ b/kernel/include/disks.hpp @@ -41,8 +41,13 @@ const char* disk_type_to_string(disk_type type); const char* partition_type_to_string(partition_type type); bool read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination); - unique_heap_array partitions(const disk_descriptor& disk); +bool partition_exists(const disk_descriptor& disk, uint64_t uuid); + +void mount(const disk_descriptor& disk, uint64_t uuid); + +const disk_descriptor* mounted_disk(); +const partition_descriptor* mounted_partition(); } diff --git a/kernel/include/utils.hpp b/kernel/include/utils.hpp index 4e98a3d4..697c42bb 100644 --- a/kernel/include/utils.hpp +++ b/kernel/include/utils.hpp @@ -4,6 +4,7 @@ #include "types.hpp" uint64_t parse(const char* str); +uint64_t parse(const char* str, const char* end); bool str_equals(const char* a, const char* b); bool str_contains(const char* a, char c); diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index 38c87653..ccf479aa 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -8,8 +8,6 @@ namespace { -bool detected = false; - //For now, 4 is enough as only the ata driver is implemented array _disks; @@ -34,6 +32,9 @@ struct boot_record_t { static_assert(sizeof(boot_record_t) == 512, "The boot record is 512 bytes long"); +const disks::disk_descriptor* _mounted_disk; +const disks::partition_descriptor* _mounted_partition; + } //end of anonymous namespace void disks::detect_disks(){ @@ -48,10 +49,10 @@ void disks::detect_disks(){ } } - detected = true; + _mounted_disk = nullptr; + _mounted_partition = nullptr; } - uint64_t disks::detected_disks(){ return number_of_disks; } @@ -155,3 +156,38 @@ unique_heap_array disks::partitions(const disk_desc return partitions; } } + +bool disks::partition_exists(const disk_descriptor& disk, uint64_t uuid){ + for(auto& partition : partitions(disk)){ + if(partition.uuid == uuid){ + return true; + } + } + + return false; +} + +void disks::mount(const disk_descriptor& disk, uint64_t uuid){ + _mounted_disk = &disk; + + if(_mounted_partition){ + delete _mounted_partition; + } + + for(auto& partition : partitions(disk)){ + if(partition.uuid == uuid){ + auto p = new partition_descriptor(); + *p = partition; + _mounted_partition = p; + break; + } + } +} + +const disks::disk_descriptor* disks::mounted_disk(){ + return _mounted_disk; +} + +const disks::partition_descriptor* disks::mounted_partition(){ + return _mounted_partition; +} diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 72b949e8..82cafbea 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -23,6 +23,7 @@ void mmap_command(const char* params); void memory_command(const char* params); void disks_command(const char* params); void partitions_command(const char* params); +void mount_command(const char* params); void ls_command(const char* params); struct command_definition { @@ -30,7 +31,7 @@ struct command_definition { void (*function)(const char*); }; -command_definition commands[12] = { +command_definition commands[13] = { {"reboot", reboot_command}, {"help", help_command}, {"uptime", uptime_command}, @@ -42,6 +43,7 @@ command_definition commands[12] = { {"memory", memory_command}, {"disks", disks_command}, {"partitions", partitions_command}, + {"mount", mount_command}, {"ls", ls_command}, }; @@ -293,6 +295,40 @@ void partitions_command(const char* params){ } } +void mount_command(const char* params){ + if(!*(params+5)){ + auto md = disks::mounted_disk(); + auto mp = disks::mounted_partition(); + + if(md && mp){ + k_printf("%d:%d is mounted\n", md->uuid, mp->uuid); + } else { + k_print_line("Nothing is mounted"); + } + } else { + const char* it = params + 6; + const char* it_end = it; + + while(*it_end != ' '){ + ++it_end; + } + + auto disk_uuid = parse(it, it_end); + auto partition_uuid = parse(it_end + 1); + + if(disks::disk_exists(disk_uuid)){ + auto& disk = disks::disk_by_uuid(disk_uuid); + if(disks::partition_exists(disk, partition_uuid)){ + disks::mount(disk, partition_uuid); + } else { + k_printf("Partition %d does not exist\n", partition_uuid); + } + } else { + k_printf("Disk %d does not exist\n", disk_uuid); + } + } +} + void ls_command(const char*){ //TODO Implement mount first //TODO Implement ls diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index e60bd508..60ae48f9 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -9,6 +9,20 @@ bool str_equals(const char* a, const char* b){ return *a == *b; } +uint64_t parse(const char* it, const char* end){ + int i = end - it - 1; + + uint64_t factor = 1; + uint64_t acc = 0; + + for(; i >= 0; --i){ + acc += (it[i] - '0') * factor; + factor *= 10; + } + + return acc; +} + uint64_t parse(const char* str){ int i = 0; From 0cccf363ec22c5f11c5c1bcf8cd0f5d712666bee Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 6 Nov 2013 21:38:37 +0100 Subject: [PATCH 14/17] memory allocator improvements Fix small bug with the split decision of k_malloc Add debug routines --- kernel/src/memory.cpp | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/kernel/src/memory.cpp b/kernel/src/memory.cpp index 7b02c0d6..c78a64b0 100644 --- a/kernel/src/memory.cpp +++ b/kernel/src/memory.cpp @@ -3,6 +3,10 @@ namespace { +//Used to compile with malloc operations in the console +//can produce a lot of output +const bool DEBUG_MALLOC = false; + struct bios_mmap_entry { uint32_t base_low; uint32_t base_high; @@ -110,6 +114,35 @@ uint64_t* allocate_block(uint64_t blocks){ return block; } +template +void debug_malloc(const char* point = nullptr){ + if(Debug){ + if(point){ + k_print_line(point); + } + + auto it = malloc_head; + + k_print("next: "); + do { + k_printf("%h -> ", reinterpret_cast(it)); + it = it->next; + } while(it != malloc_head); + + k_printf("%h\n", malloc_head); + + it = malloc_head; + + k_print("prev: "); + do { + k_printf("%h <- ", reinterpret_cast(it)); + it = it->prev; + } while(it != malloc_head); + + k_printf("%h\n", malloc_head); + } +} + } //end of anonymous namespace void init_memory_manager(){ @@ -147,12 +180,12 @@ uint64_t* k_malloc(uint64_t bytes){ auto header = reinterpret_cast(block); header->size = MIN_BLOCKS * BLOCK_SIZE - META_SIZE; + header->next = current->next; + header->prev = current; + current->next->prev = header; current->next = header; - header->next = current->next; - header->prev = current; - auto footer = reinterpret_cast( reinterpret_cast(block) + header->size + sizeof(malloc_header_chunk)); footer->size = header->size; @@ -160,7 +193,7 @@ uint64_t* k_malloc(uint64_t bytes){ //This block is big enough //Is it worth splitting the block ? - if(current->size - bytes - META_SIZE > MIN_SPLIT){ + if(current->size > bytes + META_SIZE + MIN_SPLIT){ auto new_block_size = current->size - bytes - META_SIZE; //Set the new size; @@ -183,12 +216,16 @@ uint64_t* k_malloc(uint64_t bytes){ reinterpret_cast(new_block) + new_block_size + sizeof(malloc_header_chunk)); new_footer->size = new_block_size; + debug_malloc("after malloc split"); + break; } else { //Remove this node from the free list current->prev->next = current->next; current->next->prev = current->prev; + debug_malloc("after malloc no split"); + break; } } @@ -219,6 +256,8 @@ void k_free(uint64_t* block){ header->next->prev = free_header; header->next = free_header; + + debug_malloc("after free"); } void load_memory_map(){ From fc2b9885a5448123c0418b220ceeba80621ba8ea Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 6 Nov 2013 21:47:46 +0100 Subject: [PATCH 15/17] Start putting the project under Boost Software License --- LICENSE | 23 +++++++++++++++++++++++ README.md | 8 ++++++-- license_header | 6 ++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 license_header diff --git a/LICENSE b/LICENSE index e69de29b..36b7cd93 100644 --- a/LICENSE +++ b/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 00a608d3..d1c4950d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ thor-os ======= -Thor is a minimalistic operating system created for learning reasons. +Thor is a minimalistic operating system created for learning reasons. -It is currently a 64bit OS written in assembly and C++. +It is currently a 64bit OS written in assembly and C++. + +## License ## + +This project is distributed under the Boost Software License 1.0. Read `LICENSE_1_0.txt` for details. diff --git a/license_header b/license_header new file mode 100644 index 00000000..42c50b7c --- /dev/null +++ b/license_header @@ -0,0 +1,6 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= From f02f4376494ec8eaf1e98a41c7521e57eadd1400 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 6 Nov 2013 21:55:54 +0100 Subject: [PATCH 16/17] Apply the License to all source files --- add_license.bash | 6 ++++++ bootloader/bootloader.asm | 7 +++++++ bootloader/intel_16.asm | 7 +++++++ kernel/include/array.hpp | 7 +++++++ kernel/include/ata.hpp | 7 +++++++ kernel/include/console.hpp | 7 +++++++ kernel/include/disks.hpp | 7 +++++++ kernel/include/kernel_utils.hpp | 7 +++++++ kernel/include/keyboard.hpp | 7 +++++++ kernel/include/memory.hpp | 7 +++++++ kernel/include/shell.hpp | 7 +++++++ kernel/include/thor.hpp | 7 +++++++ kernel/include/timer.hpp | 7 +++++++ kernel/include/types.hpp | 7 +++++++ kernel/include/unique_ptr.hpp | 7 +++++++ kernel/include/utils.hpp | 7 +++++++ kernel/src/ata.cpp | 7 +++++++ kernel/src/console.cpp | 7 +++++++ kernel/src/disks.cpp | 7 +++++++ kernel/src/kernel.cpp | 7 +++++++ kernel/src/kernel_utils.cpp | 7 +++++++ kernel/src/keyboard.cpp | 7 +++++++ kernel/src/memory.cpp | 7 +++++++ kernel/src/shell.cpp | 7 +++++++ kernel/src/thor.cpp | 7 +++++++ kernel/src/timer.cpp | 7 +++++++ kernel/src/utils.cpp | 7 +++++++ license_header | 1 + micro_kernel/interrupts.asm | 7 +++++++ micro_kernel/micro_kernel.asm | 7 +++++++ micro_kernel/utils/console.asm | 7 +++++++ micro_kernel/utils/macros.asm | 7 +++++++ micro_kernel/utils/utils.asm | 7 +++++++ 33 files changed, 224 insertions(+) create mode 100644 add_license.bash diff --git a/add_license.bash b/add_license.bash new file mode 100644 index 00000000..22c39d2c --- /dev/null +++ b/add_license.bash @@ -0,0 +1,6 @@ +for file in "$@" +do + cp ${file} ${file}.orig + cat license_header ${file}.orig > ${file} + rm ${file}.orig +done diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index af0d5888..6d41c2b4 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + [BITS 16] jmp rm_start diff --git a/bootloader/intel_16.asm b/bootloader/intel_16.asm index c3546a0b..70672783 100644 --- a/bootloader/intel_16.asm +++ b/bootloader/intel_16.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + [BITS 16] ; Functions diff --git a/kernel/include/array.hpp b/kernel/include/array.hpp index 86ce330b..31774295 100644 --- a/kernel/include/array.hpp +++ b/kernel/include/array.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef ARRAY_H #define ARRAY_H diff --git a/kernel/include/ata.hpp b/kernel/include/ata.hpp index b57de4bb..89732bd6 100644 --- a/kernel/include/ata.hpp +++ b/kernel/include/ata.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef ATA_H #define ATA_H diff --git a/kernel/include/console.hpp b/kernel/include/console.hpp index 16db8f6a..f729abdf 100644 --- a/kernel/include/console.hpp +++ b/kernel/include/console.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef CONSOLE_H #define CONSOLE_H diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp index aa8262c9..43f4efd9 100644 --- a/kernel/include/disks.hpp +++ b/kernel/include/disks.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef DISKS_H #define DISKS_H diff --git a/kernel/include/kernel_utils.hpp b/kernel/include/kernel_utils.hpp index 1558623a..44f43b69 100644 --- a/kernel/include/kernel_utils.hpp +++ b/kernel/include/kernel_utils.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef KERNEL_UTILS_H #define KERNEL_UTILS_H diff --git a/kernel/include/keyboard.hpp b/kernel/include/keyboard.hpp index 8532b6e1..e840dc39 100644 --- a/kernel/include/keyboard.hpp +++ b/kernel/include/keyboard.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef KEYBOARD_H #define KEYBOARD_H diff --git a/kernel/include/memory.hpp b/kernel/include/memory.hpp index 572d4193..664d446e 100644 --- a/kernel/include/memory.hpp +++ b/kernel/include/memory.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef MEMORY_H #define MEMORY_H diff --git a/kernel/include/shell.hpp b/kernel/include/shell.hpp index 5ac9f09d..1663f990 100644 --- a/kernel/include/shell.hpp +++ b/kernel/include/shell.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef SHELL_H #define SHELL_ diff --git a/kernel/include/thor.hpp b/kernel/include/thor.hpp index 96905c1c..d4464551 100644 --- a/kernel/include/thor.hpp +++ b/kernel/include/thor.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef THOR_H #define THOR_H diff --git a/kernel/include/timer.hpp b/kernel/include/timer.hpp index 9d660628..f8cd0118 100644 --- a/kernel/include/timer.hpp +++ b/kernel/include/timer.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef TIMER_H #define TIMER_H diff --git a/kernel/include/types.hpp b/kernel/include/types.hpp index fda0a67f..f627074b 100644 --- a/kernel/include/types.hpp +++ b/kernel/include/types.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef TYPES_H #define TYPES_H diff --git a/kernel/include/unique_ptr.hpp b/kernel/include/unique_ptr.hpp index dea5dec9..7957fc59 100644 --- a/kernel/include/unique_ptr.hpp +++ b/kernel/include/unique_ptr.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef UNIQUE_PTR_H #define UNIQUE_PTR_H diff --git a/kernel/include/utils.hpp b/kernel/include/utils.hpp index 697c42bb..3a73afa5 100644 --- a/kernel/include/utils.hpp +++ b/kernel/include/utils.hpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #ifndef UTILS_H #define UTILS_H diff --git a/kernel/src/ata.cpp b/kernel/src/ata.cpp index 1421f722..02266101 100644 --- a/kernel/src/ata.cpp +++ b/kernel/src/ata.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "ata.hpp" #include "kernel_utils.hpp" #include "timer.hpp" diff --git a/kernel/src/console.cpp b/kernel/src/console.cpp index 477fd7d9..0c37ad59 100644 --- a/kernel/src/console.cpp +++ b/kernel/src/console.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include #include "console.hpp" diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index ccf479aa..24cf7d24 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "disks.hpp" #include "ata.hpp" #include "thor.hpp" diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 004b0700..9421e8e5 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "memory.hpp" #include "timer.hpp" #include "shell.hpp" diff --git a/kernel/src/kernel_utils.cpp b/kernel/src/kernel_utils.cpp index 4b4ffe99..f98536f4 100644 --- a/kernel/src/kernel_utils.cpp +++ b/kernel/src/kernel_utils.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "kernel_utils.hpp" uint8_t in_byte(uint16_t _port){ diff --git a/kernel/src/keyboard.cpp b/kernel/src/keyboard.cpp index 87ff9a04..3b240415 100644 --- a/kernel/src/keyboard.cpp +++ b/kernel/src/keyboard.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "keyboard.hpp" #include "kernel_utils.hpp" diff --git a/kernel/src/memory.cpp b/kernel/src/memory.cpp index c78a64b0..cce7dae5 100644 --- a/kernel/src/memory.cpp +++ b/kernel/src/memory.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "memory.hpp" #include "console.hpp" diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 82cafbea..e64fe244 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "types.hpp" #include "keyboard.hpp" #include "kernel_utils.hpp" diff --git a/kernel/src/thor.cpp b/kernel/src/thor.cpp index c18b3220..e900ed28 100644 --- a/kernel/src/thor.cpp +++ b/kernel/src/thor.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "thor.hpp" #include "memory.hpp" diff --git a/kernel/src/timer.cpp b/kernel/src/timer.cpp index 68baa861..a965f350 100644 --- a/kernel/src/timer.cpp +++ b/kernel/src/timer.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "timer.hpp" #include "kernel_utils.hpp" diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index 60ae48f9..5f8b1f5a 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + #include "utils.hpp" bool str_equals(const char* a, const char* b){ diff --git a/license_header b/license_header index 42c50b7c..9cd10d1e 100644 --- a/license_header +++ b/license_header @@ -4,3 +4,4 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= + diff --git a/micro_kernel/interrupts.asm b/micro_kernel/interrupts.asm index baf4419b..d1b5d592 100644 --- a/micro_kernel/interrupts.asm +++ b/micro_kernel/interrupts.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + ; Variables diff --git a/micro_kernel/micro_kernel.asm b/micro_kernel/micro_kernel.asm index 46a78494..0567a648 100644 --- a/micro_kernel/micro_kernel.asm +++ b/micro_kernel/micro_kernel.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + [BITS 16] [ORG 0x1000] diff --git a/micro_kernel/utils/console.asm b/micro_kernel/utils/console.asm index 9382a5b2..72e1a863 100644 --- a/micro_kernel/utils/console.asm +++ b/micro_kernel/utils/console.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + %define BLACK_F 0x0 %define BLUE_F 0x1 %define GREEN_F 0x2 diff --git a/micro_kernel/utils/macros.asm b/micro_kernel/utils/macros.asm index 32010f17..85e1dd26 100644 --- a/micro_kernel/utils/macros.asm +++ b/micro_kernel/utils/macros.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + ; Some utility macros ; Define a string and a variable containing its length diff --git a/micro_kernel/utils/utils.asm b/micro_kernel/utils/utils.asm index e1454b8d..c8cfb1d0 100644 --- a/micro_kernel/utils/utils.asm +++ b/micro_kernel/utils/utils.asm @@ -1,3 +1,10 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + ; Compute the length of string representation of the integer ; in r8 = integer to print ; out rax = string length of int From 24f4211884d3ef193a309f8e7879b58999af0884 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 6 Nov 2013 22:00:22 +0100 Subject: [PATCH 17/17] Improve license generation --- add_license.bash | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/add_license.bash b/add_license.bash index 22c39d2c..8f61c6aa 100644 --- a/add_license.bash +++ b/add_license.bash @@ -1,6 +1,11 @@ for file in "$@" do - cp ${file} ${file}.orig - cat license_header ${file}.orig > ${file} - rm ${file}.orig + lines=`grep "Distributed under the Boost Software License" $file | wc -l` + + if [[ $lines == 0 ]] + then + cp ${file} ${file}.orig + cat license_header ${file}.orig > ${file} + rm ${file}.orig + fi done