1
0

Move atags support to be ARM arch-specific

This commit is contained in:
2012-12-24 12:40:30 -05:00
parent ed52a8af5c
commit 62755b8f38
5 changed files with 24 additions and 17 deletions

68
arch/arm/include/atags.h Normal file
View File

@ -0,0 +1,68 @@
/*
Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
This file is part of Aedrix.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef ATAGS_H
#define ATAGS_H
#include <types.h>
#define ATAG_NONE 0x00000000
#define ATAG_CORE 0x54410001
#define ATAG_MEM 0x54410002
#define ATAG_VIDEOTEXT 0x54410003
#define ATAG_RAMDISK 0x54410004
#define ATAG_INITRD2 0x54420005
#define ATAG_SERIAL 0x54410006
#define ATAG_REVISION 0x54410007
#define ATAG_VIDEOLFB 0x54410008
#define ATAG_CMDLINE 0x54410009
struct atag_core {
uint32 flags; /* bit 0 = read-only */
uint32 pagesize; /* systems page size (usually 4k) */
uint32 rootdev; /* root device number */
};
struct atag_mem {
uint32 size; /* size of the area */
arch_uint_ptr start; /* physical start address */
};
struct atag {
uint32 size; /* Size of tag in words (includes entire struct) */
uint32 tag;
union {
struct atag_core core;
struct atag_mem mem;
// struct atag_videotext videotext;
// struct atag_ramdisk ramdisk;
// struct atag_initrd2 initrd2;
// struct atag_serialnr serialnr;
// struct atag_revision revision;
// struct atag_videolfb videolfb;
// struct atag_cmdline cmdline;
} data;
};
#define atags_first_mem_region(atag) _atags_mem_region(atag, 1)
#define atags_next_mem_region(atag) _atags_mem_region(atag, 0)
int _atags_mem_region(struct atag **mem_header, int initialize);
#endif /* ATAGS_H */

80
arch/arm/kernel/atags.c Normal file
View File

@ -0,0 +1,80 @@
/*
Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
This file is part of Aedrix.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <atags.h>
#include <mmu.h>
extern arch_uint_ptr atags_ptr;
int atag_valid(struct atag *a) {
switch (a->tag) {
case ATAG_NONE:
return a->size == 2;
case ATAG_CORE:
return a->size == 2 || a->size == 5;
case ATAG_MEM:
case ATAG_INITRD2:
case ATAG_SERIAL:
return a->size == 4;
case ATAG_VIDEOTEXT:
case ATAG_RAMDISK:
return a->size == 5;
case ATAG_REVISION:
return a->size == 3;
case ATAG_VIDEOLFB:
return a->size == 8;
case ATAG_CMDLINE:
return a->size >= 3;
default:
return 0;
}
}
int _atags_mem_region(struct atag **mem_header, int initialize) {
if (initialize)
*mem_header = (struct atag *)atags_ptr;
else
*mem_header = (struct atag *)((uint32 *)*mem_header + (*mem_header)->size);
while (atag_valid(*mem_header) && (*mem_header)->tag != ATAG_NONE && (*mem_header)->tag != ATAG_MEM) {
*mem_header = (struct atag *)((uint32 *)*mem_header + (*mem_header)->size);
}
if (!atag_valid(*mem_header) || (*mem_header)->tag == ATAG_NONE)
return -1;
return 0;
}
int detect_memory() {
struct atag *atags;
char *lower, *upper;
if (atags_first_mem_region(&atags)) {
return -1;
}
do {
lower = (char *)atags->data.mem.start;
upper = lower + atags->data.mem.size - 1;
declare_memory_region(lower, upper);
} while (!atags_next_mem_region(&atags));
return 0;
}

View File

@ -3,7 +3,8 @@ SUBDIRS :=
include $(BASEDIR)/header.mk
OBJS_$(d) := $(d)/mmu.o
OBJS_$(d) := $(d)/atags.o \
$(d)/mmu.o
KOBJS += $(OBJS_$(d))