210 lines
4.7 KiB
C
210 lines
4.7 KiB
C
/* kernLdr.h - This file is a part of NutsOS
|
|
*
|
|
* NutsOS
|
|
* Copyright (C) 2013 Free Software Foundation, Inc.
|
|
*
|
|
* NutsOS is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* NutsOS is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Valentin Verdier <valentin.verdier03@gmail.com>
|
|
*/
|
|
|
|
#pragma once
|
|
#ifndef NOS_KERNLDR_H
|
|
#define NOS_KERNLDR_H
|
|
|
|
#include <stdarg.h>
|
|
#include "types.h"
|
|
#include "drivers/ATA.h"
|
|
|
|
|
|
/* Structure de passage d'arguments */
|
|
typedef struct {
|
|
T_dword low_addr;
|
|
T_dword high_addr;
|
|
T_dword low_size;
|
|
T_dword high_size;
|
|
T_dword type;
|
|
T_dword unused;
|
|
}__attribute__((packed)) T_mmap_entry;
|
|
|
|
#define BOOT_ARGS_ADDR 0x1000
|
|
|
|
typedef struct {
|
|
T_byte cursor_x;
|
|
T_byte cursor_y;
|
|
T_byte mmap_entry_count;
|
|
T_mmap_entry mmap[30]; /* Taille fixée arbitrairement */
|
|
}__attribute__((packed)) T_boot_args;
|
|
|
|
#define KERNEL_ARGS_ADDR 0x1400
|
|
|
|
typedef struct {
|
|
T_byte cursor_x;
|
|
T_byte cursor_x;
|
|
T_dword pmem_size;
|
|
T_byte mmap_entry_count;
|
|
T_dword init_proc_addr;
|
|
T_dword init_proc_size;
|
|
T_mmap_entry* mmap;
|
|
}__attribute__((packed)) T_kernel_args;
|
|
|
|
/* ############################## */
|
|
|
|
|
|
/* ######### Affichage ########## */
|
|
#define VIDEO_ADDR 0xB8000
|
|
#define VIDEO_SIZE 0xFA0
|
|
#define VIDEO_END_OFFSET 0xB8FA0
|
|
#define DEFAULT_COLOR 0x0F
|
|
|
|
char pos_x;
|
|
char pos_y;
|
|
int enable_cursor;
|
|
|
|
void scrollup(int);
|
|
void write_char(char, char);
|
|
void print(char*, ...);
|
|
void clear();
|
|
void show_cursor();
|
|
void hide_cursor();
|
|
void move_cursor(char, char);
|
|
/* ############################## */
|
|
|
|
|
|
/* ####### Fonctions I/O ######## */
|
|
void _out(T_word, T_byte);
|
|
T_byte _in(T_word);
|
|
void _outw(T_word, T_word);
|
|
T_word _inw(T_word);
|
|
void _outdw(T_word, T_dword);
|
|
T_dword _indw(T_word);
|
|
/* ############################## */
|
|
|
|
|
|
/* ########### Divers ########### */
|
|
void memcopy(char*, char*, unsigned int);
|
|
int strcmp(char*, char*);
|
|
void int_to_str(unsigned int, char*, int);
|
|
unsigned int expo(int, int);
|
|
void delay(unsigned int);
|
|
/* ############################## */
|
|
|
|
|
|
/* ###### Structure MBR et Table de partition */
|
|
|
|
#define PARTITION_BOOT_SIGN 0x80
|
|
#define VFAT32_PARTITION_ID 0x07
|
|
|
|
typedef struct {
|
|
T_byte bootsign;
|
|
T_byte chs_start_head;
|
|
T_byte chs_start_sector:6;
|
|
T_word chs_start_cylinder:10;
|
|
T_byte fs_id;
|
|
T_byte chs_end_head;
|
|
T_byte chs_end_sector:6;
|
|
T_word chs_end_cylinder:10;
|
|
T_dword lba_start_sector;
|
|
T_dword lba_sector_count;
|
|
}__attribute__((packed)) T_partition_entry;
|
|
|
|
#define MBR_BOOT_SIGN 0xAA55
|
|
|
|
typedef struct {
|
|
T_byte bootcode[446];
|
|
T_partition_entry pt[4];
|
|
T_word bootsign;
|
|
}__attribute__((packed)) T_MBR;
|
|
|
|
/* ########################################## */
|
|
|
|
/* ###### Fat32 structure ####### */
|
|
typedef struct {
|
|
T_byte jumpcode[3];
|
|
char OEM_identifier[8];
|
|
T_word byte_per_sect;
|
|
T_byte sect_per_cluster;
|
|
T_word reserved_sect_count;
|
|
T_byte fat_count;
|
|
T_word unused_1;
|
|
T_word total_sect_count_16;
|
|
T_byte media_desc_type;
|
|
T_word unused_2;
|
|
T_word sect_per_track;
|
|
T_word head_count;
|
|
T_dword hidden_sect_lba;
|
|
T_dword total_sect_count_32;
|
|
T_dword sect_per_fat;
|
|
T_word fat_info;
|
|
T_word fat_ver;
|
|
T_dword rootdir_first_cluster;
|
|
T_word fs_info_sect;
|
|
T_word dbr_cpy_sect;
|
|
T_byte reserved[12];
|
|
T_byte bios_disk_id;
|
|
T_byte reserved_NT; /* Windows NT flags */
|
|
T_byte sign;
|
|
T_dword serial_num;
|
|
char label[11];
|
|
char identifier_str[8];
|
|
T_byte bootcode[420];
|
|
T_word bootsign;
|
|
}__attribute__((packed)) T_FAT32_dbr;
|
|
|
|
#define FAT32_DIR_ENTRY_SIZE 32
|
|
|
|
typedef struct {
|
|
T_byte entry_num;
|
|
char char_part1[10];
|
|
T_byte attribute;
|
|
T_byte lfn_entry_type;
|
|
T_byte checksum;
|
|
char char_part2[12];
|
|
T_word null;
|
|
char char_part3[4];
|
|
}__attribute__((packed)) T_FAT32_lfn_entry;
|
|
|
|
typedef struct {
|
|
char filename[8];
|
|
char extention[3];
|
|
T_byte attribute;
|
|
T_byte reserved; /* Windows NT */
|
|
T_byte creation_time_1;
|
|
T_word creation_time_2;
|
|
T_word creation_date;
|
|
T_word last_acces;
|
|
T_word high_first_cluster;
|
|
T_word modif_time;
|
|
T_word modif_date;
|
|
T_word low_first_cluster;
|
|
T_dword file_size;
|
|
}__attribute__((packed)) T_FAT32_std_entry;
|
|
|
|
typedef struct {
|
|
T_ATA_device device;
|
|
T_FAT32_dbr dbr;
|
|
|
|
/* Buffer de lecture */
|
|
unsigned int loaded_fat_sect;
|
|
T_dword fat_sect_buf[128]; /* 512 octets */
|
|
T_dword* dir_cluster_buf;
|
|
|
|
/* Adresses LBA des structures sur le disque */
|
|
T_dword LBA_dbr;
|
|
T_dword LBA_fat;
|
|
T_dword LBA_first_sata_sect; /* cluster 2 */
|
|
} T_FAT32_partition;
|
|
|
|
#endif
|