I have been trying for some time to switch from 16bits boot loader to 32 to start a kernel I’m creating for my project, but I can’t find a solution. How can I do? I use gas.
I tried to go from 16 to 32 in these two ways but the first if I add the mode to 32 no longer works and I do not load the kernel to 32. While the second, which is a multiboot, doesn’t start at all. I got this mode from an internet project.
First mode or my mode:
`# generate 16-bit code
.code16
hint the assembler that here is the executable code located
.text
.globl _start;
boot code entry
_start:
jmp _boot # jump to boot code
welcome: .asciz “Hello, Worldnr” # here we define the string
.macro mWriteString str # macro which calls a function to print a string
leaw str, %si
call .writeStringIn
.endm
#function to print the string
.writeStringIn:
lodsb
orb %al, %al
jz .writeStringOut
movb $0x0e, %ah
int $0x10
jmp .writeStringIn
.writeStringOut:
.code32
.callKernel:
call kernel_main
ret
_boot:
mWriteString welcome
# move to 510th byte from the start and append boot signature
. = _start + 510
.byte 0x55
.byte 0xaa
**Second mode or internet mode:**
.code16
.text
.globl _start;
_start:
jmp _boot
nop
/*bios parameter block description of each entity /
/——————– ————————– /
.byte 0x6b,0x69,0x72,0x55,0x58,0x30,0x2e,0x31 / oem label /
.byte 0x00,0x02 / total bytes per sector /
.byte 0x01 / total sectors per cluster /
.byte 0x01,0x00 / total reserved sectors /
.byte 0x02 / total fat tables /
.byte 0xe0,0x00 / total directory entries /
.byte 0x40,0x0b / total sectors /
.byte 0xf0 / media description /
.byte 0x09,0x00 / size in of each fat table /
.byte 0x02,0x01 / total sectors per track /
.byte 0x02,0x00 / total heads per cylinder /
.byte 0x00,0x00, 0x00, 0x00 / total hidden sectors /
.byte 0x00,0x00, 0x00, 0x00 / total big sectors /
.byte 0x00 / boot drive identifier /
.byte 0x00 / total unused sectors /
.byte 0x29 / external boot signature /
.byte 0x22,0x62,0x79,0x20 / serial number /
.byte 0x41,0x53,0x48,0x41,0x4b,0x49 / volume label 6 bytes of 11 /
.byte 0x52,0x41,0x4e,0x20,0x42 / volume label 5 bytes of 11 /
.byte 0x48,0x41,0x54,0x54,0x45,0x52,0x22 / file system type */
/* include macro functions */
#include "macros.S"
/* begining of main code /
_boot:
/ initialize the environment */
initEnvironment
/* load stage2 */
loadFile $fileStage2
/* infinite loop */
_freeze:
jmp _freeze
/* abnormal termination of program */
_abort:
writeString $msgAbort
jmp _freeze
/* include functions */
#include "routines.S"
/* user-defined variables */
bootDrive : .byte 0x0000
msgAbort : .asciz "* * * F A T A L E R R O R * * *"
#fileStage2: .ascii "STAGE2 BIN"
fileStage2: .ascii "KERNEL BIN"
clusterID : .word 0x0000
/* traverse 510 bytes from beginning */
. = _start + 0x01fe
/* append boot signature */
.word BOOT_SIGNATURE`
BearSnow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.