1. Refactored kernel calling convention.
2. Linker script for kernel. 2. Updated mkiso script to link C with nasm and build a runable multiboot1 iso.
This commit is contained in:
parent
e12cac16a3
commit
b6c999753f
|
@ -0,0 +1,10 @@
|
|||
#define HYPKERNEL32 __attribute__((__cdecl__))
|
||||
extern void* kernel_stack;
|
||||
extern void print_str(char* dst);
|
||||
void HYPKERNEL32 hk_main(void* multiboot_info)
|
||||
{
|
||||
char* str = "Kernel is here";
|
||||
print_str(str);
|
||||
fuck:
|
||||
goto fuck;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
menuentry "HOS Multiboot [Dev]" {
|
||||
multiboot /HOS/kernel_multiboot.bin
|
||||
multiboot /HOS/kernel.bin
|
||||
}
|
||||
menuentry "HOS Multiboot2 [Pending]" {
|
||||
multiboot2 /HOS/kernel_multiboot2.bin
|
||||
multiboot2 /HOS/multiboot2.bin
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
OUTPUT_FORMAT("binary")
|
||||
INPUT
|
||||
(
|
||||
multiboot.o
|
||||
entry.o
|
||||
)
|
||||
OUTPUT(kernel.bin)
|
||||
SECTIONS
|
||||
{
|
||||
.text.start (0x1000000):
|
||||
{
|
||||
multiboot.o(.multiboot)
|
||||
}
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.text)
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(.bss)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
sudo rm HOS.iso
|
||||
sudo nasm -f elf32 multiboot.asm -o multiboot.o
|
||||
sudo gcc -m32 -masm=intel -c entry.c -o entry.o
|
||||
|
||||
sudo mkdir temp_iso
|
||||
sudo mkdir temp_iso/HOS
|
||||
sudo mkdir temp_iso/boot
|
||||
sudo mkdir temp_iso/boot/grub
|
||||
#link files
|
||||
sudo ld -m elf_i386 -T link.ld
|
||||
|
||||
#remove temp obj files
|
||||
sudo rm multiboot.o
|
||||
sudo rm entry.o
|
||||
|
||||
#sudo cp kernel.bin kernel.binn
|
||||
sudo mv kernel.bin temp_iso/HOS/kernel.bin
|
||||
|
||||
sudo cp grub.cfg temp_iso/boot/grub/
|
||||
#make iso file
|
||||
sudo grub-mkrescue -o HOS.iso temp_iso
|
||||
sudo rm -rf temp_iso
|
|
@ -1,5 +1,8 @@
|
|||
org 0x01000000
|
||||
|
||||
global print_str
|
||||
global kernel_stack
|
||||
extern hk_main
|
||||
[SECTION .multiboot]
|
||||
[BITS 32]
|
||||
GRUB_LOADED_FLAG equ 0x2BADB002
|
||||
GRUB_MAGIC_NUMBER equ 0x1BADB002
|
||||
GRUB_FLAGS equ 0x10003
|
||||
|
@ -41,10 +44,9 @@ db 'Loaded by multiboot1!',0
|
|||
|
||||
;stack
|
||||
times 1024 db 0
|
||||
_KERNEL_STACK:
|
||||
kernel_stack:
|
||||
|
||||
GRUB_ENTRY_ADDR:
|
||||
[BITS 32]
|
||||
cli
|
||||
|
||||
cmp eax,GRUB_LOADED_FLAG
|
||||
|
@ -52,15 +54,15 @@ jmp LOADED_BY_GRUB
|
|||
hlt
|
||||
LOADED_BY_GRUB:
|
||||
|
||||
mov eax,_KERNEL_STACK
|
||||
mov eax,kernel_stack
|
||||
mov esp,eax
|
||||
|
||||
push dword 0
|
||||
popfd
|
||||
|
||||
lgdt [GDT_PTR]
|
||||
jmp SLCT_CODE_0:Reload_CS
|
||||
Reload_CS:
|
||||
jmp SLCT_CODE_0:reload_cs
|
||||
reload_cs:
|
||||
mov ax,SLCT_DATA_0
|
||||
mov ss,ax
|
||||
mov ds,ax
|
||||
|
@ -70,13 +72,15 @@ mov ax,SLCT_GRAPH_0
|
|||
mov gs,ax
|
||||
|
||||
push DUMMY_MSG
|
||||
call _printf
|
||||
xchg bx,bx
|
||||
call print_str
|
||||
add esp,4
|
||||
|
||||
call hk_main
|
||||
end:
|
||||
jmp end
|
||||
|
||||
_printf:
|
||||
print_str:
|
||||
;void printf(char* str)
|
||||
;EAX,ECX,EDX
|
||||
push ebp
|
||||
|
@ -103,4 +107,4 @@ pop esi
|
|||
pop edi
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
|
||||
ret
|
|
@ -11,7 +11,7 @@ floppy_bootsig_check: disabled=0
|
|||
# no floppya
|
||||
# no floppyb
|
||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
ata0-master: type=cdrom, path="C:\Users\Oscar\Desktop\HOS.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
||||
ata0-master: type=cdrom, path="HOS.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
||||
ata0-slave: type=none
|
||||
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
|
||||
ata1-master: type=none
|
||||
|
|
|
@ -4,14 +4,14 @@ config_interface: win32config
|
|||
display_library: win32, options="gui_debug"
|
||||
magic_break: enabled=1
|
||||
memory: host=256, guest=512
|
||||
romimage: file="C:\Program Files (x86)\Bochs-2.6.6/BIOS-bochs-latest"
|
||||
vgaromimage: file="C:\Program Files (x86)\Bochs-2.6.6/VGABIOS-lgpl-latest"
|
||||
romimage: file="C:\Program Files (x86)\Bochs-2.6.6\BIOS-bochs-latest"
|
||||
vgaromimage: file="C:\Program Files (x86)\Bochs-2.6.6\VGABIOS-lgpl-latest"
|
||||
boot: cdrom
|
||||
floppy_bootsig_check: disabled=0
|
||||
# no floppya
|
||||
# no floppyb
|
||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
ata0-master: type=cdrom, path="C:\Users\Oscar\Desktop\HOS.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
||||
ata0-master: type=cdrom, path="HOS.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
||||
ata0-slave: type=none
|
||||
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
|
||||
ata1-master: type=none
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
uint64 g_gdt[32];
|
||||
gdt_ptr g_gdt_ptr;
|
||||
|
||||
uint32 HKA32 hk_main(multiboot_info_t* multibootInfo)
|
||||
uint32 HYPKERNEL32 hk_main(multiboot_info_t* multibootInfo)
|
||||
{
|
||||
int32 gdtIdx = 0;
|
||||
//empty segment
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef _HKDEF32_H_
|
||||
#define _HKDEF32_H_
|
||||
|
||||
#define HKA32 __cdecl
|
||||
#define HYPKERNEL32 __cdecl
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
#define GDT_SELECTOR(Index,RPL) (((Index) << 3) + (RPL))
|
||||
|
||||
#define HKernelAddress (0x01000000)
|
||||
#define HKERNEL_ADDR (0x01000000)
|
||||
#endif
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
#include "mem32.h"
|
||||
#include "type32.h"
|
||||
#include "kdef32.h"
|
||||
|
||||
int32 hk_set_segment_descriptor(segment_descriptor* pseg_descriptor, uint32 base, uint32 limit, uint8 access, uint8 flags)
|
||||
int32 HYPKERNEL32 hk_set_segment_descriptor(segment_descriptor* pseg_descriptor, uint32 base, uint32 limit, uint8 access, uint8 flags)
|
||||
{
|
||||
if (pseg_descriptor == NULL)
|
||||
return -1;
|
||||
pseg_descriptor->base_low = (base & 0xFFFF);
|
||||
pseg_descriptor->base_middle = (base >> 16) & 0xFF;
|
||||
pseg_descriptor->base_high = (base >> 24) & 0xFF;
|
||||
pseg_descriptor->base_low = (uint16)(base & 0xFFFF);
|
||||
pseg_descriptor->base_middle = (uint8)((base >> 16) & 0xFF);
|
||||
pseg_descriptor->base_high = (uint8)((base >> 24) & 0xFF);
|
||||
|
||||
pseg_descriptor->limit_low = (limit & 0xFFFF);
|
||||
pseg_descriptor->access = access & 0xFF;
|
||||
pseg_descriptor->limit_mid_flags = ((flags & 0x0F) << 4) + ((limit >> 16) & 0x0F);
|
||||
pseg_descriptor->limit_low = (uint16)(limit & 0xFFFF);
|
||||
pseg_descriptor->access = (uint8)(access & 0xFF);
|
||||
pseg_descriptor->limit_mid_flags = (uint8)(((flags & 0x0F) << 4) + ((limit >> 16) & 0x0F));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 hk_set_page_table_entry_32(uint32* dest,uint32 base,uint32 flags)
|
||||
int32 HYPKERNEL32 hk_set_page_table_entry_32(uint32* dest,uint32 base,uint32 flags)
|
||||
{
|
||||
if (dest == NULL)
|
||||
return -1;
|
||||
|
@ -24,7 +23,7 @@ int32 hk_set_page_table_entry_32(uint32* dest,uint32 base,uint32 flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32 hk_set_page_directory_entry_32(uint32* dest, uint32 base, uint32 flags)
|
||||
int32 HYPKERNEL32 hk_set_page_directory_entry_32(uint32* dest, uint32 base, uint32 flags)
|
||||
{
|
||||
if (dest == NULL)
|
||||
return -1;
|
||||
|
@ -32,7 +31,7 @@ int32 hk_set_page_directory_entry_32(uint32* dest, uint32 base, uint32 flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32 hk_map_physcial_address_32(uint32* page_directory_base, uint32 physical_addr, uint32 virtual_addr, uint32 flags)
|
||||
int32 HYPKERNEL32 hk_map_physcial_address_32(uint32* page_directory_base, uint32 physical_addr, uint32 virtual_addr, uint32 flags)
|
||||
{
|
||||
if (page_directory_base == NULL)
|
||||
return -1;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "type32.h"
|
||||
#include "kdef32.h"
|
||||
|
||||
int32 HKA32 hk_set_bit(void* dst,uint32 bit)
|
||||
int32 HYPKERNEL32 hk_set_bit(void* dst,uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
|
@ -13,7 +13,7 @@ int32 HKA32 hk_set_bit(void* dst,uint32 bit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32 HKA32 hk_clear_bit(void* dst, uint32 bit)
|
||||
int32 HYPKERNEL32 hk_clear_bit(void* dst, uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
|
@ -24,7 +24,7 @@ int32 HKA32 hk_clear_bit(void* dst, uint32 bit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32 HKA32 hk_get_bit(void* dst, uint32 bit)
|
||||
int32 HYPKERNEL32 hk_get_bit(void* dst, uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
|
@ -34,7 +34,7 @@ int32 HKA32 hk_get_bit(void* dst, uint32 bit)
|
|||
return *(int32*)(cDst) & (1 << bit);
|
||||
}
|
||||
|
||||
int32 HKA32 hk_toggle_bit(void* dst, uint32 bit)
|
||||
int32 HYPKERNEL32 hk_toggle_bit(void* dst, uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
|
@ -46,7 +46,7 @@ int32 HKA32 hk_toggle_bit(void* dst, uint32 bit)
|
|||
}
|
||||
|
||||
|
||||
int32 HKA32 hk_memcpy(void* src, void* dst, uint32 size)
|
||||
int32 HYPKERNEL32 hk_memcpy(void* src, void* dst, uint32 size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return -1;
|
||||
|
@ -57,7 +57,7 @@ int32 HKA32 hk_memcpy(void* src, void* dst, uint32 size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32 HKA32 hk_memmove(void* src, void* dst, uint32 size)
|
||||
int32 HYPKERNEL32 hk_memmove(void* src, void* dst, uint32 size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return -1;
|
||||
|
@ -74,7 +74,7 @@ int32 HKA32 hk_memmove(void* src, void* dst, uint32 size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32 HKA32 hk_print_string(char* str)
|
||||
int32 HYPKERNEL32 hk_print_string(char* str)
|
||||
{
|
||||
char* gs = (char*)(0xb8000);
|
||||
uint8 attr = 0x07;
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include "io32.h"
|
||||
#include "kdef32.h"
|
||||
|
||||
int32 HKA32 hk_clear_bit(void* dst, uint32 bit);
|
||||
int32 HKA32 hk_get_bit(void* dst, uint32 bit);
|
||||
int32 HKA32 hk_toggle_bit(void* dst, uint32 bit);
|
||||
int32 HKA32 hk_memcpy(void* src, void* dst, uint32 size);
|
||||
int32 HKA32 hk_memmove(void* src, void* dst, uint32 size);
|
||||
int32 HYPKERNEL32 hk_clear_bit(void* dst, uint32 bit);
|
||||
int32 HYPKERNEL32 hk_get_bit(void* dst, uint32 bit);
|
||||
int32 HYPKERNEL32 hk_toggle_bit(void* dst, uint32 bit);
|
||||
int32 HYPKERNEL32 hk_memcpy(void* src, void* dst, uint32 size);
|
||||
int32 HYPKERNEL32 hk_memmove(void* src, void* dst, uint32 size);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue