File:  [Local Repository] / solidite / kernel / main / main.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Sep 8 00:37:30 2026 UTC (11 days, 2 hours ago) by user
Branches: none, MAIN
CVS tags: notag, HEAD
Migrate host

/* Copyright (c) 2026 The Solidite Developers
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>. */

#include "../../libc/include/stdint.h"

#if defined(__riscv) && (__riscv_xlen == 64) /* 64-bit RISC-V */

#include "../libkernel/riscv64.h"

#define MODULED_ADDRESS 0x80400000

asm (
  ".section .text\n"
    ".globl _start\n"

  "_start:\n"
    "la sp, stack_top\n"
    "tail main\n"

  ".section .bss\n"
    ".align 12\n" /* 4 KiB stack alignment */
    ".space 0x4000\n" /* 16 KiB stack allocation */

  "stack_top:\n"

  ".section .text\n"
);

void main(unsigned long hartid, unsigned long dtb_pa) {
  if (hartid != 0)
    return; /* no SMP yet */
  else
    kwrite("[kernel] console init\n");

  ((void (*)(unsigned long))MODULED_ADDRESS)(dtb_pa);
  return;
}

#elif defined(__x86_64__) /* x86_64 */

__attribute__((used, section(".limine_requests"))) static volatile uint64_t
    limine_base_revision[] = {0xfacade934a3e2a22, 0x51da7bc4ced6c7c1, 0};
  /* uses limine boot protocol for now, TODO: add multiboot v2 */

void _start(void) {
  for (;;) {}
}

#else
#error "The kernel does not have support for your CPU architecture."
#error "Please check your C preprocessor if you believe this is a mistake."
#endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>