Questions about Higher Half Kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
AwfulMint
Member
Member
Posts: 35
Joined: Wed Nov 01, 2017 7:41 pm

Questions about Higher Half Kernel

Post by AwfulMint »

1. How I implement the code of http://wiki.osdev.org/Higher_Half_x86_Bare_Bones to the old one?

2. I have a error when compiling, all ASM methods seens wrong, but the old file works fine, what's happen?

Code: Select all

kernel/loader.s: Assembler messages:
kernel/loader.s: Warning: end of file not at end of a line; newline inserted
kernel/loader.s:1: Error: no such instruction: `global _loader'
kernel/loader.s:2: Error: no such instruction: `extern kernel_main'
kernel/loader.s:4: Error: no such instruction: `modulealign equ 1<<0'
kernel/loader.s:5: Error: no such instruction: `meminfo equ 1<<1'
kernel/loader.s:6: Error: no such instruction: `flags equ MODULEALIGN|MEMINFO'
kernel/loader.s:7: Error: no such instruction: `magic equ 0x1B4DB002'
kernel/loader.s:8: Error: no such instruction: `checksum equ -(MAGIC+FLAGS)'
kernel/loader.s:10: Error: no such instruction: `kernel_virtual_base equ 0xC0000000'
kernel/loader.s:11: Error: no such instruction: `kernel_page_number equ (KERNEL_VIRTUAL_BASE>>22)'
kernel/loader.s:13: Error: no such instruction: `section .data'
kernel/loader.s:14: Error: no such instruction: `align 0x1000'
kernel/loader.s:16: Error: no such instruction: `dd 0x00000083'
kernel/loader.s:17: Error: no such instruction: `times (KERNEL_PAGE_NUMBER - 1)dd 0'
kernel/loader.s:18: Error: no such instruction: `dd 0x00000083'
kernel/loader.s:19: Error: no such instruction: `times (1024 - KERNEL_PAGE_NUMBER - 1)dd 0'
kernel/loader.s:21: Error: no such instruction: `section .text'
kernel/loader.s:22: Error: no such instruction: `align 4'
kernel/loader.s:24: Error: no such instruction: `dd MAGIC'
kernel/loader.s:25: Error: no such instruction: `dd FLAGS'
kernel/loader.s:26: Error: no such instruction: `dd CHECKSUM'
kernel/loader.s:28: Error: no such instruction: `stack_size equ 0x4000'
kernel/loader.s:29: Error: no such instruction: `loader equ (_loader - 0xC0000000'
kernel/loader.s:30: Error: no such instruction: `global loader'
kernel/loader.s:33: Error: too many memory references for `mov'
kernel/loader.s:34: Error: too many memory references for `mov'
kernel/loader.s:36: Error: too many memory references for `mov'
kernel/loader.s:37: Error: too many memory references for `or'
kernel/loader.s:38: Error: too many memory references for `mov'
kernel/loader.s:40: Error: too many memory references for `mov'
kernel/loader.s:41: Error: too many memory references for `or'
kernel/loader.s:42: Error: too many memory references for `mov'
kernel/loader.s:44: Error: invalid char '[' beginning operand 2 `[StartInHH]'
kernel/loader.s:48: Error: junk `[BootPageDirectory]' after expression
kernel/loader.s:48: Error: too many memory references for `mov'
kernel/loader.s:49: Error: no such instruction: `invpg [0]'
kernel/loader.s:50: Error: too many memory references for `mov'
kernel/loader.s:57: Error: no such instruction: `section .bss'
kernel/loader.s:58: Error: no such instruction: `align 32'
kernel/loader.s:60: Error: no such instruction: `resb STACK_SIZE'

3. For the last, I need a direction to go, I don't know where I start but I'm learning using the "Diff metter" in wiki.
OS Development is awesome!

|AetherOS Project|
AwfulMint
Member
Member
Posts: 35
Joined: Wed Nov 01, 2017 7:41 pm

Re: Questions about Higher Half Kernel

Post by AwfulMint »

here's the code of loader.s

Code: Select all

global _loader
extern kernel_main

MODULEALIGN equ 1<<0
MEMINFO 	equ 1<<1
FLAGS		equ MODULEALIGN | MEMINFO
MAGIC		equ 0x1B4DB002
CHECKSUM	equ -(MAGIC+FLAGS)

KERNEL_VIRTUAL_BASE	equ 0xC0000000
KERNEL_PAGE_NUMBER	equ (KERNEL_VIRTUAL_BASE >> 22)

section .data
	align 0x1000
	BootPageDirectory:
		dd 0x00000083
		times (KERNEL_PAGE_NUMBER - 1) dd 0
		dd 0x00000083
		times (1024 - KERNEL_PAGE_NUMBER - 1) dd 0

section .text
	align 4
	MultiBootHeader:
		dd MAGIC
		dd FLAGS
		dd CHECKSUM
	
	STACK_SIZE	equ 0x4000
	loader equ (_loader - 0xC0000000
	global loader
	
_loader:
	mov ecx, (BootPageDirectory - KERNEL_VIRTUAL_BASE)
	mov cr3, ecx
	
	mov ecx, cr4
	or ecx, 0x00000010
	mov cr4, ecx
	
	mov ecx, cr0
	or ecx, 0x80000000
	mov cr0, ecx
	
	lea ecx, [StartInHH]
	jmp ecx
	
StartInHH:
	mov dword [BootPageDirectory], 0
	invpg [0]
	mov esp, stack+STACK_SIZE
	push eax
	push ebx
	
	call kernel_main
	hlt
	
section .bss
	align 32
	stack:
		resb STACK_SIZE
OS Development is awesome!

|AetherOS Project|
AwfulMint
Member
Member
Posts: 35
Joined: Wed Nov 01, 2017 7:41 pm

Re: Questions about Higher Half Kernel

Post by AwfulMint »

the old boot.s file:

Code: Select all

.extern kernel_main
.global start

.set MB_MAGIC, 0x1BADB002
.set MB_FLAGS, (1 << 0) | (1 << 1)
.set MB_CHECKSUM, (0 - (MB_MAGIC + MB_FLAGS))

.section .multiboot
	.align 4
	.long MB_MAGIC
	.long MB_FLAGS
	.long MB_CHECKSUM

.section .bss
	.align 16
	stack_bottom:
		.skip 4096
	stack_top:

.section .text
	start:
		mov $stack_top, %esp
		call kernel_main

		hang:
			cli
			hlt
			jmp hang
OS Development is awesome!

|AetherOS Project|
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Questions about Higher Half Kernel

Post by MichaelPetch »

Your old boot.s is written for GNU Assembler (you assemble with as). Your new loader.s is written in NASM assembly syntax so you will need to assemble it with the nasm assembler. If you want to use as to assemble your loader.s you'd have to convert the assembly code by hand.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Questions about Higher Half Kernel

Post by Schol-R-LEA »

For further flavor on what @MichaelPetch said, see the wiki pages Assembly and Opcode syntax, as well as the pages specifically about GAS and NASM.

Basically, even when they are targeting the same ISA, each different assembler can have its own syntax for things such as opcode names, order of operands, representations of different numeric bases and string formats, labels, and directives such as equates and origins.

While most x86 assemblers more or less follow the opcode syntax and argument ordering defined by Intel, the Gnu Assembler, GAS, uses an older opcode format going back to the original as assembler for AT&T Unix. There are a number of differences in the AT&T syntax from the Intel syntax, most notably that while Intel defines the argument order as 'destination, source', the AT&T syntax follows what I assume was the PDP-11 syntax of 'source, destination', meaning that for the Intel syntax, "eax += 3" (that is, add 3 to EAX and save the result in EAX) would be

Code: Select all

    add eax, DWORD 3
but for the AT&T/Gnu syntax, it would be:

Code: Select all

    addl $3, %eax
Where the '$' prefix indicates an immediate operand, the '%' prefix means a register argument, and the 'l' suffix means a long (32-bit double-word) operation.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
AwfulMint
Member
Member
Posts: 35
Joined: Wed Nov 01, 2017 7:41 pm

Re: Questions about Higher Half Kernel

Post by AwfulMint »

Thanks m8s! I'm new at osdev so I have a lot of questions, van someone teach me the art of osdeving :3
OS Development is awesome!

|AetherOS Project|
Post Reply