OS 16 bits (Hello) CD-ROM boot

1. OS 16 bits (Hello) CD-ROM boot

???
gokernel

(usa Linux Mint)

Enviado em 29/07/2017 - 08:55h

Olá Pessoal !

Fazia uma semana que estava tentando criar CD-ROM de boot ( boot loader ) com o "stage 0" e não sabia como compilar.

Depois de muita pesquisa ... Glória a Deus consegui ! ...

Vamos lá:
01: Primeiro criar a pasta( /temp/hello_boot )
02: Ao recompilar é indicado apagar todos os arquivos exceto ( hello.s, link.ld ) OK ?

Um simples exemplo do ("stage 0") Hello World:

//-------------------------------------------------------------------
//
// Um simples "Hello World" com BOOT:
//
// ARQUIVO:
// hello.s
//
// ##############################################
//
// COMPILA O BINARIO:
//
// cd /temp/hello_boot
//
// gcc -s -c hello.s -o hello.o -Wall
// ld hello.o -o hello.bin -T link.ld
// objcopy -O binary hello.bin bkernel
//
// GERA UM CD BOOTAVEL:
// mkdosfs -C hello.flp 1440 || exit
// dd status=noxfer conv=notrunc if=bkernel of=hello.flp || exit
// mkisofs -R -b hello.flp -o /temp/hello_boot.iso /temp/hello_boot
//
// ##############################################
//
// LIMITACAO:
// Programa maximo com 510 bytes.
//
// VANTAGEM:
// MODO REAL(16 bits): Pode-se usar interrupcao a vontade ...
//
// FONTES DO SCRIPT CD-ROM BOOT:
//
// Projeto MikeOS ( OS 16 bits ), arquivo ( build-linux.sh )
//
// https://github.com/mig-hub/mikeOS
//
// POR:
// Francisco - gokernel@hotmail.com
//
//-------------------------------------------------------------------
//
.code16
.text
.globl _start;
_start:

jmp _boot
nop

_boot:

// Display: "Hello"
//
mov $0xe,%ah
mov $72,%al
int $0x10
mov $101,%al
int $0x10
mov $108,%al
int $0x10
int $0x10
mov $111,%al
int $0x10

label_forever:
hlt
jmp label_forever

msgHello: .asciz "Hello World - CD BOOT MINI OS"


//-----------------------------------------------
//---------- ESSENCIAL: nao mudar aqui ----------
//-----------------------------------------------
. = _start + 510
.word 0xaa55
//-----------------------------------------------


Arquivo ( link.ld ):


SECTIONS
{
. = 0x7c00;
.text :
{
_ftext = .;
} = 0
}



Esse código vou utilizar como arranque do gardenOS ( CD-ROM BOOT ) sem o grub.

01 - Testando no QEMU:

qemu -cdrom hello_boot.iso



Já gravei o CD-ROM e guardei esse como relíquia ..."COISA PRECIOSA" !

E sim o CD-ROM funcionou perfeitamente no boot ... até funcionou com as teclas ( CTRL + ALT + DEL ) ... talvez não funcione se acrescentar ( cli ) no código ( não testei com asm("cli"); ).

Se alguém gostou e se interessar depois vou tentar traduzir esse com BOOT e postarei aqui:
http://wiki.osdev.org/Real_mode_assembly_I

Para quem não sabe todos os bootloaders(grub, lilo, etc) iniciam em MODO REAL ( 16 bits ) e depois muda para 32/64 bits se necessário.

Compartilhando !!!



  


2. Re: OS 16 bits (Hello) CD-ROM boot

Perfil removido
removido

(usa Nenhuma)

Enviado em 29/07/2017 - 12:28h

Cara esse projeto parece ser legal, tenta fazer um shell proprio para assim deixar o bash, tenta postar no github o trabalho para dar uma testada.



Meu github:
#===============================#
# https://github.com/Python-Library-Work #
#===============================#
O universo e um infinito de possibilidades!!!



3. Re: OS 16 bits (Hello) CD-ROM boot

???
gokernel

(usa Linux Mint)

Enviado em 29/07/2017 - 15:57h

Olá "AndrewUser" !

Sim o projeto é "legal acho" ;)

Já tem um mini shell implementado ( em parte ) ... mas vou codando nas horas vagas, está ainda em fase inicial.
Depois atualizarei o novo código.

Decidi mudar os comentários para o nosso BR ... motivo?: talvez o meu garoto(agora com 2 anos e 6 meses) no futuro se interesse neste, então será melhor para nossos "jovens" que não entendem bem o inglês.

Quando o projeto tiver numa fase mais adiantada então "talvez" disponibilizarei no github.
OBS: o projeto inicialmente está hospedado aqui:
https://sourceforge.net/projects/garden-linux/files/

OBS2: esse é somente o código inicial e cheio de "erros de gramática" exemplo( veja ao baixar o .iso ):
---------------------------------------------------------------------
To compile the OPERATION SISTEM ( gardenOS ) type:
---------------------------------------------------------------------

T+.




4. Re: OS 16 bits (Hello) CD-ROM boot

Paulo
paulo1205

(usa Ubuntu)

Enviado em 30/07/2017 - 07:17h

gokernel escreveu:

Decidi mudar os comentários para o nosso BR ... motivo?: talvez o meu garoto(agora com 2 anos e 6 meses) no futuro se interesse neste, então será melhor para nossos "jovens" que não entendem bem o inglês.


Outra possibilidade seria você falar Inglês com seu garoto. Faço isso com minha filha desde o útero, e, agora, com quase oito anos ela tem muita facilidade de se comunicar em Inglês. É muito interessante vê-la brincando com suas bonecas em Inglês, ver como ela ajuda mãe com o Inglês, e saber que ela sonha em Inglês, mesmo sendo eu praticamente a única pessoa que interage sempre com ela nessa língua.


5. Re: OS 16 bits (Hello) CD-ROM boot

???
gokernel

(usa Linux Mint)

Enviado em 30/07/2017 - 09:34h

"Paulo1205" escreveu:

Outra possibilidade seria você falar Inglês com seu garoto. Faço isso com minha filha desde o útero, e, agora, com quase oito anos ela tem muita facilidade de se comunicar em Inglês. É muito interessante vê-la brincando com suas bonecas em Inglês, ver como ela ajuda mãe com o Inglês, e saber que ela sonha em Inglês, mesmo sendo eu praticamente a única pessoa que interage sempre com ela nessa língua.


Tá me zoando né ? rarsrsrs

Se for interagir com o "boyzinho" em inglês vai ser uma piada ;) ... meu inglês não é bom para escrever ... e péssimo para falar ( não pratico ).

Talvez me interesse em praticar o inglês quando for convidado para passar umas férias na casa de minha prima na Flórida .

Por enquanto quero que ele brinque com coisas(físicas) tipo: areia, água, bicicleta, brinquedos de plásticos.

Divertido é quando ele vai brincar no muro com areia ... ou dar um passeio de moto comigo.



6. Re: OS 16 bits (Hello) CD-ROM boot

???
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 !




  



Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts