Add MBR (Master boot record) (closes #19)

This commit is contained in:
Alex Kotov 2022-01-17 10:58:47 +05:00
parent 2f06a24f63
commit 38a5ee265c
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
7 changed files with 61 additions and 0 deletions

View File

@ -58,6 +58,10 @@ if WITH_FRAMEBUFFER
libkernaux_a_SOURCES += src/framebuffer.c
endif
if WITH_MBR
libkernaux_a_SOURCES += src/mbr.c
endif
if WITH_MULTIBOOT2
libkernaux_a_SOURCES += \
src/multiboot2/enums_to_str.c \

View File

@ -46,6 +46,7 @@ API
* [Page Frame Allocator](/include/kernaux/pfa.h) *(work in progress)*
* [Example](/examples/pfa.c)
* Data formats
* [Master Boot Record](/include/kernaux/mbr.h) *(work in progress)*
* [Multiboot 2 (GRUB 2) information parser](/include/kernaux/multiboot2.h) *(work in progress)*
* Stivale 2 (Limine) information parser *(planned)*
* [ELF utils](/include/kernaux/elf.h) *(work in progress)*
@ -96,6 +97,7 @@ are some non-default options:
* `--with[out]-console`
* `--with[out]-elf`
* `--with[out]-framebuffer`
* `--with[out]-mbr`
* `--with[out]-multiboot2`
* `--with[out]-pfa`
* `--with[out]-units`

View File

@ -23,6 +23,7 @@ AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without co
AC_ARG_WITH( [console], AS_HELP_STRING([--without-console], [without serial console]))
AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils]))
AC_ARG_WITH( [framebuffer], AS_HELP_STRING([--without-framebuffer], [without framebuffer]))
AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record]))
AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser]))
AC_ARG_WITH( [pfa], AS_HELP_STRING([--without-pfa], [without Page Frame Allocator]))
AC_ARG_WITH( [units], AS_HELP_STRING([--without-units], [without measurement units utils]))
@ -67,6 +68,7 @@ AM_CONDITIONAL([WITH_CMDLINE], [test "$with_cmdline" != no])
AM_CONDITIONAL([WITH_CONSOLE], [test "$with_console" != no])
AM_CONDITIONAL([WITH_ELF], [test "$with_elf" != no])
AM_CONDITIONAL([WITH_FRAMEBUFFER], [test "$with_framebuffer" != no])
AM_CONDITIONAL([WITH_MBR], [test "$with_mbr" != no])
AM_CONDITIONAL([WITH_MULTIBOOT2], [test "$with_multiboot2" != no])
AM_CONDITIONAL([WITH_PFA], [test "$with_pfa" != no])
AM_CONDITIONAL([WITH_UNITS], [test "$with_units" != no])
@ -93,6 +95,7 @@ AS_IF([test "$with_cmdline" != no], [AC_DEFINE([WITH_CMDLINE],
AS_IF([test "$with_console" != no], [AC_DEFINE([WITH_CONSOLE], [1], [with serial console])])
AS_IF([test "$with_elf" != no], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])])
AS_IF([test "$with_framebuffer" != no], [AC_DEFINE([WITH_FRAMEBUFFER], [1], [with framebuffer])])
AS_IF([test "$with_mbr" != no], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])])
AS_IF([test "$with_multiboot2" != no], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])])
AS_IF([test "$with_pfa" != no], [AC_DEFINE([WITH_PFA], [1], [with Page Frame Allocator])])
AS_IF([test "$with_units", != no], [AC_DEFINE([WITH_UNITS], [1], [with measurement units utils])])

View File

@ -13,6 +13,7 @@ nobase_include_HEADERS = \
kernaux/framebuffer.h \
kernaux/itoa.h \
kernaux/libc.h \
kernaux/mbr.h \
kernaux/multiboot2.h \
kernaux/pfa.h \
kernaux/printf.h \

View File

@ -12,6 +12,7 @@
#include <kernaux/elf.h>
#include <kernaux/framebuffer.h>
#include <kernaux/itoa.h>
#include <kernaux/mbr.h>
#include <kernaux/multiboot2.h>
#include <kernaux/pfa.h>
#include <kernaux/printf.h>

45
include/kernaux/mbr.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef KERNAUX_INCLUDED_MBR
#define KERNAUX_INCLUDED_MBR
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define KERNAUX_MBR_SIZE 512
#define KERNAUX_MBR_MAGIC 0xAA55
#define KERNAUX_MBR_ENTRIES 4
#define KERNAUX_MBR_BOOTSTRAP_SIZE \
(KERNAUX_MBR_SIZE - sizeof(struct KernAux_Mbr_Info))
struct KernAux_Mbr_Entry {
uint8_t drive_attributes;
unsigned start_chs_address : 24;
uint8_t partition_type;
unsigned last_chs_address : 24;
uint32_t start_lba;
uint32_t sectors_count;
}
__attribute__((packed));
struct KernAux_Mbr_Info {
uint32_t disk_id;
uint16_t reserved;
struct KernAux_Mbr_Entry entries[KERNAUX_MBR_ENTRIES];
uint16_t magic;
}
__attribute__((packed));
struct KernAux_Mbr {
uint8_t bootstrap[KERNAUX_MBR_BOOTSTRAP_SIZE];
struct KernAux_Mbr_Info info;
}
__attribute__((packed));
#ifdef __cplusplus
}
#endif
#endif

5
src/mbr.c Normal file
View File

@ -0,0 +1,5 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/mbr.h>