gokernel
(usa Linux Mint)
Enviado em 30/07/2017 - 18:04h
Caramba!, passei praticamente a tarde toda tentando fazer esse funcionar corretamente no ( WINDOWS com GCC ):
//-------------------------------------------------------------------
// ARQUIVO:
// stage0.s
//
// COMPILE:
// gcc -c -Wall -Werror stage0.s -o stage0.o
// ld stage0.o -o stage0.elf -T stage0.ld
// objcopy -R .pdr -R .comment -R.note -S -O binary stage0.elf stage0_kernel
//
// Author:
// Ashakiran Bhatter
// https://www.codeproject.com/KB/cpp/737545/sourcecode.rar
//
// USAGE:
// qemu stage0_kernel
//
// stage0.ld:
//-----------------------------------------------
// SECTIONS
// {
// . = 0x7c00;
// .text :
// {
// _ftext = .;
// } = 0
// }
//
//-----------------------------------------------
//
//-------------------------------------------------------------------
//
.code16
.text
.globl _start;
_start:
jmp _boot
nop
/*bios parameter block description of each entity value datatype width(in bytes) */
/*-------------------- -------------------------- ----- -------- --------------- */
.byte 0x6b,0x69,0x72,0x55,0x58,0x30,0x2e,0x31 /* oem label : kirUX0.1 , type: string , length: 8 */
.byte 0x00,0x02 /* total bytes per sector : 512 , type: word , length: 4 */
.byte 0x01 /* total sectors per cluster : 1 , type: byte , length: 1 */
.byte 0x01,0x00 /* total reserved sectors : 1 , type: word , length: 4 */
.byte 0x02 /* total fat tables : 2 , type: byte , length: 1 */
.byte 0xe0,0x00 /* total directory entries : 224 , type: word , length: 4 */
.byte 0x40,0x0b /* total sectors : 2880 , type: word , length: 4 */
.byte 0xf0 /* media description : 0xf0 , type: byte , length: 1 */
.byte 0x09,0x00 /* size in sectors of each fat table : 9 , type: word , length: 4 */
.byte 0x02,0x01 /* total sectors per track : 18 , type: word , length: 4 */
.byte 0x02,0x00 /* total heads per cylinder : 2 , type: word , length: 4 */
.byte 0x00,0x00, 0x00, 0x00 /* total hidden sectors : 0 , type: double word , length: 4 */
.byte 0x00,0x00, 0x00, 0x00 /* total big sectors : 0 , type: double word , length: 4 */
.byte 0x00 /* boot drive identifier : 0 , type: byte , length: 4 */
.byte 0x00 /* total unused sectors : 0 , type: byte , length: 4 */
.byte 0x29 /* external boot signature : 0x29 , type: byte , length: 4 */
.byte 0x22,0x62,0x79,0x20 /* serial number : "by , type: string , length: 4 */
.byte 0x41,0x53,0x48,0x41,0x4b,0x49 /* volume label first 6 bytes of 11 : ASHAKI , type: string , length: 6 */
.byte 0x52,0x41,0x4e,0x20,0x42 /* volume label second 5 bytes of 11 : RAN B , type: string , length: 5 */
.byte 0x48,0x41,0x54,0x54,0x45,0x52,0x22 /* file system type : HATTER" , type: string , length: 8 */
//-----------------------------------------------
// MACROS:
//-----------------------------------------------
//
.macro initEnvironment
call _initEnvironment
.endm
.macro writeString message
pushw \message
call _writeString
addw $0x02, %sp
.endm
//-----------------------------------------------
// inicio real:
//-----------------------------------------------
_boot:
// initialize the environment
initEnvironment
writeString $msgHello
label_forever:
hlt
jmp label_forever
/* user-defined routines */
/* this function is used to set-up the */
/* registers and stack as required */
/* parameter(s): none */
_initEnvironment:
pushw %bp
movw %sp, %bp
_initEnvironmentIn:
cli
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $0x7c00, %sp
sti
_initEnvironmentOut:
movw %bp, %sp
popw %bp
ret
/* this function is used to display a string */
/* onto the screen */
/* parameter(s): input string */
_writeString:
pushw %bp
movw %sp , %bp
movw 4(%bp) , %si
jmp _writeStringCheckByte
_writeStringIn:
movb $0x000e, %ah
movb $0x0000, %bh
int $0x0010
incw %si
_writeStringCheckByte:
movb (%si) , %al
orb %al , %al
jnz _writeStringIn
_writeStringOut:
movw %bp , %sp
popw %bp
ret
// user-defined variables
bootDrive : .byte 0x0000
msgHello : .asciz "Hello World - BOOT CD-ROM MINIOS"
msgAbort : .asciz "* * * F A T A L E R R O R * * *"
#fileStage2: .ascii "STAGE2 BIN"
fileStage2: .ascii "KERNEL BIN"
clusterID : .word 0x0000
//-----------------------------------------------
//---------- ESSENCIAL: nao mudar aqui ----------
//-----------------------------------------------
. = _start + 510
.word 0xaa55
//-----------------------------------------------
SAIDA DO PROGRAMA:
Hello World - BOOT CD-ROM MINIOS
Ao tentar compilar no LINUX funcionou perfeitamente ... CONCLUSÃO:
Vou trocar o GCC pelo NASM no meu projeto, pois não pretendo deixar o OS do tio Gates sem uso. ;).
Ufa !... ainda bem que compilou !